Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1071)

Side by Side Diff: third_party/icu38/source/test/cintltst/nucnvtst.c

Issue 52030: Apply ICU patches for ICU tickets 6175 (ISO-2022 and ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2007, International Business Machines Corporation and 3 * Copyright (c) 1997-2007, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 /******************************************************************************* 6 /*******************************************************************************
7 * 7 *
8 * File CCONVTST.C 8 * File CCONVTST.C
9 * 9 *
10 * Modification History: 10 * Modification History:
11 * Name Description 11 * Name Description
12 * Steven R. Loomis 7/8/1999 Adding input buffer test 12 * Steven R. Loomis 7/8/1999 Adding input buffer test
13 ******************************************************************************** 13 ********************************************************************************
14 */ 14 */
15 #include <stdio.h> 15 #include <stdio.h>
16 #include "cstring.h" 16 #include "cstring.h"
17 #include "unicode/uloc.h" 17 #include "unicode/uloc.h"
18 #include "unicode/ucnv.h" 18 #include "unicode/ucnv.h"
19 #include "unicode/ucnv_err.h" 19 #include "unicode/ucnv_err.h"
20 #include "unicode/ucnv_cb.h"
20 #include "cintltst.h" 21 #include "cintltst.h"
21 #include "unicode/utypes.h" 22 #include "unicode/utypes.h"
22 #include "unicode/ustring.h" 23 #include "unicode/ustring.h"
23 #include "unicode/ucol.h" 24 #include "unicode/ucol.h"
24 #include "cmemory.h" 25 #include "cmemory.h"
25 26
26 static void TestNextUChar(UConverter* cnv, const char* source, const char* limit , const int32_t results[], const char* message); 27 static void TestNextUChar(UConverter* cnv, const char* source, const char* limit , const int32_t results[], const char* message);
27 static void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message); 28 static void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message);
28 #if !UCONFIG_NO_COLLATION 29 #if !UCONFIG_NO_COLLATION
29 static void TestJitterbug981(void); 30 static void TestJitterbug981(void);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 static void TestJitterbug255(void); 75 static void TestJitterbug255(void);
75 static void TestEBCDICUS4XML(void); 76 static void TestEBCDICUS4XML(void);
76 static void TestJitterbug915(void); 77 static void TestJitterbug915(void);
77 static void TestISCII(void); 78 static void TestISCII(void);
78 79
79 static void TestCoverageMBCS(void); 80 static void TestCoverageMBCS(void);
80 static void TestJitterbug2346(void); 81 static void TestJitterbug2346(void);
81 static void TestJitterbug2411(void); 82 static void TestJitterbug2411(void);
82 static void TestJB5275(void); 83 static void TestJB5275(void);
83 static void TestJB5275_1(void); 84 static void TestJB5275_1(void);
85 static void TestJitterbug6175(void);
84 #endif 86 #endif
85 87
86 static void TestRoundTrippingAllUTF(void); 88 static void TestRoundTrippingAllUTF(void);
87 static void TestConv(const uint16_t in[], 89 static void TestConv(const uint16_t in[],
88 int len, 90 int len,
89 const char* conv, 91 const char* conv,
90 const char* lang, 92 const char* lang,
91 char byteArr[], 93 char byteArr[],
92 int byteArrLen); 94 int byteArrLen);
93 void addTestNewConvert(TestNode** root); 95 void addTestNewConvert(TestNode** root);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 292
291 #if !UCONFIG_NO_LEGACY_CONVERSION 293 #if !UCONFIG_NO_LEGACY_CONVERSION
292 addTest(root, &TestCoverageMBCS, "tsconv/nucnvtst/TestCoverageMBCS"); 294 addTest(root, &TestCoverageMBCS, "tsconv/nucnvtst/TestCoverageMBCS");
293 #endif 295 #endif
294 296
295 addTest(root, &TestRoundTrippingAllUTF, "tsconv/nucnvtst/TestRoundTrippingAll UTF"); 297 addTest(root, &TestRoundTrippingAllUTF, "tsconv/nucnvtst/TestRoundTrippingAll UTF");
296 298
297 #if !UCONFIG_NO_LEGACY_CONVERSION 299 #if !UCONFIG_NO_LEGACY_CONVERSION
298 addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346"); 300 addTest(root, &TestJitterbug2346, "tsconv/nucnvtst/TestJitterbug2346");
299 addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411"); 301 addTest(root, &TestJitterbug2411, "tsconv/nucnvtst/TestJitterbug2411");
302 addTest(root, &TestJitterbug6175, "tsconv/nucnvtst/TestJitterbug6175");
300 #endif 303 #endif
301 304
302 } 305 }
303 306
304 307
305 /* Note that this test already makes use of statics, so it's not really 308 /* Note that this test already makes use of statics, so it's not really
306 multithread safe. 309 multithread safe.
307 This convenience function lets us make the error messages actually useful. 310 This convenience function lets us make the error messages actually useful.
308 */ 311 */
309 312
(...skipping 4139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4449 static const uint8_t source2[]={0x0e,0x24,0x053}; 4452 static const uint8_t source2[]={0x0e,0x24,0x053};
4450 TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeo f(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-CN]"); 4453 TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeo f(source2), U_ZERO_ERROR, "an invalid character [ISO-2022-CN]");
4451 } 4454 }
4452 4455
4453 ucnv_close(cnv); 4456 ucnv_close(cnv);
4454 free(uBuf); 4457 free(uBuf);
4455 free(cBuf); 4458 free(cBuf);
4456 free(offsets); 4459 free(offsets);
4457 } 4460 }
4458 4461
4462 /* Tests for empty segments in ISO-2022-JP/KR/CN, HZ, check that UConverterCallb ackReason is UCNV_IRREGULAR */
4463 typedef struct {
4464 const char * converterName;
4465 const char * inputText;
4466 int inputTextLength;
4467 } EmptySegmentTest;
4468
4469 /* Callback for TestJitterbug6175, should only get called for empty segment erro rs */
4470 static void UCNV_TO_U_CALLBACK_EMPTYSEGMENT( const void *context, UConverterToUn icodeArgs *toArgs, const char* codeUnits,
4471 int32_t length, UConverterCallbackR eason reason, UErrorCode * err ) {
4472 if (reason > UCNV_IRREGULAR) {
4473 return;
4474 }
4475 if (reason != UCNV_IRREGULAR) {
4476 log_err("toUnicode callback invoked for empty segment but reason is not UCNV_IRREGULAR\n");
4477 }
4478 /* Standard stuff below from UCNV_TO_U_CALLBACK_SUBSTITUTE */
4479 *err = U_ZERO_ERROR;
4480 ucnv_cbToUWriteSub(toArgs,0,err);
4481 }
4482
4483 enum { kEmptySegmentToUCharsMax = 64 };
4484 static void TestJitterbug6175(void) {
4485 static const char iso2022jp_a[] = { 0x61, 0x62, 0x1B,0x24,0x42, 0x1B,0x28,0 x42, 0x63, 0x64, 0x0D, 0x0A };
4486 static const char iso2022kr_a[] = { 0x1B,0x24,0x29,0x43, 0x61, 0x0E, 0x0F, 0x62, 0x0D, 0x0A };
4487 static const char iso2022cn_a[] = { 0x61, 0x1B,0x24,0x29,0x41, 0x62, 0x0E, 0x0F, 0x1B,0x24,0x2A,0x48, 0x1B,0x4E, 0x6A,0x65, 0x63, 0x0D, 0x0A };
4488 static const char iso2022cn_b[] = { 0x61, 0x1B,0x24,0x29,0x41, 0x62, 0x0E, 0x1B,0x24,0x29,0x47, 0x68,0x64, 0x0F, 0x63, 0x0D, 0x0A };
4489 static const char hzGB2312_a[] = { 0x61, 0x62, 0x7E,0x7B, 0x7E,0x7D, 0x63, 0x64 };
4490 static const EmptySegmentTest emptySegmentTests[] = {
4491 /* converterName inputText inputTextLength */
4492 { "ISO-2022-JP", iso2022jp_a, sizeof(iso2022jp_a) },
4493 { "ISO-2022-KR", iso2022kr_a, sizeof(iso2022kr_a) },
4494 { "ISO-2022-CN", iso2022cn_a, sizeof(iso2022cn_a) },
4495 { "ISO-2022-CN", iso2022cn_b, sizeof(iso2022cn_b) },
4496 { "HZ-GB-2312", hzGB2312_a, sizeof(hzGB2312_a) },
4497 /* terminator: */
4498 { NULL, NULL, 0, }
4499 };
4500 const EmptySegmentTest * testPtr;
4501 for (testPtr = emptySegmentTests; testPtr->converterName != NULL; ++testPtr) {
4502 UErrorCode err = U_ZERO_ERROR;
4503 UConverter * cnv = ucnv_open(testPtr->converterName, &err);
4504 if (U_FAILURE(err)) {
4505 log_data_err("Unable to open %s converter: %s\n", testPtr->converter Name, u_errorName(err));
4506 return;
4507 }
4508 ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_EMPTYSEGMENT, NULL, NULL, NU LL, &err);
4509 if (U_FAILURE(err)) {
4510 log_data_err("Unable to setToUCallBack for %s converter: %s\n", test Ptr->converterName, u_errorName(err));
4511 ucnv_close(cnv);
4512 return;
4513 }
4514 {
4515 UChar toUChars[kEmptySegmentToUCharsMax];
4516 UChar * toUCharsPtr = toUChars;
4517 const UChar * toUCharsLimit = toUCharsPtr + kEmptySegmentToUCharsMax ;
4518 const char * inCharsPtr = testPtr->inputText;
4519 const char * inCharsLimit = inCharsPtr + testPtr->inputTextLength;
4520 ucnv_toUnicode(cnv, &toUCharsPtr, toUCharsLimit, &inCharsPtr, inChar sLimit, NULL, TRUE, &err);
4521 }
4522 ucnv_close(cnv);
4523 }
4524 }
4525
4459 static void 4526 static void
4460 TestEBCDIC_STATEFUL() { 4527 TestEBCDIC_STATEFUL() {
4461 /* test input */ 4528 /* test input */
4462 static const uint8_t in[]={ 4529 static const uint8_t in[]={
4463 0x61, 4530 0x61,
4464 0x1a, 4531 0x1a,
4465 0x0f, 0x4b, 4532 0x0f, 0x4b,
4466 0x42, 4533 0x42,
4467 0x40, 4534 0x40,
4468 0x36, 4535 0x36,
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
5360 5427
5361 while(target<targetLimit){ 5428 while(target<targetLimit){
5362 if(*exp!=*target){ 5429 if(*exp!=*target){
5363 log_err("did not get the expected output. \\u%04X != \\u%04X (got)\n ", *exp, *target); 5430 log_err("did not get the expected output. \\u%04X != \\u%04X (got)\n ", *exp, *target);
5364 } 5431 }
5365 target++; 5432 target++;
5366 exp++; 5433 exp++;
5367 } 5434 }
5368 ucnv_close(conv); 5435 ucnv_close(conv);
5369 } 5436 }
OLDNEW
« no previous file with comments | « third_party/icu38/source/test/cintltst/ncnvtst.c ('k') | third_party/icu38/source/test/intltest/convtest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698