X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/fd0068a84e9996f225edba706498f6ed413d0673..9f1b115531acc2f3640893f76e8bcf6680033062:/icuSources/test/cintltst/nucnvtst.c diff --git a/icuSources/test/cintltst/nucnvtst.c b/icuSources/test/cintltst/nucnvtst.c index cab2975d..3366b669 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-2006,2008 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 @@ -17,18 +19,23 @@ #include "unicode/uloc.h" #include "unicode/ucnv.h" #include "unicode/ucnv_err.h" +#include "unicode/ucnv_cb.h" #include "cintltst.h" #include "unicode/utypes.h" #include "unicode/ustring.h" #include "unicode/ucol.h" +#include "unicode/utf16.h" #include "cmemory.h" +#include "nucnvtst.h" 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); @@ -49,6 +56,9 @@ static void TestLATIN1(void); static void TestSBCS(void); static void TestDBCS(void); static void TestMBCS(void); +#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO +static void TestICCRunout(void); +#endif #ifdef U_ENABLE_GENERIC_ISO_2022 static void TestISO_2022(void); @@ -60,7 +70,12 @@ static void TestISO_2022_JP_2(void); static void TestISO_2022_KR(void); static void TestISO_2022_KR_1(void); static void TestISO_2022_CN(void); +#if 0 + /* + * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 + */ static void TestISO_2022_CN_EXT(void); +#endif static void TestJIS(void); static void TestHZ(void); #endif @@ -73,15 +88,26 @@ static void TestGB18030(void); static void TestLMBCS(void); static void TestJitterbug255(void); static void TestEBCDICUS4XML(void); +#if 0 + /* + * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 + */ static void TestJitterbug915(void); +#endif static void TestISCII(void); static void TestCoverageMBCS(void); static void TestJitterbug2346(void); static void TestJitterbug2411(void); +static void TestJB5275(void); +static void TestJB5275_1(void); static void TestJitterbug6175(void); + +static void TestIsFixedWidth(void); #endif +static void TestInBufSizes(void); + static void TestRoundTrippingAllUTF(void); static void TestConv(const uint16_t in[], int len, @@ -89,7 +115,6 @@ static void TestConv(const uint16_t in[], const char* lang, char byteArr[], int byteArrLen); -void addTestNewConvert(TestNode** root); /* open a converter, using test data if it begins with '@' */ static UConverter *my_ucnv_open(const char *cnv, UErrorCode *err); @@ -224,8 +249,10 @@ static void TestOutBufSizes(void) void addTestNewConvert(TestNode** root) { +#if !UCONFIG_NO_FILE_IO addTest(root, &TestInBufSizes, "tsconv/nucnvtst/TestInBufSizes"); addTest(root, &TestOutBufSizes, "tsconv/nucnvtst/TestOutBufSizes"); +#endif addTest(root, &TestConverterTypesAndStarters, "tsconv/nucnvtst/TestConverterTypesAndStarters"); addTest(root, &TestAmbiguous, "tsconv/nucnvtst/TestAmbiguous"); addTest(root, &TestSignatureDetection, "tsconv/nucnvtst/TestSignatureDetection"); @@ -250,7 +277,10 @@ void addTestNewConvert(TestNode** root) #if !UCONFIG_NO_LEGACY_CONVERSION addTest(root, &TestSBCS, "tsconv/nucnvtst/TestSBCS"); +#if !UCONFIG_NO_FILE_IO addTest(root, &TestDBCS, "tsconv/nucnvtst/TestDBCS"); + addTest(root, &TestICCRunout, "tsconv/nucnvtst/TestICCRunout"); +#endif addTest(root, &TestMBCS, "tsconv/nucnvtst/TestMBCS"); #ifdef U_ENABLE_GENERIC_ISO_2022 @@ -264,8 +294,11 @@ void addTestNewConvert(TestNode** root) addTest(root, &TestISO_2022_KR, "tsconv/nucnvtst/TestISO_2022_KR"); addTest(root, &TestISO_2022_KR_1, "tsconv/nucnvtst/TestISO_2022_KR_1"); addTest(root, &TestISO_2022_CN, "tsconv/nucnvtst/TestISO_2022_CN"); + /* + * ICU 4.4 (ticket #7314) removes mappings for CNS 11643 planes 3..7 addTest(root, &TestISO_2022_CN_EXT, "tsconv/nucnvtst/TestISO_2022_CN_EXT"); addTest(root, &TestJitterbug915, "tsconv/nucnvtst/TestJitterbug915"); + */ addTest(root, &TestHZ, "tsconv/nucnvtst/TestHZ"); #endif @@ -277,7 +310,8 @@ void addTestNewConvert(TestNode** root) addTest(root, &TestJitterbug255, "tsconv/nucnvtst/TestJitterbug255"); addTest(root, &TestEBCDICUS4XML, "tsconv/nucnvtst/TestEBCDICUS4XML"); addTest(root, &TestISCII, "tsconv/nucnvtst/TestISCII"); - + addTest(root, &TestJB5275, "tsconv/nucnvtst/TestJB5275"); + addTest(root, &TestJB5275_1, "tsconv/nucnvtst/TestJB5275_1"); #if !UCONFIG_NO_COLLATION addTest(root, &TestJitterbug981, "tsconv/nucnvtst/TestJitterbug981"); #endif @@ -286,7 +320,7 @@ void addTestNewConvert(TestNode** root) #endif -#if !UCONFIG_NO_LEGACY_CONVERSION +#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_NO_FILE_IO addTest(root, &TestCoverageMBCS, "tsconv/nucnvtst/TestCoverageMBCS"); #endif @@ -296,6 +330,8 @@ void addTestNewConvert(TestNode** root) addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346"); addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411"); addTest(root, &TestJitterbug6175, "tsconv/nucnvtst/TestJitterbug6175"); + + addTest(root, &TestIsFixedWidth, "tsconv/nucnvtst/TestIsFixedWidth"); #endif } @@ -369,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; @@ -410,7 +446,7 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :", sourceLen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[9999]; char offset_str[9999]; @@ -436,9 +472,9 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, if(expectLen != targ-junkout) { log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName); log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName); - printf("\nGot:"); + fprintf(stderr, "Got:\n"); printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout)); - printf("\nExpected:"); + fprintf(stderr, "Expected:\n"); printSeqErr((const unsigned char*)expect, expectLen); return TC_MISMATCH; } @@ -469,9 +505,9 @@ static ETestConvertResult testConvertFromU( const UChar *source, int sourceLen, } else { log_err("String does not match u->%s\n", gNuConvTestName); printUSeqErr(source, sourceLen); - printf("\nGot:"); + fprintf(stderr, "Got:\n"); printSeqErr((const unsigned char *)junkout, expectLen); - printf("\nExpected:"); + fprintf(stderr, "Expected:\n"); printSeqErr((const unsigned char *)expect, expectLen); return TC_MISMATCH; @@ -527,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; @@ -571,7 +607,7 @@ static ETestConvertResult testConvertToU( const uint8_t *source, int sourcelen, log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :", sourcelen, targ-junkout); - if(VERBOSITY) + if(getTestOption(VERBOSITY_OPTION)) { char junk[9999]; char offset_str[9999]; @@ -649,15 +685,17 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) /** test chars #1 */ /* 1 2 3 1Han 2Han 3Han . */ static const UChar sampleText[] = - { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E }; + { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xD840, 0xDC21 }; + static const UChar sampleTextRoundTripUnmappable[] = + { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E, 0xfffd }; static const uint8_t expectedUTF8[] = - { 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E }; + { 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E, 0xf0, 0xa0, 0x80, 0xa1 }; static const int32_t toUTF8Offs[] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07}; + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07, 0x08, 0x08, 0x08, 0x08 }; static const int32_t fmUTF8Offs[] = - { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d }; + { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d, 0x000e, 0x000e }; #ifdef U_ENABLE_GENERIC_ISO_2022 /* Same as UTF8, but with ^[%B preceeding */ @@ -672,59 +710,59 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) /* 1 2 3 0, h1 h2 h3 . EBCDIC_STATEFUL */ static const uint8_t expectedIBM930[] = - { 0xF1, 0xF2, 0xF3, 0x00, 0x0E, 0x45, 0x41, 0x45, 0x42, 0x45, 0x43, 0x0F, 0x4B }; + { 0xF1, 0xF2, 0xF3, 0x00, 0x0E, 0x45, 0x41, 0x45, 0x42, 0x45, 0x43, 0x0F, 0x4B, 0x0e, 0xfe, 0xfe, 0x0f }; static const int32_t toIBM930Offs[] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, }; + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, -1 }; static const int32_t fmIBM930Offs[] = - { 0x0000, 0x0001, 0x0002, 0x0003, 0x0005, 0x0007, 0x0009, 0x000c}; + { 0x0000, 0x0001, 0x0002, 0x0003, 0x0005, 0x0007, 0x0009, 0x000c, 0x000e }; /* 1 2 3 0 h1 h2 h3 . MBCS*/ static const uint8_t expectedIBM943[] = - { 0x31, 0x32, 0x33, 0x00, 0x88, 0xea, 0x93, 0xf1, 0x8e, 0x4f, 0x2e }; + { 0x31, 0x32, 0x33, 0x00, 0x88, 0xea, 0x93, 0xf1, 0x8e, 0x4f, 0x2e, 0xfc, 0xfc }; static const int32_t toIBM943Offs [] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07 }; + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08 }; static const int32_t fmIBM943Offs[] = - { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0006, 0x0008, 0x000a}; + { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0006, 0x0008, 0x000a, 0x000b }; /* 1 2 3 0 h1 h2 h3 . DBCS*/ static const uint8_t expectedIBM9027[] = - { 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x4c, 0x41, 0x4c, 0x48, 0x4c, 0x55, 0xfe, 0xfe}; + { 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x4c, 0x41, 0x4c, 0x48, 0x4c, 0x55, 0xfe, 0xfe, 0xfe, 0xfe }; static const int32_t toIBM9027Offs [] = - { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07}; + { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08 }; /* 1 2 3 0 . SBCS*/ static const uint8_t expectedIBM920[] = - { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2e }; + { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2e, 0x1a }; static const int32_t toIBM920Offs [] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; /* 1 2 3 0 . SBCS*/ static const uint8_t expectedISO88593[] = - { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E }; + { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a }; static const int32_t toISO88593Offs[] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; /* 1 2 3 0 . LATIN_1*/ static const uint8_t expectedLATIN1[] = - { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E }; + { 0x31, 0x32, 0x33, 0x00, 0x1a, 0x1a, 0x1a, 0x2E, 0x1a }; static const int32_t toLATIN1Offs[] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; /* etc */ static const uint8_t expectedUTF16BE[] = - { 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x4e, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x00, 0x2e }; + { 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x4e, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x00, 0x2e, 0xd8, 0x40, 0xdc, 0x21 }; static const int32_t toUTF16BEOffs[]= - { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07}; + { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08 }; static const int32_t fmUTF16BEOffs[] = - { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e }; + { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010, 0x0010 }; static const uint8_t expectedUTF16LE[] = - { 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e, 0x2e, 0x00 }; + { 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x8c, 0x4e, 0x09, 0x4e, 0x2e, 0x00, 0x40, 0xd8, 0x21, 0xdc }; static const int32_t toUTF16LEOffs[]= - { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07}; + { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08 }; static const int32_t fmUTF16LEOffs[] = - { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e }; + { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010, 0x0010 }; static const uint8_t expectedUTF32BE[] = { 0x00, 0x00, 0x00, 0x31, @@ -734,7 +772,8 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x4e, 0x8c, 0x00, 0x00, 0x4e, 0x09, - 0x00, 0x00, 0x00, 0x2e }; + 0x00, 0x00, 0x00, 0x2e, + 0x00, 0x02, 0x00, 0x21 }; static const int32_t toUTF32BEOffs[]= { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, @@ -744,9 +783,10 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }; static const int32_t fmUTF32BEOffs[] = - { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c }; + { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0020 }; static const uint8_t expectedUTF32LE[] = { 0x31, 0x00, 0x00, 0x00, @@ -756,7 +796,8 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0x00, 0x4e, 0x00, 0x00, 0x8c, 0x4e, 0x00, 0x00, 0x09, 0x4e, 0x00, 0x00, - 0x2e, 0x00, 0x00, 0x00 }; + 0x2e, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x02, 0x00 }; static const int32_t toUTF32LEOffs[]= { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, @@ -766,9 +807,10 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }; static const int32_t fmUTF32LEOffs[] = - { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c }; + { 0x0000, 0x0004, 0x0008, 0x000c, 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0020 }; @@ -793,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"); @@ -804,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 ); @@ -812,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 @@ -861,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), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ibm-930", fmIBM930Offs,FALSE); + testConvertToU(expectedIBM930, sizeof(expectedIBM930), sampleTextRoundTripUnmappable, + UPRV_LENGTHOF(sampleTextRoundTripUnmappable), "ibm-930", fmIBM930Offs,FALSE); /*MBCS*/ - testConvertToU(expectedIBM943, sizeof(expectedIBM943), - sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ibm-943", fmIBM943Offs,FALSE); + testConvertToU(expectedIBM943, sizeof(expectedIBM943),sampleTextRoundTripUnmappable, + 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 */ @@ -916,12 +958,12 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) Hi Mom -+Jjo--! A+ImIDkQ. +- - +ZeVnLIqe + +ZeVnLIqe- */ 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x21, 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 0x2b, 0x2d, - 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65 + 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d }; static const UChar unicode[] = { /* @@ -945,7 +987,7 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 11, 12, 12, 12, 13, 13, 13, 13, 14, 15, 15, - 16, 16, 16, 17, 17, 17, 18, 18, 18 + 16, 16, 16, 17, 17, 17, 18, 18, 18, 18 }; /* same but escaping set O (the exclamation mark) */ @@ -954,12 +996,12 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) Hi Mom -+Jjo--+ACE- A+ImIDkQ. +- - +ZeVnLIqe + +ZeVnLIqe- */ 0x48, 0x69, 0x20, 0x4d, 0x6f, 0x6d, 0x20, 0x2d, 0x2b, 0x4a, 0x6a, 0x6f, 0x2d, 0x2d, 0x2b, 0x41, 0x43, 0x45, 0x2d, 0x41, 0x2b, 0x49, 0x6d, 0x49, 0x44, 0x6b, 0x51, 0x2e, 0x2b, 0x2d, - 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65 + 0x2b, 0x5a, 0x65, 0x56, 0x6e, 0x4c, 0x49, 0x71, 0x65, 0x2d }; static const int32_t toUnicodeOffsetsR[] = { 0, 1, 2, 3, 4, 5, 6, 7, 9, 13, 15, @@ -971,16 +1013,16 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 9, 10, 10, 10, 10, 10, 11, 12, 12, 12, 13, 13, 13, 13, 14, 15, 15, - 16, 16, 16, 17, 17, 17, 18, 18, 18 + 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); } /* @@ -1054,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*/ @@ -1093,7 +1135,7 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 0, 1, 5, 6, 7, 12, 17, 17, 21, 23, 24, 28 }; testConvertToU(utf8, sizeof(utf8), - utf8Expected, sizeof(utf8Expected)/sizeof(utf8Expected[0]), "utf-8", utf8Offsets ,FALSE); + utf8Expected, UPRV_LENGTHOF(utf8Expected), "utf-8", utf8Offsets ,FALSE); } @@ -1145,8 +1187,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); } @@ -1198,8 +1240,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); } } @@ -1236,7 +1278,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 ); } @@ -1254,12 +1296,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); } @@ -1277,12 +1319,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 @@ -1416,7 +1458,7 @@ static void TestConverterTypesAndStarters() static void TestAmbiguousConverter(UConverter *cnv) { - static const char inBytes[2]={ 0x61, 0x5c }; + static const char inBytes[3]={ 0x61, 0x5B, 0x5c }; UChar outUnicode[20]={ 0, 0, 0, 0 }; const char *s; @@ -1424,34 +1466,36 @@ TestAmbiguousConverter(UConverter *cnv) { UErrorCode errorCode; UBool isAmbiguous; - /* try to convert an 'a' and a US-ASCII backslash */ + /* try to convert an 'a', a square bracket and a US-ASCII backslash */ errorCode=U_ZERO_ERROR; s=inBytes; u=outUnicode; - ucnv_toUnicode(cnv, &u, u+20, &s, s+2, NULL, TRUE, &errorCode); + ucnv_toUnicode(cnv, &u, u+20, &s, s+3, NULL, TRUE, &errorCode); if(U_FAILURE(errorCode)) { /* we do not care about general failures in this test; the input may just not be mappable */ return; } - if(outUnicode[0]!=0x61 || outUnicode[1]==0xfffd) { - /* not an ASCII-family encoding, or 0x5c is unassigned/illegal: this test is not applicable */ + if(outUnicode[0]!=0x61 || outUnicode[1]!=0x5B || outUnicode[2]==0xfffd) { + /* not a close ASCII-family encoding, or 0x5c is unassigned/illegal: this test is not applicable */ + /* There are some encodings that are partially ASCII based, + like the ISO-7 and GSM series of codepages, which we ignore. */ return; } isAmbiguous=ucnv_isAmbiguous(cnv); /* check that outUnicode[1]!=0x5c is exactly the same as ucnv_isAmbiguous() */ - if((outUnicode[1]!=0x5c)!=isAmbiguous) { + if((outUnicode[2]!=0x5c)!=isAmbiguous) { log_err("error: converter \"%s\" needs a backslash fix: %d but ucnv_isAmbiguous()==%d\n", - ucnv_getName(cnv, &errorCode), outUnicode[1]!=0x5c, isAmbiguous); + ucnv_getName(cnv, &errorCode), outUnicode[2]!=0x5c, isAmbiguous); return; } - if(outUnicode[1]!=0x5c) { + if(outUnicode[2]!=0x5c) { /* needs fixup, fix it */ ucnv_fixFileSeparator(cnv, outUnicode, (int32_t)(u-outUnicode)); - if(outUnicode[1]!=0x5c) { + if(outUnicode[2]!=0x5c) { /* the fix failed */ log_err("error: ucnv_fixFileSeparator(%s) failed\n", ucnv_getName(cnv, &errorCode)); return; @@ -1473,7 +1517,7 @@ static void TestAmbiguous() 0 }; UChar asciiResult[200], sjisResult[200]; - int32_t asciiLength = 0, sjisLength = 0, i; + int32_t /*asciiLength = 0,*/ sjisLength = 0, i; const char *name; /* enumerate all converters */ @@ -1504,7 +1548,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"); @@ -1513,11 +1557,10 @@ 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"); - free(sjisResult); ucnv_close(sjis_cnv); ucnv_close(ascii_cnv); return; @@ -1525,8 +1568,6 @@ static void TestAmbiguous() if (!ucnv_isAmbiguous(sjis_cnv)) { log_err("SJIS converter should contain ambiguous character mappings.\n"); - free(sjisResult); - free(asciiResult); ucnv_close(sjis_cnv); ucnv_close(ascii_cnv); return; @@ -1624,7 +1665,7 @@ TestSignatureDetection(){ int32_t signatureLength = -1; const char* source = NULL; const char* enc = NULL; - for( ; i0xFFFF){ - dst[dstIndex++] = UTF16_LEAD(c); + dst[dstIndex++] = U16_LEAD(c); if(dstIndex UCNV_IRREGULAR) + if (reason > UCNV_IRREGULAR) { return; - if (reason != UCNV_IRREGULAR) + } + if (reason != UCNV_IRREGULAR) { log_err("toUnicode callback invoked for empty segment but reason is not UCNV_IRREGULAR\n"); + } /* Standard stuff below from UCNV_TO_U_CALLBACK_SUBSTITUTE */ *err = U_ZERO_ERROR; ucnv_cbToUWriteSub(toArgs,0,err); @@ -4802,14 +4910,14 @@ TestLMBCS() { UChar Out [sizeof(pszUnicode) + 1]; UChar * pOut = Out; - UChar * OutLimit = Out + sizeof(pszUnicode)/sizeof(UChar); + UChar * OutLimit = Out + UPRV_LENGTHOF(pszUnicode); int32_t off [sizeof(offsets)]; /* last 'offset' in expected results is just the final size. (Makes other tests easier). Compensate here: */ - off[(sizeof(offsets)/sizeof(offsets[0]))-1] = sizeof(pszLMBCS); + off[UPRV_LENGTHOF(offsets)-1] = sizeof(pszLMBCS); @@ -4892,8 +5000,8 @@ TestLMBCS() { /* 0192 (hook) converts to both group 3 & group 1. input locale should differentiate */ ucnv_fromUnicode (cnv16he, - &pLMBCSIn, (pLMBCSIn + sizeof(lmbcsString)/sizeof(lmbcsString[0])), - &pUniOut, pUniOut + sizeof(uniString)/sizeof(uniString[0]), + &pLMBCSIn, (pLMBCSIn + UPRV_LENGTHOF(lmbcsString)), + &pUniOut, pUniOut + UPRV_LENGTHOF(uniString), NULL, 1, &errorCode); if (lmbcsString[0] != 0x3 || lmbcsString[1] != 0x83) @@ -4904,8 +5012,8 @@ TestLMBCS() { pLMBCSIn= (char *)lmbcsString; pUniOut = uniString; ucnv_fromUnicode (cnv01us, - &pLMBCSIn, (const char *)(lmbcsString + sizeof(lmbcsString)/sizeof(lmbcsString[0])), - &pUniOut, pUniOut + sizeof(uniString)/sizeof(uniString[0]), + &pLMBCSIn, (const char *)(lmbcsString + UPRV_LENGTHOF(lmbcsString)), + &pUniOut, pUniOut + UPRV_LENGTHOF(uniString), NULL, 1, &errorCode); if (lmbcsString[0] != 0x9F) @@ -4972,7 +5080,7 @@ TestLMBCS() { UChar Out [sizeof(pszUnicode) + 1]; UChar * pOut = Out; - UChar * OutLimit = Out + sizeof(pszUnicode)/sizeof(UChar); + UChar * OutLimit = Out + UPRV_LENGTHOF(pszUnicode); cnv = ucnv_open(NAME_LMBCS_1, &errorCode); @@ -5033,11 +5141,14 @@ TestLMBCS() { errorCode=U_ZERO_ERROR; /* negative source request should always return U_ILLEGAL_ARGUMENT_ERROR */ - ucnv_fromUnicode(cnv, &pLOut,pLOut+1,&pUIn,pUIn-1,off,FALSE, &errorCode); + pUIn++; + ucnv_fromUnicode(cnv, &pLOut, pLOut+1, &pUIn, pUIn-1, off, FALSE, &errorCode); if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) { log_err("Unexpected Error on negative source request to ucnv_fromUnicode: %s\n", u_errorName(errorCode)); } + pUIn--; + errorCode=U_ZERO_ERROR; ucnv_toUnicode(cnv, &pUOut,pUOut+1,(const char **)&pLIn,(const char *)(pLIn-1),off,FALSE, &errorCode); if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) @@ -5078,7 +5189,7 @@ TestLMBCS() { /* running out of target room : U_BUFFER_OVERFLOW_ERROR */ pUIn = pszUnicode; - ucnv_fromUnicode(cnv, &pLOut,pLOut+offsets[4],&pUIn,pUIn+sizeof(pszUnicode)/sizeof(UChar),off,FALSE, &errorCode); + ucnv_fromUnicode(cnv, &pLOut,pLOut+offsets[4],&pUIn,pUIn+UPRV_LENGTHOF(pszUnicode),off,FALSE, &errorCode); if (errorCode != U_BUFFER_OVERFLOW_ERROR || pLOut != LOut + offsets[4] || pUIn != pszUnicode+4 ) { log_err("Unexpected results on out of target room to ucnv_fromUnicode\n"); @@ -5106,7 +5217,7 @@ TestLMBCS() { pUOut = UOut; ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode); - ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode); + ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode); if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5) { log_err("Unexpected results on chopped low surrogate\n"); @@ -5120,7 +5231,7 @@ TestLMBCS() { errorCode = U_ZERO_ERROR; pUOut = UOut; - ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+3),off,TRUE, &errorCode); + ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+3),off,TRUE, &errorCode); if (UOut[0] != 0xD801 || U_FAILURE(errorCode) || pUOut != UOut + 1 || pLIn != LIn + 3) { log_err("Unexpected results on chopped at surrogate boundary \n"); @@ -5137,7 +5248,7 @@ TestLMBCS() { errorCode = U_ZERO_ERROR; pUOut = UOut; - ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+6),off,TRUE, &errorCode); + ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+6),off,TRUE, &errorCode); if (UOut[0] != 0xD801 || UOut[1] != 0xC9D0 || U_FAILURE(errorCode) || pUOut != UOut + 2 || pLIn != LIn + 6) { log_err("Unexpected results after unpaired surrogate plus valid Unichar \n"); @@ -5154,7 +5265,7 @@ TestLMBCS() { errorCode = U_ZERO_ERROR; pUOut = UOut; - ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode); + ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode); if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5) { log_err("Unexpected results after unpaired surrogate plus chopped Unichar \n"); @@ -5171,7 +5282,7 @@ TestLMBCS() { errorCode = U_ZERO_ERROR; pUOut = UOut; - ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode); + ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode); if (UOut[0] != 0xD801 || UOut[1] != 0x1B || U_FAILURE(errorCode) || pUOut != UOut + 2 || pLIn != LIn + 5) { log_err("Unexpected results after unpaired surrogate plus valid non-Unichar\n"); @@ -5187,7 +5298,7 @@ TestLMBCS() { errorCode = U_ZERO_ERROR; pUOut = UOut; - ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+4),off,TRUE, &errorCode); + ucnv_toUnicode(cnv, &pUOut,pUOut+UPRV_LENGTHOF(UOut),(const char **)&pLIn,(const char *)(pLIn+4),off,TRUE, &errorCode); if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 4) { @@ -5205,7 +5316,7 @@ static void TestJitterbug255() const char *testBuffer = (const char *)testBytes; const char *testEnd = (const char *)testBytes + sizeof(testBytes); UErrorCode status = U_ZERO_ERROR; - UChar32 result; + /*UChar32 result;*/ UConverter *cnv = 0; cnv = ucnv_open("shift-jis", &status); @@ -5215,7 +5326,7 @@ static void TestJitterbug255() } while (testBuffer != testEnd) { - result = ucnv_getNextUChar (cnv, &testBuffer, testEnd , &status); + /*result = */ucnv_getNextUChar (cnv, &testBuffer, testEnd , &status); if (U_FAILURE(status)) { log_err("Failed to convert the next UChar for SJIS.\n"); @@ -5275,16 +5386,23 @@ static void TestJitterbug981(){ int numNeeded=0; utf8cnv = ucnv_open ("utf8", &status); if(U_FAILURE(status)){ - log_err("Could not open UTF-8 converter. Error: %s", u_errorName(status)); + log_err("Could not open UTF-8 converter. Error: %s\n", u_errorName(status)); return; } myCollator = ucol_open("zh", &status); if(U_FAILURE(status)){ - log_err("Could not open collator for zh locale. Error: %s", u_errorName(status)); + log_data_err("Could not open collator for zh locale. Error: %s\n", u_errorName(status)); + ucnv_close(utf8cnv); return; } rules = ucol_getRules(myCollator, &rules_length); + if(rules_length == 0) { + log_data_err("missing zh tailoring rule string\n"); + ucol_close(myCollator); + ucnv_close(utf8cnv); + return; + } buff_size = rules_length * ucnv_getMaxCharSize(utf8cnv); buff = malloc(buff_size); @@ -5294,13 +5412,14 @@ static void TestJitterbug981(){ status = U_ZERO_ERROR; if(target_cap >= buff_size) { log_err("wanted %d bytes, only %d available\n", target_cap, buff_size); - return; + break; } bytes_needed = ucnv_fromUChars(utf8cnv, buff, target_cap, rules, rules_length, &status); target_cap = (bytes_needed > target_cap) ? bytes_needed : target_cap +1; if(numNeeded!=0 && numNeeded!= bytes_needed){ log_err("ucnv_fromUChars returns different values for required capacity in pre-flight and conversion modes"); + break; } numNeeded = bytes_needed; } while (status == U_BUFFER_OVERFLOW_ERROR); @@ -5311,6 +5430,7 @@ static void TestJitterbug981(){ #endif +#if !UCONFIG_NO_LEGACY_CONVERSION static void TestJitterbug1293(){ static const UChar src[] = {0x30DE, 0x30A4, 0x5E83, 0x544A, 0x30BF, 0x30A4, 0x30D7,0x000}; char target[256]; @@ -5338,4 +5458,146 @@ static void TestJitterbug1293(){ } ucnv_close(conv); } +#endif + +static void TestJB5275_1(){ + + static const char* data = "\x3B\xB3\x0A" /* Easy characters */ + "\xC0\xE9\xBF\xE9\xE8\xD8\x0A" /* Gurmukhi test */ + /* Switch script: */ + "\xEF\x43\xC0\xE9\xBF\xE9\xE8\xD8\x0A" /* Bengali test */ + "\x3B\xB3\x0A" /* Easy characters - new line, so should default!*/ + "\xEF\x40\x3B\xB3\x0A"; + static const UChar expected[] ={ + 0x003b, 0x0a15, 0x000a, /* Easy characters */ + 0x0a5c, 0x0a4d, 0x0a39, 0x0a5c, 0x0a4d, 0x0a39, 0x000a, /* Gurmukhi test */ + 0x09dd, 0x09dc, 0x09cd, 0x09b9, 0x000a, /* Switch script: to Bengali*/ + 0x003b, 0x0a15, 0x000a, /* Easy characters - new line, so should default!*/ + 0x003b, 0x0a15, 0x000a /* Back to Gurmukhi*/ + }; + + UErrorCode status = U_ZERO_ERROR; + UConverter* conv = ucnv_open("iscii-gur", &status); + UChar dest[100] = {'\0'}; + UChar* target = dest; + UChar* targetLimit = dest+100; + const char* source = data; + const char* sourceLimit = data+strlen(data); + const UChar* exp = expected; + + if (U_FAILURE(status)) { + log_data_err("Unable to open converter: iscii-gur got errorCode: %s\n", u_errorName(status)); + return; + } + + log_verbose("Testing switching back to default script when new line is encountered.\n"); + ucnv_toUnicode(conv, &target, targetLimit, &source, sourceLimit, NULL, TRUE, &status); + if(U_FAILURE(status)){ + log_err("conversion failed: %s \n", u_errorName(status)); + } + targetLimit = target; + target = dest; + printUSeq(target, targetLimit-target); + while(target