]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/ncnvfbts.c
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ncnvfbts.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2004, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ***************************************************************************/
6 /*******************************************************************************
7 *
8 * File NCNVCBTS
9 *
10 * Modification History:
11 * Name Date Description
12 * Madhu Katragadda 06/23/2000 Tests for Conveter FallBack API and Functionality
13 **********************************************************************************
14 */
15 #include <stdio.h>
16 #include "unicode/uloc.h"
17 #include "unicode/ucnv.h"
18 #include "unicode/ucnv_err.h"
19 #include "cintltst.h"
20 #include "unicode/utypes.h"
21 #include "unicode/ustring.h"
22 #include "ncnvfbts.h"
23 #include "cmemory.h"
24 #include "cstring.h"
25
26 #define NEW_MAX_BUFFER 999
27
28
29 #define nct_min(x,y) ((x<y) ? x : y)
30
31 static int32_t gInBufferSize = 0;
32 static int32_t gOutBufferSize = 0;
33 static char gNuConvTestName[1024];
34
35 static UConverter *my_ucnv_open(const char *cnv, UErrorCode *err)
36 {
37 if(cnv && cnv[0] == '@') {
38 return ucnv_openPackage("testdata", cnv+1, err);
39 } else {
40 return ucnv_open(cnv, err);
41 }
42 }
43
44
45 static void printSeq(const unsigned char* a, int len)
46 {
47 int i=0;
48 log_verbose("{");
49 while (i<len)
50 log_verbose("0x%02x ", a[i++]);
51 log_verbose("}\n");
52 }
53
54 static void printUSeq(const UChar* a, int len)
55 {
56 int i=0;
57 log_verbose("{U+");
58 while (i<len)
59 log_verbose("0x%04x ", a[i++]);
60 log_verbose("}\n");
61 }
62
63 static void printSeqErr(const unsigned char* a, int len)
64 {
65 int i=0;
66 fprintf(stderr, "{");
67 while (i<len)
68 fprintf(stderr, "0x%02x ", a[i++]);
69 fprintf(stderr, "}\n");
70 }
71
72 static void printUSeqErr(const UChar* a, int len)
73 {
74 int i=0;
75 fprintf(stderr, "{U+");
76 while (i<len)
77 fprintf(stderr, "0x%04x ", a[i++]);
78 fprintf(stderr,"}\n");
79 }
80
81 static void TestConverterFallBack(void)
82 {
83 TestConvertFallBackWithBufferSizes(10,10);
84 TestConvertFallBackWithBufferSizes(2,3);
85 TestConvertFallBackWithBufferSizes(3,2);
86 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,1);
87 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,2);
88 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,3);
89 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,4);
90 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,5);
91 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,6);
92 TestConvertFallBackWithBufferSizes(1,NEW_MAX_BUFFER);
93 TestConvertFallBackWithBufferSizes(2,NEW_MAX_BUFFER);
94 TestConvertFallBackWithBufferSizes(3,NEW_MAX_BUFFER);
95 TestConvertFallBackWithBufferSizes(4,NEW_MAX_BUFFER);
96 TestConvertFallBackWithBufferSizes(5,NEW_MAX_BUFFER);
97 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER,NEW_MAX_BUFFER);
98
99 }
100
101
102 void addTestConverterFallBack(TestNode** root);
103
104 void addTestConverterFallBack(TestNode** root)
105 {
106 addTest(root, &TestConverterFallBack, "tsconv/ncnvfbts/TestConverterFallBack");
107
108 }
109
110
111 /* Note that this test already makes use of statics, so it's not really
112 multithread safe.
113 This convenience function lets us make the error messages actually useful.
114 */
115
116 static void setNuConvTestName(const char *codepage, const char *direction)
117 {
118 sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
119 codepage,
120 direction,
121 (int)gInBufferSize,
122 (int)gOutBufferSize);
123 }
124
125
126 static UBool testConvertFromUnicode(const UChar *source, int sourceLen, const uint8_t *expect, int expectLen,
127 const char *codepage, UBool fallback, const int32_t *expectOffsets)
128 {
129
130
131 UErrorCode status = U_ZERO_ERROR;
132 UConverter *conv = 0;
133 uint8_t junkout[NEW_MAX_BUFFER]; /* FIX */
134 int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
135 const UChar *src;
136 uint8_t *end;
137 uint8_t *targ;
138 int32_t *offs;
139 int i;
140 int32_t realBufferSize;
141 uint8_t *realBufferEnd;
142 const UChar *realSourceEnd;
143 const UChar *sourceLimit;
144 UBool checkOffsets = TRUE;
145 UBool doFlush;
146 UBool action=FALSE;
147 uint8_t *p;
148
149
150 for(i=0;i<NEW_MAX_BUFFER;i++)
151 junkout[i] = 0xF0;
152 for(i=0;i<NEW_MAX_BUFFER;i++)
153 junokout[i] = 0xFF;
154 setNuConvTestName(codepage, "FROM");
155
156 log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage, gInBufferSize,
157 gOutBufferSize);
158
159 conv = my_ucnv_open(codepage, &status);
160 if(U_FAILURE(status))
161 {
162 log_data_err("Couldn't open converter %s\n",codepage);
163 return TRUE;
164 }
165
166 log_verbose("Converter opened..\n");
167 /*----setting the callback routine----*/
168 ucnv_setFallback (conv, fallback);
169 action = ucnv_usesFallback(conv);
170 if(action != fallback){
171 log_err("FAIL: Error is setting fallback. Errocode=%s\n", myErrorName(status));
172 }
173 /*------------------------*/
174 src = source;
175 targ = junkout;
176 offs = junokout;
177
178 realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
179 realBufferEnd = junkout + realBufferSize;
180 realSourceEnd = source + sourceLen;
181
182 if ( gOutBufferSize != realBufferSize )
183 checkOffsets = FALSE;
184
185 if( gInBufferSize != NEW_MAX_BUFFER )
186 checkOffsets = FALSE;
187
188 do
189 {
190 end = nct_min(targ + gOutBufferSize, realBufferEnd);
191 sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
192
193 doFlush = (UBool)(sourceLimit == realSourceEnd);
194
195 if(targ == realBufferEnd)
196 {
197 log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
198 return FALSE;
199 }
200 log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
201
202
203 status = U_ZERO_ERROR;
204
205 ucnv_fromUnicode (conv,
206 (char **)&targ,
207 (const char *)end,
208 &src,
209 sourceLimit,
210 checkOffsets ? offs : NULL,
211 doFlush, /* flush if we're at the end of the input data */
212 &status);
213
214 } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (sourceLimit < realSourceEnd) );
215
216 if(U_FAILURE(status))
217 {
218 log_err("Problem doing toUnicode, errcode %d %s\n", myErrorName(status), gNuConvTestName);
219 return FALSE;
220 }
221
222 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
223 sourceLen, targ-junkout);
224 if(VERBOSITY)
225 {
226 char junk[9999];
227 char offset_str[9999];
228
229 junk[0] = 0;
230 offset_str[0] = 0;
231 for(p = junkout;p<targ;p++)
232 {
233 sprintf(junk + uprv_strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
234 sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
235 }
236
237 log_verbose(junk);
238 printSeq((const unsigned char*)expect, expectLen);
239 if ( checkOffsets )
240 {
241 log_verbose("\nOffsets:");
242 log_verbose(offset_str);
243 }
244 log_verbose("\n");
245 }
246 ucnv_close(conv);
247
248
249 if(expectLen != targ-junkout)
250 {
251 log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
252 log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
253 printSeqErr((const unsigned char*)junkout, targ-junkout);
254 printSeqErr((const unsigned char*)expect, expectLen);
255 return FALSE;
256 }
257
258 if (checkOffsets && (expectOffsets != 0) )
259 {
260 log_verbose("\ncomparing %d offsets..\n", targ-junkout);
261 if(uprv_memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
262 log_err("\ndid not get the expected offsets while %s \n", gNuConvTestName);
263 log_err("Got : ");
264 printSeqErr((const unsigned char*)junkout, targ-junkout);
265 for(p=junkout;p<targ;p++)
266 log_err("%d, ", junokout[p-junkout]);
267 log_err("\nExpected: ");
268 for(i=0; i<(targ-junkout); i++)
269 log_err("%d,", expectOffsets[i]);
270 }
271 }
272
273 log_verbose("\n\ncomparing..\n");
274 if(!memcmp(junkout, expect, expectLen))
275 {
276 log_verbose("Matches!\n");
277 return TRUE;
278 }
279 else
280 {
281 log_err("String does not match. %s\n", gNuConvTestName);
282 log_verbose("String does not match. %s\n", gNuConvTestName);
283 printSeqErr((const unsigned char*)junkout, expectLen);
284 printSeqErr((const unsigned char*)expect, expectLen);
285 return FALSE;
286 }
287 }
288
289 static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *expect, int expectlen,
290 const char *codepage, UBool fallback, const int32_t *expectOffsets)
291 {
292 UErrorCode status = U_ZERO_ERROR;
293 UConverter *conv = 0;
294 UChar junkout[NEW_MAX_BUFFER]; /* FIX */
295 int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
296 const uint8_t *src;
297 const uint8_t *realSourceEnd;
298 const uint8_t *srcLimit;
299 UChar *targ;
300 UChar *end;
301 int32_t *offs;
302 int i;
303 UBool checkOffsets = TRUE;
304 char junk[9999];
305 char offset_str[9999];
306 UChar *p;
307 UBool action;
308
309 int32_t realBufferSize;
310 UChar *realBufferEnd;
311
312
313 for(i=0;i<NEW_MAX_BUFFER;i++)
314 junkout[i] = 0xFFFE;
315
316 for(i=0;i<NEW_MAX_BUFFER;i++)
317 junokout[i] = -1;
318
319 setNuConvTestName(codepage, "TO");
320
321 log_verbose("\n========= %s\n", gNuConvTestName);
322
323 conv = my_ucnv_open(codepage, &status);
324 if(U_FAILURE(status))
325 {
326 log_data_err("Couldn't open converter %s\n",gNuConvTestName);
327 return TRUE; /* because it has been logged */
328 }
329
330 log_verbose("Converter opened..\n");
331
332 src = source;
333 targ = junkout;
334 offs = junokout;
335
336 realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
337 realBufferEnd = junkout + realBufferSize;
338 realSourceEnd = src + sourcelen;
339 /*----setting the fallback routine----*/
340 ucnv_setFallback (conv, fallback);
341 action = ucnv_usesFallback(conv);
342 if(action != fallback){
343 log_err("FAIL: Error is setting fallback. Errocode=%s\n", myErrorName(status));
344 }
345 /*-------------------------------------*/
346 if ( gOutBufferSize != realBufferSize )
347 checkOffsets = FALSE;
348
349 if( gInBufferSize != NEW_MAX_BUFFER )
350 checkOffsets = FALSE;
351
352 do
353 {
354 end = nct_min( targ + gOutBufferSize, realBufferEnd);
355 srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
356
357 if(targ == realBufferEnd)
358 {
359 log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ,gNuConvTestName);
360 return FALSE;
361 }
362 log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
363
364
365
366 status = U_ZERO_ERROR;
367
368 ucnv_toUnicode (conv,
369 &targ,
370 end,
371 (const char **)&src,
372 (const char *)srcLimit,
373 checkOffsets ? offs : NULL,
374 (UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of hte source data */
375 &status);
376 } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (srcLimit < realSourceEnd) ); /* while we just need another buffer */
377
378
379 if(U_FAILURE(status))
380 {
381 log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status), gNuConvTestName);
382 return FALSE;
383 }
384
385 log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
386 sourcelen, targ-junkout);
387 if(VERBOSITY)
388 {
389
390 junk[0] = 0;
391 offset_str[0] = 0;
392
393 for(p = junkout;p<targ;p++)
394 {
395 sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*p);
396 sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[p-junkout]);
397 }
398
399 log_verbose(junk);
400 printUSeq(expect, expectlen);
401 if ( checkOffsets )
402 {
403 log_verbose("\nOffsets:");
404 log_verbose(offset_str);
405 }
406 log_verbose("\n");
407 }
408 ucnv_close(conv);
409
410 log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
411
412 if (checkOffsets && (expectOffsets != 0))
413 {
414 if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t)))
415 {
416 log_err("\n\ndid not get the expected offsets while %s \n", gNuConvTestName);
417 log_err("\nGot : ");
418 for(p=junkout;p<targ;p++)
419 log_err("%d, ", junokout[p-junkout]);
420 log_err("\nExpected: ");
421 for(i=0; i<(targ-junkout); i++)
422 log_err("%d,", expectOffsets[i]);
423 log_err("");
424 for(i=0; i<(targ-junkout); i++)
425 log_err("0x%04X,", junkout[i]);
426 log_err("");
427 for(i=0; i<(src-source); i++)
428 log_err("0x%04X,", (unsigned char)source[i]);
429 }
430 }
431
432 if(!memcmp(junkout, expect, expectlen*2))
433 {
434 log_verbose("Matches!\n");
435 return TRUE;
436 }
437 else
438 {
439 log_err("String does not match. %s\n", gNuConvTestName);
440 log_verbose("String does not match. %s\n", gNuConvTestName);
441 printUSeqErr(junkout, expectlen);
442 printf("\n");
443 printUSeqErr(expect, expectlen);
444 return FALSE;
445 }
446 }
447
448
449
450 static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize )
451 {
452
453 static const UChar SBCSText[] =
454 { 0x0021, 0xFF01, 0x0022, 0xFF02, 0x0023, 0xFF03, 0x003A, 0xFF1A, 0x003B, 0xFF1B, 0x003C, 0xFF1C };
455 /* 21, ?, 22, ?, 23, ?, 3a, ?, 3b, ?, 3c, ? SBCS*/
456 static const uint8_t expectedNative[] =
457 { 0x21, 0x21, 0x22, 0x22, 0x23, 0x23, 0x3a, 0x3a, 0x3b, 0x3b, 0x3c, 0x3c};
458 static const UChar retrievedSBCSText[]=
459 { 0x0021, 0x0021, 0x0022, 0x0022, 0x0023, 0x0023, 0x003A, 0x003A, 0x003B, 0x003B, 0x003C, 0x003C };
460 static const int32_t toNativeOffs [] =
461 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};
462 static const int32_t fromNativeoffs [] =
463 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
464
465
466 /* 1363 isn't DBCS, but it has the DBCS section */
467 static const UChar DBCSText[] =
468 { 0x00a1, 0x00ad, 0x2010, 0x00b7, 0x30fb};
469 static const uint8_t expectedIBM1363_DBCS[] =
470 { 0xa2, 0xae, 0xa1 ,0xa9, 0xa1, 0xa9,0xa1 ,0xa4, 0xa1, 0xa4};
471 static const UChar retrievedDBCSText[]=
472 { 0x00a1, 0x2010, 0x2010, 0x30fb, 0x30fb };
473 static const int32_t toIBM1363Offs_DBCS[] =
474 { 0x00, 0x00, 0x01,0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04};
475 static const int32_t fromIBM1363offs_DBCS[] =
476 { 0, 2, 4, 6, 8};
477
478
479 static const UChar MBCSText[] =
480 { 0x0001, 0x263a, 0x2013, 0x2014, 0x263b, 0x0002};
481 static const uint8_t expectedIBM950[] =
482 { 0x01, 0x01, 0xa1, 0x56, 0xa1, 0x56, 0x02, 0x02};
483 static const UChar retrievedMBCSText[]=
484 { 0x0001, 0x0001, 0x2014, 0x2014, 0x0002, 0x0002};
485 static const int32_t toIBM950Offs [] =
486 { 0x00, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x05};
487 static const int32_t fromIBM950offs [] =
488 { 0, 1, 2, 4, 6, 7};
489
490 static const UChar MBCSText1363[] =
491 { 0x0005,
492 0xffe8,
493 0x0007,
494 0x2022,
495 0x005c,
496 0x00b7,
497 0x3016,
498 0x30fb,
499 0x9a36};
500 static const uint8_t expectedIBM1363[] =
501 { 0x05,
502 0x05,
503 0x07,
504 0x07,
505 0x7f,
506 0xa1, 0xa4,
507 0xa1, 0xe0,
508 0xa1, 0xa4,
509 0xf5, 0xe2};
510 static const UChar retrievedMBCSText1363[]=
511 { 0x0005, 0x0005, 0x0007, 0x0007, 0x001a, 0x30fb, 0x25a1, 0x30fb, 0x9a36};
512 static const int32_t toIBM1363Offs [] =
513 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08};
514 static const int32_t fromIBM1363offs [] =
515 { 0, 1, 2, 3, 4, 5, 7, 9, 11};
516
517
518
519 static const char* nativeCodePage[]={
520 /*NLCS Mapping*/
521 "ibm-367",
522 "ibm-437",
523 "ibm-850",
524 "ibm-1051",
525 "ibm-1089",
526 "ibm-1250",
527 "ibm-1251",
528 "ibm-1253",
529 "ibm-1254",
530 "ibm-1255",
531 "ibm-1256",
532 "ibm-1257",
533 "ibm-1258",
534 "ibm-1276",
535 "ibm-1277"
536 };
537
538 int32_t i=0;
539 gInBufferSize = insize;
540 gOutBufferSize = outsize;
541
542 for(i=0; i<sizeof(nativeCodePage)/sizeof(nativeCodePage[0]); i++){
543 log_verbose("Testing %s\n", nativeCodePage[i]);
544 if(!testConvertFromUnicode(SBCSText, sizeof(SBCSText)/sizeof(SBCSText[0]),
545 expectedNative, sizeof(expectedNative), nativeCodePage[i], TRUE, toNativeOffs ))
546 log_err("u-> %s(SBCS) with FallBack did not match.\n", nativeCodePage[i]);
547
548 if(!testConvertToUnicode(expectedNative, sizeof(expectedNative),
549 retrievedSBCSText, sizeof(retrievedSBCSText)/sizeof(retrievedSBCSText[0]), nativeCodePage[i], TRUE, fromNativeoffs ))
550 log_err("%s->u(SBCS) with Fallback did not match.\n", nativeCodePage[i]);
551 }
552
553 /*DBCS*/
554 if(!testConvertFromUnicode(DBCSText, sizeof(DBCSText)/sizeof(DBCSText[0]),
555 expectedIBM1363_DBCS, sizeof(expectedIBM1363_DBCS), "ibm-1363", TRUE, toIBM1363Offs_DBCS ))
556 log_err("u-> ibm-1363(DBCS portion) with FallBack did not match.\n");
557
558 if(!testConvertToUnicode(expectedIBM1363_DBCS, sizeof(expectedIBM1363_DBCS),
559 retrievedDBCSText, sizeof(retrievedDBCSText)/sizeof(retrievedDBCSText[0]),"ibm-1363", TRUE, fromIBM1363offs_DBCS ))
560 log_err("ibm-1363->u(DBCS portion) with Fallback did not match.\n");
561
562
563 /*MBCS*/
564 if(!testConvertFromUnicode(MBCSText, sizeof(MBCSText)/sizeof(MBCSText[0]),
565 expectedIBM950, sizeof(expectedIBM950), "ibm-950", TRUE, toIBM950Offs ))
566 log_err("u-> ibm-950(MBCS) with FallBack did not match.\n");
567
568 if(!testConvertToUnicode(expectedIBM950, sizeof(expectedIBM950),
569 retrievedMBCSText, sizeof(retrievedMBCSText)/sizeof(retrievedMBCSText[0]),"ibm-950", TRUE, fromIBM950offs ))
570 log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
571
572 /*commented untill data table is available*/
573 log_verbose("toUnicode fallback with fallback data for MBCS\n");
574 {
575 const uint8_t IBM950input[] = {
576 0xf4, 0x87, 0xa4, 0x4a, 0xf4, 0x88, 0xa4, 0x4b,
577 0xf9, 0x92, 0xdc, 0xb0, };
578 UChar expectedUnicodeText[]= { 0x5165, 0x5165, 0x516b, 0x516b, 0x9ef9, 0x9ef9};
579 int32_t fromIBM950inputOffs [] = { 0, 2, 4, 6, 8, 10};
580 /* for testing reverse fallback behavior */
581 UChar expectedFallbackFalse[]= { 0x5165, 0x5165, 0x516b, 0x516b, 0x9ef9, 0x9ef9};
582
583 if(!testConvertToUnicode(IBM950input, sizeof(IBM950input),
584 expectedUnicodeText, sizeof(expectedUnicodeText)/sizeof(expectedUnicodeText[0]),"ibm-950", TRUE, fromIBM950inputOffs ))
585 log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
586 if(!testConvertToUnicode(IBM950input, sizeof(IBM950input),
587 expectedFallbackFalse, sizeof(expectedFallbackFalse)/sizeof(expectedFallbackFalse[0]),"ibm-950", FALSE, fromIBM950inputOffs ))
588 log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
589
590 }
591 log_verbose("toUnicode fallback with fallback data for euc-tw\n");
592 {
593 const uint8_t euc_tw_input[] = {
594 0xA7, 0xCC, 0x8E, 0xA2, 0xA1, 0xAB,
595 0xA8, 0xC7, 0xC8, 0xDE,
596 0xA8, 0xCD, 0x8E, 0xA2, 0xA2, 0xEA,};
597 UChar expectedUnicodeText[]= { 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278};
598 int32_t from_euc_tw_offs [] = { 0, 2, 6, 8, 10, 12};
599 /* for testing reverse fallback behavior */
600 UChar expectedFallbackFalse[]= { 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278};
601
602 if(!testConvertToUnicode(euc_tw_input, sizeof(euc_tw_input),
603 expectedUnicodeText, sizeof(expectedUnicodeText)/sizeof(expectedUnicodeText[0]),"euc-tw", TRUE, from_euc_tw_offs ))
604 log_err("from euc-tw->u with Fallback did not match.\n");
605
606 if(!testConvertToUnicode(euc_tw_input, sizeof(euc_tw_input),
607 expectedFallbackFalse, sizeof(expectedFallbackFalse)/sizeof(expectedFallbackFalse[0]),"euc-tw", FALSE, from_euc_tw_offs ))
608 log_err("from euc-tw->u with Fallback false did not match.\n");
609
610
611 }
612 log_verbose("fromUnicode to euc-tw with fallback data euc-tw\n");
613 {
614 UChar inputText[]= { 0x0001, 0x008e, 0x203e, 0x2223, 0xff5c, 0x5296,
615 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278, 0xEDEC};
616 const uint8_t expected_euc_tw[] = {
617 0x01, 0x1a, 0xa2, 0xa3,
618 0xa2, 0xde, 0xa2, 0xde,
619 0x8e, 0xa2, 0xe5, 0xb9,
620 0x8e, 0xa2, 0xa1, 0xab, 0x8e, 0xa2, 0xa1, 0xab,
621 0xc8, 0xde, 0xc8, 0xde,
622 0x8e, 0xa2, 0xa2, 0xea, 0x8e, 0xa2, 0xa2, 0xea,
623 0x8e, 0xac, 0xc6, 0xf7};
624 int32_t to_euc_tw_offs [] = { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6,
625 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12};
626
627 if(!testConvertFromUnicode(inputText, sizeof(inputText)/sizeof(inputText[0]),
628 expected_euc_tw, sizeof(expected_euc_tw), "euc-tw", TRUE, to_euc_tw_offs ))
629 log_err("u-> euc-tw with FallBack did not match.\n");
630
631 }
632
633 /*MBCS 1363*/
634 if(!testConvertFromUnicode(MBCSText1363, sizeof(MBCSText1363)/sizeof(MBCSText1363[0]),
635 expectedIBM1363, sizeof(expectedIBM1363), "ibm-1363", TRUE, toIBM1363Offs ))
636 log_err("u-> ibm-1363(MBCS) with FallBack did not match.\n");
637
638 if(!testConvertToUnicode(expectedIBM1363, sizeof(expectedIBM1363),
639 retrievedMBCSText1363, sizeof(retrievedMBCSText1363)/sizeof(retrievedMBCSText1363[0]),"ibm-1363", TRUE, fromIBM1363offs ))
640 log_err("ibm-1363->u(MBCS) with Fallback did not match.\n");
641
642
643 /*some more test to increase the code coverage in MBCS. Create an test converter from test1.ucm
644 which is test file for MBCS conversion with single-byte codepage data.*/
645 {
646
647 /* MBCS with single byte codepage data test1.ucm*/
648 const UChar unicodeInput[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xdbba, 0xdfcd, 0x0003};
649 const uint8_t expectedtest1[] = { 0x00, 0x05, 0xff, 0x07, 0x08, 0xff,};
650 int32_t totest1Offs[] = { 0, 1, 2, 3, 5, 7};
651
652 const uint8_t test1input[] = { 0x00, 0x05, 0x06, 0x07, 0x08, 0x09};
653 const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xfffd, 0xfffd, 0xfffe};
654 int32_t fromtest1Offs[] = { 0, 1, 2, 3, 3, 4,5};
655
656 /*from Unicode*/
657 if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
658 expectedtest1, sizeof(expectedtest1), "@test1", TRUE, totest1Offs ))
659 log_err("u-> test1(MBCS conversion with single-byte) did not match.\n");
660
661 /*to Unicode*/
662 if(!testConvertToUnicode(test1input, sizeof(test1input),
663 expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test1", TRUE, fromtest1Offs ))
664 log_err("test1(MBCS conversion with single-byte) -> u did not match.\n");
665
666 }
667
668 /*some more test to increase the code coverage in MBCS. Create an test converter from test3.ucm
669 which is test file for MBCS conversion with three-byte codepage data.*/
670 {
671
672 /* MBCS with three byte codepage data test3.ucm*/
673 const UChar unicodeInput[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xdbba, 0xdfcd, 0x000b, 0xd84d, 0xdc56, 0x000e, 0x0003, };
674 const uint8_t expectedtest3[] = { 0x00, 0x05, 0xff, 0x07, 0xff, 0x01, 0x02, 0x0b, 0x01, 0x02, 0x0a, 0xff, 0xff,};
675 int32_t totest3Offs[] = { 0, 1, 2, 3, 5, 7, 7, 7, 8, 8, 8, 10, 11};
676
677 const uint8_t test3input[] = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x0b, 0x07, 0x01, 0x02, 0x0a,
678 0x01, 0x02, 0x0e, 0x01, 0x02, 0x0d, 0x03, 0x01, 0x02, 0x0f,};
679 const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56,
680 0x000e, 0xd891, 0xdd67, 0xfffd, 0xfffd };
681 int32_t fromtest3Offs[] = { 0, 1, 2, 3, 6, 6, 7, 7, 10, 13, 13, 16, 17};
682
683 /*from Unicode*/
684 if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
685 expectedtest3, sizeof(expectedtest3), "@test3", TRUE, totest3Offs ))
686 log_err("u-> test3(MBCS conversion with three-byte) did not match.\n");
687
688 /*to Unicode*/
689 if(!testConvertToUnicode(test3input, sizeof(test3input),
690 expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", TRUE, fromtest3Offs ))
691 log_err("test3(MBCS conversion with three-byte) -> u did not match.\n");
692
693 }
694
695 /*some more test to increase the code coverage in MBCS. Create an test converter from test4.ucm
696 which is test file for MBCS conversion with four-byte codepage data.*/
697 {
698
699 /* MBCS with three byte codepage data test4.ucm*/
700 const UChar unicodeInput[] =
701 { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xdbba, 0xdfcd,
702 0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0x000f};
703 const uint8_t expectedtest4[] =
704 { 0x00, 0x05, 0xff, 0x01, 0x02, 0x03, 0x0b, 0x07, 0xff,
705 0x01, 0x02, 0x03, 0x0a, 0xff, 0xff, 0xff};
706 int32_t totest4Offs[] =
707 { 0, 1, 2, 3, 3, 3, 3, 4, 6, 8, 8, 8, 8, 10, 11, 13};
708
709 const uint8_t test4input[] =
710 { 0x00, 0x05, 0x06, 0x01, 0x02, 0x03, 0x0b, 0x07, 0x08,
711 0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0e, 0x01, 0x02, 0x03, 0x0d, 0x03, 0x01, 0x02, 0x03, 0x0c,};
712 const UChar expectedUnicode[] =
713 { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xdbba, 0xdfcd,
714 0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0x1a, 0xfffd};
715 int32_t fromtest4Offs[] =
716 { 0, 1, 2, 3, 7, 7, 8, 8, 9, 9, 13, 17, 17, 21, 22,};
717
718 /*from Unicode*/
719 if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
720 expectedtest4, sizeof(expectedtest4), "@test4", TRUE, totest4Offs ))
721 log_err("u-> test4(MBCS conversion with four-byte) did not match.\n");
722
723 /*to Unicode*/
724 if(!testConvertToUnicode(test4input, sizeof(test4input),
725 expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", TRUE, fromtest4Offs ))
726 log_err("test4(MBCS conversion with four-byte) -> u did not match.\n");
727
728 }
729 /* Test for jitterbug 509 EBCDIC_STATEFUL Converters*/
730 {
731 const UChar unicodeInput[] = {0x00AF, 0x2013, 0x2223, 0x004C, 0x5F5D, 0xFF5E };
732 const uint8_t expectedtest1[] = {0x0E,0x42,0xA1, 0x44,0x4A, 0x42,0x4F, 0x0F,0xD3, 0x0E,0x65,0x60, 0x43,0xA1,0x0f };
733 int32_t totest1Offs[] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5 };
734 const uint8_t test1input[] = {0x0E,0x42,0xA1, 0x44,0x4A, 0x42,0x4F, 0x0F,0xD3, 0x0E,0x65,0x60, 0x43,0xA1 };
735 const UChar expectedUnicode[] = {0x203e, 0x2014, 0xff5c, 0x004c, 0x5f5e, 0x223c };
736 int32_t fromtest1Offs[] = {1, 3, 5, 8, 10, 12 };
737 /*from Unicode*/
738 if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
739 expectedtest1, sizeof(expectedtest1), "ibm-1371", TRUE, totest1Offs ))
740 log_err("u-> ibm-1371(MBCS conversion with single-byte) did not match.,\n");
741 /*to Unicode*/
742 if(!testConvertToUnicode(test1input, sizeof(test1input),
743 expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "ibm-1371", TRUE, fromtest1Offs ))
744 log_err("ibm-1371(MBCS conversion with single-byte) -> u did not match.,\n");
745 }
746
747 }