/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2010, International Business Machines Corporation and
+ * Copyright (c) 1997-2013, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#include "unicode/uset.h"
#include "unicode/udat.h"
#include "unicode/uscript.h"
+#include "unicode/uloc.h"
#include "unicode/ulocdata.h"
#include "cstring.h"
#include "locmap.h"
uset_addRange(newSet, start, end);
}
}
+ uset_closeOver(newSet,USET_CASE_INSENSITIVE);
return newSet;
}
+
static UBool
isCurrencyPreEuro(const char* currencyKey){
if( strcmp(currencyKey, "PTE") == 0 ||
}
return FALSE;
}
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void
TestKeyInRootRecursive(UResourceBundle *root, const char *rootName,
UResourceBundle *currentBundle, const char *locale) {
ures_close(subBundle);
}
}
-
+#endif
static void
testLCID(UResourceBundle *currentBundle,
}
}
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void
TestLocaleStructure(void) {
UResourceBundle *root, *currentLocale;
ures_close(root);
}
+#endif
static void
compareArrays(const char *keyName,
static void
compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) {
UErrorCode errorCode = U_ZERO_ERROR;
- UResourceBundle *fromDateTimeElements, *toDateTimeElements, *fromWeekendData = NULL, *toWeekendData = NULL;
UResourceBundle *fromArray, *toArray;
UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode);
UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode);
}
fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode);
fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode);
- fromDateTimeElements = ures_getByKeyWithFallback(fromGregorian, "DateTimeElements", NULL, &errorCode);
toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode);
toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode);
- toDateTimeElements = ures_getByKeyWithFallback(toGregorian, "DateTimeElements", NULL, &errorCode);
-
- if(U_FAILURE(errorCode)){
- log_err("Did not get DateTimeElements from the bundle %s or %s\n", fromLocale, toLocale);
- goto cleanup;
- }
-
- fromWeekendData = ures_getByKeyWithFallback(fromGregorian, "weekend", NULL, &errorCode);
- if(U_FAILURE(errorCode)){
- log_err("Did not get weekend data from the bundle %s to compare against %s\n", fromLocale, toLocale);
- goto cleanup;
- }
- toWeekendData = ures_getByKeyWithFallback(toGregorian, "weekend", NULL, &errorCode);
- if(U_FAILURE(errorCode)){
- log_err("Did not get weekend data from the bundle %s to compare against %s\n", toLocale, fromLocale);
- goto cleanup;
- }
-
- if (strcmp(fromLocale, "ar_IN") != 0)
- {
- int32_t fromSize;
- int32_t toSize;
- int32_t idx;
- const int32_t *fromBundleArr = ures_getIntVector(fromDateTimeElements, &fromSize, &errorCode);
- const int32_t *toBundleArr = ures_getIntVector(toDateTimeElements, &toSize, &errorCode);
-
- if (fromSize > toSize) {
- fromSize = toSize;
- log_err("Arrays are different size with key \"DateTimeElements\" from \"%s\" to \"%s\"\n",
- fromLocale,
- toLocale);
- }
-
- for (idx = 0; idx < fromSize; idx++) {
- if (fromBundleArr[idx] != toBundleArr[idx]) {
- log_err("Difference with key \"DateTimeElements\" at index %d from \"%s\" to \"%s\"\n",
- idx,
- fromLocale,
- toLocale);
- }
- }
- }
-
- /* test for weekend data */
- {
- int32_t fromSize;
- int32_t toSize;
- int32_t idx;
- const int32_t *fromBundleArr = ures_getIntVector(fromWeekendData, &fromSize, &errorCode);
- const int32_t *toBundleArr = ures_getIntVector(toWeekendData, &toSize, &errorCode);
-
- if (fromSize > toSize) {
- fromSize = toSize;
- log_err("Arrays are different size with key \"weekend\" data from \"%s\" to \"%s\"\n",
- fromLocale,
- toLocale);
- }
-
- for (idx = 0; idx < fromSize; idx++) {
- if (fromBundleArr[idx] != toBundleArr[idx]) {
- log_err("Difference with key \"weekend\" data at index %d from \"%s\" to \"%s\"\n",
- idx,
- fromLocale,
- toLocale);
- }
- }
- }
fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode);
toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode);
}
ures_close(fromArray);
ures_close(toArray);
-
-cleanup:
- ures_close(fromDateTimeElements);
- ures_close(toDateTimeElements);
- ures_close(fromWeekendData);
- ures_close(toWeekendData);
-
ures_close(fromCalendar);
ures_close(toCalendar);
ures_close(fromGregorian);
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] != 0x0020 && string[strIdx] != 0x00A0 && string[strIdx] != 0x002e && string[strIdx] != 0x002c && string[strIdx] != 0x002d && string[strIdx] != 0x0027 && string[strIdx] != 0x005B && string[strIdx] != 0x005D && string[strIdx] != 0x2019 && string[strIdx] != 0x0f0b
&& string[strIdx] != 0x200C && string[strIdx] != 0x200D) {
if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) {
uset_close(exemplarSet);
}
static void VerifyTranslation(void) {
- static const UVersionInfo icu47 = { 4, 7, 0, 0 };
UResourceBundle *root, *currentLocale;
int32_t locCount = uloc_countAvailable();
int32_t locIndex;
else if (getTestOption(QUICK_OPTION) && exemplarLen > 2048) {
log_verbose("skipping test for %s\n", currLoc);
}
- else if (uprv_strncmp(currLoc,"bem",3) == 0) {
+ else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0 || uprv_strncmp(currLoc,"ky",2) == 0) {
log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
}
else {
if (U_FAILURE(errorCode)) {
log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
}
- else if (uprv_strstr(currLoc, "ti_") != currLoc || isICUVersionAtLeast(icu47)) { /* TODO: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) */
+ else if (uprv_strstr(currLoc, "ti_") != currLoc || isICUVersionAtLeast(52, 0, 1)) { /* TODO: FIX or REMOVE this test! Was: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) - but CldrBug:3058 is wontfix */
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",
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);
+ if (uprv_strstr(currLoc, "uz_Arab") != currLoc || isICUVersionAtLeast(52, 0, 1)) { /* TODO: FIX or REMOVE this test! */
+ 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);
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);
+ if (uprv_strstr(currLoc, "uz_Arab") != currLoc || isICUVersionAtLeast(52, 0, 1)) { /* TODO: FIX or REMOVE this test! */
+ 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);
}
/* test that the MeasurementSystem works API works */
{
+ char fullLoc[ULOC_FULLNAME_CAPACITY];
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){
+ uloc_addLikelySubtags(currLoc, fullLoc, ULOC_FULLNAME_CAPACITY, &errorCode);
+ if(strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_MM")!=NULL || strstr(fullLoc, "_LR")!=NULL){
if(measurementSystem != UMS_US){
log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
}
ulocdata_close(uld);
}
+static void TestIndexChars(void) {
+ /* Very basic test of ULOCDATA_ES_INDEX.
+ * No comprehensive test of data, just basic check that the code path is alive.
+ */
+ UErrorCode status = U_ZERO_ERROR;
+ ULocaleData *uld;
+ USet *exemplarChars;
+ USet *indexChars;
+
+ uld = ulocdata_open("en", &status);
+ exemplarChars = uset_openEmpty();
+ indexChars = uset_openEmpty();
+ ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
+ ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
+ if (U_FAILURE(status)) {
+ log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
+ goto close_sets;
+ }
+ /* en data, standard exemplars are [a-z], lower case. */
+ /* en data, index characters are [A-Z], upper case. */
+ if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
+ log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
+ goto close_sets;
+ }
+ if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
+ log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
+ goto close_sets;
+ }
+
+ close_sets:
+ uset_close(exemplarChars);
+ uset_close(indexChars);
+ ulocdata_close(uld);
+}
+
+
+
+#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
static void TestCurrencyList(void){
#if !UCONFIG_NO_FORMATTING
UErrorCode errorCode = U_ZERO_ERROR;
uenum_close(en);
#endif
}
+#endif
+
+static void TestAvailableIsoCodes(void){
+#if !UCONFIG_NO_FORMATTING
+ UErrorCode errorCode = U_ZERO_ERROR;
+ const char* eurCode = "EUR";
+ const char* usdCode = "USD";
+ const char* lastCode = "RHD";
+ const char* zzzCode = "ZZZ";
+ UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
+ UDate date1970 = (UDate)0.0; /* year 1970 */
+ UDate date1975 = (UDate)173448000000.0; /* year 1975 */
+ UDate date1978 = (UDate)260172000000.0; /* year 1978 */
+ UDate date1981 = (UDate)346896000000.0; /* year 1981 */
+ UDate date1992 = (UDate)693792000000.0; /* year 1992 */
+ UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
+
+ /* testing available codes with no time ranges */
+ u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
+ if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
+ log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
+ }
+
+ u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
+ if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
+ log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
+ }
+
+ u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
+ if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
+ log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
+ }
+
+ u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
+ if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
+ log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
+ }
+
+ /* RHD was used from 1970-02-17 to 1980-04-18*/
+
+ /* to = null */
+ if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
+ log_data_err("FAIL: ISO code (%s) was available in time range >1970-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)
TESTCASE(TestExemplarSet);
TESTCASE(TestLocaleDisplayPattern);
TESTCASE(TestCoverage);
+ TESTCASE(TestIndexChars);
+ TESTCASE(TestAvailableIsoCodes);
}
+