X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..1a147d096ae81f4c8262f7bfc56bd19fc2dee932:/icuSources/test/cintltst/creststn.c diff --git a/icuSources/test/cintltst/creststn.c b/icuSources/test/cintltst/creststn.c index f2cfa9cd..4fe69d7a 100644 --- a/icuSources/test/cintltst/creststn.c +++ b/icuSources/test/cintltst/creststn.c @@ -1,17 +1,19 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2006, International Business Machines Corporation and + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ -/******************************************************************************** +/******************************************************************************* * -* File CRESTST.C +* File creststn.c * * Modification History: * Name Date Description * Madhu Katragadda 05/09/2000 Ported Tests for New ResourceBundle API * Madhu Katragadda 05/24/2000 Added new tests to test RES_BINARY for collationElements -********************************************************************************* +******************************************************************************** */ @@ -21,7 +23,10 @@ #include "unicode/putil.h" #include "unicode/ustring.h" #include "unicode/ucnv.h" +#include "unicode/utf8.h" +#include "unicode/utf16.h" #include "string.h" +#include "cmemory.h" #include "cstring.h" #include "unicode/uchar.h" #include "ucol_imp.h" /* for U_ICUDATA_COLL */ @@ -29,10 +34,13 @@ #define RESTEST_HEAP_CHECK 0 #include "unicode/uloc.h" +#include "unicode/ulocdata.h" #include "uresimp.h" #include "creststn.h" #include "unicode/ctest.h" #include "ucbuf.h" +#include "ureslocs.h" + static int32_t pass; static int32_t fail; @@ -167,7 +175,8 @@ param[] = { "ne", U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } } }; -static int32_t bundles_count = sizeof(param) / sizeof(param[0]); +static int32_t bundles_count = UPRV_LENGTHOF(param); + /*static void printUChars(UChar*);*/ @@ -177,6 +186,7 @@ static void TestGetFunctionalEquivalent(void); static void TestCLDRStyleAliases(void); static void TestFallbackCodes(void); static void TestGetUTF8String(void); +static void TestCLDRVersion(void); /***************************************************************************************/ @@ -185,13 +195,10 @@ static void TestGetUTF8String(void); void addNEWResourceBundleTest(TestNode** root) { addTest(root, &TestErrorCodes, "tsutil/creststn/TestErrorCodes"); +#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION addTest(root, &TestEmptyBundle, "tsutil/creststn/TestEmptyBundle"); addTest(root, &TestConstruction1, "tsutil/creststn/TestConstruction1"); addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundles"); - addTest(root, &TestFallback, "tsutil/creststn/TestFallback"); - addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion"); - addTest(root, &TestGetVersionColl, "tsutil/creststn/TestGetVersionColl"); - addTest(root, &TestAliasConflict, "tsutil/creststn/TestAliasConflict"); addTest(root, &TestNewTypes, "tsutil/creststn/TestNewTypes"); addTest(root, &TestEmptyTypes, "tsutil/creststn/TestEmptyTypes"); addTest(root, &TestBinaryCollationData, "tsutil/creststn/TestBinaryCollationData"); @@ -200,14 +207,22 @@ void addNEWResourceBundleTest(TestNode** root) addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle"); addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing"); addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess"); + addTest(root, &TestTicket9804, "tsutil/creststn/TestTicket9804"); + addTest(root, &TestXPath, "tsutil/creststn/TestXPath"); + addTest(root, &TestCLDRStyleAliases, "tsutil/creststn/TestCLDRStyleAliases"); + addTest(root, &TestFallbackCodes, "tsutil/creststn/TestFallbackCodes"); + addTest(root, &TestGetUTF8String, "tsutil/creststn/TestGetUTF8String"); + addTest(root, &TestCLDRVersion, "tsutil/creststn/TestCLDRVersion"); + addTest(root, &TestPreventFallback, "tsutil/creststn/TestPreventFallback"); +#endif + addTest(root, &TestFallback, "tsutil/creststn/TestFallback"); + addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion"); + addTest(root, &TestGetVersionColl, "tsutil/creststn/TestGetVersionColl"); + addTest(root, &TestAliasConflict, "tsutil/creststn/TestAliasConflict"); addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues"); addTest(root, &TestGetFunctionalEquivalent,"tsutil/creststn/TestGetFunctionalEquivalent"); addTest(root, &TestJB3763, "tsutil/creststn/TestJB3763"); - addTest(root, &TestXPath, "tsutil/creststn/TestXPath"); - addTest(root, &TestCLDRStyleAliases, "tsutil/creststn/TestCLDRStyleAliases"); - addTest(root, &TestFallbackCodes, "tsutil/creststn/TestFallbackCodes"); addTest(root, &TestStackReuse, "tsutil/creststn/TestStackReuse"); - addTest(root, &TestGetUTF8String, "tsutil/creststn/TestGetUTF8String"); } @@ -237,7 +252,7 @@ static void checkStatus(int32_t line, UErrorCode expected, UErrorCode status) { log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__, line); } if(status != expected) { - log_err("%s:%d: Expected error code %s, got error code %s\n", __FILE__, line, u_errorName(expected), u_errorName(status)); + log_err_status(status, "%s:%d: Expected error code %s, got error code %s\n", __FILE__, line, u_errorName(expected), u_errorName(status)); } } @@ -252,30 +267,24 @@ static void TestErrorCodes(void) { checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); ures_close(r); - /* this bundle should return zero error, so it shouldn't change the status*/ + /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_DEFAULT_WARNING; r = ures_open(NULL, "ti_ER", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); /* we look up the resource which is aliased, but it lives in fallback */ + if(U_SUCCESS(status) && r != NULL) { - status = U_USING_DEFAULT_WARNING; - r2 = ures_getByKey(r, "Languages", NULL, &status); /* languages of 'ti' aliases to 'am' */ + status = U_USING_DEFAULT_WARNING; + r2 = ures_getByKey(r, "ExemplarCharacters", NULL, &status); /* ExemplarCharacters lives in ti */ checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); - } + } ures_close(r); - /* this bundle should return zero error, so it shouldn't change the status*/ + /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_DEFAULT_WARNING; - r = ures_open(NULL, "ti", &status); + r = ures_open(U_ICUDATA_REGION, "ti", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); - - /* we look up the resource which is aliased and at our level */ - if(U_SUCCESS(status) && r != NULL) { - status = U_USING_DEFAULT_WARNING; - r2 = ures_getByKey(r, "Languages", r2, &status); - checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); - } ures_close(r); status = U_USING_FALLBACK_WARNING; @@ -284,34 +293,35 @@ static void TestErrorCodes(void) { ures_close(r); ures_close(r2); +#if !UCONFIG_NO_COLLATION /** Now, with the collation bundle **/ - + /* first bundle should return fallback warning */ r = ures_open(U_ICUDATA_COLL, "sr_YU_VOJVODINA", &status); checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); ures_close(r); - /* this bundle should return zero error, so it shouldn't change the status*/ + /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_FALLBACK_WARNING; r = ures_open(U_ICUDATA_COLL, "sr", &status); checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); /* we look up the resource which is aliased */ if(U_SUCCESS(status) && r != NULL) { - status = U_USING_DEFAULT_WARNING; + status = U_USING_DEFAULT_WARNING; r2 = ures_getByKey(r, "collations", NULL, &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); - } + } ures_close(r); - /* this bundle should return zero error, so it shouldn't change the status*/ + /* this bundle should return zero error, so it shouldn't change the status */ status = U_USING_DEFAULT_WARNING; r = ures_open(U_ICUDATA_COLL, "sr", &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); /* we look up the resource which is aliased and at our level */ if(U_SUCCESS(status) && r != NULL) { - status = U_USING_DEFAULT_WARNING; + status = U_USING_DEFAULT_WARNING; r2 = ures_getByKey(r, "collations", r2, &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); } @@ -322,6 +332,7 @@ static void TestErrorCodes(void) { checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); ures_close(r); ures_close(r2); +#endif /* !UCONFIG_NO_COLLATION */ } static void TestAliasConflict(void) { @@ -338,21 +349,21 @@ static void TestAliasConflict(void) { he = ures_open(NULL, "he", &status); iw = ures_open(NULL, "iw", &status); if(U_FAILURE(status)) { - log_err("Failed to get resource with %s\n", myErrorName(status)); + log_err_status(status, "Failed to get resource with %s\n", myErrorName(status)); } ures_close(iw); - result = ures_getStringByKey(he, "localPatternChars", &resultLen, &status); + result = ures_getStringByKey(he, "ExemplarCharacters", &resultLen, &status); if(U_FAILURE(status) || result == NULL) { - log_err("Failed to get resource localPatternChars with %s\n", myErrorName(status)); + log_err_status(status, "Failed to get resource ExemplarCharacters with %s\n", myErrorName(status)); } ures_close(he); - size = sizeof(norwayNames)/sizeof(norwayNames[0]); + size = UPRV_LENGTHOF(norwayNames); for(i = 0; i < size; i++) { status = U_ZERO_ERROR; norway = ures_open(NULL, norwayNames[i], &status); if(U_FAILURE(status)) { - log_err("Failed to get resource with %s for %s\n", myErrorName(status), norwayNames[i]); + log_err_status(status, "Failed to get resource with %s for %s\n", myErrorName(status), norwayNames[i]); continue; } realName = ures_getLocale(norway, &status); @@ -418,14 +429,10 @@ static void TestDecodedBundle(){ /* pre-flight */ int32_t num =0; const char *testdatapath = loadTestData(&error); - resB = ures_open(testdatapath, "iscii", &error); + resB = ures_open(testdatapath, "encoded", &error); srcFromRes=tres_getString(resB,-1,"str",&len,&error); if(U_FAILURE(error)){ -#if UCONFIG_NO_LEGACY_CONVERSION - log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION is turned on)\n"); -#else - log_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error)); -#endif + log_data_err("Could not find encoded.res from test data bundle. Error: %s\n", u_errorName(error)); ures_close(resB); return; } @@ -465,7 +472,7 @@ static void TestNewTypes() { if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } @@ -634,7 +641,7 @@ static void TestNewTypes() { expect ="test message ...."; u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1); CONFIRM_ErrorCode(status, U_ZERO_ERROR); - if(u_strcmp(uExpect,str)){ + if(str == NULL || u_strcmp(uExpect,str)){ log_err("Did not get the expected string for test_underscores.\n"); } } @@ -757,13 +764,13 @@ static void TestEmptyTypes() { int32_t len = 0; int32_t intResult = 0; const UChar *zeroString; - const int32_t *zeroIntVect; + const int32_t *zeroIntVect = NULL; strcpy(action, "Construction of testtypes bundle"); testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } @@ -832,6 +839,7 @@ static void TestEmptyTypes() { } else { zeroIntVect=ures_getIntVector(res, &len, &status); + (void)zeroIntVect; /* Suppress set but not used warning. */ if(!U_SUCCESS(status) || resArray != NULL || len != 0) { log_err("Shouldn't get emptyintv\n"); } @@ -848,8 +856,9 @@ static void TestEmptyTypes() { } else { binResult=ures_getBinary(res, &len, &status); - if(!U_SUCCESS(status) || binResult != NULL || len != 0) { - log_err("Shouldn't get emptybin\n"); + (void)binResult; /* Suppress set but not used warning. */ + if(!U_SUCCESS(status) || len != 0) { + log_err("Couldn't get emptybin, or it's not empty\n"); } } @@ -865,7 +874,7 @@ static void TestEmptyTypes() { else { resArray=ures_getByIndex(res, 0, resArray, &status); if(U_SUCCESS(status) || resArray != NULL){ - log_err("Shouldn't get emptyarray\n"); + log_err("Shouldn't get emptyarray[0]\n"); } } @@ -881,7 +890,7 @@ static void TestEmptyTypes() { else { resArray=ures_getByIndex(res, 0, resArray, &status); if(U_SUCCESS(status) || resArray != NULL){ - log_err("Shouldn't get emptytable\n"); + log_err("Shouldn't get emptytable[0]\n"); } } @@ -897,7 +906,7 @@ static void TestEmptyBundle(){ testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } resb = ures_open(testdatapath, "testempty", &status); @@ -914,11 +923,10 @@ static void TestEmptyBundle(){ } static void TestBinaryCollationData(){ +#if !UCONFIG_NO_COLLATION UErrorCode status=U_ZERO_ERROR; const char* locale="te"; -#if !UCONFIG_NO_COLLATION const char* testdatapath; -#endif UResourceBundle *teRes = NULL; UResourceBundle *coll=NULL; UResourceBundle *binColl = NULL; @@ -926,13 +934,12 @@ static void TestBinaryCollationData(){ int32_t len=0; const char* action="testing the binary collaton data"; -#if !UCONFIG_NO_COLLATION log_verbose("Testing binary collation data resource......\n"); testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } @@ -953,6 +960,7 @@ static void TestBinaryCollationData(){ CONFIRM_ErrorCode(status, U_ZERO_ERROR); CONFIRM_INT_EQ(ures_getType(binColl), URES_BINARY); binResult=(uint8_t*)ures_getBinary(binColl, &len, &status); + (void)binResult; /* Suppress set but not used warning. */ if(U_SUCCESS(status)){ CONFIRM_ErrorCode(status, U_ZERO_ERROR); CONFIRM_INT_GE(len, 1); @@ -990,7 +998,7 @@ static void TestAPI() { testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } len =(int32_t)strlen(testdatapath); @@ -1008,8 +1016,8 @@ static void TestAPI() { } #endif - u_memset(largeBuffer, 0x0030, sizeof(largeBuffer)/sizeof(largeBuffer[0])); - largeBuffer[sizeof(largeBuffer)/sizeof(largeBuffer[0])-1] = 0; + u_memset(largeBuffer, 0x0030, UPRV_LENGTHOF(largeBuffer)); + largeBuffer[UPRV_LENGTHOF(largeBuffer)-1] = 0; /*Test ures_openU */ @@ -1022,7 +1030,7 @@ static void TestAPI() { status = U_ZERO_ERROR; ures_close(ures_openU(NULL, "root", &status)); if(U_FAILURE(status)){ - log_err("ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status)); + log_err_status(status, "ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status)); } status = U_ILLEGAL_ARGUMENT_ERROR; @@ -1033,7 +1041,7 @@ static void TestAPI() { status = U_ZERO_ERROR; teRes=ures_openU(utestdatapath, "te", &status); if(U_FAILURE(status)){ - log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status)); + log_err_status(status, "ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status)); return; } /*Test ures_getLocale() */ @@ -1045,6 +1053,7 @@ static void TestAPI() { teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status); key=ures_getKey(teFillin); value=(UChar*)ures_getNextString(teFillin, &len, &key, &status); + (void)value; /* Suppress set but not used warning. */ ures_resetIterator(NULL); value=(UChar*)ures_getNextString(teFillin, &len, &key, &status); if(status !=U_INDEX_OUTOFBOUNDS_ERROR){ @@ -1152,7 +1161,7 @@ static void TestErrorConditions(){ testdatapath = loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } len = (int32_t)strlen(testdatapath); @@ -1169,7 +1178,7 @@ static void TestErrorConditions(){ log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath)); ures_close(teRes); } - /*Test ures_openFillIn with UResourceBundle = NULL*/ + /*Test ures_openFillIn fails when input UResourceBundle parameter is NULL*/ log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n"); status=U_ZERO_ERROR; ures_openFillIn(NULL, testdatapath, "te", &status); @@ -1177,6 +1186,14 @@ static void TestErrorConditions(){ log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n", myErrorName(status)); } + /*Test ures_openDirectFillIn fails when input UResourceBundle parameter is NULL*/ + log_verbose("Testing ures_openDirectFillIn with UResourceBundle = NULL.....\n"); + status=U_ZERO_ERROR; + ures_openDirectFillIn(NULL, testdatapath, "te", &status); + if(status != U_ILLEGAL_ARGUMENT_ERROR){ + log_err("ERROR: ures_openDirectFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n", + myErrorName(status)); + } /*Test ures_getLocale() with status != U_ZERO_ERROR*/ status=U_ZERO_ERROR; teRes=ures_openU(utestdatapath, "te", &status); @@ -1362,7 +1379,7 @@ static void TestErrorConditions(){ static void TestGetVersion(){ UVersionInfo minVersionArray = {0x01, 0x00, 0x00, 0x00}; - UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf}; + UVersionInfo maxVersionArray = {0x50, 0xff, 0xcf, 0xcf}; UVersionInfo versionArray; UErrorCode status= U_ZERO_ERROR; UResourceBundle* resB = NULL; @@ -1379,7 +1396,7 @@ static void TestGetVersion(){ log_verbose("Testing version number for locale %s\n", locName); resB = ures_open(NULL,locName, &status); if (U_FAILURE(status)) { - log_err("Resource bundle creation for locale %s failed.: %s\n", locName, myErrorName(status)); + log_err_status(status, "Resource bundle creation for locale %s failed.: %s\n", locName, myErrorName(status)); ures_close(resB); return; } @@ -1399,6 +1416,7 @@ static void TestGetVersion(){ static void TestGetVersionColl(){ +#if !UCONFIG_NO_COLLATION UVersionInfo minVersionArray = {0x00, 0x00, 0x00, 0x00}; UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf}; UVersionInfo versionArray; @@ -1410,30 +1428,32 @@ static void TestGetVersionColl(){ int32_t locLen; const UChar* rules =NULL; int32_t len = 0; - + + /* test NUL termination of UCARules */ + resB = ures_open(U_ICUDATA_COLL,locName, &status); + rules = tres_getString(resB,-1,"UCARules",&len, &status); + if(!rules || U_FAILURE(status)) { + log_data_err("Could not load UCARules for locale %s\n", locName); + status = U_ZERO_ERROR; + } else if(u_strlen(rules) != len){ + log_err("UCARules string not nul terminated! \n"); + } + ures_close(resB); + log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL); locs = ures_openAvailableLocales(U_ICUDATA_COLL, &status); if (U_FAILURE(status)) { - log_err("enumeration of %s failed.: %s\n", U_ICUDATA_COLL, myErrorName(status)); + log_err_status(status, "enumeration of %s failed.: %s\n", U_ICUDATA_COLL, myErrorName(status)); return; } - do{ + for (;;) { log_verbose("Testing version number for locale %s\n", locName); resB = ures_open(U_ICUDATA_COLL,locName, &status); if (U_FAILURE(status)) { log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL, locName, myErrorName(status)); ures_close(resB); - return; - } - /* test NUL termination of UCARules */ - rules = tres_getString(resB,-1,"UCARules",&len, &status); - if(!rules || U_FAILURE(status)) { - log_data_err("Could not load UCARules for locale %s\n", locName); - continue; - } - if(u_strlen(rules) != len){ - log_err("UCARules string not nul terminated! \n"); + break; } ures_getVersion(resB, versionArray); for (i=0; i<4; ++i) { @@ -1446,16 +1466,27 @@ static void TestGetVersionColl(){ } } ures_close(resB); - } while((locName = uenum_next(locs,&locLen,&status))&&U_SUCCESS(status)); - - if(U_FAILURE(status)) { - log_err("Err %s testing Collation locales.\n", u_errorName(status)); + locName = uenum_next(locs, &locLen, &status); + if(U_FAILURE(status)) { + log_err("uenum_next(locs) error %s\n", u_errorName(status)); + break; + } + if(locName == NULL) { + break; + } } uenum_close(locs); +#endif /* !UCONFIG_NO_COLLATION */ } static void TestResourceBundles() { + UErrorCode status = U_ZERO_ERROR; + loadTestData(&status); + if(U_FAILURE(status)) { + log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status)); + return; + } testTag("only_in_Root", TRUE, FALSE, FALSE); testTag("in_Root_te", TRUE, TRUE, FALSE); @@ -1495,7 +1526,7 @@ static void TestConstruction1() testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } @@ -1582,7 +1613,7 @@ static UBool testTag(const char* frag, int32_t count = 0; int32_t row_count=0; int32_t column_count=0; - int32_t index = 0; + int32_t idx = 0; int32_t tag_count= 0; const char* testdatapath; char verboseOutput[256]; @@ -1594,7 +1625,7 @@ static UBool testTag(const char* frag, testdatapath = loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return FALSE; } @@ -1758,25 +1789,25 @@ static UBool testTag(const char* frag, for (j=0; j<10; ++j){ - index = count ? (randi(count * 3) - count) : (randi(200) - 100); + idx = count ? (randi(count * 3) - count) : (randi(200) - 100); status = U_ZERO_ERROR; string=kERROR; array=ures_getByKey(theBundle, tag, array, &status); if(!U_FAILURE(status)){ UChar *t=NULL; - t=(UChar*)ures_getStringByIndex(array, index, &len, &status); + t=(UChar*)ures_getStringByIndex(array, idx, &len, &status); if(!U_FAILURE(status)){ UChar element[3]; string=t; u_strcpy(expected_string, base); - u_uastrcpy(element, itoa1(index,buf)); + u_uastrcpy(element, itoa1(idx,buf)); u_strcat(expected_string, element); } else { u_strcpy(expected_string, kERROR); } } - expected_status = (index >= 0 && index < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR; + expected_status = (idx >= 0 && idx < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR; CONFIRM_ErrorCode(status,expected_status); CONFIRM_EQ(string,expected_string); @@ -1902,11 +1933,11 @@ static UBool testTag(const char* frag, tag_count=ures_getSize(tags); CONFIRM_INT_GE((int32_t)tag_count, (int32_t)0); - for(index=0; index loc=%s\n", - gotAvail?'t':'f', equivLocale, - i/3, - expectAvail?'t':'f', inLocale, expectLocale); +static void TestGetFunctionalEquivalentOf(const char *path, const char *resName, const char *keyword, UBool truncate, const char * const testCases[]) { + int32_t i; + for(i=0;testCases[i];i+=3) { + UBool expectAvail = (testCases[i][0]=='t')?TRUE:FALSE; + UBool gotAvail = FALSE; + const char *inLocale = testCases[i+1]; + const char *expectLocale = testCases[i+2]; + char equivLocale[256]; + int32_t len; + UErrorCode status = U_ZERO_ERROR; + log_verbose("%d: %c %s\texpect %s\n",i/3, expectAvail?'t':'f', inLocale, expectLocale); + len = ures_getFunctionalEquivalent(equivLocale, 255, path, + resName, keyword, inLocale, + &gotAvail, truncate, &status); + if(U_FAILURE(status) || (len <= 0)) { + log_err_status(status, "FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n", + len, u_errorName(status), + i/3,expectAvail?'t':'f', inLocale, expectLocale); + } else { + log_verbose("got: %c %s\n", expectAvail?'t':'f',equivLocale); - } + if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) { + log_err("FAIL: #%d: %s -> expect avail=%c, loc=%s but get %c, loc=%s\n", + i/3, inLocale, + expectAvail?'t':'f', expectLocale, + gotAvail?'t':'f', equivLocale); + + } + } } - } } static void TestGetFunctionalEquivalent(void) { - static const char *collCases[] = { - /* avail locale equiv */ - "f", "de_US_CALIFORNIA", "de", - "t", "zh_TW@collation=stroke", "zh@collation=stroke", - "f", "de_CN@collation=pinyin", "de", - "t", "zh@collation=pinyin", "zh", - "t", "zh_CN@collation=pinyin", "zh", /* should be 'T' when validSubLocales works */ - "t", "zh_HK@collation=pinyin", "zh", - "t", "zh_HK@collation=stroke", "zh@collation=stroke", - "t", "zh_HK", "zh@collation=stroke", - "t", "zh_MO", "zh@collation=stroke", - "t", "zh_TW_STROKE", "zh@collation=stroke", - "t", "zh_TW_STROKE@collation=big5han", "zh@collation=big5han", - "f", "de_CN@calendar=japanese", "de", - "t", "de@calendar=japanese", "de", - "t", "zh_TW@collation=big5han", "zh@collation=big5han", - "t", "zh_TW@collation=gb2312han", "zh@collation=gb2312han", - "t", "zh_CN@collation=big5han", "zh@collation=big5han", - "t", "zh_CN@collation=gb2312han", "zh@collation=gb2312han", - "t", "zh@collation=big5han", "zh@collation=big5han", - "t", "zh@collation=gb2312han", "zh@collation=gb2312han", - "t", "hi_IN@collation=direct", "hi@collation=direct", - "t", "hi@collation=standard", "hi", - "t", "hi@collation=direct", "hi@collation=direct", - "f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct", - "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi", - "t", "de_DE@collation=pinyin", "de", /* bug 4582 tests */ - "f", "de_DE_BONN@collation=pinyin", "de", - "t", "nl", "root", - "t", "nl_NL", "root", - "f", "nl_NL_EEXT", "root", - "t", "nl@collation=stroke", "root", - "t", "nl_NL@collation=stroke", "root", - "f", "nl_NL_EEXT@collation=stroke", "root", - NULL - }; - - static const char *calCases[] = { - /* avail locale equiv */ - "t", "en_US_POSIX", "en_US@calendar=gregorian", - "f", "ja_JP_TOKYO", "ja_JP@calendar=gregorian", - "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese", - "t", "sr@calendar=gregorian", "sr@calendar=gregorian", - "t", "en", "en@calendar=gregorian", - NULL - }; - #if !UCONFIG_NO_COLLATION - TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases); -#endif - TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases); + static const char * const collCases[] = { + /* avail locale equiv */ + /* note: in ICU 64, empty locales are shown as available for collation */ + "f", "sv_US_CALIFORNIA", "sv", + "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */ + "t", "zh_Hant_TW@collation=stroke", "zh@collation=stroke", + "f", "sv_CN@collation=pinyin", "sv", + "t", "zh@collation=pinyin", "zh", + "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */ + "t", "zh_Hans_CN@collation=pinyin", "zh", + "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */ + "t", "zh_Hant_HK@collation=pinyin", "zh", + "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */ + "t", "zh_Hant_HK@collation=stroke", "zh@collation=stroke", + "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */ + "t", "zh_Hant_HK", "zh@collation=stroke", + "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */ + "t", "zh_Hant_MO", "zh@collation=stroke", + "f", "zh_TW_STROKE", "zh@collation=stroke", + "f", "zh_TW_STROKE@collation=pinyin", "zh", + "f", "sv_CN@calendar=japanese", "sv", + "t", "sv@calendar=japanese", "sv", + "f", "zh_TW@collation=pinyin", "zh", /* alias of zh_Hant_TW */ + "t", "zh_Hant_TW@collation=pinyin", "zh", + "f", "zh_CN@collation=stroke", "zh@collation=stroke", /* alias of zh_Hans_CN */ + "t", "zh_Hans_CN@collation=stroke", "zh@collation=stroke", + "t", "de@collation=phonebook", "de@collation=phonebook", + "t", "hi@collation=standard", "hi", + "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi", + "f", "sv_SE@collation=pinyin", "sv", /* bug 4582 tests */ + "f", "sv_SE_BONN@collation=pinyin", "sv", + "t", "nl", "root", + "f", "nl_NL", "root", + "f", "nl_NL_EEXT", "root", + "t", "nl@collation=stroke", "root", + "f", "nl_NL@collation=stroke", "root", + "f", "nl_NL_EEXT@collation=stroke", "root", + /* Additions to test aliased locales */ + "f", "yue_HK", "zh@collation=stroke", + "f", "yue_Hant", "zh@collation=stroke", + "f", "yue_Hant_HK", "zh@collation=stroke", + "f", "yue@collation=stroke", "zh@collation=stroke", + "f", "yue@collation=pinyin", "zh", + "f", "yue_CN", "zh", + "f", "yue_Hans", "zh", + "f", "yue_Hans_CN", "zh", + "f", "yue_Hans@collation=pinyin", "zh", + "f", "yue_Hans@collation=stroke", "zh@collation=stroke", + "f", "mo", "mo", /* ? */ + "f", "no", "no", /* ? */ + "f", "ars", "ars", /* ? */ + "t", "wuu", "wuu", /* ? */ + /* Additions to test locales without resources */ + "f", "en_CN", "root", + "f", "zh_Hant_CN", "zh@collation=stroke", + "f", "zh_Hant_US", "zh@collation=stroke", + "f", "zh_Hans_US", "zh", + "f", "yue_TW", "zh@collation=stroke", + "f", "yue_US", "zh@collation=stroke", + "f", "ja_CN", "ja", + "f", "ja_US", "ja", + NULL + }; +#endif /* !UCONFIG_NO_COLLATION */ + + static const char *calCases[] = { + /* avail locale equiv */ + "t", "en_US_POSIX", "en@calendar=gregorian", + "f", "ja_JP_TOKYO", "ja@calendar=gregorian", + "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese", + "t", "sr@calendar=gregorian", "sr@calendar=gregorian", + "t", "en", "en@calendar=gregorian", + NULL + }; #if !UCONFIG_NO_COLLATION - log_verbose("Testing error conditions:\n"); - { - char equivLocale[256] = "???"; - int32_t len; - UErrorCode status = U_ZERO_ERROR; - UBool gotAvail = FALSE; - - len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL, - "calendar", "calendar", "ar_EG@calendar=islamic", - &gotAvail, FALSE, &status); + TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases); +#endif + TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases); - if(status == U_MISSING_RESOURCE_ERROR) { - log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n"); - } else { - log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n", - equivLocale, gotAvail?'t':'f', u_errorName(status)); +#if !UCONFIG_NO_COLLATION + log_verbose("Testing error conditions:\n"); + { + char equivLocale[256] = "???"; + int32_t len; + UErrorCode status = U_ZERO_ERROR; + UBool gotAvail = FALSE; + + len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL, + "calendar", "calendar", "ar_EG@calendar=islamic", + &gotAvail, FALSE, &status); + (void)len; /* Suppress set but not used warning. */ + + if(status == U_MISSING_RESOURCE_ERROR) { + log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n"); + } else { + log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n", + equivLocale, gotAvail?'t':'f', u_errorName(status)); + } } - } #endif } @@ -2612,7 +2744,7 @@ static void TestXPath(void) { const char *testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } @@ -2672,7 +2804,7 @@ static void TestCLDRStyleAliases(void) { const char *expects[7] = { "", "a41", "a12", "a03", "ar4" }; const char *testdatapath=loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat %s \n",myErrorName(status)); + log_data_err("Could not load testdata.dat %s \n",myErrorName(status)); return; } log_verbose("Testing CLDR style aliases......\n"); @@ -2695,7 +2827,7 @@ static void TestCLDRStyleAliases(void) { /* instead of sprintf(resource, "a%i", i); */ a = ures_getByKeyWithFallback(alias, resource, a, &status); result = tres_getString(a, -1, NULL, &len, &status); - u_charsToUChars(expects[i], expected, strlen(expects[i])+1); + u_charsToUChars(expects[i], expected, (int32_t)strlen(expects[i])+1); if(U_FAILURE(status) || !result || u_strcmp(result, expected)) { log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource, expects[i], result, myErrorName(status)); status = U_ZERO_ERROR; @@ -2721,21 +2853,21 @@ static void TestFallbackCodes(void) { fall = ures_getByKeyWithFallback(r, "tag2", fall, &status); if(status != U_ZERO_ERROR) { - log_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status)); + log_data_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status)); status = U_ZERO_ERROR; } fall = ures_getByKeyWithFallback(r, "tag7", fall, &status); if(status != U_USING_FALLBACK_WARNING) { - log_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status)); + log_data_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status)); } status = U_ZERO_ERROR; fall = ures_getByKeyWithFallback(r, "tag1", fall, &status); if(status != U_USING_DEFAULT_WARNING) { - log_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status)); + log_data_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status)); } status = U_ZERO_ERROR; @@ -2751,7 +2883,7 @@ static void TestStackReuse(void) { UResourceBundle *rb = ures_open(NULL, "en_US", &errorCode); if(U_FAILURE(errorCode)) { - log_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode)); + log_data_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode)); return; } ures_initStackObject(&table); @@ -2769,7 +2901,7 @@ static void TestStackReuse(void) { */ extern const UChar * tres_getString(const UResourceBundle *resB, - int32_t index, const char *key, + int32_t idx, const char *key, int32_t *length, UErrorCode *status) { char buffer8[16]; @@ -2783,8 +2915,8 @@ tres_getString(const UResourceBundle *resB, if(length == NULL) { length = &length16; } - if(index >= 0) { - s16 = ures_getStringByIndex(resB, index, length, status); + if(idx >= 0) { + s16 = ures_getStringByIndex(resB, idx, length, status); } else if(key != NULL) { s16 = ures_getStringByKey(resB, key, length, status); } else { @@ -2799,8 +2931,8 @@ tres_getString(const UResourceBundle *resB, for(forceCopy = FALSE; forceCopy <= TRUE; ++forceCopy) { p8 = buffer8; length8 = (int32_t)sizeof(buffer8); - if(index >= 0) { - s8 = ures_getUTF8StringByIndex(resB, index, p8, &length8, forceCopy, status); + if(idx >= 0) { + s8 = ures_getUTF8StringByIndex(resB, idx, p8, &length8, forceCopy, status); } else if(key != NULL) { s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status); } else { @@ -2816,8 +2948,8 @@ tres_getString(const UResourceBundle *resB, if(p8 == NULL) { return s16; } - if(index >= 0) { - s8 = ures_getUTF8StringByIndex(resB, index, p8, &length8, forceCopy, status); + if(idx >= 0) { + s8 = ures_getUTF8StringByIndex(resB, idx, p8, &length8, forceCopy, status); } else if(key != NULL) { s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status); } else { @@ -2834,13 +2966,13 @@ tres_getString(const UResourceBundle *resB, if(forceCopy && s8 != p8) { log_err("ures_getUTF8String(%p, %ld, '%s') did not write the string to dest\n", - resB, (long)index, key); + resB, (long)idx, key); } /* verify NUL-termination */ if((p8 != buffer8 || length8 < sizeof(buffer8)) && s8[length8] != 0) { log_err("ures_getUTF8String(%p, %ld, '%s') did not NUL-terminate\n", - resB, (long)index, key); + resB, (long)idx, key); } /* verify correct string */ i16 = i8 = 0; @@ -2849,17 +2981,17 @@ tres_getString(const UResourceBundle *resB, U8_NEXT(s8, i8, length8, c8); if(c16 != c8) { log_err("ures_getUTF8String(%p, %ld, '%s') got a bad string, c16=U+%04lx!=U+%04lx=c8 before i16=%ld\n", - resB, (long)index, key, (long)c16, (long)c8, (long)i16); + resB, (long)idx, key, (long)c16, (long)c8, (long)i16); } } /* verify correct length */ if(i16 < length16) { log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too short, length8=%ld, length16=%ld\n", - resB, (long)index, key, (long)length8, (long)length16); + resB, (long)idx, key, (long)length8, (long)length16); } if(i8 < length8) { log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too long, length8=%ld, length16=%ld\n", - resB, (long)index, key, (long)length8, (long)length16); + resB, (long)idx, key, (long)length8, (long)length16); } /* clean up */ @@ -2891,7 +3023,7 @@ TestGetUTF8String() { status = U_ZERO_ERROR; testdatapath = loadTestData(&status); if(U_FAILURE(status)) { - log_err("Could not load testdata.dat - %s\n", u_errorName(status)); + log_data_err("Could not load testdata.dat - %s\n", u_errorName(status)); return; } @@ -2905,6 +3037,7 @@ TestGetUTF8String() { status = U_ZERO_ERROR; length8 = (int32_t)sizeof(buffer8); s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status); + (void)s8; /* Suppress set but not used warning. */ if(status != U_ZERO_ERROR) { log_err("ures_getUTF8StringByKey(testdata/root string) malfunctioned - %s\n", u_errorName(status)); } @@ -2927,3 +3060,69 @@ TestGetUTF8String() { ures_close(res); } + +static void TestCLDRVersion(void) { + UVersionInfo zeroVersion; + UVersionInfo testExpect; + UVersionInfo testCurrent; + UVersionInfo cldrVersion; + char tmp[200]; + UErrorCode status = U_ZERO_ERROR; + + /* setup the constant value */ + u_versionFromString(zeroVersion, "0.0.0.0"); + + /* test CLDR value from API */ + ulocdata_getCLDRVersion(cldrVersion, &status); + if(U_FAILURE(status)) { + /* the show is pretty much over at this point */ + log_err_status(status, "FAIL: ulocdata_getCLDRVersion() returned %s\n", u_errorName(status)); + return; + } else { + u_versionToString(cldrVersion, tmp); + log_info("ulocdata_getCLDRVersion() returned: '%s'\n", tmp); + } + + + /* setup from resource bundle */ + { + UResourceBundle *res; + const char *testdatapath; + + status = U_ZERO_ERROR; + testdatapath = loadTestData(&status); + if(U_FAILURE(status)) { + log_data_err("Could not load testdata.dat - %s\n", u_errorName(status)); + return; + } + + res = ures_openDirect(testdatapath, "root", &status); + if(U_FAILURE(status)) { + log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status +)); + return; + } + ures_getVersionByKey(res, "ExpectCLDRVersionAtLeast", testExpect, &status); + ures_getVersionByKey(res, "CurrentCLDRVersion", testCurrent, &status); + ures_close(res); + if(U_FAILURE(status)) { + log_err("Unable to get test data for CLDR version - %s\n", u_errorName(status)); + } + } + if(U_FAILURE(status)) return; + + + u_versionToString(testExpect,tmp); + log_verbose("(data) ExpectCLDRVersionAtLeast { %s }\n", tmp); + if(memcmp(cldrVersion, testExpect, sizeof(UVersionInfo)) < 0) { + log_data_err("CLDR version is too old, expect at least %s.", tmp); + } + u_versionToString(testCurrent,tmp); + log_verbose("(data) CurrentCLDRVersion { %s }\n", tmp); + switch(memcmp(cldrVersion, testCurrent, sizeof(UVersionInfo))) { + case 0: break; /* OK- current. */ + case -1: log_info("CLDR version is behind 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break; + case 1: log_info("CLDR version is ahead of 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break; + } + +}