diff --git a/icu4c/source/test/cintltst/nccbtst.c b/icu4c/source/test/cintltst/nccbtst.c index 2da83a33c7..37e81b6a8d 100644 --- a/icu4c/source/test/cintltst/nccbtst.c +++ b/icu4c/source/test/cintltst/nccbtst.c @@ -172,7 +172,10 @@ static void TestSkip(int32_t inputsize, int32_t outputsize) gInBufferSize = inputsize; gOutBufferSize = outputsize; + /*From Unicode*/ + log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SKIP \n"); + if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expskipIBM_949, sizeof(expskipIBM_949), "ibm-949", (UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, toIBM949Offsskip, NULL, 0 )) @@ -186,7 +189,46 @@ static void TestSkip(int32_t inputsize, int32_t outputsize) (UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, toIBM930Offsskip , NULL, 0)) log_err("u-> ibm-930 with skip did not match.\n"); - log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SKIP \n"); + { + static const UChar usasciiFromU[] = { 0x61, 0x80, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 }; + static const uint8_t usasciiFromUBytes[] = { 0x61, 0x31, 0x39 }; + static const int32_t usasciiFromUOffsets[] = { 0, 3, 6 }; + + static const UChar latin1FromU[] = { 0x61, 0x80, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 }; + static const uint8_t latin1FromUBytes[] = { 0x61, 0x80, 0x31, 0x39 }; + static const int32_t latin1FromUOffsets[] = { 0, 1, 3, 6 }; + + /* US-ASCII */ + if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR, + usasciiFromUBytes, sizeof(usasciiFromUBytes), + "US-ASCII", + UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets, + NULL, 0) + ) { + log_err("u->US-ASCII with skip did not match.\n"); + } + + /* SBCS NLTC codepage 367 for US-ASCII */ + if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR, + usasciiFromUBytes, sizeof(usasciiFromUBytes), + "ibm-367", + UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets, + NULL, 0) + ) { + log_err("u->ibm-367 with skip did not match.\n"); + } + + /* ISO-Latin-1 */ + if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR, + latin1FromUBytes, sizeof(latin1FromUBytes), + "LATIN_1", + UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets, + NULL, 0) + ) { + log_err("u->LATIN_1 with skip did not match.\n"); + } + } + { UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 }; const uint8_t toIBM943[]= { 0x61, 0x61 }; @@ -301,6 +343,8 @@ static void TestSkip(int32_t inputsize, int32_t outputsize) } /*to Unicode*/ + log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SKIP \n"); + if(!testConvertToUnicode(expskipIBM_949, sizeof(expskipIBM_949), IBM_949skiptoUnicode, sizeof(IBM_949skiptoUnicode)/sizeof(IBM_949skiptoUnicode),"ibm-949", (UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, fromIBM949Offs, NULL, 0 )) @@ -315,9 +359,47 @@ static void TestSkip(int32_t inputsize, int32_t outputsize) (UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, fromIBM930Offs, NULL, 0 )) log_err("ibm-930->u with skip did not match.\n"); - log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SKIP \n"); { - + static const uint8_t usasciiToUBytes[] = { 0x61, 0x80, 0x31 }; + static const UChar usasciiToU[] = { 0x61, 0x31 }; + static const int32_t usasciiToUOffsets[] = { 0, 2 }; + + static const uint8_t latin1ToUBytes[] = { 0x61, 0x80, 0x31 }; + static const UChar latin1ToU[] = { 0x61, 0x80, 0x31 }; + static const int32_t latin1ToUOffsets[] = { 0, 1, 2 }; + + /* US-ASCII */ + if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes), + usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR, + "US-ASCII", + UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets, + NULL, 0) + ) { + log_err("US-ASCII->u with skip did not match.\n"); + } + + /* SBCS NLTC codepage 367 for US-ASCII */ + if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes), + usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR, + "ibm-367", + UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets, + NULL, 0) + ) { + log_err("ibm-367->u with skip did not match.\n"); + } + + /* ISO-Latin-1 */ + if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes), + latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR, + "LATIN_1", + UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets, + NULL, 0) + ) { + log_err("LATIN_1->u with skip did not match.\n"); + } + } + + { const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={ 0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44 }; @@ -1432,39 +1514,13 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen, const uint8_t checkOffsets ? offs : NULL, doFlush, /* flush if we're at the end of the input data */ &status); - - /*check for an INVALID character for testing the call back function STOP*/ - if(status == U_INVALID_CHAR_FOUND || status == U_ILLEGAL_CHAR_FOUND ) - { - junk[0] = 0; - offset_str[0] = 0; - for(p = junkout;p