1 /********************************************************************
3 * Copyright (c) 1997-2007, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /*****************************************************************************
10 * Modification History:
12 * Madhu Katragadda 7/7/2000 Converter Tests for extended code coverage
13 ******************************************************************************
18 #include "unicode/uloc.h"
19 #include "unicode/ucnv.h"
20 #include "unicode/utypes.h"
21 #include "unicode/ustring.h"
22 #include "unicode/uset.h"
25 #define MAX_LENGTH 999
27 #define UNICODE_LIMIT 0x10FFFF
28 #define SURROGATE_HIGH_START 0xD800
29 #define SURROGATE_LOW_END 0xDFFF
31 static int32_t gInBufferSize
= 0;
32 static int32_t gOutBufferSize
= 0;
33 static char gNuConvTestName
[1024];
35 #define nct_min(x,y) ((x<y) ? x : y)
36 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
38 static void printSeq(const unsigned char* a
, int len
);
39 static void printSeqErr(const unsigned char* a
, int len
);
40 static void printUSeq(const UChar
* a
, int len
);
41 static void printUSeqErr(const UChar
* a
, int len
);
42 static UBool
convertFromU( const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
43 const char *codepage
, const int32_t *expectOffsets
, UBool doFlush
, UErrorCode expectedStatus
);
44 static UBool
convertToU( const uint8_t *source
, int sourceLen
, const UChar
*expect
, int expectLen
,
45 const char *codepage
, const int32_t *expectOffsets
, UBool doFlush
, UErrorCode expectedStatus
);
47 static UBool
testConvertFromU( const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
48 const char *codepage
, UConverterFromUCallback callback
, const int32_t *expectOffsets
, UBool testReset
);
49 static UBool
testConvertToU( const uint8_t *source
, int sourcelen
, const UChar
*expect
, int expectlen
,
50 const char *codepage
, UConverterToUCallback callback
, const int32_t *expectOffsets
, UBool testReset
);
52 static void setNuConvTestName(const char *codepage
, const char *direction
)
54 sprintf(gNuConvTestName
, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
62 static void TestSurrogateBehaviour(void);
63 static void TestErrorBehaviour(void);
65 #if !UCONFIG_NO_LEGACY_CONVERSION
66 static void TestToUnicodeErrorBehaviour(void);
67 static void TestGetNextErrorBehaviour(void);
70 static void TestRegressionUTF8(void);
71 static void TestRegressionUTF32(void);
72 static void TestAvailableConverters(void);
73 static void TestFlushInternalBuffer(void); /*for improved code coverage in ucnv_cnv.c*/
74 static void TestResetBehaviour(void);
75 static void TestTruncated(void);
76 static void TestUnicodeSet(void);
78 static void TestWithBufferSize(int32_t osize
, int32_t isize
);
81 static void printSeq(const unsigned char* a
, int len
)
86 log_verbose("0x%02X ", a
[i
++]);
90 static void printUSeq(const UChar
* a
, int len
)
95 log_verbose("%0x04X ", a
[i
++]);
99 static void printSeqErr(const unsigned char* a
, int len
)
102 fprintf(stderr
, "\n{");
103 while (i
<len
) fprintf(stderr
, "0x%02X ", a
[i
++]);
104 fprintf(stderr
, "}\n");
107 static void printUSeqErr(const UChar
* a
, int len
)
110 fprintf(stderr
, "\n{");
112 fprintf(stderr
, "0x%04X ", a
[i
++]);
113 fprintf(stderr
,"}\n");
116 void addExtraTests(TestNode
** root
);
118 void addExtraTests(TestNode
** root
)
120 addTest(root
, &TestSurrogateBehaviour
, "tsconv/ncnvtst/TestSurrogateBehaviour");
121 addTest(root
, &TestErrorBehaviour
, "tsconv/ncnvtst/TestErrorBehaviour");
123 #if !UCONFIG_NO_LEGACY_CONVERSION
124 addTest(root
, &TestToUnicodeErrorBehaviour
, "tsconv/ncnvtst/ToUnicodeErrorBehaviour");
125 addTest(root
, &TestGetNextErrorBehaviour
, "tsconv/ncnvtst/TestGetNextErrorBehaviour");
128 addTest(root
, &TestAvailableConverters
, "tsconv/ncnvtst/TestAvailableConverters");
129 addTest(root
, &TestFlushInternalBuffer
, "tsconv/ncnvtst/TestFlushInternalBuffer");
130 addTest(root
, &TestResetBehaviour
, "tsconv/ncnvtst/TestResetBehaviour");
131 addTest(root
, &TestRegressionUTF8
, "tsconv/ncnvtst/TestRegressionUTF8");
132 addTest(root
, &TestRegressionUTF32
, "tsconv/ncnvtst/TestRegressionUTF32");
133 addTest(root
, &TestTruncated
, "tsconv/ncnvtst/TestTruncated");
134 addTest(root
, &TestUnicodeSet
, "tsconv/ncnvtst/TestUnicodeSet");
137 /*test surrogate behaviour*/
138 static void TestSurrogateBehaviour(){
139 log_verbose("Testing for SBCS and LATIN_1\n");
141 UChar sampleText
[] = {0x0031, 0xd801, 0xdc01, 0x0032};
142 const uint8_t expected
[] = {0x31, 0x1a, 0x32};
144 #if !UCONFIG_NO_LEGACY_CONVERSION
146 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
147 expected
, sizeof(expected
), "ibm-920", 0 , TRUE
, U_ZERO_ERROR
))
148 log_err("u-> ibm-920 [UCNV_SBCS] not match.\n");
152 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
153 expected
, sizeof(expected
), "LATIN_1", 0, TRUE
, U_ZERO_ERROR
))
154 log_err("u-> LATIN_1 not match.\n");
158 #if !UCONFIG_NO_LEGACY_CONVERSION
159 log_verbose("Testing for DBCS and MBCS\n");
161 UChar sampleText
[] = {0x00a1, 0xd801, 0xdc01, 0x00a4};
162 const uint8_t expected
[] = {0xa2, 0xae, 0xa1, 0xe0, 0xa2, 0xb4};
163 int32_t offsets
[] = {0x00, 0x00, 0x01, 0x01, 0x03, 0x03 };
166 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
167 expected
, sizeof(expected
), "ibm-1363", 0 , TRUE
, U_ZERO_ERROR
))
168 log_err("u-> ibm-1363 [UCNV_DBCS portion] not match.\n");
169 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
170 expected
, sizeof(expected
), "ibm-1363", offsets
, TRUE
, U_ZERO_ERROR
))
171 log_err("u-> ibm-1363 [UCNV_DBCS portion] not match.\n");
173 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
174 expected
, sizeof(expected
), "ibm-1363", 0 , TRUE
, U_ZERO_ERROR
))
175 log_err("u-> ibm-1363 [UCNV_MBCS] not match.\n");
176 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
177 expected
, sizeof(expected
), "ibm-1363", offsets
, TRUE
, U_ZERO_ERROR
))
178 log_err("u-> ibm-1363 [UCNV_MBCS] not match.\n");
181 log_verbose("Testing for ISO-2022-jp\n");
183 UChar sampleText
[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
185 const uint8_t expected
[] = {0x1b, 0x24, 0x42,0x30,0x6c,0x43,0x7a,0x1b,0x28,0x42,
189 int32_t offsets
[] = {0,0,0,0,0,1,1,2,2,2,2,3,5 };
192 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
193 expected
, sizeof(expected
), "iso-2022-jp", 0 , TRUE
, U_ZERO_ERROR
))
194 log_err("u-> not match.\n");
195 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
196 expected
, sizeof(expected
), "iso-2022-jp", offsets
, TRUE
, U_ZERO_ERROR
))
197 log_err("u-> not match.\n");
200 log_verbose("Testing for ISO-2022-cn\n");
202 static const UChar sampleText
[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
204 static const uint8_t expected
[] = {
205 0x1B, 0x24, 0x29, 0x41, 0x0E, 0x52, 0x3B,
214 static const int32_t offsets
[] = {
222 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
223 expected
, sizeof(expected
), "iso-2022-cn", 0 , TRUE
, U_ZERO_ERROR
))
224 log_err("u-> not match.\n");
225 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
226 expected
, sizeof(expected
), "iso-2022-cn", offsets
, TRUE
, U_ZERO_ERROR
))
227 log_err("u-> not match.\n");
230 log_verbose("Testing for ISO-2022-kr\n");
232 static const UChar sampleText
[] = { 0x4e00,0xd801, 0xdc01, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
234 static const uint8_t expected
[] = {0x1B, 0x24, 0x29, 0x43,
242 static const int32_t offsets
[] = {-1, -1, -1, -1,
252 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
253 expected
, sizeof(expected
), "iso-2022-kr", 0 , TRUE
, U_ZERO_ERROR
))
254 log_err("u-> iso-2022-kr [UCNV_DBCS] not match.\n");
255 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
256 expected
, sizeof(expected
), "iso-2022-kr", offsets
, TRUE
, U_ZERO_ERROR
))
257 log_err("u-> iso-2022-kr [UCNV_DBCS] not match.\n");
260 log_verbose("Testing for HZ\n");
262 static const UChar sampleText
[] = { 0x4e00, 0xd801, 0xdc01, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
264 static const uint8_t expected
[] = {0x7E, 0x7B, 0x52, 0x3B,
266 0x7E, 0x7B, 0x36, 0x21,
272 static const int32_t offsets
[] = {0,0,0,0,
280 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
281 expected
, sizeof(expected
), "HZ", 0 , TRUE
, U_ZERO_ERROR
))
282 log_err("u-> HZ not match.\n");
283 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
284 expected
, sizeof(expected
), "HZ", offsets
, TRUE
, U_ZERO_ERROR
))
285 log_err("u-> HZ not match.\n");
290 log_verbose("Testing for UTF8\n");
292 static const UChar sampleText
[] = { 0x4e00, 0x0701, 0x0031, 0xbfc1, 0xd801, 0xdc01, 0x0032};
293 static const int32_t offsets
[]={0x00, 0x00, 0x00, 0x01, 0x01, 0x02,
294 0x03, 0x03, 0x03, 0x04, 0x04, 0x04,
296 static const uint8_t expected
[] = {0xe4, 0xb8, 0x80, 0xdc, 0x81, 0x31,
297 0xeb, 0xbf, 0x81, 0xF0, 0x90, 0x90, 0x81, 0x32};
300 static const int32_t fromOffsets
[] = { 0x0000, 0x0003, 0x0005, 0x0006, 0x0009, 0x0009, 0x000D };
302 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
303 expected
, sizeof(expected
), "UTF8", offsets
, TRUE
, U_ZERO_ERROR
))
304 log_err("u-> UTF8 with offsets and flush true did not match.\n");
305 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
306 expected
, sizeof(expected
), "UTF8", 0, TRUE
, U_ZERO_ERROR
))
307 log_err("u-> UTF8 with offsets and flush true did not match.\n");
308 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
309 expected
, sizeof(expected
), "UTF8", offsets
, FALSE
, U_ZERO_ERROR
))
310 log_err("u-> UTF8 with offsets and flush true did not match.\n");
311 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
312 expected
, sizeof(expected
), "UTF8", 0, FALSE
, U_ZERO_ERROR
))
313 log_err("u-> UTF8 with offsets and flush true did not match.\n");
315 if(!convertToU(expected
, sizeof(expected
),
316 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8", 0, TRUE
, U_ZERO_ERROR
))
317 log_err("UTF8 -> u did not match.\n");
318 if(!convertToU(expected
, sizeof(expected
),
319 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8", 0, FALSE
, U_ZERO_ERROR
))
320 log_err("UTF8 -> u did not match.\n");
321 if(!convertToU(expected
, sizeof(expected
),
322 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8", fromOffsets
, TRUE
, U_ZERO_ERROR
))
323 log_err("UTF8 ->u did not match.\n");
324 if(!convertToU(expected
, sizeof(expected
),
325 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8", fromOffsets
, FALSE
, U_ZERO_ERROR
))
326 log_err("UTF8 -> u did not match.\n");
331 /*test various error behaviours*/
332 static void TestErrorBehaviour(){
333 log_verbose("Testing for SBCS and LATIN_1\n");
335 static const UChar sampleText
[] = { 0x0031, 0xd801};
336 static const UChar sampleText2
[] = { 0x0031, 0xd801, 0x0032};
337 static const uint8_t expected0
[] = { 0x31};
338 static const uint8_t expected
[] = { 0x31, 0x1a};
339 static const uint8_t expected2
[] = { 0x31, 0x1a, 0x32};
341 #if !UCONFIG_NO_LEGACY_CONVERSION
343 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
344 expected
, sizeof(expected
), "ibm-920", 0, TRUE
, U_ZERO_ERROR
))
345 log_err("u-> ibm-920 [UCNV_SBCS] \n");
346 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
347 expected0
, sizeof(expected0
), "ibm-920", 0, FALSE
, U_ZERO_ERROR
))
348 log_err("u-> ibm-920 [UCNV_SBCS] \n");
349 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
350 expected2
, sizeof(expected2
), "ibm-920", 0, TRUE
, U_ZERO_ERROR
))
351 log_err("u-> ibm-920 [UCNV_SBCS] did not match\n");
355 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
356 expected
, sizeof(expected
), "LATIN_1", 0, TRUE
, U_ZERO_ERROR
))
357 log_err("u-> LATIN_1 is supposed to fail\n");
358 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
359 expected0
, sizeof(expected0
), "LATIN_1", 0, FALSE
, U_ZERO_ERROR
))
360 log_err("u-> LATIN_1 is supposed to fail\n");
362 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
363 expected2
, sizeof(expected2
), "LATIN_1", 0, TRUE
, U_ZERO_ERROR
))
364 log_err("u-> LATIN_1 did not match\n");
367 #if !UCONFIG_NO_LEGACY_CONVERSION
368 log_verbose("Testing for DBCS and MBCS\n");
370 static const UChar sampleText
[] = { 0x00a1, 0xd801};
371 static const uint8_t expected
[] = { 0xa2, 0xae};
372 static const int32_t offsets
[] = { 0x00, 0x00};
373 static const uint8_t expectedSUB
[] = { 0xa2, 0xae, 0xa1, 0xe0};
374 static const int32_t offsetsSUB
[] = { 0x00, 0x00, 0x01, 0x01};
376 static const UChar sampleText2
[] = { 0x00a1, 0xd801, 0x00a4};
377 static const uint8_t expected2
[] = { 0xa2, 0xae, 0xa1, 0xe0, 0xa2, 0xb4};
378 static const int32_t offsets2
[] = { 0x00, 0x00, 0x01, 0x01, 0x02, 0x02};
380 static const UChar sampleText3MBCS
[] = { 0x0001, 0x00a4, 0xdc01};
381 static const uint8_t expected3MBCS
[] = { 0x01, 0xa2, 0xb4, 0xa1, 0xe0};
382 static const int32_t offsets3MBCS
[] = { 0x00, 0x01, 0x01, 0x02, 0x02};
384 static const UChar sampleText4MBCS
[] = { 0x0061, 0xFFE4, 0xdc01};
385 static const uint8_t expected4MBCS
[] = { 0x61, 0x8f, 0xa2, 0xc3, 0xf4, 0xfe};
386 static const int32_t offsets4MBCS
[] = { 0x00, 0x01, 0x01, 0x01, 0x02, 0x02 };
389 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
390 expectedSUB
, sizeof(expectedSUB
), "ibm-1363", 0, TRUE
, U_ZERO_ERROR
))
391 log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
392 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
393 expected
, sizeof(expected
), "ibm-1363", 0, FALSE
, U_ZERO_ERROR
))
394 log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
396 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
397 expectedSUB
, sizeof(expectedSUB
), "ibm-1363", offsetsSUB
, TRUE
, U_ZERO_ERROR
))
398 log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
399 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
400 expected
, sizeof(expected
), "ibm-1363", offsets
, FALSE
, U_ZERO_ERROR
))
401 log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
404 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
405 expected2
, sizeof(expected2
), "ibm-1363", 0, TRUE
, U_ZERO_ERROR
))
406 log_err("u-> ibm-1363 [UCNV_DBCS portion] did not match \n");
407 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
408 expected2
, sizeof(expected2
), "ibm-1363", offsets2
, TRUE
, U_ZERO_ERROR
))
409 log_err("u-> ibm-1363 [UCNV_DBCS portion] did not match \n");
412 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
413 expectedSUB
, sizeof(expectedSUB
), "ibm-1363", 0, TRUE
, U_ZERO_ERROR
))
414 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
415 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
416 expected
, sizeof(expected
), "ibm-1363", 0, FALSE
, U_ZERO_ERROR
))
417 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
419 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
420 expected2
, sizeof(expected2
), "ibm-1363", 0, TRUE
, U_ZERO_ERROR
))
421 log_err("u-> ibm-1363 [UCNV_DBCS] did not match\n");
422 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
423 expected2
, sizeof(expected2
), "ibm-1363", 0, FALSE
, U_ZERO_ERROR
))
424 log_err("u-> ibm-1363 [UCNV_DBCS] did not match\n");
425 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
426 expected2
, sizeof(expected2
), "ibm-1363", offsets2
, FALSE
, U_ZERO_ERROR
))
427 log_err("u-> ibm-1363 [UCNV_DBCS] did not match\n");
429 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
430 expected3MBCS
, sizeof(expected3MBCS
), "ibm-1363", offsets3MBCS
, TRUE
, U_ZERO_ERROR
))
431 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
432 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
433 expected3MBCS
, sizeof(expected3MBCS
), "ibm-1363", offsets3MBCS
, FALSE
, U_ZERO_ERROR
))
434 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
436 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
437 expected4MBCS
, sizeof(expected4MBCS
), "euc-jp", offsets4MBCS
, TRUE
, U_ZERO_ERROR
))
438 log_err("u-> euc-jp [UCNV_MBCS] \n");
439 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
440 expected4MBCS
, sizeof(expected4MBCS
), "euc-jp", offsets4MBCS
, FALSE
, U_ZERO_ERROR
))
441 log_err("u-> euc-jp [UCNV_MBCS] \n");
445 log_verbose("Testing for iso-2022-jp\n");
447 static const UChar sampleText
[] = { 0x0031, 0xd801};
448 static const uint8_t expected
[] = { 0x31};
449 static const uint8_t expectedSUB
[] = { 0x31, 0x1a};
450 static const int32_t offsets
[] = { 0x00, 1};
452 static const UChar sampleText2
[] = { 0x0031, 0xd801, 0x0032};
453 static const uint8_t expected2
[] = { 0x31,0x1A,0x32};
454 static const int32_t offsets2
[] = { 0x00,0x01,0x02};
456 static const UChar sampleText4MBCS
[] = { 0x0061, 0x4e00, 0xdc01};
457 static const uint8_t expected4MBCS
[] = { 0x61, 0x1b, 0x24, 0x42, 0x30, 0x6c,0x1b,0x28,0x42,0x1a};
458 static const int32_t offsets4MBCS
[] = { 0x00, 0x01, 0x01 ,0x01, 0x01, 0x01,0x02,0x02,0x02,0x02 };
459 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
460 expectedSUB
, sizeof(expectedSUB
), "iso-2022-jp", offsets
, TRUE
, U_ZERO_ERROR
))
461 log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
462 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
463 expected
, sizeof(expected
), "iso-2022-jp", offsets
, FALSE
, U_ZERO_ERROR
))
464 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
466 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
467 expected2
, sizeof(expected2
), "iso-2022-jp", offsets2
, TRUE
, U_ZERO_ERROR
))
468 log_err("u->iso-2022-jp[UCNV_DBCS] did not match\n");
469 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
470 expected2
, sizeof(expected2
), "iso-2022-jp", offsets2
, FALSE
, U_ZERO_ERROR
))
471 log_err("u-> iso-2022-jp [UCNV_DBCS] did not match\n");
472 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
473 expected2
, sizeof(expected2
), "iso-2022-jp", offsets2
, FALSE
, U_ZERO_ERROR
))
474 log_err("u-> iso-2022-jp [UCNV_DBCS] did not match\n");
476 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
477 expected4MBCS
, sizeof(expected4MBCS
), "iso-2022-jp", offsets4MBCS
, TRUE
, U_ZERO_ERROR
))
478 log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
479 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
480 expected4MBCS
, sizeof(expected4MBCS
), "iso-2022-jp", offsets4MBCS
, FALSE
, U_ZERO_ERROR
))
481 log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
485 log_verbose("Testing for iso-2022-cn\n");
487 static const UChar sampleText
[] = { 0x0031, 0xd801};
488 static const uint8_t expected
[] = { 0x31};
489 static const uint8_t expectedSUB
[] = { 0x31, 0x1A};
490 static const int32_t offsets
[] = { 0x00, 1};
492 static const UChar sampleText2
[] = { 0x0031, 0xd801, 0x0032};
493 static const uint8_t expected2
[] = { 0x31, 0x1A,0x32};
494 static const int32_t offsets2
[] = { 0x00, 0x01,0x02};
496 static const UChar sampleText3MBCS
[] = { 0x0051, 0x0050, 0xdc01};
497 static const uint8_t expected3MBCS
[] = {0x51, 0x50, 0x1A};
498 static const int32_t offsets3MBCS
[] = { 0x00, 0x01, 0x02 };
500 static const UChar sampleText4MBCS
[] = { 0x0061, 0x4e00, 0xdc01};
501 static const uint8_t expected4MBCS
[] = { 0x61, 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x52, 0x3b, 0x0f, 0x1a };
502 static const int32_t offsets4MBCS
[] = { 0x00, 0x01, 0x01 ,0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02 };
503 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
504 expectedSUB
, sizeof(expectedSUB
), "iso-2022-cn", offsets
, TRUE
, U_ZERO_ERROR
))
505 log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
506 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
507 expected
, sizeof(expected
), "iso-2022-cn", offsets
, FALSE
, U_ZERO_ERROR
))
508 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
510 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
511 expected2
, sizeof(expected2
), "iso-2022-cn", offsets2
, TRUE
, U_ZERO_ERROR
))
512 log_err("u->iso-2022-cn[UCNV_DBCS] did not match\n");
513 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
514 expected2
, sizeof(expected2
), "iso-2022-cn", offsets2
, FALSE
, U_ZERO_ERROR
))
515 log_err("u-> iso-2022-cn [UCNV_DBCS] did not match\n");
516 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
517 expected2
, sizeof(expected2
), "iso-2022-cn", offsets2
, FALSE
, U_ZERO_ERROR
))
518 log_err("u-> iso-2022-cn [UCNV_DBCS] did not match\n");
520 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
521 expected3MBCS
, sizeof(expected3MBCS
), "iso-2022-cn", offsets3MBCS
, TRUE
, U_ZERO_ERROR
))
522 log_err("u->iso-2022-cn [UCNV_MBCS] \n");
523 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
524 expected3MBCS
, sizeof(expected3MBCS
), "iso-2022-cn", offsets3MBCS
, FALSE
, U_ZERO_ERROR
))
525 log_err("u-> iso-2022-cn[UCNV_MBCS] \n");
527 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
528 expected4MBCS
, sizeof(expected4MBCS
), "iso-2022-cn", offsets4MBCS
, TRUE
, U_ZERO_ERROR
))
529 log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
530 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
531 expected4MBCS
, sizeof(expected4MBCS
), "iso-2022-cn", offsets4MBCS
, FALSE
, U_ZERO_ERROR
))
532 log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
536 log_verbose("Testing for iso-2022-kr\n");
538 static const UChar sampleText
[] = { 0x0031, 0xd801};
539 static const uint8_t expected
[] = { 0x1b, 0x24, 0x29, 0x43, 0x31};
540 static const uint8_t expectedSUB
[] = { 0x1b, 0x24, 0x29, 0x43, 0x31, 0x1A};
541 static const int32_t offsets
[] = { -1, -1, -1, -1, 0x00, 1};
543 static const UChar sampleText2
[] = { 0x0031, 0xd801, 0x0032};
544 static const uint8_t expected2
[] = { 0x1b, 0x24, 0x29, 0x43, 0x31, 0x1A, 0x32};
545 static const int32_t offsets2
[] = { -1, -1, -1, -1, 0x00, 0x01, 0x02};
547 static const UChar sampleText3MBCS
[] = { 0x0051, 0x0050, 0xdc01};
548 static const uint8_t expected3MBCS
[] = { 0x1b, 0x24, 0x29, 0x43, 0x51, 0x50, 0x1A };
549 static const int32_t offsets3MBCS
[] = { -1, -1, -1, -1, 0x00, 0x01, 0x02, 0x02 };
551 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
552 expectedSUB
, sizeof(expectedSUB
), "iso-2022-kr", offsets
, TRUE
, U_ZERO_ERROR
))
553 log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
554 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
555 expected
, sizeof(expected
), "iso-2022-kr", offsets
, FALSE
, U_ZERO_ERROR
))
556 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
558 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
559 expected2
, sizeof(expected2
), "iso-2022-kr", offsets2
, TRUE
, U_ZERO_ERROR
))
560 log_err("u->iso-2022-kr[UCNV_DBCS] did not match\n");
561 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
562 expected2
, sizeof(expected2
), "iso-2022-kr", offsets2
, FALSE
, U_ZERO_ERROR
))
563 log_err("u-> iso-2022-kr [UCNV_DBCS] did not match\n");
564 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
565 expected2
, sizeof(expected2
), "iso-2022-kr", offsets2
, FALSE
, U_ZERO_ERROR
))
566 log_err("u-> iso-2022-kr [UCNV_DBCS] did not match\n");
568 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
569 expected3MBCS
, sizeof(expected3MBCS
), "iso-2022-kr", offsets3MBCS
, TRUE
, U_ZERO_ERROR
))
570 log_err("u->iso-2022-kr [UCNV_MBCS] \n");
571 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
572 expected3MBCS
, sizeof(expected3MBCS
), "iso-2022-kr", offsets3MBCS
, FALSE
, U_ZERO_ERROR
))
573 log_err("u-> iso-2022-kr[UCNV_MBCS] \n");
577 log_verbose("Testing for HZ\n");
579 static const UChar sampleText
[] = { 0x0031, 0xd801};
580 static const uint8_t expected
[] = { 0x7e, 0x7d, 0x31};
581 static const uint8_t expectedSUB
[] = { 0x7e, 0x7d, 0x31, 0x1A};
582 static const int32_t offsets
[] = { 0x00, 0x00, 0x00, 1};
584 static const UChar sampleText2
[] = { 0x0031, 0xd801, 0x0032};
585 static const uint8_t expected2
[] = { 0x7e, 0x7d, 0x31, 0x1A, 0x32 };
586 static const int32_t offsets2
[] = { 0x00, 0x00, 0x00, 0x01, 0x02 };
588 static const UChar sampleText3MBCS
[] = { 0x0051, 0x0050, 0xdc01};
589 static const uint8_t expected3MBCS
[] = { 0x7e, 0x7d, 0x51, 0x50, 0x1A };
590 static const int32_t offsets3MBCS
[] = { 0x00, 0x00, 0x00, 0x01, 0x02};
592 static const UChar sampleText4MBCS
[] = { 0x0061, 0x4e00, 0xdc01};
593 static const uint8_t expected4MBCS
[] = { 0x7e, 0x7d, 0x61, 0x7e, 0x7b, 0x52, 0x3b, 0x7e, 0x7d, 0x1a };
594 static const int32_t offsets4MBCS
[] = { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 ,0x01, 0x02, 0x02, 0x02 };
595 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
596 expectedSUB
, sizeof(expectedSUB
), "HZ", offsets
, TRUE
, U_ZERO_ERROR
))
597 log_err("u-> HZ [UCNV_MBCS] \n");
598 if(!convertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
599 expected
, sizeof(expected
), "HZ", offsets
, FALSE
, U_ZERO_ERROR
))
600 log_err("u-> ibm-1363 [UCNV_MBCS] \n");
602 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
603 expected2
, sizeof(expected2
), "HZ", offsets2
, TRUE
, U_ZERO_ERROR
))
604 log_err("u->HZ[UCNV_DBCS] did not match\n");
605 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
606 expected2
, sizeof(expected2
), "HZ", offsets2
, FALSE
, U_ZERO_ERROR
))
607 log_err("u-> HZ [UCNV_DBCS] did not match\n");
608 if(!convertFromU(sampleText2
, sizeof(sampleText2
)/sizeof(sampleText2
[0]),
609 expected2
, sizeof(expected2
), "HZ", offsets2
, FALSE
, U_ZERO_ERROR
))
610 log_err("u-> HZ [UCNV_DBCS] did not match\n");
612 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
613 expected3MBCS
, sizeof(expected3MBCS
), "HZ", offsets3MBCS
, TRUE
, U_ZERO_ERROR
))
614 log_err("u->HZ [UCNV_MBCS] \n");
615 if(!convertFromU(sampleText3MBCS
, sizeof(sampleText3MBCS
)/sizeof(sampleText3MBCS
[0]),
616 expected3MBCS
, sizeof(expected3MBCS
), "HZ", offsets3MBCS
, FALSE
, U_ZERO_ERROR
))
617 log_err("u-> HZ[UCNV_MBCS] \n");
619 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
620 expected4MBCS
, sizeof(expected4MBCS
), "HZ", offsets4MBCS
, TRUE
, U_ZERO_ERROR
))
621 log_err("u-> HZ [UCNV_MBCS] \n");
622 if(!convertFromU(sampleText4MBCS
, sizeof(sampleText4MBCS
)/sizeof(sampleText4MBCS
[0]),
623 expected4MBCS
, sizeof(expected4MBCS
), "HZ", offsets4MBCS
, FALSE
, U_ZERO_ERROR
))
624 log_err("u-> HZ [UCNV_MBCS] \n");
629 #if !UCONFIG_NO_LEGACY_CONVERSION
630 /*test different convertToUnicode error behaviours*/
631 static void TestToUnicodeErrorBehaviour()
633 log_verbose("Testing error conditions for DBCS\n");
635 uint8_t sampleText
[] = { 0xa2, 0xae, 0x03, 0x04};
636 const UChar expected
[] = { 0x00a1 };
638 if(!convertToU(sampleText
, sizeof(sampleText
),
639 expected
, sizeof(expected
)/sizeof(expected
[0]), "ibm-1363", 0, TRUE
, U_ZERO_ERROR
))
640 log_err("DBCS (ibm-1363)->Unicode did not match.\n");
641 if(!convertToU(sampleText
, sizeof(sampleText
),
642 expected
, sizeof(expected
)/sizeof(expected
[0]), "ibm-1363", 0, FALSE
, U_ZERO_ERROR
))
643 log_err("DBCS (ibm-1363)->Unicode with flush = false did not match.\n");
645 log_verbose("Testing error conditions for SBCS\n");
647 uint8_t sampleText
[] = { 0xa2, 0xFF};
648 const UChar expected
[] = { 0x00c2 };
650 /* uint8_t sampleText2[] = { 0xa2, 0x70 };
651 const UChar expected2[] = { 0x0073 };*/
653 if(!convertToU(sampleText
, sizeof(sampleText
),
654 expected
, sizeof(expected
)/sizeof(expected
[0]), "ibm-1051", 0, TRUE
, U_ZERO_ERROR
))
655 log_err("SBCS (ibm-1051)->Unicode did not match.\n");
656 if(!convertToU(sampleText
, sizeof(sampleText
),
657 expected
, sizeof(expected
)/sizeof(expected
[0]), "ibm-1051", 0, FALSE
, U_ZERO_ERROR
))
658 log_err("SBCS (ibm-1051)->Unicode with flush = false did not match.\n");
663 static void TestGetNextErrorBehaviour(){
664 /*Test for unassigned character*/
666 static const char input1
[INPUT_SIZE
]={ 0x70 };
667 const char* source
=(const char*)input1
;
668 UErrorCode err
=U_ZERO_ERROR
;
670 UConverter
*cnv
=ucnv_open("ibm-424", &err
);
672 log_data_err("Unable to open a SBCS(ibm-424) converter: %s\n", u_errorName(err
));
675 c
=ucnv_getNextUChar(cnv
, &source
, source
+ INPUT_SIZE
, &err
);
676 if(err
!= U_INVALID_CHAR_FOUND
&& c
!=0xfffd){
677 log_err("FAIL in TestGetNextErrorBehaviour(unassigned): Expected: U_INVALID_CHAR_ERROR or 0xfffd ----Got:%s and 0x%lx\n", myErrorName(err
), c
);
683 #define MAX_UTF16_LEN 2
684 #define MAX_UTF8_LEN 4
686 /*Regression test for utf8 converter*/
687 static void TestRegressionUTF8(){
691 UChar
*standardForm
= (UChar
*)malloc(MAX_LENGTH
*sizeof(UChar
));
692 uint8_t *utf8
= (uint8_t*)malloc(MAX_LENGTH
);
694 while (currCh
<= UNICODE_LIMIT
) {
697 while(currCh
<= UNICODE_LIMIT
698 && offset16
< (MAX_LENGTH
/sizeof(UChar
) - MAX_UTF16_LEN
)
699 && offset8
< (MAX_LENGTH
- MAX_UTF8_LEN
))
701 if (currCh
== SURROGATE_HIGH_START
) {
702 currCh
= SURROGATE_LOW_END
+ 1; /* Skip surrogate range */
704 UTF16_APPEND_CHAR_SAFE(standardForm
, offset16
, MAX_LENGTH
, currCh
);
705 UTF8_APPEND_CHAR_SAFE(utf8
, offset8
, MAX_LENGTH
, currCh
);
708 if(!convertFromU(standardForm
, offset16
,
709 utf8
, offset8
, "UTF8", 0, TRUE
, U_ZERO_ERROR
)) {
710 log_err("Unicode->UTF8 did not match.\n");
712 if(!convertToU(utf8
, offset8
,
713 standardForm
, offset16
, "UTF8", 0, TRUE
, U_ZERO_ERROR
)) {
714 log_err("UTF8->Unicode did not match.\n");
722 static const char src8
[] = { (char)0xCC, (char)0x81, (char)0xCC, (char)0x80 };
723 static const UChar expected
[] = { 0x0301, 0x0300 };
725 UErrorCode err
= U_ZERO_ERROR
;
726 UChar pivotBuffer
[100];
727 const UChar
* const pivEnd
= pivotBuffer
+ 100;
732 conv8
= ucnv_open("UTF-8", &err
);
735 pivBeg
= pivotBuffer
;
737 ucnv_toUnicode(conv8
, &pivBeg
, pivEnd
, &srcBeg
, srcEnd
, 0, FALSE
, &err
);
738 if (srcBeg
!= srcEnd
) {
739 log_err("Did not consume whole buffer on first call.\n");
743 ucnv_toUnicode(conv8
, &pivBeg
, pivEnd
, &srcBeg
, srcEnd
, 0, TRUE
, &err
);
744 if (srcBeg
!= srcEnd
) {
745 log_err("Did not consume whole buffer on second call.\n");
748 if (U_FAILURE(err
) || (int32_t)(pivBeg
- pivotBuffer
) != 2 || u_strncmp(pivotBuffer
, expected
, 2) != 0) {
749 log_err("Did not get expected results for UTF-8.\n");
755 #define MAX_UTF32_LEN 1
757 static void TestRegressionUTF32(){
761 UChar
*standardForm
= (UChar
*)malloc(MAX_LENGTH
*sizeof(UChar
));
762 UChar32
*utf32
= (UChar32
*)malloc(MAX_LENGTH
*sizeof(UChar32
));
764 while (currCh
<= UNICODE_LIMIT
) {
767 while(currCh
<= UNICODE_LIMIT
768 && offset16
< (MAX_LENGTH
/sizeof(UChar
) - MAX_UTF16_LEN
)
769 && offset32
< (MAX_LENGTH
/sizeof(UChar32
) - MAX_UTF32_LEN
))
771 if (currCh
== SURROGATE_HIGH_START
) {
772 currCh
= SURROGATE_LOW_END
+ 1; /* Skip surrogate range */
774 UTF16_APPEND_CHAR_SAFE(standardForm
, offset16
, MAX_LENGTH
, currCh
);
775 UTF32_APPEND_CHAR_SAFE(utf32
, offset32
, MAX_LENGTH
, currCh
);
778 if(!convertFromU(standardForm
, offset16
,
779 (const uint8_t *)utf32
, offset32
*sizeof(UChar32
), "UTF32_PlatformEndian", 0, TRUE
, U_ZERO_ERROR
)) {
780 log_err("Unicode->UTF32 did not match.\n");
782 if(!convertToU((const uint8_t *)utf32
, offset32
*sizeof(UChar32
),
783 standardForm
, offset16
, "UTF32_PlatformEndian", 0, TRUE
, U_ZERO_ERROR
)) {
784 log_err("UTF32->Unicode did not match.\n");
791 /* Check for lone surrogate error handling. */
792 static const UChar sampleBadStartSurrogate
[] = { 0x0031, 0xD800, 0x0032 };
793 static const UChar sampleBadEndSurrogate
[] = { 0x0031, 0xDC00, 0x0032 };
794 static const uint8_t expectedUTF32BE
[] = {
795 0x00, 0x00, 0x00, 0x31,
796 0x00, 0x00, 0xff, 0xfd,
797 0x00, 0x00, 0x00, 0x32
799 static const uint8_t expectedUTF32LE
[] = {
800 0x31, 0x00, 0x00, 0x00,
801 0xfd, 0xff, 0x00, 0x00,
802 0x32, 0x00, 0x00, 0x00
804 static const int32_t offsetsUTF32
[] = {
805 0x00, 0x00, 0x00, 0x00,
806 0x01, 0x01, 0x01, 0x01,
807 0x02, 0x02, 0x02, 0x02
810 if(!convertFromU(sampleBadStartSurrogate
, sizeof(sampleBadStartSurrogate
)/sizeof(sampleBadStartSurrogate
[0]),
811 expectedUTF32BE
, sizeof(expectedUTF32BE
), "UTF-32BE", offsetsUTF32
, TRUE
, U_ZERO_ERROR
))
812 log_err("u->UTF-32BE\n");
813 if(!convertFromU(sampleBadEndSurrogate
, sizeof(sampleBadEndSurrogate
)/sizeof(sampleBadEndSurrogate
[0]),
814 expectedUTF32BE
, sizeof(expectedUTF32BE
), "UTF-32BE", offsetsUTF32
, TRUE
, U_ZERO_ERROR
))
815 log_err("u->UTF-32BE\n");
817 if(!convertFromU(sampleBadStartSurrogate
, sizeof(sampleBadStartSurrogate
)/sizeof(sampleBadStartSurrogate
[0]),
818 expectedUTF32LE
, sizeof(expectedUTF32LE
), "UTF-32LE", offsetsUTF32
, TRUE
, U_ZERO_ERROR
))
819 log_err("u->UTF-32LE\n");
820 if(!convertFromU(sampleBadEndSurrogate
, sizeof(sampleBadEndSurrogate
)/sizeof(sampleBadEndSurrogate
[0]),
821 expectedUTF32LE
, sizeof(expectedUTF32LE
), "UTF-32LE", offsetsUTF32
, TRUE
, U_ZERO_ERROR
))
822 log_err("u->UTF-32LE\n");
826 static const char srcBE
[] = { 0, 0, 0, 0x31, 0, 0, 0, 0x30 };
827 static const UChar expected
[] = { 0x0031, 0x0030 };
829 UErrorCode err
= U_ZERO_ERROR
;
830 UChar pivotBuffer
[100];
831 const UChar
* const pivEnd
= pivotBuffer
+ 100;
836 convBE
= ucnv_open("UTF-32BE", &err
);
839 pivBeg
= pivotBuffer
;
841 ucnv_toUnicode(convBE
, &pivBeg
, pivEnd
, &srcBeg
, srcEnd
, 0, FALSE
, &err
);
842 if (srcBeg
!= srcEnd
) {
843 log_err("Did not consume whole buffer on first call.\n");
847 ucnv_toUnicode(convBE
, &pivBeg
, pivEnd
, &srcBeg
, srcEnd
, 0, TRUE
, &err
);
848 if (srcBeg
!= srcEnd
) {
849 log_err("Did not consume whole buffer on second call.\n");
852 if (U_FAILURE(err
) || (int32_t)(pivBeg
- pivotBuffer
) != 2 || u_strncmp(pivotBuffer
, expected
, 2) != 0) {
853 log_err("Did not get expected results for UTF-32BE.\n");
858 static const char srcLE
[] = { 0x31, 0, 0, 0, 0x30, 0, 0, 0 };
859 static const UChar expected
[] = { 0x0031, 0x0030 };
861 UErrorCode err
= U_ZERO_ERROR
;
862 UChar pivotBuffer
[100];
863 const UChar
* const pivEnd
= pivotBuffer
+ 100;
868 convLE
= ucnv_open("UTF-32LE", &err
);
871 pivBeg
= pivotBuffer
;
873 ucnv_toUnicode(convLE
, &pivBeg
, pivEnd
, &srcBeg
, srcEnd
, 0, FALSE
, &err
);
874 if (srcBeg
!= srcEnd
) {
875 log_err("Did not consume whole buffer on first call.\n");
879 ucnv_toUnicode(convLE
, &pivBeg
, pivEnd
, &srcBeg
, srcEnd
, 0, TRUE
, &err
);
880 if (srcBeg
!= srcEnd
) {
881 log_err("Did not consume whole buffer on second call.\n");
884 if (U_FAILURE(err
) || (int32_t)(pivBeg
- pivotBuffer
) != 2 || u_strncmp(pivotBuffer
, expected
, 2) != 0) {
885 log_err("Did not get expected results for UTF-32LE.\n");
891 /*Walk through the available converters*/
892 static void TestAvailableConverters(){
893 UErrorCode status
=U_ZERO_ERROR
;
894 UConverter
*conv
=NULL
;
896 for(i
=0; i
< ucnv_countAvailable(); i
++){
898 conv
=ucnv_open(ucnv_getAvailableName(i
), &status
);
899 if(U_FAILURE(status
)){
900 log_err("ERROR: converter creation failed. Failure in alias table or the data table for \n converter=%s. Error=%s\n",
901 ucnv_getAvailableName(i
), myErrorName(status
));
909 static void TestFlushInternalBuffer(){
910 TestWithBufferSize(MAX_LENGTH
, 1);
911 TestWithBufferSize(1, 1);
912 TestWithBufferSize(1, MAX_LENGTH
);
913 TestWithBufferSize(MAX_LENGTH
, MAX_LENGTH
);
916 static void TestWithBufferSize(int32_t insize
, int32_t outsize
){
918 gInBufferSize
=insize
;
919 gOutBufferSize
= outsize
;
921 log_verbose("Testing fromUnicode for UTF-8 with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
924 { 0x0031, 0x0032, 0x0033, 0x0000, 0x4e00, 0x4e8c, 0x4e09, 0x002E };
925 const uint8_t expectedUTF8
[] =
926 { 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E };
927 int32_t toUTF8Offs
[] =
928 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07};
929 /* int32_t fmUTF8Offs[] =
930 { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d };*/
933 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
934 expectedUTF8
, sizeof(expectedUTF8
), "UTF8", UCNV_FROM_U_CALLBACK_SUBSTITUTE
, toUTF8Offs
,FALSE
))
935 log_err("u-> UTF8 did not match.\n");
938 #if !UCONFIG_NO_LEGACY_CONVERSION
939 log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_ESCAPE \n");
941 UChar inputTest
[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
942 const uint8_t toIBM943
[]= { 0x61,
943 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
944 0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
945 0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
947 int32_t offset
[]= {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 4};
949 if(!testConvertFromU(inputTest
, sizeof(inputTest
)/sizeof(inputTest
[0]),
950 toIBM943
, sizeof(toIBM943
), "ibm-943",
951 (UConverterFromUCallback
)UCNV_FROM_U_CALLBACK_ESCAPE
, offset
,FALSE
))
952 log_err("u-> ibm-943 with subst with value did not match.\n");
956 log_verbose("Testing fromUnicode for UTF-8 with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
958 const uint8_t sampleText1
[] = { 0x31, 0xe4, 0xba, 0x8c,
960 UChar expected1
[] = { 0x0031, 0x4e8c, 0xfffd, 0x0061};
961 int32_t offsets1
[] = { 0x0000, 0x0001, 0x0004, 0x0006};
963 if(!testConvertToU(sampleText1
, sizeof(sampleText1
),
964 expected1
, sizeof(expected1
)/sizeof(expected1
[0]),"utf8", UCNV_TO_U_CALLBACK_SUBSTITUTE
, offsets1
,FALSE
))
965 log_err("utf8->u with substitute did not match.\n");;
968 #if !UCONFIG_NO_LEGACY_CONVERSION
969 log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_ESCAPE \n");
972 const uint8_t sampleTxtToU
[]= { 0x00, 0x9f, 0xaf,
973 0x81, 0xad, /*unassigned*/
975 UChar IBM_943toUnicode
[] = { 0x0000, 0x6D63,
976 0x25, 0x58, 0x38, 0x31, 0x25, 0x58, 0x41, 0x44,
978 int32_t fromIBM943Offs
[] = { 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 5};
980 if(!testConvertToU(sampleTxtToU
, sizeof(sampleTxtToU
),
981 IBM_943toUnicode
, sizeof(IBM_943toUnicode
)/sizeof(IBM_943toUnicode
[0]),"ibm-943",
982 (UConverterToUCallback
)UCNV_TO_U_CALLBACK_ESCAPE
, fromIBM943Offs
,FALSE
))
983 log_err("ibm-943->u with substitute with value did not match.\n");
989 static UBool
convertFromU( const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
990 const char *codepage
, const int32_t *expectOffsets
, UBool doFlush
, UErrorCode expectedStatus
)
996 char buffer
[MAX_LENGTH
];
997 int32_t offsetBuffer
[MAX_LENGTH
];
1001 UChar
*sourceLimit
=0;
1002 UErrorCode status
= U_ZERO_ERROR
;
1003 UConverter
*conv
= 0;
1004 conv
= ucnv_open(codepage
, &status
);
1005 if(U_FAILURE(status
))
1007 log_data_err("Couldn't open converter %s\n",codepage
);
1010 log_verbose("Converter %s opened..\n", ucnv_getName(conv
, &status
));
1012 for(i
=0; i
<MAX_LENGTH
; i
++){
1013 buffer
[i
]=(char)0xF0;
1014 offsetBuffer
[i
]=0xFF;
1018 sourceLimit
=(UChar
*)src
+(sourceLen
);
1020 targetLimit
=targ
+MAX_LENGTH
;
1022 ucnv_fromUnicode (conv
,
1024 (const char *)targetLimit
,
1027 expectOffsets
? offs
: NULL
,
1031 if(status
!= expectedStatus
){
1032 log_err("ucnv_fromUnicode() failed for codepage=%s. Error =%s Expected=%s\n", codepage
, myErrorName(status
), myErrorName(expectedStatus
));
1036 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
1037 sourceLen
, targ
-buffer
);
1039 if(expectLen
!= targ
-buffer
)
1041 log_err("Expected %d chars out, got %d FROM Unicode to %s\n", expectLen
, targ
-buffer
, codepage
);
1042 log_verbose("Expected %d chars out, got %d FROM Unicode to %s\n", expectLen
, targ
-buffer
, codepage
);
1043 printSeqErr((const unsigned char *)buffer
, (int32_t)(targ
-buffer
));
1044 printSeqErr((const unsigned char*)expect
, expectLen
);
1048 if(memcmp(buffer
, expect
, expectLen
)){
1049 log_err("String does not match. FROM Unicode to codePage%s\n", codepage
);
1051 printSeqErr((const unsigned char *)buffer
, expectLen
);
1052 log_info("\nExpected:");
1053 printSeqErr((const unsigned char *)expect
, expectLen
);
1057 log_verbose("Matches!\n");
1060 if (expectOffsets
!= 0){
1061 log_verbose("comparing %d offsets..\n", targ
-buffer
);
1062 if(memcmp(offsetBuffer
,expectOffsets
,(targ
-buffer
) * sizeof(int32_t) )){
1063 log_err("did not get the expected offsets. for FROM Unicode to %s\n", codepage
);
1064 log_info("\nGot : ");
1065 printSeqErr((const unsigned char*)buffer
, (int32_t)(targ
-buffer
));
1066 for(p
=buffer
;p
<targ
;p
++)
1067 log_info("%d, ", offsetBuffer
[p
-buffer
]);
1068 log_info("\nExpected: ");
1069 for(i
=0; i
< (targ
-buffer
); i
++)
1070 log_info("%d,", expectOffsets
[i
]);
1078 static UBool
convertToU( const uint8_t *source
, int sourceLen
, const UChar
*expect
, int expectLen
,
1079 const char *codepage
, const int32_t *expectOffsets
, UBool doFlush
, UErrorCode expectedStatus
)
1081 UErrorCode status
= U_ZERO_ERROR
;
1082 UConverter
*conv
= 0;
1086 UChar buffer
[MAX_LENGTH
];
1087 int32_t offsetBuffer
[MAX_LENGTH
];
1091 uint8_t *sourceLimit
=0;
1095 conv
= ucnv_open(codepage
, &status
);
1096 if(U_FAILURE(status
))
1098 log_data_err("Couldn't open converter %s\n",codepage
);
1101 log_verbose("Converter %s opened..\n", ucnv_getName(conv
, &status
));
1105 for(i
=0; i
<MAX_LENGTH
; i
++){
1110 src
=(const char *)source
;
1111 sourceLimit
=(uint8_t*)(src
+(sourceLen
));
1113 targetLimit
=targ
+MAX_LENGTH
;
1118 ucnv_toUnicode (conv
,
1121 (const char **)&src
,
1122 (const char *)sourceLimit
,
1123 expectOffsets
? offs
: NULL
,
1128 if(status
!= expectedStatus
){
1129 log_err("ucnv_fromUnicode() failed for codepage=%s. Error =%s Expected=%s\n", codepage
, myErrorName(status
), myErrorName(expectedStatus
));
1132 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
1133 sourceLen
, targ
-buffer
);
1138 log_verbose("comparing %d uchars (%d bytes)..\n",expectLen
,expectLen
*2);
1140 if (expectOffsets
!= 0) {
1141 if(memcmp(offsetBuffer
, expectOffsets
, (targ
-buffer
) * sizeof(int32_t))){
1143 log_err("did not get the expected offsets from %s To UNICODE\n", codepage
);
1144 log_info("\nGot : ");
1145 for(p
=buffer
;p
<targ
;p
++)
1146 log_info("%d, ", offsetBuffer
[p
-buffer
]);
1147 log_info("\nExpected: ");
1148 for(i
=0; i
<(targ
-buffer
); i
++)
1149 log_info("%d, ", expectOffsets
[i
]);
1150 log_info("\nGot result:");
1151 for(i
=0; i
<(targ
-buffer
); i
++)
1152 log_info("0x%04X,", buffer
[i
]);
1153 log_info("\nFrom Input:");
1154 for(i
=0; i
<(src
-(const char *)source
); i
++)
1155 log_info("0x%02X,", (unsigned char)source
[i
]);
1159 if(memcmp(buffer
, expect
, expectLen
*2)){
1160 log_err("String does not match. from codePage %s TO Unicode\n", codepage
);
1162 printUSeqErr(buffer
, expectLen
);
1163 log_info("\nExpected:");
1164 printUSeqErr(expect
, expectLen
);
1168 log_verbose("Matches!\n");
1175 static UBool
testConvertFromU( const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
1176 const char *codepage
, UConverterFromUCallback callback
, const int32_t *expectOffsets
, UBool testReset
)
1178 UErrorCode status
= U_ZERO_ERROR
;
1179 UConverter
*conv
= 0;
1180 char junkout
[MAX_LENGTH
]; /* FIX */
1181 int32_t junokout
[MAX_LENGTH
]; /* FIX */
1188 int32_t realBufferSize
;
1189 char *realBufferEnd
;
1190 const UChar
*realSourceEnd
;
1191 const UChar
*sourceLimit
;
1192 UBool checkOffsets
= TRUE
;
1195 UConverterFromUCallback oldAction
= NULL
;
1196 const void* oldContext
= NULL
;
1198 for(i
=0;i
<MAX_LENGTH
;i
++)
1199 junkout
[i
] = (char)0xF0;
1200 for(i
=0;i
<MAX_LENGTH
;i
++)
1203 setNuConvTestName(codepage
, "FROM");
1205 log_verbose("\n========= %s\n", gNuConvTestName
);
1207 conv
= ucnv_open(codepage
, &status
);
1208 if(U_FAILURE(status
))
1210 log_data_err("Couldn't open converter %s\n",codepage
);
1214 log_verbose("Converter opened..\n");
1215 /*----setting the callback routine----*/
1216 ucnv_setFromUCallBack (conv
, callback
, NULL
, &oldAction
, &oldContext
, &status
);
1217 if (U_FAILURE(status
)) {
1218 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
1220 /*------------------------*/
1226 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
1227 realBufferEnd
= junkout
+ realBufferSize
;
1228 realSourceEnd
= source
+ sourceLen
;
1230 if ( gOutBufferSize
!= realBufferSize
)
1231 checkOffsets
= FALSE
;
1233 if( gInBufferSize
!= MAX_LENGTH
)
1234 checkOffsets
= FALSE
;
1238 end
= nct_min(targ
+ gOutBufferSize
, realBufferEnd
);
1239 sourceLimit
= nct_min(src
+ gInBufferSize
, realSourceEnd
);
1241 doFlush
= (UBool
)(sourceLimit
== realSourceEnd
);
1243 if(targ
== realBufferEnd
)
1245 log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ
, gNuConvTestName
);
1248 log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src
,sourceLimit
, targ
,end
, doFlush
?"TRUE":"FALSE");
1251 status
= U_ZERO_ERROR
;
1252 if(gInBufferSize
==999 && gOutBufferSize
==999)
1254 ucnv_fromUnicode (conv
,
1260 doFlush
, /* flush if we're at the end of the input data */
1263 ucnv_resetToUnicode(conv
);
1264 if(gInBufferSize
==999 && gOutBufferSize
==999)
1265 ucnv_resetToUnicode(conv
);
1267 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (U_SUCCESS(status
) && sourceLimit
< realSourceEnd
) );
1269 if(U_FAILURE(status
)) {
1270 log_err("Problem doing fromUnicode to %s, errcode %s %s\n", codepage
, myErrorName(status
), gNuConvTestName
);
1274 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
1275 sourceLen
, targ
-junkout
);
1279 char offset_str
[999];
1284 for(ptr
= junkout
;ptr
<targ
;ptr
++)
1286 sprintf(junk
+ strlen(junk
), "0x%02x, ", (0xFF) & (unsigned int)*ptr
);
1287 sprintf(offset_str
+ strlen(offset_str
), "0x%02x, ", (0xFF) & (unsigned int)junokout
[ptr
-junkout
]);
1291 printSeq((const unsigned char *)expect
, expectLen
);
1294 log_verbose("\nOffsets:");
1295 log_verbose(offset_str
);
1302 if(expectLen
!= targ
-junkout
)
1304 log_err("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
1305 log_verbose("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
1307 printSeqErr((const unsigned char*)junkout
, (int32_t)(targ
-junkout
));
1308 log_info("\nExpected:");
1309 printSeqErr((const unsigned char*)expect
, expectLen
);
1313 if (checkOffsets
&& (expectOffsets
!= 0) )
1315 log_verbose("comparing %d offsets..\n", targ
-junkout
);
1316 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t) )){
1317 log_err("did not get the expected offsets. %s", gNuConvTestName
);
1319 printSeqErr((const unsigned char*)junkout
, (int32_t)(targ
-junkout
));
1320 for(p
=junkout
;p
<targ
;p
++)
1321 log_err("%d, ", junokout
[p
-junkout
]);
1322 log_err("\nExpected: ");
1323 for(i
=0; i
<(targ
-junkout
); i
++)
1324 log_err("%d,", expectOffsets
[i
]);
1328 log_verbose("comparing..\n");
1329 if(!memcmp(junkout
, expect
, expectLen
))
1331 log_verbose("Matches!\n");
1336 log_err("String does not match. %s\n", gNuConvTestName
);
1337 printUSeqErr(source
, sourceLen
);
1339 printSeqErr((const unsigned char *)junkout
, expectLen
);
1340 log_info("\nExpected:");
1341 printSeqErr((const unsigned char *)expect
, expectLen
);
1347 static UBool
testConvertToU( const uint8_t *source
, int sourcelen
, const UChar
*expect
, int expectlen
,
1348 const char *codepage
, UConverterToUCallback callback
, const int32_t *expectOffsets
, UBool testReset
)
1350 UErrorCode status
= U_ZERO_ERROR
;
1351 UConverter
*conv
= 0;
1352 UChar junkout
[MAX_LENGTH
]; /* FIX */
1353 int32_t junokout
[MAX_LENGTH
]; /* FIX */
1355 const char *realSourceEnd
;
1356 const char *srcLimit
;
1362 UBool checkOffsets
= TRUE
;
1363 int32_t realBufferSize
;
1364 UChar
*realBufferEnd
;
1367 UConverterToUCallback oldAction
= NULL
;
1368 const void* oldContext
= NULL
;
1371 for(i
=0;i
<MAX_LENGTH
;i
++)
1372 junkout
[i
] = 0xFFFE;
1374 for(i
=0;i
<MAX_LENGTH
;i
++)
1377 setNuConvTestName(codepage
, "TO");
1379 log_verbose("\n========= %s\n", gNuConvTestName
);
1381 conv
= ucnv_open(codepage
, &status
);
1382 if(U_FAILURE(status
))
1384 log_data_err("Couldn't open converter %s\n",gNuConvTestName
);
1388 log_verbose("Converter opened..\n");
1389 /*----setting the callback routine----*/
1390 ucnv_setToUCallBack (conv
, callback
, NULL
, &oldAction
, &oldContext
, &status
);
1391 if (U_FAILURE(status
)) {
1392 log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status
));
1394 /*-------------------------------------*/
1396 src
= (const char *)source
;
1400 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
1401 realBufferEnd
= junkout
+ realBufferSize
;
1402 realSourceEnd
= src
+ sourcelen
;
1404 if ( gOutBufferSize
!= realBufferSize
)
1405 checkOffsets
= FALSE
;
1407 if( gInBufferSize
!= MAX_LENGTH
)
1408 checkOffsets
= FALSE
;
1412 end
= nct_min( targ
+ gOutBufferSize
, realBufferEnd
);
1413 srcLimit
= nct_min(realSourceEnd
, src
+ gInBufferSize
);
1415 if(targ
== realBufferEnd
)
1417 log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ
,gNuConvTestName
);
1420 log_verbose("calling toUnicode @ %08lx to %08lx\n", targ
,end
);
1422 /* oldTarg = targ; */
1424 status
= U_ZERO_ERROR
;
1425 doFlush
=(UBool
)((gInBufferSize
==999 && gOutBufferSize
==999)?(srcLimit
== realSourceEnd
) : FALSE
);
1427 ucnv_toUnicode (conv
,
1430 (const char **)&src
,
1431 (const char *)srcLimit
,
1433 doFlush
, /* flush if we're at the end of hte source data */
1436 ucnv_resetFromUnicode(conv
);
1437 if(gInBufferSize
==999 && gOutBufferSize
==999)
1438 ucnv_resetToUnicode(conv
);
1439 /* offs += (targ-oldTarg); */
1441 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (U_SUCCESS(status
) && (srcLimit
< realSourceEnd
)) ); /* while we just need another buffer */
1443 if(U_FAILURE(status
))
1445 log_err("Problem doing %s toUnicode, errcode %s %s\n", codepage
, myErrorName(status
), gNuConvTestName
);
1449 log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
1450 sourcelen
, targ
-junkout
);
1454 char offset_str
[999];
1461 for(ptr
= junkout
;ptr
<targ
;ptr
++)
1463 sprintf(junk
+ strlen(junk
), "0x%04x, ", (0xFFFF) & (unsigned int)*ptr
);
1464 sprintf(offset_str
+ strlen(offset_str
), "0x%04x, ", (0xFFFF) & (unsigned int)junokout
[ptr
-junkout
]);
1471 log_verbose("\nOffsets:");
1472 log_verbose(offset_str
);
1478 log_verbose("comparing %d uchars (%d bytes)..\n",expectlen
,expectlen
*2);
1480 if (checkOffsets
&& (expectOffsets
!= 0))
1482 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t))){
1484 log_err("did not get the expected offsets. %s",gNuConvTestName
);
1485 for(p
=junkout
;p
<targ
;p
++)
1486 log_err("%d, ", junokout
[p
-junkout
]);
1487 log_err("\nExpected: ");
1488 for(i
=0; i
<(targ
-junkout
); i
++)
1489 log_err("%d,", expectOffsets
[i
]);
1491 for(i
=0; i
<(targ
-junkout
); i
++)
1492 log_err("%X,", junkout
[i
]);
1494 for(i
=0; i
<(src
-(const char *)source
); i
++)
1495 log_err("%X,", (unsigned char)source
[i
]);
1499 if(!memcmp(junkout
, expect
, expectlen
*2))
1501 log_verbose("Matches!\n");
1506 log_err("String does not match. %s\n", gNuConvTestName
);
1507 log_verbose("String does not match. %s\n", gNuConvTestName
);
1509 printUSeq(junkout
, expectlen
);
1510 log_info("\nExpected:");
1511 printUSeq(expect
, expectlen
);
1517 static void TestResetBehaviour(void){
1518 #if !UCONFIG_NO_LEGACY_CONVERSION
1519 log_verbose("Testing Reset for DBCS and MBCS\n");
1521 static const UChar sampleText
[] = {0x00a1, 0xd801, 0xdc01, 0x00a4};
1522 static const uint8_t expected
[] = {0xa2, 0xae, 0xa1, 0xe0, 0xa2, 0xb4};
1523 static const int32_t offsets
[] = {0x00, 0x00, 0x01, 0x01, 0x03, 0x03 };
1526 static const UChar sampleText1
[] = {0x00a1, 0x00a4, 0x00a7, 0x00a8};
1527 static const uint8_t expected1
[] = {0xa2, 0xae,0xA2,0xB4,0xA1,0xD7,0xA1,0xA7};
1528 static const int32_t offsets1
[] = { 0,2,4,6};
1531 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1532 expected
, sizeof(expected
), "ibm-1363", UCNV_FROM_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1533 log_err("u-> ibm-1363 [UCNV_DBCS portion] not match.\n");
1534 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1535 expected
, sizeof(expected
), "ibm-1363", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1536 log_err("u-> ibm-1363 [UCNV_DBCS portion] not match.\n");
1538 if(!testConvertToU(expected1
, sizeof(expected1
),
1539 sampleText1
, sizeof(sampleText1
)/sizeof(sampleText1
[0]), "ibm-1363",UCNV_TO_U_CALLBACK_SUBSTITUTE
,
1541 log_err("ibm-1363 -> did not match.\n");
1543 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1544 expected
, sizeof(expected
), "ibm-1363", UCNV_FROM_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1545 log_err("u-> ibm-1363 [UCNV_MBCS] not match.\n");
1546 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1547 expected
, sizeof(expected
), "ibm-1363", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1548 log_err("u-> ibm-1363 [UCNV_MBCS] not match.\n");
1550 if(!testConvertToU(expected1
, sizeof(expected1
),
1551 sampleText1
, sizeof(sampleText1
)/sizeof(sampleText1
[0]), "ibm-1363",UCNV_TO_U_CALLBACK_SUBSTITUTE
,
1553 log_err("ibm-1363 -> did not match.\n");
1557 log_verbose("Testing Reset for ISO-2022-jp\n");
1559 static const UChar sampleText
[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
1561 static const uint8_t expected
[] = {0x1b, 0x24, 0x42,0x30,0x6c,0x43,0x7a,0x1b,0x28,0x42,
1565 static const int32_t offsets
[] = {0,0,0,0,0,1,1,2,2,2,2,3,5 };
1568 static const UChar sampleText1
[] = {0x4e00, 0x04e01, 0x0031,0x001A, 0x0032};
1569 static const uint8_t expected1
[] = {0x1b, 0x24, 0x42,0x30,0x6c,0x43,0x7a,0x1b,0x28,0x42,
1571 static const int32_t offsets1
[] = { 3,5,10,11,12};
1574 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1575 expected
, sizeof(expected
), "iso-2022-jp", UCNV_FROM_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1576 log_err("u-> not match.\n");
1577 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1578 expected
, sizeof(expected
), "iso-2022-jp", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1579 log_err("u-> not match.\n");
1581 if(!testConvertToU(expected1
, sizeof(expected1
),
1582 sampleText1
, sizeof(sampleText1
)/sizeof(sampleText1
[0]), "iso-2022-jp",UCNV_TO_U_CALLBACK_SUBSTITUTE
,
1584 log_err("iso-2022-jp -> did not match.\n");
1588 log_verbose("Testing Reset for ISO-2022-cn\n");
1590 static const UChar sampleText
[] = { 0x4e00, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
1592 static const uint8_t expected
[] = {
1593 0x1B, 0x24, 0x29, 0x41, 0x0E, 0x52, 0x3B,
1601 static const int32_t offsets
[] = {
1602 0, 0, 0, 0, 0, 0, 0,
1608 UChar sampleText1
[] = {0x4e00, 0x04e01, 0x0031,0x001A, 0x0032};
1609 static const uint8_t expected1
[] = {
1610 0x1B, 0x24, 0x29, 0x41, 0x0E, 0x52, 0x3B,
1612 0x1B, 0x24, 0x29, 0x47, 0x24, 0x22,
1616 static const int32_t offsets1
[] = { 5,7,13,16,17};
1619 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1620 expected
, sizeof(expected
), "iso-2022-cn", UCNV_FROM_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1621 log_err("u-> not match.\n");
1622 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1623 expected
, sizeof(expected
), "iso-2022-cn", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1624 log_err("u-> not match.\n");
1626 if(!testConvertToU(expected1
, sizeof(expected1
),
1627 sampleText1
, sizeof(sampleText1
)/sizeof(sampleText1
[0]), "iso-2022-cn",UCNV_TO_U_CALLBACK_SUBSTITUTE
,
1629 log_err("iso-2022-cn -> did not match.\n");
1632 log_verbose("Testing Reset for ISO-2022-kr\n");
1634 UChar sampleText
[] = { 0x4e00,0xd801, 0xdc01, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
1636 static const uint8_t expected
[] = {0x1B, 0x24, 0x29, 0x43,
1644 static const int32_t offsets
[] = {-1, -1, -1, -1,
1652 static const UChar sampleText1
[] = { 0x4e00,0x0041, 0x04e01, 0x0031, 0x0042, 0x0032};
1654 static const uint8_t expected1
[] = {0x1B, 0x24, 0x29, 0x43,
1662 static const int32_t offsets1
[] = {
1668 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1669 expected
, sizeof(expected
), "iso-2022-kr", UCNV_FROM_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1670 log_err("u-> iso-2022-kr [UCNV_DBCS] not match.\n");
1671 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1672 expected
, sizeof(expected
), "iso-2022-kr", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1673 log_err("u-> iso-2022-kr [UCNV_DBCS] not match.\n");
1674 if(!testConvertToU(expected1
, sizeof(expected1
),
1675 sampleText1
, sizeof(sampleText1
)/sizeof(sampleText1
[0]), "iso-2022-kr",UCNV_TO_U_CALLBACK_SUBSTITUTE
,
1677 log_err("iso-2022-kr -> did not match.\n");
1680 log_verbose("Testing Reset for HZ\n");
1682 static const UChar sampleText
[] = { 0x4e00, 0xd801, 0xdc01, 0x04e01, 0x0031, 0xd801, 0xdc01, 0x0032};
1684 static const uint8_t expected
[] = {0x7E, 0x7B, 0x52, 0x3B,
1686 0x7E, 0x7B, 0x36, 0x21,
1692 static const int32_t offsets
[] = {0,0,0,0,
1698 static const UChar sampleText1
[] = { 0x4e00, 0x0035, 0x04e01, 0x0031, 0x0041, 0x0032};
1700 static const uint8_t expected1
[] = {0x7E, 0x7B, 0x52, 0x3B,
1702 0x7E, 0x7B, 0x36, 0x21,
1708 static const int32_t offsets1
[] = {2,6,9,13,14,15
1712 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1713 expected
, sizeof(expected
), "HZ", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,NULL
, TRUE
))
1714 log_err("u-> not match.\n");
1715 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1716 expected
, sizeof(expected
), "HZ", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1717 log_err("u-> not match.\n");
1718 if(!testConvertToU(expected1
, sizeof(expected1
),
1719 sampleText1
, sizeof(sampleText1
)/sizeof(sampleText1
[0]), "hz",UCNV_TO_U_CALLBACK_SUBSTITUTE
,
1721 log_err("hz -> did not match.\n");
1726 log_verbose("Testing for UTF8\n");
1728 static const UChar sampleText
[] = { 0x4e00, 0x0701, 0x0031, 0xbfc1, 0xd801, 0xdc01, 0x0032};
1729 int32_t offsets
[]={0x00, 0x00, 0x00, 0x01, 0x01, 0x02,
1730 0x03, 0x03, 0x03, 0x04, 0x04, 0x04,
1732 static const uint8_t expected
[] = {0xe4, 0xb8, 0x80, 0xdc, 0x81, 0x31,
1733 0xeb, 0xbf, 0x81, 0xF0, 0x90, 0x90, 0x81, 0x32};
1736 static const int32_t fromOffsets
[] = { 0x0000, 0x0003, 0x0005, 0x0006, 0x0009, 0x0009, 0x000D };
1738 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1739 expected
, sizeof(expected
), "UTF8", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1740 log_err("u-> UTF8 with offsets and flush true did not match.\n");
1741 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1742 expected
, sizeof(expected
), "UTF8", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,NULL
, TRUE
))
1743 log_err("u-> UTF8 with offsets and flush true did not match.\n");
1744 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1745 expected
, sizeof(expected
), "UTF8", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,offsets
, TRUE
))
1746 log_err("u-> UTF8 with offsets and flush true did not match.\n");
1747 if(!testConvertFromU(sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]),
1748 expected
, sizeof(expected
), "UTF8", UCNV_FROM_U_CALLBACK_SUBSTITUTE
,NULL
, TRUE
))
1749 log_err("u-> UTF8 with offsets and flush true did not match.\n");
1750 if(!testConvertToU(expected
, sizeof(expected
),
1751 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8",UCNV_TO_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1752 log_err("UTF8 -> did not match.\n");
1753 if(!testConvertToU(expected
, sizeof(expected
),
1754 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8", UCNV_TO_U_CALLBACK_SUBSTITUTE
, NULL
, TRUE
))
1755 log_err("UTF8 -> did not match.\n");
1756 if(!testConvertToU(expected
, sizeof(expected
),
1757 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8",UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromOffsets
, TRUE
))
1758 log_err("UTF8 -> did not match.\n");
1759 if(!testConvertToU(expected
, sizeof(expected
),
1760 sampleText
, sizeof(sampleText
)/sizeof(sampleText
[0]), "UTF8", UCNV_TO_U_CALLBACK_SUBSTITUTE
, fromOffsets
, TRUE
))
1761 log_err("UTF8 -> did not match.\n");
1767 /* Test that U_TRUNCATED_CHAR_FOUND is set. */
1769 doTestTruncated(const char *cnvName
, const uint8_t *bytes
, int32_t length
) {
1773 UChar
*target
, *targetLimit
;
1774 const char *source
, *sourceLimit
;
1776 UErrorCode errorCode
;
1778 errorCode
=U_ZERO_ERROR
;
1779 cnv
=ucnv_open(cnvName
, &errorCode
);
1780 if(U_FAILURE(errorCode
)) {
1781 log_data_err("error TestTruncated: unable to open \"%s\" - %s\n", cnvName
, u_errorName(errorCode
));
1784 ucnv_setToUCallBack(cnv
, UCNV_TO_U_CALLBACK_STOP
, NULL
, NULL
, NULL
, &errorCode
);
1785 if(U_FAILURE(errorCode
)) {
1786 log_data_err("error TestTruncated: unable to set the stop callback on \"%s\" - %s\n",
1787 cnvName
, u_errorName(errorCode
));
1792 source
=(const char *)bytes
;
1793 sourceLimit
=source
+length
;
1795 targetLimit
=buffer
+LENGTHOF(buffer
);
1797 /* 1. input bytes with flush=FALSE, then input nothing with flush=TRUE */
1798 ucnv_toUnicode(cnv
, &target
, targetLimit
, &source
, sourceLimit
, NULL
, FALSE
, &errorCode
);
1799 if(U_FAILURE(errorCode
) || source
!=sourceLimit
|| target
!=buffer
) {
1800 log_err("error TestTruncated(%s, 1a): input bytes[%d], flush=FALSE: %s, input left %d, output %d\n",
1801 cnvName
, length
, u_errorName(errorCode
), (int)(sourceLimit
-source
), (int)(target
-buffer
));
1804 errorCode
=U_ZERO_ERROR
;
1807 ucnv_toUnicode(cnv
, &target
, targetLimit
, &source
, sourceLimit
, NULL
, TRUE
, &errorCode
);
1808 if(errorCode
!=U_TRUNCATED_CHAR_FOUND
|| target
!=buffer
) {
1809 log_err("error TestTruncated(%s, 1b): no input (previously %d), flush=TRUE: %s (should be U_TRUNCATED_CHAR_FOUND), output %d\n",
1810 cnvName
, (int)length
, u_errorName(errorCode
), (int)(target
-buffer
));
1813 /* 2. input bytes with flush=TRUE */
1814 ucnv_resetToUnicode(cnv
);
1816 errorCode
=U_ZERO_ERROR
;
1817 source
=(const char *)bytes
;
1819 ucnv_toUnicode(cnv
, &target
, targetLimit
, &source
, sourceLimit
, NULL
, TRUE
, &errorCode
);
1820 if(errorCode
!=U_TRUNCATED_CHAR_FOUND
|| source
!=sourceLimit
|| target
!=buffer
) {
1821 log_err("error TestTruncated(%s, 2): input bytes[%d], flush=TRUE: %s (should be U_TRUNCATED_CHAR_FOUND), input left %d, output %d\n",
1822 cnvName
, length
, u_errorName(errorCode
), (int)(sourceLimit
-source
), (int)(target
-buffer
));
1831 static const struct {
1832 const char *cnvName
;
1833 uint8_t bytes
[8]; /* partial input bytes resulting in no output */
1836 { "IMAP-mailbox-name", { 0x26 }, 1 }, /* & */
1837 { "IMAP-mailbox-name", { 0x26, 0x42 }, 2 }, /* &B */
1838 { "IMAP-mailbox-name", { 0x26, 0x42, 0x42 }, 3 }, /* &BB */
1839 { "IMAP-mailbox-name", { 0x26, 0x41, 0x41 }, 3 }, /* &AA */
1841 { "UTF-7", { 0x2b, 0x42 }, 2 }, /* +B */
1842 { "UTF-8", { 0xd1 }, 1 },
1844 { "UTF-16BE", { 0x4e }, 1 },
1845 { "UTF-16LE", { 0x4e }, 1 },
1846 { "UTF-16", { 0x4e }, 1 },
1847 { "UTF-16", { 0xff }, 1 },
1848 { "UTF-16", { 0xfe, 0xff, 0x4e }, 3 },
1850 { "UTF-32BE", { 0, 0, 0x4e }, 3 },
1851 { "UTF-32LE", { 0x4e }, 1 },
1852 { "UTF-32", { 0, 0, 0x4e }, 3 },
1853 { "UTF-32", { 0xff }, 1 },
1854 { "UTF-32", { 0, 0, 0xfe, 0xff, 0 }, 5 },
1855 { "SCSU", { 0x0e, 0x4e }, 2 }, /* SQU 0x4e */
1857 #if !UCONFIG_NO_LEGACY_CONVERSION
1858 { "BOCU-1", { 0xd5 }, 1 },
1860 { "Shift-JIS", { 0xe0 }, 1 },
1862 { "ibm-939", { 0x0e, 0x41 }, 2 } /* SO 0x41 */
1864 { "BOCU-1", { 0xd5 }, 1 ,}
1869 for(i
=0; i
<LENGTHOF(testCases
); ++i
) {
1870 doTestTruncated(testCases
[i
].cnvName
, testCases
[i
].bytes
, testCases
[i
].length
);
1874 typedef struct NameRange
{
1876 UChar32 start
, end
, start2
, end2
, notStart
, notEnd
;
1881 UErrorCode errorCode
;
1887 static const char *const completeSetNames
[]={
1899 #if !UCONFIG_NO_LEGACY_CONVERSION
1905 static const char *const lmbcsNames
[]={
1906 #if !UCONFIG_NO_LEGACY_CONVERSION
1922 static const NameRange nameRanges
[]={
1923 { "US-ASCII", 0, 0x7f, -1, -1, 0x80, 0x10ffff },
1924 #if !UCONFIG_NO_LEGACY_CONVERSION
1925 { "ibm-367", 0, 0x7f, -1, -1, 0x80, 0x10ffff },
1927 { "ISO-8859-1", 0, 0x7f, -1, -1, 0x100, 0x10ffff },
1928 #if !UCONFIG_NO_LEGACY_CONVERSION
1929 { "UTF-8", 0, 0xd7ff, 0xe000, 0x10ffff, 0xd800, 0xdfff },
1930 { "windows-1251", 0, 0x7f, 0x410, 0x44f, 0x3000, 0xd7ff },
1931 /* HZ test case fixed and moved to intltest's conversion.txt, ticket #6002 */
1932 { "shift-jis", 0x3041, 0x3093, 0x30a1, 0x30f3, 0x900, 0x1cff }
1934 { "UTF-8", 0, 0xd7ff, 0xe000, 0x10ffff, 0xd800, 0xdfff }
1938 /* open an empty set */
1939 set
=uset_open(1, 0);
1941 count
=ucnv_countAvailable();
1942 for(i
=0; i
<count
; ++i
) {
1943 errorCode
=U_ZERO_ERROR
;
1944 name
=ucnv_getAvailableName(i
);
1945 cnv
=ucnv_open(name
, &errorCode
);
1946 if(U_FAILURE(errorCode
)) {
1947 log_err("error: unable to open converter %s - %s\n",
1948 name
, u_errorName(errorCode
));
1953 ucnv_getUnicodeSet(cnv
, set
, UCNV_ROUNDTRIP_SET
, &errorCode
);
1954 if(U_FAILURE(errorCode
)) {
1955 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n",
1956 name
, u_errorName(errorCode
));
1957 } else if(uset_size(set
)==0) {
1958 log_err("error: ucnv_getUnicodeSet(%s) returns an empty set\n", name
);
1964 /* test converters that are known to convert all of Unicode (except maybe for surrogates) */
1965 for(i
=0; i
<LENGTHOF(completeSetNames
); ++i
) {
1966 errorCode
=U_ZERO_ERROR
;
1967 name
=completeSetNames
[i
];
1968 cnv
=ucnv_open(name
, &errorCode
);
1969 if(U_FAILURE(errorCode
)) {
1970 log_err("error: unable to open converter %s - %s\n",
1971 name
, u_errorName(errorCode
));
1976 ucnv_getUnicodeSet(cnv
, set
, UCNV_ROUNDTRIP_SET
, &errorCode
);
1977 if(U_FAILURE(errorCode
)) {
1978 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n",
1979 name
, u_errorName(errorCode
));
1980 } else if(!uset_containsRange(set
, 0, 0xd7ff) || !uset_containsRange(set
, 0xe000, 0x10ffff)) {
1981 log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicode set\n", name
);
1987 /* test LMBCS variants which convert all of Unicode except for U+F6xx */
1988 for(i
=0; i
<LENGTHOF(lmbcsNames
); ++i
) {
1989 errorCode
=U_ZERO_ERROR
;
1991 cnv
=ucnv_open(name
, &errorCode
);
1992 if(U_FAILURE(errorCode
)) {
1993 log_err("error: unable to open converter %s - %s\n",
1994 name
, u_errorName(errorCode
));
1999 ucnv_getUnicodeSet(cnv
, set
, UCNV_ROUNDTRIP_SET
, &errorCode
);
2000 if(U_FAILURE(errorCode
)) {
2001 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n",
2002 name
, u_errorName(errorCode
));
2003 } else if(!uset_containsRange(set
, 0, 0xf5ff) || !uset_containsRange(set
, 0xf700, 0x10ffff)) {
2004 log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicode set (minus U+F6xx)\n", name
);
2010 /* test specific sets */
2011 for(i
=0; i
<LENGTHOF(nameRanges
); ++i
) {
2012 errorCode
=U_ZERO_ERROR
;
2013 name
=nameRanges
[i
].name
;
2014 cnv
=ucnv_open(name
, &errorCode
);
2015 if(U_FAILURE(errorCode
)) {
2016 log_data_err("error: unable to open converter %s - %s\n",
2017 name
, u_errorName(errorCode
));
2022 ucnv_getUnicodeSet(cnv
, set
, UCNV_ROUNDTRIP_SET
, &errorCode
);
2023 if(U_FAILURE(errorCode
)) {
2024 log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n",
2025 name
, u_errorName(errorCode
));
2027 !uset_containsRange(set
, nameRanges
[i
].start
, nameRanges
[i
].end
) ||
2028 (nameRanges
[i
].start2
>=0 && !uset_containsRange(set
, nameRanges
[i
].start2
, nameRanges
[i
].end2
))
2030 log_err("error: ucnv_getUnicodeSet(%s) does not contain the expected ranges\n", name
);
2031 } else if(nameRanges
[i
].notStart
>=0) {
2032 /* simulate containsAny() with the C API */
2033 uset_complement(set
);
2034 if(!uset_containsRange(set
, nameRanges
[i
].notStart
, nameRanges
[i
].notEnd
)) {
2035 log_err("error: ucnv_getUnicodeSet(%s) contains part of the unexpected range\n", name
);
2042 errorCode
= U_ZERO_ERROR
;
2043 ucnv_getUnicodeSet(NULL
, set
, UCNV_ROUNDTRIP_SET
, &errorCode
);
2044 if (errorCode
!= U_ILLEGAL_ARGUMENT_ERROR
) {
2045 log_err("error: ucnv_getUnicodeSet(NULL) returned wrong status code %s\n", u_errorName(errorCode
));
2047 errorCode
= U_PARSE_ERROR
;
2048 /* Make sure that it does nothing if an error is passed in. Difficult to proper test for. */
2049 ucnv_getUnicodeSet(NULL
, NULL
, UCNV_ROUNDTRIP_SET
, &errorCode
);
2050 if (errorCode
!= U_PARSE_ERROR
) {
2051 log_err("error: ucnv_getUnicodeSet(NULL) returned wrong status code %s\n", u_errorName(errorCode
));