1 /********************************************************************
3 * Copyright (c) 1997-2010, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 ********************************************************************************
10 * Modification History:
12 * Madhu Katragadda 7/21/1999 Testing error callback routines
13 ********************************************************************************
20 #include "unicode/uloc.h"
21 #include "unicode/ucnv.h"
22 #include "unicode/ucnv_err.h"
24 #include "unicode/utypes.h"
25 #include "unicode/ustring.h"
27 #include "unicode/ucnv_cb.h"
28 #define NEW_MAX_BUFFER 999
30 #define nct_min(x,y) ((x<y) ? x : y)
31 #define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
33 static int32_t gInBufferSize
= 0;
34 static int32_t gOutBufferSize
= 0;
35 static char gNuConvTestName
[1024];
37 static void printSeq(const uint8_t* a
, int len
)
42 log_verbose("0x%02X, ", a
[i
++]);
46 static void printUSeq(const UChar
* a
, int len
)
51 log_verbose(" 0x%04x, ", a
[i
++]);
55 static void printSeqErr(const uint8_t* a
, int len
)
60 fprintf(stderr
, " 0x%02x, ", a
[i
++]);
61 fprintf(stderr
, "}\n");
64 static void printUSeqErr(const UChar
* a
, int len
)
69 fprintf(stderr
, "0x%04x, ", a
[i
++]);
70 fprintf(stderr
,"}\n");
73 static void setNuConvTestName(const char *codepage
, const char *direction
)
75 sprintf(gNuConvTestName
, "[testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
83 static void TestCallBackFailure(void);
85 void addTestConvertErrorCallBack(TestNode
** root
);
87 void addTestConvertErrorCallBack(TestNode
** root
)
89 addTest(root
, &TestSkipCallBack
, "tsconv/nccbtst/TestSkipCallBack");
90 addTest(root
, &TestStopCallBack
, "tsconv/nccbtst/TestStopCallBack");
91 addTest(root
, &TestSubCallBack
, "tsconv/nccbtst/TestSubCallBack");
92 addTest(root
, &TestSubWithValueCallBack
, "tsconv/nccbtst/TestSubWithValueCallBack");
94 #if !UCONFIG_NO_LEGACY_CONVERSION
95 addTest(root
, &TestLegalAndOtherCallBack
, "tsconv/nccbtst/TestLegalAndOtherCallBack");
96 addTest(root
, &TestSingleByteCallBack
, "tsconv/nccbtst/TestSingleByteCallBack");
99 addTest(root
, &TestCallBackFailure
, "tsconv/nccbtst/TestCallBackFailure");
102 static void TestSkipCallBack()
104 TestSkip(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
105 TestSkip(1,NEW_MAX_BUFFER
);
107 TestSkip(NEW_MAX_BUFFER
, 1);
110 static void TestStopCallBack()
112 TestStop(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
113 TestStop(1,NEW_MAX_BUFFER
);
115 TestStop(NEW_MAX_BUFFER
, 1);
118 static void TestSubCallBack()
120 TestSub(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
121 TestSub(1,NEW_MAX_BUFFER
);
123 TestSub(NEW_MAX_BUFFER
, 1);
125 #if !UCONFIG_NO_LEGACY_CONVERSION
126 TestEBCDIC_STATEFUL_Sub(1, 1);
127 TestEBCDIC_STATEFUL_Sub(1, NEW_MAX_BUFFER
);
128 TestEBCDIC_STATEFUL_Sub(NEW_MAX_BUFFER
, 1);
129 TestEBCDIC_STATEFUL_Sub(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
133 static void TestSubWithValueCallBack()
135 TestSubWithValue(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
136 TestSubWithValue(1,NEW_MAX_BUFFER
);
137 TestSubWithValue(1,1);
138 TestSubWithValue(NEW_MAX_BUFFER
, 1);
141 #if !UCONFIG_NO_LEGACY_CONVERSION
142 static void TestLegalAndOtherCallBack()
144 TestLegalAndOthers(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
145 TestLegalAndOthers(1,NEW_MAX_BUFFER
);
146 TestLegalAndOthers(1,1);
147 TestLegalAndOthers(NEW_MAX_BUFFER
, 1);
150 static void TestSingleByteCallBack()
152 TestSingleByte(NEW_MAX_BUFFER
, NEW_MAX_BUFFER
);
153 TestSingleByte(1,NEW_MAX_BUFFER
);
155 TestSingleByte(NEW_MAX_BUFFER
, 1);
159 static void TestSkip(int32_t inputsize
, int32_t outputsize
)
161 static const uint8_t expskipIBM_949
[]= {
162 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xc8, 0xd3 };
164 static const uint8_t expskipIBM_943
[] = {
165 0x9f, 0xaf, 0x9f, 0xb1, 0x89, 0x59 };
167 static const uint8_t expskipIBM_930
[] = {
168 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x46, 0x6b, 0x0f };
170 gInBufferSize
= inputsize
;
171 gOutBufferSize
= outputsize
;
174 log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SKIP \n");
176 #if !UCONFIG_NO_LEGACY_CONVERSION
178 static const UChar sampleText
[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
179 static const UChar sampleText2
[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
181 static const int32_t toIBM949Offsskip
[] = { 0, 1, 1, 2, 2, 4, 4 };
182 static const int32_t toIBM943Offsskip
[] = { 0, 0, 1, 1, 3, 3 };
184 if(!testConvertFromUnicode(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
185 expskipIBM_949
, sizeof(expskipIBM_949
), "ibm-949",
186 UCNV_FROM_U_CALLBACK_SKIP
, toIBM949Offsskip
, NULL
, 0 ))
187 log_err("u-> ibm-949 with skip did not match.\n");
188 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
189 expskipIBM_943
, sizeof(expskipIBM_943
), "ibm-943",
190 UCNV_FROM_U_CALLBACK_SKIP
, toIBM943Offsskip
, NULL
, 0 ))
191 log_err("u-> ibm-943 with skip did not match.\n");
195 static const UChar fromU
[] = { 0x61, 0xff5e, 0x62, 0x6d63, 0xff5e, 0x6d64, 0x63, 0xff5e, 0x6d66 };
196 static const uint8_t fromUBytes
[] = { 0x62, 0x63, 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x0f, 0x64, 0x0e, 0x46, 0x6b, 0x0f };
197 static const int32_t fromUOffsets
[] = { 0, 2, 3, 3, 3, 5, 5, 6, 6, 8, 8, 8, 8 };
199 /* test ibm-930 (EBCDIC_STATEFUL) with fallbacks that are not taken to check correct state transitions */
200 if(!testConvertFromUnicode(fromU
, sizeof(fromU
)/U_SIZEOF_UCHAR
,
201 fromUBytes
, sizeof(fromUBytes
),
203 UCNV_FROM_U_CALLBACK_SKIP
, fromUOffsets
,
206 log_err("u->ibm-930 with skip with untaken fallbacks did not match.\n");
212 static const UChar usasciiFromU
[] = { 0x61, 0x80, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 };
213 static const uint8_t usasciiFromUBytes
[] = { 0x61, 0x31, 0x39 };
214 static const int32_t usasciiFromUOffsets
[] = { 0, 3, 6 };
216 static const UChar latin1FromU
[] = { 0x61, 0xa0, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 };
217 static const uint8_t latin1FromUBytes
[] = { 0x61, 0xa0, 0x31, 0x39 };
218 static const int32_t latin1FromUOffsets
[] = { 0, 1, 3, 6 };
221 if(!testConvertFromUnicode(usasciiFromU
, sizeof(usasciiFromU
)/U_SIZEOF_UCHAR
,
222 usasciiFromUBytes
, sizeof(usasciiFromUBytes
),
224 UCNV_FROM_U_CALLBACK_SKIP
, usasciiFromUOffsets
,
227 log_err("u->US-ASCII with skip did not match.\n");
230 #if !UCONFIG_NO_LEGACY_CONVERSION
231 /* SBCS NLTC codepage 367 for US-ASCII */
232 if(!testConvertFromUnicode(usasciiFromU
, sizeof(usasciiFromU
)/U_SIZEOF_UCHAR
,
233 usasciiFromUBytes
, sizeof(usasciiFromUBytes
),
235 UCNV_FROM_U_CALLBACK_SKIP
, usasciiFromUOffsets
,
238 log_err("u->ibm-367 with skip did not match.\n");
243 if(!testConvertFromUnicode(latin1FromU
, sizeof(latin1FromU
)/U_SIZEOF_UCHAR
,
244 latin1FromUBytes
, sizeof(latin1FromUBytes
),
246 UCNV_FROM_U_CALLBACK_SKIP
, latin1FromUOffsets
,
249 log_err("u->LATIN_1 with skip did not match.\n");
252 #if !UCONFIG_NO_LEGACY_CONVERSION
254 if(!testConvertFromUnicode(latin1FromU
, sizeof(latin1FromU
)/U_SIZEOF_UCHAR
,
255 latin1FromUBytes
, sizeof(latin1FromUBytes
),
257 UCNV_FROM_U_CALLBACK_SKIP
, latin1FromUOffsets
,
260 log_err("u->windows-1252 with skip did not match.\n");
265 static const UChar inputTest
[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
266 static const uint8_t toIBM943
[]= { 0x61, 0x61 };
267 static const int32_t offset
[]= {0, 4};
270 static const UChar euc_jp_inputText
[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
271 static const uint8_t to_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
274 static const int32_t fromEUC_JPOffs
[] ={ 0, 1, 1, 2, 2, 2, 6, 7, 7};
277 static const UChar euc_tw_inputText
[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
278 static const uint8_t to_euc_tw
[]={
279 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
280 0x61, 0xe6, 0xca, 0x8a,
282 static const int32_t from_euc_twOffs
[] ={ 0, 1, 1, 2, 2, 2, 2, 6, 7, 7, 8,};
285 static const UChar iso_2022_jp_inputText
[]={0x0041, 0x00E9/*unassigned*/,0x0042, };
286 static const uint8_t to_iso_2022_jp
[]={
291 static const int32_t from_iso_2022_jpOffs
[] ={0,2};
294 UChar
const iso_2022_jp_inputText2
[]={0x0041, 0x00E9/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
295 static const uint8_t to_iso_2022_jp2
[]={
300 static const int32_t from_iso_2022_jpOffs2
[] ={0,2};
303 static const UChar iso_2022_cn_inputText
[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
304 static const uint8_t to_iso_2022_cn
[]={
307 static const int32_t from_iso_2022_cnOffs
[] ={
312 static const UChar iso_2022_cn_inputText1
[]={0x0041, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
313 static const uint8_t to_iso_2022_cn1
[]={
317 static const int32_t from_iso_2022_cnOffs1
[] ={ 0, 2 };
320 static const UChar iso_2022_kr_inputText
[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
321 static const uint8_t to_iso_2022_kr
[]={
322 0x1b, 0x24, 0x29, 0x43,
328 static const int32_t from_iso_2022_krOffs
[] ={
337 static const UChar iso_2022_kr_inputText1
[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0,0xd801/*illegal*/, 0x0042, };
338 static const uint8_t to_iso_2022_kr1
[]={
339 0x1b, 0x24, 0x29, 0x43,
345 static const int32_t from_iso_2022_krOffs1
[] ={
353 static const UChar hz_inputText
[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
355 static const uint8_t to_hz
[]={
357 0x7e, 0x7b, 0x26, 0x30,
362 static const int32_t from_hzOffs
[] ={
369 static const UChar hz_inputText1
[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0,0xd801/*illegal*/, 0x0042, };
371 static const uint8_t to_hz1
[]={
373 0x7e, 0x7b, 0x26, 0x30,
378 static const int32_t from_hzOffs1
[] ={
387 static const UChar SCSU_inputText
[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
389 static const uint8_t to_SCSU
[]={
395 static const int32_t from_SCSUOffs
[] ={
401 #if !UCONFIG_NO_LEGACY_CONVERSION
403 static const UChar iscii_inputText
[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
404 static const uint8_t to_iscii
[]={
408 static const int32_t from_isciiOffs
[] ={
413 static const UChar iscii_inputText1
[]={0x0044, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
414 static const uint8_t to_iscii1
[]={
419 static const int32_t from_isciiOffs1
[] ={0,2};
421 if(!testConvertFromUnicode(inputTest
, sizeof(inputTest
)/sizeof(inputTest
[0]),
422 toIBM943
, sizeof(toIBM943
), "ibm-943",
423 UCNV_FROM_U_CALLBACK_SKIP
, offset
, NULL
, 0 ))
424 log_err("u-> ibm-943 with skip did not match.\n");
426 if(!testConvertFromUnicode(euc_jp_inputText
, sizeof(euc_jp_inputText
)/sizeof(euc_jp_inputText
[0]),
427 to_euc_jp
, sizeof(to_euc_jp
), "euc-jp",
428 UCNV_FROM_U_CALLBACK_SKIP
, fromEUC_JPOffs
, NULL
, 0 ))
429 log_err("u-> euc-jp with skip did not match.\n");
431 if(!testConvertFromUnicode(euc_tw_inputText
, sizeof(euc_tw_inputText
)/sizeof(euc_tw_inputText
[0]),
432 to_euc_tw
, sizeof(to_euc_tw
), "euc-tw",
433 UCNV_FROM_U_CALLBACK_SKIP
, from_euc_twOffs
, NULL
, 0 ))
434 log_err("u-> euc-tw with skip did not match.\n");
437 if(!testConvertFromUnicode(iso_2022_jp_inputText
, sizeof(iso_2022_jp_inputText
)/sizeof(iso_2022_jp_inputText
[0]),
438 to_iso_2022_jp
, sizeof(to_iso_2022_jp
), "iso-2022-jp",
439 UCNV_FROM_U_CALLBACK_SKIP
, from_iso_2022_jpOffs
, NULL
, 0 ))
440 log_err("u-> iso-2022-jp with skip did not match.\n");
443 if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2
, sizeof(iso_2022_jp_inputText2
)/sizeof(iso_2022_jp_inputText2
[0]),
444 to_iso_2022_jp2
, sizeof(to_iso_2022_jp2
), "iso-2022-jp",
445 UCNV_FROM_U_CALLBACK_SKIP
, from_iso_2022_jpOffs2
, NULL
, 0,UCNV_SKIP_STOP_ON_ILLEGAL
,U_ILLEGAL_CHAR_FOUND
))
446 log_err("u-> iso-2022-jp with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
449 if(!testConvertFromUnicode(iso_2022_cn_inputText
, sizeof(iso_2022_cn_inputText
)/sizeof(iso_2022_cn_inputText
[0]),
450 to_iso_2022_cn
, sizeof(to_iso_2022_cn
), "iso-2022-cn",
451 UCNV_FROM_U_CALLBACK_SKIP
, from_iso_2022_cnOffs
, NULL
, 0 ))
452 log_err("u-> iso-2022-cn with skip did not match.\n");
454 if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText1
, sizeof(iso_2022_cn_inputText1
)/sizeof(iso_2022_cn_inputText1
[0]),
455 to_iso_2022_cn1
, sizeof(to_iso_2022_cn1
), "iso-2022-cn",
456 UCNV_FROM_U_CALLBACK_SKIP
, from_iso_2022_cnOffs1
, NULL
, 0,UCNV_SKIP_STOP_ON_ILLEGAL
,U_ILLEGAL_CHAR_FOUND
))
457 log_err("u-> iso-2022-cn with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
460 if(!testConvertFromUnicode(iso_2022_kr_inputText
, sizeof(iso_2022_kr_inputText
)/sizeof(iso_2022_kr_inputText
[0]),
461 to_iso_2022_kr
, sizeof(to_iso_2022_kr
), "iso-2022-kr",
462 UCNV_FROM_U_CALLBACK_SKIP
, from_iso_2022_krOffs
, NULL
, 0 ))
463 log_err("u-> iso-2022-kr with skip did not match.\n");
465 if(!testConvertFromUnicodeWithContext(iso_2022_kr_inputText1
, sizeof(iso_2022_kr_inputText1
)/sizeof(iso_2022_kr_inputText1
[0]),
466 to_iso_2022_kr1
, sizeof(to_iso_2022_kr1
), "iso-2022-kr",
467 UCNV_FROM_U_CALLBACK_SKIP
, from_iso_2022_krOffs1
, NULL
, 0,UCNV_SKIP_STOP_ON_ILLEGAL
,U_ILLEGAL_CHAR_FOUND
))
468 log_err("u-> iso-2022-kr with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
471 if(!testConvertFromUnicode(hz_inputText
, sizeof(hz_inputText
)/sizeof(hz_inputText
[0]),
472 to_hz
, sizeof(to_hz
), "HZ",
473 UCNV_FROM_U_CALLBACK_SKIP
, from_hzOffs
, NULL
, 0 ))
474 log_err("u-> HZ with skip did not match.\n");
476 if(!testConvertFromUnicodeWithContext(hz_inputText1
, sizeof(hz_inputText1
)/sizeof(hz_inputText1
[0]),
477 to_hz1
, sizeof(to_hz1
), "hz",
478 UCNV_FROM_U_CALLBACK_SKIP
, from_hzOffs1
, NULL
, 0,UCNV_SKIP_STOP_ON_ILLEGAL
,U_ILLEGAL_CHAR_FOUND
))
479 log_err("u-> hz with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
483 if(!testConvertFromUnicode(SCSU_inputText
, sizeof(SCSU_inputText
)/sizeof(SCSU_inputText
[0]),
484 to_SCSU
, sizeof(to_SCSU
), "SCSU",
485 UCNV_FROM_U_CALLBACK_SKIP
, from_SCSUOffs
, NULL
, 0 ))
486 log_err("u-> SCSU with skip did not match.\n");
488 #if !UCONFIG_NO_LEGACY_CONVERSION
490 if(!testConvertFromUnicode(iscii_inputText
, sizeof(iscii_inputText
)/sizeof(iscii_inputText
[0]),
491 to_iscii
, sizeof(to_iscii
), "ISCII,version=0",
492 UCNV_FROM_U_CALLBACK_SKIP
, from_isciiOffs
, NULL
, 0 ))
493 log_err("u-> iscii with skip did not match.\n");
495 if(!testConvertFromUnicodeWithContext(iscii_inputText1
, sizeof(iscii_inputText1
)/sizeof(iscii_inputText1
[0]),
496 to_iscii1
, sizeof(to_iscii1
), "ISCII,version=0",
497 UCNV_FROM_U_CALLBACK_SKIP
, from_isciiOffs1
, NULL
, 0,UCNV_SKIP_STOP_ON_ILLEGAL
,U_ILLEGAL_CHAR_FOUND
))
498 log_err("u-> iscii with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
502 log_verbose("Testing fromUnicode for BOCU-1 with UCNV_TO_U_CALLBACK_SKIP\n");
504 static const uint8_t sampleText
[]={ /* from cintltst/bocu1tst.c/TestBOCU1 text 1 */
505 0xFB, 0xEE, 0x28, /* from source offset 0 */
523 0xF9, 0x28, /* from 16 */
532 0xFA, 0x83, /* from 24 */
541 0xF9, 0xA2, /* from 32 */
543 0xFE, 0x16, 0x3A, 0x8C,
552 static const UChar expected
[]={
553 0xFEFF, 0x0061, 0x0062, 0x0020, /* 0 */
554 0x0063, 0x0061, 0x000D, 0x000A,
556 0x0020, 0x0000, 0x00DF, 0x00E6, /* 8 */
557 0x0930, 0x0020, 0x0918, 0x0909,
559 0x3086, 0x304D, 0x0020, 0x3053, /* 16 */
560 0x4000, 0x4E00, 0x7777, 0x0020,
562 0x9FA5, 0x4E00, 0xAC00, 0xBCDE, /* 24 */
563 0x0020, 0xD7A3, 0xDC00, 0xD800,
565 0xD800, 0xDC00, 0xD845, 0xDDDD, /* 32 */
566 0xDBBB, 0xDDEE, 0x0020, 0xDBFF,
568 0xDFFF, 0x0001, 0x0E40, 0x0020, /* 40 */
571 static const int32_t offsets
[]={
572 0, 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 7,
573 8, 9, 10, 10, 11, 12, 12, 13, 14, 15,
574 16, 16, 17, 18, 19, 20, 20, 21, 21, 22, 22, 23,
575 24, 24, 25, 25, 26, 26, 26, 27, 27, 28, 29, 29, 30, 30, 31, 31,
576 32, 32, 34, 34, 34, 36, 36, 36, 36, 38, 39, 39, 39,
580 /* BOCU-1 fromUnicode never calls callbacks, so this only tests single-byte and offsets behavior */
581 if(!testConvertFromUnicode(expected
, ARRAY_LENGTH(expected
),
582 sampleText
, sizeof(sampleText
),
584 UCNV_FROM_U_CALLBACK_SKIP
, offsets
, NULL
, 0)
586 log_err("u->BOCU-1 with skip did not match.\n");
590 log_verbose("Testing fromUnicode for CESU-8 with UCNV_TO_U_CALLBACK_SKIP\n");
592 const uint8_t sampleText
[]={
594 0xc4, 0xb5, /* U+0135 */
595 0xed, 0x80, 0xa0, /* Hangul U+d020 */
596 0xed, 0xa0, 0x81, 0xed, 0xb0, 0x81, /* surrogate pair for U+10401 */
597 0xee, 0x80, 0x80, /* PUA U+e000 */
598 0xed, 0xb0, 0x81, /* unpaired trail surrogate U+dc01 */
600 0xed, 0xa0, 0x81, /* unpaired lead surrogate U+d801 */
601 0xd0, 0x80 /* U+0400 */
626 /* CESU-8 fromUnicode never calls callbacks, so this only tests conversion and offsets behavior */
628 /* without offsets */
629 if(!testConvertFromUnicode(expected
, ARRAY_LENGTH(expected
),
630 sampleText
, sizeof(sampleText
),
632 UCNV_FROM_U_CALLBACK_SKIP
, NULL
, NULL
, 0)
634 log_err("u->CESU-8 with skip did not match.\n");
638 if(!testConvertFromUnicode(expected
, ARRAY_LENGTH(expected
),
639 sampleText
, sizeof(sampleText
),
641 UCNV_FROM_U_CALLBACK_SKIP
, offsets
, NULL
, 0)
643 log_err("u->CESU-8 with skip did not match.\n");
648 log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SKIP \n");
650 #if !UCONFIG_NO_LEGACY_CONVERSION
653 static const UChar IBM_949skiptoUnicode
[]= {0x0000, 0xAC00, 0xAC01, 0xD700 };
654 static const UChar IBM_943skiptoUnicode
[]= { 0x6D63, 0x6D64, 0x6D66 };
655 static const UChar IBM_930skiptoUnicode
[]= { 0x6D63, 0x6D64, 0x6D66 };
657 static const int32_t fromIBM949Offs
[] = { 0, 1, 3, 5};
658 static const int32_t fromIBM943Offs
[] = { 0, 2, 4};
659 static const int32_t fromIBM930Offs
[] = { 1, 3, 5};
661 if(!testConvertToUnicode(expskipIBM_949
, sizeof(expskipIBM_949
),
662 IBM_949skiptoUnicode
, sizeof(IBM_949skiptoUnicode
)/sizeof(IBM_949skiptoUnicode
),"ibm-949",
663 UCNV_TO_U_CALLBACK_SKIP
, fromIBM949Offs
, NULL
, 0 ))
664 log_err("ibm-949->u with skip did not match.\n");
665 if(!testConvertToUnicode(expskipIBM_943
, sizeof(expskipIBM_943
),
666 IBM_943skiptoUnicode
, sizeof(IBM_943skiptoUnicode
)/sizeof(IBM_943skiptoUnicode
[0]),"ibm-943",
667 UCNV_TO_U_CALLBACK_SKIP
, fromIBM943Offs
, NULL
, 0 ))
668 log_err("ibm-943->u with skip did not match.\n");
671 if(!testConvertToUnicode(expskipIBM_930
, sizeof(expskipIBM_930
),
672 IBM_930skiptoUnicode
, sizeof(IBM_930skiptoUnicode
)/sizeof(IBM_930skiptoUnicode
[0]),"ibm-930",
673 UCNV_TO_U_CALLBACK_SKIP
, fromIBM930Offs
, NULL
, 0 ))
674 log_err("ibm-930->u with skip did not match.\n");
677 if(!testConvertToUnicodeWithContext(expskipIBM_930
, sizeof(expskipIBM_930
),
678 IBM_930skiptoUnicode
, sizeof(IBM_930skiptoUnicode
)/sizeof(IBM_930skiptoUnicode
[0]),"ibm-930",
679 UCNV_TO_U_CALLBACK_SKIP
, fromIBM930Offs
, NULL
, 0,"i",U_ILLEGAL_CHAR_FOUND
))
680 log_err("ibm-930->u with skip did not match.\n");
685 static const uint8_t usasciiToUBytes
[] = { 0x61, 0x80, 0x31 };
686 static const UChar usasciiToU
[] = { 0x61, 0x31 };
687 static const int32_t usasciiToUOffsets
[] = { 0, 2 };
689 static const uint8_t latin1ToUBytes
[] = { 0x61, 0xa0, 0x31 };
690 static const UChar latin1ToU
[] = { 0x61, 0xa0, 0x31 };
691 static const int32_t latin1ToUOffsets
[] = { 0, 1, 2 };
694 if(!testConvertToUnicode(usasciiToUBytes
, sizeof(usasciiToUBytes
),
695 usasciiToU
, sizeof(usasciiToU
)/U_SIZEOF_UCHAR
,
697 UCNV_TO_U_CALLBACK_SKIP
, usasciiToUOffsets
,
700 log_err("US-ASCII->u with skip did not match.\n");
703 #if !UCONFIG_NO_LEGACY_CONVERSION
704 /* SBCS NLTC codepage 367 for US-ASCII */
705 if(!testConvertToUnicode(usasciiToUBytes
, sizeof(usasciiToUBytes
),
706 usasciiToU
, sizeof(usasciiToU
)/U_SIZEOF_UCHAR
,
708 UCNV_TO_U_CALLBACK_SKIP
, usasciiToUOffsets
,
711 log_err("ibm-367->u with skip did not match.\n");
716 if(!testConvertToUnicode(latin1ToUBytes
, sizeof(latin1ToUBytes
),
717 latin1ToU
, sizeof(latin1ToU
)/U_SIZEOF_UCHAR
,
719 UCNV_TO_U_CALLBACK_SKIP
, latin1ToUOffsets
,
722 log_err("LATIN_1->u with skip did not match.\n");
725 #if !UCONFIG_NO_LEGACY_CONVERSION
727 if(!testConvertToUnicode(latin1ToUBytes
, sizeof(latin1ToUBytes
),
728 latin1ToU
, sizeof(latin1ToU
)/U_SIZEOF_UCHAR
,
730 UCNV_TO_U_CALLBACK_SKIP
, latin1ToUOffsets
,
733 log_err("windows-1252->u with skip did not match.\n");
738 #if !UCONFIG_NO_LEGACY_CONVERSION
740 static const uint8_t sampleTxtEBCIDIC_STATEFUL
[] ={
741 0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
743 static const UChar EBCIDIC_STATEFUL_toUnicode
[] ={ 0x6d63, 0x03b4
745 static const int32_t from_EBCIDIC_STATEFULOffsets
[]={ 1, 5};
749 static const uint8_t sampleTxt_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
750 0x8f, 0xda, 0xa1, /*unassigned*/
753 static const UChar euc_jptoUnicode
[]={ 0x0061, 0x4edd, 0x5bec, 0x00a2};
754 static const int32_t from_euc_jpOffs
[] ={ 0, 1, 3, 9};
757 static const uint8_t sampleTxt_euc_tw
[]={ 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
758 0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
761 static const UChar euc_twtoUnicode
[]={ 0x0061, 0x2295, 0x5BF2, 0x8706, 0x8a, };
762 static const int32_t from_euc_twOffs
[] ={ 0, 1, 3, 11, 13};
764 static const uint8_t sampleTxt_iso_2022_jp
[]={
766 0x1b, 0x24, 0x42, 0x2A, 0x44, /*unassigned*/
767 0x1b, 0x28, 0x42, 0x42,
770 static const UChar iso_2022_jptoUnicode
[]={ 0x41,0x42 };
771 static const int32_t from_iso_2022_jpOffs
[] ={ 0,9 };
774 static const uint8_t sampleTxt_iso_2022_cn
[]={
776 0x1B, 0x24, 0x29, 0x47,
777 0x0E, 0x40, 0x6f, /*unassigned*/
782 static const UChar iso_2022_cntoUnicode
[]={ 0x41, 0x44,0x42 };
783 static const int32_t from_iso_2022_cnOffs
[] ={ 1, 2, 11 };
786 static const uint8_t sampleTxt_iso_2022_kr
[]={
787 0x1b, 0x24, 0x29, 0x43,
795 static const UChar iso_2022_krtoUnicode
[]={ 0x41,0x03A0,0x51, 0x42,0x43};
796 static const int32_t from_iso_2022_krOffs
[] ={ 4, 9, 12, 13 , 14 };
799 static const uint8_t sampleTxt_hz
[]={
801 0x7e, 0x7b, 0x26, 0x30,
802 0x7f, 0x1E, /*unassigned*/
805 0x7e, 0x7b, 0x7f, 0x1E,/*unassigned*/
808 static const UChar hztoUnicode
[]={
815 static const int32_t from_hzOffs
[] ={0,3,7,11,18, };
818 static const uint8_t sampleTxt_iscii
[]={
828 static const UChar isciitoUnicode
[]={
837 static const int32_t from_isciiOffs
[] ={0,1,3,4,5,7 };
840 static const uint8_t sampleTxtLMBCS
[]={ 0x12, 0xc9, 0x50,
841 0x12, 0x92, 0xa0, /*unassigned*/
844 static const UChar LMBCSToUnicode
[]={ 0x4e2e, 0xe5c4};
845 static const int32_t fromLMBCS
[] = {0, 6};
847 if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL
, sizeof(sampleTxtEBCIDIC_STATEFUL
),
848 EBCIDIC_STATEFUL_toUnicode
, sizeof(EBCIDIC_STATEFUL_toUnicode
)/sizeof(EBCIDIC_STATEFUL_toUnicode
[0]),"ibm-930",
849 UCNV_TO_U_CALLBACK_SKIP
, from_EBCIDIC_STATEFULOffsets
, NULL
, 0 ))
850 log_err("EBCIDIC_STATEFUL->u with skip did not match.\n");
852 if(!testConvertToUnicodeWithContext(sampleTxtEBCIDIC_STATEFUL
, sizeof(sampleTxtEBCIDIC_STATEFUL
),
853 EBCIDIC_STATEFUL_toUnicode
, sizeof(EBCIDIC_STATEFUL_toUnicode
)/sizeof(EBCIDIC_STATEFUL_toUnicode
[0]),"ibm-930",
854 UCNV_TO_U_CALLBACK_SKIP
, from_EBCIDIC_STATEFULOffsets
, NULL
, 0,"i",U_ILLEGAL_CHAR_FOUND
))
855 log_err("EBCIDIC_STATEFUL->u with skip did not match.\n");
857 if(!testConvertToUnicode(sampleTxt_euc_jp
, sizeof(sampleTxt_euc_jp
),
858 euc_jptoUnicode
, sizeof(euc_jptoUnicode
)/sizeof(euc_jptoUnicode
[0]),"euc-jp",
859 UCNV_TO_U_CALLBACK_SKIP
, from_euc_jpOffs
, NULL
, 0))
860 log_err("euc-jp->u with skip did not match.\n");
864 if(!testConvertToUnicode(sampleTxt_euc_tw
, sizeof(sampleTxt_euc_tw
),
865 euc_twtoUnicode
, sizeof(euc_twtoUnicode
)/sizeof(euc_twtoUnicode
[0]),"euc-tw",
866 UCNV_TO_U_CALLBACK_SKIP
, from_euc_twOffs
, NULL
, 0))
867 log_err("euc-tw->u with skip did not match.\n");
870 if(!testConvertToUnicode(sampleTxt_iso_2022_jp
, sizeof(sampleTxt_iso_2022_jp
),
871 iso_2022_jptoUnicode
, sizeof(iso_2022_jptoUnicode
)/sizeof(iso_2022_jptoUnicode
[0]),"iso-2022-jp",
872 UCNV_TO_U_CALLBACK_SKIP
, from_iso_2022_jpOffs
, NULL
, 0))
873 log_err("iso-2022-jp->u with skip did not match.\n");
875 if(!testConvertToUnicode(sampleTxt_iso_2022_cn
, sizeof(sampleTxt_iso_2022_cn
),
876 iso_2022_cntoUnicode
, sizeof(iso_2022_cntoUnicode
)/sizeof(iso_2022_cntoUnicode
[0]),"iso-2022-cn",
877 UCNV_TO_U_CALLBACK_SKIP
, from_iso_2022_cnOffs
, NULL
, 0))
878 log_err("iso-2022-cn->u with skip did not match.\n");
880 if(!testConvertToUnicode(sampleTxt_iso_2022_kr
, sizeof(sampleTxt_iso_2022_kr
),
881 iso_2022_krtoUnicode
, sizeof(iso_2022_krtoUnicode
)/sizeof(iso_2022_krtoUnicode
[0]),"iso-2022-kr",
882 UCNV_TO_U_CALLBACK_SKIP
, from_iso_2022_krOffs
, NULL
, 0))
883 log_err("iso-2022-kr->u with skip did not match.\n");
885 if(!testConvertToUnicode(sampleTxt_hz
, sizeof(sampleTxt_hz
),
886 hztoUnicode
, sizeof(hztoUnicode
)/sizeof(hztoUnicode
[0]),"HZ",
887 UCNV_TO_U_CALLBACK_SKIP
, from_hzOffs
, NULL
, 0))
888 log_err("HZ->u with skip did not match.\n");
890 if(!testConvertToUnicode(sampleTxt_iscii
, sizeof(sampleTxt_iscii
),
891 isciitoUnicode
, sizeof(isciitoUnicode
)/sizeof(isciitoUnicode
[0]),"ISCII,version=0",
892 UCNV_TO_U_CALLBACK_SKIP
, from_isciiOffs
, NULL
, 0))
893 log_err("iscii->u with skip did not match.\n");
895 if(!testConvertToUnicode(sampleTxtLMBCS
, sizeof(sampleTxtLMBCS
),
896 LMBCSToUnicode
, sizeof(LMBCSToUnicode
)/sizeof(LMBCSToUnicode
[0]),"LMBCS-1",
897 UCNV_TO_U_CALLBACK_SKIP
, fromLMBCS
, NULL
, 0))
898 log_err("LMBCS->u with skip did not match.\n");
903 log_verbose("Testing to Unicode for UTF-8 with UCNV_TO_U_CALLBACK_SKIP \n");
905 const uint8_t sampleText1
[] = { 0x31, 0xe4, 0xba, 0x8c,
907 UChar expected1
[] = { 0x0031, 0x4e8c, 0x0061};
908 int32_t offsets1
[] = { 0x0000, 0x0001, 0x0006};
910 if(!testConvertToUnicode(sampleText1
, sizeof(sampleText1
),
911 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"utf8",
912 UCNV_TO_U_CALLBACK_SKIP
, offsets1
, NULL
, 0 ))
913 log_err("utf8->u with skip did not match.\n");;
916 log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SKIP \n");
918 const uint8_t sampleText1
[] = { 0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,};
919 UChar expected1
[] = { 0x00ba, 0x008c, 0x00f8, 0x0061,0xfffe,0xfffe};
920 int32_t offsets1
[] = { 0x0000, 0x0001,0x0002,0x0003,4,5};
922 if(!testConvertToUnicode(sampleText1
, sizeof(sampleText1
),
923 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"SCSU",
924 UCNV_TO_U_CALLBACK_SKIP
, offsets1
, NULL
, 0 ))
925 log_err("scsu->u with skip did not match.\n");
928 log_verbose("Testing toUnicode for BOCU-1 with UCNV_TO_U_CALLBACK_SKIP\n");
930 const uint8_t sampleText
[]={ /* modified from cintltst/bocu1tst.c/TestBOCU1 text 1 */
931 0xFB, 0xEE, 0x28, /* single-code point sequence at offset 0 */
932 0x24, 0x1E, 0x52, /* 3 */
935 0x40, 0x07, /* 8 - wrong trail byte */
938 0xD0, 0x20, /* 12 - wrong trail byte */
959 0xFB, 0x16, 0x87, /* 42 */
966 0xFC, 0x10, 0x3E, /* 56 */
967 0xFE, 0x16, 0x3A, 0x8C, /* 59 */
969 0xFC, 0x03, 0xAC, /* 64 */
970 0xFF, /* 67 - FF just resets the state without encoding anything */
977 0xFEFF, 0x0061, 0x0062, 0x0020,
978 0x0063, 0x0061, 0x000D, 0x000A,
979 0x0020, 0x0000, 0x00DF, 0x00E6,
980 0x0930, 0x0020, 0x0918, 0x0909,
981 0x3086, 0x304D, 0x0020, 0x3053,
982 0x4000, 0x4E00, 0x7777, 0x0020,
983 0x9FA5, 0x4E00, 0xAC00, 0xBCDE,
984 0x0020, 0xD7A3, 0xDC00, 0xD800,
985 0xD800, 0xDC00, 0xD845, 0xDDDD,
986 0xDBBB, 0xDDEE, 0x0020, 0xDBFF,
987 0xDFFF, 0x0001, 0x0E40, 0x0020,
991 0, 3, 6, 7, /* skip 8, */
992 10, 11, /* skip 12, */
994 20, 21, 23, 24, 25, 26, 28, 29,
995 30, 31, 33, 35, 37, 38,
997 50, 52, 54, /* trail */ 54, 56, /* trail */ 56, 59, /* trail */ 59,
998 63, 64, /* trail */ 64, /* reset only 67, */
1003 if(!testConvertToUnicode(sampleText
, sizeof(sampleText
),
1004 expected
, ARRAY_LENGTH(expected
), "BOCU-1",
1005 UCNV_TO_U_CALLBACK_SKIP
, offsets
, NULL
, 0)
1007 log_err("BOCU-1->u with skip did not match.\n");
1011 log_verbose("Testing toUnicode for CESU-8 with UCNV_TO_U_CALLBACK_SKIP\n");
1013 const uint8_t sampleText
[]={
1015 0xc0, 0x80, /* 1 non-shortest form */
1016 0xc4, 0xb5, /* 3 U+0135 */
1017 0xed, 0x80, 0xa0, /* 5 Hangul U+d020 */
1018 0xed, 0xa0, 0x81, 0xed, 0xb0, 0x81, /* 8 surrogate pair for U+10401 */
1019 0xee, 0x80, 0x80, /* 14 PUA U+e000 */
1020 0xed, 0xb0, 0x81, /* 17 unpaired trail surrogate U+dc01 */
1021 0xf0, 0x90, 0x80, 0x80, /* 20 illegal 4-byte form for U+10000 */
1023 0xed, 0xa0, 0x81, /* 25 unpaired lead surrogate U+d801 */
1024 0xed, 0xa0, /* 28 incomplete sequence */
1025 0xd0, 0x80 /* 30 U+0400 */
1055 /* without offsets */
1056 if(!testConvertToUnicode(sampleText
, sizeof(sampleText
),
1057 expected
, ARRAY_LENGTH(expected
), "CESU-8",
1058 UCNV_TO_U_CALLBACK_SKIP
, NULL
, NULL
, 0)
1060 log_err("CESU-8->u with skip did not match.\n");
1064 if(!testConvertToUnicode(sampleText
, sizeof(sampleText
),
1065 expected
, ARRAY_LENGTH(expected
), "CESU-8",
1066 UCNV_TO_U_CALLBACK_SKIP
, offsets
, NULL
, 0)
1068 log_err("CESU-8->u with skip did not match.\n");
1073 static void TestStop(int32_t inputsize
, int32_t outputsize
)
1075 static const UChar sampleText
[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
1076 static const UChar sampleText2
[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
1078 static const uint8_t expstopIBM_949
[]= {
1079 0x00, 0xb0, 0xa1, 0xb0, 0xa2};
1081 static const uint8_t expstopIBM_943
[] = {
1082 0x9f, 0xaf, 0x9f, 0xb1};
1084 static const uint8_t expstopIBM_930
[] = {
1085 0x0e, 0x5d, 0x5f, 0x5d, 0x63};
1087 static const UChar IBM_949stoptoUnicode
[]= {0x0000, 0xAC00, 0xAC01};
1088 static const UChar IBM_943stoptoUnicode
[]= { 0x6D63, 0x6D64};
1089 static const UChar IBM_930stoptoUnicode
[]= { 0x6D63, 0x6D64};
1092 static const int32_t toIBM949Offsstop
[] = { 0, 1, 1, 2, 2};
1093 static const int32_t toIBM943Offsstop
[] = { 0, 0, 1, 1};
1094 static const int32_t toIBM930Offsstop
[] = { 0, 0, 0, 1, 1};
1096 static const int32_t fromIBM949Offs
[] = { 0, 1, 3};
1097 static const int32_t fromIBM943Offs
[] = { 0, 2};
1098 static const int32_t fromIBM930Offs
[] = { 1, 3};
1100 gInBufferSize
= inputsize
;
1101 gOutBufferSize
= outputsize
;
1105 #if !UCONFIG_NO_LEGACY_CONVERSION
1106 if(!testConvertFromUnicode(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1107 expstopIBM_949
, sizeof(expstopIBM_949
), "ibm-949",
1108 UCNV_FROM_U_CALLBACK_STOP
, toIBM949Offsstop
, NULL
, 0 ))
1109 log_err("u-> ibm-949 with stop did not match.\n");
1110 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
1111 expstopIBM_943
, sizeof(expstopIBM_943
), "ibm-943",
1112 UCNV_FROM_U_CALLBACK_STOP
, toIBM943Offsstop
, NULL
, 0))
1113 log_err("u-> ibm-943 with stop did not match.\n");
1114 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
1115 expstopIBM_930
, sizeof(expstopIBM_930
), "ibm-930",
1116 UCNV_FROM_U_CALLBACK_STOP
, toIBM930Offsstop
, NULL
, 0 ))
1117 log_err("u-> ibm-930 with stop did not match.\n");
1119 log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_STOP \n");
1121 static const UChar inputTest
[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
1122 static const uint8_t toIBM943
[]= { 0x61,};
1123 static const int32_t offset
[]= {0,} ;
1126 static const UChar euc_jp_inputText
[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
1127 static const uint8_t to_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,};
1128 static const int32_t fromEUC_JPOffs
[] ={ 0, 1, 1, 2, 2, 2,};
1131 static const UChar euc_tw_inputText
[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
1132 static const uint8_t to_euc_tw
[]={
1133 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,};
1134 static const int32_t from_euc_twOffs
[] ={ 0, 1, 1, 2, 2, 2, 2,};
1137 static const UChar iso_2022_jp_inputText
[]={0x0041, 0x00E9, 0x0042, };
1138 static const uint8_t to_iso_2022_jp
[]={
1142 static const int32_t from_iso_2022_jpOffs
[] ={0,};
1145 static const UChar iso_2022_cn_inputText
[]={ 0x0041, 0x3712, 0x0042, };
1146 static const uint8_t to_iso_2022_cn
[]={
1150 static const int32_t from_iso_2022_cnOffs
[] ={
1156 static const UChar iso_2022_kr_inputText
[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
1157 static const uint8_t to_iso_2022_kr
[]={
1158 0x1b, 0x24, 0x29, 0x43,
1162 static const int32_t from_iso_2022_krOffs
[] ={
1169 static const UChar hz_inputText
[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
1171 static const uint8_t to_hz
[]={
1173 0x7e, 0x7b, 0x26, 0x30,
1176 static const int32_t from_hzOffs
[] ={
1182 static const UChar iscii_inputText
[]={ 0x0041, 0x3712, 0x0042, };
1183 static const uint8_t to_iscii
[]={
1186 static const int32_t from_isciiOffs
[] ={
1190 if(!testConvertFromUnicode(inputTest
, sizeof(inputTest
)/sizeof(inputTest
[0]),
1191 toIBM943
, sizeof(toIBM943
), "ibm-943",
1192 UCNV_FROM_U_CALLBACK_STOP
, offset
, NULL
, 0 ))
1193 log_err("u-> ibm-943 with stop did not match.\n");
1195 if(!testConvertFromUnicode(euc_jp_inputText
, sizeof(euc_jp_inputText
)/sizeof(euc_jp_inputText
[0]),
1196 to_euc_jp
, sizeof(to_euc_jp
), "euc-jp",
1197 UCNV_FROM_U_CALLBACK_STOP
, fromEUC_JPOffs
, NULL
, 0 ))
1198 log_err("u-> euc-jp with stop did not match.\n");
1200 if(!testConvertFromUnicode(euc_tw_inputText
, sizeof(euc_tw_inputText
)/sizeof(euc_tw_inputText
[0]),
1201 to_euc_tw
, sizeof(to_euc_tw
), "euc-tw",
1202 UCNV_FROM_U_CALLBACK_STOP
, from_euc_twOffs
, NULL
, 0 ))
1203 log_err("u-> euc-tw with stop did not match.\n");
1205 if(!testConvertFromUnicode(iso_2022_jp_inputText
, sizeof(iso_2022_jp_inputText
)/sizeof(iso_2022_jp_inputText
[0]),
1206 to_iso_2022_jp
, sizeof(to_iso_2022_jp
), "iso-2022-jp",
1207 UCNV_FROM_U_CALLBACK_STOP
, from_iso_2022_jpOffs
, NULL
, 0 ))
1208 log_err("u-> iso-2022-jp with stop did not match.\n");
1210 if(!testConvertFromUnicode(iso_2022_jp_inputText
, sizeof(iso_2022_jp_inputText
)/sizeof(iso_2022_jp_inputText
[0]),
1211 to_iso_2022_jp
, sizeof(to_iso_2022_jp
), "iso-2022-jp",
1212 UCNV_FROM_U_CALLBACK_STOP
, from_iso_2022_jpOffs
, NULL
, 0 ))
1213 log_err("u-> iso-2022-jp with stop did not match.\n");
1215 if(!testConvertFromUnicode(iso_2022_cn_inputText
, sizeof(iso_2022_cn_inputText
)/sizeof(iso_2022_cn_inputText
[0]),
1216 to_iso_2022_cn
, sizeof(to_iso_2022_cn
), "iso-2022-cn",
1217 UCNV_FROM_U_CALLBACK_STOP
, from_iso_2022_cnOffs
, NULL
, 0 ))
1218 log_err("u-> iso-2022-cn with stop did not match.\n");
1220 if(!testConvertFromUnicode(iso_2022_kr_inputText
, sizeof(iso_2022_kr_inputText
)/sizeof(iso_2022_kr_inputText
[0]),
1221 to_iso_2022_kr
, sizeof(to_iso_2022_kr
), "iso-2022-kr",
1222 UCNV_FROM_U_CALLBACK_STOP
, from_iso_2022_krOffs
, NULL
, 0 ))
1223 log_err("u-> iso-2022-kr with stop did not match.\n");
1225 if(!testConvertFromUnicode(hz_inputText
, sizeof(hz_inputText
)/sizeof(hz_inputText
[0]),
1226 to_hz
, sizeof(to_hz
), "HZ",
1227 UCNV_FROM_U_CALLBACK_STOP
, from_hzOffs
, NULL
, 0 ))
1228 log_err("u-> HZ with stop did not match.\n");\
1230 if(!testConvertFromUnicode(iscii_inputText
, sizeof(iscii_inputText
)/sizeof(iscii_inputText
[0]),
1231 to_iscii
, sizeof(to_iscii
), "ISCII,version=0",
1232 UCNV_FROM_U_CALLBACK_STOP
, from_isciiOffs
, NULL
, 0 ))
1233 log_err("u-> iscii with stop did not match.\n");
1239 log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_STOP \n");
1241 static const UChar SCSU_inputText
[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
1243 static const uint8_t to_SCSU
[]={
1247 int32_t from_SCSUOffs
[] ={
1251 if(!testConvertFromUnicode(SCSU_inputText
, sizeof(SCSU_inputText
)/sizeof(SCSU_inputText
[0]),
1252 to_SCSU
, sizeof(to_SCSU
), "SCSU",
1253 UCNV_FROM_U_CALLBACK_STOP
, from_SCSUOffs
, NULL
, 0 ))
1254 log_err("u-> SCSU with skip did not match.\n");
1260 #if !UCONFIG_NO_LEGACY_CONVERSION
1261 if(!testConvertToUnicode(expstopIBM_949
, sizeof(expstopIBM_949
),
1262 IBM_949stoptoUnicode
, sizeof(IBM_949stoptoUnicode
)/sizeof(IBM_949stoptoUnicode
[0]),"ibm-949",
1263 UCNV_TO_U_CALLBACK_STOP
, fromIBM949Offs
, NULL
, 0 ))
1264 log_err("ibm-949->u with stop did not match.\n");
1265 if(!testConvertToUnicode(expstopIBM_943
, sizeof(expstopIBM_943
),
1266 IBM_943stoptoUnicode
, sizeof(IBM_943stoptoUnicode
)/sizeof(IBM_943stoptoUnicode
[0]),"ibm-943",
1267 UCNV_TO_U_CALLBACK_STOP
, fromIBM943Offs
, NULL
, 0 ))
1268 log_err("ibm-943->u with stop did not match.\n");
1269 if(!testConvertToUnicode(expstopIBM_930
, sizeof(expstopIBM_930
),
1270 IBM_930stoptoUnicode
, sizeof(IBM_930stoptoUnicode
)/sizeof(IBM_930stoptoUnicode
[0]),"ibm-930",
1271 UCNV_TO_U_CALLBACK_STOP
, fromIBM930Offs
, NULL
, 0 ))
1272 log_err("ibm-930->u with stop did not match.\n");
1274 log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_STOP \n");
1277 static const uint8_t sampleTxtEBCIDIC_STATEFUL
[] ={
1278 0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
1280 static const UChar EBCIDIC_STATEFUL_toUnicode
[] ={ 0x6d63 };
1281 static const int32_t from_EBCIDIC_STATEFULOffsets
[]={ 1};
1285 static const uint8_t sampleTxt_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1286 0x8f, 0xda, 0xa1, /*unassigned*/
1289 static const UChar euc_jptoUnicode
[]={ 0x0061, 0x4edd, 0x5bec};
1290 static const int32_t from_euc_jpOffs
[] ={ 0, 1, 3};
1293 static const uint8_t sampleTxt_euc_tw
[]={ 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1294 0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
1297 UChar euc_twtoUnicode
[]={ 0x0061, 0x2295, 0x5BF2};
1298 int32_t from_euc_twOffs
[] ={ 0, 1, 3};
1302 if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL
, sizeof(sampleTxtEBCIDIC_STATEFUL
),
1303 EBCIDIC_STATEFUL_toUnicode
, sizeof(EBCIDIC_STATEFUL_toUnicode
)/sizeof(EBCIDIC_STATEFUL_toUnicode
[0]),"ibm-930",
1304 UCNV_TO_U_CALLBACK_STOP
, from_EBCIDIC_STATEFULOffsets
, NULL
, 0 ))
1305 log_err("EBCIDIC_STATEFUL->u with stop did not match.\n");
1307 if(!testConvertToUnicode(sampleTxt_euc_jp
, sizeof(sampleTxt_euc_jp
),
1308 euc_jptoUnicode
, sizeof(euc_jptoUnicode
)/sizeof(euc_jptoUnicode
[0]),"euc-jp",
1309 UCNV_TO_U_CALLBACK_STOP
, from_euc_jpOffs
, NULL
, 0))
1310 log_err("euc-jp->u with stop did not match.\n");
1312 if(!testConvertToUnicode(sampleTxt_euc_tw
, sizeof(sampleTxt_euc_tw
),
1313 euc_twtoUnicode
, sizeof(euc_twtoUnicode
)/sizeof(euc_twtoUnicode
[0]),"euc-tw",
1314 UCNV_TO_U_CALLBACK_STOP
, from_euc_twOffs
, NULL
, 0 ))
1315 log_err("euc-tw->u with stop did not match.\n");
1319 log_verbose("Testing toUnicode for UTF-8 with UCNV_TO_U_CALLBACK_STOP \n");
1321 static const uint8_t sampleText1
[] = { 0x31, 0xe4, 0xba, 0x8c,
1323 static const UChar expected1
[] = { 0x0031, 0x4e8c,};
1324 static const int32_t offsets1
[] = { 0x0000, 0x0001};
1326 if(!testConvertToUnicode(sampleText1
, sizeof(sampleText1
),
1327 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"utf8",
1328 UCNV_TO_U_CALLBACK_STOP
, offsets1
, NULL
, 0 ))
1329 log_err("utf8->u with stop did not match.\n");;
1331 log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_STOP \n");
1333 static const uint8_t sampleText1
[] = { 0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,0x04};
1334 static const UChar expected1
[] = { 0x00ba, 0x008c, 0x00f8, 0x0061};
1335 static const int32_t offsets1
[] = { 0x0000, 0x0001,0x0002,0x0003};
1337 if(!testConvertToUnicode(sampleText1
, sizeof(sampleText1
),
1338 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"SCSU",
1339 UCNV_TO_U_CALLBACK_STOP
, offsets1
, NULL
, 0 ))
1340 log_err("scsu->u with stop did not match.\n");;
1345 static void TestSub(int32_t inputsize
, int32_t outputsize
)
1347 static const UChar sampleText
[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
1348 static const UChar sampleText2
[]= { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
1350 static const uint8_t expsubIBM_949
[] =
1351 { 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xaf, 0xfe, 0xc8, 0xd3 };
1353 static const uint8_t expsubIBM_943
[] = {
1354 0x9f, 0xaf, 0x9f, 0xb1, 0xfc, 0xfc, 0x89, 0x59 };
1356 static const uint8_t expsubIBM_930
[] = {
1357 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfe, 0xfe, 0x46, 0x6b, 0x0f };
1359 static const UChar IBM_949subtoUnicode
[]= {0x0000, 0xAC00, 0xAC01, 0xfffd, 0xD700 };
1360 static const UChar IBM_943subtoUnicode
[]= {0x6D63, 0x6D64, 0xfffd, 0x6D66 };
1361 static const UChar IBM_930subtoUnicode
[]= {0x6D63, 0x6D64, 0xfffd, 0x6D66 };
1363 static const int32_t toIBM949Offssub
[] ={ 0, 1, 1, 2, 2, 3, 3, 4, 4 };
1364 static const int32_t toIBM943Offssub
[] ={ 0, 0, 1, 1, 2, 2, 3, 3 };
1365 static const int32_t toIBM930Offssub
[] ={ 0, 0, 0, 1, 1, 2, 2, 3, 3, 3 };
1367 static const int32_t fromIBM949Offs
[] = { 0, 1, 3, 5, 7 };
1368 static const int32_t fromIBM943Offs
[] = { 0, 2, 4, 6 };
1369 static const int32_t fromIBM930Offs
[] = { 1, 3, 5, 7 };
1371 gInBufferSize
= inputsize
;
1372 gOutBufferSize
= outputsize
;
1376 #if !UCONFIG_NO_LEGACY_CONVERSION
1377 if(!testConvertFromUnicode(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1378 expsubIBM_949
, sizeof(expsubIBM_949
), "ibm-949",
1379 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, toIBM949Offssub
, NULL
, 0 ))
1380 log_err("u-> ibm-949 with subst did not match.\n");
1381 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
1382 expsubIBM_943
, sizeof(expsubIBM_943
), "ibm-943",
1383 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, toIBM943Offssub
, NULL
, 0))
1384 log_err("u-> ibm-943 with subst did not match.\n");
1385 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
1386 expsubIBM_930
, sizeof(expsubIBM_930
), "ibm-930",
1387 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, toIBM930Offssub
, NULL
, 0 ))
1388 log_err("u-> ibm-930 with subst did not match.\n");
1390 log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SUBSTITUTE \n");
1392 static const UChar inputTest
[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
1393 static const uint8_t toIBM943
[]= { 0x61, 0xfc, 0xfc, 0xfc, 0xfc, 0x61 };
1394 static const int32_t offset
[]= {0, 1, 1, 3, 3, 4};
1398 static const UChar euc_jp_inputText
[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
1399 static const uint8_t to_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1400 0xf4, 0xfe, 0xf4, 0xfe,
1403 static const int32_t fromEUC_JPOffs
[] ={ 0, 1, 1, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7};
1406 static const UChar euc_tw_inputText
[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
1407 static const uint8_t to_euc_tw
[]={
1408 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1409 0xfd, 0xfe, 0xfd, 0xfe,
1410 0x61, 0xe6, 0xca, 0x8a,
1413 static const int32_t from_euc_twOffs
[] ={ 0, 1, 1, 2, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7, 8,};
1415 if(!testConvertFromUnicode(inputTest
, sizeof(inputTest
)/sizeof(inputTest
[0]),
1416 toIBM943
, sizeof(toIBM943
), "ibm-943",
1417 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offset
, NULL
, 0 ))
1418 log_err("u-> ibm-943 with substitute did not match.\n");
1420 if(!testConvertFromUnicode(euc_jp_inputText
, sizeof(euc_jp_inputText
)/sizeof(euc_jp_inputText
[0]),
1421 to_euc_jp
, sizeof(to_euc_jp
), "euc-jp",
1422 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, fromEUC_JPOffs
, NULL
, 0 ))
1423 log_err("u-> euc-jp with substitute did not match.\n");
1425 if(!testConvertFromUnicode(euc_tw_inputText
, sizeof(euc_tw_inputText
)/sizeof(euc_tw_inputText
[0]),
1426 to_euc_tw
, sizeof(to_euc_tw
), "euc-tw",
1427 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, from_euc_twOffs
, NULL
, 0 ))
1428 log_err("u-> euc-tw with substitute did not match.\n");
1432 log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_SUBSTITUTE \n");
1434 UChar SCSU_inputText
[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
1436 const uint8_t to_SCSU
[]={
1443 int32_t from_SCSUOffs
[] ={
1449 const uint8_t to_SCSU_1
[]={
1453 int32_t from_SCSUOffs_1
[] ={
1457 if(!testConvertFromUnicode(SCSU_inputText
, sizeof(SCSU_inputText
)/sizeof(SCSU_inputText
[0]),
1458 to_SCSU
, sizeof(to_SCSU
), "SCSU",
1459 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, from_SCSUOffs
, NULL
, 0 ))
1460 log_err("u-> SCSU with substitute did not match.\n");
1462 if(!testConvertFromUnicodeWithContext(SCSU_inputText
, sizeof(SCSU_inputText
)/sizeof(SCSU_inputText
[0]),
1463 to_SCSU_1
, sizeof(to_SCSU_1
), "SCSU",
1464 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, from_SCSUOffs_1
, NULL
, 0,"i",U_ILLEGAL_CHAR_FOUND
))
1465 log_err("u-> SCSU with substitute did not match.\n");
1468 log_verbose("Testing fromUnicode for UTF-8 with UCNV_FROM_U_CALLBACK_SUBSTITUTE\n");
1470 static const UChar testinput
[]={ 0x20ac, 0xd801, 0xdc01, 0xdc01, 0xd801, 0xffff, 0x0061,};
1471 static const uint8_t expectedUTF8
[]= { 0xe2, 0x82, 0xac,
1472 0xf0, 0x90, 0x90, 0x81,
1473 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
1474 0xef, 0xbf, 0xbf, 0x61,
1477 static const int32_t offsets
[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
1478 if(!testConvertFromUnicode(testinput
, sizeof(testinput
)/sizeof(testinput
[0]),
1479 expectedUTF8
, sizeof(expectedUTF8
), "utf8",
1480 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offsets
, NULL
, 0 )) {
1481 log_err("u-> utf8 with stop did not match.\n");
1485 log_verbose("Testing fromUnicode for UTF-16 with UCNV_FROM_U_CALLBACK_SUBSTITUTE\n");
1487 static const UChar in
[]={ 0x0041, 0xfeff };
1489 static const uint8_t out
[]={
1500 static const int32_t offsets
[]={
1504 if(!testConvertFromUnicode(in
, ARRAY_LENGTH(in
),
1505 out
, sizeof(out
), "UTF-16",
1506 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offsets
, NULL
, 0)
1508 log_err("u->UTF-16 with substitute did not match.\n");
1512 log_verbose("Testing fromUnicode for UTF-32 with UCNV_FROM_U_CALLBACK_SUBSTITUTE\n");
1514 static const UChar in
[]={ 0x0041, 0xfeff };
1516 static const uint8_t out
[]={
1518 0x00, 0x00, 0xfe, 0xff,
1519 0x00, 0x00, 0x00, 0x41,
1520 0x00, 0x00, 0xfe, 0xff
1522 0xff, 0xfe, 0x00, 0x00,
1523 0x41, 0x00, 0x00, 0x00,
1524 0xff, 0xfe, 0x00, 0x00
1527 static const int32_t offsets
[]={
1528 -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1
1531 if(!testConvertFromUnicode(in
, ARRAY_LENGTH(in
),
1532 out
, sizeof(out
), "UTF-32",
1533 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offsets
, NULL
, 0)
1535 log_err("u->UTF-32 with substitute did not match.\n");
1541 #if !UCONFIG_NO_LEGACY_CONVERSION
1542 if(!testConvertToUnicode(expsubIBM_949
, sizeof(expsubIBM_949
),
1543 IBM_949subtoUnicode
, sizeof(IBM_949subtoUnicode
)/sizeof(IBM_949subtoUnicode
[0]),"ibm-949",
1544 UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromIBM949Offs
, NULL
, 0 ))
1545 log_err("ibm-949->u with substitute did not match.\n");
1546 if(!testConvertToUnicode(expsubIBM_943
, sizeof(expsubIBM_943
),
1547 IBM_943subtoUnicode
, sizeof(IBM_943subtoUnicode
)/sizeof(IBM_943subtoUnicode
[0]),"ibm-943",
1548 UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromIBM943Offs
, NULL
, 0 ))
1549 log_err("ibm-943->u with substitute did not match.\n");
1550 if(!testConvertToUnicode(expsubIBM_930
, sizeof(expsubIBM_930
),
1551 IBM_930subtoUnicode
, sizeof(IBM_930subtoUnicode
)/sizeof(IBM_930subtoUnicode
[0]),"ibm-930",
1552 UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromIBM930Offs
, NULL
, 0 ))
1553 log_err("ibm-930->u with substitute did not match.\n");
1555 log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
1558 const uint8_t sampleTxtEBCIDIC_STATEFUL
[] ={
1559 0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
1561 UChar EBCIDIC_STATEFUL_toUnicode
[] ={ 0x6d63, 0xfffd, 0x03b4
1563 int32_t from_EBCIDIC_STATEFULOffsets
[]={ 1, 3, 5};
1567 const uint8_t sampleTxt_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1568 0x8f, 0xda, 0xa1, /*unassigned*/
1571 UChar euc_jptoUnicode
[]={ 0x0061, 0x4edd, 0x5bec, 0xfffd, 0x00a2, 0x008a };
1572 int32_t from_euc_jpOffs
[] ={ 0, 1, 3, 6, 9, 11 };
1575 const uint8_t sampleTxt_euc_tw
[]={
1576 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1577 0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
1580 UChar euc_twtoUnicode
[]={ 0x0061, 0x2295, 0x5BF2, 0xfffd, 0x8706, 0x8a, };
1581 int32_t from_euc_twOffs
[] ={ 0, 1, 3, 7, 11, 13};
1584 if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL
, sizeof(sampleTxtEBCIDIC_STATEFUL
),
1585 EBCIDIC_STATEFUL_toUnicode
, sizeof(EBCIDIC_STATEFUL_toUnicode
)/sizeof(EBCIDIC_STATEFUL_toUnicode
[0]),"ibm-930",
1586 UCNV_TO_U_CALLBACK_SUBSTITUTE
, from_EBCIDIC_STATEFULOffsets
, NULL
, 0 ))
1587 log_err("EBCIDIC_STATEFUL->u with substitute did not match.\n");
1590 if(!testConvertToUnicode(sampleTxt_euc_jp
, sizeof(sampleTxt_euc_jp
),
1591 euc_jptoUnicode
, sizeof(euc_jptoUnicode
)/sizeof(euc_jptoUnicode
[0]),"euc-jp",
1592 UCNV_TO_U_CALLBACK_SUBSTITUTE
, from_euc_jpOffs
, NULL
, 0 ))
1593 log_err("euc-jp->u with substitute did not match.\n");
1596 if(!testConvertToUnicode(sampleTxt_euc_tw
, sizeof(sampleTxt_euc_tw
),
1597 euc_twtoUnicode
, sizeof(euc_twtoUnicode
)/sizeof(euc_twtoUnicode
[0]),"euc-tw",
1598 UCNV_TO_U_CALLBACK_SUBSTITUTE
, from_euc_twOffs
, NULL
, 0 ))
1599 log_err("euc-tw->u with substitute did not match.\n");
1602 if(!testConvertToUnicodeWithContext(sampleTxt_euc_jp
, sizeof(sampleTxt_euc_jp
),
1603 euc_jptoUnicode
, sizeof(euc_jptoUnicode
)/sizeof(euc_jptoUnicode
[0]),"euc-jp",
1604 UCNV_TO_U_CALLBACK_SUBSTITUTE
, from_euc_jpOffs
, NULL
, 0 ,"i", U_ILLEGAL_CHAR_FOUND
))
1605 log_err("euc-jp->u with substitute did not match.\n");
1609 log_verbose("Testing toUnicode for UTF-8 with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
1611 const uint8_t sampleText1
[] = { 0x31, 0xe4, 0xba, 0x8c,
1613 UChar expected1
[] = { 0x0031, 0x4e8c, 0xfffd, 0x0061};
1614 int32_t offsets1
[] = { 0x0000, 0x0001, 0x0004, 0x0006};
1616 if(!testConvertToUnicode(sampleText1
, sizeof(sampleText1
),
1617 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"utf8",
1618 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets1
, NULL
, 0 ))
1619 log_err("utf8->u with substitute did not match.\n");;
1621 log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
1623 const uint8_t sampleText1
[] = { 0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,};
1624 UChar expected1
[] = { 0x00ba, 0x008c, 0x00f8, 0x0061,0xfffd,0xfffd};
1625 int32_t offsets1
[] = { 0x0000, 0x0001,0x0002,0x0003,4,5};
1627 if(!testConvertToUnicode(sampleText1
, sizeof(sampleText1
),
1628 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"SCSU",
1629 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets1
, NULL
, 0 ))
1630 log_err("scsu->u with stop did not match.\n");;
1633 #if !UCONFIG_NO_LEGACY_CONVERSION
1634 log_verbose("Testing ibm-930 subchar/subchar1\n");
1636 static const UChar u1
[]={ 0x6d63, 0x6d64, 0x6d65, 0x6d66, 0xdf };
1637 static const uint8_t s1
[]={ 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfe, 0xfe, 0x46, 0x6b, 0x0f, 0x3f };
1638 static const int32_t offsets1
[]={ 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4 };
1640 static const UChar u2
[]={ 0x6d63, 0x6d64, 0xfffd, 0x6d66, 0x1a };
1641 static const uint8_t s2
[]={ 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfc, 0xfc, 0x46, 0x6b, 0x0f, 0x57 };
1642 static const int32_t offsets2
[]={ 1, 3, 5, 7, 10 };
1644 if(!testConvertFromUnicode(u1
, ARRAY_LENGTH(u1
), s1
, ARRAY_LENGTH(s1
), "ibm-930",
1645 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offsets1
, NULL
, 0)
1647 log_err("u->ibm-930 subchar/subchar1 did not match.\n");
1650 if(!testConvertToUnicode(s2
, ARRAY_LENGTH(s2
), u2
, ARRAY_LENGTH(u2
), "ibm-930",
1651 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets2
, NULL
, 0)
1653 log_err("ibm-930->u subchar/subchar1 did not match.\n");
1657 log_verbose("Testing GB 18030 with substitute callbacks\n");
1659 static const UChar u2
[]={
1660 0x24, 0x7f, 0x80, 0x1f9, 0x20ac, 0x4e00, 0x9fa6, 0xffff, 0xd800, 0xdc00, 0xfffd, 0xdbff, 0xdfff };
1661 static const uint8_t gb2
[]={
1662 0x24, 0x7f, 0x81, 0x30, 0x81, 0x30, 0xa8, 0xbf, 0xa2, 0xe3, 0xd2, 0xbb, 0x82, 0x35, 0x8f, 0x33, 0x84, 0x31, 0xa4, 0x39, 0x90, 0x30, 0x81, 0x30, 0xe3, 0x32, 0x9a, 0x36, 0xe3, 0x32, 0x9a, 0x35 };
1663 static const int32_t offsets2
[]={
1664 0, 1, 2, 6, 8, 10, 12, 16, 20, 20, 24, 28, 28 };
1666 if(!testConvertToUnicode(gb2
, ARRAY_LENGTH(gb2
), u2
, ARRAY_LENGTH(u2
), "gb18030",
1667 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets2
, NULL
, 0)
1669 log_err("gb18030->u with substitute did not match.\n");
1674 log_verbose("Testing UTF-7 toUnicode with substitute callbacks\n");
1676 static const uint8_t utf7
[]={
1677 /* a~ a+AB~ a+AB\x0c a+AB- a+AB. a+. */
1678 0x61, 0x7e, 0x61, 0x2b, 0x41, 0x42, 0x7e, 0x61, 0x2b, 0x41, 0x42, 0x0c, 0x61, 0x2b, 0x41, 0x42, 0x2d, 0x61, 0x2b, 0x41, 0x42, 0x2e, 0x61, 0x2b, 0x2e
1680 static const UChar unicode
[]={
1681 0x61, 0xfffd, 0x61, 0xfffd, 0xfffd, 0x61, 0xfffd, 0xfffd, 0x61, 0xfffd, 0x61, 0xfffd, 0x2e, 0x61, 0xfffd, 0x2e
1683 static const int32_t offsets
[]={
1684 0, 1, 2, 4, 6, 7, 9, 11, 12, 14, 17, 19, 21, 22, 23, 24
1687 if(!testConvertToUnicode(utf7
, ARRAY_LENGTH(utf7
), unicode
, ARRAY_LENGTH(unicode
), "UTF-7",
1688 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets
, NULL
, 0)
1690 log_err("UTF-7->u with substitute did not match.\n");
1694 log_verbose("Testing UTF-16 toUnicode with substitute callbacks\n");
1696 static const uint8_t
1697 in1
[]={ 0xfe, 0xff, 0x4e, 0x00, 0xfe, 0xff },
1698 in2
[]={ 0xff, 0xfe, 0x4e, 0x00, 0xfe, 0xff },
1699 in3
[]={ 0xfe, 0xfd, 0x4e, 0x00, 0xfe, 0xff };
1702 out1
[]={ 0x4e00, 0xfeff },
1703 out2
[]={ 0x004e, 0xfffe },
1704 out3
[]={ 0xfefd, 0x4e00, 0xfeff };
1706 static const int32_t
1707 offsets1
[]={ 2, 4 },
1708 offsets2
[]={ 2, 4 },
1709 offsets3
[]={ 0, 2, 4 };
1711 if(!testConvertToUnicode(in1
, ARRAY_LENGTH(in1
), out1
, ARRAY_LENGTH(out1
), "UTF-16",
1712 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets1
, NULL
, 0)
1714 log_err("UTF-16 (BE BOM)->u with substitute did not match.\n");
1717 if(!testConvertToUnicode(in2
, ARRAY_LENGTH(in2
), out2
, ARRAY_LENGTH(out2
), "UTF-16",
1718 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets2
, NULL
, 0)
1720 log_err("UTF-16 (LE BOM)->u with substitute did not match.\n");
1723 if(!testConvertToUnicode(in3
, ARRAY_LENGTH(in3
), out3
, ARRAY_LENGTH(out3
), "UTF-16",
1724 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets3
, NULL
, 0)
1726 log_err("UTF-16 (no BOM)->u with substitute did not match.\n");
1730 log_verbose("Testing UTF-32 toUnicode with substitute callbacks\n");
1732 static const uint8_t
1733 in1
[]={ 0x00, 0x00, 0xfe, 0xff, 0x00, 0x10, 0x0f, 0x00, 0x00, 0x00, 0xfe, 0xff },
1734 in2
[]={ 0xff, 0xfe, 0x00, 0x00, 0x00, 0x10, 0x0f, 0x00, 0xfe, 0xff, 0x00, 0x00 },
1735 in3
[]={ 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x10, 0x0f, 0x00, 0x00, 0x00, 0xd8, 0x40, 0x00, 0x00, 0xdc, 0x01 },
1736 in4
[]={ 0x00, 0x01, 0x02, 0x03, 0x00, 0x11, 0x12, 0x00, 0x00, 0x00, 0x4e, 0x00 };
1739 out1
[]={ UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xfeff },
1740 out2
[]={ UTF16_LEAD(0x0f1000), UTF16_TRAIL(0x0f1000), 0xfffe },
1741 out3
[]={ 0xfefe, UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xfffd, 0xfffd },
1742 out4
[]={ UTF16_LEAD(0x10203), UTF16_TRAIL(0x10203), 0xfffd, 0x4e00 };
1744 static const int32_t
1745 offsets1
[]={ 4, 4, 8 },
1746 offsets2
[]={ 4, 4, 8 },
1747 offsets3
[]={ 0, 4, 4, 8, 12 },
1748 offsets4
[]={ 0, 0, 4, 8 };
1750 if(!testConvertToUnicode(in1
, ARRAY_LENGTH(in1
), out1
, ARRAY_LENGTH(out1
), "UTF-32",
1751 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets1
, NULL
, 0)
1753 log_err("UTF-32 (BE BOM)->u with substitute did not match.\n");
1756 if(!testConvertToUnicode(in2
, ARRAY_LENGTH(in2
), out2
, ARRAY_LENGTH(out2
), "UTF-32",
1757 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets2
, NULL
, 0)
1759 log_err("UTF-32 (LE BOM)->u with substitute did not match.\n");
1762 if(!testConvertToUnicode(in3
, ARRAY_LENGTH(in3
), out3
, ARRAY_LENGTH(out3
), "UTF-32",
1763 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets3
, NULL
, 0)
1765 log_err("UTF-32 (no BOM)->u with substitute did not match.\n");
1768 if(!testConvertToUnicode(in4
, ARRAY_LENGTH(in4
), out4
, ARRAY_LENGTH(out4
), "UTF-32",
1769 UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets4
, NULL
, 0)
1771 log_err("UTF-32 (no BOM, with error)->u with substitute did not match.\n");
1776 static void TestSubWithValue(int32_t inputsize
, int32_t outputsize
)
1778 UChar sampleText
[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
1779 UChar sampleText2
[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
1781 const uint8_t expsubwvalIBM_949
[]= {
1782 0x00, 0xb0, 0xa1, 0xb0, 0xa2,
1783 0x25, 0x55, 0x45, 0x46, 0x36, 0x37, 0xc8, 0xd3 };
1785 const uint8_t expsubwvalIBM_943
[]= {
1786 0x9f, 0xaf, 0x9f, 0xb1,
1787 0x25, 0x55, 0x36, 0x44, 0x36, 0x35, 0x89, 0x59 };
1789 const uint8_t expsubwvalIBM_930
[] = {
1790 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x0f, 0x6c, 0xe4, 0xf6, 0xc4, 0xf6, 0xf5, 0x0e, 0x46, 0x6b, 0x0f };
1792 int32_t toIBM949Offs
[] ={ 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4 };
1793 int32_t toIBM943Offs
[] = { 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3 };
1794 int32_t toIBM930Offs
[] = { 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3 }; /* last item: 3,3,3,3 because there's SO+DBCS+SI */
1796 gInBufferSize
= inputsize
;
1797 gOutBufferSize
= outputsize
;
1801 #if !UCONFIG_NO_LEGACY_CONVERSION
1802 if(!testConvertFromUnicode(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1803 expsubwvalIBM_949
, sizeof(expsubwvalIBM_949
), "ibm-949",
1804 UCNV_FROM_U_CALLBACK_ESCAPE
, toIBM949Offs
, NULL
, 0 ))
1805 log_err("u-> ibm-949 with subst with value did not match.\n");
1807 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
1808 expsubwvalIBM_943
, sizeof(expsubwvalIBM_943
), "ibm-943",
1809 UCNV_FROM_U_CALLBACK_ESCAPE
, toIBM943Offs
, NULL
, 0 ))
1810 log_err("u-> ibm-943 with sub with value did not match.\n");
1812 if(!testConvertFromUnicode(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
1813 expsubwvalIBM_930
, sizeof(expsubwvalIBM_930
), "ibm-930",
1814 UCNV_FROM_U_CALLBACK_ESCAPE
, toIBM930Offs
, NULL
, 0 ))
1815 log_err("u-> ibm-930 with subst with value did not match.\n");
1818 log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_ESCAPE \n");
1820 static const UChar inputTest
[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
1821 static const uint8_t toIBM943
[]= { 0x61,
1822 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1823 0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
1824 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1826 static const int32_t offset
[]= {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 4};
1830 static const UChar euc_jp_inputText
[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2, };
1831 static const uint8_t to_euc_jp
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1832 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1833 0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
1834 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1837 static const int32_t fromEUC_JPOffs
[] ={ 0, 1, 1, 2, 2, 2,
1845 static const UChar euc_tw_inputText
[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
1846 static const uint8_t to_euc_tw
[]={
1847 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1848 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1849 0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
1850 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1851 0x61, 0xe6, 0xca, 0x8a,
1853 static const int32_t from_euc_twOffs
[] ={ 0, 1, 1, 2, 2, 2, 2,
1854 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5,
1858 static const UChar iso_2022_jp_inputText1
[]={ 0x3000, 0x00E9, 0x3001,0x00E9, 0x0042} ;
1859 static const uint8_t to_iso_2022_jp1
[]={
1860 0x1b, 0x24, 0x42, 0x21, 0x21,
1861 0x1b, 0x28, 0x42, 0x25, 0x55, 0x30, 0x30, 0x45, 0x39,
1862 0x1b, 0x24, 0x42, 0x21, 0x22,
1863 0x1b, 0x28, 0x42, 0x25, 0x55, 0x30, 0x30, 0x45, 0x39,
1867 static const int32_t from_iso_2022_jpOffs1
[] ={
1875 static const UChar iso_2022_jp_inputText2
[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042} ;
1876 static const uint8_t to_iso_2022_jp2
[]={
1877 0x1b, 0x24, 0x42, 0x21, 0x21,
1878 0x1b, 0x28, 0x42, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1879 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1880 0x1b, 0x24, 0x42, 0x21, 0x22,
1881 0x1b, 0x28, 0x42, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1882 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1885 static const int32_t from_iso_2022_jpOffs2
[] ={
1896 static const UChar iso_2022_cn_inputText
[]={ 0x0041, 0x3712, 0x0042, };
1897 static const uint8_t to_iso_2022_cn
[]={
1899 0x25, 0x55, 0x33, 0x37, 0x31, 0x32,
1902 static const int32_t from_iso_2022_cnOffs
[] ={
1908 static const UChar iso_2022_cn_inputText4
[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042};
1910 static const uint8_t to_iso_2022_cn4
[]={
1911 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
1912 0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1913 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1915 0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1916 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1919 static const int32_t from_iso_2022_cnOffs4
[] ={
1931 static const UChar iso_2022_kr_inputText2
[]={ 0x0041, 0x03A0,0xD84D, 0xDC56/*unassigned*/,0x03A0, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
1932 static const uint8_t to_iso_2022_kr2
[]={
1933 0x1b, 0x24, 0x29, 0x43,
1936 0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1937 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1940 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1941 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1944 static const int32_t from_iso_2022_krOffs2
[] ={
1957 static const UChar iso_2022_kr_inputText
[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042,0x3712/*unassigned*/,0x43 };
1958 static const uint8_t to_iso_2022_kr
[]={
1959 0x1b, 0x24, 0x29, 0x43,
1962 0x0f, 0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
1965 0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
1970 static const int32_t from_iso_2022_krOffs
[] ={
1981 static const UChar hz_inputText
[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
1983 static const uint8_t to_hz
[]={
1985 0x7e, 0x7b, 0x26, 0x30,
1986 0x7e, 0x7d, 0x25, 0x55, 0x30, 0x36, 0x36, 0x32, /*unassigned*/
1987 0x7e, 0x7b, 0x26, 0x30,
1991 static const int32_t from_hzOffs
[] ={
1999 static const UChar hz_inputText2
[]={ 0x0041, 0x03A0,0xD84D, 0xDC56/*unassigned*/,0x03A0, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
2000 static const uint8_t to_hz2
[]={
2002 0x7e, 0x7b, 0x26, 0x30,
2003 0x7e, 0x7d, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
2004 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
2005 0x7e, 0x7b, 0x26, 0x30,
2007 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
2008 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
2011 static const int32_t from_hzOffs2
[] ={
2024 static const UChar iscii_inputText
[]={ 0x0041, 0x0901,0x3712/*unassigned*/,0x0902, 0x0042,0x3712/*unassigned*/,0x43 };
2025 static const uint8_t to_iscii
[]={
2028 0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
2031 0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
2036 static const int32_t from_isciiOffs
[] ={
2046 if(!testConvertFromUnicode(inputTest
, sizeof(inputTest
)/sizeof(inputTest
[0]),
2047 toIBM943
, sizeof(toIBM943
), "ibm-943",
2048 UCNV_FROM_U_CALLBACK_ESCAPE
, offset
, NULL
, 0 ))
2049 log_err("u-> ibm-943 with subst with value did not match.\n");
2051 if(!testConvertFromUnicode(euc_jp_inputText
, sizeof(euc_jp_inputText
)/sizeof(euc_jp_inputText
[0]),
2052 to_euc_jp
, sizeof(to_euc_jp
), "euc-jp",
2053 UCNV_FROM_U_CALLBACK_ESCAPE
, fromEUC_JPOffs
, NULL
, 0 ))
2054 log_err("u-> euc-jp with subst with value did not match.\n");
2056 if(!testConvertFromUnicode(euc_tw_inputText
, sizeof(euc_tw_inputText
)/sizeof(euc_tw_inputText
[0]),
2057 to_euc_tw
, sizeof(to_euc_tw
), "euc-tw",
2058 UCNV_FROM_U_CALLBACK_ESCAPE
, from_euc_twOffs
, NULL
, 0 ))
2059 log_err("u-> euc-tw with subst with value did not match.\n");
2061 if(!testConvertFromUnicode(iso_2022_jp_inputText1
, sizeof(iso_2022_jp_inputText1
)/sizeof(iso_2022_jp_inputText1
[0]),
2062 to_iso_2022_jp1
, sizeof(to_iso_2022_jp1
), "iso-2022-jp",
2063 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffs1
, NULL
, 0 ))
2064 log_err("u-> iso_2022_jp with subst with value did not match.\n");
2066 if(!testConvertFromUnicode(iso_2022_jp_inputText1
, sizeof(iso_2022_jp_inputText1
)/sizeof(iso_2022_jp_inputText1
[0]),
2067 to_iso_2022_jp1
, sizeof(to_iso_2022_jp1
), "iso-2022-jp",
2068 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffs1
, NULL
, 0 ))
2069 log_err("u-> iso_2022_jp with subst with value did not match.\n");
2071 if(!testConvertFromUnicode(iso_2022_jp_inputText2
, sizeof(iso_2022_jp_inputText2
)/sizeof(iso_2022_jp_inputText2
[0]),
2072 to_iso_2022_jp2
, sizeof(to_iso_2022_jp2
), "iso-2022-jp",
2073 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffs2
, NULL
, 0 ))
2074 log_err("u-> iso_2022_jp with subst with value did not match.\n");
2078 static const UChar iso_2022_jp_inputText3
[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042,0x0901c } ;
2079 static const uint8_t to_iso_2022_jp3_v2
[]={
2080 0x1b, 0x24, 0x42, 0x21, 0x21,
2081 0x1b, 0x28, 0x42, 0x26, 0x23, 0x31, 0x34, 0x34, 0x34, 0x37, 0x30, 0x3b,
2083 0x1b, 0x24, 0x42, 0x21, 0x22,
2084 0x1b, 0x28, 0x42, 0x26, 0x23, 0x31, 0x34, 0x34, 0x34, 0x37, 0x30, 0x3b,
2087 0x26, 0x23, 0x33, 0x36, 0x38, 0x39, 0x32, 0x3b,
2090 static const int32_t from_iso_2022_jpOffs3_v2
[] ={
2092 1,1,1,1,1,1,1,1,1,1,1,1,
2095 4,4,4,4,4,4,4,4,4,4,4,4,
2101 if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText3
, sizeof(iso_2022_jp_inputText3
)/sizeof(iso_2022_jp_inputText3
[0]),
2102 to_iso_2022_jp3_v2
, sizeof(to_iso_2022_jp3_v2
), "iso-2022-jp",
2103 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffs3_v2
, NULL
, 0,UCNV_ESCAPE_XML_DEC
,U_ZERO_ERROR
))
2104 log_err("u-> iso-2022-jp with sub & UCNV_ESCAPE_XML_DEC did not match.\n");
2107 static const UChar iso_2022_cn_inputText5
[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042,0x0902};
2108 static const uint8_t to_iso_2022_cn5_v2
[]={
2109 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
2110 0x0f, 0x5c, 0x75, 0x44, 0x38, 0x34, 0x44,
2111 0x5c, 0x75, 0x44, 0x43, 0x35, 0x36,
2113 0x0f, 0x5c, 0x75, 0x44, 0x38, 0x34, 0x44,
2114 0x5c, 0x75, 0x44, 0x43, 0x35, 0x36,
2116 0x5c, 0x75, 0x30, 0x39, 0x30, 0x32,
2118 static const int32_t from_iso_2022_cnOffs5_v2
[] ={
2128 if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText5
, sizeof(iso_2022_cn_inputText5
)/sizeof(iso_2022_cn_inputText5
[0]),
2129 to_iso_2022_cn5_v2
, sizeof(to_iso_2022_cn5_v2
), "iso-2022-cn",
2130 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs5_v2
, NULL
, 0,UCNV_ESCAPE_JAVA
,U_ZERO_ERROR
))
2131 log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_JAVA did not match.\n");
2135 static const UChar iso_2022_cn_inputText6
[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042,0x0902};
2136 static const uint8_t to_iso_2022_cn6_v2
[]={
2137 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
2138 0x0f, 0x7b, 0x55, 0x2b, 0x32, 0x33, 0x34, 0x35, 0x36, 0x7d,
2140 0x0f, 0x7b, 0x55, 0x2b, 0x32, 0x33, 0x34, 0x35, 0x36, 0x7d,
2142 0x7b, 0x55, 0x2b, 0x30, 0x39, 0x30, 0x32, 0x7d
2144 static const int32_t from_iso_2022_cnOffs6_v2
[] ={
2145 0, 0, 0, 0, 0, 0, 0,
2146 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2148 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2150 7, 7, 7, 7, 7, 7, 7, 7,
2152 if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText6
, sizeof(iso_2022_cn_inputText6
)/sizeof(iso_2022_cn_inputText6
[0]),
2153 to_iso_2022_cn6_v2
, sizeof(to_iso_2022_cn6_v2
), "iso-2022-cn",
2154 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs6_v2
, NULL
, 0,UCNV_ESCAPE_UNICODE
,U_ZERO_ERROR
))
2155 log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_UNICODE did not match.\n");
2159 static const UChar iso_2022_cn_inputText7
[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042,0x0902};
2160 static const uint8_t to_iso_2022_cn7_v2
[]={
2161 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
2162 0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44, 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
2164 0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44, 0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
2165 0x42, 0x25, 0x55, 0x30, 0x39, 0x30, 0x32,
2167 static const int32_t from_iso_2022_cnOffs7_v2
[] ={
2168 0, 0, 0, 0, 0, 0, 0,
2169 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2171 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2175 if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText7
, sizeof(iso_2022_cn_inputText7
)/sizeof(iso_2022_cn_inputText7
[0]),
2176 to_iso_2022_cn7_v2
, sizeof(to_iso_2022_cn7_v2
), "iso-2022-cn",
2177 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs7_v2
, NULL
, 0,"K" ,U_ZERO_ERROR
))
2178 log_err("u-> iso-2022-cn with sub & K did not match.\n");
2182 static const UChar iso_2022_cn_inputText8
[]={
2190 static const uint8_t to_iso_2022_cn8_v2
[]={
2191 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
2192 0x0f, 0x5c, 0x32, 0x33, 0x34, 0x35, 0x36, 0x20,
2194 0x0f, 0x5c, 0x32, 0x33, 0x34, 0x35, 0x36, 0x20,
2195 0x5c, 0x31, 0x30, 0x46, 0x46, 0x46, 0x46, 0x20,
2197 0x5c, 0x39, 0x30, 0x32, 0x20
2199 static const int32_t from_iso_2022_cnOffs8_v2
[] ={
2200 0, 0, 0, 0, 0, 0, 0,
2201 1, 1, 1, 1, 1, 1, 1, 1,
2203 4, 4, 4, 4, 4, 4, 4, 4,
2204 6, 6, 6, 6, 6, 6, 6, 6,
2208 if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText8
, sizeof(iso_2022_cn_inputText8
)/sizeof(iso_2022_cn_inputText8
[0]),
2209 to_iso_2022_cn8_v2
, sizeof(to_iso_2022_cn8_v2
), "iso-2022-cn",
2210 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs8_v2
, NULL
, 0,UCNV_ESCAPE_CSS2
,U_ZERO_ERROR
))
2211 log_err("u-> iso-2022-cn with sub & UCNV_ESCAPE_CSS2 did not match.\n");
2215 static const uint8_t to_iso_2022_cn4_v3
[]={
2216 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
2217 0x0f, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x32, 0x33, 0x34, 0x35, 0x36,
2219 0x0f, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x32, 0x33, 0x34, 0x35, 0x36,
2224 static const int32_t from_iso_2022_cnOffs4_v3
[] ={
2226 1,1,1,1,1,1,1,1,1,1,1,
2229 4,4,4,4,4,4,4,4,4,4,4,
2234 if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4
, sizeof(iso_2022_cn_inputText4
)/sizeof(iso_2022_cn_inputText4
[0]),
2235 to_iso_2022_cn4_v3
, sizeof(to_iso_2022_cn4_v3
), "iso-2022-cn",
2236 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs4_v3
, NULL
, 0,UCNV_ESCAPE_C
,U_ZERO_ERROR
))
2238 log_err("u-> iso-2022-cn with skip & UCNV_ESCAPE_C did not match.\n");
2241 if(!testConvertFromUnicode(iso_2022_cn_inputText
, sizeof(iso_2022_cn_inputText
)/sizeof(iso_2022_cn_inputText
[0]),
2242 to_iso_2022_cn
, sizeof(to_iso_2022_cn
), "iso-2022-cn",
2243 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs
, NULL
, 0 ))
2244 log_err("u-> iso_2022_cn with subst with value did not match.\n");
2246 if(!testConvertFromUnicode(iso_2022_cn_inputText4
, sizeof(iso_2022_cn_inputText4
)/sizeof(iso_2022_cn_inputText4
[0]),
2247 to_iso_2022_cn4
, sizeof(to_iso_2022_cn4
), "iso-2022-cn",
2248 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs4
, NULL
, 0 ))
2249 log_err("u-> iso_2022_cn with subst with value did not match.\n");
2250 if(!testConvertFromUnicode(iso_2022_kr_inputText
, sizeof(iso_2022_kr_inputText
)/sizeof(iso_2022_kr_inputText
[0]),
2251 to_iso_2022_kr
, sizeof(to_iso_2022_kr
), "iso-2022-kr",
2252 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_krOffs
, NULL
, 0 ))
2253 log_err("u-> iso_2022_kr with subst with value did not match.\n");
2254 if(!testConvertFromUnicode(iso_2022_kr_inputText2
, sizeof(iso_2022_kr_inputText2
)/sizeof(iso_2022_kr_inputText2
[0]),
2255 to_iso_2022_kr2
, sizeof(to_iso_2022_kr2
), "iso-2022-kr",
2256 UCNV_FROM_U_CALLBACK_ESCAPE
, from_iso_2022_krOffs2
, NULL
, 0 ))
2257 log_err("u-> iso_2022_kr2 with subst with value did not match.\n");
2258 if(!testConvertFromUnicode(hz_inputText
, sizeof(hz_inputText
)/sizeof(hz_inputText
[0]),
2259 to_hz
, sizeof(to_hz
), "HZ",
2260 UCNV_FROM_U_CALLBACK_ESCAPE
, from_hzOffs
, NULL
, 0 ))
2261 log_err("u-> hz with subst with value did not match.\n");
2262 if(!testConvertFromUnicode(hz_inputText2
, sizeof(hz_inputText2
)/sizeof(hz_inputText2
[0]),
2263 to_hz2
, sizeof(to_hz2
), "HZ",
2264 UCNV_FROM_U_CALLBACK_ESCAPE
, from_hzOffs2
, NULL
, 0 ))
2265 log_err("u-> hz with subst with value did not match.\n");
2267 if(!testConvertFromUnicode(iscii_inputText
, sizeof(iscii_inputText
)/sizeof(iscii_inputText
[0]),
2268 to_iscii
, sizeof(to_iscii
), "ISCII,version=0",
2269 UCNV_FROM_U_CALLBACK_ESCAPE
, from_isciiOffs
, NULL
, 0 ))
2270 log_err("u-> iscii with subst with value did not match.\n");
2274 log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_ESCAPE \n");
2277 #if !UCONFIG_NO_LEGACY_CONVERSION
2278 static const uint8_t sampleTxtToU
[]= { 0x00, 0x9f, 0xaf,
2279 0x81, 0xad, /*unassigned*/
2281 static const UChar IBM_943toUnicode
[] = { 0x0000, 0x6D63,
2282 0x25, 0x58, 0x38, 0x31, 0x25, 0x58, 0x41, 0x44,
2284 static const int32_t fromIBM943Offs
[] = { 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 5};
2287 static const uint8_t sampleTxt_EUC_JP
[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
2288 0x8f, 0xda, 0xa1, /*unassigned*/
2291 static const UChar EUC_JPtoUnicode
[]={ 0x0061, 0x4edd, 0x5bec,
2292 0x25, 0x58, 0x38, 0x46, 0x25, 0x58, 0x44, 0x41, 0x25, 0x58, 0x41, 0x31,
2294 static const int32_t fromEUC_JPOffs
[] ={ 0, 1, 3,
2295 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
2300 static const uint8_t sampleTxt_euc_tw
[]={
2301 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
2302 0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
2305 static const UChar euc_twtoUnicode
[]={ 0x0061, 0x2295, 0x5BF2,
2306 0x25, 0x58, 0x38, 0x45, 0x25, 0x58, 0x41, 0x41, 0x25, 0x58, 0x42, 0x42, 0x25, 0x58, 0x43, 0x43,
2308 static const int32_t from_euc_twOffs
[] ={ 0, 1, 3,
2309 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
2313 static const uint8_t sampleTxt_iso_2022_jp
[]={
2314 0x1b, 0x28, 0x42, 0x41,
2315 0x1b, 0x24, 0x42, 0x2A, 0x44, /*unassigned*/
2316 0x1b, 0x28, 0x42, 0x42,
2319 static const UChar iso_2022_jptoUnicode
[]={ 0x41,0x25,0x58,0x32,0x41,0x25,0x58,0x34,0x34, 0x42 };
2320 static const int32_t from_iso_2022_jpOffs
[] ={ 3, 7, 7, 7, 7, 7, 7, 7, 7, 12 };
2323 static const uint8_t sampleTxt_iso_2022_cn
[]={
2325 0x1B, 0x24, 0x29, 0x47,
2326 0x0E, 0x40, 0x6c, /*unassigned*/
2330 static const UChar iso_2022_cntoUnicode
[]={ 0x41, 0x44,0x25,0x58,0x34,0x30,0x25,0x58,0x36,0x43,0x42 };
2331 static const int32_t from_iso_2022_cnOffs
[] ={ 1, 2, 8, 8, 8, 8, 8, 8, 8, 8, 11 };
2334 static const uint8_t sampleTxt_iso_2022_kr
[]={
2335 0x1b, 0x24, 0x29, 0x43,
2343 static const UChar iso_2022_krtoUnicode
[]={ 0x41,0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,0x03A0,0x51, 0x42,0x43};
2344 static const int32_t from_iso_2022_krOffs
[] ={ 4, 6, 6, 6, 6, 6, 6, 6, 6, 9, 12, 13 , 14 };
2347 static const uint8_t sampleTxt_hz
[]={
2349 0x7e, 0x7b, 0x26, 0x30,
2350 0x7f, 0x1E, /*unassigned*/
2353 0x7e, 0x7b, 0x7f, 0x1E,/*unassigned*/
2356 static const UChar hztoUnicode
[]={
2359 0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,
2362 0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,
2365 static const int32_t from_hzOffs
[] ={0,3,5,5,5,5,5,5,5,5,7,11,14,14,14,14,14,14,14,14,18, };
2369 static const uint8_t sampleTxt_iscii
[]={
2372 0xEB, /*unassigned*/
2375 0xEC, /*unassigned*/
2378 static const UChar isciitoUnicode
[]={
2381 0x25, 0x58, 0x45, 0x42,
2384 0x25, 0x58, 0x45, 0x43,
2387 static const int32_t from_isciiOffs
[] ={0,1,2,2,2,2,3,4,5,5,5,5,6 };
2391 static const uint8_t sampleTxtUTF8
[]={
2393 0xC2, 0x7E, /* truncated char */
2395 0xE0, 0xB5, 0x7E, /* truncated char */
2398 static const UChar UTF8ToUnicode
[]={
2399 0x0020, 0x0064, 0x0050,
2400 0x0025, 0x0058, 0x0043, 0x0032, 0x007E, /* \xC2~ */
2402 0x0025, 0x0058, 0x0045, 0x0030, 0x0025, 0x0058, 0x0042, 0x0035, 0x007E,
2405 static const int32_t fromUTF8
[] = {
2409 6, 6, 6, 6, 6, 6, 6, 6, 8,
2412 static const UChar UTF8ToUnicodeXML_DEC
[]={
2413 0x0020, 0x0064, 0x0050,
2414 0x0026, 0x0023, 0x0031, 0x0039, 0x0034, 0x003B, 0x007E, /* Â~ */
2416 0x0026, 0x0023, 0x0032, 0x0032, 0x0034, 0x003B, 0x0026, 0x0023, 0x0031, 0x0038, 0x0031, 0x003B, 0x007E,
2419 static const int32_t fromUTF8XML_DEC
[] = {
2421 3, 3, 3, 3, 3, 3, 4,
2423 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8,
2428 #if !UCONFIG_NO_LEGACY_CONVERSION
2429 if(!testConvertToUnicode(sampleTxtToU
, sizeof(sampleTxtToU
),
2430 IBM_943toUnicode
, sizeof(IBM_943toUnicode
)/sizeof(IBM_943toUnicode
[0]),"ibm-943",
2431 UCNV_TO_U_CALLBACK_ESCAPE
, fromIBM943Offs
, NULL
, 0 ))
2432 log_err("ibm-943->u with substitute with value did not match.\n");
2434 if(!testConvertToUnicode(sampleTxt_EUC_JP
, sizeof(sampleTxt_EUC_JP
),
2435 EUC_JPtoUnicode
, sizeof(EUC_JPtoUnicode
)/sizeof(EUC_JPtoUnicode
[0]),"euc-jp",
2436 UCNV_TO_U_CALLBACK_ESCAPE
, fromEUC_JPOffs
, NULL
, 0))
2437 log_err("euc-jp->u with substitute with value did not match.\n");
2439 if(!testConvertToUnicode(sampleTxt_euc_tw
, sizeof(sampleTxt_euc_tw
),
2440 euc_twtoUnicode
, sizeof(euc_twtoUnicode
)/sizeof(euc_twtoUnicode
[0]),"euc-tw",
2441 UCNV_TO_U_CALLBACK_ESCAPE
, from_euc_twOffs
, NULL
, 0))
2442 log_err("euc-tw->u with substitute with value did not match.\n");
2444 if(!testConvertToUnicode(sampleTxt_iso_2022_jp
, sizeof(sampleTxt_iso_2022_jp
),
2445 iso_2022_jptoUnicode
, sizeof(iso_2022_jptoUnicode
)/sizeof(iso_2022_jptoUnicode
[0]),"iso-2022-jp",
2446 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffs
, NULL
, 0))
2447 log_err("iso-2022-jp->u with substitute with value did not match.\n");
2449 if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp
, sizeof(sampleTxt_iso_2022_jp
),
2450 iso_2022_jptoUnicode
, sizeof(iso_2022_jptoUnicode
)/sizeof(iso_2022_jptoUnicode
[0]),"iso-2022-jp",
2451 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffs
, NULL
, 0,"K",U_ZERO_ERROR
))
2452 log_err("iso-2022-jp->u with substitute with value did not match.\n");
2454 {/* test UCNV_TO_U_CALLBACK_ESCAPE with options */
2456 static const UChar iso_2022_jptoUnicodeDec
[]={
2458 0x0026, 0x0023, 0x0034, 0x0032, 0x003b,
2459 0x0026, 0x0023, 0x0036, 0x0038, 0x003b,
2461 static const int32_t from_iso_2022_jpOffsDec
[] ={ 3,7,7,7,7,7,7,7,7,7,7,12, };
2462 if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp
, sizeof(sampleTxt_iso_2022_jp
),
2463 iso_2022_jptoUnicodeDec
, sizeof(iso_2022_jptoUnicodeDec
)/sizeof(iso_2022_jptoUnicode
[0]),"iso-2022-jp",
2464 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffsDec
, NULL
, 0,UCNV_ESCAPE_XML_DEC
,U_ZERO_ERROR
))
2465 log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_DEC did not match.\n");
2468 static const UChar iso_2022_jptoUnicodeHex
[]={
2470 0x0026, 0x0023, 0x0078, 0x0032, 0x0041, 0x003b,
2471 0x0026, 0x0023, 0x0078, 0x0034, 0x0034, 0x003b,
2473 static const int32_t from_iso_2022_jpOffsHex
[] ={ 3,7,7,7,7,7,7,7,7,7,7,7,7,12 };
2474 if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp
, sizeof(sampleTxt_iso_2022_jp
),
2475 iso_2022_jptoUnicodeHex
, sizeof(iso_2022_jptoUnicodeHex
)/sizeof(iso_2022_jptoUnicode
[0]),"iso-2022-jp",
2476 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffsHex
, NULL
, 0,UCNV_ESCAPE_XML_HEX
,U_ZERO_ERROR
))
2477 log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_HEX did not match.\n");
2480 static const UChar iso_2022_jptoUnicodeC
[]={
2482 0x005C, 0x0078, 0x0032, 0x0041,
2483 0x005C, 0x0078, 0x0034, 0x0034,
2485 int32_t from_iso_2022_jpOffsC
[] ={ 3,7,7,7,7,7,7,7,7,12 };
2486 if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp
, sizeof(sampleTxt_iso_2022_jp
),
2487 iso_2022_jptoUnicodeC
, sizeof(iso_2022_jptoUnicodeC
)/sizeof(iso_2022_jptoUnicode
[0]),"iso-2022-jp",
2488 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_jpOffsC
, NULL
, 0,UCNV_ESCAPE_C
,U_ZERO_ERROR
))
2489 log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_C did not match.\n");
2492 if(!testConvertToUnicode(sampleTxt_iso_2022_cn
, sizeof(sampleTxt_iso_2022_cn
),
2493 iso_2022_cntoUnicode
, sizeof(iso_2022_cntoUnicode
)/sizeof(iso_2022_cntoUnicode
[0]),"iso-2022-cn",
2494 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_cnOffs
, NULL
, 0))
2495 log_err("iso-2022-cn->u with substitute with value did not match.\n");
2497 if(!testConvertToUnicode(sampleTxt_iso_2022_kr
, sizeof(sampleTxt_iso_2022_kr
),
2498 iso_2022_krtoUnicode
, sizeof(iso_2022_krtoUnicode
)/sizeof(iso_2022_krtoUnicode
[0]),"iso-2022-kr",
2499 UCNV_TO_U_CALLBACK_ESCAPE
, from_iso_2022_krOffs
, NULL
, 0))
2500 log_err("iso-2022-kr->u with substitute with value did not match.\n");
2502 if(!testConvertToUnicode(sampleTxt_hz
, sizeof(sampleTxt_hz
),
2503 hztoUnicode
, sizeof(hztoUnicode
)/sizeof(hztoUnicode
[0]),"HZ",
2504 UCNV_TO_U_CALLBACK_ESCAPE
, from_hzOffs
, NULL
, 0))
2505 log_err("hz->u with substitute with value did not match.\n");
2507 if(!testConvertToUnicode(sampleTxt_iscii
, sizeof(sampleTxt_iscii
),
2508 isciitoUnicode
, sizeof(isciitoUnicode
)/sizeof(isciitoUnicode
[0]),"ISCII,version=0",
2509 UCNV_TO_U_CALLBACK_ESCAPE
, from_isciiOffs
, NULL
, 0))
2510 log_err("ISCII ->u with substitute with value did not match.\n");
2513 if(!testConvertToUnicode(sampleTxtUTF8
, sizeof(sampleTxtUTF8
),
2514 UTF8ToUnicode
, sizeof(UTF8ToUnicode
)/sizeof(UTF8ToUnicode
[0]),"UTF-8",
2515 UCNV_TO_U_CALLBACK_ESCAPE
, fromUTF8
, NULL
, 0))
2516 log_err("UTF8->u with UCNV_TO_U_CALLBACK_ESCAPE with value did not match.\n");
2517 if(!testConvertToUnicodeWithContext(sampleTxtUTF8
, sizeof(sampleTxtUTF8
),
2518 UTF8ToUnicodeXML_DEC
, sizeof(UTF8ToUnicodeXML_DEC
)/sizeof(UTF8ToUnicodeXML_DEC
[0]),"UTF-8",
2519 UCNV_TO_U_CALLBACK_ESCAPE
, fromUTF8XML_DEC
, NULL
, 0, UCNV_ESCAPE_XML_DEC
, U_ZERO_ERROR
))
2520 log_err("UTF8->u with UCNV_TO_U_CALLBACK_ESCAPE with value did not match.\n");
2524 #if !UCONFIG_NO_LEGACY_CONVERSION
2525 static void TestLegalAndOthers(int32_t inputsize
, int32_t outputsize
)
2527 static const UChar legalText
[] = { 0x0000, 0xAC00, 0xAC01, 0xD700 };
2528 static const uint8_t templegal949
[] ={ 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xc8, 0xd3 };
2529 static const int32_t to949legal
[] = {0, 1, 1, 2, 2, 3, 3};
2532 static const uint8_t text943
[] = {
2533 0x82, 0xa9, 0x82, 0x20, 0x61, 0x8a, 0xbf, 0x8e, 0x9a };
2534 static const UChar toUnicode943sub
[] = { 0x304b, 0x1a, 0x20, 0x0061, 0x6f22, 0x5b57 };
2535 static const UChar toUnicode943skip
[]= { 0x304b, 0x20, 0x0061, 0x6f22, 0x5b57 };
2536 static const UChar toUnicode943stop
[]= { 0x304b};
2538 static const int32_t fromIBM943Offssub
[] = { 0, 2, 3, 4, 5, 7 };
2539 static const int32_t fromIBM943Offsskip
[] = { 0, 3, 4, 5, 7 };
2540 static const int32_t fromIBM943Offsstop
[] = { 0};
2542 gInBufferSize
= inputsize
;
2543 gOutBufferSize
= outputsize
;
2544 /*checking with a legal value*/
2545 if(!testConvertFromUnicode(legalText
, sizeof(legalText
)/sizeof(legalText
[0]),
2546 templegal949
, sizeof(templegal949
), "ibm-949",
2547 UCNV_FROM_U_CALLBACK_SKIP
, to949legal
, NULL
, 0 ))
2548 log_err("u-> ibm-949 with skip did not match.\n");
2550 /*checking illegal value for ibm-943 with substitute*/
2551 if(!testConvertToUnicode(text943
, sizeof(text943
),
2552 toUnicode943sub
, sizeof(toUnicode943sub
)/sizeof(toUnicode943sub
[0]),"ibm-943",
2553 UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromIBM943Offssub
, NULL
, 0 ))
2554 log_err("ibm-943->u with subst did not match.\n");
2555 /*checking illegal value for ibm-943 with skip */
2556 if(!testConvertToUnicode(text943
, sizeof(text943
),
2557 toUnicode943skip
, sizeof(toUnicode943skip
)/sizeof(toUnicode943skip
[0]),"ibm-943",
2558 UCNV_TO_U_CALLBACK_SKIP
, fromIBM943Offsskip
, NULL
, 0 ))
2559 log_err("ibm-943->u with skip did not match.\n");
2561 /*checking illegal value for ibm-943 with stop */
2562 if(!testConvertToUnicode(text943
, sizeof(text943
),
2563 toUnicode943stop
, sizeof(toUnicode943stop
)/sizeof(toUnicode943stop
[0]),"ibm-943",
2564 UCNV_TO_U_CALLBACK_STOP
, fromIBM943Offsstop
, NULL
, 0 ))
2565 log_err("ibm-943->u with stop did not match.\n");
2569 static void TestSingleByte(int32_t inputsize
, int32_t outputsize
)
2571 static const uint8_t sampleText
[] = {
2572 0x82, 0xa9, 0x61, 0x62, 0x63 , 0x82,
2574 static const UChar toUnicode943sub
[] = { 0x304b, 0x0061, 0x0062, 0x0063, 0x1a, 0x1a, 0x0032, 0x0033 };
2575 static const int32_t fromIBM943Offssub
[] = { 0, 2, 3, 4, 5, 6, 7, 8 };
2576 /*checking illegal value for ibm-943 with substitute*/
2577 gInBufferSize
= inputsize
;
2578 gOutBufferSize
= outputsize
;
2580 if(!testConvertToUnicode(sampleText
, sizeof(sampleText
),
2581 toUnicode943sub
, sizeof(toUnicode943sub
)/sizeof(toUnicode943sub
[0]),"ibm-943",
2582 UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromIBM943Offssub
, NULL
, 0 ))
2583 log_err("ibm-943->u with subst did not match.\n");
2586 static void TestEBCDIC_STATEFUL_Sub(int32_t inputsize
, int32_t outputsize
)
2589 static const UChar ebcdic_inputTest
[] = { 0x0061, 0x6d64, 0x0061, 0x00A2, 0x6d65, 0x0061 };
2590 static const uint8_t toIBM930
[]= { 0x62, 0x0e, 0x5d, 0x63, 0x0f, 0x62, 0xb1, 0x0e, 0xfe, 0xfe, 0x0f, 0x62 };
2591 static const int32_t offset_930
[]= { 0, 1, 1, 1, 2, 2, 3, 4, 4, 4, 5, 5 };
2592 /* s SO doubl SI sng s SO fe fe SI s */
2594 /*EBCDIC_STATEFUL with subChar=3f*/
2595 static const uint8_t toIBM930_subvaried
[]= { 0x62, 0x0e, 0x5d, 0x63, 0x0f, 0x62, 0xb1, 0x3f, 0x62 };
2596 static const int32_t offset_930_subvaried
[]= { 0, 1, 1, 1, 2, 2, 3, 4, 5 };
2597 static const char mySubChar
[]={ 0x3f};
2599 gInBufferSize
= inputsize
;
2600 gOutBufferSize
= outputsize
;
2602 if(!testConvertFromUnicode(ebcdic_inputTest
, sizeof(ebcdic_inputTest
)/sizeof(ebcdic_inputTest
[0]),
2603 toIBM930
, sizeof(toIBM930
), "ibm-930",
2604 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offset_930
, NULL
, 0 ))
2605 log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst did not match.\n");
2607 if(!testConvertFromUnicode(ebcdic_inputTest
, sizeof(ebcdic_inputTest
)/sizeof(ebcdic_inputTest
[0]),
2608 toIBM930_subvaried
, sizeof(toIBM930_subvaried
), "ibm-930",
2609 UCNV_FROM_U_CALLBACK_SUBSTITUTE
, offset_930_subvaried
, mySubChar
, 1 ))
2610 log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst(setSubChar=0x3f) did not match.\n");
2614 UBool
testConvertFromUnicode(const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
2615 const char *codepage
, UConverterFromUCallback callback
, const int32_t *expectOffsets
,
2616 const char *mySubChar
, int8_t len
)
2620 UErrorCode status
= U_ZERO_ERROR
;
2621 UConverter
*conv
= 0;
2622 char junkout
[NEW_MAX_BUFFER
]; /* FIX */
2623 int32_t junokout
[NEW_MAX_BUFFER
]; /* FIX */
2629 int32_t realBufferSize
;
2630 char *realBufferEnd
;
2631 const UChar
*realSourceEnd
;
2632 const UChar
*sourceLimit
;
2633 UBool checkOffsets
= TRUE
;
2636 char offset_str
[9999];
2638 UConverterFromUCallback oldAction
= NULL
;
2639 const void* oldContext
= NULL
;
2642 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
2643 junkout
[i
] = (char)0xF0;
2644 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
2646 setNuConvTestName(codepage
, "FROM");
2648 log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage
, gInBufferSize
,
2651 conv
= ucnv_open(codepage
, &status
);
2652 if(U_FAILURE(status
))
2654 log_data_err("Couldn't open converter %s\n",codepage
);
2658 log_verbose("Converter opened..\n");
2660 /*----setting the callback routine----*/
2661 ucnv_setFromUCallBack (conv
, callback
, NULL
, &oldAction
, &oldContext
, &status
);
2662 if (U_FAILURE(status
))
2664 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
2666 /*------------------------*/
2667 /*setting the subChar*/
2668 if(mySubChar
!= NULL
){
2669 ucnv_setSubstChars(conv
, mySubChar
, len
, &status
);
2670 if (U_FAILURE(status
)) {
2671 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
2680 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
2681 realBufferEnd
= junkout
+ realBufferSize
;
2682 realSourceEnd
= source
+ sourceLen
;
2684 if ( gOutBufferSize
!= realBufferSize
)
2685 checkOffsets
= FALSE
;
2687 if( gInBufferSize
!= NEW_MAX_BUFFER
)
2688 checkOffsets
= FALSE
;
2692 end
= nct_min(targ
+ gOutBufferSize
, realBufferEnd
);
2693 sourceLimit
= nct_min(src
+ gInBufferSize
, realSourceEnd
);
2695 doFlush
= (UBool
)(sourceLimit
== realSourceEnd
);
2697 if(targ
== realBufferEnd
)
2699 log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ
, gNuConvTestName
);
2702 log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src
,sourceLimit
, targ
,end
, doFlush
?"TRUE":"FALSE");
2705 status
= U_ZERO_ERROR
;
2707 ucnv_fromUnicode (conv
,
2712 checkOffsets
? offs
: NULL
,
2713 doFlush
, /* flush if we're at the end of the input data */
2715 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (U_SUCCESS(status
) && (sourceLimit
< realSourceEnd
)) );
2718 if(status
==U_INVALID_CHAR_FOUND
|| status
== U_ILLEGAL_CHAR_FOUND
){
2719 UChar errChars
[50]; /* should be sufficient */
2721 UErrorCode err
= U_ZERO_ERROR
;
2722 const UChar
* limit
= NULL
;
2723 const UChar
* start
= NULL
;
2724 ucnv_getInvalidUChars(conv
,errChars
, &errLen
, &err
);
2726 log_err("ucnv_getInvalidUChars failed with error : %s\n",u_errorName(err
));
2728 /* src points to limit of invalid chars */
2730 /* length of in invalid chars should be equal to returned length*/
2731 start
= src
- errLen
;
2732 if(u_strncmp(errChars
,start
,errLen
)!=0){
2733 log_err("ucnv_getInvalidUChars did not return the correct invalid chars for encoding %s \n", ucnv_getName(conv
,&err
));
2736 /* allow failure codes for the stop callback */
2737 if(U_FAILURE(status
) &&
2738 (callback
!= UCNV_FROM_U_CALLBACK_STOP
|| (status
!= U_INVALID_CHAR_FOUND
&& status
!= U_ILLEGAL_CHAR_FOUND
)))
2740 log_err("Problem in fromUnicode, errcode %s %s\n", myErrorName(status
), gNuConvTestName
);
2744 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
2745 sourceLen
, targ
-junkout
);
2746 if(getTestOption(VERBOSITY_OPTION
))
2751 for(p
= junkout
;p
<targ
;p
++)
2753 sprintf(junk
+ strlen(junk
), "0x%02x, ", (0xFF) & (unsigned int)*p
);
2754 sprintf(offset_str
+ strlen(offset_str
), "0x%02x, ", (0xFF) & (unsigned int)junokout
[p
-junkout
]);
2758 printSeq(expect
, expectLen
);
2761 log_verbose("\nOffsets:");
2762 log_verbose(offset_str
);
2769 if(expectLen
!= targ
-junkout
)
2771 log_err("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
2772 log_verbose("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
2773 printSeqErr((const uint8_t *)junkout
, (int32_t)(targ
-junkout
));
2774 printSeqErr(expect
, expectLen
);
2778 if (checkOffsets
&& (expectOffsets
!= 0) )
2780 log_verbose("comparing %d offsets..\n", targ
-junkout
);
2781 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t) )){
2782 log_err("did not get the expected offsets while %s \n", gNuConvTestName
);
2783 log_err("Got Output : ");
2784 printSeqErr((const uint8_t *)junkout
, (int32_t)(targ
-junkout
));
2785 log_err("Got Offsets: ");
2786 for(p
=junkout
;p
<targ
;p
++)
2787 log_err("%d,", junokout
[p
-junkout
]);
2789 log_err("Expected Offsets: ");
2790 for(i
=0; i
<(targ
-junkout
); i
++)
2791 log_err("%d,", expectOffsets
[i
]);
2797 if(!memcmp(junkout
, expect
, expectLen
))
2799 log_verbose("String matches! %s\n", gNuConvTestName
);
2804 log_err("String does not match. %s\n", gNuConvTestName
);
2805 log_err("source: ");
2806 printUSeqErr(source
, sourceLen
);
2808 printSeqErr((const uint8_t *)junkout
, expectLen
);
2809 log_err("Expected: ");
2810 printSeqErr(expect
, expectLen
);
2815 UBool
testConvertToUnicode( const uint8_t *source
, int sourcelen
, const UChar
*expect
, int expectlen
,
2816 const char *codepage
, UConverterToUCallback callback
, const int32_t *expectOffsets
,
2817 const char *mySubChar
, int8_t len
)
2819 UErrorCode status
= U_ZERO_ERROR
;
2820 UConverter
*conv
= 0;
2821 UChar junkout
[NEW_MAX_BUFFER
]; /* FIX */
2822 int32_t junokout
[NEW_MAX_BUFFER
]; /* FIX */
2824 const char *realSourceEnd
;
2825 const char *srcLimit
;
2830 UBool checkOffsets
= TRUE
;
2832 char offset_str
[9999];
2834 UConverterToUCallback oldAction
= NULL
;
2835 const void* oldContext
= NULL
;
2837 int32_t realBufferSize
;
2838 UChar
*realBufferEnd
;
2841 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
2842 junkout
[i
] = 0xFFFE;
2844 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
2847 setNuConvTestName(codepage
, "TO");
2849 log_verbose("\n========= %s\n", gNuConvTestName
);
2851 conv
= ucnv_open(codepage
, &status
);
2852 if(U_FAILURE(status
))
2854 log_data_err("Couldn't open converter %s\n",gNuConvTestName
);
2858 log_verbose("Converter opened..\n");
2860 src
= (const char *)source
;
2864 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
2865 realBufferEnd
= junkout
+ realBufferSize
;
2866 realSourceEnd
= src
+ sourcelen
;
2867 /*----setting the callback routine----*/
2868 ucnv_setToUCallBack (conv
, callback
, NULL
, &oldAction
, &oldContext
, &status
);
2869 if (U_FAILURE(status
))
2871 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
2873 /*-------------------------------------*/
2874 /*setting the subChar*/
2875 if(mySubChar
!= NULL
){
2876 ucnv_setSubstChars(conv
, mySubChar
, len
, &status
);
2877 if (U_FAILURE(status
)) {
2878 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
2884 if ( gOutBufferSize
!= realBufferSize
)
2885 checkOffsets
= FALSE
;
2887 if( gInBufferSize
!= NEW_MAX_BUFFER
)
2888 checkOffsets
= FALSE
;
2892 end
= nct_min( targ
+ gOutBufferSize
, realBufferEnd
);
2893 srcLimit
= nct_min(realSourceEnd
, src
+ gInBufferSize
);
2895 if(targ
== realBufferEnd
)
2897 log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ
,gNuConvTestName
);
2900 log_verbose("calling toUnicode @ %08lx to %08lx\n", targ
,end
);
2904 status
= U_ZERO_ERROR
;
2906 ucnv_toUnicode (conv
,
2909 (const char **)&src
,
2910 (const char *)srcLimit
,
2911 checkOffsets
? offs
: NULL
,
2912 (UBool
)(srcLimit
== realSourceEnd
), /* flush if we're at the end of the source data */
2914 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (U_SUCCESS(status
) && (srcLimit
< realSourceEnd
)) ); /* while we just need another buffer */
2916 if(status
==U_INVALID_CHAR_FOUND
|| status
== U_ILLEGAL_CHAR_FOUND
){
2917 char errChars
[50]; /* should be sufficient */
2919 UErrorCode err
= U_ZERO_ERROR
;
2920 const char* limit
= NULL
;
2921 const char* start
= NULL
;
2922 ucnv_getInvalidChars(conv
,errChars
, &errLen
, &err
);
2924 log_err("ucnv_getInvalidChars failed with error : %s\n",u_errorName(err
));
2926 /* src points to limit of invalid chars */
2928 /* length of in invalid chars should be equal to returned length*/
2929 start
= src
- errLen
;
2930 if(uprv_strncmp(errChars
,start
,errLen
)!=0){
2931 log_err("ucnv_getInvalidChars did not return the correct invalid chars for encoding %s \n", ucnv_getName(conv
,&err
));
2934 /* allow failure codes for the stop callback */
2935 if(U_FAILURE(status
) &&
2936 (callback
!= UCNV_TO_U_CALLBACK_STOP
|| (status
!= U_INVALID_CHAR_FOUND
&& status
!= U_ILLEGAL_CHAR_FOUND
&& status
!= U_TRUNCATED_CHAR_FOUND
)))
2938 log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status
), gNuConvTestName
);
2942 log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
2943 sourcelen
, targ
-junkout
);
2944 if(getTestOption(VERBOSITY_OPTION
))
2950 for(p
= junkout
;p
<targ
;p
++)
2952 sprintf(junk
+ strlen(junk
), "0x%04x, ", (0xFFFF) & (unsigned int)*p
);
2953 sprintf(offset_str
+ strlen(offset_str
), "0x%04x, ", (0xFFFF) & (unsigned int)junokout
[p
-junkout
]);
2957 printUSeq(expect
, expectlen
);
2960 log_verbose("\nOffsets:");
2961 log_verbose(offset_str
);
2967 log_verbose("comparing %d uchars (%d bytes)..\n",expectlen
,expectlen
*2);
2969 if (checkOffsets
&& (expectOffsets
!= 0))
2971 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t)))
2973 log_err("did not get the expected offsets while %s \n", gNuConvTestName
);
2974 log_err("Got offsets: ");
2975 for(p
=junkout
;p
<targ
;p
++)
2976 log_err(" %2d,", junokout
[p
-junkout
]);
2978 log_err("Expected offsets: ");
2979 for(i
=0; i
<(targ
-junkout
); i
++)
2980 log_err(" %2d,", expectOffsets
[i
]);
2982 log_err("Got output: ");
2983 for(i
=0; i
<(targ
-junkout
); i
++)
2984 log_err("0x%04x,", junkout
[i
]);
2986 log_err("From source: ");
2987 for(i
=0; i
<(src
-(const char *)source
); i
++)
2988 log_err(" 0x%02x,", (unsigned char)source
[i
]);
2993 if(!memcmp(junkout
, expect
, expectlen
*2))
2995 log_verbose("Matches!\n");
3000 log_err("String does not match. %s\n", gNuConvTestName
);
3001 log_verbose("String does not match. %s\n", gNuConvTestName
);
3003 printUSeqErr(junkout
, expectlen
);
3004 log_err("Expected: ");
3005 printUSeqErr(expect
, expectlen
);
3011 UBool
testConvertFromUnicodeWithContext(const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
3012 const char *codepage
, UConverterFromUCallback callback
, const int32_t *expectOffsets
,
3013 const char *mySubChar
, int8_t len
, const void* context
, UErrorCode expectedError
)
3017 UErrorCode status
= U_ZERO_ERROR
;
3018 UConverter
*conv
= 0;
3019 char junkout
[NEW_MAX_BUFFER
]; /* FIX */
3020 int32_t junokout
[NEW_MAX_BUFFER
]; /* FIX */
3026 int32_t realBufferSize
;
3027 char *realBufferEnd
;
3028 const UChar
*realSourceEnd
;
3029 const UChar
*sourceLimit
;
3030 UBool checkOffsets
= TRUE
;
3033 char offset_str
[9999];
3035 UConverterFromUCallback oldAction
= NULL
;
3036 const void* oldContext
= NULL
;
3039 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
3040 junkout
[i
] = (char)0xF0;
3041 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
3043 setNuConvTestName(codepage
, "FROM");
3045 log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage
, gInBufferSize
,
3048 conv
= ucnv_open(codepage
, &status
);
3049 if(U_FAILURE(status
))
3051 log_data_err("Couldn't open converter %s\n",codepage
);
3052 return TRUE
; /* Because the err has already been logged. */
3055 log_verbose("Converter opened..\n");
3057 /*----setting the callback routine----*/
3058 ucnv_setFromUCallBack (conv
, callback
, context
, &oldAction
, &oldContext
, &status
);
3059 if (U_FAILURE(status
))
3061 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
3063 /*------------------------*/
3064 /*setting the subChar*/
3065 if(mySubChar
!= NULL
){
3066 ucnv_setSubstChars(conv
, mySubChar
, len
, &status
);
3067 if (U_FAILURE(status
)) {
3068 log_err("FAILURE in setting substitution chars! %s\n", myErrorName(status
));
3077 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
3078 realBufferEnd
= junkout
+ realBufferSize
;
3079 realSourceEnd
= source
+ sourceLen
;
3081 if ( gOutBufferSize
!= realBufferSize
)
3082 checkOffsets
= FALSE
;
3084 if( gInBufferSize
!= NEW_MAX_BUFFER
)
3085 checkOffsets
= FALSE
;
3089 end
= nct_min(targ
+ gOutBufferSize
, realBufferEnd
);
3090 sourceLimit
= nct_min(src
+ gInBufferSize
, realSourceEnd
);
3092 doFlush
= (UBool
)(sourceLimit
== realSourceEnd
);
3094 if(targ
== realBufferEnd
)
3096 log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ
, gNuConvTestName
);
3099 log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src
,sourceLimit
, targ
,end
, doFlush
?"TRUE":"FALSE");
3102 status
= U_ZERO_ERROR
;
3104 ucnv_fromUnicode (conv
,
3109 checkOffsets
? offs
: NULL
,
3110 doFlush
, /* flush if we're at the end of the input data */
3112 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (U_SUCCESS(status
) && (sourceLimit
< realSourceEnd
)) );
3114 /* allow failure codes for the stop callback */
3115 if(U_FAILURE(status
) && status
!= expectedError
)
3117 log_err("Problem in fromUnicode, errcode %s %s\n", myErrorName(status
), gNuConvTestName
);
3121 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
3122 sourceLen
, targ
-junkout
);
3123 if(getTestOption(VERBOSITY_OPTION
))
3128 for(p
= junkout
;p
<targ
;p
++)
3130 sprintf(junk
+ strlen(junk
), "0x%02x, ", (0xFF) & (unsigned int)*p
);
3131 sprintf(offset_str
+ strlen(offset_str
), "0x%02x, ", (0xFF) & (unsigned int)junokout
[p
-junkout
]);
3135 printSeq(expect
, expectLen
);
3138 log_verbose("\nOffsets:");
3139 log_verbose(offset_str
);
3146 if(expectLen
!= targ
-junkout
)
3148 log_err("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
3149 log_verbose("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
3150 printSeqErr((const uint8_t *)junkout
, (int32_t)(targ
-junkout
));
3151 printSeqErr(expect
, expectLen
);
3155 if (checkOffsets
&& (expectOffsets
!= 0) )
3157 log_verbose("comparing %d offsets..\n", targ
-junkout
);
3158 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t) )){
3159 log_err("did not get the expected offsets while %s \n", gNuConvTestName
);
3160 log_err("Got Output : ");
3161 printSeqErr((const uint8_t *)junkout
, (int32_t)(targ
-junkout
));
3162 log_err("Got Offsets: ");
3163 for(p
=junkout
;p
<targ
;p
++)
3164 log_err("%d,", junokout
[p
-junkout
]);
3166 log_err("Expected Offsets: ");
3167 for(i
=0; i
<(targ
-junkout
); i
++)
3168 log_err("%d,", expectOffsets
[i
]);
3174 if(!memcmp(junkout
, expect
, expectLen
))
3176 log_verbose("String matches! %s\n", gNuConvTestName
);
3181 log_err("String does not match. %s\n", gNuConvTestName
);
3182 log_err("source: ");
3183 printUSeqErr(source
, sourceLen
);
3185 printSeqErr((const uint8_t *)junkout
, expectLen
);
3186 log_err("Expected: ");
3187 printSeqErr(expect
, expectLen
);
3191 UBool
testConvertToUnicodeWithContext( const uint8_t *source
, int sourcelen
, const UChar
*expect
, int expectlen
,
3192 const char *codepage
, UConverterToUCallback callback
, const int32_t *expectOffsets
,
3193 const char *mySubChar
, int8_t len
, const void* context
, UErrorCode expectedError
)
3195 UErrorCode status
= U_ZERO_ERROR
;
3196 UConverter
*conv
= 0;
3197 UChar junkout
[NEW_MAX_BUFFER
]; /* FIX */
3198 int32_t junokout
[NEW_MAX_BUFFER
]; /* FIX */
3200 const char *realSourceEnd
;
3201 const char *srcLimit
;
3206 UBool checkOffsets
= TRUE
;
3208 char offset_str
[9999];
3210 UConverterToUCallback oldAction
= NULL
;
3211 const void* oldContext
= NULL
;
3213 int32_t realBufferSize
;
3214 UChar
*realBufferEnd
;
3217 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
3218 junkout
[i
] = 0xFFFE;
3220 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
3223 setNuConvTestName(codepage
, "TO");
3225 log_verbose("\n========= %s\n", gNuConvTestName
);
3227 conv
= ucnv_open(codepage
, &status
);
3228 if(U_FAILURE(status
))
3230 log_data_err("Couldn't open converter %s\n",gNuConvTestName
);
3234 log_verbose("Converter opened..\n");
3236 src
= (const char *)source
;
3240 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
3241 realBufferEnd
= junkout
+ realBufferSize
;
3242 realSourceEnd
= src
+ sourcelen
;
3243 /*----setting the callback routine----*/
3244 ucnv_setToUCallBack (conv
, callback
, context
, &oldAction
, &oldContext
, &status
);
3245 if (U_FAILURE(status
))
3247 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
3249 /*-------------------------------------*/
3250 /*setting the subChar*/
3251 if(mySubChar
!= NULL
){
3252 ucnv_setSubstChars(conv
, mySubChar
, len
, &status
);
3253 if (U_FAILURE(status
)) {
3254 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
3260 if ( gOutBufferSize
!= realBufferSize
)
3261 checkOffsets
= FALSE
;
3263 if( gInBufferSize
!= NEW_MAX_BUFFER
)
3264 checkOffsets
= FALSE
;
3268 end
= nct_min( targ
+ gOutBufferSize
, realBufferEnd
);
3269 srcLimit
= nct_min(realSourceEnd
, src
+ gInBufferSize
);
3271 if(targ
== realBufferEnd
)
3273 log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ
,gNuConvTestName
);
3276 log_verbose("calling toUnicode @ %08lx to %08lx\n", targ
,end
);
3280 status
= U_ZERO_ERROR
;
3282 ucnv_toUnicode (conv
,
3285 (const char **)&src
,
3286 (const char *)srcLimit
,
3287 checkOffsets
? offs
: NULL
,
3288 (UBool
)(srcLimit
== realSourceEnd
), /* flush if we're at the end of the source data */
3290 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (U_SUCCESS(status
) && (srcLimit
< realSourceEnd
)) ); /* while we just need another buffer */
3292 /* allow failure codes for the stop callback */
3293 if(U_FAILURE(status
) && status
!=expectedError
)
3295 log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status
), gNuConvTestName
);
3299 log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
3300 sourcelen
, targ
-junkout
);
3301 if(getTestOption(VERBOSITY_OPTION
))
3307 for(p
= junkout
;p
<targ
;p
++)
3309 sprintf(junk
+ strlen(junk
), "0x%04x, ", (0xFFFF) & (unsigned int)*p
);
3310 sprintf(offset_str
+ strlen(offset_str
), "0x%04x, ", (0xFFFF) & (unsigned int)junokout
[p
-junkout
]);
3314 printUSeq(expect
, expectlen
);
3317 log_verbose("\nOffsets:");
3318 log_verbose(offset_str
);
3324 log_verbose("comparing %d uchars (%d bytes)..\n",expectlen
,expectlen
*2);
3326 if (checkOffsets
&& (expectOffsets
!= 0))
3328 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t)))
3330 log_err("did not get the expected offsets while %s \n", gNuConvTestName
);
3331 log_err("Got offsets: ");
3332 for(p
=junkout
;p
<targ
;p
++)
3333 log_err(" %2d,", junokout
[p
-junkout
]);
3335 log_err("Expected offsets: ");
3336 for(i
=0; i
<(targ
-junkout
); i
++)
3337 log_err(" %2d,", expectOffsets
[i
]);
3339 log_err("Got output: ");
3340 for(i
=0; i
<(targ
-junkout
); i
++)
3341 log_err("0x%04x,", junkout
[i
]);
3343 log_err("From source: ");
3344 for(i
=0; i
<(src
-(const char *)source
); i
++)
3345 log_err(" 0x%02x,", (unsigned char)source
[i
]);
3350 if(!memcmp(junkout
, expect
, expectlen
*2))
3352 log_verbose("Matches!\n");
3357 log_err("String does not match. %s\n", gNuConvTestName
);
3358 log_verbose("String does not match. %s\n", gNuConvTestName
);
3360 printUSeqErr(junkout
, expectlen
);
3361 log_err("Expected: ");
3362 printUSeqErr(expect
, expectlen
);
3368 static void TestCallBackFailure(void) {
3369 UErrorCode status
= U_USELESS_COLLATOR_ERROR
;
3370 ucnv_cbFromUWriteBytes(NULL
, NULL
, -1, -1, &status
);
3371 if (status
!= U_USELESS_COLLATOR_ERROR
) {
3372 log_err("Error: ucnv_cbFromUWriteBytes did not react correctly to a bad UErrorCode\n");
3374 ucnv_cbFromUWriteUChars(NULL
, NULL
, NULL
, -1, &status
);
3375 if (status
!= U_USELESS_COLLATOR_ERROR
) {
3376 log_err("Error: ucnv_cbFromUWriteUChars did not react correctly to a bad UErrorCode\n");
3378 ucnv_cbFromUWriteSub(NULL
, -1, &status
);
3379 if (status
!= U_USELESS_COLLATOR_ERROR
) {
3380 log_err("Error: ucnv_cbFromUWriteSub did not react correctly to a bad UErrorCode\n");
3382 ucnv_cbToUWriteUChars(NULL
, NULL
, -1, -1, &status
);
3383 if (status
!= U_USELESS_COLLATOR_ERROR
) {
3384 log_err("Error: ucnv_cbToUWriteUChars did not react correctly to a bad UErrorCode\n");