From 7a91fe3d9ad0eb0b84a9c554c95bcefc8fa6a635 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 14 May 2004 22:06:34 +0000 Subject: [PATCH] ICU-3546 TestFlushCache doesn't need internal API for testing anymore, but TestDefaultConverterError does need internal API for testing. X-SVN-Rev: 15317 --- icu4c/source/test/cintltst/ccapitst.c | 79 ++++++++++++++++++++++++++- icu4c/source/test/cintltst/cctest.c | 79 +++++---------------------- 2 files changed, 90 insertions(+), 68 deletions(-) diff --git a/icu4c/source/test/cintltst/ccapitst.c b/icu4c/source/test/cintltst/ccapitst.c index 624550e833..8622e1e611 100644 --- a/icu4c/source/test/cintltst/ccapitst.c +++ b/icu4c/source/test/cintltst/ccapitst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * Copyright (c) 1997-2004, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -94,7 +94,7 @@ cnv_open(const char *name, UErrorCode *pErrorCode) { static void ListNames(void); - void TestFlushCache(void); /* defined in cctest.c */ +static void TestFlushCache(void); static void TestDuplicateAlias(void); static void TestCCSID(void); static void TestJ932(void); @@ -104,6 +104,7 @@ static void TestConvertSafeCloneCallback(void); static void TestEBCDICSwapLFNL(void); static void TestConvertEx(void); static void TestConvertAlgorithmic(void); + void TestDefaultConverterError(void); /* defined in cctest.c */ void addTestConvert(TestNode** root); @@ -123,6 +124,7 @@ void addTestConvert(TestNode** root) addTest(root, &TestEBCDICSwapLFNL, "tsconv/ccapitst/TestEBCDICSwapLFNL"); addTest(root, &TestConvertEx, "tsconv/ccapitst/TestConvertEx"); addTest(root, &TestConvertAlgorithmic, "tsconv/ccapitst/TestConvertAlgorithmic"); + addTest(root, &TestDefaultConverterError, "tsconv/ccapitst/TestDefaultConverterError"); } static void ListNames(void) { @@ -1059,6 +1061,79 @@ static UConverterToUCallback otherCharAction(UConverterToUCallback MIA) return (MIA==(UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP)?(UConverterToUCallback)UCNV_TO_U_CALLBACK_SUBSTITUTE:(UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP; } +static void TestFlushCache(void) { + UErrorCode err = U_ZERO_ERROR; + UConverter* someConverters[5]; + int flushCount = 0; + + /* flush the converter cache to get a consistent state before the flushing is tested */ + ucnv_flushCache(); + + /*Testing ucnv_open()*/ + /* Note: These converters have been chosen because they do NOT + encode the Latin characters (U+0041, ...), and therefore are + highly unlikely to be chosen as system default codepages */ + + someConverters[0] = ucnv_open("ibm-1047", &err); + if (U_FAILURE(err)) { + log_data_err("FAILURE! %s\n", myErrorName(err)); + } + + someConverters[1] = ucnv_open("ibm-1047", &err); + if (U_FAILURE(err)) { + log_data_err("FAILURE! %s\n", myErrorName(err)); + } + + someConverters[2] = ucnv_open("ibm-1047", &err); + if (U_FAILURE(err)) { + log_data_err("FAILURE! %s\n", myErrorName(err)); + } + + someConverters[3] = ucnv_open("gb18030", &err); + if (U_FAILURE(err)) { + log_data_err("FAILURE! %s\n", myErrorName(err)); + } + + someConverters[4] = ucnv_open("ibm-954", &err); + if (U_FAILURE(err)) { + log_data_err("FAILURE! %s\n", myErrorName(err)); + } + + + /* Testing ucnv_flushCache() */ + log_verbose("\n---Testing ucnv_flushCache...\n"); + if ((flushCount=ucnv_flushCache())==0) + log_verbose("Flush cache ok\n"); + else + log_data_err("Flush Cache failed [line %d], expect 0 got %d \n", __LINE__, flushCount); + + /*testing ucnv_close() and ucnv_flushCache() */ + ucnv_close(someConverters[0]); + ucnv_close(someConverters[1]); + + if ((flushCount=ucnv_flushCache())==0) + log_verbose("Flush cache ok\n"); + else + log_data_err("Flush Cache failed [line %d], expect 0 got %d \n", __LINE__, flushCount); + + ucnv_close(someConverters[2]); + ucnv_close(someConverters[3]); + + if ((flushCount=ucnv_flushCache())==2) + log_verbose("Flush cache ok\n"); /*because first, second and third are same */ + else + log_data_err("Flush Cache failed line %d, got %d expected 2 or there is an error in ucnv_close()\n", + __LINE__, + flushCount); + + ucnv_close(someConverters[4]); + if ( (flushCount=ucnv_flushCache())==1) + log_verbose("Flush cache ok\n"); + else + log_data_err("Flush Cache failed line %d, expected 1 got %d \n", __LINE__, flushCount); + +} + /** * Test the converter alias API, specifically the fuzzy matching of * alias names and the alias table integrity. Make sure each diff --git a/icu4c/source/test/cintltst/cctest.c b/icu4c/source/test/cintltst/cctest.c index 2448317b2d..fb4d607bdd 100644 --- a/icu4c/source/test/cintltst/cctest.c +++ b/icu4c/source/test/cintltst/cctest.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * Copyright (c) 1997-2004, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -9,80 +9,27 @@ #include "cintltst.h" #include "ustr_imp.h" -void TestFlushCache(void); /* keep gcc happy */ +void TestDefaultConverterError(void); /* keep gcc happy */ -void TestFlushCache(void) { +/* This makes sure that a converter isn't leaked when an error is passed to + u_getDefaultConverter */ +void TestDefaultConverterError(void) { UErrorCode err = U_ZERO_ERROR; - UConverter* someConverters[5]; - int flushCount = 0; - /* flush the converter cache to get a consistent state before the flushing is tested */ - ucnv_flushCache(); + /* Remove the default converter */ + ucnv_close(u_getDefaultConverter(&err)); - /*Testing ucnv_open()*/ - /* Note: These converters have been chosen because they do NOT - encode the Latin characters (U+0041, ...), and therefore are - highly unlikely to be chosen as system default codepages */ - - someConverters[0] = ucnv_open("ibm-1047", &err); if (U_FAILURE(err)) { - log_data_err("FAILURE! %s\n", myErrorName(err)); + log_err("Didn't expect a failure yet %s\n", myErrorName(err)); + return; } - someConverters[1] = ucnv_open("ibm-1047", &err); - if (U_FAILURE(err)) { - log_data_err("FAILURE! %s\n", myErrorName(err)); + /* Set to any radom error state */ + err = U_FILE_ACCESS_ERROR; + if (u_getDefaultConverter(&err) != NULL) { + log_err("Didn't expect to get a converter on a failure\n"); } - - someConverters[2] = ucnv_open("ibm-1047", &err); - if (U_FAILURE(err)) { - log_data_err("FAILURE! %s\n", myErrorName(err)); - } - - someConverters[3] = ucnv_open("gb18030", &err); - if (U_FAILURE(err)) { - log_data_err("FAILURE! %s\n", myErrorName(err)); - } - - someConverters[4] = ucnv_open("ibm-954", &err); - if (U_FAILURE(err)) { - log_data_err("FAILURE! %s\n", myErrorName(err)); - } - - - /* Testing ucnv_flushCache() */ - log_verbose("\n---Testing ucnv_flushCache...\n"); - if ((flushCount=ucnv_flushCache())==0) - log_verbose("Flush cache ok\n"); - else - log_data_err("Flush Cache failed [line %d], expect 0 got %d \n", __LINE__, flushCount); - - /*testing ucnv_close() and ucnv_flushCache() */ - ucnv_close(someConverters[0]); - ucnv_close(someConverters[1]); - - if ((flushCount=ucnv_flushCache())==0) - log_verbose("Flush cache ok\n"); - else - log_data_err("Flush Cache failed [line %d], expect 0 got %d \n", __LINE__, flushCount); - - ucnv_close(someConverters[2]); - ucnv_close(someConverters[3]); - - if ((flushCount=ucnv_flushCache())==2) - log_verbose("Flush cache ok\n"); /*because first, second and third are same */ - else - log_data_err("Flush Cache failed line %d, got %d expected 2 or there is an error in ucnv_close()\n", - __LINE__, - flushCount); - - ucnv_close(someConverters[4]); - if ( (flushCount=ucnv_flushCache())==1) - log_verbose("Flush cache ok\n"); - else - log_data_err("Flush Cache failed line %d, expected 1 got %d \n", __LINE__, flushCount); - }