From 994d196cbb31e6c0a4fa958fc4f72ebb8711f498 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 15 Dec 2000 19:16:43 +0000 Subject: [PATCH] ICU-432 Fixed a very odd leak with cloctest, cucdtst and crestst X-SVN-Rev: 3245 --- icu4c/source/test/cintltst/cintltst.c | 55 +++--- icu4c/source/test/cintltst/cloctst.c | 238 ++++++++++++-------------- icu4c/source/test/cintltst/cloctst.h | 8 +- icu4c/source/test/cintltst/crestst.c | 38 ++-- icu4c/source/test/cintltst/crestst.h | 13 +- icu4c/source/test/cintltst/cucdtst.c | 187 ++++++++++---------- icu4c/source/test/cintltst/cucdtst.h | 4 +- 7 files changed, 258 insertions(+), 285 deletions(-) diff --git a/icu4c/source/test/cintltst/cintltst.c b/icu4c/source/test/cintltst/cintltst.c index 16c93b91471..4bf143b3cde 100644 --- a/icu4c/source/test/cintltst/cintltst.c +++ b/icu4c/source/test/cintltst/cintltst.c @@ -8,7 +8,7 @@ * File CINTLTST.C * * Modification History: -* Name Description +* Name Description * Madhu Katragadda Creation ********************************************************************************* */ @@ -21,9 +21,6 @@ #include "unicode/utypes.h" #include "cintltst.h" -U_CDECL_BEGIN -#include "cucdtst.h" -U_CDECL_END #include "unicode/uchar.h" #include "unicode/ustring.h" @@ -95,7 +92,6 @@ int main(int argc, const char* const argv[]) addAllTests(&root); nerrors = processArgs(root, argc, argv); cleanUpTestTree(root); - cleanUpDataTable(); #ifdef CTST_LEAK_CHECK ctst_freeAll(); @@ -112,35 +108,30 @@ int main(int argc, const char* const argv[]) void ctest_pathnameInContext( char* fullname, int32_t maxsize, const char* relPath ) { - char mainDirBuffer[200]; + char mainDirBuffer[1024]; char* mainDir = NULL; + const char *dataDirectory = u_getDataDirectory(); const char inpSepChar = '|'; char* tmp; int32_t lenMainDir; - int32_t lenRelPath ; + int32_t lenRelPath; -#if defined(_WIN32) || defined(WIN32) || defined(__OS2__) || defined(OS2) - /* This should always be u_getDataDirectory(). - */ - mainDir= u_getDataDirectory(); - if(mainDir!=NULL) { - strcpy(mainDirBuffer, mainDir); - strcat(mainDirBuffer, ".."); - } else { - mainDirBuffer[0]='\0'; - } - mainDir=mainDirBuffer; -#elif defined(XP_MAC) - Str255 volName; - int16_t volNum; - OSErr err = GetVol( volName, &volNum ); - if (err != noErr) volName[0] = 0; - mainDir = (char*) &(volName[1]); - mainDir[volName[0]] = 0; +#ifdef XP_MAC + Str255 volName; + int16_t volNum; + OSErr err = GetVol( volName, &volNum ); + if (err != noErr) + volName[0] = 0; + mainDir = (char*) &(volName[1]); + mainDir[volName[0]] = 0; #else - strcpy(mainDirBuffer, u_getDataDirectory()); + if (dataDirectory != NULL) { + strcpy(mainDirBuffer, dataDirectory); strcat(mainDirBuffer, ".." U_FILE_SEP_STRING); - mainDir = mainDirBuffer; + } else { + mainDirBuffer[0]='\0'; + } + mainDir = mainDirBuffer; #endif lenMainDir = strlen( mainDir ); @@ -149,9 +140,13 @@ ctest_pathnameInContext( char* fullname, int32_t maxsize, const char* relPath ) mainDir[lenMainDir] = 0; } - if (relPath[0] == '|') relPath++; + if (relPath[0] == '|') + relPath++; lenRelPath = strlen( relPath ); - if (maxsize < lenMainDir + lenRelPath + 2) { fullname[0] = 0; return; } + if (maxsize < lenMainDir + lenRelPath + 2) { + fullname[0] = 0; + return; + } strcpy( fullname, mainDir ); /*strcat( fullname, U_FILE_SEP_STRING );*/ strcat( fullname, relPath ); @@ -193,7 +188,7 @@ char *austrdup(const UChar* unichars) length = u_strlen ( unichars ); /*newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */ newString = (char*)ctst_malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */ - + if ( newString == NULL ) return NULL; diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index bf62b40a768..970ab82242d 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -28,9 +28,10 @@ void PrintDataTable(); /*--------------------------------------------------- table of valid data --------------------------------------------------- */ +#define LOCALE_SIZE 5 +#define LOCALE_INFO_SIZE 23 - -static const char* rawData2[23][5] = { +static const char* rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = { /* language code */ { "en", "fr", "hr", "el", "no" }, /* country code */ @@ -65,22 +66,22 @@ static const char* rawData2[23][5] = { { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "croate (Croatie)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, Nynorsk)" }, /* display langage (Croatian) */ - { "", "", "hrvatski", "", "" }, - /* display country (Croatian) */ - { "", "", "Hrvatska", "", "" }, + { "", "", "hrvatski", "", "" }, + /* display country (Croatian) */ + { "", "", "Hrvatska", "", "" }, /* display variant (Croatian) */ - { "", "", "", "", "" }, + { "", "", "", "", "" }, /* display name (Croatian) */ { "", "", "hrvatski (Hrvatska)", "", "" }, - /* display langage (Greek) [actual values listed below] */ - { "", "", "", "", "" }, - /* display country (Greek) [actual values listed below] */ - { "", "", "", "", "" }, + /* display langage (Greek) */ + { "", "", "", "\\u03b5\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac", "" }, + /* display country (Greek) */ + { "", "", "", "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1", "" }, /* display variant (Greek) */ - { "", "", "", "", "" }, - /* display name (Greek) [actual values listed below] */ - { "", "", "", "", "" } + { "", "", "", "", "" }, + /* display name (Greek) */ + { "", "", "", "\\u03b5\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)", "" } }; static UChar*** dataTable=0; @@ -122,8 +123,6 @@ enum { void addLocaleTest(TestNode** root) { - setUpDataTable(); - addTest(root, &TestBasicGetters, "tsutil/cloctst/TestBasicGetters"); addTest(root, &TestSimpleResourceInfo, "tsutil/cloctst/TestSimpleResourceInfo"); addTest(root, &TestDisplayNames, "tsutil/cloctst/TestDisplayNames"); @@ -134,9 +133,8 @@ void addLocaleTest(TestNode** root) addTest(root, &TestUninstalledISO3Names, "tsutil/cloctst/TestUninstalledISO3Names"); addTest(root, &TestSimpleDisplayNames, "tsutil/cloctst/TestSimpleDisplayNames"); addTest(root, &TestVariantParsing, "tsutil/cloctst/TestVariantParsing"); - } - + /* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_getCountry() */ static void TestBasicGetters() { @@ -189,12 +187,9 @@ static void TestBasicGetters() { log_err("ERROR: in uloc_getVariant %s\n", myErrorName(status)); } if (0 != strcmp(temp, rawData2[VAR][i])) { - log_err("Variant code mismatch: %s versus %s\n", temp, rawData2[VAR][i]); - - } - - + } + cap=uloc_getName(testLocale, NULL, 0, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; @@ -212,14 +207,12 @@ static void TestBasicGetters() { free(temp); free(name); - free(testLocale); + free(testLocale); } - } /* testing uloc_getISO3Language(), uloc_getISO3Country(), */ static void TestSimpleResourceInfo() { - int32_t i; char* testLocale = 0; UChar* expected = 0; @@ -229,38 +222,40 @@ static void TestSimpleResourceInfo() { testLocale=(char*)malloc(sizeof(char) * 1); expected=(UChar*)malloc(sizeof(UChar) * 1); +setUpDataTable(); log_verbose("Testing getISO3Language and getISO3Country\n"); for (i = 0; i <= MAX_LOCALES; i++) { - + testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1)); u_austrcpy(testLocale, dataTable[NAME][i]); - + log_verbose("Testing %s ......\n", testLocale); - + temp=uloc_getISO3Language(testLocale); expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1)); u_uastrcpy(expected,temp); if (0 != u_strcmp(expected, dataTable[LANG3][i])) { log_err(" ISO-3 language code mismatch: %s versus %s\n", austrdup(expected), austrdup(dataTable[LANG3][i])); - } - + } + temp=uloc_getISO3Country(testLocale); expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1)); u_uastrcpy(expected,temp); if (0 != u_strcmp(expected, dataTable[CTRY3][i])) { log_err(" ISO-3 Country code mismatch: %s versus %s\n", austrdup(expected), austrdup(dataTable[CTRY3][i])); - } + } sprintf(temp2, "%x", uloc_getLCID(testLocale)); if (strcmp(temp2, rawData2[LCID][i]) != 0) { log_err("LCID mismatch: %ld versus %s\n", (int32_t)uloc_getLCID(testLocale) , rawData2[LCID][i]); } - + } - + free(expected); free(testLocale); +cleanUpDataTable(); } static void TestDisplayNames() @@ -272,9 +267,9 @@ static void TestDisplayNames() */ const char *saveDefault; char *defaultLocale; - + UErrorCode err = U_ZERO_ERROR; - + saveDefault = uloc_getDefault(); defaultLocale = (char*) malloc(strlen(saveDefault) + 1); @@ -289,11 +284,11 @@ static void TestDisplayNames() log_err("uloc_setDefault returned error code "); return; } - - + + log_verbose("Testing getDisplayName for different locales\n"); log_verbose("With default = en_US...\n"); - + log_verbose(" In default locale...\n"); doTestDisplayNames(" ", DLANG_EN, FALSE); log_verbose(" In locale = en_US...\n"); @@ -310,9 +305,9 @@ static void TestDisplayNames() log_err("Locale::setDefault returned error code %s\n", myErrorName(err)); return; } - + log_verbose("With default = fr_FR...\n"); - + log_verbose(" In default locale...\n"); doTestDisplayNames(" ", DLANG_FR, TRUE); log_verbose(" In locale = en_US...\n"); @@ -341,23 +336,22 @@ static void TestGetAvailableLocales() const char *locList; int32_t locCount,i; - + log_verbose("Testing the no of avialable locales\n"); locCount=uloc_countAvailable(); if (locCount == 0) log_err("countAvailable() returned an empty list!\n"); - + /* use something sensible w/o hardcoding the count */ else if(locCount < 0){ log_err("countAvailable() returned a wrong value!= %d\n", locCount); } else{ log_info("Number of locales returned = %d\n", locCount); - } for(i=0;i