1 /********************************************************************
3 * Copyright (c) 1997-2007, 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 #if !UCONFIG_NO_LEGACY_CONVERSION
27 #define NEW_MAX_BUFFER 999
30 #define nct_min(x,y) ((x<y) ? x : y)
32 static int32_t gInBufferSize
= 0;
33 static int32_t gOutBufferSize
= 0;
34 static char gNuConvTestName
[1024];
36 static UConverter
*my_ucnv_open(const char *cnv
, UErrorCode
*err
)
38 if(cnv
&& cnv
[0] == '@') {
39 return ucnv_openPackage("testdata", cnv
+1, err
);
41 return ucnv_open(cnv
, err
);
46 static void printSeq(const unsigned char* a
, int len
)
51 log_verbose("0x%02x ", a
[i
++]);
55 static void printUSeq(const UChar
* a
, int len
)
60 log_verbose("0x%04x ", a
[i
++]);
64 static void printSeqErr(const unsigned char* a
, int len
)
69 fprintf(stderr
, "0x%02x ", a
[i
++]);
70 fprintf(stderr
, "}\n");
73 static void printUSeqErr(const UChar
* a
, int len
)
76 fprintf(stderr
, "{U+");
78 fprintf(stderr
, "0x%04x ", a
[i
++]);
79 fprintf(stderr
,"}\n");
82 static void TestConverterFallBack(void)
84 TestConvertFallBackWithBufferSizes(10,10);
85 TestConvertFallBackWithBufferSizes(2,3);
86 TestConvertFallBackWithBufferSizes(3,2);
87 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,1);
88 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,2);
89 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,3);
90 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,4);
91 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,5);
92 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,6);
93 TestConvertFallBackWithBufferSizes(1,NEW_MAX_BUFFER
);
94 TestConvertFallBackWithBufferSizes(2,NEW_MAX_BUFFER
);
95 TestConvertFallBackWithBufferSizes(3,NEW_MAX_BUFFER
);
96 TestConvertFallBackWithBufferSizes(4,NEW_MAX_BUFFER
);
97 TestConvertFallBackWithBufferSizes(5,NEW_MAX_BUFFER
);
98 TestConvertFallBackWithBufferSizes(NEW_MAX_BUFFER
,NEW_MAX_BUFFER
);
103 void addTestConverterFallBack(TestNode
** root
);
105 void addTestConverterFallBack(TestNode
** root
)
107 addTest(root
, &TestConverterFallBack
, "tsconv/ncnvfbts/TestConverterFallBack");
112 /* Note that this test already makes use of statics, so it's not really
114 This convenience function lets us make the error messages actually useful.
117 static void setNuConvTestName(const char *codepage
, const char *direction
)
119 sprintf(gNuConvTestName
, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
123 (int)gOutBufferSize
);
127 static UBool
testConvertFromUnicode(const UChar
*source
, int sourceLen
, const uint8_t *expect
, int expectLen
,
128 const char *codepage
, UBool fallback
, const int32_t *expectOffsets
)
132 UErrorCode status
= U_ZERO_ERROR
;
133 UConverter
*conv
= 0;
134 char junkout
[NEW_MAX_BUFFER
]; /* FIX */
135 int32_t junokout
[NEW_MAX_BUFFER
]; /* FIX */
141 int32_t realBufferSize
;
143 const UChar
*realSourceEnd
;
144 const UChar
*sourceLimit
;
145 UBool checkOffsets
= TRUE
;
151 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
152 junkout
[i
] = (char)0xF0;
153 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
155 setNuConvTestName(codepage
, "FROM");
157 log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage
, gInBufferSize
,
160 conv
= my_ucnv_open(codepage
, &status
);
161 if(U_FAILURE(status
))
163 log_data_err("Couldn't open converter %s\n",codepage
);
167 log_verbose("Converter opened..\n");
168 /*----setting the callback routine----*/
169 ucnv_setFallback (conv
, fallback
);
170 action
= ucnv_usesFallback(conv
);
171 if(action
!= fallback
){
172 log_err("FAIL: Error is setting fallback. Errocode=%s\n", myErrorName(status
));
174 /*------------------------*/
179 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
180 realBufferEnd
= junkout
+ realBufferSize
;
181 realSourceEnd
= source
+ sourceLen
;
183 if ( gOutBufferSize
!= realBufferSize
)
184 checkOffsets
= FALSE
;
186 if( gInBufferSize
!= NEW_MAX_BUFFER
)
187 checkOffsets
= FALSE
;
191 end
= nct_min(targ
+ gOutBufferSize
, realBufferEnd
);
192 sourceLimit
= nct_min(src
+ gInBufferSize
, realSourceEnd
);
194 doFlush
= (UBool
)(sourceLimit
== realSourceEnd
);
196 if(targ
== realBufferEnd
)
198 log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ
, gNuConvTestName
);
201 log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx TARGET: %08lx to %08lx, flush=%s\n", src
,sourceLimit
, targ
,end
, doFlush
?"TRUE":"FALSE");
204 status
= U_ZERO_ERROR
;
206 ucnv_fromUnicode (conv
,
211 checkOffsets
? offs
: NULL
,
212 doFlush
, /* flush if we're at the end of the input data */
215 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (sourceLimit
< realSourceEnd
) );
217 if(U_FAILURE(status
))
219 log_err("Problem doing toUnicode, errcode %d %s\n", myErrorName(status
), gNuConvTestName
);
223 log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
224 sourceLen
, targ
-junkout
);
228 char offset_str
[9999];
232 for(p
= junkout
;p
<targ
;p
++)
234 sprintf(junk
+ uprv_strlen(junk
), "0x%02x, ", (0xFF) & (unsigned int)*p
);
235 sprintf(offset_str
+ strlen(offset_str
), "0x%02x, ", (0xFF) & (unsigned int)junokout
[p
-junkout
]);
239 printSeq((const unsigned char*)expect
, expectLen
);
242 log_verbose("\nOffsets:");
243 log_verbose(offset_str
);
250 if(expectLen
!= targ
-junkout
)
252 log_err("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
253 log_verbose("Expected %d chars out, got %d %s\n", expectLen
, targ
-junkout
, gNuConvTestName
);
254 printSeqErr((const unsigned char*)junkout
, (int32_t)(targ
-junkout
));
255 printSeqErr((const unsigned char*)expect
, expectLen
);
259 if (checkOffsets
&& (expectOffsets
!= 0) )
261 log_verbose("\ncomparing %d offsets..\n", targ
-junkout
);
262 if(uprv_memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t) )){
263 log_err("\ndid not get the expected offsets while %s \n", gNuConvTestName
);
265 printSeqErr((const unsigned char*)junkout
, (int32_t)(targ
-junkout
));
266 for(p
=junkout
;p
<targ
;p
++)
267 log_err("%d, ", junokout
[p
-junkout
]);
268 log_err("\nExpected: ");
269 for(i
=0; i
<(targ
-junkout
); i
++)
270 log_err("%d,", expectOffsets
[i
]);
274 log_verbose("\n\ncomparing..\n");
275 if(!memcmp(junkout
, expect
, expectLen
))
277 log_verbose("Matches!\n");
282 log_err("String does not match. %s\n", gNuConvTestName
);
283 log_verbose("String does not match. %s\n", gNuConvTestName
);
284 printSeqErr((const unsigned char*)junkout
, expectLen
);
285 printSeqErr((const unsigned char*)expect
, expectLen
);
290 static UBool
testConvertToUnicode( const uint8_t *source
, int sourcelen
, const UChar
*expect
, int expectlen
,
291 const char *codepage
, UBool fallback
, const int32_t *expectOffsets
)
293 UErrorCode status
= U_ZERO_ERROR
;
294 UConverter
*conv
= 0;
295 UChar junkout
[NEW_MAX_BUFFER
]; /* FIX */
296 int32_t junokout
[NEW_MAX_BUFFER
]; /* FIX */
298 const char *realSourceEnd
;
299 const char *srcLimit
;
304 UBool checkOffsets
= TRUE
;
306 char offset_str
[9999];
310 int32_t realBufferSize
;
311 UChar
*realBufferEnd
;
314 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
317 for(i
=0;i
<NEW_MAX_BUFFER
;i
++)
320 setNuConvTestName(codepage
, "TO");
322 log_verbose("\n========= %s\n", gNuConvTestName
);
324 conv
= my_ucnv_open(codepage
, &status
);
325 if(U_FAILURE(status
))
327 log_data_err("Couldn't open converter %s\n",gNuConvTestName
);
328 return TRUE
; /* because it has been logged */
331 log_verbose("Converter opened..\n");
333 src
= (const char *)source
;
337 realBufferSize
= (sizeof(junkout
)/sizeof(junkout
[0]));
338 realBufferEnd
= junkout
+ realBufferSize
;
339 realSourceEnd
= src
+ sourcelen
;
340 /*----setting the fallback routine----*/
341 ucnv_setFallback (conv
, fallback
);
342 action
= ucnv_usesFallback(conv
);
343 if(action
!= fallback
){
344 log_err("FAIL: Error is setting fallback. Errocode=%s\n", myErrorName(status
));
346 /*-------------------------------------*/
347 if ( gOutBufferSize
!= realBufferSize
)
348 checkOffsets
= FALSE
;
350 if( gInBufferSize
!= NEW_MAX_BUFFER
)
351 checkOffsets
= FALSE
;
355 end
= nct_min( targ
+ gOutBufferSize
, realBufferEnd
);
356 srcLimit
= nct_min(realSourceEnd
, src
+ gInBufferSize
);
358 if(targ
== realBufferEnd
)
360 log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ
,gNuConvTestName
);
363 log_verbose("calling toUnicode @ %08lx to %08lx\n", targ
,end
);
367 status
= U_ZERO_ERROR
;
369 ucnv_toUnicode (conv
,
373 (const char *)srcLimit
,
374 checkOffsets
? offs
: NULL
,
375 (UBool
)(srcLimit
== realSourceEnd
), /* flush if we're at the end of hte source data */
377 } while ( (status
== U_BUFFER_OVERFLOW_ERROR
) || (srcLimit
< realSourceEnd
) ); /* while we just need another buffer */
380 if(U_FAILURE(status
))
382 log_err("Problem doing toUnicode, errcode %s %s\n", myErrorName(status
), gNuConvTestName
);
386 log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
387 sourcelen
, targ
-junkout
);
394 for(p
= junkout
;p
<targ
;p
++)
396 sprintf(junk
+ strlen(junk
), "0x%04x, ", (0xFFFF) & (unsigned int)*p
);
397 sprintf(offset_str
+ strlen(offset_str
), "0x%04x, ", (0xFFFF) & (unsigned int)junokout
[p
-junkout
]);
401 printUSeq(expect
, expectlen
);
404 log_verbose("\nOffsets:");
405 log_verbose(offset_str
);
411 log_verbose("comparing %d uchars (%d bytes)..\n",expectlen
,expectlen
*2);
413 if (checkOffsets
&& (expectOffsets
!= 0))
415 if(memcmp(junokout
,expectOffsets
,(targ
-junkout
) * sizeof(int32_t)))
417 log_err("\n\ndid not get the expected offsets while %s \n", gNuConvTestName
);
419 for(p
=junkout
;p
<targ
;p
++)
420 log_err("%d, ", junokout
[p
-junkout
]);
421 log_err("\nExpected: ");
422 for(i
=0; i
<(targ
-junkout
); i
++)
423 log_err("%d,", expectOffsets
[i
]);
425 for(i
=0; i
<(targ
-junkout
); i
++)
426 log_err("0x%04X,", junkout
[i
]);
428 for(i
=0; i
<(src
-(const char *)source
); i
++)
429 log_err("0x%04X,", (unsigned char)source
[i
]);
433 if(!memcmp(junkout
, expect
, expectlen
*2))
435 log_verbose("Matches!\n");
440 log_err("String does not match. %s\n", gNuConvTestName
);
441 log_verbose("String does not match. %s\n", gNuConvTestName
);
442 printUSeqErr(junkout
, expectlen
);
444 printUSeqErr(expect
, expectlen
);
451 static void TestConvertFallBackWithBufferSizes(int32_t outsize
, int32_t insize
)
454 static const UChar SBCSText
[] =
455 { 0x0021, 0xFF01, 0x0022, 0xFF02, 0x0023, 0xFF03, 0x003A, 0xFF1A, 0x003B, 0xFF1B, 0x003C, 0xFF1C };
456 /* 21, ?, 22, ?, 23, ?, 3a, ?, 3b, ?, 3c, ? SBCS*/
457 static const uint8_t expectedNative
[] =
458 { 0x21, 0x21, 0x22, 0x22, 0x23, 0x23, 0x3a, 0x3a, 0x3b, 0x3b, 0x3c, 0x3c};
459 static const UChar retrievedSBCSText
[]=
460 { 0x0021, 0x0021, 0x0022, 0x0022, 0x0023, 0x0023, 0x003A, 0x003A, 0x003B, 0x003B, 0x003C, 0x003C };
461 static const int32_t toNativeOffs
[] =
462 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};
463 static const int32_t fromNativeoffs
[] =
464 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
467 /* 1363 isn't DBCS, but it has the DBCS section */
468 static const UChar DBCSText
[] =
469 { 0x00a1, 0x00ad, 0x2010, 0x00b7, 0x30fb};
470 static const uint8_t expectedIBM1363_DBCS
[] =
471 { 0xa2, 0xae, 0xa1 ,0xa9, 0xa1, 0xa9,0xa1 ,0xa4, 0xa1, 0xa4};
472 static const UChar retrievedDBCSText
[]=
473 { 0x00a1, 0x2010, 0x2010, 0x30fb, 0x30fb };
474 static const int32_t toIBM1363Offs_DBCS
[] =
475 { 0x00, 0x00, 0x01,0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04};
476 static const int32_t fromIBM1363offs_DBCS
[] =
480 static const UChar MBCSText
[] =
481 { 0x0001, 0x263a, 0x2013, 0x2014, 0x263b, 0x0002};
482 static const uint8_t expectedIBM950
[] =
483 { 0x01, 0x01, 0xa1, 0x56, 0xa1, 0x56, 0x02, 0x02};
484 static const UChar retrievedMBCSText
[]=
485 { 0x0001, 0x0001, 0x2014, 0x2014, 0x0002, 0x0002};
486 static const int32_t toIBM950Offs
[] =
487 { 0x00, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x05};
488 static const int32_t fromIBM950offs
[] =
491 static const UChar MBCSText1363
[] =
501 static const uint8_t expectedIBM1363
[] =
511 static const UChar retrievedMBCSText1363
[]=
512 { 0x0005, 0x0005, 0x0007, 0x0007, 0x001a, 0x30fb, 0x25a1, 0x30fb, 0x9a36};
513 static const int32_t toIBM1363Offs
[] =
514 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08};
515 static const int32_t fromIBM1363offs
[] =
516 { 0, 1, 2, 3, 4, 5, 7, 9, 11};
520 static const char* nativeCodePage
[]={
540 gInBufferSize
= insize
;
541 gOutBufferSize
= outsize
;
543 for(i
=0; i
<sizeof(nativeCodePage
)/sizeof(nativeCodePage
[0]); i
++){
544 log_verbose("Testing %s\n", nativeCodePage
[i
]);
545 if(!testConvertFromUnicode(SBCSText
, sizeof(SBCSText
)/sizeof(SBCSText
[0]),
546 expectedNative
, sizeof(expectedNative
), nativeCodePage
[i
], TRUE
, toNativeOffs
))
547 log_err("u-> %s(SBCS) with FallBack did not match.\n", nativeCodePage
[i
]);
549 if(!testConvertToUnicode(expectedNative
, sizeof(expectedNative
),
550 retrievedSBCSText
, sizeof(retrievedSBCSText
)/sizeof(retrievedSBCSText
[0]), nativeCodePage
[i
], TRUE
, fromNativeoffs
))
551 log_err("%s->u(SBCS) with Fallback did not match.\n", nativeCodePage
[i
]);
555 if(!testConvertFromUnicode(DBCSText
, sizeof(DBCSText
)/sizeof(DBCSText
[0]),
556 expectedIBM1363_DBCS
, sizeof(expectedIBM1363_DBCS
), "ibm-1363", TRUE
, toIBM1363Offs_DBCS
))
557 log_err("u-> ibm-1363(DBCS portion) with FallBack did not match.\n");
559 if(!testConvertToUnicode(expectedIBM1363_DBCS
, sizeof(expectedIBM1363_DBCS
),
560 retrievedDBCSText
, sizeof(retrievedDBCSText
)/sizeof(retrievedDBCSText
[0]),"ibm-1363", TRUE
, fromIBM1363offs_DBCS
))
561 log_err("ibm-1363->u(DBCS portion) with Fallback did not match.\n");
565 if(!testConvertFromUnicode(MBCSText
, sizeof(MBCSText
)/sizeof(MBCSText
[0]),
566 expectedIBM950
, sizeof(expectedIBM950
), "ibm-950", TRUE
, toIBM950Offs
))
567 log_err("u-> ibm-950(MBCS) with FallBack did not match.\n");
569 if(!testConvertToUnicode(expectedIBM950
, sizeof(expectedIBM950
),
570 retrievedMBCSText
, sizeof(retrievedMBCSText
)/sizeof(retrievedMBCSText
[0]),"ibm-950", TRUE
, fromIBM950offs
))
571 log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
573 /*commented untill data table is available*/
574 log_verbose("toUnicode fallback with fallback data for MBCS\n");
576 const uint8_t IBM950input
[] = {
577 0xf4, 0x87, 0xa4, 0x4a, 0xf4, 0x88, 0xa4, 0x4b,
578 0xf9, 0x92, 0xdc, 0xb0, };
579 UChar expectedUnicodeText
[]= { 0x5165, 0x5165, 0x516b, 0x516b, 0x9ef9, 0x9ef9};
580 int32_t fromIBM950inputOffs
[] = { 0, 2, 4, 6, 8, 10};
581 /* for testing reverse fallback behavior */
582 UChar expectedFallbackFalse
[]= { 0x5165, 0x5165, 0x516b, 0x516b, 0x9ef9, 0x9ef9};
584 if(!testConvertToUnicode(IBM950input
, sizeof(IBM950input
),
585 expectedUnicodeText
, sizeof(expectedUnicodeText
)/sizeof(expectedUnicodeText
[0]),"ibm-950", TRUE
, fromIBM950inputOffs
))
586 log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
587 if(!testConvertToUnicode(IBM950input
, sizeof(IBM950input
),
588 expectedFallbackFalse
, sizeof(expectedFallbackFalse
)/sizeof(expectedFallbackFalse
[0]),"ibm-950", FALSE
, fromIBM950inputOffs
))
589 log_err("ibm-950->u(MBCS) with Fallback did not match.\n");
592 log_verbose("toUnicode fallback with fallback data for euc-tw\n");
594 const uint8_t euc_tw_input
[] = {
595 0xA7, 0xCC, 0x8E, 0xA2, 0xA1, 0xAB,
596 0xA8, 0xC7, 0xC8, 0xDE,
597 0xA8, 0xCD, 0x8E, 0xA2, 0xA2, 0xEA,};
598 UChar expectedUnicodeText
[]= { 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278};
599 int32_t from_euc_tw_offs
[] = { 0, 2, 6, 8, 10, 12};
600 /* for testing reverse fallback behavior */
601 UChar expectedFallbackFalse
[]= { 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278};
603 if(!testConvertToUnicode(euc_tw_input
, sizeof(euc_tw_input
),
604 expectedUnicodeText
, sizeof(expectedUnicodeText
)/sizeof(expectedUnicodeText
[0]),"euc-tw", TRUE
, from_euc_tw_offs
))
605 log_err("from euc-tw->u with Fallback did not match.\n");
607 if(!testConvertToUnicode(euc_tw_input
, sizeof(euc_tw_input
),
608 expectedFallbackFalse
, sizeof(expectedFallbackFalse
)/sizeof(expectedFallbackFalse
[0]),"euc-tw", FALSE
, from_euc_tw_offs
))
609 log_err("from euc-tw->u with Fallback false did not match.\n");
613 log_verbose("fromUnicode to euc-tw with fallback data euc-tw\n");
615 UChar inputText
[]= { 0x0001, 0x008e, 0x203e, 0x2223, 0xff5c, 0x5296,
616 0x5C6E, 0x5C6E, 0x81FC, 0x81FC, 0x8278, 0x8278, 0xEDEC};
617 const uint8_t expected_euc_tw
[] = {
618 0x01, 0x1a, 0xa2, 0xa3,
619 0xa2, 0xde, 0xa2, 0xde,
620 0x8e, 0xa2, 0xe5, 0xb9,
621 0x8e, 0xa2, 0xa1, 0xab, 0x8e, 0xa2, 0xa1, 0xab,
622 0xc8, 0xde, 0xc8, 0xde,
623 0x8e, 0xa2, 0xa2, 0xea, 0x8e, 0xa2, 0xa2, 0xea,
624 0x8e, 0xac, 0xc6, 0xf7};
625 int32_t to_euc_tw_offs
[] = { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6,
626 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12};
628 if(!testConvertFromUnicode(inputText
, sizeof(inputText
)/sizeof(inputText
[0]),
629 expected_euc_tw
, sizeof(expected_euc_tw
), "euc-tw", TRUE
, to_euc_tw_offs
))
630 log_err("u-> euc-tw with FallBack did not match.\n");
635 if(!testConvertFromUnicode(MBCSText1363
, sizeof(MBCSText1363
)/sizeof(MBCSText1363
[0]),
636 expectedIBM1363
, sizeof(expectedIBM1363
), "ibm-1363", TRUE
, toIBM1363Offs
))
637 log_err("u-> ibm-1363(MBCS) with FallBack did not match.\n");
639 if(!testConvertToUnicode(expectedIBM1363
, sizeof(expectedIBM1363
),
640 retrievedMBCSText1363
, sizeof(retrievedMBCSText1363
)/sizeof(retrievedMBCSText1363
[0]),"ibm-1363", TRUE
, fromIBM1363offs
))
641 log_err("ibm-1363->u(MBCS) with Fallback did not match.\n");
644 /*some more test to increase the code coverage in MBCS. Create an test converter from test1.ucm
645 which is test file for MBCS conversion with single-byte codepage data.*/
648 /* MBCS with single byte codepage data test1.ucm*/
649 const UChar unicodeInput
[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xdbba, 0xdfcd, 0x0003};
650 const uint8_t expectedtest1
[] = { 0x00, 0x05, 0xff, 0x07, 0x08, 0xff,};
651 int32_t totest1Offs
[] = { 0, 1, 2, 3, 5, 7};
653 const uint8_t test1input
[] = { 0x00, 0x05, 0x06, 0x07, 0x08, 0x09};
654 const UChar expectedUnicode
[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xfffd, 0xfffd, 0xfffe};
655 int32_t fromtest1Offs
[] = { 0, 1, 2, 3, 3, 4,5};
658 if(!testConvertFromUnicode(unicodeInput
, sizeof(unicodeInput
)/sizeof(unicodeInput
[0]),
659 expectedtest1
, sizeof(expectedtest1
), "@test1", TRUE
, totest1Offs
))
660 log_err("u-> test1(MBCS conversion with single-byte) did not match.\n");
663 if(!testConvertToUnicode(test1input
, sizeof(test1input
),
664 expectedUnicode
, sizeof(expectedUnicode
)/sizeof(expectedUnicode
[0]), "@test1", TRUE
, fromtest1Offs
))
665 log_err("test1(MBCS conversion with single-byte) -> u did not match.\n");
669 /*some more test to increase the code coverage in MBCS. Create an test converter from test3.ucm
670 which is test file for MBCS conversion with three-byte codepage data.*/
673 /* MBCS with three byte codepage data test3.ucm*/
674 const UChar unicodeInput
[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xdbba, 0xdfcd, 0x000b, 0xd84d, 0xdc56, 0x000e, 0x0003, };
675 const uint8_t expectedtest3
[] = { 0x00, 0x05, 0xff, 0x07, 0xff, 0x01, 0x02, 0x0b, 0x01, 0x02, 0x0a, 0xff, 0xff,};
676 int32_t totest3Offs
[] = { 0, 1, 2, 3, 5, 7, 7, 7, 8, 8, 8, 10, 11};
678 const uint8_t test3input
[] = { 0x00, 0x05, 0x06, 0x01, 0x02, 0x0b, 0x07, 0x01, 0x02, 0x0a,
679 0x01, 0x02, 0x0e, 0x01, 0x02, 0x0d, 0x03, 0x01, 0x02, 0x0f,};
680 const UChar expectedUnicode
[] = { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xd84d, 0xdc56,
681 0x000e, 0xd891, 0xdd67, 0xfffd, 0xfffd };
682 int32_t fromtest3Offs
[] = { 0, 1, 2, 3, 6, 6, 7, 7, 10, 13, 13, 16, 17};
685 if(!testConvertFromUnicode(unicodeInput
, sizeof(unicodeInput
)/sizeof(unicodeInput
[0]),
686 expectedtest3
, sizeof(expectedtest3
), "@test3", TRUE
, totest3Offs
))
687 log_err("u-> test3(MBCS conversion with three-byte) did not match.\n");
690 if(!testConvertToUnicode(test3input
, sizeof(test3input
),
691 expectedUnicode
, sizeof(expectedUnicode
)/sizeof(expectedUnicode
[0]), "@test3", TRUE
, fromtest3Offs
))
692 log_err("test3(MBCS conversion with three-byte) -> u did not match.\n");
696 /*some more test to increase the code coverage in MBCS. Create an test converter from test4.ucm
697 which is test file for MBCS conversion with four-byte codepage data.*/
700 /* MBCS with three byte codepage data test4.ucm*/
701 const UChar unicodeInput
[] =
702 { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xdbba, 0xdfcd,
703 0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0x000f};
704 const uint8_t expectedtest4
[] =
705 { 0x00, 0x05, 0xff, 0x01, 0x02, 0x03, 0x0b, 0x07, 0xff,
706 0x01, 0x02, 0x03, 0x0a, 0xff, 0xff, 0xff};
707 int32_t totest4Offs
[] =
708 { 0, 1, 2, 3, 3, 3, 3, 4, 6, 8, 8, 8, 8, 10, 11, 13};
710 const uint8_t test4input
[] =
711 { 0x00, 0x05, 0x06, 0x01, 0x02, 0x03, 0x0b, 0x07, 0x08,
712 0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0e, 0x01, 0x02, 0x03, 0x0d, 0x03, 0x01, 0x02, 0x03, 0x0c,};
713 const UChar expectedUnicode
[] =
714 { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xdbba, 0xdfcd,
715 0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0x1a, 0xfffd};
716 int32_t fromtest4Offs
[] =
717 { 0, 1, 2, 3, 7, 7, 8, 8, 9, 9, 13, 17, 17, 21, 22,};
720 if(!testConvertFromUnicode(unicodeInput
, sizeof(unicodeInput
)/sizeof(unicodeInput
[0]),
721 expectedtest4
, sizeof(expectedtest4
), "@test4", TRUE
, totest4Offs
))
722 log_err("u-> test4(MBCS conversion with four-byte) did not match.\n");
725 if(!testConvertToUnicode(test4input
, sizeof(test4input
),
726 expectedUnicode
, sizeof(expectedUnicode
)/sizeof(expectedUnicode
[0]), "@test4", TRUE
, fromtest4Offs
))
727 log_err("test4(MBCS conversion with four-byte) -> u did not match.\n");
730 /* Test for jitterbug 509 EBCDIC_STATEFUL Converters*/
732 const UChar unicodeInput
[] = {0x00AF, 0x2013, 0x2223, 0x004C, 0x5F5D, 0xFF5E };
733 const uint8_t expectedtest1
[] = {0x0E,0x42,0xA1, 0x44,0x4A, 0x42,0x4F, 0x0F,0xD3, 0x0E,0x65,0x60, 0x43,0xA1,0x0f };
734 int32_t totest1Offs
[] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5 };
735 const uint8_t test1input
[] = {0x0E,0x42,0xA1, 0x44,0x4A, 0x42,0x4F, 0x0F,0xD3, 0x0E,0x65,0x60, 0x43,0xA1 };
736 const UChar expectedUnicode
[] = {0x203e, 0x2014, 0xff5c, 0x004c, 0x5f5e, 0x223c };
737 int32_t fromtest1Offs
[] = {1, 3, 5, 8, 10, 12 };
739 if(!testConvertFromUnicode(unicodeInput
, sizeof(unicodeInput
)/sizeof(unicodeInput
[0]),
740 expectedtest1
, sizeof(expectedtest1
), "ibm-1371", TRUE
, totest1Offs
))
741 log_err("u-> ibm-1371(MBCS conversion with single-byte) did not match.,\n");
743 if(!testConvertToUnicode(test1input
, sizeof(test1input
),
744 expectedUnicode
, sizeof(expectedUnicode
)/sizeof(expectedUnicode
[0]), "ibm-1371", TRUE
, fromtest1Offs
))
745 log_err("ibm-1371(MBCS conversion with single-byte) -> u did not match.,\n");
750 void addTestConverterFallBack(TestNode
** root
)
752 /* test nothing... */