X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/4388f060552cc537e71e957d32f35e9d75a61233..1a147d096ae81f4c8262f7bfc56bd19fc2dee932:/icuSources/test/cintltst/nucnvtst.c diff --git a/icuSources/test/cintltst/nucnvtst.c b/icuSources/test/cintltst/nucnvtst.c index 5742de03..ba8d1313 100644 --- a/icuSources/test/cintltst/nucnvtst.c +++ b/icuSources/test/cintltst/nucnvtst.c @@ -1,11 +1,13 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2011, International Business Machines Corporation and + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************* * -* File CCONVTST.C +* File nucnvtst.c * * Modification History: * Name Description @@ -26,14 +28,14 @@ #include "cmemory.h" #include "nucnvtst.h" -#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) - static void TestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message); static void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message); #if !UCONFIG_NO_COLLATION static void TestJitterbug981(void); #endif +#if !UCONFIG_NO_LEGACY_CONVERSION static void TestJitterbug1293(void); +#endif static void TestNewConvertWithBufferSizes(int32_t osize, int32_t isize) ; static void TestConverterTypesAndStarters(void); static void TestAmbiguous(void); @@ -403,7 +405,7 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, targ = junkout; offs = junokout; - realBufferSize = (sizeof(junkout)/sizeof(junkout[0])); + realBufferSize = UPRV_LENGTHOF(junkout); realBufferEnd = junkout + realBufferSize; realSourceEnd = source + sourceLen; @@ -561,7 +563,7 @@ static ETestConvertResult testConvertToU( const uint8_t *source, int sourcelen, targ = junkout; offs = junokout; - realBufferSize = (sizeof(junkout)/sizeof(junkout[0])); + realBufferSize = UPRV_LENGTHOF(junkout); realBufferEnd = junkout + realBufferSize; realSourceEnd = src + sourcelen; @@ -833,7 +835,7 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) /*UTF-8*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedUTF8, sizeof(expectedUTF8), "UTF8", toUTF8Offs,FALSE ); log_verbose("Test surrogate behaviour for UTF8\n"); @@ -844,7 +846,7 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0xef, 0xbf, 0xbd }; static const int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3 }; - testConvertFromU(testinput, sizeof(testinput)/sizeof(testinput[0]), + testConvertFromU(testinput, UPRV_LENGTHOF(testinput), expectedUTF8test2, sizeof(expectedUTF8test2), "UTF8", offsets,FALSE ); @@ -852,47 +854,47 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) #if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022) /*ISO-2022*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedISO2022, sizeof(expectedISO2022), "ISO_2022", toISO2022Offs,FALSE ); #endif /*UTF16 LE*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs,FALSE ); /*UTF16 BE*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedUTF16BE, sizeof(expectedUTF16BE), "utf-16be", toUTF16BEOffs,FALSE ); /*UTF32 LE*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedUTF32LE, sizeof(expectedUTF32LE), "utf-32le", toUTF32LEOffs,FALSE ); /*UTF32 BE*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedUTF32BE, sizeof(expectedUTF32BE), "utf-32be", toUTF32BEOffs,FALSE ); /*LATIN_1*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedLATIN1, sizeof(expectedLATIN1), "LATIN_1", toLATIN1Offs,FALSE ); #if !UCONFIG_NO_LEGACY_CONVERSION /*EBCDIC_STATEFUL*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedIBM930, sizeof(expectedIBM930), "ibm-930", toIBM930Offs,FALSE ); - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,FALSE ); /*MBCS*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedIBM943, sizeof(expectedIBM943), "ibm-943", toIBM943Offs,FALSE ); /*DBCS*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedIBM9027, sizeof(expectedIBM9027), "@ibm9027", toIBM9027Offs,FALSE ); /*SBCS*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedIBM920, sizeof(expectedIBM920), "ibm-920", toIBM920Offs,FALSE ); /*SBCS*/ - testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), + testConvertFromU(sampleText, UPRV_LENGTHOF(sampleText), expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs,FALSE ); #endif @@ -901,51 +903,51 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) /*UTF-8*/ testConvertToU(expectedUTF8, sizeof(expectedUTF8), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf8", fmUTF8Offs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "utf8", fmUTF8Offs,FALSE); #if !UCONFIG_NO_LEGACY_CONVERSION && defined(U_ENABLE_GENERIC_ISO_2022) /*ISO-2022*/ testConvertToU(expectedISO2022, sizeof(expectedISO2022), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ISO_2022", fmISO2022Offs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "ISO_2022", fmISO2022Offs,FALSE); #endif /*UTF16 LE*/ testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "utf-16le", fmUTF16LEOffs,FALSE); /*UTF16 BE*/ testConvertToU(expectedUTF16BE, sizeof(expectedUTF16BE), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16be", fmUTF16BEOffs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "utf-16be", fmUTF16BEOffs,FALSE); /*UTF32 LE*/ testConvertToU(expectedUTF32LE, sizeof(expectedUTF32LE), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-32le", fmUTF32LEOffs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "utf-32le", fmUTF32LEOffs,FALSE); /*UTF32 BE*/ testConvertToU(expectedUTF32BE, sizeof(expectedUTF32BE), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-32be", fmUTF32BEOffs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "utf-32be", fmUTF32BEOffs,FALSE); #if !UCONFIG_NO_LEGACY_CONVERSION /*EBCDIC_STATEFUL*/ testConvertToU(expectedIBM930, sizeof(expectedIBM930), sampleTextRoundTripUnmappable, - sizeof(sampleTextRoundTripUnmappable)/sizeof(sampleTextRoundTripUnmappable[0]), "ibm-930", fmIBM930Offs,FALSE); + UPRV_LENGTHOF(sampleTextRoundTripUnmappable), "ibm-930", fmIBM930Offs,FALSE); /*MBCS*/ testConvertToU(expectedIBM943, sizeof(expectedIBM943),sampleTextRoundTripUnmappable, - sizeof(sampleTextRoundTripUnmappable)/sizeof(sampleTextRoundTripUnmappable[0]), "ibm-943", fmIBM943Offs,FALSE); + UPRV_LENGTHOF(sampleTextRoundTripUnmappable), "ibm-943", fmIBM943Offs,FALSE); #endif /* Try it again to make sure it still works */ testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE); + sampleText, UPRV_LENGTHOF(sampleText), "utf-16le", fmUTF16LEOffs,FALSE); #if !UCONFIG_NO_LEGACY_CONVERSION testConvertToU(expectedMaltese913, sizeof(expectedMaltese913), - malteseUChars, sizeof(malteseUChars)/sizeof(malteseUChars[0]), "latin3", NULL,FALSE); + malteseUChars, UPRV_LENGTHOF(malteseUChars), "latin3", NULL,FALSE); - testConvertFromU(malteseUChars, sizeof(malteseUChars)/sizeof(malteseUChars[0]), + testConvertFromU(malteseUChars, UPRV_LENGTHOF(malteseUChars), expectedMaltese913, sizeof(expectedMaltese913), "iso-8859-3", NULL,FALSE ); /*LMBCS*/ - testConvertFromU(LMBCSUChars, sizeof(LMBCSUChars)/sizeof(LMBCSUChars[0]), + testConvertFromU(LMBCSUChars, UPRV_LENGTHOF(LMBCSUChars), expectedLMBCS, sizeof(expectedLMBCS), "LMBCS-1", toLMBCSOffs,FALSE ); testConvertToU(expectedLMBCS, sizeof(expectedLMBCS), - LMBCSUChars, sizeof(LMBCSUChars)/sizeof(LMBCSUChars[0]), "LMBCS-1", fmLMBCSOffs,FALSE); + LMBCSUChars, UPRV_LENGTHOF(LMBCSUChars), "LMBCS-1", fmLMBCSOffs,FALSE); #endif /* UTF-7 examples are mostly from http://www.imc.org/rfc2152 */ @@ -1014,13 +1016,13 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 16, 16, 16, 17, 17, 17, 18, 18, 18, 18 }; - testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,FALSE); + testConvertFromU(unicode, UPRV_LENGTHOF(unicode), utf7, sizeof(utf7), "UTF-7", fromUnicodeOffsets,FALSE); - testConvertToU(utf7, sizeof(utf7), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "UTF-7", toUnicodeOffsets,FALSE); + testConvertToU(utf7, sizeof(utf7), unicode, UPRV_LENGTHOF(unicode), "UTF-7", toUnicodeOffsets,FALSE); - testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, utf7Restricted, sizeof(utf7Restricted), "UTF-7,version=1", fromUnicodeOffsetsR,FALSE); + testConvertFromU(unicode, UPRV_LENGTHOF(unicode), utf7Restricted, sizeof(utf7Restricted), "UTF-7,version=1", fromUnicodeOffsetsR,FALSE); - testConvertToU(utf7Restricted, sizeof(utf7Restricted), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "UTF-7,version=1", toUnicodeOffsetsR,FALSE); + testConvertToU(utf7Restricted, sizeof(utf7Restricted), unicode, UPRV_LENGTHOF(unicode), "UTF-7,version=1", toUnicodeOffsetsR,FALSE); } /* @@ -1094,9 +1096,9 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 35, 36, 36, 36, 37, 37, 37, 37, 37 }; - testConvertFromU(unicode, sizeof(unicode)/U_SIZEOF_UCHAR, imap, sizeof(imap), "IMAP-mailbox-name", fromUnicodeOffsets,FALSE); + testConvertFromU(unicode, UPRV_LENGTHOF(unicode), imap, sizeof(imap), "IMAP-mailbox-name", fromUnicodeOffsets,FALSE); - testConvertToU(imap, sizeof(imap), unicode, sizeof(unicode)/U_SIZEOF_UCHAR, "IMAP-mailbox-name", toUnicodeOffsets,FALSE); + testConvertToU(imap, sizeof(imap), unicode, UPRV_LENGTHOF(unicode), "IMAP-mailbox-name", toUnicodeOffsets,FALSE); } /* Test UTF-8 bad data handling*/ @@ -1111,29 +1113,39 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0xf4, 0x8f, 0xbf, 0xbf, /* 10FFFF */ 0xdf, 0xbf, /* 7ff */ 0xbf, /* truncated tail */ - 0xf4, 0x90, 0x80, 0x80, /* 11FFFF */ + 0xf4, 0x90, 0x80, 0x80, /* 110000 */ 0x02 }; static const uint16_t utf8Expected[]={ 0x0061, - 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x0000, 0x0062, - 0xfffd, - 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xdbff, 0xdfff, 0x07ff, 0xfffd, - 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0x0002 }; static const int32_t utf8Offsets[]={ - 0, 1, 5, 6, 7, 12, 17, 17, 21, 23, 24, 28 + 0, + 1, 2, 3, 4, + 5, + 6, + 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, + 17, 17, + 21, + 23, + 24, 25, 26, 27, + 28 }; testConvertToU(utf8, sizeof(utf8), - utf8Expected, sizeof(utf8Expected)/sizeof(utf8Expected[0]), "utf-8", utf8Offsets ,FALSE); + utf8Expected, UPRV_LENGTHOF(utf8Expected), "utf-8", utf8Offsets ,FALSE); } @@ -1185,8 +1197,8 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) }; testConvertToU(utf32, sizeof(utf32), - utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), "utf-32be", utf32Offsets ,FALSE); - testConvertFromU(utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), + utf32Expected, UPRV_LENGTHOF(utf32Expected), "utf-32be", utf32Offsets ,FALSE); + testConvertFromU(utf32Expected, UPRV_LENGTHOF(utf32Expected), utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32be", utf32OffsetsBack, FALSE); } @@ -1238,8 +1250,8 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 8,8,8,8 }; testConvertToU(utf32, sizeof(utf32), - utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), "utf-32le", utf32Offsets,FALSE ); - testConvertFromU(utf32Expected, sizeof(utf32Expected)/sizeof(utf32Expected[0]), + utf32Expected, UPRV_LENGTHOF(utf32Expected), "utf-32le", utf32Offsets,FALSE ); + testConvertFromU(utf32Expected, UPRV_LENGTHOF(utf32Expected), utf32ExpectedBack, sizeof(utf32ExpectedBack), "utf-32le", utf32OffsetsBack, FALSE); } } @@ -1276,7 +1288,7 @@ static void TestCoverageMBCS(){ int32_t totest1Offs[] = { 0, 1, 2, 3, 5, }; /*from Unicode*/ - testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), + testConvertFromU(unicodeInput, UPRV_LENGTHOF(unicodeInput), expectedtest1, sizeof(expectedtest1), "@test1", totest1Offs,FALSE ); } @@ -1294,12 +1306,12 @@ static void TestCoverageMBCS(){ int32_t fromtest3Offs[] = { 0, 1, 2, 3, 6, 6, 7, 7, 10 }; /*from Unicode*/ - testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), + testConvertFromU(unicodeInput, UPRV_LENGTHOF(unicodeInput), expectedtest3, sizeof(expectedtest3), "@test3", totest3Offs,FALSE ); /*to Unicode*/ testConvertToU(test3input, sizeof(test3input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", fromtest3Offs ,FALSE); + expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test3", fromtest3Offs ,FALSE); } @@ -1317,12 +1329,12 @@ static void TestCoverageMBCS(){ static const int32_t fromtest4Offs[] = { 0, 1, 2, 3, 7, 7, 8, 8, 12,}; /*from Unicode*/ - testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), + testConvertFromU(unicodeInput, UPRV_LENGTHOF(unicodeInput), expectedtest4, sizeof(expectedtest4), "@test4", totest4Offs,FALSE ); /*to Unicode*/ testConvertToU(test4input, sizeof(test4input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", fromtest4Offs,FALSE ); + expectedUnicode, UPRV_LENGTHOF(expectedUnicode), "@test4", fromtest4Offs,FALSE ); } #if 0 @@ -1546,7 +1558,7 @@ static void TestAmbiguous() return; } /* convert target from SJIS to Unicode */ - sjisLength = ucnv_toUChars(sjis_cnv, sjisResult, sizeof(sjisResult)/U_SIZEOF_UCHAR, target, (int32_t)strlen(target), &status); + sjisLength = ucnv_toUChars(sjis_cnv, sjisResult, UPRV_LENGTHOF(sjisResult), target, (int32_t)strlen(target), &status); if (U_FAILURE(status)) { log_err("Failed to convert the SJIS string.\n"); @@ -1555,7 +1567,7 @@ static void TestAmbiguous() return; } /* convert target from Latin-1 to Unicode */ - /*asciiLength =*/ ucnv_toUChars(ascii_cnv, asciiResult, sizeof(asciiResult)/U_SIZEOF_UCHAR, target, (int32_t)strlen(target), &status); + /*asciiLength =*/ ucnv_toUChars(ascii_cnv, asciiResult, UPRV_LENGTHOF(asciiResult), target, (int32_t)strlen(target), &status); if (U_FAILURE(status)) { log_err("Failed to convert the Latin-1 string.\n"); @@ -1663,7 +1675,7 @@ TestSignatureDetection(){ int32_t signatureLength = -1; const char* source = NULL; const char* enc = NULL; - for( ; i