1
/********************************************************************
3
* Copyright (c) 1997-2001, International Business Machines Corporation and
4
* others. All Rights Reserved.
5
********************************************************************/
9
* Modification History:
11
* Madhu Katragadda 7/21/1999 Testing error callback routines
12
**************************************************************************************
19
#include "unicode/uloc.h"
20
#include "unicode/ucnv.h"
21
#include "unicode/ucnv_err.h"
23
#include "unicode/utypes.h"
24
#include "unicode/ustring.h"
26
#define NEW_MAX_BUFFER 999
28
#define nct_min(x,y) ((x<y) ? x : y)
29
#define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
31
static int32_t gInBufferSize = 0;
32
static int32_t gOutBufferSize = 0;
33
static char gNuConvTestName[1024];
35
static void printSeq(const uint8_t* a, int len)
40
log_verbose("0x%02X, ", a[i++]);
44
static void printUSeq(const UChar* a, int len)
49
log_verbose(" 0x%04x, ", a[i++]);
53
static void printSeqErr(const uint8_t* a, int len)
58
fprintf(stderr, " 0x%02x, ", a[i++]);
59
fprintf(stderr, "}\n");
62
static void printUSeqErr(const UChar* a, int len)
67
fprintf(stderr, "0x%04x, ", a[i++]);
68
fprintf(stderr,"}\n");
71
static void setNuConvTestName(const char *codepage, const char *direction)
73
sprintf(gNuConvTestName, "[testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
81
void addTestConvertErrorCallBack(TestNode** root);
83
void addTestConvertErrorCallBack(TestNode** root)
85
addTest(root, &TestSkipCallBack, "tsconv/nccbtst/TestSkipCallBack");
86
addTest(root, &TestStopCallBack, "tsconv/nccbtst/TestStopCallBack");
87
addTest(root, &TestSubCallBack, "tsconv/nccbtst/TestSubCallBack");
88
addTest(root, &TestSubWithValueCallBack, "tsconv/nccbtst/TestSubWithValueCallBack");
89
addTest(root, &TestLegalAndOtherCallBack, "tsconv/nccbtst/TestLegalAndOtherCallBack");
90
addTest(root, &TestSingleByteCallBack, "tsconv/nccbtst/TestSingleByteCallBack");
93
static void TestSkipCallBack()
95
TestSkip(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
96
TestSkip(1,NEW_MAX_BUFFER);
98
TestSkip(NEW_MAX_BUFFER, 1);
101
static void TestStopCallBack()
103
TestStop(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
104
TestStop(1,NEW_MAX_BUFFER);
106
TestStop(NEW_MAX_BUFFER, 1);
109
static void TestSubCallBack()
111
TestSub(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
112
TestSub(1,NEW_MAX_BUFFER);
114
TestSub(NEW_MAX_BUFFER, 1);
115
TestEBCDIC_STATEFUL_Sub(1, 1);
116
TestEBCDIC_STATEFUL_Sub(1, NEW_MAX_BUFFER);
117
TestEBCDIC_STATEFUL_Sub(NEW_MAX_BUFFER, 1);
118
TestEBCDIC_STATEFUL_Sub(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
123
static void TestSubWithValueCallBack()
125
TestSubWithValue(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
126
TestSubWithValue(1,NEW_MAX_BUFFER);
127
TestSubWithValue(1,1);
128
TestSubWithValue(NEW_MAX_BUFFER, 1);
131
static void TestLegalAndOtherCallBack()
133
TestLegalAndOthers(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
134
TestLegalAndOthers(1,NEW_MAX_BUFFER);
135
TestLegalAndOthers(1,1);
136
TestLegalAndOthers(NEW_MAX_BUFFER, 1);
139
static void TestSingleByteCallBack()
141
TestSingleByte(NEW_MAX_BUFFER, NEW_MAX_BUFFER);
142
TestSingleByte(1,NEW_MAX_BUFFER);
144
TestSingleByte(NEW_MAX_BUFFER, 1);
147
static void TestSkip(int32_t inputsize, int32_t outputsize)
149
static const UChar sampleText[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
150
static const UChar sampleText2[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
152
static const uint8_t expskipIBM_949[]= {
153
0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xc8, 0xd3 };
155
static const uint8_t expskipIBM_943[] = {
156
0x9f, 0xaf, 0x9f, 0xb1, 0x89, 0x59 };
158
static const uint8_t expskipIBM_930[] = {
159
0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x46, 0x6b };
161
static const UChar IBM_949skiptoUnicode[]= {0x0000, 0xAC00, 0xAC01, 0xD700 };
162
static const UChar IBM_943skiptoUnicode[]= { 0x6D63, 0x6D64, 0x6D66 };
163
static const UChar IBM_930skiptoUnicode[]= { 0x6D63, 0x6D64, 0x6D66 };
166
static const int32_t toIBM949Offsskip [] = { 0, 1, 1, 2, 2, 4, 4};
167
static const int32_t toIBM943Offsskip [] = { 0, 0, 1, 1, 3, 3};
168
static const int32_t toIBM930Offsskip [] = { 0, 0, 0, 1, 1, 3, 3};
170
static const int32_t fromIBM949Offs [] = { 0, 1, 3, 5};
171
static const int32_t fromIBM943Offs [] = { 0, 2, 4};
172
static const int32_t fromIBM930Offs [] = { 1, 3, 5};
174
gInBufferSize = inputsize;
175
gOutBufferSize = outputsize;
178
log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SKIP \n");
180
if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
181
expskipIBM_949, sizeof(expskipIBM_949), "ibm-949",
182
UCNV_FROM_U_CALLBACK_SKIP, toIBM949Offsskip, NULL, 0 ))
183
log_err("u-> ibm-949 with skip did not match.\n");
184
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
185
expskipIBM_943, sizeof(expskipIBM_943), "ibm-943",
186
UCNV_FROM_U_CALLBACK_SKIP, toIBM943Offsskip, NULL, 0 ))
187
log_err("u-> ibm-943 with skip did not match.\n");
188
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
189
expskipIBM_930, sizeof(expskipIBM_930), "ibm-930",
190
UCNV_FROM_U_CALLBACK_SKIP, toIBM930Offsskip , NULL, 0))
191
log_err("u-> ibm-930 with skip did not match.\n");
194
static const UChar fromU[] = { 0x61, 0xff5e, 0x62, 0x6d63, 0xff5e, 0x6d64, 0x63, 0xff5e, 0x6d66 };
195
static const uint8_t fromUBytes[] = { 0x62, 0x63, 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x0f, 0x64, 0x0e, 0x46, 0x6b };
196
static const int32_t fromUOffsets[] = { 0, 2, 3, 3, 3, 5, 5, 6, 6, 8, 8, 8 };
198
/* test ibm-930 (EBCDIC_STATEFUL) with fallbacks that are not taken to check correct state transitions */
199
if(!testConvertFromUnicode(fromU, sizeof(fromU)/U_SIZEOF_UCHAR,
200
fromUBytes, sizeof(fromUBytes),
202
UCNV_FROM_U_CALLBACK_SKIP, fromUOffsets,
205
log_err("u->ibm-930 with skip with untaken fallbacks did not match.\n");
210
static const UChar usasciiFromU[] = { 0x61, 0x80, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 };
211
static const uint8_t usasciiFromUBytes[] = { 0x61, 0x31, 0x39 };
212
static const int32_t usasciiFromUOffsets[] = { 0, 3, 6 };
214
static const UChar latin1FromU[] = { 0x61, 0xa0, 0x4e00, 0x31, 0xd800, 0xdfff, 0x39 };
215
static const uint8_t latin1FromUBytes[] = { 0x61, 0xa0, 0x31, 0x39 };
216
static const int32_t latin1FromUOffsets[] = { 0, 1, 3, 6 };
219
if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR,
220
usasciiFromUBytes, sizeof(usasciiFromUBytes),
222
UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets,
225
log_err("u->US-ASCII with skip did not match.\n");
228
/* SBCS NLTC codepage 367 for US-ASCII */
229
if(!testConvertFromUnicode(usasciiFromU, sizeof(usasciiFromU)/U_SIZEOF_UCHAR,
230
usasciiFromUBytes, sizeof(usasciiFromUBytes),
232
UCNV_FROM_U_CALLBACK_SKIP, usasciiFromUOffsets,
235
log_err("u->ibm-367 with skip did not match.\n");
239
if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR,
240
latin1FromUBytes, sizeof(latin1FromUBytes),
242
UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets,
245
log_err("u->LATIN_1 with skip did not match.\n");
249
if(!testConvertFromUnicode(latin1FromU, sizeof(latin1FromU)/U_SIZEOF_UCHAR,
250
latin1FromUBytes, sizeof(latin1FromUBytes),
252
UCNV_FROM_U_CALLBACK_SKIP, latin1FromUOffsets,
255
log_err("u->windows-1252 with skip did not match.\n");
260
static const UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
261
static const uint8_t toIBM943[]= { 0x61, 0x61 };
262
static const int32_t offset[]= {0, 4};
265
static const UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
266
static const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
269
static const int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2, 6, 7, 7};
272
static const UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
273
static const uint8_t to_euc_tw[]={
274
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
275
0x61, 0xe6, 0xca, 0x8a,
277
static const int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 6, 7, 7, 8,};
280
static const UChar iso_2022_jp_inputText[]={0x0041, 0x00E9/*unassigned*/,0x0042, };
281
static const uint8_t to_iso_2022_jp[]={
286
static const int32_t from_iso_2022_jpOffs [] ={0,2};
288
static const UChar iso_2022_jp_inputText1[]={0x3000, 0x00E9, 0x3001, };
289
static const uint8_t to_iso_2022_jp1[]={
290
0x1b, 0x24, 0x42, 0x21, 0x21,
294
static const int32_t from_iso_2022_jpOffs1 [] ={0,0,0,0,0,2,2,};
297
UChar const iso_2022_jp_inputText2[]={0x0041, 0x00E9/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
298
static const uint8_t to_iso_2022_jp2[]={
303
static const int32_t from_iso_2022_jpOffs2 [] ={0,2};
306
static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
307
static const uint8_t to_iso_2022_cn[]={
311
static const int32_t from_iso_2022_cnOffs [] ={
317
static const UChar iso_2022_cn_inputText1[]={0x0041, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
318
static const uint8_t to_iso_2022_cn1[]={
323
static const int32_t from_iso_2022_cnOffs1 [] ={0,0,2,2};
326
static const UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
327
static const uint8_t to_iso_2022_kr[]={
328
0x1b, 0x24, 0x29, 0x43,
334
static const int32_t from_iso_2022_krOffs [] ={
343
static const UChar iso_2022_kr_inputText1[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0,0xd801/*illegal*/, 0x0042, };
344
static const uint8_t to_iso_2022_kr1[]={
345
0x1b, 0x24, 0x29, 0x43,
351
static const int32_t from_iso_2022_krOffs1 [] ={
359
static const UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
361
static const uint8_t to_hz[]={
363
0x7e, 0x7b, 0x26, 0x30,
368
static const int32_t from_hzOffs [] ={
375
static const UChar hz_inputText1[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0,0xd801/*illegal*/, 0x0042, };
377
static const uint8_t to_hz1[]={
379
0x7e, 0x7b, 0x26, 0x30,
384
static const int32_t from_hzOffs1 [] ={
392
static const UChar SCSU_inputText[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
394
static const uint8_t to_SCSU[]={
400
static const int32_t from_SCSUOffs [] ={
406
static const UChar iscii_inputText[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
407
static const uint8_t to_iscii[]={
411
static const int32_t from_isciiOffs [] ={
416
static const UChar iscii_inputText1[]={0x0044, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
417
static const uint8_t to_iscii1[]={
422
static const int32_t from_isciiOffs1 [] ={0,2};
424
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
425
toIBM943, sizeof(toIBM943), "ibm-943",
426
UCNV_FROM_U_CALLBACK_SKIP, offset, NULL, 0 ))
427
log_err("u-> ibm-943 with skip did not match.\n");
429
if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
430
to_euc_jp, sizeof(to_euc_jp), "euc-jp",
431
UCNV_FROM_U_CALLBACK_SKIP, fromEUC_JPOffs, NULL, 0 ))
432
log_err("u-> euc-jp with skip did not match.\n");
434
if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
435
to_euc_tw, sizeof(to_euc_tw), "euc-tw",
436
UCNV_FROM_U_CALLBACK_SKIP, from_euc_twOffs, NULL, 0 ))
437
log_err("u-> euc-tw with skip did not match.\n");
440
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
441
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
442
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs, NULL, 0 ))
443
log_err("u-> iso-2022-jp with skip did not match.\n");
445
if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
446
to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
447
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs1, NULL, 0 ))
448
log_err("u-> iso-2022-jp with skip did not match.\n");
450
if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
451
to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
452
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs2, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
453
log_err("u-> iso-2022-jp with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
456
if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
457
to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
458
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs, NULL, 0 ))
459
log_err("u-> iso-2022-cn with skip did not match.\n");
461
if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText1, sizeof(iso_2022_cn_inputText1)/sizeof(iso_2022_cn_inputText1[0]),
462
to_iso_2022_cn1, sizeof(to_iso_2022_cn1), "iso-2022-cn",
463
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_cnOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
464
log_err("u-> iso-2022-cn with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
467
if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
468
to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
469
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs, NULL, 0 ))
470
log_err("u-> iso-2022-kr with skip did not match.\n");
472
if(!testConvertFromUnicodeWithContext(iso_2022_kr_inputText1, sizeof(iso_2022_kr_inputText1)/sizeof(iso_2022_kr_inputText1[0]),
473
to_iso_2022_kr1, sizeof(to_iso_2022_kr1), "iso-2022-kr",
474
UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_krOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
475
log_err("u-> iso-2022-kr with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
478
if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
479
to_hz, sizeof(to_hz), "HZ",
480
UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs, NULL, 0 ))
481
log_err("u-> HZ with skip did not match.\n");
483
if(!testConvertFromUnicodeWithContext(hz_inputText1, sizeof(hz_inputText1)/sizeof(hz_inputText1[0]),
484
to_hz1, sizeof(to_hz1), "hz",
485
UCNV_FROM_U_CALLBACK_SKIP, from_hzOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
486
log_err("u-> hz with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
489
if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
490
to_SCSU, sizeof(to_SCSU), "SCSU",
491
UCNV_FROM_U_CALLBACK_SKIP, from_SCSUOffs, NULL, 0 ))
492
log_err("u-> SCSU with skip did not match.\n");
495
if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
496
to_iscii, sizeof(to_iscii), "ISCII,version=0",
497
UCNV_FROM_U_CALLBACK_SKIP, from_isciiOffs, NULL, 0 ))
498
log_err("u-> iscii with skip did not match.\n");
500
if(!testConvertFromUnicodeWithContext(iscii_inputText1, sizeof(iscii_inputText1)/sizeof(iscii_inputText1[0]),
501
to_iscii1, sizeof(to_iscii1), "ISCII,version=0",
502
UCNV_FROM_U_CALLBACK_SKIP, from_isciiOffs1, NULL, 0,UCNV_SKIP_STOP_ON_ILLEGAL,U_ILLEGAL_CHAR_FOUND ))
503
log_err("u-> iscii with skip & UCNV_SKIP_STOP_ON_ILLEGAL did not match.\n");
508
log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SKIP \n");
510
if(!testConvertToUnicode(expskipIBM_949, sizeof(expskipIBM_949),
511
IBM_949skiptoUnicode, sizeof(IBM_949skiptoUnicode)/sizeof(IBM_949skiptoUnicode),"ibm-949",
512
UCNV_TO_U_CALLBACK_SKIP, fromIBM949Offs, NULL, 0 ))
513
log_err("ibm-949->u with skip did not match.\n");
514
if(!testConvertToUnicode(expskipIBM_943, sizeof(expskipIBM_943),
515
IBM_943skiptoUnicode, sizeof(IBM_943skiptoUnicode)/sizeof(IBM_943skiptoUnicode[0]),"ibm-943",
516
UCNV_TO_U_CALLBACK_SKIP, fromIBM943Offs, NULL, 0 ))
517
log_err("ibm-943->u with skip did not match.\n");
519
if(!testConvertToUnicode(expskipIBM_930, sizeof(expskipIBM_930),
520
IBM_930skiptoUnicode, sizeof(IBM_930skiptoUnicode)/sizeof(IBM_930skiptoUnicode[0]),"ibm-930",
521
UCNV_TO_U_CALLBACK_SKIP, fromIBM930Offs, NULL, 0 ))
522
log_err("ibm-930->u with skip did not match.\n");
525
static const uint8_t usasciiToUBytes[] = { 0x61, 0x80, 0x31 };
526
static const UChar usasciiToU[] = { 0x61, 0x31 };
527
static const int32_t usasciiToUOffsets[] = { 0, 2 };
529
static const uint8_t latin1ToUBytes[] = { 0x61, 0xa0, 0x31 };
530
static const UChar latin1ToU[] = { 0x61, 0xa0, 0x31 };
531
static const int32_t latin1ToUOffsets[] = { 0, 1, 2 };
534
if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes),
535
usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR,
537
UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets,
540
log_err("US-ASCII->u with skip did not match.\n");
543
/* SBCS NLTC codepage 367 for US-ASCII */
544
if(!testConvertToUnicode(usasciiToUBytes, sizeof(usasciiToUBytes),
545
usasciiToU, sizeof(usasciiToU)/U_SIZEOF_UCHAR,
547
UCNV_TO_U_CALLBACK_SKIP, usasciiToUOffsets,
550
log_err("ibm-367->u with skip did not match.\n");
554
if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes),
555
latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR,
557
UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets,
560
log_err("LATIN_1->u with skip did not match.\n");
564
if(!testConvertToUnicode(latin1ToUBytes, sizeof(latin1ToUBytes),
565
latin1ToU, sizeof(latin1ToU)/U_SIZEOF_UCHAR,
567
UCNV_TO_U_CALLBACK_SKIP, latin1ToUOffsets,
570
log_err("windows-1252->u with skip did not match.\n");
575
const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={
576
0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
578
UChar EBCIDIC_STATEFUL_toUnicode[] ={ 0x6d63, 0x03b4
580
int32_t from_EBCIDIC_STATEFULOffsets []={ 1, 5};
584
const uint8_t sampleTxt_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
585
0x8f, 0xda, 0xa1, /*unassigned*/
588
UChar euc_jptoUnicode[]={ 0x0061, 0x4edd, 0x5bec, 0x00a2};
589
int32_t from_euc_jpOffs [] ={ 0, 1, 3, 9};
592
const uint8_t sampleTxt_euc_tw[]={ 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
593
0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
596
UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2, 0x8706, 0x8a, };
597
int32_t from_euc_twOffs [] ={ 0, 1, 3, 11, 13};
599
const uint8_t sampleTxt_iso_2022_jp[]={
601
0x1b, 0x24, 0x42, 0x2A, 0x44, /*unassigned*/
602
0x1b, 0x28, 0x42, 0x42,
605
UChar iso_2022_jptoUnicode[]={ 0x41,0x42 };
606
int32_t from_iso_2022_jpOffs [] ={ 0,9 };
609
const uint8_t sampleTxt_iso_2022_cn[]={
611
0x1B, 0x24, 0x29, 0x47,
612
0x0E, 0x40, 0x6f, /*unassigned*/
617
UChar iso_2022_cntoUnicode[]={ 0x41, 0x44,0x42 };
618
int32_t from_iso_2022_cnOffs [] ={ 1, 2, 11 };
621
const uint8_t sampleTxt_iso_2022_kr[]={
622
0x1b, 0x24, 0x29, 0x43,
630
UChar iso_2022_krtoUnicode[]={ 0x41,0x03A0,0x51, 0x42,0x43};
631
int32_t from_iso_2022_krOffs [] ={ 4, 9, 12, 13 , 14 };
634
const uint8_t sampleTxt_hz[]={
636
0x7e, 0x7b, 0x26, 0x30,
637
0x7f, 0x1E, /*unassigned*/
640
0x7e, 0x7b, 0x7f, 0x1E,/*unassigned*/
643
UChar hztoUnicode[]={
650
int32_t from_hzOffs [] ={0,3,7,11,18, };
653
const uint8_t sampleTxt_iscii[]={
663
UChar isciitoUnicode[]={
672
int32_t from_isciiOffs [] ={0,1,3,4,5,7 };
675
const uint8_t sampleTxtLMBCS[]={ 0x12, 0xc9, 0x50,
676
0x12, 0x92, 0xa0, /*unassigned*/
679
UChar LMBCSToUnicode[]={ 0x4e2e, 0xe5c4};
680
int32_t fromLMBCS[] = {0, 6};
682
if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
683
EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
684
UCNV_TO_U_CALLBACK_SKIP, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
685
log_err("EBCIDIC_STATEFUL->u with skip did not match.\n");
689
if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
690
euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
691
UCNV_TO_U_CALLBACK_SKIP, from_euc_jpOffs , NULL, 0))
692
log_err("euc-jp->u with skip did not match.\n");
696
if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
697
euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
698
UCNV_TO_U_CALLBACK_SKIP, from_euc_twOffs , NULL, 0))
699
log_err("euc-tw->u with skip did not match.\n");
702
if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
703
iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
704
UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_jpOffs , NULL, 0))
705
log_err("iso-2022-jp->u with skip did not match.\n");
707
if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
708
iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
709
UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_cnOffs , NULL, 0))
710
log_err("iso-2022-cn->u with skip did not match.\n");
712
if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
713
iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
714
UCNV_TO_U_CALLBACK_SKIP, from_iso_2022_krOffs , NULL, 0))
715
log_err("iso-2022-kr->u with skip did not match.\n");
717
if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
718
hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
719
UCNV_TO_U_CALLBACK_SKIP, from_hzOffs , NULL, 0))
720
log_err("HZ->u with skip did not match.\n");
722
if(!testConvertToUnicode(sampleTxt_iscii, sizeof(sampleTxt_iscii),
723
isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
724
UCNV_TO_U_CALLBACK_SKIP, from_isciiOffs , NULL, 0))
725
log_err("iscii->u with skip did not match.\n");
727
if(/* broken for icu 1.6 and 1.6.0.1, do not test */uprv_strcmp("1.7", U_ICU_VERSION) != 0 && !testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
728
LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS-1",
729
UCNV_TO_U_CALLBACK_SKIP, fromLMBCS , NULL, 0))
730
log_err("LMBCS->u with skip did not match.\n");
733
log_verbose("Testing to Unicode for UTF-8 with UCNV_TO_U_CALLBACK_SKIP \n");
735
const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c,
737
UChar expected1[] = { 0x0031, 0x4e8c, 0x0061};
738
int32_t offsets1[] = { 0x0000, 0x0001, 0x0006};
740
if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
741
expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
742
UCNV_TO_U_CALLBACK_SKIP, offsets1, NULL, 0 ))
743
log_err("utf8->u with skip did not match.\n");;
746
log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SKIP \n");
748
const uint8_t sampleText1[] = { 0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,};
749
UChar expected1[] = { 0x00ba, 0x008c, 0x00f8, 0x0061,0xfffe,0xfffe};
750
int32_t offsets1[] = { 0x0000, 0x0001,0x0002,0x0003,4,5};
752
if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
753
expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
754
UCNV_TO_U_CALLBACK_SKIP, offsets1, NULL, 0 ))
755
log_err("scsu->u with stop did not match.\n");;
759
static void TestStop(int32_t inputsize, int32_t outputsize)
761
static const UChar sampleText[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
762
static const UChar sampleText2[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
764
static const uint8_t expstopIBM_949[]= {
765
0x00, 0xb0, 0xa1, 0xb0, 0xa2};
767
static const uint8_t expstopIBM_943[] = {
768
0x9f, 0xaf, 0x9f, 0xb1};
770
static const uint8_t expstopIBM_930[] = {
771
0x0e, 0x5d, 0x5f, 0x5d, 0x63};
773
static const UChar IBM_949stoptoUnicode[]= {0x0000, 0xAC00, 0xAC01};
774
static const UChar IBM_943stoptoUnicode[]= { 0x6D63, 0x6D64};
775
static const UChar IBM_930stoptoUnicode[]= { 0x6D63, 0x6D64};
778
static const int32_t toIBM949Offsstop [] = { 0, 1, 1, 2, 2};
779
static const int32_t toIBM943Offsstop [] = { 0, 0, 1, 1};
780
static const int32_t toIBM930Offsstop [] = { 0, 0, 0, 1, 1};
782
static const int32_t fromIBM949Offs [] = { 0, 1, 3};
783
static const int32_t fromIBM943Offs [] = { 0, 2};
784
static const int32_t fromIBM930Offs [] = { 1, 3};
786
gInBufferSize = inputsize;
787
gOutBufferSize = outputsize;
789
if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
790
expstopIBM_949, sizeof(expstopIBM_949), "ibm-949",
791
UCNV_FROM_U_CALLBACK_STOP, toIBM949Offsstop, NULL, 0 ))
792
log_err("u-> ibm-949 with stop did not match.\n");
793
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
794
expstopIBM_943, sizeof(expstopIBM_943), "ibm-943",
795
UCNV_FROM_U_CALLBACK_STOP, toIBM943Offsstop , NULL, 0))
796
log_err("u-> ibm-943 with stop did not match.\n");
797
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
798
expstopIBM_930, sizeof(expstopIBM_930), "ibm-930",
799
UCNV_FROM_U_CALLBACK_STOP, toIBM930Offsstop, NULL, 0 ))
800
log_err("u-> ibm-930 with stop did not match.\n");
802
log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_STOP \n");
804
static const UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
805
static const uint8_t toIBM943[]= { 0x61,};
806
static const int32_t offset[]= {0,} ;
809
static const UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
810
static const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,};
811
static const int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2,};
814
static const UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
815
static const uint8_t to_euc_tw[]={
816
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,};
817
static const int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2,};
820
static const UChar iso_2022_jp_inputText[]={0x0041, 0x00E9, 0x0042, };
821
static const uint8_t to_iso_2022_jp[]={
825
static const int32_t from_iso_2022_jpOffs [] ={0,};
828
static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
829
static const uint8_t to_iso_2022_cn[]={
833
static const int32_t from_iso_2022_cnOffs [] ={
839
static const UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
840
static const uint8_t to_iso_2022_kr[]={
841
0x1b, 0x24, 0x29, 0x43,
845
static const int32_t from_iso_2022_krOffs [] ={
852
static const UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
854
static const uint8_t to_hz[]={
856
0x7e, 0x7b, 0x26, 0x30,
859
static const int32_t from_hzOffs [] ={
865
static const UChar iscii_inputText[]={ 0x0041, 0x3712, 0x0042, };
866
static const uint8_t to_iscii[]={
869
static const int32_t from_isciiOffs [] ={
873
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
874
toIBM943, sizeof(toIBM943), "ibm-943",
875
UCNV_FROM_U_CALLBACK_STOP, offset, NULL, 0 ))
876
log_err("u-> ibm-943 with stop did not match.\n");
878
if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
879
to_euc_jp, sizeof(to_euc_jp), "euc-jp",
880
UCNV_FROM_U_CALLBACK_STOP, fromEUC_JPOffs, NULL, 0 ))
881
log_err("u-> euc-jp with stop did not match.\n");
883
if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
884
to_euc_tw, sizeof(to_euc_tw), "euc-tw",
885
UCNV_FROM_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
886
log_err("u-> euc-tw with stop did not match.\n");
888
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
889
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
890
UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
891
log_err("u-> iso-2022-jp with stop did not match.\n");
893
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
894
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
895
UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_jpOffs, NULL, 0 ))
896
log_err("u-> iso-2022-jp with stop did not match.\n");
898
if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
899
to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
900
UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_cnOffs, NULL, 0 ))
901
log_err("u-> iso-2022-cn with stop did not match.\n");
903
if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
904
to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
905
UCNV_FROM_U_CALLBACK_STOP, from_iso_2022_krOffs, NULL, 0 ))
906
log_err("u-> iso-2022-kr with stop did not match.\n");
908
if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
909
to_hz, sizeof(to_hz), "HZ",
910
UCNV_FROM_U_CALLBACK_STOP, from_hzOffs, NULL, 0 ))
911
log_err("u-> HZ with stop did not match.\n");\
913
if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
914
to_iscii, sizeof(to_iscii), "ISCII,version=0",
915
UCNV_FROM_U_CALLBACK_STOP, from_isciiOffs, NULL, 0 ))
916
log_err("u-> iscii with stop did not match.\n");
920
log_verbose("Testing fromUnicode for UTF-8 with UCNV_FROM_U_CALLBACK_STOP \n");
922
const UChar testinput[]={ 0x20ac, 0xd801, 0xdc01, 0xdc01, 0xd801, 0xffff, 0x0061,};
923
const uint8_t expectedUTF8[]= { 0xe2, 0x82, 0xac,
924
0xf0, 0x90, 0x90, 0x81,
925
0xed, 0xb0, 0x81, 0xed, 0xa0, 0x81,
926
0xef, 0xbf, 0xbf, 0x61,
929
int32_t offsets[]={ 0, 0, 0, 1, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
930
if(!testConvertFromUnicode(testinput, sizeof(testinput)/sizeof(testinput[0]),
931
expectedUTF8, sizeof(expectedUTF8), "utf8",
932
UCNV_FROM_U_CALLBACK_STOP, offsets, NULL, 0 ))
933
log_err("u-> utf8 with stop did not match.\n");
935
log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_STOP \n");
937
UChar SCSU_inputText[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
939
const uint8_t to_SCSU[]={
943
int32_t from_SCSUOffs [] ={
947
if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
948
to_SCSU, sizeof(to_SCSU), "SCSU",
949
UCNV_FROM_U_CALLBACK_STOP, from_SCSUOffs, NULL, 0 ))
950
log_err("u-> SCSU with skip did not match.\n");
954
if(!testConvertToUnicode(expstopIBM_949, sizeof(expstopIBM_949),
955
IBM_949stoptoUnicode, sizeof(IBM_949stoptoUnicode)/sizeof(IBM_949stoptoUnicode[0]),"ibm-949",
956
UCNV_TO_U_CALLBACK_STOP, fromIBM949Offs, NULL, 0 ))
957
log_err("ibm-949->u with stop did not match.\n");
958
if(!testConvertToUnicode(expstopIBM_943, sizeof(expstopIBM_943),
959
IBM_943stoptoUnicode, sizeof(IBM_943stoptoUnicode)/sizeof(IBM_943stoptoUnicode[0]),"ibm-943",
960
UCNV_TO_U_CALLBACK_STOP, fromIBM943Offs, NULL, 0 ))
961
log_err("ibm-943->u with stop did not match.\n");
962
if(!testConvertToUnicode(expstopIBM_930, sizeof(expstopIBM_930),
963
IBM_930stoptoUnicode, sizeof(IBM_930stoptoUnicode)/sizeof(IBM_930stoptoUnicode[0]),"ibm-930",
964
UCNV_TO_U_CALLBACK_STOP, fromIBM930Offs, NULL, 0 ))
965
log_err("ibm-930->u with stop did not match.\n");
967
log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_STOP \n");
970
const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={
971
0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
973
UChar EBCIDIC_STATEFUL_toUnicode[] ={ 0x6d63 };
974
int32_t from_EBCIDIC_STATEFULOffsets []={ 1};
978
const uint8_t sampleTxt_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
979
0x8f, 0xda, 0xa1, /*unassigned*/
982
UChar euc_jptoUnicode[]={ 0x0061, 0x4edd, 0x5bec};
983
int32_t from_euc_jpOffs [] ={ 0, 1, 3};
986
const uint8_t sampleTxt_euc_tw[]={ 0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
987
0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
990
UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2};
991
int32_t from_euc_twOffs [] ={ 0, 1, 3};
995
if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
996
EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
997
UCNV_TO_U_CALLBACK_STOP, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
998
log_err("EBCIDIC_STATEFUL->u with stop did not match.\n");
1000
if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
1001
euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
1002
UCNV_TO_U_CALLBACK_STOP, from_euc_jpOffs , NULL, 0))
1003
log_err("euc-jp->u with stop did not match.\n");
1005
if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
1006
euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
1007
UCNV_TO_U_CALLBACK_STOP, from_euc_twOffs, NULL, 0 ))
1008
log_err("euc-tw->u with stop did not match.\n");
1010
log_verbose("Testing toUnicode for UTF-8 with UCNV_TO_U_CALLBACK_STOP \n");
1012
const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c,
1014
UChar expected1[] = { 0x0031, 0x4e8c,};
1015
int32_t offsets1[] = { 0x0000, 0x0001};
1017
if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
1018
expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
1019
UCNV_TO_U_CALLBACK_STOP, offsets1, NULL, 0 ))
1020
log_err("utf8->u with stop did not match.\n");;
1022
log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_STOP \n");
1024
const uint8_t sampleText1[] = { 0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,0x04};
1025
UChar expected1[] = { 0x00ba, 0x008c, 0x00f8, 0x0061};
1026
int32_t offsets1[] = { 0x0000, 0x0001,0x0002,0x0003};
1028
if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
1029
expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
1030
UCNV_TO_U_CALLBACK_STOP, offsets1, NULL, 0 ))
1031
log_err("scsu->u with stop did not match.\n");;
1036
static void TestSub(int32_t inputsize, int32_t outputsize)
1038
UChar sampleText[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
1039
UChar sampleText2[]= { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
1041
const uint8_t expsubIBM_949[] =
1042
{ 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xaf, 0xfe, 0xc8, 0xd3 };
1044
const uint8_t expsubIBM_943[] = {
1045
0x9f, 0xaf, 0x9f, 0xb1, 0xfc, 0xfc, 0x89, 0x59 };
1047
const uint8_t expsubIBM_930[] = {
1048
0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfe, 0xfe, 0x46, 0x6b };
1050
UChar IBM_949subtoUnicode[]= {0x0000, 0xAC00, 0xAC01, 0xfffd, 0xD700 };
1051
UChar IBM_943subtoUnicode[]= {0x6D63, 0x6D64, 0xfffd, 0x6D66 };
1052
UChar IBM_930subtoUnicode[]= {0x6D63, 0x6D64, 0xfffd, 0x6D66 };
1054
int32_t toIBM949Offssub [] ={ 0, 1, 1, 2, 2, 3, 3, 4, 4};
1055
int32_t toIBM943Offssub [] ={ 0, 0, 1, 1, 2, 2, 3, 3};
1056
int32_t toIBM930Offssub [] ={ 0, 0, 0, 1, 1, 2, 2, 3, 3};
1058
int32_t fromIBM949Offs [] = { 0, 1, 3, 5, 7};
1059
int32_t fromIBM943Offs [] = { 0, 2, 4, 6};
1060
int32_t fromIBM930Offs [] = { 1, 3, 5, 7};
1062
gInBufferSize = inputsize;
1063
gOutBufferSize = outputsize;
1066
if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
1067
expsubIBM_949, sizeof(expsubIBM_949), "ibm-949",
1068
UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM949Offssub, NULL, 0 ))
1069
log_err("u-> ibm-949 with subst did not match.\n");
1070
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
1071
expsubIBM_943, sizeof(expsubIBM_943), "ibm-943",
1072
UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM943Offssub , NULL, 0))
1073
log_err("u-> ibm-943 with subst did not match.\n");
1074
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
1075
expsubIBM_930, sizeof(expsubIBM_930), "ibm-930",
1076
UCNV_FROM_U_CALLBACK_SUBSTITUTE, toIBM930Offssub, NULL, 0 ))
1077
log_err("u-> ibm-930 with subst did not match.\n");
1079
log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_SUBSTITUTE \n");
1081
UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
1082
const uint8_t toIBM943[]= { 0x61, 0xfc, 0xfc, 0xfc, 0xfc, 0x61 };
1083
int32_t offset[]= {0, 1, 1, 3, 3, 4};
1087
UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2 };
1088
const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1089
0xf4, 0xfe, 0xf4, 0xfe,
1092
int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7};
1095
UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
1096
const uint8_t to_euc_tw[]={
1097
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1098
0xfd, 0xfe, 0xfd, 0xfe,
1099
0x61, 0xe6, 0xca, 0x8a,
1101
int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7, 8,};
1103
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
1104
toIBM943, sizeof(toIBM943), "ibm-943",
1105
UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset, NULL, 0 ))
1106
log_err("u-> ibm-943 with substitute did not match.\n");
1108
if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
1109
to_euc_jp, sizeof(to_euc_jp), "euc-jp",
1110
UCNV_FROM_U_CALLBACK_SUBSTITUTE, fromEUC_JPOffs, NULL, 0 ))
1111
log_err("u-> euc-jp with substitute did not match.\n");
1113
if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
1114
to_euc_tw, sizeof(to_euc_tw), "euc-tw",
1115
UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
1116
log_err("u-> euc-tw with substitute did not match.\n");
1119
log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_SUBSTITUTE \n");
1121
UChar SCSU_inputText[]={ 0x0041, 0xd801/*illegal*/, 0x0042, };
1123
const uint8_t to_SCSU[]={
1130
int32_t from_SCSUOffs [] ={
1136
if(!testConvertFromUnicode(SCSU_inputText, sizeof(SCSU_inputText)/sizeof(SCSU_inputText[0]),
1137
to_SCSU, sizeof(to_SCSU), "SCSU",
1138
UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_SCSUOffs, NULL, 0 ))
1139
log_err("u-> SCSU with skip did not match.\n");
1145
if(!testConvertToUnicode(expsubIBM_949, sizeof(expsubIBM_949),
1146
IBM_949subtoUnicode, sizeof(IBM_949subtoUnicode)/sizeof(IBM_949subtoUnicode[0]),"ibm-949",
1147
UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM949Offs, NULL, 0 ))
1148
log_err("ibm-949->u with substitute did not match.\n");
1149
if(!testConvertToUnicode(expsubIBM_943, sizeof(expsubIBM_943),
1150
IBM_943subtoUnicode, sizeof(IBM_943subtoUnicode)/sizeof(IBM_943subtoUnicode[0]),"ibm-943",
1151
UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offs, NULL, 0 ))
1152
log_err("ibm-943->u with substitute did not match.\n");
1153
if(!testConvertToUnicode(expsubIBM_930, sizeof(expsubIBM_930),
1154
IBM_930subtoUnicode, sizeof(IBM_930subtoUnicode)/sizeof(IBM_930subtoUnicode[0]),"ibm-930",
1155
UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM930Offs, NULL, 0 ))
1156
log_err("ibm-930->u with substitute did not match.\n");
1158
log_verbose("Testing toUnicode with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
1161
const uint8_t sampleTxtEBCIDIC_STATEFUL [] ={
1162
0x0e, 0x5d, 0x5f , 0x41, 0x79, 0x41, 0x44
1164
UChar EBCIDIC_STATEFUL_toUnicode[] ={ 0x6d63, 0xfffd, 0x03b4
1166
int32_t from_EBCIDIC_STATEFULOffsets []={ 1, 3, 5};
1170
const uint8_t sampleTxt_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1171
0x8f, 0xda, 0xa1, /*unassigned*/
1174
UChar euc_jptoUnicode[]={ 0x0061, 0x4edd, 0x5bec, 0xfffd, 0x00a2, 0x008a };
1175
int32_t from_euc_jpOffs [] ={ 0, 1, 3, 6, 9, 11 };
1178
const uint8_t sampleTxt_euc_tw[]={
1179
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1180
0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
1183
UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2, 0xfffd, 0x8706, 0x8a, };
1184
int32_t from_euc_twOffs [] ={ 0, 1, 3, 7, 11, 13};
1187
if(!testConvertToUnicode(sampleTxtEBCIDIC_STATEFUL, sizeof(sampleTxtEBCIDIC_STATEFUL),
1188
EBCIDIC_STATEFUL_toUnicode, sizeof(EBCIDIC_STATEFUL_toUnicode)/sizeof(EBCIDIC_STATEFUL_toUnicode[0]),"ibm-930",
1189
UCNV_TO_U_CALLBACK_SUBSTITUTE, from_EBCIDIC_STATEFULOffsets, NULL, 0 ))
1190
log_err("EBCIDIC_STATEFUL->u with substitute did not match.\n");
1193
if(!testConvertToUnicode(sampleTxt_euc_jp, sizeof(sampleTxt_euc_jp),
1194
euc_jptoUnicode, sizeof(euc_jptoUnicode)/sizeof(euc_jptoUnicode[0]),"euc-jp",
1195
UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_jpOffs, NULL, 0 ))
1196
log_err("euc-jp->u with substitute did not match.\n");
1199
if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
1200
euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
1201
UCNV_TO_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
1202
log_err("euc-tw->u with substitute did not match.\n");
1206
log_verbose("Testing toUnicode for UTF-8 with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
1208
const uint8_t sampleText1[] = { 0x31, 0xe4, 0xba, 0x8c,
1210
UChar expected1[] = { 0x0031, 0x4e8c, 0xfffd, 0x0061};
1211
int32_t offsets1[] = { 0x0000, 0x0001, 0x0004, 0x0006};
1213
if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
1214
expected1, sizeof(expected1)/sizeof(expected1[0]),"utf8",
1215
UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0 ))
1216
log_err("utf8->u with substitute did not match.\n");;
1218
log_verbose("Testing toUnicode for SCSU with UCNV_TO_U_CALLBACK_SUBSTITUTE \n");
1220
const uint8_t sampleText1[] = { 0xba, 0x8c,0xF8, 0x61,0x0c, 0x0c,};
1221
UChar expected1[] = { 0x00ba, 0x008c, 0x00f8, 0x0061,0xfffd,0xfffd};
1222
int32_t offsets1[] = { 0x0000, 0x0001,0x0002,0x0003,4,5};
1224
if(!testConvertToUnicode(sampleText1, sizeof(sampleText1),
1225
expected1, sizeof(expected1)/sizeof(expected1[0]),"SCSU",
1226
UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0 ))
1227
log_err("scsu->u with stop did not match.\n");;
1230
log_verbose("Testing ibm-930 subchar/subchar1\n");
1232
static const UChar u1[]={ 0x6d63, 0x6d64, 0x6d65, 0x6d66, 0xdf };
1233
static const uint8_t s1[]={ 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfe, 0xfe, 0x46, 0x6b, 0x0f, 0x3f };
1234
static const int32_t offsets1[]={ 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4 };
1236
static const UChar u2[]={ 0x6d63, 0x6d64, 0xfffd, 0x6d66, 0x1a };
1237
static const uint8_t s2[]={ 0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0xfc, 0xfc, 0x46, 0x6b, 0x0f, 0x57 };
1238
static const int32_t offsets2[]={ 1, 3, 5, 7, 10 };
1240
if(!testConvertFromUnicode(u1, ARRAY_LENGTH(u1), s1, ARRAY_LENGTH(s1), "ibm-930",
1241
UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
1243
log_err("u->ibm-930 subchar/subchar1 did not match.\n");
1246
if(!testConvertToUnicode(s2, ARRAY_LENGTH(s2), u2, ARRAY_LENGTH(u2), "ibm-930",
1247
UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
1249
log_err("ibm-930->u subchar/subchar1 did not match.\n");
1253
log_verbose("Testing GB 18030 with substitute callbacks\n");
1255
static const UChar u1[]={
1256
0x24, 0x7f, 0x80, 0x1f9, 0x20ac, 0x4e00, 0x9fa6, 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff };
1257
static const uint8_t gb1[]={
1258
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, 0x35 };
1259
static const int32_t offsets1[]={
1260
0, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 10, 10, 10, 10 };
1262
static const UChar u2[]={
1263
0x24, 0x7f, 0x80, 0x1f9, 0x20ac, 0x4e00, 0x9fa6, 0xffff, 0xd800, 0xdc00, 0xfffd, 0xdbff, 0xdfff };
1264
static const uint8_t gb2[]={
1265
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 };
1266
static const int32_t offsets2[]={
1267
0, 1, 2, 6, 8, 10, 12, 16, 20, 20, 24, 28, 28 };
1269
if(!testConvertFromUnicode(u1, ARRAY_LENGTH(u1), gb1, ARRAY_LENGTH(gb1), "gb18030",
1270
UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
1272
log_err("u->gb18030 with substitute did not match.\n");
1275
if(!testConvertToUnicode(gb2, ARRAY_LENGTH(gb2), u2, ARRAY_LENGTH(u2), "gb18030",
1276
UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
1278
log_err("gb18030->u with substitute did not match.\n");
1282
log_verbose("Testing UTF-7 with substitute callbacks\n");
1284
static const uint8_t utf7[]={
1285
/* a~ a+AB~ a+AB\x0c a+AB- a+AB. a+. */
1286
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
1288
static const UChar unicode[]={
1289
0x61, 0xfffd, 0x61, 0xfffd, 0x61, 0xfffd, 0x61, 0xfffd, 0x61, 0xfffd, 0x61, 0xfffd
1291
static const int32_t offsets[]={
1292
0, 1, 2, 4, 7, 9, 12, 14, 17, 19, 22, 23
1295
if(!testConvertToUnicode(utf7, ARRAY_LENGTH(utf7), unicode, ARRAY_LENGTH(unicode), "UTF-7",
1296
UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0)
1298
log_err("UTF-7->u with substitute did not match.\n");
1303
static void TestSubWithValue(int32_t inputsize, int32_t outputsize)
1305
UChar sampleText[] = { 0x0000, 0xAC00, 0xAC01, 0xEF67, 0xD700 };
1306
UChar sampleText2[] = { 0x6D63, 0x6D64, 0x6D65, 0x6D66 };
1308
const uint8_t expsubwvalIBM_949[]= {
1309
0x00, 0xb0, 0xa1, 0xb0, 0xa2,
1310
0x25, 0x55, 0x45, 0x46, 0x36, 0x37, 0xc8, 0xd3 };
1312
const uint8_t expsubwvalIBM_943[]= {
1313
0x9f, 0xaf, 0x9f, 0xb1,
1314
0x25, 0x55, 0x36, 0x44, 0x36, 0x35, 0x89, 0x59 };
1316
const uint8_t expsubwvalIBM_930[] = {
1317
0x0e, 0x5d, 0x5f, 0x5d, 0x63, 0x0f, 0x6c, 0xe4, 0xf6, 0xc4, 0xf6, 0xf5, 0x0e, 0x46, 0x6b };
1319
int32_t toIBM949Offs [] ={ 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4};
1320
int32_t toIBM943Offs [] = { 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3};
1321
int32_t toIBM930Offs [] = { 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3}; /* last item: 3,3,3 because there's a shift plus a doublebyter .. */
1323
gInBufferSize = inputsize;
1324
gOutBufferSize = outputsize;
1327
if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
1328
expsubwvalIBM_949, sizeof(expsubwvalIBM_949), "ibm-949",
1329
UCNV_FROM_U_CALLBACK_ESCAPE, toIBM949Offs, NULL, 0 ))
1330
log_err("u-> ibm-949 with subst with value did not match.\n");
1332
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
1333
expsubwvalIBM_943, sizeof(expsubwvalIBM_943), "ibm-943",
1334
UCNV_FROM_U_CALLBACK_ESCAPE, toIBM943Offs, NULL, 0 ))
1335
log_err("u-> ibm-943 with sub with value did not match.\n");
1337
if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
1338
expsubwvalIBM_930, sizeof(expsubwvalIBM_930), "ibm-930",
1339
UCNV_FROM_U_CALLBACK_ESCAPE, toIBM930Offs, NULL, 0 ))
1340
log_err("u-> ibm-930 with subst with value did not match.\n");
1343
log_verbose("Testing fromUnicode with UCNV_FROM_U_CALLBACK_ESCAPE \n");
1345
UChar inputTest[] = { 0x0061, 0xd801, 0xdc01, 0xd801, 0x0061 };
1346
const uint8_t toIBM943[]= { 0x61,
1347
0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1348
0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
1349
0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1351
int32_t offset[]= {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 4};
1355
UChar euc_jp_inputText[]={ 0x0061, 0x4edd, 0x5bec, 0xd801, 0xdc01, 0xd801, 0x0061, 0x00a2, };
1356
const uint8_t to_euc_jp[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1357
0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1358
0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
1359
0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1362
int32_t fromEUC_JPOffs [] ={ 0, 1, 1, 2, 2, 2,
1370
UChar euc_tw_inputText[]={ 0x0061, 0x2295, 0x5BF2, 0xd801, 0xdc01, 0xd801, 0x0061, 0x8706, 0x8a, };
1371
const uint8_t to_euc_tw[]={
1372
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1373
0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1374
0x25, 0x55, 0x44, 0x43, 0x30, 0x31,
1375
0x25, 0x55, 0x44, 0x38, 0x30, 0x31,
1376
0x61, 0xe6, 0xca, 0x8a,
1378
int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2,
1379
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5,
1383
UChar iso_2022_jp_inputText[]={ 0x0041, 0x00E9, 0x0042,0x00E9,0x3000 };
1384
const uint8_t to_iso_2022_jp[]={
1386
0x25, 0x55, 0x30, 0x30, 0x45, 0x39,
1388
0x25, 0x55, 0x30, 0x30, 0x45, 0x39,
1389
0x1b, 0x24, 0x42, 0x21, 0x21,
1392
int32_t from_iso_2022_jpOffs [] ={
1399
UChar iso_2022_jp_inputText1[]={ 0x3000, 0x00E9, 0x3001,0x00E9, 0x0042} ;
1400
const uint8_t to_iso_2022_jp1[]={
1401
0x1b, 0x24, 0x42, 0x21, 0x21,
1402
0x1b, 0x28, 0x42, 0x25, 0x55, 0x30, 0x30, 0x45, 0x39,
1403
0x1b, 0x24, 0x42, 0x21, 0x22,
1404
0x1b, 0x28, 0x42, 0x25, 0x55, 0x30, 0x30, 0x45, 0x39,
1408
int32_t from_iso_2022_jpOffs1 [] ={
1416
UChar iso_2022_jp_inputText2[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042} ;
1417
const uint8_t to_iso_2022_jp2[]={
1418
0x1b, 0x24, 0x42, 0x21, 0x21,
1419
0x1b, 0x28, 0x42, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1420
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1421
0x1b, 0x24, 0x42, 0x21, 0x22,
1422
0x1b, 0x28, 0x42, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1423
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1426
int32_t from_iso_2022_jpOffs2 [] ={
1437
UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
1438
const uint8_t to_iso_2022_cn[]={
1440
0x0f, 0x25, 0x55, 0x33, 0x37, 0x31, 0x32,
1443
int32_t from_iso_2022_cnOffs [] ={
1448
UChar iso_2022_cn_inputText1[]={ 0x4e00, 0x3712, 0x4e01, };
1449
const uint8_t to_iso_2022_cn1[]={
1450
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x52, 0x3b,
1451
0x0f, 0x25, 0x55, 0x33, 0x37, 0x31, 0x32,
1452
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x36, 0x21,
1454
int32_t from_iso_2022_cnOffs1 [] ={
1455
0, 0, 0, 0, 0, 0, 0,
1456
1, 1, 1, 1, 1, 1, 1,
1457
2, 2, 2, 2, 2, 2, 2,
1459
UChar iso_2022_cn_inputText3[]={ 0x3000, 0x3712, 0x3001, };
1460
const uint8_t to_iso_2022_cn3[]={
1461
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
1462
0x0f, 0x25, 0x55, 0x33, 0x37, 0x31, 0x32,
1463
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x22,
1465
int32_t from_iso_2022_cnOffs3 [] ={
1470
UChar iso_2022_cn_inputText2[]={ 0x0041, 0x3712, 0x4e00, };
1471
const uint8_t to_iso_2022_cn2[]={
1473
0x0f, 0x25, 0x55, 0x33, 0x37, 0x31, 0x32,
1474
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x52, 0x3b,
1476
int32_t from_iso_2022_cnOffs2 [] ={
1482
UChar iso_2022_cn_inputText4[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042};
1484
const uint8_t to_iso_2022_cn4[]={
1485
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
1486
0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1487
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1488
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x22,
1489
0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1490
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1493
int32_t from_iso_2022_cnOffs4 [] ={
1505
UChar iso_2022_kr_inputText2[]={ 0x0041, 0x03A0,0xD84D, 0xDC56/*unassigned*/,0x03A0, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
1506
const uint8_t to_iso_2022_kr2[]={
1507
0x1b, 0x24, 0x29, 0x43,
1510
0x0f, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1511
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1514
0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1515
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1518
int32_t from_iso_2022_krOffs2 [] ={
1531
UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042,0x3712/*unassigned*/,0x43 };
1532
const uint8_t to_iso_2022_kr[]={
1533
0x1b, 0x24, 0x29, 0x43,
1536
0x0f, 0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
1539
0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
1544
int32_t from_iso_2022_krOffs [] ={
1555
UChar hz_inputText[]={ 0x0041, 0x03A0,0x0662/*unassigned*/,0x03A0, 0x0042, };
1557
const uint8_t to_hz[]={
1559
0x7e, 0x7b, 0x26, 0x30,
1560
0x7e, 0x7d, 0x25, 0x55, 0x30, 0x36, 0x36, 0x32, /*unassigned*/
1561
0x7e, 0x7b, 0x26, 0x30,
1565
int32_t from_hzOffs [] ={
1573
UChar hz_inputText2[]={ 0x0041, 0x03A0,0xD84D, 0xDC56/*unassigned*/,0x03A0, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
1574
const uint8_t to_hz2[]={
1576
0x7e, 0x7b, 0x26, 0x30,
1577
0x7e, 0x7d, 0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1578
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1579
0x7e, 0x7b, 0x26, 0x30,
1581
0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1582
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1585
int32_t from_hzOffs2 [] ={
1598
UChar iscii_inputText2[]={ 0x0041, 0x0901,0xD84D, 0xDC56/*unassigned*/,0x0902, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
1599
const uint8_t to_iscii2[]={
1602
0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1603
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1606
0x25, 0x55, 0x44, 0x38, 0x34, 0x44,
1607
0x25, 0x55, 0x44, 0x43, 0x35, 0x36,
1610
int32_t from_isciiOffs2 [] ={
1622
UChar iscii_inputText[]={ 0x0041, 0x0901,0x3712/*unassigned*/,0x0902, 0x0042,0x3712/*unassigned*/,0x43 };
1623
const uint8_t to_iscii[]={
1626
0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
1629
0x25, 0x55, 0x33, 0x37, 0x31, 0x32, /*unassigned*/
1634
int32_t from_isciiOffs [] ={
1644
if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
1645
toIBM943, sizeof(toIBM943), "ibm-943",
1646
UCNV_FROM_U_CALLBACK_ESCAPE, offset, NULL, 0 ))
1647
log_err("u-> ibm-943 with subst with value did not match.\n");
1649
if(!testConvertFromUnicode(euc_jp_inputText, sizeof(euc_jp_inputText)/sizeof(euc_jp_inputText[0]),
1650
to_euc_jp, sizeof(to_euc_jp), "euc-jp",
1651
UCNV_FROM_U_CALLBACK_ESCAPE, fromEUC_JPOffs, NULL, 0 ))
1652
log_err("u-> euc-jp with subst with value did not match.\n");
1654
if(!testConvertFromUnicode(euc_tw_inputText, sizeof(euc_tw_inputText)/sizeof(euc_tw_inputText[0]),
1655
to_euc_tw, sizeof(to_euc_tw), "euc-tw",
1656
UCNV_FROM_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0 ))
1657
log_err("u-> euc-tw with subst with value did not match.\n");
1659
if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
1660
to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
1661
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0 ))
1662
log_err("u-> iso_2022_jp with subst with value did not match.\n");
1664
if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
1665
to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
1666
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
1667
log_err("u-> iso_2022_jp with subst with value did not match.\n");
1669
if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
1670
to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
1671
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
1672
log_err("u-> iso_2022_jp with subst with value did not match.\n");
1674
if(!testConvertFromUnicode(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
1675
to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
1676
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2, NULL, 0 ))
1677
log_err("u-> iso_2022_jp with subst with value did not match.\n");
1680
const uint8_t to_iso_2022_jp2_v2[]={
1681
0x1b, 0x24, 0x42, 0x21, 0x21,
1682
0x1b, 0x28, 0x42, 0x26, 0x23, 0x31, 0x34, 0x34, 0x34, 0x37, 0x30, 0x3b,
1684
0x1b, 0x24, 0x42, 0x21, 0x22,
1685
0x1b, 0x28, 0x42, 0x26, 0x23, 0x31, 0x34, 0x34, 0x34, 0x37, 0x30, 0x3b,
1690
int32_t from_iso_2022_jpOffs2_v2 [] ={
1692
1,1,1,1,1,1,1,1,1,1,1,1,
1695
4,4,4,4,4,4,4,4,4,4,4,4,
1700
if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
1701
to_iso_2022_jp2_v2, sizeof(to_iso_2022_jp2_v2), "iso-2022-jp",
1702
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2_v2, NULL, 0,UCNV_ESCAPE_XML_DEC,U_ZERO_ERROR ))
1703
log_err("u-> iso-2022-jp with skip & UCNV_ESCAPE_XML_DEC did not match.\n");
1706
const uint8_t to_iso_2022_jp2_v3[]={
1707
0x1b, 0x24, 0x42, 0x21, 0x21,
1708
0x1b, 0x28, 0x42, 0x26, 0x23, 0x78, 0x32, 0x33, 0x34, 0x35, 0x36, 0x3b ,
1710
0x1b, 0x24, 0x42, 0x21, 0x22,
1711
0x1b, 0x28, 0x42, 0x26, 0x23, 0x78, 0x32, 0x33, 0x34, 0x35, 0x36, 0x3b ,
1716
int32_t from_iso_2022_jpOffs2_v3 [] ={
1718
1,1,1,1,1,1,1,1,1,1,1,1,
1721
4,4,4,4,4,4,4,4,4,4,4,4,
1725
if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
1726
to_iso_2022_jp2_v3, sizeof(to_iso_2022_jp2_v3), "iso-2022-jp",
1727
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs2_v3, NULL, 0,UCNV_ESCAPE_XML_HEX,U_ZERO_ERROR ))
1728
log_err("u-> iso-2022-jp with skip & UCNV_ESCAPE_XML_HEX did not match.\n");
1732
const uint8_t to_iso_2022_cn4_v2[]={
1733
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
1734
0x0f, 0x5c, 0x75, 0x44, 0x38, 0x34, 0x44,
1735
0x5c, 0x75, 0x44, 0x43, 0x35, 0x36,
1736
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x22,
1737
0x0f, 0x5c, 0x75, 0x44, 0x38, 0x34, 0x44,
1738
0x5c, 0x75, 0x44, 0x43, 0x35, 0x36,
1741
int32_t from_iso_2022_cnOffs4_v2 [] ={
1751
if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
1752
to_iso_2022_cn4_v2, sizeof(to_iso_2022_cn4_v2), "iso-2022-cn",
1753
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4_v2, NULL, 0,UCNV_ESCAPE_JAVA,U_ZERO_ERROR ))
1754
log_err("u-> iso-2022-cn with skip & UCNV_ESCAPE_JAVA did not match.\n");
1758
const uint8_t to_iso_2022_cn4_v3[]={
1759
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x21,
1760
0x0f, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x32, 0x33, 0x34, 0x35, 0x36,
1761
0x1b, 0x24, 0x29, 0x41, 0x0e, 0x21, 0x22,
1762
0x0f, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x32, 0x33, 0x34, 0x35, 0x36,
1767
int32_t from_iso_2022_cnOffs4_v3 [] ={
1769
1,1,1,1,1,1,1,1,1,1,1,
1772
4,4,4,4,4,4,4,4,4,4,4,
1777
if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
1778
to_iso_2022_cn4_v3, sizeof(to_iso_2022_cn4_v3), "iso-2022-cn",
1779
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4_v3, NULL, 0,UCNV_ESCAPE_C,U_ZERO_ERROR ))
1780
log_err("u-> iso-2022-cn with skip & UCNV_ESCAPE_C did not match.\n");
1782
if(!testConvertFromUnicode(iso_2022_cn_inputText, sizeof(iso_2022_cn_inputText)/sizeof(iso_2022_cn_inputText[0]),
1783
to_iso_2022_cn, sizeof(to_iso_2022_cn), "iso-2022-cn",
1784
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0 ))
1785
log_err("u-> iso_2022_cn with subst with value did not match.\n");
1787
if(!testConvertFromUnicode(iso_2022_cn_inputText1, sizeof(iso_2022_cn_inputText1)/sizeof(iso_2022_cn_inputText1[0]),
1788
to_iso_2022_cn1, sizeof(to_iso_2022_cn1), "iso-2022-cn",
1789
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs1, NULL, 0 ))
1790
log_err("u-> iso_2022_cn with subst with value did not match.\n");
1791
if(!testConvertFromUnicode(iso_2022_cn_inputText2, sizeof(iso_2022_cn_inputText2)/sizeof(iso_2022_cn_inputText2[0]),
1792
to_iso_2022_cn2, sizeof(to_iso_2022_cn2), "iso-2022-cn",
1793
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs2, NULL, 0 ))
1794
log_err("u-> iso_2022_cn with subst with value did not match.\n");
1795
if(!testConvertFromUnicode(iso_2022_cn_inputText3, sizeof(iso_2022_cn_inputText3)/sizeof(iso_2022_cn_inputText3[0]),
1796
to_iso_2022_cn3, sizeof(to_iso_2022_cn3), "iso-2022-cn",
1797
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs3, NULL, 0 ))
1798
log_err("u-> iso_2022_cn with subst with value did not match.\n");
1799
if(!testConvertFromUnicode(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
1800
to_iso_2022_cn4, sizeof(to_iso_2022_cn4), "iso-2022-cn",
1801
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4, NULL, 0 ))
1802
log_err("u-> iso_2022_cn with subst with value did not match.\n");
1803
if(!testConvertFromUnicode(iso_2022_kr_inputText, sizeof(iso_2022_kr_inputText)/sizeof(iso_2022_kr_inputText[0]),
1804
to_iso_2022_kr, sizeof(to_iso_2022_kr), "iso-2022-kr",
1805
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_krOffs, NULL, 0 ))
1806
log_err("u-> iso_2022_kr with subst with value did not match.\n");
1807
if(!testConvertFromUnicode(iso_2022_kr_inputText2, sizeof(iso_2022_kr_inputText2)/sizeof(iso_2022_kr_inputText2[0]),
1808
to_iso_2022_kr2, sizeof(to_iso_2022_kr2), "iso-2022-kr",
1809
UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_krOffs2, NULL, 0 ))
1810
log_err("u-> iso_2022_kr2 with subst with value did not match.\n");
1811
if(!testConvertFromUnicode(hz_inputText, sizeof(hz_inputText)/sizeof(hz_inputText[0]),
1812
to_hz, sizeof(to_hz), "HZ",
1813
UCNV_FROM_U_CALLBACK_ESCAPE, from_hzOffs, NULL, 0 ))
1814
log_err("u-> hz with subst with value did not match.\n");
1815
if(!testConvertFromUnicode(hz_inputText2, sizeof(hz_inputText2)/sizeof(hz_inputText2[0]),
1816
to_hz2, sizeof(to_hz2), "HZ",
1817
UCNV_FROM_U_CALLBACK_ESCAPE, from_hzOffs2, NULL, 0 ))
1818
log_err("u-> hz with subst with value did not match.\n");
1820
if(!testConvertFromUnicode(iscii_inputText, sizeof(iscii_inputText)/sizeof(iscii_inputText[0]),
1821
to_iscii, sizeof(to_iscii), "ISCII,version=0",
1822
UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0 ))
1823
log_err("u-> iscii with subst with value did not match.\n");
1825
if(!testConvertFromUnicode(iscii_inputText2, sizeof(iscii_inputText2)/sizeof(iscii_inputText2[0]),
1826
to_iscii2, sizeof(to_iscii2), "ISCII,version=0",
1827
UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs2, NULL, 0 ))
1828
log_err("u-> iscii2 with subst with value did not match.\n");
1832
log_verbose("Testing toUnicode with UCNV_FROM_U_CALLBACK_ESCAPE \n");
1835
const uint8_t sampleTxtToU[]= { 0x00, 0x9f, 0xaf,
1836
0x81, 0xad, /*unassigned*/
1838
UChar IBM_943toUnicode[] = { 0x0000, 0x6D63,
1839
0x25, 0x58, 0x38, 0x31, 0x25, 0x58, 0x41, 0x44,
1841
int32_t fromIBM943Offs [] = { 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 5};
1844
const uint8_t sampleTxt_EUC_JP[]={ 0x61, 0xa1, 0xb8, 0x8f, 0xf4, 0xae,
1845
0x8f, 0xda, 0xa1, /*unassigned*/
1848
UChar EUC_JPtoUnicode[]={ 0x0061, 0x4edd, 0x5bec,
1849
0x25, 0x58, 0x38, 0x46, 0x25, 0x58, 0x44, 0x41, 0x25, 0x58, 0x41, 0x31,
1851
int32_t fromEUC_JPOffs [] ={ 0, 1, 3,
1852
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
1857
const uint8_t sampleTxt_euc_tw[]={
1858
0x61, 0xa2, 0xd3, 0x8e, 0xa2, 0xdc, 0xe5,
1859
0x8e, 0xaa, 0xbb, 0xcc,/*unassigned*/
1862
UChar euc_twtoUnicode[]={ 0x0061, 0x2295, 0x5BF2,
1863
0x25, 0x58, 0x38, 0x45, 0x25, 0x58, 0x41, 0x41, 0x25, 0x58, 0x42, 0x42, 0x25, 0x58, 0x43, 0x43,
1865
int32_t from_euc_twOffs [] ={ 0, 1, 3,
1866
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
1870
const uint8_t sampleTxt_iso_2022_jp[]={
1871
0x1b, 0x28, 0x42, 0x41,
1872
0x1b, 0x24, 0x42, 0x2A, 0x44, /*unassigned*/
1873
0x1b, 0x28, 0x42, 0x42,
1876
UChar iso_2022_jptoUnicode[]={ 0x41,0x25,0x58,0x32,0x41,0x25,0x58,0x34,0x34, 0x42 };
1877
int32_t from_iso_2022_jpOffs [] ={ 3, 7, 7, 7, 7, 7, 7, 7, 7, 12 };
1880
const uint8_t sampleTxt_iso_2022_cn[]={
1882
0x1B, 0x24, 0x29, 0x47,
1883
0x0E, 0x40, 0x6c, /*unassigned*/
1887
UChar iso_2022_cntoUnicode[]={ 0x41, 0x44,0x25,0x58,0x34,0x30,0x25,0x58,0x36,0x43,0x42 };
1888
int32_t from_iso_2022_cnOffs [] ={ 1, 2, 8, 8, 8, 8, 8, 8, 8, 8, 11 };
1891
const uint8_t sampleTxt_iso_2022_kr[]={
1892
0x1b, 0x24, 0x29, 0x43,
1900
UChar iso_2022_krtoUnicode[]={ 0x41,0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,0x03A0,0x51, 0x42,0x43};
1901
int32_t from_iso_2022_krOffs [] ={ 4, 6, 6, 6, 6, 6, 6, 6, 6, 9, 12, 13 , 14 };
1904
const uint8_t sampleTxt_hz[]={
1906
0x7e, 0x7b, 0x26, 0x30,
1907
0x7f, 0x1E, /*unassigned*/
1910
0x7e, 0x7b, 0x7f, 0x1E,/*unassigned*/
1913
UChar hztoUnicode[]={
1916
0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,
1919
0x25,0x58,0x37,0x46,0x25,0x58,0x31,0x45,
1922
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, };
1926
const uint8_t sampleTxt_iscii[]={
1929
0xEB, /*unassigned*/
1932
0xEC, /*unassigned*/
1935
UChar isciitoUnicode[]={
1938
0x25, 0x58, 0x45, 0x42,
1941
0x25, 0x58, 0x45, 0x43,
1944
int32_t from_isciiOffs [] ={0,1,2,2,2,2,3,4,5,5,5,5,6 };
1948
const uint8_t sampleTxtLMBCS[]={ 0x12, 0xc9, 0x50,
1949
0x12, 0x92, 0xa0, /*unassigned*/
1952
UChar LMBCSToUnicode[]={ 0x4e2e,
1953
0x25, 0x58, 0x31, 0x32, 0x25, 0x58, 0x39, 0x32, 0x25, 0x58, 0x41, 0x30,
1955
int32_t fromLMBCS[] = {0,
1956
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1960
if(!testConvertToUnicode(sampleTxtToU, sizeof(sampleTxtToU),
1961
IBM_943toUnicode, sizeof(IBM_943toUnicode)/sizeof(IBM_943toUnicode[0]),"ibm-943",
1962
UCNV_TO_U_CALLBACK_ESCAPE, fromIBM943Offs, NULL, 0 ))
1963
log_err("ibm-943->u with substitute with value did not match.\n");
1965
if(!testConvertToUnicode(sampleTxt_EUC_JP, sizeof(sampleTxt_EUC_JP),
1966
EUC_JPtoUnicode, sizeof(EUC_JPtoUnicode)/sizeof(EUC_JPtoUnicode[0]),"euc-jp",
1967
UCNV_TO_U_CALLBACK_ESCAPE, fromEUC_JPOffs, NULL, 0))
1968
log_err("euc-jp->u with substitute with value did not match.\n");
1970
if(!testConvertToUnicode(sampleTxt_euc_tw, sizeof(sampleTxt_euc_tw),
1971
euc_twtoUnicode, sizeof(euc_twtoUnicode)/sizeof(euc_twtoUnicode[0]),"euc-tw",
1972
UCNV_TO_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0))
1973
log_err("euc-tw->u with substitute with value did not match.\n");
1975
if(!testConvertToUnicode(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
1976
iso_2022_jptoUnicode, sizeof(iso_2022_jptoUnicode)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
1977
UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0))
1978
log_err("iso-2022-jp->u with substitute with value did not match.\n");
1980
{/* test UCNV_TO_U_CALLBACK_ESCAPE with options */
1982
UChar iso_2022_jptoUnicodeDec[]={ 0x0041,
1983
0x0026, 0x0023, 0x0034, 0x0032, 0x003b,
1984
0x0026, 0x0023, 0x0036, 0x0038, 0x003b,
1986
int32_t from_iso_2022_jpOffsDec [] ={ 3,7,7,7,7,7,7,7,7,7,7,12, };
1987
if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
1988
iso_2022_jptoUnicodeDec, sizeof(iso_2022_jptoUnicodeDec)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
1989
UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsDec, NULL, 0,UCNV_ESCAPE_XML_DEC,U_ZERO_ERROR ))
1990
log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_DEC did not match.\n");
1993
UChar iso_2022_jptoUnicodeHex[]={ 0x0041,
1994
0x0026, 0x0023, 0x0078, 0x0032, 0x0041, 0x003b,
1995
0x0026, 0x0023, 0x0078, 0x0034, 0x0034, 0x003b,
1997
int32_t from_iso_2022_jpOffsHex [] ={ 3,7,7,7,7,7,7,7,7,7,7,7,7,12 };
1998
if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
1999
iso_2022_jptoUnicodeHex, sizeof(iso_2022_jptoUnicodeHex)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
2000
UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsHex, NULL, 0,UCNV_ESCAPE_XML_HEX,U_ZERO_ERROR ))
2001
log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_XML_HEX did not match.\n");
2004
UChar iso_2022_jptoUnicodeC[]={ 0x0041,
2005
0x005C, 0x0078, 0x0032, 0x0041,
2006
0x005C, 0x0078, 0x0034, 0x0034,
2008
int32_t from_iso_2022_jpOffsC [] ={ 3,7,7,7,7,7,7,7,7,12 };
2009
if(!testConvertToUnicodeWithContext(sampleTxt_iso_2022_jp, sizeof(sampleTxt_iso_2022_jp),
2010
iso_2022_jptoUnicodeC, sizeof(iso_2022_jptoUnicodeC)/sizeof(iso_2022_jptoUnicode[0]),"iso-2022-jp",
2011
UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_jpOffsC, NULL, 0,UCNV_ESCAPE_C,U_ZERO_ERROR ))
2012
log_err("iso-2022-jp->u with substitute with value and UCNV_ESCAPE_C did not match.\n");
2015
if(!testConvertToUnicode(sampleTxt_iso_2022_cn, sizeof(sampleTxt_iso_2022_cn),
2016
iso_2022_cntoUnicode, sizeof(iso_2022_cntoUnicode)/sizeof(iso_2022_cntoUnicode[0]),"iso-2022-cn",
2017
UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0))
2018
log_err("iso-2022-cn->u with substitute with value did not match.\n");
2020
if(!testConvertToUnicode(sampleTxt_iso_2022_kr, sizeof(sampleTxt_iso_2022_kr),
2021
iso_2022_krtoUnicode, sizeof(iso_2022_krtoUnicode)/sizeof(iso_2022_krtoUnicode[0]),"iso-2022-kr",
2022
UCNV_TO_U_CALLBACK_ESCAPE, from_iso_2022_krOffs, NULL, 0))
2023
log_err("iso-2022-kr->u with substitute with value did not match.\n");
2025
if(!testConvertToUnicode(sampleTxt_hz, sizeof(sampleTxt_hz),
2026
hztoUnicode, sizeof(hztoUnicode)/sizeof(hztoUnicode[0]),"HZ",
2027
UCNV_TO_U_CALLBACK_ESCAPE, from_hzOffs, NULL, 0))
2028
log_err("hz->u with substitute with value did not match.\n");
2030
if(!testConvertToUnicode(sampleTxt_iscii, sizeof(sampleTxt_iscii),
2031
isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
2032
UCNV_TO_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0))
2033
log_err("ISCII ->u with substitute with value did not match.\n");
2034
/*got to confirm this*/
2035
if(/* broken for icu 1.6.0.1, do not test */uprv_strcmp("1.7", U_ICU_VERSION) != 0 && !testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
2036
LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS",
2037
UCNV_TO_U_CALLBACK_ESCAPE, fromLMBCS, NULL, 0))
2038
log_err("LMBCS->u with substitute with value did not match.\n");
2042
static void TestLegalAndOthers(int32_t inputsize, int32_t outputsize)
2044
UChar legalText[] = { 0x0000, 0xAC00, 0xAC01, 0xD700 };
2045
const uint8_t templegal949[] ={ 0x00, 0xb0, 0xa1, 0xb0, 0xa2, 0xc8, 0xd3 };
2046
int32_t to949legal[] = {0, 1, 1, 2, 2, 3, 3};
2049
const uint8_t text943[] = {
2050
0x82, 0xa9, 0x82, 0x20, /*0xc8,*/ 0x61, 0x8a, 0xbf, 0x8e, 0x9a };
2051
UChar toUnicode943sub[] = { 0x304b, 0xfffd, /*0xff88,*/ 0x0061, 0x6f22, 0x5b57};
2052
UChar toUnicode943skip[]= { 0x304b, /*0xff88,*/ 0x0061, 0x6f22, 0x5b57};
2053
UChar toUnicode943stop[]= { 0x304b};
2055
int32_t fromIBM943Offssub[] = {0, 2, 4, 5, 7};
2056
int32_t fromIBM943Offsskip[] = { 0, 4, 5, 7};
2057
int32_t fromIBM943Offsstop[] = { 0};
2059
gInBufferSize = inputsize;
2060
gOutBufferSize = outputsize;
2061
/*checking with a legal value*/
2062
if(!testConvertFromUnicode(legalText, sizeof(legalText)/sizeof(legalText[0]),
2063
templegal949, sizeof(templegal949), "ibm-949",
2064
UCNV_FROM_U_CALLBACK_SKIP, to949legal, NULL, 0 ))
2065
log_err("u-> ibm-949 with skip did not match.\n");
2067
/*checking illegal value for ibm-943 with substitute*/
2068
if(!testConvertToUnicode(text943, sizeof(text943),
2069
toUnicode943sub, sizeof(toUnicode943sub)/sizeof(toUnicode943sub[0]),"ibm-943",
2070
UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offssub, NULL, 0 ))
2071
log_err("ibm-943->u with subst did not match.\n");
2072
/*checking illegal value for ibm-943 with skip */
2073
if(!testConvertToUnicode(text943, sizeof(text943),
2074
toUnicode943skip, sizeof(toUnicode943skip)/sizeof(toUnicode943skip[0]),"ibm-943",
2075
UCNV_TO_U_CALLBACK_SKIP, fromIBM943Offsskip, NULL, 0 ))
2076
log_err("ibm-943->u with skip did not match.\n");
2078
/*checking illegal value for ibm-943 with stop */
2079
if(!testConvertToUnicode(text943, sizeof(text943),
2080
toUnicode943stop, sizeof(toUnicode943stop)/sizeof(toUnicode943stop[0]),"ibm-943",
2081
UCNV_TO_U_CALLBACK_STOP, fromIBM943Offsstop, NULL, 0 ))
2082
log_err("ibm-943->u with stop did not match.\n");
2086
static void TestSingleByte(int32_t inputsize, int32_t outputsize)
2088
const uint8_t sampleText[] = {
2089
0x82, 0xa9, 0x61, 0x62, 0x63 , 0x82,
2090
0xff, /*0x82, 0xa9,*/ 0x32, 0x33};
2091
UChar toUnicode943sub[] = {0x304b, 0x0061, 0x0062, 0x0063, 0xfffd,/*0x304b,*/ 0x0032, 0x0033};
2092
int32_t fromIBM943Offssub[] = {0, 2, 3, 4, 5, 7, 8};
2093
/*checking illegal value for ibm-943 with substitute*/
2094
gInBufferSize = inputsize;
2095
gOutBufferSize = outputsize;
2097
if(!testConvertToUnicode(sampleText, sizeof(sampleText),
2098
toUnicode943sub, sizeof(toUnicode943sub)/sizeof(toUnicode943sub[0]),"ibm-943",
2099
UCNV_TO_U_CALLBACK_SUBSTITUTE, fromIBM943Offssub, NULL, 0 ))
2100
log_err("ibm-943->u with subst did not match.\n");
2103
static void TestEBCDIC_STATEFUL_Sub(int32_t inputsize, int32_t outputsize)
2106
UChar ebcdic_inputTest[] = { 0x0061, 0x6d64, 0x0061, 0x00A2, 0x6d65, 0x0061 };
2107
const uint8_t toIBM930[]= { 0x62, 0x0e, 0x5d, 0x63, 0x0f, 0x62, 0xb1, 0x0e, 0xfe, 0xfe, 0x0f, 0x62 };
2108
int32_t offset_930[]= { 0, 1, 1, 1, 2, 2, 3, 4, 4, 4, 5, 5 };
2109
/* s SO doubl SI sng s SO fe fe SI s */
2111
/*EBCDIC_STATEFUL with subChar=3f*/
2112
const uint8_t toIBM930_subvaried[]= { 0x62, 0x0e, 0x5d, 0x63, 0x0f, 0x62, 0xb1, 0x3f, 0x62 };
2113
int32_t offset_930_subvaried[]= { 0, 1, 1, 1, 2, 2, 3, 4, 5 };
2114
const char mySubChar[]={ 0x3f};
2116
gInBufferSize = inputsize;
2117
gOutBufferSize = outputsize;
2119
if(!testConvertFromUnicode(ebcdic_inputTest, sizeof(ebcdic_inputTest)/sizeof(ebcdic_inputTest[0]),
2120
toIBM930, sizeof(toIBM930), "ibm-930",
2121
UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset_930, NULL, 0 ))
2122
log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst did not match.\n");
2124
if(!testConvertFromUnicode(ebcdic_inputTest, sizeof(ebcdic_inputTest)/sizeof(ebcdic_inputTest[0]),
2125
toIBM930_subvaried, sizeof(toIBM930_subvaried), "ibm-930",
2126
UCNV_FROM_U_CALLBACK_SUBSTITUTE, offset_930_subvaried, mySubChar, 1 ))
2127
log_err("u-> ibm-930(EBCDIC_STATEFUL) with subst(setSubChar=0x3f) did not match.\n");
2132
UBool testConvertFromUnicode(const UChar *source, int sourceLen, const uint8_t *expect, int expectLen,
2133
const char *codepage, UConverterFromUCallback callback , const int32_t *expectOffsets,
2134
const char *mySubChar, int8_t len)
2138
UErrorCode status = U_ZERO_ERROR;
2139
UConverter *conv = 0;
2140
uint8_t junkout[NEW_MAX_BUFFER]; /* FIX */
2141
int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
2147
int32_t realBufferSize;
2148
uint8_t *realBufferEnd;
2149
const UChar *realSourceEnd;
2150
const UChar *sourceLimit;
2151
UBool checkOffsets = TRUE;
2154
char offset_str[9999];
2156
UConverterFromUCallback oldAction = NULL;
2157
const void* oldContext = NULL;
2160
for(i=0;i<NEW_MAX_BUFFER;i++)
2162
for(i=0;i<NEW_MAX_BUFFER;i++)
2164
setNuConvTestName(codepage, "FROM");
2166
log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage, gInBufferSize,
2169
conv = ucnv_open(codepage, &status);
2170
if(U_FAILURE(status))
2172
log_err("Couldn't open converter %s\n",codepage);
2176
log_verbose("Converter opened..\n");
2178
/*----setting the callback routine----*/
2179
ucnv_setFromUCallBack (conv, callback, NULL, &oldAction, &oldContext, &status);
2180
if (U_FAILURE(status))
2182
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2184
/*------------------------*/
2185
/*setting the subChar*/
2186
if(mySubChar != NULL){
2187
ucnv_setSubstChars(conv, mySubChar, len, &status);
2188
if (U_FAILURE(status)) {
2189
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2198
realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
2199
realBufferEnd = junkout + realBufferSize;
2200
realSourceEnd = source + sourceLen;
2202
if ( gOutBufferSize != realBufferSize )
2203
checkOffsets = FALSE;
2205
if( gInBufferSize != NEW_MAX_BUFFER )
2206
checkOffsets = FALSE;
2210
end = nct_min(targ + gOutBufferSize, realBufferEnd);
2211
sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
2213
doFlush = (UBool)(sourceLimit == realSourceEnd);
2215
if(targ == realBufferEnd)
2217
log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
2220
log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
2223
status = U_ZERO_ERROR;
2225
ucnv_fromUnicode (conv,
2230
checkOffsets ? offs : NULL,
2231
doFlush, /* flush if we're at the end of the input data */
2233
} while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (sourceLimit < realSourceEnd)) );
2235
/* allow failure codes for the stop callback */
2236
if(U_FAILURE(status) &&
2237
(callback != UCNV_FROM_U_CALLBACK_STOP || (status != U_INVALID_CHAR_FOUND && status != U_ILLEGAL_CHAR_FOUND)))
2239
log_err("Problem in fromUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
2243
log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
2244
sourceLen, targ-junkout);
2250
for(p = junkout;p<targ;p++)
2252
sprintf(junk + strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
2253
sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
2257
printSeq(expect, expectLen);
2260
log_verbose("\nOffsets:");
2261
log_verbose(offset_str);
2268
if(expectLen != targ-junkout)
2270
log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
2271
log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
2272
printSeqErr(junkout, targ-junkout);
2273
printSeqErr(expect, expectLen);
2277
if (checkOffsets && (expectOffsets != 0) )
2279
log_verbose("comparing %d offsets..\n", targ-junkout);
2280
if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
2281
log_err("did not get the expected offsets while %s \n", gNuConvTestName);
2282
log_err("Got Output : ");
2283
printSeqErr(junkout, targ-junkout);
2284
log_err("Got Offsets: ");
2285
for(p=junkout;p<targ;p++)
2286
log_err("%d,", junokout[p-junkout]);
2288
log_err("Expected Offsets: ");
2289
for(i=0; i<(targ-junkout); i++)
2290
log_err("%d,", expectOffsets[i]);
2296
if(!memcmp(junkout, expect, expectLen))
2298
log_verbose("String matches! %s\n", gNuConvTestName);
2303
log_err("String does not match. %s\n", gNuConvTestName);
2304
log_err("source: ");
2305
printUSeqErr(source, sourceLen);
2307
printSeqErr(junkout, expectLen);
2308
log_err("Expected: ");
2309
printSeqErr(expect, expectLen);
2313
UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen,
2314
const char *codepage, UConverterToUCallback callback, const int32_t *expectOffsets,
2315
const char *mySubChar, int8_t len)
2317
UErrorCode status = U_ZERO_ERROR;
2318
UConverter *conv = 0;
2319
UChar junkout[NEW_MAX_BUFFER]; /* FIX */
2320
int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
2322
const uint8_t *realSourceEnd;
2323
const uint8_t *srcLimit;
2328
UBool checkOffsets = TRUE;
2330
char offset_str[9999];
2332
UConverterToUCallback oldAction = NULL;
2333
const void* oldContext = NULL;
2335
int32_t realBufferSize;
2336
UChar *realBufferEnd;
2339
for(i=0;i<NEW_MAX_BUFFER;i++)
2340
junkout[i] = 0xFFFE;
2342
for(i=0;i<NEW_MAX_BUFFER;i++)
2345
setNuConvTestName(codepage, "TO");
2347
log_verbose("\n========= %s\n", gNuConvTestName);
2349
conv = ucnv_open(codepage, &status);
2350
if(U_FAILURE(status))
2352
log_err("Couldn't open converter %s\n",gNuConvTestName);
2356
log_verbose("Converter opened..\n");
2362
realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
2363
realBufferEnd = junkout + realBufferSize;
2364
realSourceEnd = src + sourcelen;
2365
/*----setting the callback routine----*/
2366
ucnv_setToUCallBack (conv, callback, NULL, &oldAction, &oldContext, &status);
2367
if (U_FAILURE(status))
2369
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2371
/*-------------------------------------*/
2372
/*setting the subChar*/
2373
if(mySubChar != NULL){
2374
ucnv_setSubstChars(conv, mySubChar, len, &status);
2375
if (U_FAILURE(status)) {
2376
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2382
if ( gOutBufferSize != realBufferSize )
2383
checkOffsets = FALSE;
2385
if( gInBufferSize != NEW_MAX_BUFFER )
2386
checkOffsets = FALSE;
2390
end = nct_min( targ + gOutBufferSize, realBufferEnd);
2391
srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
2393
if(targ == realBufferEnd)
2395
log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ,gNuConvTestName);
2398
log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
2402
status = U_ZERO_ERROR;
2404
ucnv_toUnicode (conv,
2407
(const char **)&src,
2408
(const char *)srcLimit,
2409
checkOffsets ? offs : NULL,
2410
(UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of the source data */
2412
} while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
2414
/* allow failure codes for the stop callback */
2415
if(U_FAILURE(status) &&
2416
(callback != UCNV_TO_U_CALLBACK_STOP || (status != U_INVALID_CHAR_FOUND && status != U_ILLEGAL_CHAR_FOUND && status != U_TRUNCATED_CHAR_FOUND)))
2418
log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
2422
log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
2423
sourcelen, targ-junkout);
2430
for(p = junkout;p<targ;p++)
2432
sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*p);
2433
sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[p-junkout]);
2437
printUSeq(expect, expectlen);
2440
log_verbose("\nOffsets:");
2441
log_verbose(offset_str);
2447
log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
2449
if (checkOffsets && (expectOffsets != 0))
2451
if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t)))
2453
log_err("did not get the expected offsets while %s \n", gNuConvTestName);
2454
log_err("Got offsets: ");
2455
for(p=junkout;p<targ;p++)
2456
log_err(" %2d,", junokout[p-junkout]);
2458
log_err("Expected offsets: ");
2459
for(i=0; i<(targ-junkout); i++)
2460
log_err(" %2d,", expectOffsets[i]);
2462
log_err("Got output: ");
2463
for(i=0; i<(targ-junkout); i++)
2464
log_err("0x%04x,", junkout[i]);
2466
log_err("From source: ");
2467
for(i=0; i<(src-source); i++)
2468
log_err(" 0x%02x,", (unsigned char)source[i]);
2473
if(!memcmp(junkout, expect, expectlen*2))
2475
log_verbose("Matches!\n");
2480
log_err("String does not match. %s\n", gNuConvTestName);
2481
log_verbose("String does not match. %s\n", gNuConvTestName);
2483
printUSeqErr(junkout, expectlen);
2484
log_err("Expected: ");
2485
printUSeqErr(expect, expectlen);
2491
UBool testConvertFromUnicodeWithContext(const UChar *source, int sourceLen, const uint8_t *expect, int expectLen,
2492
const char *codepage, UConverterFromUCallback callback , const int32_t *expectOffsets,
2493
const char *mySubChar, int8_t len, const void* context, UErrorCode expectedError)
2497
UErrorCode status = U_ZERO_ERROR;
2498
UConverter *conv = 0;
2499
uint8_t junkout[NEW_MAX_BUFFER]; /* FIX */
2500
int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
2506
int32_t realBufferSize;
2507
uint8_t *realBufferEnd;
2508
const UChar *realSourceEnd;
2509
const UChar *sourceLimit;
2510
UBool checkOffsets = TRUE;
2513
char offset_str[9999];
2515
UConverterFromUCallback oldAction = NULL;
2516
const void* oldContext = NULL;
2519
for(i=0;i<NEW_MAX_BUFFER;i++)
2521
for(i=0;i<NEW_MAX_BUFFER;i++)
2523
setNuConvTestName(codepage, "FROM");
2525
log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage, gInBufferSize,
2528
conv = ucnv_open(codepage, &status);
2529
if(U_FAILURE(status))
2531
log_err("Couldn't open converter %s\n",codepage);
2535
log_verbose("Converter opened..\n");
2537
/*----setting the callback routine----*/
2538
ucnv_setFromUCallBack (conv, callback, context, &oldAction, &oldContext, &status);
2539
if (U_FAILURE(status))
2541
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2543
/*------------------------*/
2544
/*setting the subChar*/
2545
if(mySubChar != NULL){
2546
ucnv_setSubstChars(conv, mySubChar, len, &status);
2547
if (U_FAILURE(status)) {
2548
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2557
realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
2558
realBufferEnd = junkout + realBufferSize;
2559
realSourceEnd = source + sourceLen;
2561
if ( gOutBufferSize != realBufferSize )
2562
checkOffsets = FALSE;
2564
if( gInBufferSize != NEW_MAX_BUFFER )
2565
checkOffsets = FALSE;
2569
end = nct_min(targ + gOutBufferSize, realBufferEnd);
2570
sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
2572
doFlush = (UBool)(sourceLimit == realSourceEnd);
2574
if(targ == realBufferEnd)
2576
log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
2579
log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
2582
status = U_ZERO_ERROR;
2584
ucnv_fromUnicode (conv,
2589
checkOffsets ? offs : NULL,
2590
doFlush, /* flush if we're at the end of the input data */
2592
} while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (sourceLimit < realSourceEnd)) );
2594
/* allow failure codes for the stop callback */
2595
if(U_FAILURE(status) && status != expectedError)
2597
log_err("Problem in fromUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
2601
log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
2602
sourceLen, targ-junkout);
2608
for(p = junkout;p<targ;p++)
2610
sprintf(junk + strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
2611
sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
2615
printSeq(expect, expectLen);
2618
log_verbose("\nOffsets:");
2619
log_verbose(offset_str);
2626
if(expectLen != targ-junkout)
2628
log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
2629
log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
2630
printSeqErr(junkout, targ-junkout);
2631
printSeqErr(expect, expectLen);
2635
if (checkOffsets && (expectOffsets != 0) )
2637
log_verbose("comparing %d offsets..\n", targ-junkout);
2638
if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
2639
log_err("did not get the expected offsets while %s \n", gNuConvTestName);
2640
log_err("Got Output : ");
2641
printSeqErr(junkout, targ-junkout);
2642
log_err("Got Offsets: ");
2643
for(p=junkout;p<targ;p++)
2644
log_err("%d,", junokout[p-junkout]);
2646
log_err("Expected Offsets: ");
2647
for(i=0; i<(targ-junkout); i++)
2648
log_err("%d,", expectOffsets[i]);
2654
if(!memcmp(junkout, expect, expectLen))
2656
log_verbose("String matches! %s\n", gNuConvTestName);
2661
log_err("String does not match. %s\n", gNuConvTestName);
2662
log_err("source: ");
2663
printUSeqErr(source, sourceLen);
2665
printSeqErr(junkout, expectLen);
2666
log_err("Expected: ");
2667
printSeqErr(expect, expectLen);
2671
UBool testConvertToUnicodeWithContext( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen,
2672
const char *codepage, UConverterToUCallback callback, const int32_t *expectOffsets,
2673
const char *mySubChar, int8_t len, const void* context, UErrorCode expectedError)
2675
UErrorCode status = U_ZERO_ERROR;
2676
UConverter *conv = 0;
2677
UChar junkout[NEW_MAX_BUFFER]; /* FIX */
2678
int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
2680
const uint8_t *realSourceEnd;
2681
const uint8_t *srcLimit;
2686
UBool checkOffsets = TRUE;
2688
char offset_str[9999];
2690
UConverterToUCallback oldAction = NULL;
2691
const void* oldContext = NULL;
2693
int32_t realBufferSize;
2694
UChar *realBufferEnd;
2697
for(i=0;i<NEW_MAX_BUFFER;i++)
2698
junkout[i] = 0xFFFE;
2700
for(i=0;i<NEW_MAX_BUFFER;i++)
2703
setNuConvTestName(codepage, "TO");
2705
log_verbose("\n========= %s\n", gNuConvTestName);
2707
conv = ucnv_open(codepage, &status);
2708
if(U_FAILURE(status))
2710
log_err("Couldn't open converter %s\n",gNuConvTestName);
2714
log_verbose("Converter opened..\n");
2720
realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
2721
realBufferEnd = junkout + realBufferSize;
2722
realSourceEnd = src + sourcelen;
2723
/*----setting the callback routine----*/
2724
ucnv_setToUCallBack (conv, callback, context, &oldAction, &oldContext, &status);
2725
if (U_FAILURE(status))
2727
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2729
/*-------------------------------------*/
2730
/*setting the subChar*/
2731
if(mySubChar != NULL){
2732
ucnv_setSubstChars(conv, mySubChar, len, &status);
2733
if (U_FAILURE(status)) {
2734
log_err("FAILURE in setting the callback Function! %s\n", myErrorName(status));
2740
if ( gOutBufferSize != realBufferSize )
2741
checkOffsets = FALSE;
2743
if( gInBufferSize != NEW_MAX_BUFFER )
2744
checkOffsets = FALSE;
2748
end = nct_min( targ + gOutBufferSize, realBufferEnd);
2749
srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
2751
if(targ == realBufferEnd)
2753
log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ,gNuConvTestName);
2756
log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
2760
status = U_ZERO_ERROR;
2762
ucnv_toUnicode (conv,
2765
(const char **)&src,
2766
(const char *)srcLimit,
2767
checkOffsets ? offs : NULL,
2768
(UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of the source data */
2770
} while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
2772
/* allow failure codes for the stop callback */
2773
if(U_FAILURE(status) && status!=expectedError)
2775
log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
2779
log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
2780
sourcelen, targ-junkout);
2787
for(p = junkout;p<targ;p++)
2789
sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*p);
2790
sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[p-junkout]);
2794
printUSeq(expect, expectlen);
2797
log_verbose("\nOffsets:");
2798
log_verbose(offset_str);
2804
log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
2806
if (checkOffsets && (expectOffsets != 0))
2808
if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t)))
2810
log_err("did not get the expected offsets while %s \n", gNuConvTestName);
2811
log_err("Got offsets: ");
2812
for(p=junkout;p<targ;p++)
2813
log_err(" %2d,", junokout[p-junkout]);
2815
log_err("Expected offsets: ");
2816
for(i=0; i<(targ-junkout); i++)
2817
log_err(" %2d,", expectOffsets[i]);
2819
log_err("Got output: ");
2820
for(i=0; i<(targ-junkout); i++)
2821
log_err("0x%04x,", junkout[i]);
2823
log_err("From source: ");
2824
for(i=0; i<(src-source); i++)
2825
log_err(" 0x%02x,", (unsigned char)source[i]);
2830
if(!memcmp(junkout, expect, expectlen*2))
2832
log_verbose("Matches!\n");
2837
log_err("String does not match. %s\n", gNuConvTestName);
2838
log_verbose("String does not match. %s\n", gNuConvTestName);
2840
printUSeqErr(junkout, expectlen);
2841
log_err("Expected: ");
2842
printUSeqErr(expect, expectlen);