ICU-703 Added more tests for ISO 2022 converters

X-SVN-Rev: 2887
This commit is contained in:
Ram Viswanadha 2000-11-08 23:15:12 +00:00
parent 93097aa9f4
commit f7a4b0a4ea
3 changed files with 504 additions and 6 deletions

View File

@ -198,6 +198,60 @@ void TestSkip(int32_t inputsize, int32_t outputsize)
};
int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 6, 7, 7, 8,};
/*ISO-2022-JP*/
UChar iso_2022_jp_inputText[]={0x0041, 0x00E9, 0x0042, };
const uint8_t to_iso_2022_jp[]={
0x1b, 0x28, 0x42, 0x41,
0x1b, 0x28, 0x42,
0x42,
};
int32_t from_iso_2022_jpOffs [] ={0,0,0,0,2,2,2,2};
/*ISO-2022-cn*/
UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
const uint8_t to_iso_2022_cn[]={
0x0F, 0x41,
0x0F, 0x42,
};
int32_t from_iso_2022_cnOffs [] ={
0,0,
2,2,
};
/*ISO-2022-kr*/
UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
const uint8_t to_iso_2022_kr[]={
0x1b, 0x24, 0x29, 0x43,
0x41,
0x0e, 0x25, 0x50,
0x0e, 0x25, 0x50,
0x0f, 0x42,
};
int32_t from_iso_2022_krOffs [] ={
-1,-1,-1,-1,
0,1,1,1,
3,3,3,
4,4
};
/* HZ encoding */
UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
const uint8_t to_hz[]={
0x7e, 0x7d, 0x41,
0x7e, 0x7b, 0x26, 0x30,
0x7e, 0x7b, 0x26, 0x30,
0x7e, 0x7d, 0x42,
};
int32_t from_hzOffs [] ={
0,0,0,
1,1,1,1,
3,3,3,3,
4,4,4,4
};
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
toIBM943, sizeof(toIBM943), "ibm-943",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, offset, NULL, 0 ))
@ -212,6 +266,27 @@ void TestSkip(int32_t inputsize, int32_t outputsize)
to_euc_tw, sizeof(to_euc_tw), "euc-tw",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, from_euc_twOffs, NULL, 0 ))
log_err("u-> euc-tw with skip did not match.\n");
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs, NULL, 0 ))
log_err("u-> iso-2022-jp with skip did not match.\n");
if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs, NULL, 0 ))
log_err("u-> iso-2022-cn with skip did not match.\n");
if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs, NULL, 0 ))
log_err("u-> iso-2022-kr with skip did not match.\n");
if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
to_hz, sizeof(to_hz), "HZ",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs, NULL, 0 ))
log_err("u-> HZ with skip did not match.\n");
}
@ -256,6 +331,58 @@ void TestSkip(int32_t inputsize, int32_t outputsize)
};
UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2, 0x8706, 0x8a, };
int32_t from_euc_twOffs [] ={ 0, 1, 3, 11, 13};
/*iso-2022-jp*/
const uint8_t sampleTxt_iso_2022_jp[]={
0x1b, 0x28, 0x42, 0x41,
0x1b, 0x24, 0x42, 0x2A, 0x44, /*unassigned*/
0x1b, 0x28, 0x42, 0x42,
};
UChar iso_2022_jptoUnicode[]={ 0x41,0x42 };
int32_t from_iso_2022_jpOffs [] ={ 3,12 };
/*iso-2022-cn*/
const uint8_t sampleTxt_iso_2022_cn[]={
0x0f, 0x41, 0x44,
0x1B, 0x24, 0x29, 0x47,
0x0E, 0x40, 0x6c, /*unassigned*/
0x0f, 0x42,
};
UChar iso_2022_cntoUnicode[]={ 0x41, 0x44,0x42 };
int32_t from_iso_2022_cnOffs [] ={ 1, 2, 11 };
/*iso-2022-kr*/
const uint8_t sampleTxt_iso_2022_kr[]={
0x1b, 0x24, 0x29, 0x43,
0x41,
0x0E, 0x7f, 0x1E,
0x0e, 0x25, 0x50,
0x0f, 0x51,
0x42, 0x43,
};
UChar iso_2022_krtoUnicode[]={ 0x41,0x03A0,0x51, 0x42,0x43};
int32_t from_iso_2022_krOffs [] ={ 4, 9, 12, 13 , 14 };
/*hz*/
const uint8_t sampleTxt_hz[]={
0x41,
0x7e, 0x7b, 0x26, 0x30,
0x7f, 0x1E, /*unassigned*/
0x26, 0x30,
0x7e, 0x7d, 0x42,
0x7e, 0x7b, 0x7f, 0x1E,/*unassigned*/
0x7e, 0x7d, 0x42,
};
UChar hztoUnicode[]={
0x41,
0x03a0,
0x03A0,
0x42,
0x42,};
int32_t from_hzOffs [] ={0,3,7,11,18, };
/*LMBCS*/
const uint8_t sampleTxtLMBCS[]={ 0x12, 0xc9, 0x50,
@ -284,6 +411,27 @@ void TestSkip(int32_t inputsize, int32_t outputsize)
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, from_euc_twOffs , NULL, 0))
log_err("euc-tw->u with skip did not match.\n");
if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_jpOffs , NULL, 0))
log_err("iso-2022-jp->u with skip did not match.\n");
if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_cnOffs , NULL, 0))
log_err("iso-2022-cn->u with skip did not match.\n");
if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_krOffs , NULL, 0))
log_err("iso-2022-kr->u with skip did not match.\n");
if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, from_hzOffs , NULL, 0))
log_err("HZ->u with skip did not match.\n");
if(/* broken for icu 1.6 and 1.6.0.1, do not test */uprv_strcmp("1.6.0.1", U_ICU_VERSION) != 0 && !testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS-1",
(UConverterToUCallback)UCNV_TO_U_CALLBACK_SKIP, fromLMBCS , NULL, 0))
@ -363,6 +511,51 @@ void TestStop(int32_t inputsize, int32_t outputsize)
const uint8_t to_euc_tw[]={
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,};
int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2,};
/*ISO-2022-JP*/
UChar iso_2022_jp_inputText[]={0x0041, 0x00E9, 0x0042, };
const uint8_t to_iso_2022_jp[]={
0x1b, 0x28, 0x42, 0x41,
};
int32_t from_iso_2022_jpOffs [] ={0,0,0,0,2,2,2,2};
/*ISO-2022-cn*/
UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
const uint8_t to_iso_2022_cn[]={
0x0F, 0x41,
};
int32_t from_iso_2022_cnOffs [] ={
0,0,
2,2,
};
/*ISO-2022-kr*/
UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
const uint8_t to_iso_2022_kr[]={
0x1b, 0x24, 0x29, 0x43,
0x41,
0x0e, 0x25, 0x50,
};
int32_t from_iso_2022_krOffs [] ={
-1,-1,-1,-1,
0,1,1,1,
};
/* HZ encoding */
UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
const uint8_t to_hz[]={
0x7e, 0x7d, 0x41,
0x7e, 0x7b, 0x26, 0x30,
};
int32_t from_hzOffs [] ={
0, 0,0,
1,1,1,1,
};
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
toIBM943, sizeof(toIBM943), "ibm-943",
@ -379,6 +572,32 @@ void TestStop(int32_t inputsize, int32_t outputsize)
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
log_err("u-> euc-tw with stop did not match.\n");
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
log_err("u-> iso-2022-jp with stop did not match.\n");
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
log_err("u-> iso-2022-jp with stop did not match.\n");
if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_cnOffs, NULL, 0 ))
log_err("u-> iso-2022-cn with stop did not match.\n");
if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_krOffs, NULL, 0 ))
log_err("u-> iso-2022-kr with stop did not match.\n");
if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
to_hz, sizeof(to_hz), "HZ",
(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP, from_hzOffs, NULL, 0 ))
log_err("u-> HZ with stop did not match.\n");
}
log_verbose("Testing fromUnicode for UTF-8 with UCNV_FROM_U_CALLBACK_STOP \n");
{
@ -655,6 +874,7 @@ void TestSub(int32_t inputsize, int32_t outputsize)
log_err("gb18030->u with substitute did not match.\n");
}
}
}
void TestSubWithValue(int32_t inputsize, int32_t outputsize)
@ -784,7 +1004,7 @@ void TestSubWithValue(int32_t inputsize, int32_t outputsize)
UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
const uint8_t to_hz[]={
0x41,
0x7e, 0x7d, 0x41,
0x7e, 0x7b, 0x26, 0x30,
0x7e, 0x7d, 0x25, 0x55, 0x30, 0x36, 0x36, 0x32, /*unassigned*/
0x7e, 0x7b, 0x26, 0x30,
@ -792,11 +1012,11 @@ void TestSubWithValue(int32_t inputsize, int32_t outputsize)
};
int32_t from_hzOffs [] ={
0,
0,0,0,
1,1,1,1,
2,2,2,2,2,2,2,2,
3,3,3,3,
4,4,4,4,
4,4,4
};
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
@ -907,7 +1127,7 @@ void TestSubWithValue(int32_t inputsize, int32_t outputsize)
UChar iso_2022_krtoUnicode[]={ 0x41,0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,0x03A0,0x51, 0x42,0x43};
int32_t from_iso_2022_krOffs [] ={ 4, 6, 6, 6, 6, 6, 6, 6, 6, 9, 12, 13 , 14 };
/*iso-2022-kr*/
/*hz*/
const uint8_t sampleTxt_hz[]={
0x41,
0x7e, 0x7b, 0x26, 0x30,

View File

@ -151,6 +151,85 @@ void TestSurrogateBehaviour(){
expected, sizeof(expected), "ibm-1363", offsets2 , TRUE, U_ZERO_ERROR))
log_err("u-> ibm-1363 [UCNV_MBCS] not match.\n");
}
log_verbose("Testing for ISO-2022-jp\n");
{
UChar sampleText[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
const uint8_t expected[] = {0x1b, 0x24, 0x42,0x30,0x6c,0x43,0x7a,0x1b,0x28,0x42,
0x31,0x1b,0x28,0x42,0x1A,0x1b,0x28,0x42, 0x32};
int32_t offsets[] = {0,0,0,0,0,1,1,2,2,2,2,3,3,3,3,5,5,5,5 };
/*iso-2022-jp*/
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-jp", 0 , TRUE, U_ZERO_ERROR))
log_err("u-> not match.\n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-jp", offsets , TRUE, U_ZERO_ERROR))
log_err("u-> not match.\n");
}
log_verbose("Testing for ISO-2022-cn\n");
{
UChar sampleText[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
const uint8_t expected[] = {
0x1B, 0x24, 0x29, 0x41, 0x0E, 0x52, 0x3B,
0x36, 0x21,
0x1B, 0x24, 0x29, 0x47, 0x1B, 0x4E, 0x24, 0x22,
0x0f, 0x1A,
0x1B, 0x24, 0x29, 0x47, 0x1B, 0x4E, 0x24, 0x23
};
int32_t offsets[] = {
0, 0, 0, 0, 0, 0, 0,
1, 1,
2, 2, 2, 2, 2, 2, 2, 2,
3, 3,
5, 5, 5, 5, 5, 5, 5, 5 };
/*iso-2022-jp*/
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-cn", 0 , TRUE, U_ZERO_ERROR))
log_err("u-> not match.\n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-cn", offsets , TRUE, U_ZERO_ERROR))
log_err("u-> not match.\n");
}
log_verbose("Testing for ISO-2022-kr\n");
{
UChar sampleText[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
const uint8_t expected[] = {0x1B, 0x24, 0x29, 0x43, 0x0E, 0x6C, 0x69, 0x6F, 0x4B, 0x0F, 0x31,0x0f, 0x1A, 0x0F, 0x32 };
int32_t offsets[] = {-1,-1,-1,-1,0,0,0,1,1,2,2,3,3,5,5 };
/*iso-2022-jp*/
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-kr", 0 , TRUE, U_ZERO_ERROR))
log_err("u-> ibm-1362 [UCNV_DBCS] not match.\n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-kr", offsets , TRUE, U_ZERO_ERROR))
log_err("u-> ibm-1362 [UCNV_DBCS] not match.\n");
}
log_verbose("Testing for HZ\n");
{
UChar sampleText[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
const uint8_t expected[] = {0x7E ,0x7B, 0x52, 0x3B, 0x36, 0x21, 0x7E, 0x7D, 0x31,0x7E, 0x7D, 0x1A,0x7E, 0x7D,0x32 };
int32_t offsets[] = {0,0,0,0,1,1,2,2,2,3,3,3,5,5,5};
/*iso-2022-jp*/
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "HZ", 0 , TRUE, U_ZERO_ERROR))
log_err("u-> not match.\n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "HZ", offsets , TRUE, U_ZERO_ERROR))
log_err("u-> not match.\n");
}
/*UTF-8*/
log_verbose("Testing for UTF8\n");
{
@ -233,6 +312,8 @@ void TestErrorBehaviour(){
#endif
}
log_verbose("Testing for DBCS and MBCS\n");
{
UChar sampleText[] = { 0x00a1, 0xd801};
@ -305,6 +386,203 @@ void TestErrorBehaviour(){
expected4MBCS, sizeof(expected4MBCS), "euc-jp", offsets4MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> euc-jp [UCNV_MBCS] \n");
}
/*iso-2022-jp*/
log_verbose("Testing for iso-2022-jp\n");
{
UChar sampleText[] = { 0x0031, 0xd801};
const uint8_t expected[] = { 0x1b,0x28,0x42, 0x31};
int32_t offsets[] = { 0x00, 0x00, 0x00, 0x00};
UChar sampleText2[] = { 0x0031, 0xd801, 0x0032};
const uint8_t expected2[] = { 0x1b,0x28,0x42, 0x31, 0x1b,0x28,0x42,0x1A,0x1b,0x28,0x42,0x32};
int32_t offsets2[] = { 0x00, 0x00, 0x00, 0x00, 0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02};
UChar sampleText3MBCS[] = { 0x0051, 0x0050, 0xdc01};
const uint8_t expected3MBCS[] = {0x1b,0x28,0x42, 0x51, 0x50,0x1b,0x28,0x42,0x1A};
int32_t offsets3MBCS[] = { 0x00, 0x00, 0x00, 0x00, 0x01,0x02,0x02,0x02,0x02 };
UChar sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01};
const uint8_t expected4MBCS[] = {0x1b,0x28,0x42, 0x61,0x1b,0x24,0x42, 0x30, 0x6c,0x1b,0x28,0x42,0x1a};
int32_t offsets4MBCS[] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01 ,0x01,0x01,0x01,0x02,0x02,0x02,0x02 };
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-jp", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-jp", 0, FALSE, U_ZERO_ERROR))
log_err("u-> ibm-1363 [UCNV_MBCS] \n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-jp", 0, TRUE, U_ZERO_ERROR))
log_err("u->iso-2022-jp[UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-jp", 0, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-jp [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-jp", offsets2, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-jp [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "iso-2022-jp", offsets3MBCS, TRUE, U_ZERO_ERROR))
log_err("u->iso-2022-jp [UCNV_MBCS] \n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "iso-2022-jp", offsets3MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-jp[UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "iso-2022-jp", offsets4MBCS, TRUE, U_ZERO_ERROR))
log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "iso-2022-jp", offsets4MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
}
/*iso-2022-cn*/
log_verbose("Testing for iso-2022-cn\n");
{
UChar sampleText[] = { 0x0031, 0xd801};
const uint8_t expected[] = { 0x0f, 0x31};
int32_t offsets[] = { 0x00, 0x00,};
UChar sampleText2[] = { 0x0031, 0xd801, 0x0032};
const uint8_t expected2[] = { 0x0f, 0x31, 0x0f,0x1A,0x0f,0x32};
int32_t offsets2[] = { 0x00, 0x00, 0x01,0x01,0x02,0x02};
UChar sampleText3MBCS[] = { 0x0051, 0x0050, 0xdc01};
const uint8_t expected3MBCS[] = {0x0f, 0x51, 0x50,0x0f,0x1A};
int32_t offsets3MBCS[] = { 0x00, 0x00, 0x01, 0x02, 0x02 };
UChar sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01};
const uint8_t expected4MBCS[] = { 0x0f, 0x61, 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x52, 0x3b, 0x0f, 0x1a };
int32_t offsets4MBCS[] = { 0x00, 0x00, 0x01, 0x01 ,0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02 };
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-cn", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-cn", 0, FALSE, U_ZERO_ERROR))
log_err("u-> ibm-1363 [UCNV_MBCS] \n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-cn", 0, TRUE, U_ZERO_ERROR))
log_err("u->iso-2022-cn[UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-cn", 0, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-cn [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-cn", offsets2, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-cn [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "iso-2022-cn", offsets3MBCS, TRUE, U_ZERO_ERROR))
log_err("u->iso-2022-cn [UCNV_MBCS] \n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "iso-2022-cn", offsets3MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-cn[UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "iso-2022-cn", offsets4MBCS, TRUE, U_ZERO_ERROR))
log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "iso-2022-cn", offsets4MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
}
/*iso-2022-kr*/
log_verbose("Testing for iso-2022-kr\n");
{
UChar sampleText[] = { 0x0031, 0xd801};
const uint8_t expected[] = { 0x1b, 0x24, 0x29, 0x43, 0x31};
int32_t offsets[] = { -1, -1, -1, -1, 0x00};
UChar sampleText2[] = { 0x0031, 0xd801, 0x0032};
const uint8_t expected2[] = { 0x1b, 0x24, 0x29, 0x43, 0x31, 0x0f, 0x1A, 0x0f,0x32};
int32_t offsets2[] = { -1, -1, -1, -1, 0x00, 0x01, 0x01, 0x02,0x02};
UChar sampleText3MBCS[] = { 0x0051, 0x0050, 0xdc01};
const uint8_t expected3MBCS[] = { 0x1b, 0x24, 0x29, 0x43, 0x51, 0x50, 0x0f, 0x1A };
int32_t offsets3MBCS[] = { -1, -1, -1, -1, 0x00, 0x01, 0x02, 0x02 };
UChar sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01};
const uint8_t expected4MBCS[] = { 0x1b, 0x24, 0x29, 0x43, 0x61, 0x0e, 0x6c, 0x69, 0x0f, 0x1a };
int32_t offsets4MBCS[] = { -1, -1, -1, -1, 0x00, 0x01 ,0x01, 0x01, 0x02, 0x02 };
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-kr", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "iso-2022-kr", 0, FALSE, U_ZERO_ERROR))
log_err("u-> ibm-1363 [UCNV_MBCS] \n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-kr", 0, TRUE, U_ZERO_ERROR))
log_err("u->iso-2022-kr[UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-kr", 0, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-kr [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "iso-2022-kr", offsets2, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-kr [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "iso-2022-kr", offsets3MBCS, TRUE, U_ZERO_ERROR))
log_err("u->iso-2022-kr [UCNV_MBCS] \n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "iso-2022-kr", offsets3MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-kr[UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "iso-2022-kr", offsets4MBCS, TRUE, U_ZERO_ERROR))
log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "iso-2022-kr", offsets4MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
}
/*HZ*/
log_verbose("Testing for HZ\n");
{
UChar sampleText[] = { 0x0031, 0xd801};
const uint8_t expected[] = { 0x7e, 0x7d, 0x31};
int32_t offsets[] = { 0x00, 0x00, 0x00};
UChar sampleText2[] = { 0x0031, 0xd801, 0x0032};
const uint8_t expected2[] = { 0x7e, 0x7d, 0x31, 0x7e, 0x7d, 0x1A, 0x7e, 0x7d, 0x32 };
int32_t offsets2[] = { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02 };
UChar sampleText3MBCS[] = { 0x0051, 0x0050, 0xdc01};
const uint8_t expected3MBCS[] = { 0x7e, 0x7d, 0x51, 0x50, 0x7e, 0x7d, 0x1A };
int32_t offsets3MBCS[] = { 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02 };
UChar sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01};
const uint8_t expected4MBCS[] = { 0x7e, 0x7d, 0x61, 0x7e, 0x7b, 0x52, 0x3b, 0x7e, 0x7d, 0x1a };
int32_t offsets4MBCS[] = { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 ,0x01, 0x02, 0x02, 0x02 };
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "HZ", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
log_err("u-> HZ [UCNV_MBCS] \n");
if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
expected, sizeof(expected), "HZ", 0, FALSE, U_ZERO_ERROR))
log_err("u-> ibm-1363 [UCNV_MBCS] \n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "HZ", 0, TRUE, U_ZERO_ERROR))
log_err("u->HZ[UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "HZ", 0, FALSE, U_ZERO_ERROR))
log_err("u-> HZ [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
expected2, sizeof(expected2), "HZ", offsets2, FALSE, U_ZERO_ERROR))
log_err("u-> HZ [UCNV_DBCS] did not match\n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "HZ", offsets3MBCS, TRUE, U_ZERO_ERROR))
log_err("u->HZ [UCNV_MBCS] \n");
if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
expected3MBCS, sizeof(expected3MBCS), "HZ", offsets3MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> HZ[UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "HZ", offsets4MBCS, TRUE, U_ZERO_ERROR))
log_err("u-> HZ [UCNV_MBCS] \n");
if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
expected4MBCS, sizeof(expected4MBCS), "HZ", offsets4MBCS, FALSE, U_ZERO_ERROR))
log_err("u-> HZ [UCNV_MBCS] \n");
}
}

View File

@ -1375,7 +1375,7 @@ TestSmallTargetBuffer(const uint16_t* source, const UChar* sourceLimit,UConverte
cSourceLimit =cTarget;
do{
uTargetLimit=uTargetLimit+i;
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,NULL,FALSE,&errorCode);
ucnv_toUnicode(cnv,&uTarget,uTargetLimit,&cSource,cSourceLimit,NULL,FALSE,&errorCode);
if(errorCode==U_BUFFER_OVERFLOW_ERROR){
errorCode=U_ZERO_ERROR;
continue;
@ -1545,7 +1545,7 @@ void
TestISO_2022_JP() {
/* test input */
static const uint16_t in[]={
0x3000, 0x3001, 0x3002, 0x0020, 0xFF0E, 0x30FB, 0xFF1A, 0xFF1B, 0x000D, 0x000A,
0x0041,/*0x00E9,*/0x3000, 0x3001, 0x3002, 0x0020, 0xFF0E, 0x30FB, 0xFF1A, 0xFF1B, 0x000D, 0x000A,
0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A,
0xFF1F, 0xFF01, 0x309B, 0x309C, 0x00B4, 0xFF40, 0x00A8, 0xFF3E, 0x000D, 0x000A,
0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A,