1 /********************************************************************
3 * Copyright (c) 1997-2004, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ***************************************************************************/
6 /*******************************************************************************
10 * Modification History:
11 * Name Date Description
12 * Madhu Katragadda 06/23/2000 Tests for Conveter FallBack API and Functionality
13 **********************************************************************************
16 #include "unicode/uloc.h"
17 #include "unicode/ucnv.h"
18 #include "unicode/ucnv_err.h"
20 #include "unicode/utypes.h"
21 #include "unicode/ustring.h"
26 #define NEW_MAX_BUFFER 999
29 #define nct_min(x,y) ((x<y) ? x : y)
31 static int32_t gInBufferSize
= 0;
32 static int32_t gOutBufferSize
= 0;
33 static char gNuConvTestName
[1024];
35 static UConverter
*my_ucnv_open(const char *cnv
, UErrorCode
*err
)
37 if(cnv
&& cnv
[0] == '@') {
38 return ucnv_openPackage("testdata", cnv
+1, err
);
40 return ucnv_open(cnv
, err
);
45 static void printSeq(const unsigned char* a
, int len
)
50 log_verbose("0x%02x ", a
[i
++]);
54 static void printUSeq(const UChar
* a
, int len
)
59 log_verbose("0x%04x ", a
[i
++]);
63 static void printSeqErr(const unsigned char* a
, int len
)
68 fprintf(stderr
, "0x%02x ", a
[i
++]);
69 fprintf(stderr
, "}\n");
72 static void printUSeqErr(const UChar
* a
, int len
)
75 fprintf(stderr
, "{U+");
77 fprintf(stderr
, "0x%04x ", a
[i
++]);
78 fprintf(stderr
,"}\n");
81 static void TestConverterFallBack(void)
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
);
102 void addTestConverterFallBack(TestNode
** root
);
104 void addTestConverterFallBack(TestNode
** root
)
106 addTest(root
, &TestConverterFallBack
, "tsconv/ncnvfbts/TestConverterFallBack");
111 /* Note that this test already makes use of statics, so it's not really
113 This convenience function lets us make the error messages actually useful.
116 static void setNuConvTestName(const char *codepage
, const char *direction
)
118 sprintf(gNuConvTestName
, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
122 (int)gOutBufferSize
);
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
)
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 */
140 int32_t realBufferSize
;
141 uint8_t *realBufferEnd
;
142 const UChar
*realSourceEnd
;
143 const UChar
*sourceLimit
;
144 UBool checkOffsets
= TRUE
;
150 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
152 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
154 setNuConvTestName(codepage
, "FROM");
156 log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage
, gInBufferSize
,
159 conv
= my_ucnv_open(codepage
, &status
);
160 if(U_FAILURE(status
))
162 log_data_err("Couldn't open converter %s\n",codepage
);
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
));
173 /*------------------------*/
178 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
179 realBufferEnd
= junkout
+ realBufferSize
;
180 realSourceEnd
= source
+ sourceLen
;
182 if ( gOutBufferSize
!= realBufferSize
)
183 checkOffsets
= FALSE
;
185 if( gInBufferSize
!= NEW_MAX_BUFFER
)
186 checkOffsets
= FALSE
;
190 end
= nct_min(targ
+ gOutBufferSize
, realBufferEnd
);
191 sourceLimit
= nct_min(src
+ gInBufferSize
, realSourceEnd
);
193 doFlush
= (UBool
)(sourceLimit
== realSourceEnd
);
195 if(targ
== realBufferEnd
)
197 log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ
, gNuConvTestName
);
200 log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src
,sourceLimit
, targ
,end
, doFlush
?"TRUE":"FALSE");
203 status
= U_ZERO_ERROR
;
205 ucnv_fromUnicode (conv
,
210 checkOffsets
? offs
: NULL
,
211 doFlush
, /* flush if we're at the end of the input data */
214 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (sourceLimit
< realSourceEnd
) );
216 if(U_FAILURE(status
))
218 log_err("Problem doing toUnicode, errcode %d %s\n", myErrorName(status
), gNuConvTestName
);
222 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
223 sourceLen
, targ
-junkout
);
227 char offset_str
[9999];
231 for(p
= junkout
;p
<targ
;p
++)
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
]);
238 printSeq((const unsigned char*)expect
, expectLen
);
241 log_verbose("\nOffsets:");
242 log_verbose(offset_str
);
249 if(expectLen
!= targ
-junkout
)
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
);
258 if (checkOffsets
&& (expectOffsets
!= 0) )
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
);
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
]);
273 log_verbose("\n\ncomparing..\n");
274 if(!memcmp(junkout
, expect
, expectLen
))
276 log_verbose("Matches!\n");
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
);
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
)
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 */
297 const uint8_t *realSourceEnd
;
298 const uint8_t *srcLimit
;
303 UBool checkOffsets
= TRUE
;
305 char offset_str
[9999];
309 int32_t realBufferSize
;
310 UChar
*realBufferEnd
;
313 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
316 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
319 setNuConvTestName(codepage
, "TO");
321 log_verbose("\n========= %s\n", gNuConvTestName
);
323 conv
= my_ucnv_open(codepage
, &status
);
324 if(U_FAILURE(status
))
326 log_data_err("Couldn't open converter %s\n",gNuConvTestName
);
327 return TRUE
; /* because it has been logged */
330 log_verbose("Converter opened..\n");
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
));
345 /*-------------------------------------*/
346 if ( gOutBufferSize
!= realBufferSize
)
347 checkOffsets
= FALSE
;
349 if( gInBufferSize
!= NEW_MAX_BUFFER
)
350 checkOffsets
= FALSE
;
354 end
= nct_min( targ
+ gOutBufferSize
, realBufferEnd
);
355 srcLimit
= nct_min(realSourceEnd
, src
+ gInBufferSize
);
357 if(targ
== realBufferEnd
)
359 log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ
,gNuConvTestName
);
362 log_verbose("calling toUnicode @ %08lx to %08lx\n", targ
,end
);
366 status
= U_ZERO_ERROR
;
368 ucnv_toUnicode (conv
,
372 (const char *)srcLimit
,
373 checkOffsets
? offs
: NULL
,
374 (UBool
)(srcLimit
== realSourceEnd
), /* flush if we're at the end of hte source data */
376 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (srcLimit
< realSourceEnd
) ); /* while we just need another buffer */
379 if(U_FAILURE(status
))
381 log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status
), gNuConvTestName
);
385 log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
386 sourcelen
, targ
-junkout
);
393 for(p
= junkout
;p
<targ
;p
++)
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
]);
400 printUSeq(expect
, expectlen
);
403 log_verbose("\nOffsets:");
404 log_verbose(offset_str
);
410 log_verbose("comparing %d uchars (%d bytes)..\n",expectlen
,expectlen
*2);
412 if (checkOffsets
&& (expectOffsets
!= 0))
414 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t)))
416 log_err("\n\ndid not get the expected offsets while %s \n", gNuConvTestName
);
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
]);
424 for(i
=0; i
<(targ
-junkout
); i
++)
425 log_err("0x%04X,", junkout
[i
]);
427 for(i
=0; i
<(src
-source
); i
++)
428 log_err("0x%04X,", (unsigned char)source
[i
]);
432 if(!memcmp(junkout
, expect
, expectlen
*2))
434 log_verbose("Matches!\n");
439 log_err("String does not match. %s\n", gNuConvTestName
);
440 log_verbose("String does not match. %s\n", gNuConvTestName
);
441 printUSeqErr(junkout
, expectlen
);
443 printUSeqErr(expect
, expectlen
);
450 static void TestConvertFallBackWithBufferSizes(int32_t outsize
, int32_t insize
)
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};
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
[] =
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
[] =
490 static const UChar MBCSText1363
[] =
500 static const uint8_t expectedIBM1363
[] =
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};
519 static const char* nativeCodePage
[]={
539 gInBufferSize
= insize
;
540 gOutBufferSize
= outsize
;
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
]);
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
]);
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");
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");
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");
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");
572 /*commented untill data table is available*/
573 log_verbose("toUnicode fallback with fallback data for MBCS\n");
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};
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");
591 log_verbose("toUnicode fallback with fallback data for euc-tw\n");
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};
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");
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");
612 log_verbose("fromUnicode to euc-tw with fallback data euc-tw\n");
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};
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");
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");
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");
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.*/
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};
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};
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");
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");
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.*/
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};
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};
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");
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");
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.*/
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};
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,};
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");
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");
729 /* Test for jitterbug 509 EBCDIC_STATEFUL Converters*/
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 };
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");
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");