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/uloc.h"
15 #include "unicode/ulocdata.h"
21 returns a new UnicodeSet that is a flattened form of the original
25 createFlattenSet(USet
*origSet
, UErrorCode
*status
) {
29 int32_t origItemCount
= 0;
30 int32_t idx
, graphmeSize
;
33 if (U_FAILURE(*status
)) {
34 log_err("createFlattenSet called with %s\n", u_errorName(*status
));
37 newSet
= uset_open(1, 0);
38 origItemCount
= uset_getItemCount(origSet
);
39 for (idx
= 0; idx
< origItemCount
; idx
++) {
40 graphmeSize
= uset_getItem(origSet
, idx
,
42 graphme
, (int32_t)(sizeof(graphme
)/sizeof(graphme
[0])),
44 if (U_FAILURE(*status
)) {
45 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status
));
46 *status
= U_ZERO_ERROR
;
49 uset_addAllCodePoints(newSet
, graphme
, graphmeSize
);
52 uset_addRange(newSet
, start
, end
);
55 uset_closeOver(newSet
,USET_CASE_INSENSITIVE
);
60 isCurrencyPreEuro(const char* currencyKey
){
61 if( strcmp(currencyKey
, "PTE") == 0 ||
62 strcmp(currencyKey
, "ESP") == 0 ||
63 strcmp(currencyKey
, "LUF") == 0 ||
64 strcmp(currencyKey
, "GRD") == 0 ||
65 strcmp(currencyKey
, "BEF") == 0 ||
66 strcmp(currencyKey
, "ITL") == 0 ||
67 strcmp(currencyKey
, "EEK") == 0){
72 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
74 TestKeyInRootRecursive(UResourceBundle
*root
, const char *rootName
,
75 UResourceBundle
*currentBundle
, const char *locale
) {
76 UErrorCode errorCode
= U_ZERO_ERROR
;
77 UResourceBundle
*subRootBundle
= NULL
, *subBundle
= NULL
, *arr
= NULL
;
79 ures_resetIterator(root
);
80 ures_resetIterator(currentBundle
);
81 while (ures_hasNext(currentBundle
)) {
82 const char *subBundleKey
= NULL
;
83 const char *currentBundleKey
= NULL
;
85 errorCode
= U_ZERO_ERROR
;
86 currentBundleKey
= ures_getKey(currentBundle
);
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 /* if (sameArray && strcmp(rootName, "root") == 0) {
319 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
321 ures_getKey(currentBundle),
325 ures_close(subSubBundle
);
326 ures_close(subSubRootBundle
);
328 else if (ures_getType(subBundle
) == URES_STRING
) {
330 const UChar
*string
= ures_getString(subBundle
, &len
, &errorCode
);
331 if (U_FAILURE(errorCode
) || string
== NULL
) {
332 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
334 ures_getKey(currentBundle
),
336 } else if (string
[0] == (UChar
)0x20) {
337 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
339 ures_getKey(currentBundle
),
341 /* localeDisplayPattern/separator can end with a space */
342 } else if (string
[len
- 1] == (UChar
)0x20 && (strcmp(subBundleKey
,"separator"))) {
343 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
345 ures_getKey(currentBundle
),
347 } else if (strcmp(subBundleKey
, "localPatternChars") == 0) {
348 /* Note: We no longer import localPatternChars data starting
349 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
352 /* Check well-formedness of localPatternChars. First, the
353 * length must match the number of fields defined by
354 * DateFormat. Second, each character in the string must
355 * be in the set [A-Za-z]. Finally, each character must be
359 #if !UCONFIG_NO_FORMATTING
360 if (len
!= UDAT_FIELD_COUNT
) {
361 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
366 /* Check char validity. */
367 for (i
=0; i
<len
; ++i
) {
368 if (!((string
[i
] >= 65/*'A'*/ && string
[i
] <= 90/*'Z'*/) ||
369 (string
[i
] >= 97/*'a'*/ && string
[i
] <= 122/*'z'*/))) {
370 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
375 /* Do O(n^2) check for duplicate chars. */
376 for (j
=0; j
<i
; ++j
) {
377 if (string
[j
] == string
[i
]) {
378 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
386 /* No fallback was done. Check for duplicate data */
387 /* The ures_* API does not do fallback of sub-resource bundles,
388 So we can't do this now. */
390 else if (strcmp(locale
, "root") != 0 && errorCode
== U_ZERO_ERROR
) {
392 const UChar
*rootString
= ures_getString(subRootBundle
, &len
, &errorCode
);
393 if (U_FAILURE(errorCode
) || rootString
== NULL
) {
394 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
395 ures_getKey(subRootBundle
),
396 ures_getKey(currentBundle
));
398 } else if (u_strcmp(string
, rootString
) == 0) {
399 if (strcmp(locale
, "de_CH") != 0 && strcmp(subBundleKey
, "Countries") != 0 &&
400 strcmp(subBundleKey
, "Version") != 0) {
401 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
402 ures_getKey(subRootBundle
),
403 ures_getKey(currentBundle
),
407 /* Ignore for now. */
408 /* Can be fixed if fallback through de locale was done. */
409 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
415 else if (ures_getType(subBundle
) == URES_TABLE
) {
416 if (strcmp(subBundleKey
, "availableFormats")!=0) {
417 /* Here is one of the recursive parts */
418 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
421 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
424 else if (ures_getType(subBundle
) == URES_BINARY
|| ures_getType(subBundle
) == URES_INT
) {
425 /* Can't do anything to check it */
426 /* We'll assume it's all correct */
427 if (strcmp(subBundleKey
, "MeasurementSystem") != 0) {
428 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
430 ures_getKey(currentBundle
),
433 /* Testing for MeasurementSystem is done in VerifyTranslation */
436 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
437 ures_getType(subBundle
),
439 ures_getKey(currentBundle
),
442 ures_close(subRootBundle
);
443 ures_close(subBundle
);
449 testLCID(UResourceBundle
*currentBundle
,
450 const char *localeName
)
452 UErrorCode status
= U_ZERO_ERROR
;
453 uint32_t expectedLCID
;
454 char lcidStringC
[64] = {0};
456 expectedLCID
= uloc_getLCID(localeName
);
457 if (expectedLCID
== 0) {
458 log_verbose("INFO: %-5s does not have any LCID mapping\n",
463 status
= U_ZERO_ERROR
;
464 uprv_strcpy(lcidStringC
, uprv_convertToPosix(expectedLCID
, &status
));
465 if (U_FAILURE(status
)) {
466 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
467 expectedLCID
, u_errorName(status
));
470 if(strcmp(localeName
, lcidStringC
) != 0) {
473 uloc_getLanguage(localeName
, langName
, sizeof(langName
), &status
);
474 uloc_getLanguage(lcidStringC
, langLCID
, sizeof(langLCID
), &status
);
476 if (strcmp(langName
, langLCID
) == 0) {
477 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
478 localeName
, lcidStringC
, expectedLCID
);
481 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
482 localeName
, expectedLCID
, lcidStringC
);
487 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
489 TestLocaleStructure(void) {
490 UResourceBundle
*root
, *currentLocale
;
491 int32_t locCount
= uloc_countAvailable();
493 UErrorCode errorCode
= U_ZERO_ERROR
;
494 const char *currLoc
, *resolvedLoc
;
496 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
497 /* char locName[ULOC_FULLNAME_CAPACITY];
500 for (locIndex = 0; locIndex < locCount; locIndex++) {
501 errorCode=U_ZERO_ERROR;
502 strcpy(locName, uloc_getAvailable(locIndex));
503 locNamePtr = strrchr(locName, '_');
508 strcpy(locName, "root");
511 root = ures_openDirect(NULL, locName, &errorCode);
512 if(U_FAILURE(errorCode)) {
513 log_err("Can't open %s\n", locName);
518 log_data_err("At least root needs to be installed\n");
521 root
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
522 if(U_FAILURE(errorCode
)) {
523 log_data_err("Can't open structLocale\n");
526 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
527 errorCode
=U_ZERO_ERROR
;
528 currLoc
= uloc_getAvailable(locIndex
);
529 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
530 if(errorCode
!= U_ZERO_ERROR
) {
531 if(U_SUCCESS(errorCode
)) {
532 /* It's installed, but there is no data.
533 It's installed for the g18n white paper [grhoten] */
534 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
535 uloc_getAvailable(locIndex
), u_errorName(errorCode
));
537 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
538 u_errorName(errorCode
),
539 uloc_getAvailable(locIndex
));
541 ures_close(currentLocale
);
544 ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
);
545 if(errorCode
!= U_ZERO_ERROR
) {
546 log_err("No version information is available for locale %s, and it should be!\n",
549 else if (ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
)[0] == (UChar
)(0x78)) {
550 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
553 resolvedLoc
= ures_getLocaleByType(currentLocale
, ULOC_ACTUAL_LOCALE
, &errorCode
);
554 if (strcmp(resolvedLoc
, currLoc
) != 0) {
555 /* All locales have at least a Version resource.
556 If it's absolutely empty, then the previous test will fail too.*/
557 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
558 currLoc
, resolvedLoc
);
560 TestKeyInRootRecursive(root
, "root", currentLocale
, currLoc
);
562 testLCID(currentLocale
, currLoc
);
564 ures_close(currentLocale
);
572 compareArrays(const char *keyName
,
573 UResourceBundle
*fromArray
, const char *fromLocale
,
574 UResourceBundle
*toArray
, const char *toLocale
,
575 int32_t start
, int32_t end
)
577 int32_t fromSize
= ures_getSize(fromArray
);
578 int32_t toSize
= ures_getSize(fromArray
);
580 UErrorCode errorCode
= U_ZERO_ERROR
;
582 if (fromSize
> toSize
) {
584 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
589 for (idx
= start
; idx
<= end
; idx
++) {
590 const UChar
*fromBundleStr
= ures_getStringByIndex(fromArray
, idx
, NULL
, &errorCode
);
591 const UChar
*toBundleStr
= ures_getStringByIndex(toArray
, idx
, NULL
, &errorCode
);
592 if (fromBundleStr
&& toBundleStr
&& u_strcmp(fromBundleStr
, toBundleStr
) != 0)
594 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
598 austrdup(fromBundleStr
),
600 austrdup(toBundleStr
));
606 compareConsistentCountryInfo(const char *fromLocale
, const char *toLocale
) {
607 UErrorCode errorCode
= U_ZERO_ERROR
;
608 UResourceBundle
*fromArray
, *toArray
;
609 UResourceBundle
*fromLocaleBund
= ures_open(NULL
, fromLocale
, &errorCode
);
610 UResourceBundle
*toLocaleBund
= ures_open(NULL
, toLocale
, &errorCode
);
611 UResourceBundle
*toCalendar
, *fromCalendar
, *toGregorian
, *fromGregorian
;
613 if(U_FAILURE(errorCode
)) {
614 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale
, toLocale
, u_errorName(errorCode
));
617 fromCalendar
= ures_getByKey(fromLocaleBund
, "calendar", NULL
, &errorCode
);
618 fromGregorian
= ures_getByKeyWithFallback(fromCalendar
, "gregorian", NULL
, &errorCode
);
620 toCalendar
= ures_getByKey(toLocaleBund
, "calendar", NULL
, &errorCode
);
621 toGregorian
= ures_getByKeyWithFallback(toCalendar
, "gregorian", NULL
, &errorCode
);
623 fromArray
= ures_getByKey(fromLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
624 toArray
= ures_getByKey(toLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
625 if (strcmp(fromLocale
, "en_CA") != 0)
627 /* The first one is probably localized. */
628 compareArrays("CurrencyElements", fromArray
, fromLocale
, toArray
, toLocale
, 1, 2);
630 ures_close(fromArray
);
633 fromArray
= ures_getByKey(fromLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
634 toArray
= ures_getByKey(toLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
635 if (strcmp(fromLocale
, "en_CA") != 0)
637 compareArrays("NumberPatterns", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
639 ures_close(fromArray
);
642 /* Difficult to test properly */
644 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
645 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
647 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
649 ures_close(fromArray);
650 ures_close(toArray);*/
652 fromArray
= ures_getByKey(fromLocaleBund
, "NumberElements", NULL
, &errorCode
);
653 toArray
= ures_getByKey(toLocaleBund
, "NumberElements", NULL
, &errorCode
);
654 if (strcmp(fromLocale
, "en_CA") != 0)
656 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
657 /* Index 4 is a script based 0 */
658 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 5, 10);
660 ures_close(fromArray
);
662 ures_close(fromCalendar
);
663 ures_close(toCalendar
);
664 ures_close(fromGregorian
);
665 ures_close(toGregorian
);
667 ures_close(fromLocaleBund
);
668 ures_close(toLocaleBund
);
672 TestConsistentCountryInfo(void) {
673 /* UResourceBundle *fromLocale, *toLocale;*/
674 int32_t locCount
= uloc_countAvailable();
675 int32_t fromLocIndex
, toLocIndex
;
677 int32_t fromCountryLen
, toCountryLen
;
678 char fromCountry
[ULOC_FULLNAME_CAPACITY
], toCountry
[ULOC_FULLNAME_CAPACITY
];
680 int32_t fromVariantLen
, toVariantLen
;
681 char fromVariant
[ULOC_FULLNAME_CAPACITY
], toVariant
[ULOC_FULLNAME_CAPACITY
];
683 UErrorCode errorCode
= U_ZERO_ERROR
;
685 for (fromLocIndex
= 0; fromLocIndex
< locCount
; fromLocIndex
++) {
686 const char *fromLocale
= uloc_getAvailable(fromLocIndex
);
688 errorCode
=U_ZERO_ERROR
;
689 fromCountryLen
= uloc_getCountry(fromLocale
, fromCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
690 if (fromCountryLen
<= 0) {
691 /* Ignore countryless locales */
694 fromVariantLen
= uloc_getVariant(fromLocale
, fromVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
695 if (fromVariantLen
> 0) {
696 /* Most variants are ignorable like PREEURO, or collation variants. */
699 /* Start comparing only after the current index.
700 Previous loop should have already compared fromLocIndex.
702 for (toLocIndex
= fromLocIndex
+ 1; toLocIndex
< locCount
; toLocIndex
++) {
703 const char *toLocale
= uloc_getAvailable(toLocIndex
);
705 toCountryLen
= uloc_getCountry(toLocale
, toCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
706 if(U_FAILURE(errorCode
)) {
707 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
708 fromLocale
, toLocale
, u_errorName(errorCode
));
712 if (toCountryLen
<= 0) {
713 /* Ignore countryless locales */
716 toVariantLen
= uloc_getVariant(toLocale
, toVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
717 if (toVariantLen
> 0) {
718 /* Most variants are ignorable like PREEURO, or collation variants. */
719 /* They're a variant for a reason. */
722 if (strcmp(fromCountry
, toCountry
) == 0) {
723 log_verbose("comparing fromLocale=%s toLocale=%s\n",
724 fromLocale
, toLocale
);
725 compareConsistentCountryInfo(fromLocale
, toLocale
);
732 findStringSetMismatch(const char *currLoc
, const UChar
*string
, int32_t langSize
,
733 const UChar
*exemplarCharacters
, int32_t exemplarLen
,
734 UBool ignoreNumbers
, UChar
* badCharPtr
) {
735 UErrorCode errorCode
= U_ZERO_ERROR
;
736 USet
*origSet
= uset_openPatternOptions(exemplarCharacters
, exemplarLen
, USET_CASE_INSENSITIVE
, &errorCode
);
737 USet
*exemplarSet
= createFlattenSet(origSet
, &errorCode
);
740 if (U_FAILURE(errorCode
)) {
741 log_err("%s: error uset_openPattern returned %s\n", currLoc
, u_errorName(errorCode
));
745 for (strIdx
= 0; strIdx
< langSize
; strIdx
++) {
746 if (!uset_contains(exemplarSet
, string
[strIdx
])
747 && 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
748 && string
[strIdx
] != 0x200C && string
[strIdx
] != 0x200D) {
749 if (!ignoreNumbers
|| (ignoreNumbers
&& (string
[strIdx
] < 0x30 || string
[strIdx
] > 0x39))) {
750 uset_close(exemplarSet
);
752 *badCharPtr
= string
[strIdx
];
758 uset_close(exemplarSet
);
764 /* include non-invariant chars */
766 myUCharsToChars(const UChar
* us
, char* cs
, int32_t len
){
778 findSetMatch( UScriptCode
*scriptCodes
, int32_t scriptsLen
,
781 USet
*scripts
[10]= {0};
782 char pattern
[256] = { '[', ':', 0x000 };
784 UChar uPattern
[256] = {0};
785 UErrorCode status
= U_ZERO_ERROR
;
788 /* create the sets with script codes */
789 for(i
= 0; i
<scriptsLen
; i
++){
790 strcat(pattern
, uscript_getShortName(scriptCodes
[i
]));
791 strcat(pattern
, ":]");
792 patternLen
= (int32_t)strlen(pattern
);
793 u_charsToUChars(pattern
, uPattern
, patternLen
);
794 scripts
[i
] = uset_openPattern(uPattern
, patternLen
, &status
);
795 if(U_FAILURE(status
)){
796 log_err("Could not create set for pattern %s. Error: %s\n", pattern
, u_errorName(status
));
801 if (strcmp(locale
, "uk") == 0 || strcmp(locale
, "uk_UA") == 0) {
802 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
803 uset_add(scripts
[0], 0x2bc);
805 if(U_SUCCESS(status
)){
806 UBool existsInScript
= FALSE
;
807 /* iterate over the exemplarSet and ascertain if all
808 * UChars in exemplarSet belong to the scripts returned
811 int32_t count
= uset_getItemCount(exemplarSet
);
813 for( i
=0; i
< count
; i
++){
817 int32_t strCapacity
= 0;
819 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
820 if(U_SUCCESS(status
)){
822 if(strCapacity
== 0){
823 /* ok the item is a range */
824 for( j
= 0; j
< scriptsLen
; j
++){
825 if(uset_containsRange(scripts
[j
], start
, end
) == TRUE
){
826 existsInScript
= TRUE
;
829 if(existsInScript
== FALSE
){
830 for( j
= 0; j
< scriptsLen
; j
++){
831 UChar toPattern
[500]={'\0'};
832 char pat
[500]={'\0'};
833 int32_t len
= uset_toPattern(scripts
[j
], toPattern
, 500, TRUE
, &status
);
834 len
= myUCharsToChars(toPattern
, pat
, len
);
835 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
));
837 log_err("Pattern: %s\n",pat
);
840 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
843 strCapacity
++; /* increment for NUL termination */
844 /* allocate the str and call the api again */
845 str
= (UChar
*) malloc(U_SIZEOF_UCHAR
* strCapacity
);
846 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
847 /* iterate over the scripts and figure out if the string contained is actually
850 for( j
= 0; j
< scriptsLen
; j
++){
851 if(uset_containsString(scripts
[j
],str
, strCapacity
) == TRUE
){
852 existsInScript
= TRUE
;
855 if(existsInScript
== FALSE
){
856 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
865 for(i
= 0; i
<scriptsLen
; i
++){
866 uset_close(scripts
[i
]);
870 static void VerifyTranslation(void) {
871 UResourceBundle
*root
, *currentLocale
;
872 int32_t locCount
= uloc_countAvailable();
874 UErrorCode errorCode
= U_ZERO_ERROR
;
876 const UChar
*exemplarCharacters
;
878 UScriptCode scripts
[USCRIPT_CODE_LIMIT
];
882 UResourceBundle
*resArray
;
885 log_data_err("At least root needs to be installed\n");
888 root
= ures_openDirect(NULL
, "root", &errorCode
);
889 if(U_FAILURE(errorCode
)) {
890 log_data_err("Can't open root\n");
893 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
894 errorCode
=U_ZERO_ERROR
;
895 currLoc
= uloc_getAvailable(locIndex
);
896 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
897 if(errorCode
!= U_ZERO_ERROR
) {
898 if(U_SUCCESS(errorCode
)) {
899 /* It's installed, but there is no data.
900 It's installed for the g18n white paper [grhoten] */
901 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
902 uloc_getAvailable(locIndex
));
904 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
905 u_errorName(errorCode
),
906 uloc_getAvailable(locIndex
));
908 ures_close(currentLocale
);
911 exemplarCharacters
= ures_getStringByKey(currentLocale
, "ExemplarCharacters", &exemplarLen
, &errorCode
);
912 if (U_FAILURE(errorCode
)) {
913 log_err("error ures_getStringByKey returned %s\n", u_errorName(errorCode
));
915 else if (getTestOption(QUICK_OPTION
) && exemplarLen
> 2048) {
916 log_verbose("skipping test for %s\n", currLoc
);
918 else if (uprv_strncmp(currLoc
,"bem",3) == 0 || uprv_strncmp(currLoc
,"mgo",3) == 0 || uprv_strncmp(currLoc
,"nl",2) == 0 || uprv_strncmp(currLoc
,"ky",2) == 0) {
919 log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc
);
922 UChar langBuffer
[128];
926 langSize
= uloc_getDisplayLanguage(currLoc
, currLoc
, langBuffer
, sizeof(langBuffer
)/sizeof(langBuffer
[0]), &errorCode
);
927 if (U_FAILURE(errorCode
)) {
928 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode
));
931 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, exemplarCharacters
, exemplarLen
, FALSE
, &badChar
);
933 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
934 currLoc
, strIdx
, badChar
);
937 langSize
= uloc_getDisplayCountry(currLoc
, currLoc
, langBuffer
, sizeof(langBuffer
)/sizeof(langBuffer
[0]), &errorCode
);
938 if (U_FAILURE(errorCode
)) {
939 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode
));
941 else if (uprv_strstr(currLoc
, "ti_") != currLoc
|| isICUVersionAtLeast(52, 0, 1)) { /* TODO: FIX or REMOVE this test! Was: restore DisplayCountry test for ti_* when cldrbug 3058 is fixed) - but CldrBug:3058 is wontfix */
942 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, exemplarCharacters
, exemplarLen
, FALSE
, &badChar
);
944 log_err("getDisplayCountry(%s) at index %d returned characters not in the exemplar characters: %04X.\n",
945 currLoc
, strIdx
, badChar
);
949 UResourceBundle
* cal
= ures_getByKey(currentLocale
, "calendar", NULL
, &errorCode
);
950 UResourceBundle
* greg
= ures_getByKeyWithFallback(cal
, "gregorian", NULL
, &errorCode
);
951 UResourceBundle
* names
= ures_getByKeyWithFallback(greg
, "dayNames", NULL
, &errorCode
);
952 UResourceBundle
* format
= ures_getByKeyWithFallback(names
, "format", NULL
, &errorCode
);
953 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
955 if (U_FAILURE(errorCode
)) {
956 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
958 if (getTestOption(QUICK_OPTION
)) {
962 end
= ures_getSize(resArray
);
966 for (idx
= 0; idx
< end
; idx
++) {
967 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
968 if (U_FAILURE(errorCode
)) {
969 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
972 if (uprv_strstr(currLoc
, "uz_Arab") != currLoc
|| isICUVersionAtLeast(52, 0, 1)) { /* TODO: FIX or REMOVE this test! */
973 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, exemplarCharacters
, exemplarLen
, TRUE
, &badChar
);
975 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
976 currLoc
, idx
, strIdx
, badChar
);
980 ures_close(resArray
);
984 names
= ures_getByKeyWithFallback(greg
, "monthNames", NULL
, &errorCode
);
985 format
= ures_getByKeyWithFallback(names
,"format", NULL
, &errorCode
);
986 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
987 if (U_FAILURE(errorCode
)) {
988 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
990 if (getTestOption(QUICK_OPTION
)) {
994 end
= ures_getSize(resArray
);
997 for (idx
= 0; idx
< end
; idx
++) {
998 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
999 if (U_FAILURE(errorCode
)) {
1000 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1003 if (uprv_strstr(currLoc
, "uz_Arab") != currLoc
|| isICUVersionAtLeast(52, 0, 1)) { /* TODO: FIX or REMOVE this test! */
1004 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, exemplarCharacters
, exemplarLen
, TRUE
, &badChar
);
1006 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1007 currLoc
, idx
, strIdx
, badChar
);
1011 ures_close(resArray
);
1017 errorCode
= U_ZERO_ERROR
;
1018 numScripts
= uscript_getCode(currLoc
, scripts
, sizeof(scripts
)/sizeof(scripts
[0]), &errorCode
);
1019 if (numScripts
== 0) {
1020 log_err("uscript_getCode(%s) doesn't work.\n", currLoc
);
1021 }else if(scripts
[0] == USCRIPT_COMMON
){
1022 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc
);
1025 /* test that the scripts are a superset of exemplar characters. */
1027 ULocaleData
*uld
= ulocdata_open(currLoc
,&errorCode
);
1028 USet
*exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &errorCode
);
1029 /* test if exemplar characters are part of script code */
1030 findSetMatch(scripts
, numScripts
, exemplarSet
, currLoc
);
1031 uset_close(exemplarSet
);
1032 ulocdata_close(uld
);
1035 /* test that the paperSize API works */
1037 int32_t height
=0, width
=0;
1038 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1039 if(U_FAILURE(errorCode
)){
1040 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1042 if(strstr(currLoc
, "_US")!=NULL
&& height
!= 279 && width
!= 216 ){
1043 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1046 /* test that the MeasurementSystem works API works */
1048 char fullLoc
[ULOC_FULLNAME_CAPACITY
];
1049 UMeasurementSystem measurementSystem
= ulocdata_getMeasurementSystem(currLoc
, &errorCode
);
1050 if(U_FAILURE(errorCode
)){
1051 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1053 uloc_addLikelySubtags(currLoc
, fullLoc
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
1054 if(strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_MM")!=NULL
|| strstr(fullLoc
, "_LR")!=NULL
){
1055 if(measurementSystem
!= UMS_US
){
1056 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1058 }else if(measurementSystem
!= UMS_SI
){
1059 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1063 ures_close(currentLocale
);
1069 /* adjust this limit as appropriate */
1070 #define MAX_SCRIPTS_PER_LOCALE 8
1072 static void TestExemplarSet(void){
1073 int32_t i
, j
, k
, m
, n
;
1074 int32_t equalCount
= 0;
1075 UErrorCode ec
= U_ZERO_ERROR
;
1076 UEnumeration
* avail
;
1077 USet
* exemplarSets
[2];
1078 USet
* unassignedSet
;
1079 UScriptCode code
[MAX_SCRIPTS_PER_LOCALE
];
1080 USet
* codeSets
[MAX_SCRIPTS_PER_LOCALE
];
1082 char cbuf
[32]; /* 9 should be enough */
1083 UChar ubuf
[64]; /* adjust as needed */
1084 UBool existsInScript
;
1089 unassignedSet
= NULL
;
1090 exemplarSets
[0] = NULL
;
1091 exemplarSets
[1] = NULL
;
1092 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1096 avail
= ures_openAvailableLocales(NULL
, &ec
);
1097 if (!assertSuccess("ures_openAvailableLocales", &ec
)) goto END
;
1098 n
= uenum_count(avail
, &ec
);
1099 if (!assertSuccess("uenum_count", &ec
)) goto END
;
1101 u_uastrcpy(ubuf
, "[:unassigned:]");
1102 unassignedSet
= uset_openPattern(ubuf
, -1, &ec
);
1103 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1106 const char* locale
= uenum_next(avail
, NULL
, &ec
);
1107 if (!assertSuccess("uenum_next", &ec
)) goto END
;
1108 log_verbose("%s\n", locale
);
1109 for (k
=0; k
<2; ++k
) {
1110 uint32_t option
= (k
==0) ? 0 : USET_CASE_INSENSITIVE
;
1111 ULocaleData
*uld
= ulocdata_open(locale
,&ec
);
1112 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
,NULL
, option
, ULOCDATA_ES_STANDARD
, &ec
);
1113 uset_close(exemplarSets
[k
]);
1114 ulocdata_close(uld
);
1115 exemplarSets
[k
] = exemplarSet
;
1116 if (!assertSuccess("ulocaledata_getExemplarSet", &ec
)) goto END
;
1118 if (uset_containsSome(exemplarSet
, unassignedSet
)) {
1119 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale
);
1121 codeLen
= uscript_getCode(locale
, code
, 8, &ec
);
1122 if (!assertSuccess("uscript_getCode", &ec
)) goto END
;
1124 for (j
=0; j
<MAX_SCRIPTS_PER_LOCALE
; ++j
) {
1125 uset_close(codeSets
[j
]);
1128 for (j
=0; j
<codeLen
; ++j
) {
1129 uprv_strcpy(cbuf
, "[:");
1131 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale
);
1134 uprv_strcat(cbuf
, uscript_getShortName(code
[j
]));
1135 uprv_strcat(cbuf
, ":]");
1136 u_uastrcpy(ubuf
, cbuf
);
1137 codeSets
[j
] = uset_openPattern(ubuf
, -1, &ec
);
1139 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1141 existsInScript
= FALSE
;
1142 itemCount
= uset_getItemCount(exemplarSet
);
1143 for (m
=0; m
<itemCount
&& !existsInScript
; ++m
) {
1144 strLen
= uset_getItem(exemplarSet
, m
, &start
, &end
, ubuf
,
1145 sizeof(ubuf
)/sizeof(ubuf
[0]), &ec
);
1146 /* failure here might mean str[] needs to be larger */
1147 if (!assertSuccess("uset_getItem", &ec
)) goto END
;
1149 for (j
=0; j
<codeLen
; ++j
) {
1150 if (codeSets
[j
]!=NULL
&& uset_containsRange(codeSets
[j
], start
, end
)) {
1151 existsInScript
= TRUE
;
1156 for (j
=0; j
<codeLen
; ++j
) {
1157 if (codeSets
[j
]!=NULL
&& uset_containsString(codeSets
[j
], ubuf
, strLen
)) {
1158 existsInScript
= TRUE
;
1165 if (existsInScript
== FALSE
){
1166 log_err("ExemplarSet containment failed for locale : %s\n", locale
);
1169 assertTrue("case-folded is a superset",
1170 uset_containsAll(exemplarSets
[1], exemplarSets
[0]));
1171 if (uset_equals(exemplarSets
[1], exemplarSets
[0])) {
1175 /* Note: The case-folded set should sometimes be a strict superset
1176 and sometimes be equal. */
1177 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1178 equalCount
> 0 && equalCount
< n
);
1182 uset_close(exemplarSets
[0]);
1183 uset_close(exemplarSets
[1]);
1184 uset_close(unassignedSet
);
1185 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1186 uset_close(codeSets
[i
]);
1190 static void TestLocaleDisplayPattern(void){
1191 UErrorCode status
= U_ZERO_ERROR
;
1192 UChar pattern
[32] = {0,};
1193 UChar separator
[32] = {0,};
1194 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1196 if(U_FAILURE(status
)){
1197 log_data_err("ulocdata_open error");
1200 ulocdata_getLocaleDisplayPattern(uld
, pattern
, 32, &status
);
1201 if (U_FAILURE(status
)){
1202 log_err("ulocdata_getLocaleDisplayPattern error!");
1204 status
= U_ZERO_ERROR
;
1205 ulocdata_getLocaleSeparator(uld
, separator
, 32, &status
);
1206 if (U_FAILURE(status
)){
1207 log_err("ulocdata_getLocaleSeparator error!");
1209 ulocdata_close(uld
);
1212 static void TestCoverage(void){
1213 ULocaleDataDelimiterType types
[] = {
1214 ULOCDATA_QUOTATION_START
, /* Quotation start */
1215 ULOCDATA_QUOTATION_END
, /* Quotation end */
1216 ULOCDATA_ALT_QUOTATION_START
, /* Alternate quotation start */
1217 ULOCDATA_ALT_QUOTATION_END
, /* Alternate quotation end */
1218 ULOCDATA_DELIMITER_COUNT
1222 UErrorCode status
= U_ZERO_ERROR
;
1223 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1225 if(U_FAILURE(status
)){
1226 log_data_err("ulocdata_open error");
1231 for(i
= 0; i
< ULOCDATA_DELIMITER_COUNT
; i
++){
1232 UChar result
[32] = {0,};
1233 status
= U_ZERO_ERROR
;
1234 ulocdata_getDelimiter(uld
, types
[i
], result
, 32, &status
);
1235 if (U_FAILURE(status
)){
1236 log_err("ulocdata_getgetDelimiter error with type %d", types
[i
]);
1240 sub
= ulocdata_getNoSubstitute(uld
);
1241 ulocdata_setNoSubstitute(uld
,sub
);
1242 ulocdata_close(uld
);
1245 static void TestIndexChars(void) {
1246 /* Very basic test of ULOCDATA_ES_INDEX.
1247 * No comprehensive test of data, just basic check that the code path is alive.
1249 UErrorCode status
= U_ZERO_ERROR
;
1251 USet
*exemplarChars
;
1254 uld
= ulocdata_open("en", &status
);
1255 exemplarChars
= uset_openEmpty();
1256 indexChars
= uset_openEmpty();
1257 ulocdata_getExemplarSet(uld
, exemplarChars
, 0, ULOCDATA_ES_STANDARD
, &status
);
1258 ulocdata_getExemplarSet(uld
, indexChars
, 0, ULOCDATA_ES_INDEX
, &status
);
1259 if (U_FAILURE(status
)) {
1260 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__
, __LINE__
, u_errorName(status
));
1263 /* en data, standard exemplars are [a-z], lower case. */
1264 /* en data, index characters are [A-Z], upper case. */
1265 if ((uset_contains(exemplarChars
, (UChar32
)0x41) || uset_contains(indexChars
, (UChar32
)0x61))) {
1266 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1269 if (!(uset_contains(exemplarChars
, (UChar32
)0x61) && uset_contains(indexChars
, (UChar32
)0x41) )) {
1270 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1275 uset_close(exemplarChars
);
1276 uset_close(indexChars
);
1277 ulocdata_close(uld
);
1282 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1283 static void TestCurrencyList(void){
1284 #if !UCONFIG_NO_FORMATTING
1285 UErrorCode errorCode
= U_ZERO_ERROR
;
1286 int32_t structLocaleCount
, currencyCount
;
1287 UEnumeration
*en
= ucurr_openISOCurrencies(UCURR_ALL
, &errorCode
);
1288 const char *isoCode
, *structISOCode
;
1289 UResourceBundle
*subBundle
;
1290 UResourceBundle
*currencies
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
1291 if(U_FAILURE(errorCode
)) {
1292 log_data_err("Can't open structLocale\n");
1295 currencies
= ures_getByKey(currencies
, "Currencies", currencies
, &errorCode
);
1296 currencyCount
= uenum_count(en
, &errorCode
);
1297 structLocaleCount
= ures_getSize(currencies
);
1298 if (currencyCount
!= structLocaleCount
) {
1299 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount
, currencyCount
);
1300 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1301 ures_resetIterator(currencies
);
1302 while ((isoCode
= uenum_next(en
, NULL
, &errorCode
)) != NULL
&& ures_hasNext(currencies
)) {
1303 subBundle
= ures_getNextResource(currencies
, NULL
, &errorCode
);
1304 structISOCode
= ures_getKey(subBundle
);
1305 ures_close(subBundle
);
1306 if (strcmp(structISOCode
, isoCode
) != 0) {
1307 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode
, isoCode
);
1313 ures_close(currencies
);
1319 static void TestAvailableIsoCodes(void){
1320 #if !UCONFIG_NO_FORMATTING
1321 UErrorCode errorCode
= U_ZERO_ERROR
;
1322 const char* eurCode
= "EUR";
1323 const char* usdCode
= "USD";
1324 const char* lastCode
= "RHD";
1325 const char* zzzCode
= "ZZZ";
1326 UDate date1950
= (UDate
)-630720000000.0;/* year 1950 */
1327 UDate date1970
= (UDate
)0.0; /* year 1970 */
1328 UDate date1975
= (UDate
)173448000000.0; /* year 1975 */
1329 UDate date1978
= (UDate
)260172000000.0; /* year 1978 */
1330 UDate date1981
= (UDate
)346896000000.0; /* year 1981 */
1331 UDate date1992
= (UDate
)693792000000.0; /* year 1992 */
1332 UChar
* isoCode
= (UChar
*)malloc(sizeof(UChar
) * (uprv_strlen(usdCode
) + 1));
1334 /* testing available codes with no time ranges */
1335 u_charsToUChars(eurCode
, isoCode
, uprv_strlen(usdCode
) + 1);
1336 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1337 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode
);
1340 u_charsToUChars(usdCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1341 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1342 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode
);
1345 u_charsToUChars(zzzCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1346 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1347 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode
);
1350 u_charsToUChars(lastCode
, isoCode
, uprv_strlen(zzzCode
) + 1);
1351 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1352 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode
);
1355 /* RHD was used from 1970-02-17 to 1980-04-18*/
1358 if (ucurr_isAvailable(isoCode
, date1970
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1359 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode
);
1362 if (ucurr_isAvailable(isoCode
, date1975
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1363 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode
);
1366 if (ucurr_isAvailable(isoCode
, date1981
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1367 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode
);
1371 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1970
, &errorCode
) == TRUE
) {
1372 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode
);
1375 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1975
, &errorCode
) == FALSE
) {
1376 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode
);
1379 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1981
, &errorCode
) == FALSE
) {
1380 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode
);
1384 if (ucurr_isAvailable(isoCode
, date1975
, date1978
, &errorCode
) == FALSE
) {
1385 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode
);
1388 if (ucurr_isAvailable(isoCode
, date1970
, date1975
, &errorCode
) == FALSE
) {
1389 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode
);
1392 if (ucurr_isAvailable(isoCode
, date1975
, date1981
, &errorCode
) == FALSE
) {
1393 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode
);
1396 if (ucurr_isAvailable(isoCode
, date1970
, date1981
, &errorCode
) == FALSE
) {
1397 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode
);
1400 if (ucurr_isAvailable(isoCode
, date1981
, date1992
, &errorCode
) == TRUE
) {
1401 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode
);
1404 if (ucurr_isAvailable(isoCode
, date1950
, date1970
, &errorCode
) == TRUE
) {
1405 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode
);
1408 /* wrong range - from > to*/
1409 if (ucurr_isAvailable(isoCode
, date1975
, date1970
, &errorCode
) == TRUE
) {
1410 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode
);
1411 } else if (errorCode
!= U_ILLEGAL_ARGUMENT_ERROR
) {
1412 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode
);
1419 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1421 void addCLDRTest(TestNode
** root
);
1423 void addCLDRTest(TestNode
** root
)
1425 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1426 TESTCASE(TestLocaleStructure
);
1427 TESTCASE(TestCurrencyList
);
1429 TESTCASE(TestConsistentCountryInfo
);
1430 TESTCASE(VerifyTranslation
);
1431 TESTCASE(TestExemplarSet
);
1432 TESTCASE(TestLocaleDisplayPattern
);
1433 TESTCASE(TestCoverage
);
1434 TESTCASE(TestIndexChars
);
1435 TESTCASE(TestAvailableIsoCodes
);