1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
10 #include "unicode/ures.h"
11 #include "unicode/ucurr.h"
12 #include "unicode/ustring.h"
13 #include "unicode/uset.h"
14 #include "unicode/udat.h"
15 #include "unicode/uscript.h"
16 #include "unicode/ulocdata.h"
23 returns a new UnicodeSet that is a flattened form of the original
27 createFlattenSet(USet *origSet, UErrorCode *status) {
31 int32_t origItemCount = 0;
32 int32_t idx, graphmeSize;
35 if (U_FAILURE(*status)) {
36 log_err("createFlattenSet called with %s\n", u_errorName(*status));
39 newSet = uset_open(1, 0);
40 origItemCount = uset_getItemCount(origSet);
41 for (idx = 0; idx < origItemCount; idx++) {
42 graphmeSize = uset_getItem(origSet, idx,
44 graphme, UPRV_LENGTHOF(graphme),
46 if (U_FAILURE(*status)) {
47 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status));
48 *status = U_ZERO_ERROR;
51 uset_addAllCodePoints(newSet, graphme, graphmeSize);
54 uset_addRange(newSet, start, end);
57 uset_closeOver(newSet,USET_CASE_INSENSITIVE);
62 isCurrencyPreEuro(const char* currencyKey){
63 if( strcmp(currencyKey, "PTE") == 0 ||
64 strcmp(currencyKey, "ESP") == 0 ||
65 strcmp(currencyKey, "LUF") == 0 ||
66 strcmp(currencyKey, "GRD") == 0 ||
67 strcmp(currencyKey, "BEF") == 0 ||
68 strcmp(currencyKey, "ITL") == 0 ||
69 strcmp(currencyKey, "EEK") == 0){
74 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
76 TestKeyInRootRecursive(UResourceBundle *root, const char *rootName,
77 UResourceBundle *currentBundle, const char *locale) {
78 UErrorCode errorCode = U_ZERO_ERROR;
79 UResourceBundle *subRootBundle = NULL, *subBundle = NULL, *arr = NULL;
81 ures_resetIterator(root);
82 ures_resetIterator(currentBundle);
83 while (ures_hasNext(currentBundle)) {
84 const char *subBundleKey = NULL;
85 const char *currentBundleKey = NULL;
87 errorCode = U_ZERO_ERROR;
88 currentBundleKey = ures_getKey(currentBundle);
89 (void)currentBundleKey; /* Suppress set but not used warning. */
90 subBundle = ures_getNextResource(currentBundle, NULL, &errorCode);
91 if (U_FAILURE(errorCode)) {
92 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale, u_errorName(errorCode));
95 subBundleKey = ures_getKey(subBundle);
98 subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode);
99 if (U_FAILURE(errorCode)) {
100 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
102 ures_getKey(currentBundle),
105 ures_close(subBundle);
108 if (ures_getType(subRootBundle) != ures_getType(subBundle)) {
109 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
110 "\troot=%d, locale=%d\n",
112 ures_getKey(currentBundle),
114 ures_getType(subRootBundle),
115 ures_getType(subBundle));
116 ures_close(subBundle);
119 else if (ures_getType(subBundle) == URES_INT_VECTOR) {
121 int32_t subBundleSize;
123 UBool sameArray = TRUE;
124 const int32_t *subRootBundleArr = ures_getIntVector(subRootBundle, &minSize, &errorCode);
125 const int32_t *subBundleArr = ures_getIntVector(subBundle, &subBundleSize, &errorCode);
127 if (minSize > subBundleSize) {
128 minSize = subBundleSize;
129 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
131 ures_getKey(currentBundle),
135 for (idx = 0; idx < minSize && sameArray; idx++) {
136 if (subRootBundleArr[idx] != subBundleArr[idx]) {
139 if (strcmp(subBundleKey, "DateTimeElements") == 0
140 && (subBundleArr[idx] < 1 || 7 < subBundleArr[idx]))
142 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
145 ures_getKey(currentBundle),
149 /* Special exception es_US and DateTimeElements */
151 && !(strcmp(locale, "es_US") == 0 && strcmp(subBundleKey, "DateTimeElements") == 0))
153 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
155 ures_getKey(currentBundle),
159 else if (ures_getType(subBundle) == URES_ARRAY) {
160 UResourceBundle *subSubBundle = ures_getByIndex(subBundle, 0, NULL, &errorCode);
161 UResourceBundle *subSubRootBundle = ures_getByIndex(subRootBundle, 0, NULL, &errorCode);
163 if (U_SUCCESS(errorCode)
164 && (ures_getType(subSubBundle) == URES_ARRAY || ures_getType(subSubRootBundle) == URES_ARRAY))
166 /* Here is one of the recursive parts */
167 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
170 int32_t minSize = ures_getSize(subRootBundle);
172 UBool sameArray = TRUE;
174 if (minSize > ures_getSize(subBundle)) {
175 minSize = ures_getSize(subBundle);
178 if ((subBundleKey == NULL
179 || (subBundleKey != NULL && strcmp(subBundleKey, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey)))
180 && ures_getSize(subRootBundle) != ures_getSize(subBundle))
182 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
183 "\troot array size=%d, locale array size=%d\n",
185 ures_getKey(currentBundle),
187 ures_getSize(subRootBundle),
188 ures_getSize(subBundle));
191 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
192 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
194 ures_getKey(currentBundle),
196 ures_getSize(subBundle));
199 for (idx = 0; idx < minSize; idx++) {
200 int32_t rootStrLen, localeStrLen;
201 const UChar *rootStr = ures_getStringByIndex(subRootBundle,idx,&rootStrLen,&errorCode);
202 const UChar *localeStr = ures_getStringByIndex(subBundle,idx,&localeStrLen,&errorCode);
203 if (rootStr && localeStr && U_SUCCESS(errorCode)) {
204 if (u_strcmp(rootStr, localeStr) != 0) {
209 if ( rootStrLen > 1 && rootStr[0] == 0x41 && rootStr[1] >= 0x30 && rootStr[1] <= 0x39 ) {
210 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
211 /* string. Attempt to read it as an array. */
212 errorCode = U_ZERO_ERROR;
213 arr = ures_getByIndex(subBundle,idx,NULL,&errorCode);
214 if (U_FAILURE(errorCode)) {
215 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
217 ures_getKey(currentBundle),
222 if (ures_getType(arr) != URES_ARRAY || ures_getSize(arr) != (int32_t)rootStr[1] - 0x30) {
223 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",
226 ures_getKey(currentBundle),
232 localeStr = ures_getStringByIndex(arr,0,&localeStrLen,&errorCode);
234 if (U_FAILURE(errorCode)) {
235 log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
237 ures_getKey(currentBundle),
243 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
245 ures_getKey(currentBundle),
251 if (localeStr[0] == (UChar)0x20) {
252 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
255 ures_getKey(currentBundle),
258 else if ((localeStr[localeStrLen - 1] == (UChar)0x20) && (strcmp(subBundleKey,"separator") != 0)) {
259 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
262 ures_getKey(currentBundle),
265 else if (subBundleKey != NULL
266 && strcmp(subBundleKey, "DateTimePatterns") == 0)
269 const UChar *localeStrItr = localeStr;
270 while (*localeStrItr) {
271 if (*localeStrItr == (UChar)0x27 /* ' */) {
274 else if ((quoted % 2) == 0) {
275 /* Search for unquoted characters */
276 if (4 <= idx && idx <= 7
277 && (*localeStrItr == (UChar)0x6B /* k */
278 || *localeStrItr == (UChar)0x48 /* H */
279 || *localeStrItr == (UChar)0x6D /* m */
280 || *localeStrItr == (UChar)0x73 /* s */
281 || *localeStrItr == (UChar)0x53 /* S */
282 || *localeStrItr == (UChar)0x61 /* a */
283 || *localeStrItr == (UChar)0x68 /* h */
284 || *localeStrItr == (UChar)0x7A /* z */))
286 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
291 else if (0 <= idx && idx <= 3
292 && (*localeStrItr == (UChar)0x47 /* G */
293 || *localeStrItr == (UChar)0x79 /* y */
294 || *localeStrItr == (UChar)0x4D /* M */
295 || *localeStrItr == (UChar)0x64 /* d */
296 || *localeStrItr == (UChar)0x45 /* E */
297 || *localeStrItr == (UChar)0x44 /* D */
298 || *localeStrItr == (UChar)0x46 /* F */
299 || *localeStrItr == (UChar)0x77 /* w */
300 || *localeStrItr == (UChar)0x57 /* W */))
302 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
311 else if (idx == 4 && subBundleKey != NULL
312 && strcmp(subBundleKey, "NumberElements") == 0
313 && u_charDigitValue(localeStr[0]) != 0)
315 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
321 (void)sameArray; /* Suppress set but not used warning. */
322 /* if (sameArray && strcmp(rootName, "root") == 0) {
323 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
325 ures_getKey(currentBundle),
329 ures_close(subSubBundle);
330 ures_close(subSubRootBundle);
332 else if (ures_getType(subBundle) == URES_STRING) {
334 const UChar *string = ures_getString(subBundle, &len, &errorCode);
335 if (U_FAILURE(errorCode) || string == NULL) {
336 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
338 ures_getKey(currentBundle),
340 } else if (string[0] == (UChar)0x20) {
341 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
343 ures_getKey(currentBundle),
345 /* localeDisplayPattern/separator can end with a space */
346 } else if (string[len - 1] == (UChar)0x20 && (strcmp(subBundleKey,"separator"))) {
347 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
349 ures_getKey(currentBundle),
351 } else if (strcmp(subBundleKey, "localPatternChars") == 0) {
352 /* Note: We no longer import localPatternChars data starting
353 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
356 /* Check well-formedness of localPatternChars. First, the
357 * length must match the number of fields defined by
358 * DateFormat. Second, each character in the string must
359 * be in the set [A-Za-z]. Finally, each character must be
363 #if !UCONFIG_NO_FORMATTING
364 if (len != UDAT_FIELD_COUNT) {
365 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
370 /* Check char validity. */
371 for (i=0; i<len; ++i) {
372 if (!((string[i] >= 65/*'A'*/ && string[i] <= 90/*'Z'*/) ||
373 (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) {
374 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
379 /* Do O(n^2) check for duplicate chars. */
380 for (j=0; j<i; ++j) {
381 if (string[j] == string[i]) {
382 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
390 /* No fallback was done. Check for duplicate data */
391 /* The ures_* API does not do fallback of sub-resource bundles,
392 So we can't do this now. */
394 else if (strcmp(locale, "root") != 0 && errorCode == U_ZERO_ERROR) {
396 const UChar *rootString = ures_getString(subRootBundle, &len, &errorCode);
397 if (U_FAILURE(errorCode) || rootString == NULL) {
398 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
399 ures_getKey(subRootBundle),
400 ures_getKey(currentBundle));
402 } else if (u_strcmp(string, rootString) == 0) {
403 if (strcmp(locale, "de_CH") != 0 && strcmp(subBundleKey, "Countries") != 0 &&
404 strcmp(subBundleKey, "Version") != 0) {
405 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
406 ures_getKey(subRootBundle),
407 ures_getKey(currentBundle),
411 /* Ignore for now. */
412 /* Can be fixed if fallback through de locale was done. */
413 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
419 else if (ures_getType(subBundle) == URES_TABLE) {
420 if (strcmp(subBundleKey, "availableFormats")!=0) {
421 /* Here is one of the recursive parts */
422 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
425 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
428 else if (ures_getType(subBundle) == URES_BINARY || ures_getType(subBundle) == URES_INT) {
429 /* Can't do anything to check it */
430 /* We'll assume it's all correct */
431 if (strcmp(subBundleKey, "MeasurementSystem") != 0) {
432 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
434 ures_getKey(currentBundle),
437 /* Testing for MeasurementSystem is done in VerifyTranslation */
440 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
441 ures_getType(subBundle),
443 ures_getKey(currentBundle),
446 ures_close(subRootBundle);
447 ures_close(subBundle);
453 testLCID(UResourceBundle *currentBundle,
454 const char *localeName)
456 UErrorCode status = U_ZERO_ERROR;
457 uint32_t expectedLCID;
458 char lcidStringC[64] = {0};
461 expectedLCID = uloc_getLCID(localeName);
462 if (expectedLCID == 0) {
463 log_verbose("INFO: %-5s does not have any LCID mapping\n",
468 status = U_ZERO_ERROR;
469 len = uprv_convertToPosix(expectedLCID, lcidStringC, UPRV_LENGTHOF(lcidStringC) - 1, &status);
470 if (U_FAILURE(status)) {
471 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
472 expectedLCID, u_errorName(status));
474 lcidStringC[len] = 0;
476 if(strcmp(localeName, lcidStringC) != 0) {
479 uloc_getLanguage(localeName, langName, sizeof(langName), &status);
480 uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status);
482 if (strcmp(langName, langLCID) == 0) {
483 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
484 localeName, lcidStringC, expectedLCID);
487 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
488 localeName, expectedLCID, lcidStringC);
493 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
495 TestLocaleStructure(void) {
496 // This test checks the locale structure against a key file located
497 // at source/test/testdata/structLocale.txt. When adding new data to
498 // a locale file such as en.txt, the structLocale.txt file must be changed
499 // too to include the the template of the new data. Otherwise this test
502 UResourceBundle *root, *currentLocale;
503 int32_t locCount = uloc_countAvailable();
505 UErrorCode errorCode = U_ZERO_ERROR;
506 const char *currLoc, *resolvedLoc;
508 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
509 /* char locName[ULOC_FULLNAME_CAPACITY];
512 for (locIndex = 0; locIndex < locCount; locIndex++) {
513 errorCode=U_ZERO_ERROR;
514 strcpy(locName, uloc_getAvailable(locIndex));
515 locNamePtr = strrchr(locName, '_');
520 strcpy(locName, "root");
523 root = ures_openDirect(NULL, locName, &errorCode);
524 if(U_FAILURE(errorCode)) {
525 log_err("Can't open %s\n", locName);
530 log_data_err("At least root needs to be installed\n");
533 root = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
534 if(U_FAILURE(errorCode)) {
535 log_data_err("Can't open structLocale\n");
538 for (locIndex = 0; locIndex < locCount; locIndex++) {
539 errorCode=U_ZERO_ERROR;
540 currLoc = uloc_getAvailable(locIndex);
541 currentLocale = ures_open(NULL, currLoc, &errorCode);
542 if(errorCode != U_ZERO_ERROR) {
543 if(U_SUCCESS(errorCode)) {
544 /* It's installed, but there is no data.
545 It's installed for the g18n white paper [grhoten] */
546 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
547 uloc_getAvailable(locIndex), u_errorName(errorCode));
549 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
550 u_errorName(errorCode),
551 uloc_getAvailable(locIndex));
553 ures_close(currentLocale);
556 ures_getStringByKey(currentLocale, "Version", NULL, &errorCode);
557 if(errorCode != U_ZERO_ERROR) {
558 log_err("No version information is available for locale %s, and it should be!\n",
561 else if (ures_getStringByKey(currentLocale, "Version", NULL, &errorCode)[0] == (UChar)(0x78)) {
562 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
565 resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode);
566 if (strcmp(resolvedLoc, currLoc) != 0) {
567 /* All locales have at least a Version resource.
568 If it's absolutely empty, then the previous test will fail too.*/
569 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
570 currLoc, resolvedLoc);
572 TestKeyInRootRecursive(root, "root", currentLocale, currLoc);
574 testLCID(currentLocale, currLoc);
576 ures_close(currentLocale);
584 compareArrays(const char *keyName,
585 UResourceBundle *fromArray, const char *fromLocale,
586 UResourceBundle *toArray, const char *toLocale,
587 int32_t start, int32_t end)
589 int32_t fromSize = ures_getSize(fromArray);
590 int32_t toSize = ures_getSize(fromArray);
592 UErrorCode errorCode = U_ZERO_ERROR;
594 if (fromSize > toSize) {
596 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
601 for (idx = start; idx <= end; idx++) {
602 const UChar *fromBundleStr = ures_getStringByIndex(fromArray, idx, NULL, &errorCode);
603 const UChar *toBundleStr = ures_getStringByIndex(toArray, idx, NULL, &errorCode);
604 if (fromBundleStr && toBundleStr && u_strcmp(fromBundleStr, toBundleStr) != 0)
606 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
610 austrdup(fromBundleStr),
612 austrdup(toBundleStr));
618 compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) {
619 UErrorCode errorCode = U_ZERO_ERROR;
620 UResourceBundle *fromArray, *toArray;
621 UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode);
622 UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode);
623 UResourceBundle *toCalendar, *fromCalendar, *toGregorian, *fromGregorian;
625 if(U_FAILURE(errorCode)) {
626 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale, toLocale, u_errorName(errorCode));
629 fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode);
630 fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode);
632 toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode);
633 toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode);
635 fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode);
636 toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode);
637 if (strcmp(fromLocale, "en_CA") != 0)
639 /* The first one is probably localized. */
640 compareArrays("CurrencyElements", fromArray, fromLocale, toArray, toLocale, 1, 2);
642 ures_close(fromArray);
645 fromArray = ures_getByKey(fromLocaleBund, "NumberPatterns", NULL, &errorCode);
646 toArray = ures_getByKey(toLocaleBund, "NumberPatterns", NULL, &errorCode);
647 if (strcmp(fromLocale, "en_CA") != 0)
649 compareArrays("NumberPatterns", fromArray, fromLocale, toArray, toLocale, 0, 3);
651 ures_close(fromArray);
654 /* Difficult to test properly */
656 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
657 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
659 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
661 ures_close(fromArray);
662 ures_close(toArray);*/
664 fromArray = ures_getByKey(fromLocaleBund, "NumberElements", NULL, &errorCode);
665 toArray = ures_getByKey(toLocaleBund, "NumberElements", NULL, &errorCode);
666 if (strcmp(fromLocale, "en_CA") != 0)
668 compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 0, 3);
669 /* Index 4 is a script based 0 */
670 compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 5, 10);
672 ures_close(fromArray);
674 ures_close(fromCalendar);
675 ures_close(toCalendar);
676 ures_close(fromGregorian);
677 ures_close(toGregorian);
679 ures_close(fromLocaleBund);
680 ures_close(toLocaleBund);
684 TestConsistentCountryInfo(void) {
685 /* UResourceBundle *fromLocale, *toLocale;*/
686 int32_t locCount = uloc_countAvailable();
687 int32_t fromLocIndex, toLocIndex;
689 int32_t fromCountryLen, toCountryLen;
690 char fromCountry[ULOC_FULLNAME_CAPACITY], toCountry[ULOC_FULLNAME_CAPACITY];
692 int32_t fromVariantLen, toVariantLen;
693 char fromVariant[ULOC_FULLNAME_CAPACITY], toVariant[ULOC_FULLNAME_CAPACITY];
695 UErrorCode errorCode = U_ZERO_ERROR;
697 for (fromLocIndex = 0; fromLocIndex < locCount; fromLocIndex++) {
698 const char *fromLocale = uloc_getAvailable(fromLocIndex);
700 errorCode=U_ZERO_ERROR;
701 fromCountryLen = uloc_getCountry(fromLocale, fromCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
702 if (fromCountryLen <= 0) {
703 /* Ignore countryless locales */
706 fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
707 if (fromVariantLen > 0) {
708 /* Most variants are ignorable like PREEURO, or collation variants. */
711 /* Start comparing only after the current index.
712 Previous loop should have already compared fromLocIndex.
714 for (toLocIndex = fromLocIndex + 1; toLocIndex < locCount; toLocIndex++) {
715 const char *toLocale = uloc_getAvailable(toLocIndex);
717 toCountryLen = uloc_getCountry(toLocale, toCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
718 if(U_FAILURE(errorCode)) {
719 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
720 fromLocale, toLocale, u_errorName(errorCode));
724 if (toCountryLen <= 0) {
725 /* Ignore countryless locales */
728 toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
729 if (toVariantLen > 0) {
730 /* Most variants are ignorable like PREEURO, or collation variants. */
731 /* They're a variant for a reason. */
734 if (strcmp(fromCountry, toCountry) == 0) {
735 log_verbose("comparing fromLocale=%s toLocale=%s\n",
736 fromLocale, toLocale);
737 compareConsistentCountryInfo(fromLocale, toLocale);
744 findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize,
745 USet * mergedExemplarSet,
746 UBool ignoreNumbers, UChar* badCharPtr) {
747 UErrorCode errorCode = U_ZERO_ERROR;
750 if (mergedExemplarSet == NULL) {
753 exemplarSet = createFlattenSet(mergedExemplarSet, &errorCode);
754 if (U_FAILURE(errorCode)) {
755 log_err("%s: error createFlattenSet returned %s\n", currLoc, u_errorName(errorCode));
759 for (strIdx = 0; strIdx < langSize; strIdx++) {
760 if (!uset_contains(exemplarSet, string[strIdx])
761 && 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
762 && string[strIdx] != 0x200C && string[strIdx] != 0x200D) {
763 if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) {
764 uset_close(exemplarSet);
766 *badCharPtr = string[strIdx];
772 uset_close(exemplarSet);
778 /* include non-invariant chars */
780 myUCharsToChars(const UChar* us, char* cs, int32_t len){
792 findSetMatch( UScriptCode *scriptCodes, int32_t scriptsLen,
795 USet *scripts[10]= {0};
796 char pattern[256] = { '[', ':', 0x000 };
798 UChar uPattern[256] = {0};
799 UErrorCode status = U_ZERO_ERROR;
802 /* create the sets with script codes */
803 for(i = 0; i<scriptsLen; i++){
804 strcat(pattern, uscript_getShortName(scriptCodes[i]));
805 strcat(pattern, ":]");
806 patternLen = (int32_t)strlen(pattern);
807 u_charsToUChars(pattern, uPattern, patternLen);
808 scripts[i] = uset_openPattern(uPattern, patternLen, &status);
809 if(U_FAILURE(status)){
810 log_err("Could not create set for pattern %s. Error: %s\n", pattern, u_errorName(status));
815 if (strcmp(locale, "uk") == 0 || strcmp(locale, "uk_UA") == 0) {
816 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
817 uset_add(scripts[0], 0x2bc);
819 if(U_SUCCESS(status)){
820 UBool existsInScript = FALSE;
821 /* iterate over the exemplarSet and ascertain if all
822 * UChars in exemplarSet belong to the scripts returned
825 int32_t count = uset_getItemCount(exemplarSet);
827 for( i=0; i < count; i++){
831 int32_t strCapacity = 0;
833 strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
834 if(U_SUCCESS(status)){
836 if(strCapacity == 0){
837 /* ok the item is a range */
838 for( j = 0; j < scriptsLen; j++){
839 if(uset_containsRange(scripts[j], start, end) == TRUE){
840 existsInScript = TRUE;
843 if(existsInScript == FALSE){
844 for( j = 0; j < scriptsLen; j++){
845 UChar toPattern[500]={'\0'};
846 char pat[500]={'\0'};
847 int32_t len = uset_toPattern(scripts[j], toPattern, 500, TRUE, &status);
848 len = myUCharsToChars(toPattern, pat, len);
849 log_err("uset_indexOf(\\u%04X)=%i uset_indexOf(\\u%04X)=%i\n", start, uset_indexOf(scripts[0], start), end, uset_indexOf(scripts[0], end));
851 log_err("Pattern: %s\n",pat);
854 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
857 strCapacity++; /* increment for NUL termination */
858 /* allocate the str and call the api again */
859 str = (UChar*) malloc(U_SIZEOF_UCHAR * strCapacity);
860 strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
861 /* iterate over the scripts and figure out if the string contained is actually
864 for( j = 0; j < scriptsLen; j++){
865 if(uset_containsString(scripts[j],str, strCapacity) == TRUE){
866 existsInScript = TRUE;
869 if(existsInScript == FALSE){
870 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
879 for(i = 0; i<scriptsLen; i++){
880 uset_close(scripts[i]);
884 static void VerifyTranslation(void) {
885 UResourceBundle *root, *currentLocale;
886 int32_t locCount = uloc_countAvailable();
888 UErrorCode errorCode = U_ZERO_ERROR;
890 UScriptCode scripts[USCRIPT_CODE_LIMIT];
894 UResourceBundle *resArray;
897 log_data_err("At least root needs to be installed\n");
900 root = ures_openDirect(NULL, "root", &errorCode);
901 if(U_FAILURE(errorCode)) {
902 log_data_err("Can't open root\n");
905 for (locIndex = 0; locIndex < locCount; locIndex++) {
906 USet * mergedExemplarSet = NULL;
907 errorCode=U_ZERO_ERROR;
908 currLoc = uloc_getAvailable(locIndex);
909 currentLocale = ures_open(NULL, currLoc, &errorCode);
910 if(errorCode != U_ZERO_ERROR) {
911 if(U_SUCCESS(errorCode)) {
912 /* It's installed, but there is no data.
913 It's installed for the g18n white paper [grhoten] */
914 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
915 uloc_getAvailable(locIndex));
917 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
918 u_errorName(errorCode),
919 uloc_getAvailable(locIndex));
921 ures_close(currentLocale);
925 UErrorCode exemplarStatus = U_ZERO_ERROR;
926 ULocaleData * uld = ulocdata_open(currLoc, &exemplarStatus);
927 if (U_SUCCESS(exemplarStatus)) {
928 USet * exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_STANDARD, &exemplarStatus);
929 if (U_SUCCESS(exemplarStatus)) {
930 mergedExemplarSet = uset_cloneAsThawed(exemplarSet);
931 uset_close(exemplarSet);
932 exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_AUXILIARY, &exemplarStatus);
933 if (U_SUCCESS(exemplarStatus)) {
934 uset_addAll(mergedExemplarSet, exemplarSet);
935 uset_close(exemplarSet);
937 exemplarStatus = U_ZERO_ERROR;
938 exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_PUNCTUATION, &exemplarStatus);
939 if (U_SUCCESS(exemplarStatus)) {
940 uset_addAll(mergedExemplarSet, exemplarSet);
941 uset_close(exemplarSet);
944 log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc, u_errorName(errorCode));
948 log_err("error ulocdata_open for locale %s returned %s\n", currLoc, u_errorName(errorCode));
951 if (mergedExemplarSet == NULL /*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
952 log_verbose("skipping test for %s\n", currLoc);
954 //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
955 // log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
958 UChar langBuffer[128];
962 langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
963 if (U_FAILURE(errorCode)) {
964 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
967 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, mergedExemplarSet, FALSE, &badChar);
969 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
970 currLoc, strIdx, badChar);
973 langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
974 if (U_FAILURE(errorCode)) {
975 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
978 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
979 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
980 UResourceBundle* names = ures_getByKeyWithFallback(greg, "dayNames", NULL, &errorCode);
981 UResourceBundle* format = ures_getByKeyWithFallback(names, "format", NULL, &errorCode);
982 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
984 if (U_FAILURE(errorCode)) {
985 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
987 if (getTestOption(QUICK_OPTION)) {
991 end = ures_getSize(resArray);
994 if ((uprv_strncmp(currLoc,"lrc",3) == 0 || uprv_strncmp(currLoc,"mzn",3) == 0) &&
995 log_knownIssue("cldrbug:8899", "lrc and mzn locales don't have translated day names")) {
999 for (idx = 0; idx < end; idx++) {
1000 const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1001 if (U_FAILURE(errorCode)) {
1002 log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1005 strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, TRUE, &badChar);
1006 if ( strIdx >= 0 ) {
1007 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1008 currLoc, idx, strIdx, badChar);
1011 ures_close(resArray);
1015 names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode);
1016 format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode);
1017 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
1018 if (U_FAILURE(errorCode)) {
1019 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
1021 if (getTestOption(QUICK_OPTION)) {
1025 end = ures_getSize(resArray);
1028 for (idx = 0; idx < end; idx++) {
1029 const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1030 if (U_FAILURE(errorCode)) {
1031 log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1034 strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, TRUE, &badChar);
1036 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1037 currLoc, idx, strIdx, badChar);
1040 ures_close(resArray);
1046 errorCode = U_ZERO_ERROR;
1047 numScripts = uscript_getCode(currLoc, scripts, UPRV_LENGTHOF(scripts), &errorCode);
1048 if (strcmp(currLoc, "yi") == 0 && numScripts > 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1049 scripts[0] = USCRIPT_HEBREW;
1051 if (numScripts == 0) {
1052 log_err("uscript_getCode(%s) doesn't work.\n", currLoc);
1053 }else if(scripts[0] == USCRIPT_COMMON){
1054 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc);
1057 /* test that the scripts are a superset of exemplar characters. */
1059 ULocaleData *uld = ulocdata_open(currLoc,&errorCode);
1060 USet *exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode);
1061 /* test if exemplar characters are part of script code */
1062 findSetMatch(scripts, numScripts, exemplarSet, currLoc);
1063 uset_close(exemplarSet);
1064 ulocdata_close(uld);
1067 /* test that the paperSize API works */
1069 int32_t height=0, width=0;
1070 ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1071 if(U_FAILURE(errorCode)){
1072 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1074 if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){
1075 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1078 /* test that the MeasurementSystem API works */
1080 char fullLoc[ULOC_FULLNAME_CAPACITY];
1081 UMeasurementSystem measurementSystem;
1082 int32_t height = 0, width = 0;
1084 uloc_addLikelySubtags(currLoc, fullLoc, ULOC_FULLNAME_CAPACITY, &errorCode);
1086 errorCode = U_ZERO_ERROR;
1087 measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
1088 if (U_FAILURE(errorCode)) {
1089 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1091 if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_MM")!=NULL || strstr(fullLoc, "_LR")!=NULL ) {
1092 if(measurementSystem != UMS_US){
1093 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1095 } else if ( strstr(fullLoc, "_GB")!=NULL ) {
1096 if(measurementSystem != UMS_UK){
1097 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1099 } else if (measurementSystem != UMS_SI) {
1100 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1104 errorCode = U_ZERO_ERROR;
1105 ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1106 if (U_FAILURE(errorCode)) {
1107 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1109 if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_BZ")!=NULL || strstr(fullLoc, "_CA")!=NULL || strstr(fullLoc, "_CL")!=NULL ||
1110 strstr(fullLoc, "_CO")!=NULL || strstr(fullLoc, "_CR")!=NULL || strstr(fullLoc, "_GT")!=NULL || strstr(fullLoc, "_MX")!=NULL ||
1111 strstr(fullLoc, "_NI")!=NULL || strstr(fullLoc, "_PA")!=NULL || strstr(fullLoc, "_PH")!=NULL || strstr(fullLoc, "_PR")!=NULL ||
1112 strstr(fullLoc, "_SV")!=NULL || strstr(fullLoc, "_VE")!=NULL ) {
1113 if (height != 279 || width != 216) {
1114 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1116 } else if (height != 297 || width != 210) {
1117 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1122 if (mergedExemplarSet != NULL) {
1123 uset_close(mergedExemplarSet);
1125 ures_close(currentLocale);
1131 /* adjust this limit as appropriate */
1132 #define MAX_SCRIPTS_PER_LOCALE 8
1134 static void TestExemplarSet(void){
1135 int32_t i, j, k, m, n;
1136 int32_t equalCount = 0;
1137 UErrorCode ec = U_ZERO_ERROR;
1138 UEnumeration* avail;
1139 USet* exemplarSets[2];
1140 USet* unassignedSet;
1141 UScriptCode code[MAX_SCRIPTS_PER_LOCALE];
1142 USet* codeSets[MAX_SCRIPTS_PER_LOCALE];
1144 char cbuf[32]; /* 9 should be enough */
1145 UChar ubuf[64]; /* adjust as needed */
1146 UBool existsInScript;
1151 unassignedSet = NULL;
1152 exemplarSets[0] = NULL;
1153 exemplarSets[1] = NULL;
1154 for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1158 avail = ures_openAvailableLocales(NULL, &ec);
1159 if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END;
1160 n = uenum_count(avail, &ec);
1161 if (!assertSuccess("uenum_count", &ec)) goto END;
1163 u_uastrcpy(ubuf, "[:unassigned:]");
1164 unassignedSet = uset_openPattern(ubuf, -1, &ec);
1165 if (!assertSuccess("uset_openPattern", &ec)) goto END;
1168 const char* locale = uenum_next(avail, NULL, &ec);
1169 if (!assertSuccess("uenum_next", &ec)) goto END;
1170 log_verbose("%s\n", locale);
1171 for (k=0; k<2; ++k) {
1172 uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE;
1173 ULocaleData *uld = ulocdata_open(locale,&ec);
1174 USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec);
1175 uset_close(exemplarSets[k]);
1176 ulocdata_close(uld);
1177 exemplarSets[k] = exemplarSet;
1178 if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END;
1180 if (uset_containsSome(exemplarSet, unassignedSet)) {
1181 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale);
1183 codeLen = uscript_getCode(locale, code, 8, &ec);
1184 if (strcmp(locale, "yi") == 0 && codeLen > 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1185 code[0] = USCRIPT_HEBREW;
1187 if (!assertSuccess("uscript_getCode", &ec)) goto END;
1189 for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) {
1190 uset_close(codeSets[j]);
1193 for (j=0; j<codeLen; ++j) {
1194 uprv_strcpy(cbuf, "[:");
1196 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale);
1199 uprv_strcat(cbuf, uscript_getShortName(code[j]));
1200 uprv_strcat(cbuf, ":]");
1201 u_uastrcpy(ubuf, cbuf);
1202 codeSets[j] = uset_openPattern(ubuf, -1, &ec);
1204 if (!assertSuccess("uset_openPattern", &ec)) goto END;
1206 existsInScript = FALSE;
1207 itemCount = uset_getItemCount(exemplarSet);
1208 for (m=0; m<itemCount && !existsInScript; ++m) {
1209 strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf,
1210 UPRV_LENGTHOF(ubuf), &ec);
1211 /* failure here might mean str[] needs to be larger */
1212 if (!assertSuccess("uset_getItem", &ec)) goto END;
1214 for (j=0; j<codeLen; ++j) {
1215 if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) {
1216 existsInScript = TRUE;
1221 for (j=0; j<codeLen; ++j) {
1222 if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) {
1223 existsInScript = TRUE;
1230 if (existsInScript == FALSE){
1231 log_err("ExemplarSet containment failed for locale : %s\n", locale);
1234 assertTrue("case-folded is a superset",
1235 uset_containsAll(exemplarSets[1], exemplarSets[0]));
1236 if (uset_equals(exemplarSets[1], exemplarSets[0])) {
1240 /* Note: The case-folded set should sometimes be a strict superset
1241 and sometimes be equal. */
1242 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1243 equalCount > 0 && equalCount < n);
1247 uset_close(exemplarSets[0]);
1248 uset_close(exemplarSets[1]);
1249 uset_close(unassignedSet);
1250 for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1251 uset_close(codeSets[i]);
1255 enum { kUBufMax = 32 };
1256 static void TestLocaleDisplayPattern(void){
1258 UChar pattern[kUBufMax] = {0,};
1259 UChar separator[kUBufMax] = {0,};
1261 static const UChar enExpectPat[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1262 static const UChar enExpectSep[] = { 0x002C,0x0020,0 }; /* ", " */
1263 static const UChar zhExpectPat[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1264 static const UChar zhExpectSep[] = { 0xFF0C,0 };
1266 status = U_ZERO_ERROR;
1267 uld = ulocdata_open("en", &status);
1268 if(U_FAILURE(status)){
1269 log_data_err("ulocdata_open en error %s", u_errorName(status));
1271 ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1272 if (U_FAILURE(status)){
1273 log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status));
1274 } else if (u_strcmp(pattern, enExpectPat) != 0) {
1275 log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1277 status = U_ZERO_ERROR;
1278 ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1279 if (U_FAILURE(status)){
1280 log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status));
1281 } else if (u_strcmp(separator, enExpectSep) != 0) {
1282 log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1284 ulocdata_close(uld);
1287 status = U_ZERO_ERROR;
1288 uld = ulocdata_open("zh", &status);
1289 if(U_FAILURE(status)){
1290 log_data_err("ulocdata_open zh error %s", u_errorName(status));
1292 ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1293 if (U_FAILURE(status)){
1294 log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status));
1295 } else if (u_strcmp(pattern, zhExpectPat) != 0) {
1296 log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1298 status = U_ZERO_ERROR;
1299 ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1300 if (U_FAILURE(status)){
1301 log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status));
1302 } else if (u_strcmp(separator, zhExpectSep) != 0) {
1303 log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1305 ulocdata_close(uld);
1309 static void TestCoverage(void){
1310 ULocaleDataDelimiterType types[] = {
1311 ULOCDATA_QUOTATION_START, /* Quotation start */
1312 ULOCDATA_QUOTATION_END, /* Quotation end */
1313 ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
1314 ULOCDATA_ALT_QUOTATION_END, /* Alternate quotation end */
1315 ULOCDATA_DELIMITER_COUNT
1319 UErrorCode status = U_ZERO_ERROR;
1320 ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
1322 if(U_FAILURE(status)){
1323 log_data_err("ulocdata_open error");
1328 for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
1329 UChar result[32] = {0,};
1330 status = U_ZERO_ERROR;
1331 ulocdata_getDelimiter(uld, types[i], result, 32, &status);
1332 if (U_FAILURE(status)){
1333 log_err("ulocdata_getgetDelimiter error with type %d", types[i]);
1337 sub = ulocdata_getNoSubstitute(uld);
1338 ulocdata_setNoSubstitute(uld,sub);
1339 ulocdata_close(uld);
1342 static void TestIndexChars(void) {
1343 /* Very basic test of ULOCDATA_ES_INDEX.
1344 * No comprehensive test of data, just basic check that the code path is alive.
1346 UErrorCode status = U_ZERO_ERROR;
1348 USet *exemplarChars;
1351 uld = ulocdata_open("en", &status);
1352 exemplarChars = uset_openEmpty();
1353 indexChars = uset_openEmpty();
1354 ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
1355 ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
1356 if (U_FAILURE(status)) {
1357 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
1360 /* en data, standard exemplars are [a-z], lower case. */
1361 /* en data, index characters are [A-Z], upper case. */
1362 if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
1363 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1366 if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
1367 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1372 uset_close(exemplarChars);
1373 uset_close(indexChars);
1374 ulocdata_close(uld);
1379 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1380 static void TestCurrencyList(void){
1381 #if !UCONFIG_NO_FORMATTING
1382 UErrorCode errorCode = U_ZERO_ERROR;
1383 int32_t structLocaleCount, currencyCount;
1384 UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &errorCode);
1385 const char *isoCode, *structISOCode;
1386 UResourceBundle *subBundle;
1387 UResourceBundle *currencies = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
1388 if(U_FAILURE(errorCode)) {
1389 log_data_err("Can't open structLocale\n");
1392 currencies = ures_getByKey(currencies, "Currencies", currencies, &errorCode);
1393 currencyCount = uenum_count(en, &errorCode);
1394 structLocaleCount = ures_getSize(currencies);
1395 if (currencyCount != structLocaleCount) {
1396 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount, currencyCount);
1397 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1398 ures_resetIterator(currencies);
1399 while ((isoCode = uenum_next(en, NULL, &errorCode)) != NULL && ures_hasNext(currencies)) {
1400 subBundle = ures_getNextResource(currencies, NULL, &errorCode);
1401 structISOCode = ures_getKey(subBundle);
1402 ures_close(subBundle);
1403 if (strcmp(structISOCode, isoCode) != 0) {
1404 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode, isoCode);
1410 ures_close(currencies);
1416 static void TestAvailableIsoCodes(void){
1417 #if !UCONFIG_NO_FORMATTING
1418 UErrorCode errorCode = U_ZERO_ERROR;
1419 const char* eurCode = "EUR";
1420 const char* usdCode = "USD";
1421 const char* lastCode = "RHD";
1422 const char* zzzCode = "ZZZ";
1423 UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
1424 UDate date1970 = (UDate)0.0; /* year 1970 */
1425 UDate date1975 = (UDate)173448000000.0; /* year 1975 */
1426 UDate date1978 = (UDate)260172000000.0; /* year 1978 */
1427 UDate date1981 = (UDate)346896000000.0; /* year 1981 */
1428 UDate date1992 = (UDate)693792000000.0; /* year 1992 */
1429 UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
1431 /* testing available codes with no time ranges */
1432 u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
1433 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1434 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
1437 u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
1438 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1439 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
1442 u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
1443 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
1444 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
1447 u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
1448 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1449 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
1452 /* RHD was used from 1970-02-17 to 1980-04-18*/
1455 if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
1456 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
1459 if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) {
1460 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
1463 if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == TRUE) {
1464 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode);
1468 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == TRUE) {
1469 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode);
1472 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == FALSE) {
1473 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
1476 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) {
1477 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
1481 if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) {
1482 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
1485 if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) {
1486 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
1489 if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) {
1490 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
1493 if (ucurr_isAvailable(isoCode, date1970, date1981, &errorCode) == FALSE) {
1494 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
1497 if (ucurr_isAvailable(isoCode, date1981, date1992, &errorCode) == TRUE) {
1498 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode);
1501 if (ucurr_isAvailable(isoCode, date1950, date1970, &errorCode) == TRUE) {
1502 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode);
1505 /* wrong range - from > to*/
1506 if (ucurr_isAvailable(isoCode, date1975, date1970, &errorCode) == TRUE) {
1507 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode);
1508 } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1509 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
1516 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1518 void addCLDRTest(TestNode** root);
1520 void addCLDRTest(TestNode** root)
1522 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1523 TESTCASE(TestLocaleStructure);
1524 TESTCASE(TestCurrencyList);
1526 TESTCASE(TestConsistentCountryInfo);
1527 TESTCASE(VerifyTranslation);
1528 TESTCASE(TestExemplarSet);
1529 TESTCASE(TestLocaleDisplayPattern);
1530 TESTCASE(TestCoverage);
1531 TESTCASE(TestIndexChars);
1532 TESTCASE(TestAvailableIsoCodes);