1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
10 #include "unicode/ures.h"
11 #include "unicode/ucurr.h"
12 #include "unicode/ustring.h"
13 #include "unicode/uset.h"
14 #include "unicode/udat.h"
15 #include "unicode/uscript.h"
16 #include "unicode/ulocdata.h"
17 #include "unicode/utf16.h"
24 returns a new UnicodeSet that is a flattened form of the original
28 createFlattenSet(USet
*origSet
, UErrorCode
*status
) {
32 int32_t origItemCount
= 0;
33 int32_t idx
, graphmeSize
;
36 if (U_FAILURE(*status
)) {
37 log_err("createFlattenSet called with %s\n", u_errorName(*status
));
40 newSet
= uset_open(1, 0);
41 origItemCount
= uset_getItemCount(origSet
);
42 for (idx
= 0; idx
< origItemCount
; idx
++) {
43 graphmeSize
= uset_getItem(origSet
, idx
,
45 graphme
, UPRV_LENGTHOF(graphme
),
47 if (U_FAILURE(*status
)) {
48 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status
));
49 *status
= U_ZERO_ERROR
;
52 uset_addAllCodePoints(newSet
, graphme
, graphmeSize
);
55 uset_addRange(newSet
, start
, end
);
58 uset_closeOver(newSet
,USET_CASE_INSENSITIVE
);
63 isCurrencyPreEuro(const char* currencyKey
){
64 if( strcmp(currencyKey
, "PTE") == 0 ||
65 strcmp(currencyKey
, "ESP") == 0 ||
66 strcmp(currencyKey
, "LUF") == 0 ||
67 strcmp(currencyKey
, "GRD") == 0 ||
68 strcmp(currencyKey
, "BEF") == 0 ||
69 strcmp(currencyKey
, "ITL") == 0 ||
70 strcmp(currencyKey
, "EEK") == 0){
75 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
77 TestKeyInRootRecursive(UResourceBundle
*root
, const char *rootName
,
78 UResourceBundle
*currentBundle
, const char *locale
) {
79 UErrorCode errorCode
= U_ZERO_ERROR
;
80 UResourceBundle
*subRootBundle
= NULL
, *subBundle
= NULL
, *arr
= NULL
;
82 ures_resetIterator(root
);
83 ures_resetIterator(currentBundle
);
84 while (ures_hasNext(currentBundle
)) {
85 const char *subBundleKey
= NULL
;
86 const char *currentBundleKey
= NULL
;
88 errorCode
= U_ZERO_ERROR
;
89 currentBundleKey
= ures_getKey(currentBundle
);
90 (void)currentBundleKey
; /* Suppress set but not used warning. */
91 subBundle
= ures_getNextResource(currentBundle
, NULL
, &errorCode
);
92 if (U_FAILURE(errorCode
)) {
93 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale
, u_errorName(errorCode
));
96 subBundleKey
= ures_getKey(subBundle
);
99 subRootBundle
= ures_getByKey(root
, subBundleKey
, NULL
, &errorCode
);
100 if (U_FAILURE(errorCode
)) {
101 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
103 ures_getKey(currentBundle
),
106 ures_close(subBundle
);
109 if (ures_getType(subRootBundle
) != ures_getType(subBundle
)) {
110 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
111 "\troot=%d, locale=%d\n",
113 ures_getKey(currentBundle
),
115 ures_getType(subRootBundle
),
116 ures_getType(subBundle
));
117 ures_close(subBundle
);
120 else if (ures_getType(subBundle
) == URES_INT_VECTOR
) {
122 int32_t subBundleSize
;
124 UBool sameArray
= TRUE
;
125 const int32_t *subRootBundleArr
= ures_getIntVector(subRootBundle
, &minSize
, &errorCode
);
126 const int32_t *subBundleArr
= ures_getIntVector(subBundle
, &subBundleSize
, &errorCode
);
128 if (minSize
> subBundleSize
) {
129 minSize
= subBundleSize
;
130 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
132 ures_getKey(currentBundle
),
136 for (idx
= 0; idx
< minSize
&& sameArray
; idx
++) {
137 if (subRootBundleArr
[idx
] != subBundleArr
[idx
]) {
140 if (strcmp(subBundleKey
, "DateTimeElements") == 0
141 && (subBundleArr
[idx
] < 1 || 7 < subBundleArr
[idx
]))
143 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
146 ures_getKey(currentBundle
),
150 /* Special exception es_US and DateTimeElements */
152 && !(strcmp(locale
, "es_US") == 0 && strcmp(subBundleKey
, "DateTimeElements") == 0))
154 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
156 ures_getKey(currentBundle
),
160 else if (ures_getType(subBundle
) == URES_ARRAY
) {
161 UResourceBundle
*subSubBundle
= ures_getByIndex(subBundle
, 0, NULL
, &errorCode
);
162 UResourceBundle
*subSubRootBundle
= ures_getByIndex(subRootBundle
, 0, NULL
, &errorCode
);
164 if (U_SUCCESS(errorCode
)
165 && (ures_getType(subSubBundle
) == URES_ARRAY
|| ures_getType(subSubRootBundle
) == URES_ARRAY
))
167 /* Here is one of the recursive parts */
168 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
171 int32_t minSize
= ures_getSize(subRootBundle
);
173 UBool sameArray
= TRUE
;
175 if (minSize
> ures_getSize(subBundle
)) {
176 minSize
= ures_getSize(subBundle
);
179 if ((subBundleKey
== NULL
180 || (subBundleKey
!= NULL
&& strcmp(subBundleKey
, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey
)))
181 && ures_getSize(subRootBundle
) != ures_getSize(subBundle
))
183 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
184 "\troot array size=%d, locale array size=%d\n",
186 ures_getKey(currentBundle
),
188 ures_getSize(subRootBundle
),
189 ures_getSize(subBundle
));
192 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
193 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
195 ures_getKey(currentBundle),
197 ures_getSize(subBundle));
200 for (idx
= 0; idx
< minSize
; idx
++) {
201 int32_t rootStrLen
, localeStrLen
;
202 const UChar
*rootStr
= ures_getStringByIndex(subRootBundle
,idx
,&rootStrLen
,&errorCode
);
203 const UChar
*localeStr
= ures_getStringByIndex(subBundle
,idx
,&localeStrLen
,&errorCode
);
204 if (rootStr
&& localeStr
&& U_SUCCESS(errorCode
)) {
205 if (u_strcmp(rootStr
, localeStr
) != 0) {
210 if ( rootStrLen
> 1 && rootStr
[0] == 0x41 && rootStr
[1] >= 0x30 && rootStr
[1] <= 0x39 ) {
211 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
212 /* string. Attempt to read it as an array. */
213 errorCode
= U_ZERO_ERROR
;
214 arr
= ures_getByIndex(subBundle
,idx
,NULL
,&errorCode
);
215 if (U_FAILURE(errorCode
)) {
216 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
218 ures_getKey(currentBundle
),
223 if (ures_getType(arr
) != URES_ARRAY
|| ures_getSize(arr
) != (int32_t)rootStr
[1] - 0x30) {
224 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",
227 ures_getKey(currentBundle
),
233 localeStr
= ures_getStringByIndex(arr
,0,&localeStrLen
,&errorCode
);
235 if (U_FAILURE(errorCode
)) {
236 log_err("Got something other than a string or array for key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
238 ures_getKey(currentBundle
),
244 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
246 ures_getKey(currentBundle
),
252 if (localeStr
[0] == (UChar
)0x20) {
253 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
256 ures_getKey(currentBundle
),
259 else if ((localeStr
[localeStrLen
- 1] == (UChar
)0x20) && (strcmp(subBundleKey
,"separator") != 0)) {
260 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
263 ures_getKey(currentBundle
),
266 else if (subBundleKey
!= NULL
267 && strcmp(subBundleKey
, "DateTimePatterns") == 0)
270 const UChar
*localeStrItr
= localeStr
;
271 while (*localeStrItr
) {
272 if (*localeStrItr
== (UChar
)0x27 /* ' */) {
275 else if ((quoted
% 2) == 0) {
276 /* Search for unquoted characters */
277 if (4 <= idx
&& idx
<= 7
278 && (*localeStrItr
== (UChar
)0x6B /* k */
279 || *localeStrItr
== (UChar
)0x48 /* H */
280 || *localeStrItr
== (UChar
)0x6D /* m */
281 || *localeStrItr
== (UChar
)0x73 /* s */
282 || *localeStrItr
== (UChar
)0x53 /* S */
283 || *localeStrItr
== (UChar
)0x61 /* a */
284 || *localeStrItr
== (UChar
)0x68 /* h */
285 || *localeStrItr
== (UChar
)0x7A /* z */))
287 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
292 else if (0 <= idx
&& idx
<= 3
293 && (*localeStrItr
== (UChar
)0x47 /* G */
294 || *localeStrItr
== (UChar
)0x79 /* y */
295 || *localeStrItr
== (UChar
)0x4D /* M */
296 || *localeStrItr
== (UChar
)0x64 /* d */
297 || *localeStrItr
== (UChar
)0x45 /* E */
298 || *localeStrItr
== (UChar
)0x44 /* D */
299 || *localeStrItr
== (UChar
)0x46 /* F */
300 || *localeStrItr
== (UChar
)0x77 /* w */
301 || *localeStrItr
== (UChar
)0x57 /* W */))
303 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
312 else if (idx
== 4 && subBundleKey
!= NULL
313 && strcmp(subBundleKey
, "NumberElements") == 0
314 && u_charDigitValue(localeStr
[0]) != 0)
316 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
322 (void)sameArray
; /* Suppress set but not used warning. */
323 /* if (sameArray && strcmp(rootName, "root") == 0) {
324 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
326 ures_getKey(currentBundle),
330 ures_close(subSubBundle
);
331 ures_close(subSubRootBundle
);
333 else if (ures_getType(subBundle
) == URES_STRING
) {
335 const UChar
*string
= ures_getString(subBundle
, &len
, &errorCode
);
336 if (U_FAILURE(errorCode
) || string
== NULL
) {
337 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
339 ures_getKey(currentBundle
),
341 } else if (string
[0] == (UChar
)0x20) {
342 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
344 ures_getKey(currentBundle
),
346 /* localeDisplayPattern/separator can end with a space */
347 } else if (string
[len
- 1] == (UChar
)0x20 && (strcmp(subBundleKey
,"separator"))) {
348 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
350 ures_getKey(currentBundle
),
352 } else if (strcmp(subBundleKey
, "localPatternChars") == 0) {
353 /* Note: We no longer import localPatternChars data starting
354 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
357 /* Check well-formedness of localPatternChars. First, the
358 * length must match the number of fields defined by
359 * DateFormat. Second, each character in the string must
360 * be in the set [A-Za-z]. Finally, each character must be
364 #if !UCONFIG_NO_FORMATTING
365 if (len
!= UDAT_FIELD_COUNT
) {
366 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
371 /* Check char validity. */
372 for (i
=0; i
<len
; ++i
) {
373 if (!((string
[i
] >= 65/*'A'*/ && string
[i
] <= 90/*'Z'*/) ||
374 (string
[i
] >= 97/*'a'*/ && string
[i
] <= 122/*'z'*/))) {
375 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
380 /* Do O(n^2) check for duplicate chars. */
381 for (j
=0; j
<i
; ++j
) {
382 if (string
[j
] == string
[i
]) {
383 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
391 /* No fallback was done. Check for duplicate data */
392 /* The ures_* API does not do fallback of sub-resource bundles,
393 So we can't do this now. */
395 else if (strcmp(locale
, "root") != 0 && errorCode
== U_ZERO_ERROR
) {
397 const UChar
*rootString
= ures_getString(subRootBundle
, &len
, &errorCode
);
398 if (U_FAILURE(errorCode
) || rootString
== NULL
) {
399 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
400 ures_getKey(subRootBundle
),
401 ures_getKey(currentBundle
));
403 } else if (u_strcmp(string
, rootString
) == 0) {
404 if (strcmp(locale
, "de_CH") != 0 && strcmp(subBundleKey
, "Countries") != 0 &&
405 strcmp(subBundleKey
, "Version") != 0) {
406 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
407 ures_getKey(subRootBundle
),
408 ures_getKey(currentBundle
),
412 /* Ignore for now. */
413 /* Can be fixed if fallback through de locale was done. */
414 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
420 else if (ures_getType(subBundle
) == URES_TABLE
) {
421 if (strcmp(subBundleKey
, "availableFormats")!=0) {
422 /* Here is one of the recursive parts */
423 TestKeyInRootRecursive(subRootBundle
, rootName
, subBundle
, locale
);
426 log_verbose("Skipping key %s in %s\n", subBundleKey
, locale
);
429 else if (ures_getType(subBundle
) == URES_BINARY
|| ures_getType(subBundle
) == URES_INT
) {
430 /* Can't do anything to check it */
431 /* We'll assume it's all correct */
432 if (strcmp(subBundleKey
, "MeasurementSystem") != 0) {
433 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
435 ures_getKey(currentBundle
),
438 /* Testing for MeasurementSystem is done in VerifyTranslation */
441 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
442 ures_getType(subBundle
),
444 ures_getKey(currentBundle
),
447 ures_close(subRootBundle
);
448 ures_close(subBundle
);
454 testLCID(UResourceBundle
*currentBundle
,
455 const char *localeName
)
457 UErrorCode status
= U_ZERO_ERROR
;
458 uint32_t expectedLCID
;
459 char lcidStringC
[64] = {0};
462 expectedLCID
= uloc_getLCID(localeName
);
463 if (expectedLCID
== 0) {
464 log_verbose("INFO: %-5s does not have any LCID mapping\n",
469 status
= U_ZERO_ERROR
;
470 len
= uprv_convertToPosix(expectedLCID
, lcidStringC
, UPRV_LENGTHOF(lcidStringC
) - 1, &status
);
471 if (U_FAILURE(status
)) {
472 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
473 expectedLCID
, u_errorName(status
));
475 lcidStringC
[len
] = 0;
477 if(strcmp(localeName
, lcidStringC
) != 0) {
480 uloc_getLanguage(localeName
, langName
, sizeof(langName
), &status
);
481 uloc_getLanguage(lcidStringC
, langLCID
, sizeof(langLCID
), &status
);
483 if (strcmp(langName
, langLCID
) == 0) {
484 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
485 localeName
, lcidStringC
, expectedLCID
);
487 else if (!(strcmp(localeName
, "ku") == 0 && log_knownIssue("20181", "ICU-20181 Fix LCID mapping for ckb vs ku"))) {
488 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
489 localeName
, expectedLCID
, lcidStringC
);
494 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
496 TestLocaleStructure(void) {
497 // This test checks the locale structure against a key file located
498 // at source/test/testdata/structLocale.txt. When adding new data to
499 // a locale file such as en.txt, the structLocale.txt file must be changed
500 // too to include the the template of the new data. Otherwise this test
503 UResourceBundle
*root
, *currentLocale
;
504 int32_t locCount
= uloc_countAvailable();
506 UErrorCode errorCode
= U_ZERO_ERROR
;
507 const char *currLoc
, *resolvedLoc
;
509 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
510 /* char locName[ULOC_FULLNAME_CAPACITY];
513 for (locIndex = 0; locIndex < locCount; locIndex++) {
514 errorCode=U_ZERO_ERROR;
515 strcpy(locName, uloc_getAvailable(locIndex));
516 locNamePtr = strrchr(locName, '_');
521 strcpy(locName, "root");
524 root = ures_openDirect(NULL, locName, &errorCode);
525 if(U_FAILURE(errorCode)) {
526 log_err("Can't open %s\n", locName);
531 log_data_err("At least root needs to be installed\n");
534 root
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
535 if(U_FAILURE(errorCode
)) {
536 log_data_err("Can't open structLocale\n");
539 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
540 errorCode
=U_ZERO_ERROR
;
541 currLoc
= uloc_getAvailable(locIndex
);
542 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
543 if(errorCode
!= U_ZERO_ERROR
) {
544 if(U_SUCCESS(errorCode
)) {
545 /* It's installed, but there is no data.
546 It's installed for the g18n white paper [grhoten] */
547 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
548 uloc_getAvailable(locIndex
), u_errorName(errorCode
));
550 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
551 u_errorName(errorCode
),
552 uloc_getAvailable(locIndex
));
554 ures_close(currentLocale
);
557 ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
);
558 if(errorCode
!= U_ZERO_ERROR
) {
559 log_err("No version information is available for locale %s, and it should be!\n",
562 else if (ures_getStringByKey(currentLocale
, "Version", NULL
, &errorCode
)[0] == (UChar
)(0x78)) {
563 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
566 resolvedLoc
= ures_getLocaleByType(currentLocale
, ULOC_ACTUAL_LOCALE
, &errorCode
);
567 if (strcmp(resolvedLoc
, currLoc
) != 0 && strcmp(currLoc
, "ars") != 0 && strcmp(currLoc
, "wuu") != 0 // /* ars,wuu are aliased locales */
568 && strcmp(currLoc
, "ur_Arab_IN") != 0 && strcmp(currLoc
, "ur_Aran_IN") != 0 /* so are ur_Ara?_IN <rdar://problem/47494884> */
569 && strcmp(currLoc
, "pa_Aran") != 0) { /* and pa_Aran <rdar://problem/51418203> */
570 /* All locales have at least a Version resource.
571 If it's absolutely empty, then the previous test will fail too.*/
572 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
573 currLoc
, resolvedLoc
);
575 TestKeyInRootRecursive(root
, "root", currentLocale
, currLoc
);
577 testLCID(currentLocale
, currLoc
);
579 ures_close(currentLocale
);
587 compareArrays(const char *keyName
,
588 UResourceBundle
*fromArray
, const char *fromLocale
,
589 UResourceBundle
*toArray
, const char *toLocale
,
590 int32_t start
, int32_t end
)
592 int32_t fromSize
= ures_getSize(fromArray
);
593 int32_t toSize
= ures_getSize(fromArray
);
595 UErrorCode errorCode
= U_ZERO_ERROR
;
597 if (fromSize
> toSize
) {
599 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
604 for (idx
= start
; idx
<= end
; idx
++) {
605 const UChar
*fromBundleStr
= ures_getStringByIndex(fromArray
, idx
, NULL
, &errorCode
);
606 const UChar
*toBundleStr
= ures_getStringByIndex(toArray
, idx
, NULL
, &errorCode
);
607 if (fromBundleStr
&& toBundleStr
&& u_strcmp(fromBundleStr
, toBundleStr
) != 0)
609 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
613 austrdup(fromBundleStr
),
615 austrdup(toBundleStr
));
621 compareConsistentCountryInfo(const char *fromLocale
, const char *toLocale
) {
622 UErrorCode errorCode
= U_ZERO_ERROR
;
623 UResourceBundle
*fromArray
, *toArray
;
624 UResourceBundle
*fromLocaleBund
= ures_open(NULL
, fromLocale
, &errorCode
);
625 UResourceBundle
*toLocaleBund
= ures_open(NULL
, toLocale
, &errorCode
);
626 UResourceBundle
*toCalendar
, *fromCalendar
, *toGregorian
, *fromGregorian
;
628 if(U_FAILURE(errorCode
)) {
629 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale
, toLocale
, u_errorName(errorCode
));
632 fromCalendar
= ures_getByKey(fromLocaleBund
, "calendar", NULL
, &errorCode
);
633 fromGregorian
= ures_getByKeyWithFallback(fromCalendar
, "gregorian", NULL
, &errorCode
);
635 toCalendar
= ures_getByKey(toLocaleBund
, "calendar", NULL
, &errorCode
);
636 toGregorian
= ures_getByKeyWithFallback(toCalendar
, "gregorian", NULL
, &errorCode
);
638 fromArray
= ures_getByKey(fromLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
639 toArray
= ures_getByKey(toLocaleBund
, "CurrencyElements", NULL
, &errorCode
);
640 if (strcmp(fromLocale
, "en_CA") != 0)
642 /* The first one is probably localized. */
643 compareArrays("CurrencyElements", fromArray
, fromLocale
, toArray
, toLocale
, 1, 2);
645 ures_close(fromArray
);
648 fromArray
= ures_getByKey(fromLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
649 toArray
= ures_getByKey(toLocaleBund
, "NumberPatterns", NULL
, &errorCode
);
650 if (strcmp(fromLocale
, "en_CA") != 0)
652 compareArrays("NumberPatterns", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
654 ures_close(fromArray
);
657 /* Difficult to test properly */
659 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
660 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
662 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
664 ures_close(fromArray);
665 ures_close(toArray);*/
667 fromArray
= ures_getByKey(fromLocaleBund
, "NumberElements", NULL
, &errorCode
);
668 toArray
= ures_getByKey(toLocaleBund
, "NumberElements", NULL
, &errorCode
);
669 if (strcmp(fromLocale
, "en_CA") != 0)
671 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 0, 3);
672 /* Index 4 is a script based 0 */
673 compareArrays("NumberElements", fromArray
, fromLocale
, toArray
, toLocale
, 5, 10);
675 ures_close(fromArray
);
677 ures_close(fromCalendar
);
678 ures_close(toCalendar
);
679 ures_close(fromGregorian
);
680 ures_close(toGregorian
);
682 ures_close(fromLocaleBund
);
683 ures_close(toLocaleBund
);
687 TestConsistentCountryInfo(void) {
688 /* UResourceBundle *fromLocale, *toLocale;*/
689 int32_t locCount
= uloc_countAvailable();
690 int32_t fromLocIndex
, toLocIndex
;
692 int32_t fromCountryLen
, toCountryLen
;
693 char fromCountry
[ULOC_FULLNAME_CAPACITY
], toCountry
[ULOC_FULLNAME_CAPACITY
];
695 int32_t fromVariantLen
, toVariantLen
;
696 char fromVariant
[ULOC_FULLNAME_CAPACITY
], toVariant
[ULOC_FULLNAME_CAPACITY
];
698 UErrorCode errorCode
= U_ZERO_ERROR
;
700 for (fromLocIndex
= 0; fromLocIndex
< locCount
; fromLocIndex
++) {
701 const char *fromLocale
= uloc_getAvailable(fromLocIndex
);
703 errorCode
=U_ZERO_ERROR
;
704 fromCountryLen
= uloc_getCountry(fromLocale
, fromCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
705 if (fromCountryLen
<= 0) {
706 /* Ignore countryless locales */
709 fromVariantLen
= uloc_getVariant(fromLocale
, fromVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
710 if (fromVariantLen
> 0) {
711 /* Most variants are ignorable like collation variants. */
714 /* Start comparing only after the current index.
715 Previous loop should have already compared fromLocIndex.
717 for (toLocIndex
= fromLocIndex
+ 1; toLocIndex
< locCount
; toLocIndex
++) {
718 const char *toLocale
= uloc_getAvailable(toLocIndex
);
720 toCountryLen
= uloc_getCountry(toLocale
, toCountry
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
721 if(U_FAILURE(errorCode
)) {
722 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
723 fromLocale
, toLocale
, u_errorName(errorCode
));
727 if (toCountryLen
<= 0) {
728 /* Ignore countryless locales */
731 toVariantLen
= uloc_getVariant(toLocale
, toVariant
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
732 if (toVariantLen
> 0) {
733 /* Most variants are ignorable like collation variants. */
734 /* They're a variant for a reason. */
737 if (strcmp(fromCountry
, toCountry
) == 0) {
738 log_verbose("comparing fromLocale=%s toLocale=%s\n",
739 fromLocale
, toLocale
);
740 compareConsistentCountryInfo(fromLocale
, toLocale
);
747 findStringSetMismatch(const char *currLoc
, const UChar
*string
, int32_t langSize
,
748 USet
* mergedExemplarSet
,
749 UBool ignoreNumbers
, UChar32
* badCharPtr
) {
750 UErrorCode errorCode
= U_ZERO_ERROR
;
753 if (mergedExemplarSet
== NULL
) {
756 exemplarSet
= createFlattenSet(mergedExemplarSet
, &errorCode
);
757 if (U_FAILURE(errorCode
)) {
758 log_err("%s: error createFlattenSet returned %s\n", currLoc
, u_errorName(errorCode
));
762 for (strIdx
= 0; strIdx
< langSize
;) {
764 U16_NEXT(string
, strIdx
, langSize
, testChar
);
765 if (!uset_contains(exemplarSet
, testChar
)
766 && testChar
!= 0x0020 && testChar
!= 0x00A0 && testChar
!= 0x002e && testChar
!= 0x002c && testChar
!= 0x002d && testChar
!= 0x0027
767 && testChar
!= 0x005B && testChar
!= 0x005D && testChar
!= 0x2019 && testChar
!= 0x0f0b && testChar
!= 0x200C && testChar
!= 0x200D) {
768 if (!ignoreNumbers
|| (ignoreNumbers
&& (testChar
< 0x30 || testChar
> 0x39))) {
769 uset_close(exemplarSet
);
771 *badCharPtr
= testChar
;
777 uset_close(exemplarSet
);
783 /* include non-invariant chars */
785 myUCharsToChars(const UChar
* us
, char* cs
, int32_t len
){
797 findSetMatch( UScriptCode
*scriptCodes
, int32_t scriptsLen
,
800 USet
*scripts
[10]= {0};
801 char pattern
[256] = { '[', ':', 0x000 };
803 UChar uPattern
[256] = {0};
804 UErrorCode status
= U_ZERO_ERROR
;
807 /* create the sets with script codes */
808 for(i
= 0; i
<scriptsLen
; i
++){
809 strcat(pattern
, uscript_getShortName(scriptCodes
[i
]));
810 strcat(pattern
, ":]");
811 patternLen
= (int32_t)strlen(pattern
);
812 u_charsToUChars(pattern
, uPattern
, patternLen
);
813 scripts
[i
] = uset_openPattern(uPattern
, patternLen
, &status
);
814 if(U_FAILURE(status
)){
815 log_err("Could not create set for pattern %s. Error: %s\n", pattern
, u_errorName(status
));
820 if (strcmp(locale
, "uk") == 0 || strcmp(locale
, "uk_UA") == 0) {
821 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
822 uset_add(scripts
[0], 0x2bc);
824 if(U_SUCCESS(status
)){
825 UBool existsInScript
= FALSE
;
826 /* iterate over the exemplarSet and ascertain if all
827 * UChars in exemplarSet belong to the scripts returned
830 int32_t count
= uset_getItemCount(exemplarSet
);
832 for( i
=0; i
< count
; i
++){
836 int32_t strCapacity
= 0;
838 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
839 if(U_SUCCESS(status
)){
841 if(strCapacity
== 0){
842 /* ok the item is a range */
843 for( j
= 0; j
< scriptsLen
; j
++){
844 if(uset_containsRange(scripts
[j
], start
, end
) == TRUE
){
845 existsInScript
= TRUE
;
848 if(existsInScript
== FALSE
){
849 for( j
= 0; j
< scriptsLen
; j
++){
850 UChar toPattern
[500]={'\0'};
851 char pat
[500]={'\0'};
852 int32_t len
= uset_toPattern(scripts
[j
], toPattern
, 500, TRUE
, &status
);
853 len
= myUCharsToChars(toPattern
, pat
, len
);
854 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
));
856 log_err("Pattern: %s\n",pat
);
859 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
862 strCapacity
++; /* increment for NUL termination */
863 /* allocate the str and call the api again */
864 str
= (UChar
*) malloc(U_SIZEOF_UCHAR
* strCapacity
);
865 strCapacity
= uset_getItem(exemplarSet
, i
, &start
, &end
, str
, strCapacity
, &status
);
866 /* iterate over the scripts and figure out if the string contained is actually
869 for( j
= 0; j
< scriptsLen
; j
++){
870 if(uset_containsString(scripts
[j
],str
, strCapacity
) == TRUE
){
871 existsInScript
= TRUE
;
874 if(existsInScript
== FALSE
){
875 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale
);
884 for(i
= 0; i
<scriptsLen
; i
++){
885 uset_close(scripts
[i
]);
889 static void VerifyTranslation(void) {
890 UResourceBundle
*root
, *currentLocale
;
891 int32_t locCount
= uloc_countAvailable();
893 UErrorCode errorCode
= U_ZERO_ERROR
;
895 UScriptCode scripts
[USCRIPT_CODE_LIMIT
];
899 UResourceBundle
*resArray
;
902 log_data_err("At least root needs to be installed\n");
905 root
= ures_openDirect(NULL
, "root", &errorCode
);
906 if(U_FAILURE(errorCode
)) {
907 log_data_err("Can't open root\n");
910 for (locIndex
= 0; locIndex
< locCount
; locIndex
++) {
911 USet
* mergedExemplarSet
= NULL
;
912 errorCode
=U_ZERO_ERROR
;
913 currLoc
= uloc_getAvailable(locIndex
);
914 currentLocale
= ures_open(NULL
, currLoc
, &errorCode
);
915 if(errorCode
!= U_ZERO_ERROR
) {
916 if(U_SUCCESS(errorCode
)) {
917 /* It's installed, but there is no data.
918 It's installed for the g18n white paper [grhoten] */
919 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
920 uloc_getAvailable(locIndex
));
922 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
923 u_errorName(errorCode
),
924 uloc_getAvailable(locIndex
));
926 ures_close(currentLocale
);
930 UErrorCode exemplarStatus
= U_ZERO_ERROR
;
931 ULocaleData
* uld
= ulocdata_open(currLoc
, &exemplarStatus
);
932 if (U_SUCCESS(exemplarStatus
)) {
933 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, USET_ADD_CASE_MAPPINGS
, ULOCDATA_ES_STANDARD
, &exemplarStatus
);
934 if (U_SUCCESS(exemplarStatus
)) {
935 mergedExemplarSet
= uset_cloneAsThawed(exemplarSet
);
936 uset_close(exemplarSet
);
937 exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, USET_ADD_CASE_MAPPINGS
, ULOCDATA_ES_AUXILIARY
, &exemplarStatus
);
938 if (U_SUCCESS(exemplarStatus
)) {
939 uset_addAll(mergedExemplarSet
, exemplarSet
);
940 uset_close(exemplarSet
);
942 exemplarStatus
= U_ZERO_ERROR
;
943 exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_PUNCTUATION
, &exemplarStatus
);
944 if (U_SUCCESS(exemplarStatus
)) {
945 uset_addAll(mergedExemplarSet
, exemplarSet
);
946 uset_close(exemplarSet
);
949 log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc
, u_errorName(errorCode
));
953 log_err("error ulocdata_open for locale %s returned %s\n", currLoc
, u_errorName(errorCode
));
956 if (mergedExemplarSet
== NULL
/*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
957 log_verbose("skipping test for %s\n", currLoc
);
959 //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
960 // log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
963 UChar langBuffer
[128];
967 langSize
= uloc_getDisplayLanguage(currLoc
, currLoc
, langBuffer
, UPRV_LENGTHOF(langBuffer
), &errorCode
);
968 if (U_FAILURE(errorCode
)) {
969 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode
));
970 } else if (uprv_strncmp(currLoc
,"gez",3) == 0 || uprv_strcmp(currLoc
,"sa") == 0 || uprv_strncmp(currLoc
,"sa_",3) == 0) { // Apple xtra locales
971 log_verbose("skipping DisplayLanguage test for %s, name or exemplars may need adjustment\n", currLoc
);
973 strIdx
= findStringSetMismatch(currLoc
, langBuffer
, langSize
, mergedExemplarSet
, FALSE
, &badChar
);
976 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X in \"%s\"\n",
977 currLoc
, strIdx
, badChar
, u_austrncpy(bbuf
,langBuffer
,langSize
));
980 langSize
= uloc_getDisplayCountry(currLoc
, currLoc
, langBuffer
, UPRV_LENGTHOF(langBuffer
), &errorCode
);
981 if (U_FAILURE(errorCode
)) {
982 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode
));
984 if ( uprv_strcmp(currLoc
,"ba") == 0 || uprv_strncmp(currLoc
,"ba_",3) == 0 ||
985 uprv_strcmp(currLoc
,"cv") == 0 || uprv_strncmp(currLoc
,"cv_",3) == 0 ||
986 uprv_strcmp(currLoc
,"dv") == 0 || uprv_strncmp(currLoc
,"dv_",3) == 0 ||
987 uprv_strcmp(currLoc
,"sa") == 0 || uprv_strncmp(currLoc
,"sa_",3) == 0 ||
988 uprv_strncmp(currLoc
,"kaj",3) == 0 || uprv_strncmp(currLoc
,"kpe",3) == 0 ||
989 uprv_strncmp(currLoc
,"nqo",3) == 0 || uprv_strncmp(currLoc
,"sat",3) == 0 ||
990 uprv_strncmp(currLoc
,"syr",3) == 0 ||
991 uprv_strcmp(currLoc
,"ks_Deva") == 0 || uprv_strncmp(currLoc
,"mni_Mtei",8) == 0 ||
992 uprv_strcmp(currLoc
,"sd_Deva") == 0 ) { // Apple xtra locales
993 log_verbose("skipping day/month tests for %s, missing some translated names\n", currLoc
);
995 UResourceBundle
* cal
= ures_getByKey(currentLocale
, "calendar", NULL
, &errorCode
);
996 UResourceBundle
* greg
= ures_getByKeyWithFallback(cal
, "gregorian", NULL
, &errorCode
);
997 UResourceBundle
* names
= ures_getByKeyWithFallback(greg
, "dayNames", NULL
, &errorCode
);
998 UResourceBundle
* format
= ures_getByKeyWithFallback(names
, "format", NULL
, &errorCode
);
999 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
1001 if (U_FAILURE(errorCode
)) {
1002 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
1004 if (getTestOption(QUICK_OPTION
)) {
1008 end
= ures_getSize(resArray
);
1011 if ((uprv_strncmp(currLoc
,"lrc",3) == 0 || uprv_strncmp(currLoc
,"mzn",3) == 0) &&
1012 log_knownIssue("cldrbug:8899", "lrc and mzn locales don't have translated day names")) {
1016 for (idx
= 0; idx
< end
; idx
++) {
1017 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
1018 if (U_FAILURE(errorCode
)) {
1019 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1022 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, mergedExemplarSet
, TRUE
, &badChar
);
1023 if ( strIdx
>= 0 ) {
1024 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1025 currLoc
, idx
, strIdx
, badChar
);
1028 ures_close(resArray
);
1032 names
= ures_getByKeyWithFallback(greg
, "monthNames", NULL
, &errorCode
);
1033 format
= ures_getByKeyWithFallback(names
,"format", NULL
, &errorCode
);
1034 resArray
= ures_getByKeyWithFallback(format
, "wide", NULL
, &errorCode
);
1035 if (U_FAILURE(errorCode
)) {
1036 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode
));
1038 if (getTestOption(QUICK_OPTION
)) {
1042 end
= ures_getSize(resArray
);
1045 for (idx
= 0; idx
< end
; idx
++) {
1046 const UChar
*fromBundleStr
= ures_getStringByIndex(resArray
, idx
, &langSize
, &errorCode
);
1047 if (U_FAILURE(errorCode
)) {
1048 log_err("error ures_getStringByIndex(%d) returned %s\n", idx
, u_errorName(errorCode
));
1051 strIdx
= findStringSetMismatch(currLoc
, fromBundleStr
, langSize
, mergedExemplarSet
, TRUE
, &badChar
);
1053 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1054 currLoc
, idx
, strIdx
, badChar
);
1057 ures_close(resArray
);
1063 errorCode
= U_ZERO_ERROR
;
1064 numScripts
= uscript_getCode(currLoc
, scripts
, UPRV_LENGTHOF(scripts
), &errorCode
);
1065 if (strcmp(currLoc
, "yi") == 0 && numScripts
> 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1066 scripts
[0] = USCRIPT_HEBREW
;
1068 if (numScripts
== 0) {
1069 log_err("uscript_getCode(%s) doesn't work.\n", currLoc
);
1070 }else if(scripts
[0] == USCRIPT_COMMON
){
1071 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc
);
1074 /* test that the scripts are a superset of exemplar characters. */
1076 ULocaleData
*uld
= ulocdata_open(currLoc
,&errorCode
);
1077 USet
*exemplarSet
= ulocdata_getExemplarSet(uld
, NULL
, 0, ULOCDATA_ES_STANDARD
, &errorCode
);
1078 /* test if exemplar characters are part of script code */
1079 findSetMatch(scripts
, numScripts
, exemplarSet
, currLoc
);
1080 uset_close(exemplarSet
);
1081 ulocdata_close(uld
);
1084 /* test that the paperSize API works */
1086 int32_t height
=0, width
=0;
1087 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1088 if(U_FAILURE(errorCode
)){
1089 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1091 if(strstr(currLoc
, "_US")!=NULL
&& height
!= 279 && width
!= 216 ){
1092 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1095 /* test that the MeasurementSystem API works */
1097 char fullLoc
[ULOC_FULLNAME_CAPACITY
];
1098 UMeasurementSystem measurementSystem
;
1099 int32_t height
= 0, width
= 0;
1101 uloc_addLikelySubtags(currLoc
, fullLoc
, ULOC_FULLNAME_CAPACITY
, &errorCode
);
1103 errorCode
= U_ZERO_ERROR
;
1104 measurementSystem
= ulocdata_getMeasurementSystem(currLoc
, &errorCode
);
1105 if (U_FAILURE(errorCode
)) {
1106 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1108 if ( strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_MM")!=NULL
|| strstr(fullLoc
, "_LR")!=NULL
) {
1109 if(measurementSystem
!= UMS_US
){
1110 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1112 } else if ( strstr(fullLoc
, "_GB")!=NULL
) {
1113 if(measurementSystem
!= UMS_UK
){
1114 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1116 } else if (measurementSystem
!= UMS_SI
) {
1117 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc
);
1121 errorCode
= U_ZERO_ERROR
;
1122 ulocdata_getPaperSize(currLoc
, &height
, &width
, &errorCode
);
1123 if (U_FAILURE(errorCode
)) {
1124 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc
, u_errorName(errorCode
));
1126 if ( strstr(fullLoc
, "_US")!=NULL
|| strstr(fullLoc
, "_BZ")!=NULL
|| strstr(fullLoc
, "_CA")!=NULL
|| strstr(fullLoc
, "_CL")!=NULL
||
1127 strstr(fullLoc
, "_CO")!=NULL
|| strstr(fullLoc
, "_CR")!=NULL
|| strstr(fullLoc
, "_GT")!=NULL
|| strstr(fullLoc
, "_MX")!=NULL
||
1128 strstr(fullLoc
, "_NI")!=NULL
|| strstr(fullLoc
, "_PA")!=NULL
|| strstr(fullLoc
, "_PH")!=NULL
|| strstr(fullLoc
, "_PR")!=NULL
||
1129 strstr(fullLoc
, "_SV")!=NULL
|| strstr(fullLoc
, "_VE")!=NULL
) {
1130 if (height
!= 279 || width
!= 216) {
1131 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1133 } else if (height
!= 297 || width
!= 210) {
1134 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc
);
1139 if (mergedExemplarSet
!= NULL
) {
1140 uset_close(mergedExemplarSet
);
1142 ures_close(currentLocale
);
1148 /* adjust this limit as appropriate */
1149 #define MAX_SCRIPTS_PER_LOCALE 8
1151 static void TestExemplarSet(void){
1152 int32_t i
, j
, k
, m
, n
;
1153 int32_t equalCount
= 0;
1154 UErrorCode ec
= U_ZERO_ERROR
;
1155 UEnumeration
* avail
;
1156 USet
* exemplarSets
[2];
1157 USet
* unassignedSet
;
1158 UScriptCode code
[MAX_SCRIPTS_PER_LOCALE
];
1159 USet
* codeSets
[MAX_SCRIPTS_PER_LOCALE
];
1161 char cbuf
[32]; /* 9 should be enough */
1162 UChar ubuf
[64]; /* adjust as needed */
1163 UBool existsInScript
;
1168 unassignedSet
= NULL
;
1169 exemplarSets
[0] = NULL
;
1170 exemplarSets
[1] = NULL
;
1171 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1175 avail
= ures_openAvailableLocales(NULL
, &ec
);
1176 if (!assertSuccess("ures_openAvailableLocales", &ec
)) goto END
;
1177 n
= uenum_count(avail
, &ec
);
1178 if (!assertSuccess("uenum_count", &ec
)) goto END
;
1180 u_uastrcpy(ubuf
, "[:unassigned:]");
1181 unassignedSet
= uset_openPattern(ubuf
, -1, &ec
);
1182 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1185 const char* locale
= uenum_next(avail
, NULL
, &ec
);
1186 if (!assertSuccess("uenum_next", &ec
)) goto END
;
1187 log_verbose("%s\n", locale
);
1188 for (k
=0; k
<2; ++k
) {
1189 uint32_t option
= (k
==0) ? 0 : USET_CASE_INSENSITIVE
;
1190 ULocaleData
*uld
= ulocdata_open(locale
,&ec
);
1191 USet
* exemplarSet
= ulocdata_getExemplarSet(uld
,NULL
, option
, ULOCDATA_ES_STANDARD
, &ec
);
1192 uset_close(exemplarSets
[k
]);
1193 ulocdata_close(uld
);
1194 exemplarSets
[k
] = exemplarSet
;
1195 if (!assertSuccess("ulocaledata_getExemplarSet", &ec
)) goto END
;
1197 if (uset_containsSome(exemplarSet
, unassignedSet
)) {
1198 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale
);
1200 codeLen
= uscript_getCode(locale
, code
, 8, &ec
);
1201 if (strcmp(locale
, "yi") == 0 && codeLen
> 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1202 code
[0] = USCRIPT_HEBREW
;
1204 if (!assertSuccess("uscript_getCode", &ec
)) goto END
;
1206 for (j
=0; j
<MAX_SCRIPTS_PER_LOCALE
; ++j
) {
1207 uset_close(codeSets
[j
]);
1210 for (j
=0; j
<codeLen
; ++j
) {
1211 uprv_strcpy(cbuf
, "[:");
1213 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale
);
1216 uprv_strcat(cbuf
, uscript_getShortName(code
[j
]));
1217 uprv_strcat(cbuf
, ":]");
1218 u_uastrcpy(ubuf
, cbuf
);
1219 codeSets
[j
] = uset_openPattern(ubuf
, -1, &ec
);
1221 if (!assertSuccess("uset_openPattern", &ec
)) goto END
;
1223 existsInScript
= FALSE
;
1224 itemCount
= uset_getItemCount(exemplarSet
);
1225 for (m
=0; m
<itemCount
&& !existsInScript
; ++m
) {
1226 strLen
= uset_getItem(exemplarSet
, m
, &start
, &end
, ubuf
,
1227 UPRV_LENGTHOF(ubuf
), &ec
);
1228 /* failure here might mean str[] needs to be larger */
1229 if (!assertSuccess("uset_getItem", &ec
)) goto END
;
1231 for (j
=0; j
<codeLen
; ++j
) {
1232 if (codeSets
[j
]!=NULL
&& uset_containsRange(codeSets
[j
], start
, end
)) {
1233 existsInScript
= TRUE
;
1238 for (j
=0; j
<codeLen
; ++j
) {
1239 if (codeSets
[j
]!=NULL
&& uset_containsString(codeSets
[j
], ubuf
, strLen
)) {
1240 existsInScript
= TRUE
;
1247 if (existsInScript
== FALSE
){
1248 log_err("ExemplarSet containment failed for locale : %s\n", locale
);
1251 assertTrue("case-folded is a superset",
1252 uset_containsAll(exemplarSets
[1], exemplarSets
[0]));
1253 if (uset_equals(exemplarSets
[1], exemplarSets
[0])) {
1257 /* Note: The case-folded set should sometimes be a strict superset
1258 and sometimes be equal. */
1259 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1260 equalCount
> 0 && equalCount
< n
);
1264 uset_close(exemplarSets
[0]);
1265 uset_close(exemplarSets
[1]);
1266 uset_close(unassignedSet
);
1267 for (i
=0; i
<MAX_SCRIPTS_PER_LOCALE
; ++i
) {
1268 uset_close(codeSets
[i
]);
1272 enum { kUBufMax
= 32 };
1273 static void TestLocaleDisplayPattern(void){
1275 UChar pattern
[kUBufMax
] = {0,};
1276 UChar separator
[kUBufMax
] = {0,};
1278 static const UChar enExpectPat
[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1279 static const UChar enExpectSep
[] = { 0x002C,0x0020,0 }; /* ", " */
1280 static const UChar zhExpectPat
[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1281 static const UChar zhExpectSep
[] = { 0xFF0C,0 };
1283 status
= U_ZERO_ERROR
;
1284 uld
= ulocdata_open("en", &status
);
1285 if(U_FAILURE(status
)){
1286 log_data_err("ulocdata_open en error %s", u_errorName(status
));
1288 ulocdata_getLocaleDisplayPattern(uld
, pattern
, kUBufMax
, &status
);
1289 if (U_FAILURE(status
)){
1290 log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status
));
1291 } else if (u_strcmp(pattern
, enExpectPat
) != 0) {
1292 log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1294 status
= U_ZERO_ERROR
;
1295 ulocdata_getLocaleSeparator(uld
, separator
, kUBufMax
, &status
);
1296 if (U_FAILURE(status
)){
1297 log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status
));
1298 } else if (u_strcmp(separator
, enExpectSep
) != 0) {
1299 log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1301 ulocdata_close(uld
);
1304 status
= U_ZERO_ERROR
;
1305 uld
= ulocdata_open("zh", &status
);
1306 if(U_FAILURE(status
)){
1307 log_data_err("ulocdata_open zh error %s", u_errorName(status
));
1309 ulocdata_getLocaleDisplayPattern(uld
, pattern
, kUBufMax
, &status
);
1310 if (U_FAILURE(status
)){
1311 log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status
));
1312 } else if (u_strcmp(pattern
, zhExpectPat
) != 0) {
1313 log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1315 status
= U_ZERO_ERROR
;
1316 ulocdata_getLocaleSeparator(uld
, separator
, kUBufMax
, &status
);
1317 if (U_FAILURE(status
)){
1318 log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status
));
1319 } else if (u_strcmp(separator
, zhExpectSep
) != 0) {
1320 log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1322 ulocdata_close(uld
);
1326 static void TestCoverage(void){
1327 ULocaleDataDelimiterType types
[] = {
1328 ULOCDATA_QUOTATION_START
, /* Quotation start */
1329 ULOCDATA_QUOTATION_END
, /* Quotation end */
1330 ULOCDATA_ALT_QUOTATION_START
, /* Alternate quotation start */
1331 ULOCDATA_ALT_QUOTATION_END
, /* Alternate quotation end */
1332 ULOCDATA_DELIMITER_COUNT
1336 UErrorCode status
= U_ZERO_ERROR
;
1337 ULocaleData
*uld
= ulocdata_open(uloc_getDefault(), &status
);
1339 if(U_FAILURE(status
)){
1340 log_data_err("ulocdata_open error");
1345 for(i
= 0; i
< ULOCDATA_DELIMITER_COUNT
; i
++){
1346 UChar result
[32] = {0,};
1347 status
= U_ZERO_ERROR
;
1348 ulocdata_getDelimiter(uld
, types
[i
], result
, 32, &status
);
1349 if (U_FAILURE(status
)){
1350 log_err("ulocdata_getgetDelimiter error with type %d", types
[i
]);
1354 sub
= ulocdata_getNoSubstitute(uld
);
1355 ulocdata_setNoSubstitute(uld
,sub
);
1356 ulocdata_close(uld
);
1359 static void TestIndexChars(void) {
1360 /* Very basic test of ULOCDATA_ES_INDEX.
1361 * No comprehensive test of data, just basic check that the code path is alive.
1363 UErrorCode status
= U_ZERO_ERROR
;
1365 USet
*exemplarChars
;
1368 uld
= ulocdata_open("en", &status
);
1369 exemplarChars
= uset_openEmpty();
1370 indexChars
= uset_openEmpty();
1371 ulocdata_getExemplarSet(uld
, exemplarChars
, 0, ULOCDATA_ES_STANDARD
, &status
);
1372 ulocdata_getExemplarSet(uld
, indexChars
, 0, ULOCDATA_ES_INDEX
, &status
);
1373 if (U_FAILURE(status
)) {
1374 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__
, __LINE__
, u_errorName(status
));
1377 /* en data, standard exemplars are [a-z], lower case. */
1378 /* en data, index characters are [A-Z], upper case. */
1379 if ((uset_contains(exemplarChars
, (UChar32
)0x41) || uset_contains(indexChars
, (UChar32
)0x61))) {
1380 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1383 if (!(uset_contains(exemplarChars
, (UChar32
)0x61) && uset_contains(indexChars
, (UChar32
)0x41) )) {
1384 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__
, __LINE__
);
1389 uset_close(exemplarChars
);
1390 uset_close(indexChars
);
1391 ulocdata_close(uld
);
1396 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1397 static void TestCurrencyList(void){
1398 #if !UCONFIG_NO_FORMATTING
1399 UErrorCode errorCode
= U_ZERO_ERROR
;
1400 int32_t structLocaleCount
, currencyCount
;
1401 UEnumeration
*en
= ucurr_openISOCurrencies(UCURR_ALL
, &errorCode
);
1402 const char *isoCode
, *structISOCode
;
1403 UResourceBundle
*subBundle
;
1404 UResourceBundle
*currencies
= ures_openDirect(loadTestData(&errorCode
), "structLocale", &errorCode
);
1405 if(U_FAILURE(errorCode
)) {
1406 log_data_err("Can't open structLocale\n");
1409 currencies
= ures_getByKey(currencies
, "Currencies", currencies
, &errorCode
);
1410 currencyCount
= uenum_count(en
, &errorCode
);
1411 structLocaleCount
= ures_getSize(currencies
);
1412 if (currencyCount
!= structLocaleCount
) {
1413 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount
, currencyCount
);
1414 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1415 ures_resetIterator(currencies
);
1416 while ((isoCode
= uenum_next(en
, NULL
, &errorCode
)) != NULL
&& ures_hasNext(currencies
)) {
1417 subBundle
= ures_getNextResource(currencies
, NULL
, &errorCode
);
1418 structISOCode
= ures_getKey(subBundle
);
1419 ures_close(subBundle
);
1420 if (strcmp(structISOCode
, isoCode
) != 0) {
1421 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode
, isoCode
);
1427 ures_close(currencies
);
1433 static void TestAvailableIsoCodes(void){
1434 #if !UCONFIG_NO_FORMATTING
1435 UErrorCode errorCode
= U_ZERO_ERROR
;
1436 const char* eurCode
= "EUR";
1437 const char* usdCode
= "USD";
1438 const char* lastCode
= "RHD";
1439 const char* zzzCode
= "ZZZ";
1440 UDate date1950
= (UDate
)-630720000000.0;/* year 1950 */
1441 UDate date1970
= (UDate
)0.0; /* year 1970 */
1442 UDate date1975
= (UDate
)173448000000.0; /* year 1975 */
1443 UDate date1978
= (UDate
)260172000000.0; /* year 1978 */
1444 UDate date1981
= (UDate
)346896000000.0; /* year 1981 */
1445 UDate date1992
= (UDate
)693792000000.0; /* year 1992 */
1446 UChar
* isoCode
= (UChar
*)malloc(sizeof(UChar
) * (uprv_strlen(usdCode
) + 1));
1448 /* testing available codes with no time ranges */
1449 u_charsToUChars(eurCode
, isoCode
, (int32_t)uprv_strlen(usdCode
) + 1);
1450 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1451 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode
);
1454 u_charsToUChars(usdCode
, isoCode
, (int32_t)uprv_strlen(zzzCode
) + 1);
1455 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1456 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode
);
1459 u_charsToUChars(zzzCode
, isoCode
, (int32_t)uprv_strlen(zzzCode
) + 1);
1460 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1461 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode
);
1464 u_charsToUChars(lastCode
, isoCode
, (int32_t)uprv_strlen(zzzCode
) + 1);
1465 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1466 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode
);
1469 /* RHD was used from 1970-02-17 to 1980-04-18*/
1472 if (ucurr_isAvailable(isoCode
, date1970
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1473 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode
);
1476 if (ucurr_isAvailable(isoCode
, date1975
, U_DATE_MAX
, &errorCode
) == FALSE
) {
1477 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode
);
1480 if (ucurr_isAvailable(isoCode
, date1981
, U_DATE_MAX
, &errorCode
) == TRUE
) {
1481 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode
);
1485 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1970
, &errorCode
) == TRUE
) {
1486 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode
);
1489 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1975
, &errorCode
) == FALSE
) {
1490 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode
);
1493 if (ucurr_isAvailable(isoCode
, U_DATE_MIN
, date1981
, &errorCode
) == FALSE
) {
1494 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode
);
1498 if (ucurr_isAvailable(isoCode
, date1975
, date1978
, &errorCode
) == FALSE
) {
1499 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode
);
1502 if (ucurr_isAvailable(isoCode
, date1970
, date1975
, &errorCode
) == FALSE
) {
1503 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode
);
1506 if (ucurr_isAvailable(isoCode
, date1975
, date1981
, &errorCode
) == FALSE
) {
1507 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode
);
1510 if (ucurr_isAvailable(isoCode
, date1970
, date1981
, &errorCode
) == FALSE
) {
1511 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode
);
1514 if (ucurr_isAvailable(isoCode
, date1981
, date1992
, &errorCode
) == TRUE
) {
1515 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode
);
1518 if (ucurr_isAvailable(isoCode
, date1950
, date1970
, &errorCode
) == TRUE
) {
1519 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode
);
1522 /* wrong range - from > to*/
1523 if (ucurr_isAvailable(isoCode
, date1975
, date1970
, &errorCode
) == TRUE
) {
1524 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode
);
1525 } else if (errorCode
!= U_ILLEGAL_ARGUMENT_ERROR
) {
1526 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode
);
1536 const UChar
* quoteStart
;
1537 const UChar
* quoteEnd
;
1538 const UChar
* altQuoteStart
;
1539 const UChar
* altQuoteEnd
;
1541 static const DelimItem delimItems
[] = {
1542 { "en", u
"“", u
"”", u
"‘", u
"’"},
1543 { "es", u
"«", u
"»", u
"“", u
"”"},
1544 { "es_MX", u
"“", u
"”", u
"‘", u
"’"},
1545 { "ja", u
"「", u
"」", u
"『", u
"』"},
1546 { NULL
,NULL
,NULL
,NULL
,NULL
}
1548 enum {kMaxDelimLen
= 8};
1550 static void TestDelimiters(void){
1551 const DelimItem
* itemPtr
;
1552 for (itemPtr
= delimItems
; itemPtr
->locale
!= NULL
; itemPtr
++) {
1553 UErrorCode status
= U_ZERO_ERROR
;
1554 ULocaleData
* uldat
= ulocdata_open(itemPtr
->locale
, &status
);
1555 if (U_FAILURE(status
)) {
1556 log_data_err("FAIL: ulocdata_open fails for locale %s: %s\n", itemPtr
->locale
, u_errorName(status
));
1558 UChar quoteStart
[kMaxDelimLen
+1];
1559 UChar quoteEnd
[kMaxDelimLen
+1];
1560 UChar altQuoteStart
[kMaxDelimLen
+1];
1561 UChar altQuoteEnd
[kMaxDelimLen
+1];
1563 ulocdata_getDelimiter(uldat
, ULOCDATA_QUOTATION_START
, quoteStart
, kMaxDelimLen
, &status
);
1564 quoteStart
[kMaxDelimLen
] = 0;
1565 ulocdata_getDelimiter(uldat
, ULOCDATA_QUOTATION_END
, quoteEnd
, kMaxDelimLen
, &status
);
1566 quoteEnd
[kMaxDelimLen
] = 0;
1567 ulocdata_getDelimiter(uldat
, ULOCDATA_ALT_QUOTATION_START
, altQuoteStart
, kMaxDelimLen
, &status
);
1568 altQuoteStart
[kMaxDelimLen
] = 0;
1569 ulocdata_getDelimiter(uldat
, ULOCDATA_ALT_QUOTATION_END
, altQuoteEnd
, kMaxDelimLen
, &status
);
1570 altQuoteEnd
[kMaxDelimLen
] = 0;
1571 if (U_FAILURE(status
)) {
1572 log_err("FAIL: ulocdata_getDelimiter fails for locale %s: %s\n", itemPtr
->locale
, u_errorName(status
));
1573 } else if (u_strcmp(quoteStart
, itemPtr
->quoteStart
) != 0 || u_strcmp(quoteEnd
, itemPtr
->quoteEnd
) != 0 ||
1574 u_strcmp(altQuoteStart
, itemPtr
->altQuoteStart
) != 0 || u_strcmp(altQuoteEnd
, itemPtr
->altQuoteEnd
) != 0) {
1575 log_err("FAIL: ulocdata_getDelimiter error for locale %s, one or more delimiters not as expected\n", itemPtr
->locale
);
1577 ulocdata_close(uldat
);
1583 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1585 void addCLDRTest(TestNode
** root
);
1587 void addCLDRTest(TestNode
** root
)
1589 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1590 TESTCASE(TestLocaleStructure
);
1591 TESTCASE(TestCurrencyList
);
1593 TESTCASE(TestConsistentCountryInfo
);
1594 TESTCASE(VerifyTranslation
);
1595 TESTCASE(TestExemplarSet
);
1596 TESTCASE(TestLocaleDisplayPattern
);
1597 TESTCASE(TestCoverage
);
1598 TESTCASE(TestIndexChars
);
1599 TESTCASE(TestAvailableIsoCodes
);
1600 TESTCASE(TestDelimiters
);