/******************************************************************** * COPYRIGHT: * Copyright (c) 1997-2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ #include "cintltst.h" #include "unicode/ures.h" #include "unicode/ucurr.h" #include "unicode/ustring.h" #include "unicode/uset.h" #include "unicode/udat.h" #include "unicode/uscript.h" #include "unicode/ulocdata.h" #include "cstring.h" #include "locmap.h" #include "uresimp.h" /* returns a new UnicodeSet that is a flattened form of the original UnicodeSet. */ static USet* createFlattenSet(USet *origSet, UErrorCode *status) { USet *newSet = NULL; int32_t origItemCount = 0; int32_t idx, graphmeSize; UChar32 start, end; UChar graphme[64]; if (U_FAILURE(*status)) { log_err("createFlattenSet called with %s\n", u_errorName(*status)); return NULL; } newSet = uset_open(1, 0); origItemCount = uset_getItemCount(origSet); for (idx = 0; idx < origItemCount; idx++) { graphmeSize = uset_getItem(origSet, idx, &start, &end, graphme, (int32_t)(sizeof(graphme)/sizeof(graphme[0])), status); if (U_FAILURE(*status)) { log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status)); *status = U_ZERO_ERROR; } if (graphmeSize) { uset_addAllCodePoints(newSet, graphme, graphmeSize); } else { uset_addRange(newSet, start, end); } } uset_closeOver(newSet,USET_CASE_INSENSITIVE); return newSet; } static UBool isCurrencyPreEuro(const char* currencyKey){ if( strcmp(currencyKey, "PTE") == 0 || strcmp(currencyKey, "ESP") == 0 || strcmp(currencyKey, "LUF") == 0 || strcmp(currencyKey, "GRD") == 0 || strcmp(currencyKey, "BEF") == 0 || strcmp(currencyKey, "ITL") == 0 || strcmp(currencyKey, "EEK") == 0){ return TRUE; } return FALSE; } static void TestKeyInRootRecursive(UResourceBundle *root, const char *rootName, UResourceBundle *currentBundle, const char *locale) { UErrorCode errorCode = U_ZERO_ERROR; UResourceBundle *subRootBundle = NULL, *subBundle = NULL, *arr = NULL; ures_resetIterator(root); ures_resetIterator(currentBundle); while (ures_hasNext(currentBundle)) { const char *subBundleKey = NULL; const char *currentBundleKey = NULL; errorCode = U_ZERO_ERROR; currentBundleKey = ures_getKey(currentBundle); subBundle = ures_getNextResource(currentBundle, NULL, &errorCode); if (U_FAILURE(errorCode)) { log_err("Can't open a resource for lnocale %s. Error: %s\n", locale, u_errorName(errorCode)); continue; } subBundleKey = ures_getKey(subBundle); subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode); if (U_FAILURE(errorCode)) { log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), rootName, locale); ures_close(subBundle); continue; } if (ures_getType(subRootBundle) != ures_getType(subBundle)) { log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n" "\troot=%d, locale=%d\n", subBundleKey, ures_getKey(currentBundle), locale, ures_getType(subRootBundle), ures_getType(subBundle)); ures_close(subBundle); continue; } else if (ures_getType(subBundle) == URES_INT_VECTOR) { int32_t minSize; int32_t subBundleSize; int32_t idx; UBool sameArray = TRUE; const int32_t *subRootBundleArr = ures_getIntVector(subRootBundle, &minSize, &errorCode); const int32_t *subBundleArr = ures_getIntVector(subBundle, &subBundleSize, &errorCode); if (minSize > subBundleSize) { minSize = subBundleSize; log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), locale); } for (idx = 0; idx < minSize && sameArray; idx++) { if (subRootBundleArr[idx] != subBundleArr[idx]) { sameArray = FALSE; } if (strcmp(subBundleKey, "DateTimeElements") == 0 && (subBundleArr[idx] < 1 || 7 < subBundleArr[idx])) { log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n", subBundleKey, idx, ures_getKey(currentBundle), locale); } } /* Special exception es_US and DateTimeElements */ if (sameArray && !(strcmp(locale, "es_US") == 0 && strcmp(subBundleKey, "DateTimeElements") == 0)) { log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), locale); } } else if (ures_getType(subBundle) == URES_ARRAY) { UResourceBundle *subSubBundle = ures_getByIndex(subBundle, 0, NULL, &errorCode); UResourceBundle *subSubRootBundle = ures_getByIndex(subRootBundle, 0, NULL, &errorCode); if (U_SUCCESS(errorCode) && (ures_getType(subSubBundle) == URES_ARRAY || ures_getType(subSubRootBundle) == URES_ARRAY)) { /* Here is one of the recursive parts */ TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale); } else { int32_t minSize = ures_getSize(subRootBundle); int32_t idx; UBool sameArray = TRUE; if (minSize > ures_getSize(subBundle)) { minSize = ures_getSize(subBundle); } if ((subBundleKey == NULL || (subBundleKey != NULL && strcmp(subBundleKey, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey))) && ures_getSize(subRootBundle) != ures_getSize(subBundle)) { log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n" "\troot array size=%d, locale array size=%d\n", subBundleKey, ures_getKey(currentBundle), locale, ures_getSize(subRootBundle), ures_getSize(subBundle)); } /* if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){ log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n", subBundleKey, ures_getKey(currentBundle), locale, ures_getSize(subBundle)); } */ for (idx = 0; idx < minSize; idx++) { int32_t rootStrLen, localeStrLen; const UChar *rootStr = ures_getStringByIndex(subRootBundle,idx,&rootStrLen,&errorCode); const UChar *localeStr = ures_getStringByIndex(subBundle,idx,&localeStrLen,&errorCode); if (rootStr && localeStr && U_SUCCESS(errorCode)) { if (u_strcmp(rootStr, localeStr) != 0) { sameArray = FALSE; } } else { if ( rootStrLen > 1 && rootStr[0] == 0x41 && rootStr[1] >= 0x30 && rootStr[1] <= 0x39 ) { /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */ /* string. Attempt to read it as an array. */ errorCode = U_ZERO_ERROR; arr = ures_getByIndex(subBundle,idx,NULL,&errorCode); if (U_FAILURE(errorCode)) { log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), idx, locale); continue; } if (ures_getType(arr) != URES_ARRAY || ures_getSize(arr) != (int32_t)rootStr[1] - 0x30) { log_err("Got something other than a string or array of size %d for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n", rootStr[1] - 0x30, subBundleKey, ures_getKey(currentBundle), idx, locale); ures_close(arr); continue; } localeStr = ures_getStringByIndex(arr,0,&localeStrLen,&errorCode); ures_close(arr); if (U_FAILURE(errorCode)) { log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), idx, locale); continue; } } else { log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), idx, locale); continue; } } if (localeStr[0] == (UChar)0x20) { log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n", subBundleKey, idx, ures_getKey(currentBundle), locale); } else if ((localeStr[localeStrLen - 1] == (UChar)0x20) && (strcmp(subBundleKey,"separator") != 0)) { log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n", subBundleKey, idx, ures_getKey(currentBundle), locale); } else if (subBundleKey != NULL && strcmp(subBundleKey, "DateTimePatterns") == 0) { int32_t quoted = 0; const UChar *localeStrItr = localeStr; while (*localeStrItr) { if (*localeStrItr == (UChar)0x27 /* ' */) { quoted++; } else if ((quoted % 2) == 0) { /* Search for unquoted characters */ if (4 <= idx && idx <= 7 && (*localeStrItr == (UChar)0x6B /* k */ || *localeStrItr == (UChar)0x48 /* H */ || *localeStrItr == (UChar)0x6D /* m */ || *localeStrItr == (UChar)0x73 /* s */ || *localeStrItr == (UChar)0x53 /* S */ || *localeStrItr == (UChar)0x61 /* a */ || *localeStrItr == (UChar)0x68 /* h */ || *localeStrItr == (UChar)0x7A /* z */)) { log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n", subBundleKey, idx, locale); } else if (0 <= idx && idx <= 3 && (*localeStrItr == (UChar)0x47 /* G */ || *localeStrItr == (UChar)0x79 /* y */ || *localeStrItr == (UChar)0x4D /* M */ || *localeStrItr == (UChar)0x64 /* d */ || *localeStrItr == (UChar)0x45 /* E */ || *localeStrItr == (UChar)0x44 /* D */ || *localeStrItr == (UChar)0x46 /* F */ || *localeStrItr == (UChar)0x77 /* w */ || *localeStrItr == (UChar)0x57 /* W */)) { log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n", subBundleKey, idx, locale); } } localeStrItr++; } } else if (idx == 4 && subBundleKey != NULL && strcmp(subBundleKey, "NumberElements") == 0 && u_charDigitValue(localeStr[0]) != 0) { log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n", subBundleKey, idx, locale); } } /* if (sameArray && strcmp(rootName, "root") == 0) { log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), locale); }*/ } ures_close(subSubBundle); ures_close(subSubRootBundle); } else if (ures_getType(subBundle) == URES_STRING) { int32_t len = 0; const UChar *string = ures_getString(subBundle, &len, &errorCode); if (U_FAILURE(errorCode) || string == NULL) { log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), locale); } else if (string[0] == (UChar)0x20) { log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), locale); /* localeDisplayPattern/separator can end with a space */ } else if (string[len - 1] == (UChar)0x20 && (strcmp(subBundleKey,"separator"))) { log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n", subBundleKey, ures_getKey(currentBundle), locale); } else if (strcmp(subBundleKey, "localPatternChars") == 0) { /* Note: We no longer import localPatternChars data starting * ICU 3.8. So it never comes into this else if block. (ticket#5597) */ /* Check well-formedness of localPatternChars. First, the * length must match the number of fields defined by * DateFormat. Second, each character in the string must * be in the set [A-Za-z]. Finally, each character must be * unique. */ int32_t i,j; #if !UCONFIG_NO_FORMATTING if (len != UDAT_FIELD_COUNT) { log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n", subBundleKey, locale); } #endif /* Check char validity. */ for (i=0; i= 65/*'A'*/ && string[i] <= 90/*'Z'*/) || (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) { log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n", subBundleKey, (char) string[i], locale); } /* Do O(n^2) check for duplicate chars. */ for (j=0; j toSize) { fromSize = toSize; log_err("Arrays are different size from \"%s\" to \"%s\"\n", fromLocale, toLocale); } for (idx = start; idx <= end; idx++) { const UChar *fromBundleStr = ures_getStringByIndex(fromArray, idx, NULL, &errorCode); const UChar *toBundleStr = ures_getStringByIndex(toArray, idx, NULL, &errorCode); if (fromBundleStr && toBundleStr && u_strcmp(fromBundleStr, toBundleStr) != 0) { log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n", keyName, idx, fromLocale, austrdup(fromBundleStr), toLocale, austrdup(toBundleStr)); } } } static void compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) { UErrorCode errorCode = U_ZERO_ERROR; UResourceBundle *fromArray, *toArray; UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode); UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode); UResourceBundle *toCalendar, *fromCalendar, *toGregorian, *fromGregorian; if(U_FAILURE(errorCode)) { log_err("Can't open resource bundle %s or %s - %s\n", fromLocale, toLocale, u_errorName(errorCode)); return; } fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode); fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode); toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode); toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode); fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode); toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode); if (strcmp(fromLocale, "en_CA") != 0) { /* The first one is probably localized. */ compareArrays("CurrencyElements", fromArray, fromLocale, toArray, toLocale, 1, 2); } ures_close(fromArray); ures_close(toArray); fromArray = ures_getByKey(fromLocaleBund, "NumberPatterns", NULL, &errorCode); toArray = ures_getByKey(toLocaleBund, "NumberPatterns", NULL, &errorCode); if (strcmp(fromLocale, "en_CA") != 0) { compareArrays("NumberPatterns", fromArray, fromLocale, toArray, toLocale, 0, 3); } ures_close(fromArray); ures_close(toArray); /* Difficult to test properly */ /* fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode); toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode); { compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale); } ures_close(fromArray); ures_close(toArray);*/ fromArray = ures_getByKey(fromLocaleBund, "NumberElements", NULL, &errorCode); toArray = ures_getByKey(toLocaleBund, "NumberElements", NULL, &errorCode); if (strcmp(fromLocale, "en_CA") != 0) { compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 0, 3); /* Index 4 is a script based 0 */ compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 5, 10); } ures_close(fromArray); ures_close(toArray); ures_close(fromCalendar); ures_close(toCalendar); ures_close(fromGregorian); ures_close(toGregorian); ures_close(fromLocaleBund); ures_close(toLocaleBund); } static void TestConsistentCountryInfo(void) { /* UResourceBundle *fromLocale, *toLocale;*/ int32_t locCount = uloc_countAvailable(); int32_t fromLocIndex, toLocIndex; int32_t fromCountryLen, toCountryLen; char fromCountry[ULOC_FULLNAME_CAPACITY], toCountry[ULOC_FULLNAME_CAPACITY]; int32_t fromVariantLen, toVariantLen; char fromVariant[ULOC_FULLNAME_CAPACITY], toVariant[ULOC_FULLNAME_CAPACITY]; UErrorCode errorCode = U_ZERO_ERROR; for (fromLocIndex = 0; fromLocIndex < locCount; fromLocIndex++) { const char *fromLocale = uloc_getAvailable(fromLocIndex); errorCode=U_ZERO_ERROR; fromCountryLen = uloc_getCountry(fromLocale, fromCountry, ULOC_FULLNAME_CAPACITY, &errorCode); if (fromCountryLen <= 0) { /* Ignore countryless locales */ continue; } fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode); if (fromVariantLen > 0) { /* Most variants are ignorable like PREEURO, or collation variants. */ continue; } /* Start comparing only after the current index. Previous loop should have already compared fromLocIndex. */ for (toLocIndex = fromLocIndex + 1; toLocIndex < locCount; toLocIndex++) { const char *toLocale = uloc_getAvailable(toLocIndex); toCountryLen = uloc_getCountry(toLocale, toCountry, ULOC_FULLNAME_CAPACITY, &errorCode); if(U_FAILURE(errorCode)) { log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n", fromLocale, toLocale, u_errorName(errorCode)); continue; } if (toCountryLen <= 0) { /* Ignore countryless locales */ continue; } toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode); if (toVariantLen > 0) { /* Most variants are ignorable like PREEURO, or collation variants. */ /* They're a variant for a reason. */ continue; } if (strcmp(fromCountry, toCountry) == 0) { log_verbose("comparing fromLocale=%s toLocale=%s\n", fromLocale, toLocale); compareConsistentCountryInfo(fromLocale, toLocale); } } } } static int32_t findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize, const UChar *exemplarCharacters, int32_t exemplarLen, UBool ignoreNumbers, UChar* badCharPtr) { UErrorCode errorCode = U_ZERO_ERROR; USet *origSet = uset_openPatternOptions(exemplarCharacters, exemplarLen, USET_CASE_INSENSITIVE, &errorCode); USet *exemplarSet = createFlattenSet(origSet, &errorCode); int32_t strIdx; uset_close(origSet); if (U_FAILURE(errorCode)) { log_err("%s: error uset_openPattern returned %s\n", currLoc, u_errorName(errorCode)); return -1; } for (strIdx = 0; strIdx < langSize; strIdx++) { if (!uset_contains(exemplarSet, string[strIdx]) && string[strIdx] != 0x0020 && string[strIdx] != 0x00A0 && string[strIdx] != 0x002e && string[strIdx] != 0x002c && string[strIdx] != 0x002d && string[strIdx] != 0x0027 && string[strIdx] != 0x2019 && string[strIdx] != 0x0f0b && string[strIdx] != 0x200C && string[strIdx] != 0x200D) { if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) { uset_close(exemplarSet); if (badCharPtr) { *badCharPtr = string[strIdx]; } return strIdx; } } } uset_close(exemplarSet); if (badCharPtr) { *badCharPtr = 0; } return -1; } /* include non-invariant chars */ static int32_t myUCharsToChars(const UChar* us, char* cs, int32_t len){ int32_t i=0; for(; i< len; i++){ if(us[i] < 0x7f){ cs[i] = (char)us[i]; }else{ return -1; } } return i; } static void findSetMatch( UScriptCode *scriptCodes, int32_t scriptsLen, USet *exemplarSet, const char *locale){ USet *scripts[10]= {0}; char pattern[256] = { '[', ':', 0x000 }; int32_t patternLen; UChar uPattern[256] = {0}; UErrorCode status = U_ZERO_ERROR; int32_t i; /* create the sets with script codes */ for(i = 0; i 2048) { log_verbose("skipping test for %s\n", currLoc); } else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) { log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc); } else { UChar langBuffer[128]; int32_t langSize; int32_t strIdx; UChar badChar; langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode); if (U_FAILURE(errorCode)) { log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode)); } else { strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE, &badChar); if (strIdx >= 0) { log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n", currLoc, strIdx, badChar); } } langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode); if (U_FAILURE(errorCode)) { log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode)); } else if (uprv_strstr(currLoc, "ti_") != currLoc || isICUVersionAtLeast(50, 1, 0)) { /* TODO: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) */ strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE, &badChar); if (strIdx >= 0) { log_err("getDisplayCountry(%s) at index %d returned characters not in the exemplar characters: %04X.\n", currLoc, strIdx, badChar); } } { UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode); UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode); UResourceBundle* names = ures_getByKeyWithFallback(greg, "dayNames", NULL, &errorCode); UResourceBundle* format = ures_getByKeyWithFallback(names, "format", NULL, &errorCode); resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode); if (U_FAILURE(errorCode)) { log_err("error ures_getByKey returned %s\n", u_errorName(errorCode)); } if (getTestOption(QUICK_OPTION)) { end = 1; } else { end = ures_getSize(resArray); } for (idx = 0; idx < end; idx++) { const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode); if (U_FAILURE(errorCode)) { log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode)); continue; } strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE, &badChar); if (strIdx >= 0) { log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n", currLoc, idx, strIdx, badChar); } } ures_close(resArray); ures_close(format); ures_close(names); names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode); format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode); resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode); if (U_FAILURE(errorCode)) { log_err("error ures_getByKey returned %s\n", u_errorName(errorCode)); } if (getTestOption(QUICK_OPTION)) { end = 1; } else { end = ures_getSize(resArray); } for (idx = 0; idx < end; idx++) { const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode); if (U_FAILURE(errorCode)) { log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode)); continue; } strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE, &badChar); if (strIdx >= 0) { log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n", currLoc, idx, strIdx, badChar); } } ures_close(resArray); ures_close(format); ures_close(names); ures_close(greg); ures_close(cal); } errorCode = U_ZERO_ERROR; numScripts = uscript_getCode(currLoc, scripts, sizeof(scripts)/sizeof(scripts[0]), &errorCode); if (numScripts == 0) { log_err("uscript_getCode(%s) doesn't work.\n", currLoc); }else if(scripts[0] == USCRIPT_COMMON){ log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc); } /* test that the scripts are a superset of exemplar characters. */ { ULocaleData *uld = ulocdata_open(currLoc,&errorCode); USet *exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode); /* test if exemplar characters are part of script code */ findSetMatch(scripts, numScripts, exemplarSet, currLoc); uset_close(exemplarSet); ulocdata_close(uld); } /* test that the paperSize API works */ { int32_t height=0, width=0; ulocdata_getPaperSize(currLoc, &height, &width, &errorCode); if(U_FAILURE(errorCode)){ log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode)); } if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){ log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc); } } /* test that the MeasurementSystem works API works */ { UMeasurementSystem measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode); if(U_FAILURE(errorCode)){ log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode)); } if(strstr(currLoc, "_US")!=NULL || strstr(currLoc, "_MM")!=NULL || strstr(currLoc, "_LR")!=NULL){ if(measurementSystem != UMS_US){ log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc); } }else if(measurementSystem != UMS_SI){ log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc); } } } ures_close(currentLocale); } ures_close(root); } /* adjust this limit as appropriate */ #define MAX_SCRIPTS_PER_LOCALE 8 static void TestExemplarSet(void){ int32_t i, j, k, m, n; int32_t equalCount = 0; UErrorCode ec = U_ZERO_ERROR; UEnumeration* avail; USet* exemplarSets[2]; USet* unassignedSet; UScriptCode code[MAX_SCRIPTS_PER_LOCALE]; USet* codeSets[MAX_SCRIPTS_PER_LOCALE]; int32_t codeLen; char cbuf[32]; /* 9 should be enough */ UChar ubuf[64]; /* adjust as needed */ UBool existsInScript; int32_t itemCount; int32_t strLen; UChar32 start, end; unassignedSet = NULL; exemplarSets[0] = NULL; exemplarSets[1] = NULL; for (i=0; i 0 && equalCount < n); END: uenum_close(avail); uset_close(exemplarSets[0]); uset_close(exemplarSets[1]); uset_close(unassignedSet); for (i=0; i1970-01-01.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == TRUE) { log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode); } /* from = null */ if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == TRUE) { log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode); } if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode); } if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode); } /* full ranges */ if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1970, date1981, &errorCode) == FALSE) { log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1981, date1992, &errorCode) == TRUE) { log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode); } if (ucurr_isAvailable(isoCode, date1950, date1970, &errorCode) == TRUE) { log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode); } /* wrong range - from > to*/ if (ucurr_isAvailable(isoCode, date1975, date1970, &errorCode) == TRUE) { log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode); } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) { log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode); } free(isoCode); #endif } #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name) void addCLDRTest(TestNode** root); void addCLDRTest(TestNode** root) { #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION TESTCASE(TestLocaleStructure); TESTCASE(TestCurrencyList); #endif TESTCASE(TestConsistentCountryInfo); TESTCASE(VerifyTranslation); TESTCASE(TestExemplarSet); TESTCASE(TestLocaleDisplayPattern); TESTCASE(TestCoverage); TESTCASE(TestIndexChars); TESTCASE(TestAvailableIsoCodes); }