1 /********************************************************************
3 * Copyright (c) 1997-2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
8 #include "unicode/ures.h"
9 #include "unicode/ucurr.h"
10 #include "unicode/ustring.h"
11 #include "unicode/uset.h"
12 #include "unicode/udat.h"
13 #include "unicode/uscript.h"
14 #include "unicode/ulocdata.h"
20 returns a new UnicodeSet that is a flattened form of the original
24 createFlattenSet(USet *origSet, UErrorCode *status) {
28 int32_t origItemCount = 0;
29 int32_t idx, graphmeSize;
32 if (U_FAILURE(*status)) {
33 log_err("createFlattenSet called with %s\n", u_errorName(*status));
36 newSet = uset_open(1, 0);
37 origItemCount = uset_getItemCount(origSet);
38 for (idx = 0; idx < origItemCount; idx++) {
39 graphmeSize = uset_getItem(origSet, idx,
41 graphme, (int32_t)(sizeof(graphme)/sizeof(graphme[0])),
43 if (U_FAILURE(*status)) {
44 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status));
45 *status = U_ZERO_ERROR;
48 uset_addAllCodePoints(newSet, graphme, graphmeSize);
51 uset_addRange(newSet, start, end);
54 uset_closeOver(newSet,USET_CASE_INSENSITIVE);
59 isCurrencyPreEuro(const char* currencyKey){
60 if( strcmp(currencyKey, "PTE") == 0 ||
61 strcmp(currencyKey, "ESP") == 0 ||
62 strcmp(currencyKey, "LUF") == 0 ||
63 strcmp(currencyKey, "GRD") == 0 ||
64 strcmp(currencyKey, "BEF") == 0 ||
65 strcmp(currencyKey, "ITL") == 0 ||
66 strcmp(currencyKey, "EEK") == 0){
71 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
73 TestKeyInRootRecursive(UResourceBundle *root, const char *rootName,
74 UResourceBundle *currentBundle, const char *locale) {
75 UErrorCode errorCode = U_ZERO_ERROR;
76 UResourceBundle *subRootBundle = NULL, *subBundle = NULL, *arr = NULL;
78 ures_resetIterator(root);
79 ures_resetIterator(currentBundle);
80 while (ures_hasNext(currentBundle)) {
81 const char *subBundleKey = NULL;
82 const char *currentBundleKey = NULL;
84 errorCode = U_ZERO_ERROR;
85 currentBundleKey = ures_getKey(currentBundle);
86 (void)currentBundleKey; /* Suppress set but not used warning. */
87 subBundle = ures_getNextResource(currentBundle, NULL, &errorCode);
88 if (U_FAILURE(errorCode)) {
89 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale, u_errorName(errorCode));
92 subBundleKey = ures_getKey(subBundle);
95 subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode);
96 if (U_FAILURE(errorCode)) {
97 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
99 ures_getKey(currentBundle),
102 ures_close(subBundle);
105 if (ures_getType(subRootBundle) != ures_getType(subBundle)) {
106 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
107 "\troot=%d, locale=%d\n",
109 ures_getKey(currentBundle),
111 ures_getType(subRootBundle),
112 ures_getType(subBundle));
113 ures_close(subBundle);
116 else if (ures_getType(subBundle) == URES_INT_VECTOR) {
118 int32_t subBundleSize;
120 UBool sameArray = TRUE;
121 const int32_t *subRootBundleArr = ures_getIntVector(subRootBundle, &minSize, &errorCode);
122 const int32_t *subBundleArr = ures_getIntVector(subBundle, &subBundleSize, &errorCode);
124 if (minSize > subBundleSize) {
125 minSize = subBundleSize;
126 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
128 ures_getKey(currentBundle),
132 for (idx = 0; idx < minSize && sameArray; idx++) {
133 if (subRootBundleArr[idx] != subBundleArr[idx]) {
136 if (strcmp(subBundleKey, "DateTimeElements") == 0
137 && (subBundleArr[idx] < 1 || 7 < subBundleArr[idx]))
139 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
142 ures_getKey(currentBundle),
146 /* Special exception es_US and DateTimeElements */
148 && !(strcmp(locale, "es_US") == 0 && strcmp(subBundleKey, "DateTimeElements") == 0))
150 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
152 ures_getKey(currentBundle),
156 else if (ures_getType(subBundle) == URES_ARRAY) {
157 UResourceBundle *subSubBundle = ures_getByIndex(subBundle, 0, NULL, &errorCode);
158 UResourceBundle *subSubRootBundle = ures_getByIndex(subRootBundle, 0, NULL, &errorCode);
160 if (U_SUCCESS(errorCode)
161 && (ures_getType(subSubBundle) == URES_ARRAY || ures_getType(subSubRootBundle) == URES_ARRAY))
163 /* Here is one of the recursive parts */
164 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
167 int32_t minSize = ures_getSize(subRootBundle);
169 UBool sameArray = TRUE;
171 if (minSize > ures_getSize(subBundle)) {
172 minSize = ures_getSize(subBundle);
175 if ((subBundleKey == NULL
176 || (subBundleKey != NULL && strcmp(subBundleKey, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey)))
177 && ures_getSize(subRootBundle) != ures_getSize(subBundle))
179 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
180 "\troot array size=%d, locale array size=%d\n",
182 ures_getKey(currentBundle),
184 ures_getSize(subRootBundle),
185 ures_getSize(subBundle));
188 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
189 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
191 ures_getKey(currentBundle),
193 ures_getSize(subBundle));
196 for (idx = 0; idx < minSize; idx++) {
197 int32_t rootStrLen, localeStrLen;
198 const UChar *rootStr = ures_getStringByIndex(subRootBundle,idx,&rootStrLen,&errorCode);
199 const UChar *localeStr = ures_getStringByIndex(subBundle,idx,&localeStrLen,&errorCode);
200 if (rootStr && localeStr && U_SUCCESS(errorCode)) {
201 if (u_strcmp(rootStr, localeStr) != 0) {
206 if ( rootStrLen > 1 && rootStr[0] == 0x41 && rootStr[1] >= 0x30 && rootStr[1] <= 0x39 ) {
207 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
208 /* string. Attempt to read it as an array. */
209 errorCode = U_ZERO_ERROR;
210 arr = ures_getByIndex(subBundle,idx,NULL,&errorCode);
211 if (U_FAILURE(errorCode)) {
212 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
214 ures_getKey(currentBundle),
219 if (ures_getType(arr) != URES_ARRAY || ures_getSize(arr) != (int32_t)rootStr[1] - 0x30) {
220 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",
223 ures_getKey(currentBundle),
229 localeStr = ures_getStringByIndex(arr,0,&localeStrLen,&errorCode);
231 if (U_FAILURE(errorCode)) {
232 log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
234 ures_getKey(currentBundle),
240 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
242 ures_getKey(currentBundle),
248 if (localeStr[0] == (UChar)0x20) {
249 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
252 ures_getKey(currentBundle),
255 else if ((localeStr[localeStrLen - 1] == (UChar)0x20) && (strcmp(subBundleKey,"separator") != 0)) {
256 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
259 ures_getKey(currentBundle),
262 else if (subBundleKey != NULL
263 && strcmp(subBundleKey, "DateTimePatterns") == 0)
266 const UChar *localeStrItr = localeStr;
267 while (*localeStrItr) {
268 if (*localeStrItr == (UChar)0x27 /* ' */) {
271 else if ((quoted % 2) == 0) {
272 /* Search for unquoted characters */
273 if (4 <= idx && idx <= 7
274 && (*localeStrItr == (UChar)0x6B /* k */
275 || *localeStrItr == (UChar)0x48 /* H */
276 || *localeStrItr == (UChar)0x6D /* m */
277 || *localeStrItr == (UChar)0x73 /* s */
278 || *localeStrItr == (UChar)0x53 /* S */
279 || *localeStrItr == (UChar)0x61 /* a */
280 || *localeStrItr == (UChar)0x68 /* h */
281 || *localeStrItr == (UChar)0x7A /* z */))
283 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
288 else if (0 <= idx && idx <= 3
289 && (*localeStrItr == (UChar)0x47 /* G */
290 || *localeStrItr == (UChar)0x79 /* y */
291 || *localeStrItr == (UChar)0x4D /* M */
292 || *localeStrItr == (UChar)0x64 /* d */
293 || *localeStrItr == (UChar)0x45 /* E */
294 || *localeStrItr == (UChar)0x44 /* D */
295 || *localeStrItr == (UChar)0x46 /* F */
296 || *localeStrItr == (UChar)0x77 /* w */
297 || *localeStrItr == (UChar)0x57 /* W */))
299 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
308 else if (idx == 4 && subBundleKey != NULL
309 && strcmp(subBundleKey, "NumberElements") == 0
310 && u_charDigitValue(localeStr[0]) != 0)
312 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
318 (void)sameArray; /* Suppress set but not used warning. */
319 /* if (sameArray && strcmp(rootName, "root") == 0) {
320 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
322 ures_getKey(currentBundle),
326 ures_close(subSubBundle);
327 ures_close(subSubRootBundle);
329 else if (ures_getType(subBundle) == URES_STRING) {
331 const UChar *string = ures_getString(subBundle, &len, &errorCode);
332 if (U_FAILURE(errorCode) || string == NULL) {
333 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
335 ures_getKey(currentBundle),
337 } else if (string[0] == (UChar)0x20) {
338 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
340 ures_getKey(currentBundle),
342 /* localeDisplayPattern/separator can end with a space */
343 } else if (string[len - 1] == (UChar)0x20 && (strcmp(subBundleKey,"separator"))) {
344 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
346 ures_getKey(currentBundle),
348 } else if (strcmp(subBundleKey, "localPatternChars") == 0) {
349 /* Note: We no longer import localPatternChars data starting
350 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
353 /* Check well-formedness of localPatternChars. First, the
354 * length must match the number of fields defined by
355 * DateFormat. Second, each character in the string must
356 * be in the set [A-Za-z]. Finally, each character must be
360 #if !UCONFIG_NO_FORMATTING
361 if (len != UDAT_FIELD_COUNT) {
362 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
367 /* Check char validity. */
368 for (i=0; i<len; ++i) {
369 if (!((string[i] >= 65/*'A'*/ && string[i] <= 90/*'Z'*/) ||
370 (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) {
371 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
376 /* Do O(n^2) check for duplicate chars. */
377 for (j=0; j<i; ++j) {
378 if (string[j] == string[i]) {
379 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
387 /* No fallback was done. Check for duplicate data */
388 /* The ures_* API does not do fallback of sub-resource bundles,
389 So we can't do this now. */
391 else if (strcmp(locale, "root") != 0 && errorCode == U_ZERO_ERROR) {
393 const UChar *rootString = ures_getString(subRootBundle, &len, &errorCode);
394 if (U_FAILURE(errorCode) || rootString == NULL) {
395 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
396 ures_getKey(subRootBundle),
397 ures_getKey(currentBundle));
399 } else if (u_strcmp(string, rootString) == 0) {
400 if (strcmp(locale, "de_CH") != 0 && strcmp(subBundleKey, "Countries") != 0 &&
401 strcmp(subBundleKey, "Version") != 0) {
402 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
403 ures_getKey(subRootBundle),
404 ures_getKey(currentBundle),
408 /* Ignore for now. */
409 /* Can be fixed if fallback through de locale was done. */
410 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
416 else if (ures_getType(subBundle) == URES_TABLE) {
417 if (strcmp(subBundleKey, "availableFormats")!=0) {
418 /* Here is one of the recursive parts */
419 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
422 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
425 else if (ures_getType(subBundle) == URES_BINARY || ures_getType(subBundle) == URES_INT) {
426 /* Can't do anything to check it */
427 /* We'll assume it's all correct */
428 if (strcmp(subBundleKey, "MeasurementSystem") != 0) {
429 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
431 ures_getKey(currentBundle),
434 /* Testing for MeasurementSystem is done in VerifyTranslation */
437 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
438 ures_getType(subBundle),
440 ures_getKey(currentBundle),
443 ures_close(subRootBundle);
444 ures_close(subBundle);
450 testLCID(UResourceBundle *currentBundle,
451 const char *localeName)
453 UErrorCode status = U_ZERO_ERROR;
454 uint32_t expectedLCID;
455 char lcidStringC[64] = {0};
458 expectedLCID = uloc_getLCID(localeName);
459 if (expectedLCID == 0) {
460 log_verbose("INFO: %-5s does not have any LCID mapping\n",
465 status = U_ZERO_ERROR;
466 len = uprv_convertToPosix(expectedLCID, lcidStringC, sizeof(lcidStringC)/sizeof(lcidStringC[0]) - 1, &status);
467 if (U_FAILURE(status)) {
468 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
469 expectedLCID, u_errorName(status));
471 lcidStringC[len] = 0;
473 if(strcmp(localeName, lcidStringC) != 0) {
476 uloc_getLanguage(localeName, langName, sizeof(langName), &status);
477 uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status);
479 if (strcmp(langName, langLCID) == 0) {
480 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
481 localeName, lcidStringC, expectedLCID);
484 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
485 localeName, expectedLCID, lcidStringC);
490 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
492 TestLocaleStructure(void) {
493 // This test checks the locale structure against a key file located
494 // at source/test/testdata/structLocale.txt. When adding new data to
495 // a loale file such as en.txt, the structLocale.txt file must be changed
496 // too to include the the template of the new data. Otherwise this test
499 UResourceBundle *root, *currentLocale;
500 int32_t locCount = uloc_countAvailable();
502 UErrorCode errorCode = U_ZERO_ERROR;
503 const char *currLoc, *resolvedLoc;
505 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
506 /* char locName[ULOC_FULLNAME_CAPACITY];
509 for (locIndex = 0; locIndex < locCount; locIndex++) {
510 errorCode=U_ZERO_ERROR;
511 strcpy(locName, uloc_getAvailable(locIndex));
512 locNamePtr = strrchr(locName, '_');
517 strcpy(locName, "root");
520 root = ures_openDirect(NULL, locName, &errorCode);
521 if(U_FAILURE(errorCode)) {
522 log_err("Can't open %s\n", locName);
527 log_data_err("At least root needs to be installed\n");
530 root = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
531 if(U_FAILURE(errorCode)) {
532 log_data_err("Can't open structLocale\n");
535 for (locIndex = 0; locIndex < locCount; locIndex++) {
536 errorCode=U_ZERO_ERROR;
537 currLoc = uloc_getAvailable(locIndex);
538 currentLocale = ures_open(NULL, currLoc, &errorCode);
539 if(errorCode != U_ZERO_ERROR) {
540 if(U_SUCCESS(errorCode)) {
541 /* It's installed, but there is no data.
542 It's installed for the g18n white paper [grhoten] */
543 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
544 uloc_getAvailable(locIndex), u_errorName(errorCode));
546 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
547 u_errorName(errorCode),
548 uloc_getAvailable(locIndex));
550 ures_close(currentLocale);
553 ures_getStringByKey(currentLocale, "Version", NULL, &errorCode);
554 if(errorCode != U_ZERO_ERROR) {
555 log_err("No version information is available for locale %s, and it should be!\n",
558 else if (ures_getStringByKey(currentLocale, "Version", NULL, &errorCode)[0] == (UChar)(0x78)) {
559 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
562 resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode);
563 if (strcmp(resolvedLoc, currLoc) != 0) {
564 /* All locales have at least a Version resource.
565 If it's absolutely empty, then the previous test will fail too.*/
566 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
567 currLoc, resolvedLoc);
569 TestKeyInRootRecursive(root, "root", currentLocale, currLoc);
571 testLCID(currentLocale, currLoc);
573 ures_close(currentLocale);
581 compareArrays(const char *keyName,
582 UResourceBundle *fromArray, const char *fromLocale,
583 UResourceBundle *toArray, const char *toLocale,
584 int32_t start, int32_t end)
586 int32_t fromSize = ures_getSize(fromArray);
587 int32_t toSize = ures_getSize(fromArray);
589 UErrorCode errorCode = U_ZERO_ERROR;
591 if (fromSize > toSize) {
593 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
598 for (idx = start; idx <= end; idx++) {
599 const UChar *fromBundleStr = ures_getStringByIndex(fromArray, idx, NULL, &errorCode);
600 const UChar *toBundleStr = ures_getStringByIndex(toArray, idx, NULL, &errorCode);
601 if (fromBundleStr && toBundleStr && u_strcmp(fromBundleStr, toBundleStr) != 0)
603 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
607 austrdup(fromBundleStr),
609 austrdup(toBundleStr));
615 compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) {
616 UErrorCode errorCode = U_ZERO_ERROR;
617 UResourceBundle *fromArray, *toArray;
618 UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode);
619 UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode);
620 UResourceBundle *toCalendar, *fromCalendar, *toGregorian, *fromGregorian;
622 if(U_FAILURE(errorCode)) {
623 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale, toLocale, u_errorName(errorCode));
626 fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode);
627 fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode);
629 toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode);
630 toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode);
632 fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode);
633 toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode);
634 if (strcmp(fromLocale, "en_CA") != 0)
636 /* The first one is probably localized. */
637 compareArrays("CurrencyElements", fromArray, fromLocale, toArray, toLocale, 1, 2);
639 ures_close(fromArray);
642 fromArray = ures_getByKey(fromLocaleBund, "NumberPatterns", NULL, &errorCode);
643 toArray = ures_getByKey(toLocaleBund, "NumberPatterns", NULL, &errorCode);
644 if (strcmp(fromLocale, "en_CA") != 0)
646 compareArrays("NumberPatterns", fromArray, fromLocale, toArray, toLocale, 0, 3);
648 ures_close(fromArray);
651 /* Difficult to test properly */
653 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
654 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
656 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
658 ures_close(fromArray);
659 ures_close(toArray);*/
661 fromArray = ures_getByKey(fromLocaleBund, "NumberElements", NULL, &errorCode);
662 toArray = ures_getByKey(toLocaleBund, "NumberElements", NULL, &errorCode);
663 if (strcmp(fromLocale, "en_CA") != 0)
665 compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 0, 3);
666 /* Index 4 is a script based 0 */
667 compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 5, 10);
669 ures_close(fromArray);
671 ures_close(fromCalendar);
672 ures_close(toCalendar);
673 ures_close(fromGregorian);
674 ures_close(toGregorian);
676 ures_close(fromLocaleBund);
677 ures_close(toLocaleBund);
681 TestConsistentCountryInfo(void) {
682 /* UResourceBundle *fromLocale, *toLocale;*/
683 int32_t locCount = uloc_countAvailable();
684 int32_t fromLocIndex, toLocIndex;
686 int32_t fromCountryLen, toCountryLen;
687 char fromCountry[ULOC_FULLNAME_CAPACITY], toCountry[ULOC_FULLNAME_CAPACITY];
689 int32_t fromVariantLen, toVariantLen;
690 char fromVariant[ULOC_FULLNAME_CAPACITY], toVariant[ULOC_FULLNAME_CAPACITY];
692 UErrorCode errorCode = U_ZERO_ERROR;
694 for (fromLocIndex = 0; fromLocIndex < locCount; fromLocIndex++) {
695 const char *fromLocale = uloc_getAvailable(fromLocIndex);
697 errorCode=U_ZERO_ERROR;
698 fromCountryLen = uloc_getCountry(fromLocale, fromCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
699 if (fromCountryLen <= 0) {
700 /* Ignore countryless locales */
703 fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
704 if (fromVariantLen > 0) {
705 /* Most variants are ignorable like PREEURO, or collation variants. */
708 /* Start comparing only after the current index.
709 Previous loop should have already compared fromLocIndex.
711 for (toLocIndex = fromLocIndex + 1; toLocIndex < locCount; toLocIndex++) {
712 const char *toLocale = uloc_getAvailable(toLocIndex);
714 toCountryLen = uloc_getCountry(toLocale, toCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
715 if(U_FAILURE(errorCode)) {
716 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
717 fromLocale, toLocale, u_errorName(errorCode));
721 if (toCountryLen <= 0) {
722 /* Ignore countryless locales */
725 toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
726 if (toVariantLen > 0) {
727 /* Most variants are ignorable like PREEURO, or collation variants. */
728 /* They're a variant for a reason. */
731 if (strcmp(fromCountry, toCountry) == 0) {
732 log_verbose("comparing fromLocale=%s toLocale=%s\n",
733 fromLocale, toLocale);
734 compareConsistentCountryInfo(fromLocale, toLocale);
741 findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize,
742 USet * mergedExemplarSet,
743 UBool ignoreNumbers, UChar* badCharPtr) {
744 UErrorCode errorCode = U_ZERO_ERROR;
747 if (mergedExemplarSet == NULL) {
750 exemplarSet = createFlattenSet(mergedExemplarSet, &errorCode);
751 if (U_FAILURE(errorCode)) {
752 log_err("%s: error createFlattenSet returned %s\n", currLoc, u_errorName(errorCode));
756 for (strIdx = 0; strIdx < langSize; strIdx++) {
757 if (!uset_contains(exemplarSet, string[strIdx])
758 && 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
759 && string[strIdx] != 0x200C && string[strIdx] != 0x200D) {
760 if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) {
761 uset_close(exemplarSet);
763 *badCharPtr = string[strIdx];
769 uset_close(exemplarSet);
775 /* include non-invariant chars */
777 myUCharsToChars(const UChar* us, char* cs, int32_t len){
789 findSetMatch( UScriptCode *scriptCodes, int32_t scriptsLen,
792 USet *scripts[10]= {0};
793 char pattern[256] = { '[', ':', 0x000 };
795 UChar uPattern[256] = {0};
796 UErrorCode status = U_ZERO_ERROR;
799 /* create the sets with script codes */
800 for(i = 0; i<scriptsLen; i++){
801 strcat(pattern, uscript_getShortName(scriptCodes[i]));
802 strcat(pattern, ":]");
803 patternLen = (int32_t)strlen(pattern);
804 u_charsToUChars(pattern, uPattern, patternLen);
805 scripts[i] = uset_openPattern(uPattern, patternLen, &status);
806 if(U_FAILURE(status)){
807 log_err("Could not create set for pattern %s. Error: %s\n", pattern, u_errorName(status));
812 if (strcmp(locale, "uk") == 0 || strcmp(locale, "uk_UA") == 0) {
813 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
814 uset_add(scripts[0], 0x2bc);
816 if(U_SUCCESS(status)){
817 UBool existsInScript = FALSE;
818 /* iterate over the exemplarSet and ascertain if all
819 * UChars in exemplarSet belong to the scripts returned
822 int32_t count = uset_getItemCount(exemplarSet);
824 for( i=0; i < count; i++){
828 int32_t strCapacity = 0;
830 strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
831 if(U_SUCCESS(status)){
833 if(strCapacity == 0){
834 /* ok the item is a range */
835 for( j = 0; j < scriptsLen; j++){
836 if(uset_containsRange(scripts[j], start, end) == TRUE){
837 existsInScript = TRUE;
840 if(existsInScript == FALSE){
841 for( j = 0; j < scriptsLen; j++){
842 UChar toPattern[500]={'\0'};
843 char pat[500]={'\0'};
844 int32_t len = uset_toPattern(scripts[j], toPattern, 500, TRUE, &status);
845 len = myUCharsToChars(toPattern, pat, len);
846 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));
848 log_err("Pattern: %s\n",pat);
851 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
854 strCapacity++; /* increment for NUL termination */
855 /* allocate the str and call the api again */
856 str = (UChar*) malloc(U_SIZEOF_UCHAR * strCapacity);
857 strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
858 /* iterate over the scripts and figure out if the string contained is actually
861 for( j = 0; j < scriptsLen; j++){
862 if(uset_containsString(scripts[j],str, strCapacity) == TRUE){
863 existsInScript = TRUE;
866 if(existsInScript == FALSE){
867 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
876 for(i = 0; i<scriptsLen; i++){
877 uset_close(scripts[i]);
881 static void VerifyTranslation(void) {
882 UResourceBundle *root, *currentLocale;
883 int32_t locCount = uloc_countAvailable();
885 UErrorCode errorCode = U_ZERO_ERROR;
887 UScriptCode scripts[USCRIPT_CODE_LIMIT];
891 UResourceBundle *resArray;
894 log_data_err("At least root needs to be installed\n");
897 root = ures_openDirect(NULL, "root", &errorCode);
898 if(U_FAILURE(errorCode)) {
899 log_data_err("Can't open root\n");
902 for (locIndex = 0; locIndex < locCount; locIndex++) {
903 USet * mergedExemplarSet = NULL;
904 errorCode=U_ZERO_ERROR;
905 currLoc = uloc_getAvailable(locIndex);
906 currentLocale = ures_open(NULL, currLoc, &errorCode);
907 if(errorCode != U_ZERO_ERROR) {
908 if(U_SUCCESS(errorCode)) {
909 /* It's installed, but there is no data.
910 It's installed for the g18n white paper [grhoten] */
911 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
912 uloc_getAvailable(locIndex));
914 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
915 u_errorName(errorCode),
916 uloc_getAvailable(locIndex));
918 ures_close(currentLocale);
922 UErrorCode exemplarStatus = U_ZERO_ERROR;
923 ULocaleData * uld = ulocdata_open(currLoc, &exemplarStatus);
924 if (U_SUCCESS(exemplarStatus)) {
925 USet * exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_STANDARD, &exemplarStatus);
926 if (U_SUCCESS(exemplarStatus)) {
927 mergedExemplarSet = uset_cloneAsThawed(exemplarSet);
928 uset_close(exemplarSet);
929 exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_AUXILIARY, &exemplarStatus);
930 if (U_SUCCESS(exemplarStatus)) {
931 uset_addAll(mergedExemplarSet, exemplarSet);
932 uset_close(exemplarSet);
934 exemplarStatus = U_ZERO_ERROR;
935 exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_PUNCTUATION, &exemplarStatus);
936 if (U_SUCCESS(exemplarStatus)) {
937 uset_addAll(mergedExemplarSet, exemplarSet);
938 uset_close(exemplarSet);
941 log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc, u_errorName(errorCode));
945 log_err("error ulocdata_open for locale %s returned %s\n", currLoc, u_errorName(errorCode));
948 if (mergedExemplarSet == NULL /*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
949 log_verbose("skipping test for %s\n", currLoc);
951 //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
952 // log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
955 UChar langBuffer[128];
959 langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode);
960 if (U_FAILURE(errorCode)) {
961 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
964 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, mergedExemplarSet, FALSE, &badChar);
966 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
967 currLoc, strIdx, badChar);
970 langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode);
971 if (U_FAILURE(errorCode)) {
972 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
975 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
976 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
977 UResourceBundle* names = ures_getByKeyWithFallback(greg, "dayNames", NULL, &errorCode);
978 UResourceBundle* format = ures_getByKeyWithFallback(names, "format", NULL, &errorCode);
979 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
981 if (U_FAILURE(errorCode)) {
982 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
984 if (getTestOption(QUICK_OPTION)) {
988 end = ures_getSize(resArray);
992 for (idx = 0; idx < end; idx++) {
993 const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
994 if (U_FAILURE(errorCode)) {
995 log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
998 if (uprv_strstr(currLoc, "uz_Arab") != currLoc || !log_knownIssue("10405", "skipping exemplar check: %s", currLoc)) { /* TODO: FIX or REMOVE this test! */
999 strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, TRUE, &badChar);
1001 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1002 currLoc, idx, strIdx, badChar);
1006 ures_close(resArray);
1010 names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode);
1011 format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode);
1012 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
1013 if (U_FAILURE(errorCode)) {
1014 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
1016 if (getTestOption(QUICK_OPTION)) {
1020 end = ures_getSize(resArray);
1023 for (idx = 0; idx < end; idx++) {
1024 const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1025 if (U_FAILURE(errorCode)) {
1026 log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1029 if (uprv_strstr(currLoc, "uz_Arab") != currLoc || !log_knownIssue("10405", "skipping exemplar check: %s", currLoc)) { /* TODO: FIX or REMOVE this test! */
1030 strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, TRUE, &badChar);
1032 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1033 currLoc, idx, strIdx, badChar);
1037 ures_close(resArray);
1043 errorCode = U_ZERO_ERROR;
1044 numScripts = uscript_getCode(currLoc, scripts, sizeof(scripts)/sizeof(scripts[0]), &errorCode);
1045 if (numScripts == 0) {
1046 log_err("uscript_getCode(%s) doesn't work.\n", currLoc);
1047 }else if(scripts[0] == USCRIPT_COMMON){
1048 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc);
1051 /* test that the scripts are a superset of exemplar characters. */
1053 ULocaleData *uld = ulocdata_open(currLoc,&errorCode);
1054 USet *exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode);
1055 /* test if exemplar characters are part of script code */
1056 findSetMatch(scripts, numScripts, exemplarSet, currLoc);
1057 uset_close(exemplarSet);
1058 ulocdata_close(uld);
1061 /* test that the paperSize API works */
1063 int32_t height=0, width=0;
1064 ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1065 if(U_FAILURE(errorCode)){
1066 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1068 if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){
1069 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1072 /* test that the MeasurementSystem API works */
1074 char fullLoc[ULOC_FULLNAME_CAPACITY];
1075 UMeasurementSystem measurementSystem;
1076 int32_t height = 0, width = 0;
1078 uloc_addLikelySubtags(currLoc, fullLoc, ULOC_FULLNAME_CAPACITY, &errorCode);
1080 errorCode = U_ZERO_ERROR;
1081 measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
1082 if (U_FAILURE(errorCode)) {
1083 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1085 if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_MM")!=NULL || strstr(fullLoc, "_LR")!=NULL ) {
1086 if(measurementSystem != UMS_US){
1087 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1089 } else if (measurementSystem != UMS_SI) {
1090 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1094 errorCode = U_ZERO_ERROR;
1095 ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1096 if (U_FAILURE(errorCode)) {
1097 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1099 if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_BZ")!=NULL || strstr(fullLoc, "_CA")!=NULL || strstr(fullLoc, "_CL")!=NULL ||
1100 strstr(fullLoc, "_CO")!=NULL || strstr(fullLoc, "_CR")!=NULL || strstr(fullLoc, "_GT")!=NULL || strstr(fullLoc, "_MX")!=NULL ||
1101 strstr(fullLoc, "_NI")!=NULL || strstr(fullLoc, "_PA")!=NULL || strstr(fullLoc, "_PH")!=NULL || strstr(fullLoc, "_PR")!=NULL ||
1102 strstr(fullLoc, "_SV")!=NULL || strstr(fullLoc, "_VE")!=NULL ) {
1103 if (height != 279 || width != 216) {
1104 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1106 } else if (height != 297 || width != 210) {
1107 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1112 if (mergedExemplarSet != NULL) {
1113 uset_close(mergedExemplarSet);
1115 ures_close(currentLocale);
1121 /* adjust this limit as appropriate */
1122 #define MAX_SCRIPTS_PER_LOCALE 8
1124 static void TestExemplarSet(void){
1125 int32_t i, j, k, m, n;
1126 int32_t equalCount = 0;
1127 UErrorCode ec = U_ZERO_ERROR;
1128 UEnumeration* avail;
1129 USet* exemplarSets[2];
1130 USet* unassignedSet;
1131 UScriptCode code[MAX_SCRIPTS_PER_LOCALE];
1132 USet* codeSets[MAX_SCRIPTS_PER_LOCALE];
1134 char cbuf[32]; /* 9 should be enough */
1135 UChar ubuf[64]; /* adjust as needed */
1136 UBool existsInScript;
1141 unassignedSet = NULL;
1142 exemplarSets[0] = NULL;
1143 exemplarSets[1] = NULL;
1144 for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1148 avail = ures_openAvailableLocales(NULL, &ec);
1149 if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END;
1150 n = uenum_count(avail, &ec);
1151 if (!assertSuccess("uenum_count", &ec)) goto END;
1153 u_uastrcpy(ubuf, "[:unassigned:]");
1154 unassignedSet = uset_openPattern(ubuf, -1, &ec);
1155 if (!assertSuccess("uset_openPattern", &ec)) goto END;
1158 const char* locale = uenum_next(avail, NULL, &ec);
1159 if (!assertSuccess("uenum_next", &ec)) goto END;
1160 log_verbose("%s\n", locale);
1161 for (k=0; k<2; ++k) {
1162 uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE;
1163 ULocaleData *uld = ulocdata_open(locale,&ec);
1164 USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec);
1165 uset_close(exemplarSets[k]);
1166 ulocdata_close(uld);
1167 exemplarSets[k] = exemplarSet;
1168 if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END;
1170 if (uset_containsSome(exemplarSet, unassignedSet)) {
1171 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale);
1173 codeLen = uscript_getCode(locale, code, 8, &ec);
1174 if (!assertSuccess("uscript_getCode", &ec)) goto END;
1176 for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) {
1177 uset_close(codeSets[j]);
1180 for (j=0; j<codeLen; ++j) {
1181 uprv_strcpy(cbuf, "[:");
1183 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale);
1186 uprv_strcat(cbuf, uscript_getShortName(code[j]));
1187 uprv_strcat(cbuf, ":]");
1188 u_uastrcpy(ubuf, cbuf);
1189 codeSets[j] = uset_openPattern(ubuf, -1, &ec);
1191 if (!assertSuccess("uset_openPattern", &ec)) goto END;
1193 existsInScript = FALSE;
1194 itemCount = uset_getItemCount(exemplarSet);
1195 for (m=0; m<itemCount && !existsInScript; ++m) {
1196 strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf,
1197 sizeof(ubuf)/sizeof(ubuf[0]), &ec);
1198 /* failure here might mean str[] needs to be larger */
1199 if (!assertSuccess("uset_getItem", &ec)) goto END;
1201 for (j=0; j<codeLen; ++j) {
1202 if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) {
1203 existsInScript = TRUE;
1208 for (j=0; j<codeLen; ++j) {
1209 if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) {
1210 existsInScript = TRUE;
1217 if (existsInScript == FALSE){
1218 log_err("ExemplarSet containment failed for locale : %s\n", locale);
1221 assertTrue("case-folded is a superset",
1222 uset_containsAll(exemplarSets[1], exemplarSets[0]));
1223 if (uset_equals(exemplarSets[1], exemplarSets[0])) {
1227 /* Note: The case-folded set should sometimes be a strict superset
1228 and sometimes be equal. */
1229 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1230 equalCount > 0 && equalCount < n);
1234 uset_close(exemplarSets[0]);
1235 uset_close(exemplarSets[1]);
1236 uset_close(unassignedSet);
1237 for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1238 uset_close(codeSets[i]);
1242 enum { kUBufMax = 32 };
1243 static void TestLocaleDisplayPattern(void){
1245 UChar pattern[kUBufMax] = {0,};
1246 UChar separator[kUBufMax] = {0,};
1248 static const UChar enExpectPat[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1249 static const UChar enExpectSep[] = { 0x002C,0x0020,0 }; /* ", " */
1250 static const UChar zhExpectPat[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1251 static const UChar zhExpectSep[] = { 0x3001,0 };
1253 status = U_ZERO_ERROR;
1254 uld = ulocdata_open("en", &status);
1255 if(U_FAILURE(status)){
1256 log_data_err("ulocdata_open en error %s", u_errorName(status));
1258 ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1259 if (U_FAILURE(status)){
1260 log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status));
1261 } else if (u_strcmp(pattern, enExpectPat) != 0) {
1262 log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1264 status = U_ZERO_ERROR;
1265 ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1266 if (U_FAILURE(status)){
1267 log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status));
1268 } else if (u_strcmp(separator, enExpectSep) != 0) {
1269 log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1271 ulocdata_close(uld);
1274 status = U_ZERO_ERROR;
1275 uld = ulocdata_open("zh", &status);
1276 if(U_FAILURE(status)){
1277 log_data_err("ulocdata_open zh error %s", u_errorName(status));
1279 ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1280 if (U_FAILURE(status)){
1281 log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status));
1282 } else if (u_strcmp(pattern, zhExpectPat) != 0) {
1283 log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1285 status = U_ZERO_ERROR;
1286 ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1287 if (U_FAILURE(status)){
1288 log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status));
1289 } else if (u_strcmp(separator, zhExpectSep) != 0) {
1290 log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1292 ulocdata_close(uld);
1296 static void TestCoverage(void){
1297 ULocaleDataDelimiterType types[] = {
1298 ULOCDATA_QUOTATION_START, /* Quotation start */
1299 ULOCDATA_QUOTATION_END, /* Quotation end */
1300 ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
1301 ULOCDATA_ALT_QUOTATION_END, /* Alternate quotation end */
1302 ULOCDATA_DELIMITER_COUNT
1306 UErrorCode status = U_ZERO_ERROR;
1307 ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
1309 if(U_FAILURE(status)){
1310 log_data_err("ulocdata_open error");
1315 for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
1316 UChar result[32] = {0,};
1317 status = U_ZERO_ERROR;
1318 ulocdata_getDelimiter(uld, types[i], result, 32, &status);
1319 if (U_FAILURE(status)){
1320 log_err("ulocdata_getgetDelimiter error with type %d", types[i]);
1324 sub = ulocdata_getNoSubstitute(uld);
1325 ulocdata_setNoSubstitute(uld,sub);
1326 ulocdata_close(uld);
1329 static void TestIndexChars(void) {
1330 /* Very basic test of ULOCDATA_ES_INDEX.
1331 * No comprehensive test of data, just basic check that the code path is alive.
1333 UErrorCode status = U_ZERO_ERROR;
1335 USet *exemplarChars;
1338 uld = ulocdata_open("en", &status);
1339 exemplarChars = uset_openEmpty();
1340 indexChars = uset_openEmpty();
1341 ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
1342 ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
1343 if (U_FAILURE(status)) {
1344 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
1347 /* en data, standard exemplars are [a-z], lower case. */
1348 /* en data, index characters are [A-Z], upper case. */
1349 if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
1350 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1353 if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
1354 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1359 uset_close(exemplarChars);
1360 uset_close(indexChars);
1361 ulocdata_close(uld);
1366 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1367 static void TestCurrencyList(void){
1368 #if !UCONFIG_NO_FORMATTING
1369 UErrorCode errorCode = U_ZERO_ERROR;
1370 int32_t structLocaleCount, currencyCount;
1371 UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &errorCode);
1372 const char *isoCode, *structISOCode;
1373 UResourceBundle *subBundle;
1374 UResourceBundle *currencies = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
1375 if(U_FAILURE(errorCode)) {
1376 log_data_err("Can't open structLocale\n");
1379 currencies = ures_getByKey(currencies, "Currencies", currencies, &errorCode);
1380 currencyCount = uenum_count(en, &errorCode);
1381 structLocaleCount = ures_getSize(currencies);
1382 if (currencyCount != structLocaleCount) {
1383 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount, currencyCount);
1384 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1385 ures_resetIterator(currencies);
1386 while ((isoCode = uenum_next(en, NULL, &errorCode)) != NULL && ures_hasNext(currencies)) {
1387 subBundle = ures_getNextResource(currencies, NULL, &errorCode);
1388 structISOCode = ures_getKey(subBundle);
1389 ures_close(subBundle);
1390 if (strcmp(structISOCode, isoCode) != 0) {
1391 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode, isoCode);
1397 ures_close(currencies);
1403 static void TestAvailableIsoCodes(void){
1404 #if !UCONFIG_NO_FORMATTING
1405 UErrorCode errorCode = U_ZERO_ERROR;
1406 const char* eurCode = "EUR";
1407 const char* usdCode = "USD";
1408 const char* lastCode = "RHD";
1409 const char* zzzCode = "ZZZ";
1410 UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
1411 UDate date1970 = (UDate)0.0; /* year 1970 */
1412 UDate date1975 = (UDate)173448000000.0; /* year 1975 */
1413 UDate date1978 = (UDate)260172000000.0; /* year 1978 */
1414 UDate date1981 = (UDate)346896000000.0; /* year 1981 */
1415 UDate date1992 = (UDate)693792000000.0; /* year 1992 */
1416 UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
1418 /* testing available codes with no time ranges */
1419 u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
1420 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1421 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
1424 u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
1425 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1426 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
1429 u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
1430 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
1431 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
1434 u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
1435 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1436 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
1439 /* RHD was used from 1970-02-17 to 1980-04-18*/
1442 if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
1443 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
1446 if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) {
1447 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
1450 if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == TRUE) {
1451 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode);
1455 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == TRUE) {
1456 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode);
1459 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == FALSE) {
1460 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
1463 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) {
1464 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
1468 if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) {
1469 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
1472 if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) {
1473 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
1476 if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) {
1477 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
1480 if (ucurr_isAvailable(isoCode, date1970, date1981, &errorCode) == FALSE) {
1481 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
1484 if (ucurr_isAvailable(isoCode, date1981, date1992, &errorCode) == TRUE) {
1485 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode);
1488 if (ucurr_isAvailable(isoCode, date1950, date1970, &errorCode) == TRUE) {
1489 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode);
1492 /* wrong range - from > to*/
1493 if (ucurr_isAvailable(isoCode, date1975, date1970, &errorCode) == TRUE) {
1494 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode);
1495 } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1496 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
1503 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1505 void addCLDRTest(TestNode** root);
1507 void addCLDRTest(TestNode** root)
1509 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1510 TESTCASE(TestLocaleStructure);
1511 TESTCASE(TestCurrencyList);
1513 TESTCASE(TestConsistentCountryInfo);
1514 TESTCASE(VerifyTranslation);
1515 TESTCASE(TestExemplarSet);
1516 TESTCASE(TestLocaleDisplayPattern);
1517 TESTCASE(TestCoverage);
1518 TESTCASE(TestIndexChars);
1519 TESTCASE(TestAvailableIsoCodes);