X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..374ca955a76ecab1204ca8bfa63ff9238d998416:/icuSources/test/cintltst/creststn.c diff --git a/icuSources/test/cintltst/creststn.c b/icuSources/test/cintltst/creststn.c index 282fe934..6a3eaca1 100644 --- a/icuSources/test/cintltst/creststn.c +++ b/icuSources/test/cintltst/creststn.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. ********************************************************************/ /******************************************************************************** @@ -18,13 +18,13 @@ #include #include "unicode/utypes.h" #include "cintltst.h" -#include "unicode/utypes.h" +#include "unicode/putil.h" #include "unicode/ustring.h" #include "unicode/ucnv.h" #include "string.h" #include "cstring.h" #include "unicode/uchar.h" - +#include "ucol_imp.h" /* for U_ICUDATA_COLL */ #define RESTEST_HEAP_CHECK 0 #include "unicode/uloc.h" @@ -157,8 +157,10 @@ param[] = static int32_t bundles_count = sizeof(param) / sizeof(param[0]); -static void printUChars(UChar*); +/*static void printUChars(UChar*);*/ static void TestDecodedBundle(void); +static void TestGetKeywordValues(void); +static void TestGetFunctionalEquivalent(void); /***************************************************************************************/ @@ -172,6 +174,7 @@ void addNEWResourceBundleTest(TestNode** root) addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundle"); 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"); @@ -181,6 +184,9 @@ void addNEWResourceBundleTest(TestNode** root) addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle"); addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing"); addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess"); + addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues"); + addTest(root, &TestGetFunctionalEquivalent,"tsutil/creststn/TestGetFunctionalEquivalent"); + addTest(root, &TestJB3763, "tsutil/creststn/TestJB3763"); } @@ -206,12 +212,12 @@ static const char* norwayLocales[] = { "nb" }; -static void checkStatus(UErrorCode expected, UErrorCode status) { +static void checkStatus(int32_t line, UErrorCode expected, UErrorCode status) { if(U_FAILURE(status)) { - log_data_err("Resource not present, cannot test\n"); + log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__, line); } if(status != expected) { - log_err("Expected error code %s, got error code %s\n", u_errorName(expected), u_errorName(status)); + log_err("%s:%d: Expected error code %s, got error code %s\n", __FILE__, line, u_errorName(expected), u_errorName(status)); } } @@ -220,40 +226,80 @@ static void TestErrorCodes(void) { UResourceBundle *r = NULL, *r2 = NULL; + /* First check with ICUDATA */ /* first bundle should return fallback warning */ - r = ures_open(NULL, "sr_YU_VOJVODINA", &status); - checkStatus(U_USING_FALLBACK_WARNING, status); + r = ures_open(NULL, "ti_ER_ASSAB", &status); + checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); ures_close(r); /* this bundle should return zero error, so it shouldn't change the status*/ status = U_USING_DEFAULT_WARNING; - r = ures_open(NULL, "sr_YU", &status); - checkStatus(U_USING_DEFAULT_WARNING, status); + 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, "CollationElements", NULL, &status); - checkStatus(U_USING_FALLBACK_WARNING, status); + r2 = ures_getByKey(r, "Languages", NULL, &status); /* languages of 'ti' aliases to 'am' */ + checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status); } ures_close(r); /* this bundle should return zero error, so it shouldn't change the status*/ status = U_USING_DEFAULT_WARNING; - r = ures_open(NULL, "sr", &status); - checkStatus(U_USING_DEFAULT_WARNING, status); + r = ures_open(NULL, "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, "CollationElements", r2, &status); - checkStatus(U_USING_DEFAULT_WARNING, status); + r2 = ures_getByKey(r, "Languages", r2, &status); + checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); } ures_close(r); status = U_USING_FALLBACK_WARNING; r = ures_open(NULL, "nolocale", &status); - checkStatus(U_USING_DEFAULT_WARNING, status); + checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); + ures_close(r); + 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*/ + 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; + 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*/ + 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; + r2 = ures_getByKey(r, "collations", r2, &status); + checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); + } + ures_close(r); + + status = U_USING_FALLBACK_WARNING; + r = ures_open(U_ICUDATA_COLL, "nolocale", &status); + checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status); ures_close(r); ures_close(r2); } @@ -511,7 +557,7 @@ static void TestNewTypes() { const UChar* str = ures_getStringByKey(theBundle,"testescape",&len,&status); CONFIRM_ErrorCode(status, U_ZERO_ERROR); if(U_SUCCESS(status)){ - u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1); + u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1); if(u_strcmp(uExpect,str)){ log_err("Did not get the expected string for testescape\n"); } @@ -520,29 +566,43 @@ static void TestNewTypes() { /* this tests if unescaping works are expected */ len=0; { - static const char pattern[] = "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 " + char pattern[2048] = ""; + int32_t patternLen; + UChar* expectedEscaped; + const UChar* got; + int32_t expectedLen; + + /* This strcpy fixes compiler warnings about long strings */ + strcpy(pattern, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 " "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F " "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 " "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD " "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF " + ); + strcat(pattern, "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF " "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF " "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF " "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB " "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C " + ); + strcat(pattern, "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F " - "]"; - - int32_t patternLen = uprv_strlen(pattern); - UChar* expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen); - const UChar* got = ures_getStringByKey(theBundle,"test_unescaping",&len,&status); - int32_t expectedLen = u_unescape(pattern,expectedEscaped,patternLen); - if(u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){ + "]" + ); + + patternLen = (int32_t)uprv_strlen(pattern); + expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen); + got = ures_getStringByKey(theBundle,"test_unescaping",&len,&status); + expectedLen = u_unescape(pattern,expectedEscaped,patternLen); + if(got==NULL || u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){ log_err("genrb failed to unescape string\n"); } - for(i=0;i= 0) { - locName = uloc_getAvailable(j); - } - 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)); - ures_close(resB); - return; - } - ures_getVersion(resB, versionArray); - for (i=0; i<4; ++i) { - if (versionArray[i] < minVersionArray[i] || - versionArray[i] > maxVersionArray[i]) - { - log_err("Testing ures_getVersion() - unexpected result: %d.%d.%d.%d\n", - versionArray[0], versionArray[1], versionArray[2], versionArray[3]); - break; - } - } - ures_close(resB); + if(j >= 0) { + locName = uloc_getAvailable(j); + } + 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)); + ures_close(resB); + return; + } + ures_getVersion(resB, versionArray); + for (i=0; i<4; ++i) { + if (versionArray[i] < minVersionArray[i] || + versionArray[i] > maxVersionArray[i]) + { + log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n", + locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]); + break; + } + } + ures_close(resB); } } + +static void TestGetVersionColl(){ + UVersionInfo minVersionArray = {0x00, 0x00, 0x00, 0x00}; + UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf}; + UVersionInfo versionArray; + UErrorCode status= U_ZERO_ERROR; + UResourceBundle* resB = NULL; + UEnumeration *locs= NULL; + int i=0; + const char *locName = "root"; + int32_t locLen; + const UChar* rules =NULL; + int32_t len = 0; + + 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)); + return; + } + + do{ + 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 = ures_getStringByKey(resB,"%%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"); + } + ures_getVersion(resB, versionArray); + for (i=0; i<4; ++i) { + if (versionArray[i] < minVersionArray[i] || + versionArray[i] > maxVersionArray[i]) + { + log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n", + locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]); + break; + } + } + 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)); + } + uenum_close(locs); +} + static void TestResourceBundles() { - testTag("only_in_Root", TRUE, FALSE, FALSE); - testTag("in_Root_te", TRUE, TRUE, FALSE); - testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE); - testTag("in_Root_te_IN", TRUE, FALSE, TRUE); - testTag("only_in_te", FALSE, TRUE, FALSE); - testTag("only_in_te_IN", FALSE, FALSE, TRUE); - testTag("in_te_te_IN", FALSE, TRUE, TRUE); - testTag("nonexistent", FALSE, FALSE, FALSE); + testTag("only_in_Root", TRUE, FALSE, FALSE); + testTag("in_Root_te", TRUE, TRUE, FALSE); + testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE); + testTag("in_Root_te_IN", TRUE, FALSE, TRUE); + testTag("only_in_te", FALSE, TRUE, FALSE); + testTag("only_in_te_IN", FALSE, FALSE, TRUE); + testTag("in_te_te_IN", FALSE, TRUE, TRUE); + testTag("nonexistent", FALSE, FALSE, FALSE); - log_verbose("Passed:= %d Failed= %d \n", pass, fail); + log_verbose("Passed:= %d Failed= %d \n", pass, fail); } @@ -1815,6 +1942,7 @@ static void TestFallback() { UErrorCode status = U_ZERO_ERROR; UResourceBundle *fr_FR = NULL; + UResourceBundle *subResource = NULL; const UChar *junk; /* ignored */ int32_t resultLen; @@ -1838,20 +1966,21 @@ static void TestFallback() status = U_ZERO_ERROR; /* OK first one. This should be a Default value. */ - junk = ures_getStringByKey(fr_FR, "%%PREEURO", &resultLen, &status); + subResource = ures_getByKey(fr_FR, "MeasurementSystem", NULL, &status); if(status != U_USING_DEFAULT_WARNING) { - log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get %%PREEURO from fr_FR, got %s\n", + log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get CurrencyMap from fr_FR, got %s\n", u_errorName(status)); } status = U_ZERO_ERROR; + ures_close(subResource); /* and this is a Fallback, to fr */ - junk = ures_getStringByKey(fr_FR, "DayNames", &resultLen, &status); + junk = ures_getStringByKey(fr_FR, "Countries", &resultLen, &status); if(status != U_USING_FALLBACK_WARNING) { - log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get DayNames from fr_FR, got %d\n", + log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get Countries from fr_FR, got %d\n", status); } @@ -1863,18 +1992,20 @@ static void TestFallback() { UErrorCode err =U_ZERO_ERROR; UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err); - UResourceBundle* resLocID = ures_getByKey(myResB, "LocaleID", NULL, &err); + UResourceBundle* resLocID = ures_getByKey(myResB, "Version", NULL, &err); UResourceBundle* tResB; + static const UChar versionStr[] = { 0x0031, 0x002E, 0x0032, 0}; + if(err != U_ZERO_ERROR){ - log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for LocaleID err=%s\n",u_errorName(err)); + 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)); return; } - if(ures_getInt(resLocID, &err) != 0x814){ - log_data_err("Expected LocaleID=814, but got 0x%X\n", ures_getInt(resLocID, &err)); + if(u_strcmp(ures_getString(resLocID, &resultLen, &err), versionStr) != 0){ + log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value\n"); } - tResB = ures_getByKey(myResB, "DayNames", NULL, &err); + tResB = ures_getByKey(myResB, "calendar", 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 DayNames err=%s\n",u_errorName(err)); + log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for calendar err=%s\n",u_errorName(err)); } ures_close(resLocID); ures_close(myResB); @@ -1884,259 +2015,482 @@ static void TestFallback() } -static void printUChars(UChar* uchars){ - int16_t i=0; - for(i=0; i loc=%s\n", + gotAvail?'t':'f', equivLocale, + i/3, + expectAvail?'t':'f', inLocale, expectLocale); + } } } +} - ures_close(t); - ures_close(t2); +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", + NULL + }; + + static const char *calCases[] = { + /* avail locale equiv */ + "t", "en_US", "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 + TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases); +#endif + TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases); + +#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); + + 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 } +