X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..ba6d6ed23dec08b1cd5700a128c0752491c10ac9:/icuSources/test/cintltst/creststn.c diff --git a/icuSources/test/cintltst/creststn.c b/icuSources/test/cintltst/creststn.c index 1e96154b..a574bcd0 100644 --- a/icuSources/test/cintltst/creststn.c +++ b/icuSources/test/cintltst/creststn.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2008, International Business Machines Corporation and + * Copyright (c) 1997-2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************* @@ -29,10 +29,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; @@ -170,6 +173,7 @@ param[] = static int32_t bundles_count = sizeof(param) / sizeof(param[0]); + /*static void printUChars(UChar*);*/ static void TestDecodedBundle(void); static void TestGetKeywordValues(void); @@ -177,6 +181,7 @@ static void TestGetFunctionalEquivalent(void); static void TestCLDRStyleAliases(void); static void TestFallbackCodes(void); static void TestGetUTF8String(void); +static void TestCLDRVersion(void); /***************************************************************************************/ @@ -185,13 +190,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 +202,20 @@ void addNEWResourceBundleTest(TestNode** root) addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle"); addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing"); addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess"); + 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"); +#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 +245,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,28 +260,30 @@ 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, "LocaleScript", NULL, &status); /* LocaleScript 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); + /* TODO: restore the following test when cldrbug 3058: is fixed */ + if(U_SUCCESS(status) && r != NULL && isICUVersionAtLeast(50, 0, 0)) { + status = U_USING_DEFAULT_WARNING; + r2 = ures_getByKey(r, "Countries", r2, &status); checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); } ures_close(r); @@ -285,33 +295,33 @@ static void TestErrorCodes(void) { ures_close(r2); /** 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); } @@ -338,12 +348,12 @@ 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, "ExemplarCharacters", &resultLen, &status); if(U_FAILURE(status) || result == NULL) { - log_err("Failed to get resource ExemplarCharacters with %s\n", myErrorName(status)); + log_err_status(status, "Failed to get resource ExemplarCharacters with %s\n", myErrorName(status)); } ures_close(he); @@ -352,7 +362,7 @@ static void TestAliasConflict(void) { 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); @@ -848,8 +858,8 @@ 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"); + if(!U_SUCCESS(status) || len != 0) { + log_err("Couldn't get emptybin, or it's not empty\n"); } } @@ -865,7 +875,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 +891,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"); } } @@ -1022,7 +1032,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 +1043,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() */ @@ -1379,7 +1389,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; } @@ -1414,7 +1424,7 @@ static void TestGetVersionColl(){ 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; } @@ -2010,7 +2020,7 @@ static void TestFallback() fr_FR = ures_open(NULL, "fr_FR", &status); if(U_FAILURE(status)) { - log_err("Couldn't open fr_FR - %d\n", status); + log_err_status(status, "Couldn't open fr_FR - %s\n", u_errorName(status)); return; } @@ -2037,10 +2047,10 @@ static void TestFallback() ures_close(subResource); /* and this is a Fallback, to fr */ - junk = tres_getString(fr_FR, -1, "Countries", &resultLen, &status); + junk = tres_getString(fr_FR, -1, "ExemplarCharacters", &resultLen, &status); if(status != U_USING_FALLBACK_WARNING) { - log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get Countries from fr_FR, got %d\n", + log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get ExemplarCharacters from fr_FR, got %d\n", status); } @@ -2054,8 +2064,9 @@ static void TestFallback() UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err); UResourceBundle* resLocID = ures_getByKey(myResB, "Version", NULL, &err); UResourceBundle* tResB; + UResourceBundle* zoneResource; const UChar* version = NULL; - static const UChar versionStr[] = { 0x0031, 0x002E, 0x0034, 0x0035, 0x0000}; + static const UChar versionStr[] = { 0x0032, 0x002E, 0x0030, 0x002E, 0x0034, 0x0031, 0x002E, 0x0032, 0x0033, 0x0000}; if(err != U_ZERO_ERROR){ log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for Version err=%s\n",u_errorName(err)); @@ -2070,14 +2081,15 @@ static void TestFallback() log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value. Expected '%s', but got '%s'\n", x, g); } - tResB = ures_getByKey(myResB, "zoneStrings", NULL, &err); + zoneResource = ures_open(U_ICUDATA_ZONE, "no_NO_NY", &err); + tResB = ures_getByKey(zoneResource, "zoneStrings", NULL, &err); if(err != U_USING_FALLBACK_WARNING){ log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for zoneStrings err=%s\n",u_errorName(err)); } + ures_close(tResB); + ures_close(zoneResource); ures_close(resLocID); ures_close(myResB); - ures_close(tResB); - } } @@ -2141,7 +2153,7 @@ static void TestResourceLevelAliasing(void) { /* testing referencing/composed alias */ uk = ures_findResource("ja/LocaleScript/2", uk, &status); if((uk == NULL) || U_FAILURE(status)) { - log_err("Couldn't findResource('ja/LocaleScript/2') err %s\n", u_errorName(status)); + log_err_status(status, "Couldn't findResource('ja/LocaleScript/2') err %s\n", u_errorName(status)); goto cleanup; } @@ -2151,12 +2163,12 @@ static void TestResourceLevelAliasing(void) { string = tres_getString(tb, -1, NULL, &strLen, &status); if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { - log_err("Referencing alias didn't get the right string\n"); + log_err("Referencing alias didn't get the right string (1)\n"); } string = tres_getString(aliasB, -1, "referencingalias", &strLen, &status); if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { - log_err("Referencing alias didn't get the right string\n"); + log_err("Referencing alias didn't get the right string (2)\n"); } checkStatus(__LINE__, U_ZERO_ERROR, status); @@ -2170,7 +2182,7 @@ static void TestResourceLevelAliasing(void) { if(U_FAILURE(status)) { log_err("%s trying to get string via separate getters\n", u_errorName(status)); } else if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { - log_err("Referencing alias didn't get the right string\n"); + log_err("Referencing alias didn't get the right string (3)\n"); } @@ -2203,7 +2215,7 @@ static void TestResourceLevelAliasing(void) { string = tres_getString(tb, -1, NULL, &strLen, &status); if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { - log_err("Referencing alias didn't get the right string\n"); + log_err("Referencing alias didn't get the right string (4)\n"); } /* test indexed aliasing */ @@ -2212,11 +2224,11 @@ static void TestResourceLevelAliasing(void) { tb = ures_getByKey(tb, "zoneAlias2", tb, &status); string = tres_getString(tb, -1, NULL, &strLen, &status); - en = ures_findResource("en/zoneStrings/3/0", en, &status); + en = ures_findResource("/ICUDATA-zone/en/zoneStrings/3/0", en, &status); sequence = tres_getString(en, -1, NULL, &seqLen, &status); if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) { - log_err("Referencing alias didn't get the right string\n"); + log_err("Referencing alias didn't get the right string (5)\n"); } } /* test getting aliased string by index */ @@ -2241,65 +2253,67 @@ static void TestResourceLevelAliasing(void) { const char *key = NULL; tb = ures_getByKey(aliasB, "testGetStringByKeyAliasing", tb, &status); if(U_FAILURE(status)) { - log_err("Couldn't get testGetStringByKeyAliasing resource\n"); - } - for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { - result = tres_getString(tb, -1, keys[i], &resultLen, &status); - if(U_FAILURE(status)){ - log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); - continue; - } - uBufferLen = u_unescape(strings[i], uBuffer, 256); - if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { - log_err("Didn't get correct string while accesing alias table by key (%s)\n", keys[i]); - } - } - for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { - result = tres_getString(tb, i, NULL, &resultLen, &status); - if(U_FAILURE(status)){ - log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); - continue; - } - uBufferLen = u_unescape(strings[i], uBuffer, 256); - if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { - log_err("Didn't get correct string while accesing alias table by index (%s)\n", strings[i]); + log_err("FAIL: Couldn't get testGetStringByKeyAliasing resource: %s\n", u_errorName(status)); + } else { + for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { + result = tres_getString(tb, -1, keys[i], &resultLen, &status); + if(U_FAILURE(status)){ + log_err("(1) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); + continue; + } + uBufferLen = u_unescape(strings[i], uBuffer, 256); + if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { + log_err("(1) Didn't get correct string while accessing alias table by key (%s)\n", keys[i]); + } } - } - for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { - result = ures_getNextString(tb, &resultLen, &key, &status); - if(U_FAILURE(status)){ - log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); - continue; + for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { + result = tres_getString(tb, i, NULL, &resultLen, &status); + if(U_FAILURE(status)){ + log_err("(2) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); + continue; + } + uBufferLen = u_unescape(strings[i], uBuffer, 256); + if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { + log_err("(2) Didn't get correct string while accesing alias table by index (%s)\n", strings[i]); + } } - uBufferLen = u_unescape(strings[i], uBuffer, 256); - if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { - log_err("Didn't get correct string while iterating over alias table (%s)\n", strings[i]); + for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { + result = ures_getNextString(tb, &resultLen, &key, &status); + if(U_FAILURE(status)){ + log_err("(3) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); + continue; + } + uBufferLen = u_unescape(strings[i], uBuffer, 256); + if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { + log_err("(3) Didn't get correct string while iterating over alias table (%s)\n", strings[i]); + } } } tb = ures_getByKey(aliasB, "testGetStringByIndexAliasing", tb, &status); if(U_FAILURE(status)) { - log_err("Couldn't get testGetStringByIndexAliasing resource\n"); - } - for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { - result = tres_getString(tb, i, NULL, &resultLen, &status); - if(U_FAILURE(status)){ - log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); - continue; - } - uBufferLen = u_unescape(strings[i], uBuffer, 256); - if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { - log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings[i]); - } - } - for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { - result = ures_getNextString(tb, &resultLen, &key, &status); - if(U_FAILURE(status)){ - log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); - continue; + log_err("FAIL: Couldn't get testGetStringByIndexAliasing resource: %s\n", u_errorName(status)); + } else { + for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { + result = tres_getString(tb, i, NULL, &resultLen, &status); + if(U_FAILURE(status)){ + log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); + continue; + } + uBufferLen = u_unescape(strings[i], uBuffer, 256); + if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { + log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings[i]); + } } - uBufferLen = u_unescape(strings[i], uBuffer, 256); - if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { - log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings[i]); + for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { + result = ures_getNextString(tb, &resultLen, &key, &status); + if(U_FAILURE(status)){ + log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status)); + continue; + } + uBufferLen = u_unescape(strings[i], uBuffer, 256); + if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) { + log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings[i]); + } } } } @@ -2364,9 +2378,9 @@ static void TestDirectAccess(void) { } } - t2 = ures_open(NULL, "sr", &status); + t2 = ures_open(U_ICUDATA_LANG, "sr", &status); if(U_FAILURE(status)) { - log_err("Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status)); + log_err_status(status, "Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status)); log_data_err("No 'sr', no test - you have bigger problems than testing direct access. " "You probably have no data! Aborting this test\n"); } @@ -2416,7 +2430,7 @@ static void TestDirectAccess(void) { t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status); t2 = ures_getByKeyWithFallback(t2, "eras", t2, &status); if(U_FAILURE(status)) { - log_err("Didn't get Eras. I know they are there!\n"); + log_err_status(status, "Didn't get Eras. I know they are there!\n"); } status = U_ZERO_ERROR; @@ -2445,7 +2459,7 @@ static void TestJB3763(void) { t = ures_getByKeyWithFallback(t, "gregorian", t, &status); t = ures_getByKeyWithFallback(t, "AmPmMarkers", t, &status); if(U_FAILURE(status)) { - log_err("This resource should be available?\n"); + log_err_status(status, "This resource should be available?\n"); } status = U_ZERO_ERROR; @@ -2474,11 +2488,11 @@ static void TestGetKeywordValues(void) { } } if(foundStandard == FALSE) { - log_err("'standard' was not found in the keyword list.\n"); + log_err_status(status, "'standard' was not found in the keyword list.\n"); } uenum_close(kwVals); if(U_FAILURE(status)) { - log_err("err %s getting collation values\n", u_errorName(status)); + log_err_status(status, "err %s getting collation values\n", u_errorName(status)); } status = U_ZERO_ERROR; #endif @@ -2498,11 +2512,11 @@ static void TestGetKeywordValues(void) { } } if(foundStandard == FALSE) { - log_err("'japanese' was not found in the calendar keyword list.\n"); + log_err_status(status, "'japanese' was not found in the calendar keyword list.\n"); } uenum_close(kwVals); if(U_FAILURE(status)) { - log_err("err %s getting calendar values\n", u_errorName(status)); + log_err_status(status, "err %s getting calendar values\n", u_errorName(status)); } } @@ -2521,7 +2535,7 @@ static void TestGetFunctionalEquivalentOf(const char *path, const char *resName, resName, keyword, inLocale, &gotAvail, truncate, &status); if(U_FAILURE(status) || (len <= 0)) { - log_err("FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n", + 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 { @@ -2570,10 +2584,7 @@ static void TestGetFunctionalEquivalent(void) { "t", "zh_Hans_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", @@ -2588,8 +2599,8 @@ static void TestGetFunctionalEquivalent(void) { static const char *calCases[] = { /* avail locale equiv */ - "t", "en_US_POSIX", "en_US@calendar=gregorian", - "f", "ja_JP_TOKYO", "ja_JP@calendar=gregorian", + "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", @@ -2949,3 +2960,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; + } + +}