From 6c106f7b4b2ee5be777d61e96dabb84ca7afded9 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 17 Jul 2002 02:41:04 +0000 Subject: [PATCH] ICU-1991 ucnv_openPackage X-SVN-Rev: 9221 --- icu4c/source/test/cintltst/ncnvfbts.c | 26 ++++++++++++----- icu4c/source/test/cintltst/nucnvtst.c | 42 ++++++++++++++++++++------- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/icu4c/source/test/cintltst/ncnvfbts.c b/icu4c/source/test/cintltst/ncnvfbts.c index dbae5ac861a..6ad6c0855c8 100644 --- a/icu4c/source/test/cintltst/ncnvfbts.c +++ b/icu4c/source/test/cintltst/ncnvfbts.c @@ -32,6 +32,16 @@ static int32_t gInBufferSize = 0; static int32_t gOutBufferSize = 0; static char gNuConvTestName[1024]; +static UConverter *my_ucnv_open(const char *cnv, UErrorCode *err) +{ + if(cnv && cnv[0] == '@') { + return ucnv_openPackage("testdata", cnv+1, err); + } else { + return ucnv_open(cnv, err); + } +} + + static void printSeq(const unsigned char* a, int len) { int i=0; @@ -146,7 +156,7 @@ static UBool testConvertFromUnicode(const UChar *source, int sourceLen, const u log_verbose("\nTesting========= %s FROM \n inputbuffer= %d outputbuffer= %d\n", codepage, gInBufferSize, gOutBufferSize); - conv = ucnv_open(codepage, &status); + conv = my_ucnv_open(codepage, &status); if(U_FAILURE(status)) { log_err("Couldn't open converter %s\n",codepage); @@ -310,7 +320,7 @@ static UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const U log_verbose("\n========= %s\n", gNuConvTestName); - conv = ucnv_open(codepage, &status); + conv = my_ucnv_open(codepage, &status); if(U_FAILURE(status)) { log_err("Couldn't open converter %s\n",gNuConvTestName); @@ -642,12 +652,12 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize ) /*from Unicode*/ if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), - expectedtest1, sizeof(expectedtest1), "test1", TRUE, totest1Offs )) + expectedtest1, sizeof(expectedtest1), "@test1", TRUE, totest1Offs )) log_err("u-> test1(MBCS conversion with single-byte) did not match.\n"); /*to Unicode*/ if(!testConvertToUnicode(test1input, sizeof(test1input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "test1", TRUE, fromtest1Offs )) + expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test1", TRUE, fromtest1Offs )) log_err("test1(MBCS conversion with single-byte) -> u did not match.\n"); } @@ -669,12 +679,12 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize ) /*from Unicode*/ if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), - expectedtest3, sizeof(expectedtest3), "test3", TRUE, totest3Offs )) + expectedtest3, sizeof(expectedtest3), "@test3", TRUE, totest3Offs )) log_err("u-> test3(MBCS conversion with three-byte) did not match.\n"); /*to Unicode*/ if(!testConvertToUnicode(test3input, sizeof(test3input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "test3", TRUE, fromtest3Offs )) + expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", TRUE, fromtest3Offs )) log_err("test3(MBCS conversion with three-byte) -> u did not match.\n"); } @@ -704,12 +714,12 @@ static void TestConvertFallBackWithBufferSizes(int32_t outsize, int32_t insize ) /*from Unicode*/ if(!testConvertFromUnicode(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), - expectedtest4, sizeof(expectedtest4), "test4", TRUE, totest4Offs )) + expectedtest4, sizeof(expectedtest4), "@test4", TRUE, totest4Offs )) log_err("u-> test4(MBCS conversion with four-byte) did not match.\n"); /*to Unicode*/ if(!testConvertToUnicode(test4input, sizeof(test4input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "test4", TRUE, fromtest4Offs )) + expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", TRUE, fromtest4Offs )) log_err("test4(MBCS conversion with four-byte) -> u did not match.\n"); } diff --git a/icu4c/source/test/cintltst/nucnvtst.c b/icu4c/source/test/cintltst/nucnvtst.c index 63eae4f04ed..b2181794852 100644 --- a/icu4c/source/test/cintltst/nucnvtst.c +++ b/icu4c/source/test/cintltst/nucnvtst.c @@ -74,6 +74,9 @@ static void TestCoverageMBCS(void); void addTestNewConvert(TestNode** root); +/* open a converter, using test data if it begins with '@' */ +static UConverter *my_ucnv_open(const char *cnv, UErrorCode *err); + #define NEW_MAX_BUFFER 999 @@ -83,6 +86,15 @@ static char gNuConvTestName[1024]; #define nct_min(x,y) ((x test1(MBCS conversion with single-byte) did not match.\n"); /*to Unicode*/ if(!testConvertToU(test1input, sizeof(test1input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "test1", fromtest1Offs ,FALSE)) + expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test1", fromtest1Offs ,FALSE)) log_err("test1(MBCS conversion with single-byte) -> u did not match.\n"); } @@ -1099,12 +1116,12 @@ static void TestCoverageMBCS(){ /*from Unicode*/ if(!testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), - expectedtest3, sizeof(expectedtest3), "test3", totest3Offs,FALSE )) + expectedtest3, sizeof(expectedtest3), "@test3", totest3Offs,FALSE )) log_err("u-> test3(MBCS conversion with three-byte) did not match.\n"); /*to Unicode*/ if(!testConvertToU(test3input, sizeof(test3input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "test3", fromtest3Offs ,FALSE)) + expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test3", fromtest3Offs ,FALSE)) log_err("test3(MBCS conversion with three-byte) -> u did not match.\n"); } @@ -1124,20 +1141,22 @@ static void TestCoverageMBCS(){ /*from Unicode*/ if(!testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]), - expectedtest4, sizeof(expectedtest4), "test4", totest4Offs,FALSE )) + expectedtest4, sizeof(expectedtest4), "@test4", totest4Offs,FALSE )) log_err("u-> test4(MBCS conversion with four-byte) did not match.\n"); /*to Unicode*/ if(!testConvertToU(test4input, sizeof(test4input), - expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "test4", fromtest4Offs,FALSE )) + expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test4", fromtest4Offs,FALSE )) log_err("test4(MBCS conversion with four-byte) -> u did not match.\n"); } +#if 0 uprv_free(tdpath); /* restore the original data directory */ log_verbose("Setting the data directory to %s \n", saveDirectory); u_setDataDirectory(saveDirectory); uprv_free(saveDirectory); +#endif } @@ -1145,7 +1164,8 @@ static void TestConverterType(const char *convName, UConverterType convType) { UConverter* myConverter; UErrorCode err = U_ZERO_ERROR; - myConverter = ucnv_open(convName, &err); + myConverter = my_ucnv_open(convName, &err); + if (U_FAILURE(err)) { log_err("Failed to create an %s converter\n", convName); return; @@ -2639,7 +2659,7 @@ static int TestJitterbug930(const char* enc){ int32_t* offsets = off; int numOffWritten=0; UBool flush = 0; - converter = ucnv_open(enc, &err); /* "",&err);*/ + converter = my_ucnv_open(enc, &err); in[0] = 0x41; /* 0x4E00;*/ in[1] = 0x4E01; @@ -3011,7 +3031,7 @@ static void TestConv(const uint16_t in[],int len, const char* conv, const char* UConverter *cnv; int32_t* offsets = (int32_t*) malloc(uBufSize * sizeof(int32_t) ); int32_t* myOff= offsets; - cnv=ucnv_open(conv, &errorCode); + cnv=my_ucnv_open(conv, &errorCode); if(U_FAILURE(errorCode)) { log_err("Unable to open a %s converter: %s\n", conv, u_errorName(errorCode)); return;