]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cldrtest.c
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cldrtest.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2016, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7 #include "cintltst.h"
8 #include "unicode/ures.h"
9 #include "unicode/ucurr.h"
10 #include "unicode/ustring.h"
11 #include "unicode/uset.h"
12 #include "unicode/udat.h"
13 #include "unicode/uscript.h"
14 #include "unicode/ulocdata.h"
15 #include "cmemory.h"
16 #include "cstring.h"
17 #include "locmap.h"
18 #include "uresimp.h"
19
20 /*
21 returns a new UnicodeSet that is a flattened form of the original
22 UnicodeSet.
23 */
24 static USet*
25 createFlattenSet(USet *origSet, UErrorCode *status) {
26
27
28 USet *newSet = NULL;
29 int32_t origItemCount = 0;
30 int32_t idx, graphmeSize;
31 UChar32 start, end;
32 UChar graphme[64];
33 if (U_FAILURE(*status)) {
34 log_err("createFlattenSet called with %s\n", u_errorName(*status));
35 return NULL;
36 }
37 newSet = uset_open(1, 0);
38 origItemCount = uset_getItemCount(origSet);
39 for (idx = 0; idx < origItemCount; idx++) {
40 graphmeSize = uset_getItem(origSet, idx,
41 &start, &end,
42 graphme, UPRV_LENGTHOF(graphme),
43 status);
44 if (U_FAILURE(*status)) {
45 log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status));
46 *status = U_ZERO_ERROR;
47 }
48 if (graphmeSize) {
49 uset_addAllCodePoints(newSet, graphme, graphmeSize);
50 }
51 else {
52 uset_addRange(newSet, start, end);
53 }
54 }
55 uset_closeOver(newSet,USET_CASE_INSENSITIVE);
56 return newSet;
57 }
58
59 static UBool
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){
68 return TRUE;
69 }
70 return FALSE;
71 }
72 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
73 static void
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;
78
79 ures_resetIterator(root);
80 ures_resetIterator(currentBundle);
81 while (ures_hasNext(currentBundle)) {
82 const char *subBundleKey = NULL;
83 const char *currentBundleKey = NULL;
84
85 errorCode = U_ZERO_ERROR;
86 currentBundleKey = ures_getKey(currentBundle);
87 (void)currentBundleKey; /* Suppress set but not used warning. */
88 subBundle = ures_getNextResource(currentBundle, NULL, &errorCode);
89 if (U_FAILURE(errorCode)) {
90 log_err("Can't open a resource for lnocale %s. Error: %s\n", locale, u_errorName(errorCode));
91 continue;
92 }
93 subBundleKey = ures_getKey(subBundle);
94
95
96 subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode);
97 if (U_FAILURE(errorCode)) {
98 log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n",
99 subBundleKey,
100 ures_getKey(currentBundle),
101 rootName,
102 locale);
103 ures_close(subBundle);
104 continue;
105 }
106 if (ures_getType(subRootBundle) != ures_getType(subBundle)) {
107 log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n"
108 "\troot=%d, locale=%d\n",
109 subBundleKey,
110 ures_getKey(currentBundle),
111 locale,
112 ures_getType(subRootBundle),
113 ures_getType(subBundle));
114 ures_close(subBundle);
115 continue;
116 }
117 else if (ures_getType(subBundle) == URES_INT_VECTOR) {
118 int32_t minSize;
119 int32_t subBundleSize;
120 int32_t idx;
121 UBool sameArray = TRUE;
122 const int32_t *subRootBundleArr = ures_getIntVector(subRootBundle, &minSize, &errorCode);
123 const int32_t *subBundleArr = ures_getIntVector(subBundle, &subBundleSize, &errorCode);
124
125 if (minSize > subBundleSize) {
126 minSize = subBundleSize;
127 log_err("Arrays are different size with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
128 subBundleKey,
129 ures_getKey(currentBundle),
130 locale);
131 }
132
133 for (idx = 0; idx < minSize && sameArray; idx++) {
134 if (subRootBundleArr[idx] != subBundleArr[idx]) {
135 sameArray = FALSE;
136 }
137 if (strcmp(subBundleKey, "DateTimeElements") == 0
138 && (subBundleArr[idx] < 1 || 7 < subBundleArr[idx]))
139 {
140 log_err("Value out of range with key \"%s\" at index %d in \"%s\" for locale \"%s\"\n",
141 subBundleKey,
142 idx,
143 ures_getKey(currentBundle),
144 locale);
145 }
146 }
147 /* Special exception es_US and DateTimeElements */
148 if (sameArray
149 && !(strcmp(locale, "es_US") == 0 && strcmp(subBundleKey, "DateTimeElements") == 0))
150 {
151 log_err("Integer vectors are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
152 subBundleKey,
153 ures_getKey(currentBundle),
154 locale);
155 }
156 }
157 else if (ures_getType(subBundle) == URES_ARRAY) {
158 UResourceBundle *subSubBundle = ures_getByIndex(subBundle, 0, NULL, &errorCode);
159 UResourceBundle *subSubRootBundle = ures_getByIndex(subRootBundle, 0, NULL, &errorCode);
160
161 if (U_SUCCESS(errorCode)
162 && (ures_getType(subSubBundle) == URES_ARRAY || ures_getType(subSubRootBundle) == URES_ARRAY))
163 {
164 /* Here is one of the recursive parts */
165 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
166 }
167 else {
168 int32_t minSize = ures_getSize(subRootBundle);
169 int32_t idx;
170 UBool sameArray = TRUE;
171
172 if (minSize > ures_getSize(subBundle)) {
173 minSize = ures_getSize(subBundle);
174 }
175
176 if ((subBundleKey == NULL
177 || (subBundleKey != NULL && strcmp(subBundleKey, "LocaleScript") != 0 && !isCurrencyPreEuro(subBundleKey)))
178 && ures_getSize(subRootBundle) != ures_getSize(subBundle))
179 {
180 log_err("Different size array with key \"%s\" in \"%s\" from root for locale \"%s\"\n"
181 "\troot array size=%d, locale array size=%d\n",
182 subBundleKey,
183 ures_getKey(currentBundle),
184 locale,
185 ures_getSize(subRootBundle),
186 ures_getSize(subBundle));
187 }
188 /*
189 if(isCurrencyPreEuro(subBundleKey) && ures_getSize(subBundle)!=3){
190 log_err("Different size array with key \"%s\" in \"%s\" for locale \"%s\" the expected size is 3 got size=%d\n",
191 subBundleKey,
192 ures_getKey(currentBundle),
193 locale,
194 ures_getSize(subBundle));
195 }
196 */
197 for (idx = 0; idx < minSize; idx++) {
198 int32_t rootStrLen, localeStrLen;
199 const UChar *rootStr = ures_getStringByIndex(subRootBundle,idx,&rootStrLen,&errorCode);
200 const UChar *localeStr = ures_getStringByIndex(subBundle,idx,&localeStrLen,&errorCode);
201 if (rootStr && localeStr && U_SUCCESS(errorCode)) {
202 if (u_strcmp(rootStr, localeStr) != 0) {
203 sameArray = FALSE;
204 }
205 }
206 else {
207 if ( rootStrLen > 1 && rootStr[0] == 0x41 && rootStr[1] >= 0x30 && rootStr[1] <= 0x39 ) {
208 /* A2 or A4 in the root string indicates that the resource can optionally be an array instead of a */
209 /* string. Attempt to read it as an array. */
210 errorCode = U_ZERO_ERROR;
211 arr = ures_getByIndex(subBundle,idx,NULL,&errorCode);
212 if (U_FAILURE(errorCode)) {
213 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
214 subBundleKey,
215 ures_getKey(currentBundle),
216 idx,
217 locale);
218 continue;
219 }
220 if (ures_getType(arr) != URES_ARRAY || ures_getSize(arr) != (int32_t)rootStr[1] - 0x30) {
221 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",
222 rootStr[1] - 0x30,
223 subBundleKey,
224 ures_getKey(currentBundle),
225 idx,
226 locale);
227 ures_close(arr);
228 continue;
229 }
230 localeStr = ures_getStringByIndex(arr,0,&localeStrLen,&errorCode);
231 ures_close(arr);
232 if (U_FAILURE(errorCode)) {
233 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 subBundleKey,
235 ures_getKey(currentBundle),
236 idx,
237 locale);
238 continue;
239 }
240 } else {
241 log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n",
242 subBundleKey,
243 ures_getKey(currentBundle),
244 idx,
245 locale);
246 continue;
247 }
248 }
249 if (localeStr[0] == (UChar)0x20) {
250 log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n",
251 subBundleKey,
252 idx,
253 ures_getKey(currentBundle),
254 locale);
255 }
256 else if ((localeStr[localeStrLen - 1] == (UChar)0x20) && (strcmp(subBundleKey,"separator") != 0)) {
257 log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n",
258 subBundleKey,
259 idx,
260 ures_getKey(currentBundle),
261 locale);
262 }
263 else if (subBundleKey != NULL
264 && strcmp(subBundleKey, "DateTimePatterns") == 0)
265 {
266 int32_t quoted = 0;
267 const UChar *localeStrItr = localeStr;
268 while (*localeStrItr) {
269 if (*localeStrItr == (UChar)0x27 /* ' */) {
270 quoted++;
271 }
272 else if ((quoted % 2) == 0) {
273 /* Search for unquoted characters */
274 if (4 <= idx && idx <= 7
275 && (*localeStrItr == (UChar)0x6B /* k */
276 || *localeStrItr == (UChar)0x48 /* H */
277 || *localeStrItr == (UChar)0x6D /* m */
278 || *localeStrItr == (UChar)0x73 /* s */
279 || *localeStrItr == (UChar)0x53 /* S */
280 || *localeStrItr == (UChar)0x61 /* a */
281 || *localeStrItr == (UChar)0x68 /* h */
282 || *localeStrItr == (UChar)0x7A /* z */))
283 {
284 log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n",
285 subBundleKey,
286 idx,
287 locale);
288 }
289 else if (0 <= idx && idx <= 3
290 && (*localeStrItr == (UChar)0x47 /* G */
291 || *localeStrItr == (UChar)0x79 /* y */
292 || *localeStrItr == (UChar)0x4D /* M */
293 || *localeStrItr == (UChar)0x64 /* d */
294 || *localeStrItr == (UChar)0x45 /* E */
295 || *localeStrItr == (UChar)0x44 /* D */
296 || *localeStrItr == (UChar)0x46 /* F */
297 || *localeStrItr == (UChar)0x77 /* w */
298 || *localeStrItr == (UChar)0x57 /* W */))
299 {
300 log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n",
301 subBundleKey,
302 idx,
303 locale);
304 }
305 }
306 localeStrItr++;
307 }
308 }
309 else if (idx == 4 && subBundleKey != NULL
310 && strcmp(subBundleKey, "NumberElements") == 0
311 && u_charDigitValue(localeStr[0]) != 0)
312 {
313 log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n",
314 subBundleKey,
315 idx,
316 locale);
317 }
318 }
319 (void)sameArray; /* Suppress set but not used warning. */
320 /* if (sameArray && strcmp(rootName, "root") == 0) {
321 log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n",
322 subBundleKey,
323 ures_getKey(currentBundle),
324 locale);
325 }*/
326 }
327 ures_close(subSubBundle);
328 ures_close(subSubRootBundle);
329 }
330 else if (ures_getType(subBundle) == URES_STRING) {
331 int32_t len = 0;
332 const UChar *string = ures_getString(subBundle, &len, &errorCode);
333 if (U_FAILURE(errorCode) || string == NULL) {
334 log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n",
335 subBundleKey,
336 ures_getKey(currentBundle),
337 locale);
338 } else if (string[0] == (UChar)0x20) {
339 log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n",
340 subBundleKey,
341 ures_getKey(currentBundle),
342 locale);
343 /* localeDisplayPattern/separator can end with a space */
344 } else if (string[len - 1] == (UChar)0x20 && (strcmp(subBundleKey,"separator"))) {
345 log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n",
346 subBundleKey,
347 ures_getKey(currentBundle),
348 locale);
349 } else if (strcmp(subBundleKey, "localPatternChars") == 0) {
350 /* Note: We no longer import localPatternChars data starting
351 * ICU 3.8. So it never comes into this else if block. (ticket#5597)
352 */
353
354 /* Check well-formedness of localPatternChars. First, the
355 * length must match the number of fields defined by
356 * DateFormat. Second, each character in the string must
357 * be in the set [A-Za-z]. Finally, each character must be
358 * unique.
359 */
360 int32_t i,j;
361 #if !UCONFIG_NO_FORMATTING
362 if (len != UDAT_FIELD_COUNT) {
363 log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n",
364 subBundleKey,
365 locale);
366 }
367 #endif
368 /* Check char validity. */
369 for (i=0; i<len; ++i) {
370 if (!((string[i] >= 65/*'A'*/ && string[i] <= 90/*'Z'*/) ||
371 (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) {
372 log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n",
373 subBundleKey,
374 (char) string[i],
375 locale);
376 }
377 /* Do O(n^2) check for duplicate chars. */
378 for (j=0; j<i; ++j) {
379 if (string[j] == string[i]) {
380 log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n",
381 subBundleKey,
382 (char) string[i],
383 locale);
384 }
385 }
386 }
387 }
388 /* No fallback was done. Check for duplicate data */
389 /* The ures_* API does not do fallback of sub-resource bundles,
390 So we can't do this now. */
391 #if 0
392 else if (strcmp(locale, "root") != 0 && errorCode == U_ZERO_ERROR) {
393
394 const UChar *rootString = ures_getString(subRootBundle, &len, &errorCode);
395 if (U_FAILURE(errorCode) || rootString == NULL) {
396 log_err("Can't open a string with key \"%s\" in \"%s\" in root\n",
397 ures_getKey(subRootBundle),
398 ures_getKey(currentBundle));
399 continue;
400 } else if (u_strcmp(string, rootString) == 0) {
401 if (strcmp(locale, "de_CH") != 0 && strcmp(subBundleKey, "Countries") != 0 &&
402 strcmp(subBundleKey, "Version") != 0) {
403 log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n",
404 ures_getKey(subRootBundle),
405 ures_getKey(currentBundle),
406 locale);
407 }
408 else {
409 /* Ignore for now. */
410 /* Can be fixed if fallback through de locale was done. */
411 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
412 }
413 }
414 }
415 #endif
416 }
417 else if (ures_getType(subBundle) == URES_TABLE) {
418 if (strcmp(subBundleKey, "availableFormats")!=0) {
419 /* Here is one of the recursive parts */
420 TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale);
421 }
422 else {
423 log_verbose("Skipping key %s in %s\n", subBundleKey, locale);
424 }
425 }
426 else if (ures_getType(subBundle) == URES_BINARY || ures_getType(subBundle) == URES_INT) {
427 /* Can't do anything to check it */
428 /* We'll assume it's all correct */
429 if (strcmp(subBundleKey, "MeasurementSystem") != 0) {
430 log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n",
431 subBundleKey,
432 ures_getKey(currentBundle),
433 locale);
434 }
435 /* Testing for MeasurementSystem is done in VerifyTranslation */
436 }
437 else {
438 log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n",
439 ures_getType(subBundle),
440 subBundleKey,
441 ures_getKey(currentBundle),
442 locale);
443 }
444 ures_close(subRootBundle);
445 ures_close(subBundle);
446 }
447 }
448 #endif
449
450 static void
451 testLCID(UResourceBundle *currentBundle,
452 const char *localeName)
453 {
454 UErrorCode status = U_ZERO_ERROR;
455 uint32_t expectedLCID;
456 char lcidStringC[64] = {0};
457 int32_t len;
458
459 expectedLCID = uloc_getLCID(localeName);
460 if (expectedLCID == 0) {
461 log_verbose("INFO: %-5s does not have any LCID mapping\n",
462 localeName);
463 return;
464 }
465
466 status = U_ZERO_ERROR;
467 len = uprv_convertToPosix(expectedLCID, lcidStringC, UPRV_LENGTHOF(lcidStringC) - 1, &status);
468 if (U_FAILURE(status)) {
469 log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n",
470 expectedLCID, u_errorName(status));
471 }
472 lcidStringC[len] = 0;
473
474 if(strcmp(localeName, lcidStringC) != 0) {
475 char langName[1024];
476 char langLCID[1024];
477 uloc_getLanguage(localeName, langName, sizeof(langName), &status);
478 uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status);
479
480 if (strcmp(langName, langLCID) == 0) {
481 log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
482 localeName, lcidStringC, expectedLCID);
483 }
484 else {
485 log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
486 localeName, expectedLCID, lcidStringC);
487 }
488 }
489 }
490
491 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
492 static void
493 TestLocaleStructure(void) {
494 // This test checks the locale structure against a key file located
495 // at source/test/testdata/structLocale.txt. When adding new data to
496 // a locale file such as en.txt, the structLocale.txt file must be changed
497 // too to include the the template of the new data. Otherwise this test
498 // will fail!
499
500 UResourceBundle *root, *currentLocale;
501 int32_t locCount = uloc_countAvailable();
502 int32_t locIndex;
503 UErrorCode errorCode = U_ZERO_ERROR;
504 const char *currLoc, *resolvedLoc;
505
506 /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */
507 /* char locName[ULOC_FULLNAME_CAPACITY];
508 char *locNamePtr;
509
510 for (locIndex = 0; locIndex < locCount; locIndex++) {
511 errorCode=U_ZERO_ERROR;
512 strcpy(locName, uloc_getAvailable(locIndex));
513 locNamePtr = strrchr(locName, '_');
514 if (locNamePtr) {
515 *locNamePtr = 0;
516 }
517 else {
518 strcpy(locName, "root");
519 }
520
521 root = ures_openDirect(NULL, locName, &errorCode);
522 if(U_FAILURE(errorCode)) {
523 log_err("Can't open %s\n", locName);
524 continue;
525 }
526 */
527 if (locCount <= 1) {
528 log_data_err("At least root needs to be installed\n");
529 }
530
531 root = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
532 if(U_FAILURE(errorCode)) {
533 log_data_err("Can't open structLocale\n");
534 return;
535 }
536 for (locIndex = 0; locIndex < locCount; locIndex++) {
537 errorCode=U_ZERO_ERROR;
538 currLoc = uloc_getAvailable(locIndex);
539 currentLocale = ures_open(NULL, currLoc, &errorCode);
540 if(errorCode != U_ZERO_ERROR) {
541 if(U_SUCCESS(errorCode)) {
542 /* It's installed, but there is no data.
543 It's installed for the g18n white paper [grhoten] */
544 log_err("ERROR: Locale %-5s not installed, and it should be, err %s\n",
545 uloc_getAvailable(locIndex), u_errorName(errorCode));
546 } else {
547 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
548 u_errorName(errorCode),
549 uloc_getAvailable(locIndex));
550 }
551 ures_close(currentLocale);
552 continue;
553 }
554 ures_getStringByKey(currentLocale, "Version", NULL, &errorCode);
555 if(errorCode != U_ZERO_ERROR) {
556 log_err("No version information is available for locale %s, and it should be!\n",
557 currLoc);
558 }
559 else if (ures_getStringByKey(currentLocale, "Version", NULL, &errorCode)[0] == (UChar)(0x78)) {
560 log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n",
561 currLoc);
562 }
563 resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode);
564 if (strcmp(resolvedLoc, currLoc) != 0 && strcmp(currLoc, "ars") != 0) { /* ars IS an aliased locale */
565 /* All locales have at least a Version resource.
566 If it's absolutely empty, then the previous test will fail too.*/
567 log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
568 currLoc, resolvedLoc);
569 }
570 TestKeyInRootRecursive(root, "root", currentLocale, currLoc);
571
572 testLCID(currentLocale, currLoc);
573
574 ures_close(currentLocale);
575 }
576
577 ures_close(root);
578 }
579 #endif
580
581 static void
582 compareArrays(const char *keyName,
583 UResourceBundle *fromArray, const char *fromLocale,
584 UResourceBundle *toArray, const char *toLocale,
585 int32_t start, int32_t end)
586 {
587 int32_t fromSize = ures_getSize(fromArray);
588 int32_t toSize = ures_getSize(fromArray);
589 int32_t idx;
590 UErrorCode errorCode = U_ZERO_ERROR;
591
592 if (fromSize > toSize) {
593 fromSize = toSize;
594 log_err("Arrays are different size from \"%s\" to \"%s\"\n",
595 fromLocale,
596 toLocale);
597 }
598
599 for (idx = start; idx <= end; idx++) {
600 const UChar *fromBundleStr = ures_getStringByIndex(fromArray, idx, NULL, &errorCode);
601 const UChar *toBundleStr = ures_getStringByIndex(toArray, idx, NULL, &errorCode);
602 if (fromBundleStr && toBundleStr && u_strcmp(fromBundleStr, toBundleStr) != 0)
603 {
604 log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n",
605 keyName,
606 idx,
607 fromLocale,
608 austrdup(fromBundleStr),
609 toLocale,
610 austrdup(toBundleStr));
611 }
612 }
613 }
614
615 static void
616 compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) {
617 UErrorCode errorCode = U_ZERO_ERROR;
618 UResourceBundle *fromArray, *toArray;
619 UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode);
620 UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode);
621 UResourceBundle *toCalendar, *fromCalendar, *toGregorian, *fromGregorian;
622
623 if(U_FAILURE(errorCode)) {
624 log_err("Can't open resource bundle %s or %s - %s\n", fromLocale, toLocale, u_errorName(errorCode));
625 return;
626 }
627 fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode);
628 fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode);
629
630 toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode);
631 toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode);
632
633 fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode);
634 toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode);
635 if (strcmp(fromLocale, "en_CA") != 0)
636 {
637 /* The first one is probably localized. */
638 compareArrays("CurrencyElements", fromArray, fromLocale, toArray, toLocale, 1, 2);
639 }
640 ures_close(fromArray);
641 ures_close(toArray);
642
643 fromArray = ures_getByKey(fromLocaleBund, "NumberPatterns", NULL, &errorCode);
644 toArray = ures_getByKey(toLocaleBund, "NumberPatterns", NULL, &errorCode);
645 if (strcmp(fromLocale, "en_CA") != 0)
646 {
647 compareArrays("NumberPatterns", fromArray, fromLocale, toArray, toLocale, 0, 3);
648 }
649 ures_close(fromArray);
650 ures_close(toArray);
651
652 /* Difficult to test properly */
653 /*
654 fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode);
655 toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode);
656 {
657 compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale);
658 }
659 ures_close(fromArray);
660 ures_close(toArray);*/
661
662 fromArray = ures_getByKey(fromLocaleBund, "NumberElements", NULL, &errorCode);
663 toArray = ures_getByKey(toLocaleBund, "NumberElements", NULL, &errorCode);
664 if (strcmp(fromLocale, "en_CA") != 0)
665 {
666 compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 0, 3);
667 /* Index 4 is a script based 0 */
668 compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 5, 10);
669 }
670 ures_close(fromArray);
671 ures_close(toArray);
672 ures_close(fromCalendar);
673 ures_close(toCalendar);
674 ures_close(fromGregorian);
675 ures_close(toGregorian);
676
677 ures_close(fromLocaleBund);
678 ures_close(toLocaleBund);
679 }
680
681 static void
682 TestConsistentCountryInfo(void) {
683 /* UResourceBundle *fromLocale, *toLocale;*/
684 int32_t locCount = uloc_countAvailable();
685 int32_t fromLocIndex, toLocIndex;
686
687 int32_t fromCountryLen, toCountryLen;
688 char fromCountry[ULOC_FULLNAME_CAPACITY], toCountry[ULOC_FULLNAME_CAPACITY];
689
690 int32_t fromVariantLen, toVariantLen;
691 char fromVariant[ULOC_FULLNAME_CAPACITY], toVariant[ULOC_FULLNAME_CAPACITY];
692
693 UErrorCode errorCode = U_ZERO_ERROR;
694
695 for (fromLocIndex = 0; fromLocIndex < locCount; fromLocIndex++) {
696 const char *fromLocale = uloc_getAvailable(fromLocIndex);
697
698 errorCode=U_ZERO_ERROR;
699 fromCountryLen = uloc_getCountry(fromLocale, fromCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
700 if (fromCountryLen <= 0) {
701 /* Ignore countryless locales */
702 continue;
703 }
704 fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
705 if (fromVariantLen > 0) {
706 /* Most variants are ignorable like PREEURO, or collation variants. */
707 continue;
708 }
709 /* Start comparing only after the current index.
710 Previous loop should have already compared fromLocIndex.
711 */
712 for (toLocIndex = fromLocIndex + 1; toLocIndex < locCount; toLocIndex++) {
713 const char *toLocale = uloc_getAvailable(toLocIndex);
714
715 toCountryLen = uloc_getCountry(toLocale, toCountry, ULOC_FULLNAME_CAPACITY, &errorCode);
716 if(U_FAILURE(errorCode)) {
717 log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n",
718 fromLocale, toLocale, u_errorName(errorCode));
719 continue;
720 }
721
722 if (toCountryLen <= 0) {
723 /* Ignore countryless locales */
724 continue;
725 }
726 toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
727 if (toVariantLen > 0) {
728 /* Most variants are ignorable like PREEURO, or collation variants. */
729 /* They're a variant for a reason. */
730 continue;
731 }
732 if (strcmp(fromCountry, toCountry) == 0) {
733 log_verbose("comparing fromLocale=%s toLocale=%s\n",
734 fromLocale, toLocale);
735 compareConsistentCountryInfo(fromLocale, toLocale);
736 }
737 }
738 }
739 }
740
741 static int32_t
742 findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize,
743 USet * mergedExemplarSet,
744 UBool ignoreNumbers, UChar* badCharPtr) {
745 UErrorCode errorCode = U_ZERO_ERROR;
746 USet *exemplarSet;
747 int32_t strIdx;
748 if (mergedExemplarSet == NULL) {
749 return -1;
750 }
751 exemplarSet = createFlattenSet(mergedExemplarSet, &errorCode);
752 if (U_FAILURE(errorCode)) {
753 log_err("%s: error createFlattenSet returned %s\n", currLoc, u_errorName(errorCode));
754 return -1;
755 }
756
757 for (strIdx = 0; strIdx < langSize; strIdx++) {
758 if (!uset_contains(exemplarSet, string[strIdx])
759 && 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
760 && string[strIdx] != 0x200C && string[strIdx] != 0x200D) {
761 if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) {
762 uset_close(exemplarSet);
763 if (badCharPtr) {
764 *badCharPtr = string[strIdx];
765 }
766 return strIdx;
767 }
768 }
769 }
770 uset_close(exemplarSet);
771 if (badCharPtr) {
772 *badCharPtr = 0;
773 }
774 return -1;
775 }
776 /* include non-invariant chars */
777 static int32_t
778 myUCharsToChars(const UChar* us, char* cs, int32_t len){
779 int32_t i=0;
780 for(; i< len; i++){
781 if(us[i] < 0x7f){
782 cs[i] = (char)us[i];
783 }else{
784 return -1;
785 }
786 }
787 return i;
788 }
789 static void
790 findSetMatch( UScriptCode *scriptCodes, int32_t scriptsLen,
791 USet *exemplarSet,
792 const char *locale){
793 USet *scripts[10]= {0};
794 char pattern[256] = { '[', ':', 0x000 };
795 int32_t patternLen;
796 UChar uPattern[256] = {0};
797 UErrorCode status = U_ZERO_ERROR;
798 int32_t i;
799
800 /* create the sets with script codes */
801 for(i = 0; i<scriptsLen; i++){
802 strcat(pattern, uscript_getShortName(scriptCodes[i]));
803 strcat(pattern, ":]");
804 patternLen = (int32_t)strlen(pattern);
805 u_charsToUChars(pattern, uPattern, patternLen);
806 scripts[i] = uset_openPattern(uPattern, patternLen, &status);
807 if(U_FAILURE(status)){
808 log_err("Could not create set for pattern %s. Error: %s\n", pattern, u_errorName(status));
809 return;
810 }
811 pattern[2] = 0;
812 }
813 if (strcmp(locale, "uk") == 0 || strcmp(locale, "uk_UA") == 0) {
814 /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */
815 uset_add(scripts[0], 0x2bc);
816 }
817 if(U_SUCCESS(status)){
818 UBool existsInScript = FALSE;
819 /* iterate over the exemplarSet and ascertain if all
820 * UChars in exemplarSet belong to the scripts returned
821 * by getScript
822 */
823 int32_t count = uset_getItemCount(exemplarSet);
824
825 for( i=0; i < count; i++){
826 UChar32 start = 0;
827 UChar32 end = 0;
828 UChar *str = NULL;
829 int32_t strCapacity = 0;
830
831 strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
832 if(U_SUCCESS(status)){
833 int32_t j;
834 if(strCapacity == 0){
835 /* ok the item is a range */
836 for( j = 0; j < scriptsLen; j++){
837 if(uset_containsRange(scripts[j], start, end) == TRUE){
838 existsInScript = TRUE;
839 }
840 }
841 if(existsInScript == FALSE){
842 for( j = 0; j < scriptsLen; j++){
843 UChar toPattern[500]={'\0'};
844 char pat[500]={'\0'};
845 int32_t len = uset_toPattern(scripts[j], toPattern, 500, TRUE, &status);
846 len = myUCharsToChars(toPattern, pat, len);
847 log_err("uset_indexOf(\\u%04X)=%i uset_indexOf(\\u%04X)=%i\n", start, uset_indexOf(scripts[0], start), end, uset_indexOf(scripts[0], end));
848 if(len!=-1){
849 log_err("Pattern: %s\n",pat);
850 }
851 }
852 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
853 }
854 }else{
855 strCapacity++; /* increment for NUL termination */
856 /* allocate the str and call the api again */
857 str = (UChar*) malloc(U_SIZEOF_UCHAR * strCapacity);
858 strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status);
859 /* iterate over the scripts and figure out if the string contained is actually
860 * in the script set
861 */
862 for( j = 0; j < scriptsLen; j++){
863 if(uset_containsString(scripts[j],str, strCapacity) == TRUE){
864 existsInScript = TRUE;
865 }
866 }
867 if(existsInScript == FALSE){
868 log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale);
869 }
870 }
871 }
872 }
873
874 }
875
876 /* close the sets */
877 for(i = 0; i<scriptsLen; i++){
878 uset_close(scripts[i]);
879 }
880 }
881
882 static void VerifyTranslation(void) {
883 UResourceBundle *root, *currentLocale;
884 int32_t locCount = uloc_countAvailable();
885 int32_t locIndex;
886 UErrorCode errorCode = U_ZERO_ERROR;
887 const char *currLoc;
888 UScriptCode scripts[USCRIPT_CODE_LIMIT];
889 int32_t numScripts;
890 int32_t idx;
891 int32_t end;
892 UResourceBundle *resArray;
893
894 if (locCount <= 1) {
895 log_data_err("At least root needs to be installed\n");
896 }
897
898 root = ures_openDirect(NULL, "root", &errorCode);
899 if(U_FAILURE(errorCode)) {
900 log_data_err("Can't open root\n");
901 return;
902 }
903 for (locIndex = 0; locIndex < locCount; locIndex++) {
904 USet * mergedExemplarSet = NULL;
905 errorCode=U_ZERO_ERROR;
906 currLoc = uloc_getAvailable(locIndex);
907 currentLocale = ures_open(NULL, currLoc, &errorCode);
908 if(errorCode != U_ZERO_ERROR) {
909 if(U_SUCCESS(errorCode)) {
910 /* It's installed, but there is no data.
911 It's installed for the g18n white paper [grhoten] */
912 log_err("ERROR: Locale %-5s not installed, and it should be!\n",
913 uloc_getAvailable(locIndex));
914 } else {
915 log_err("%%%%%%% Unexpected error %d in %s %%%%%%%",
916 u_errorName(errorCode),
917 uloc_getAvailable(locIndex));
918 }
919 ures_close(currentLocale);
920 continue;
921 }
922 {
923 UErrorCode exemplarStatus = U_ZERO_ERROR;
924 ULocaleData * uld = ulocdata_open(currLoc, &exemplarStatus);
925 if (U_SUCCESS(exemplarStatus)) {
926 USet * exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_STANDARD, &exemplarStatus);
927 if (U_SUCCESS(exemplarStatus)) {
928 mergedExemplarSet = uset_cloneAsThawed(exemplarSet);
929 uset_close(exemplarSet);
930 exemplarSet = ulocdata_getExemplarSet(uld, NULL, USET_ADD_CASE_MAPPINGS, ULOCDATA_ES_AUXILIARY, &exemplarStatus);
931 if (U_SUCCESS(exemplarStatus)) {
932 uset_addAll(mergedExemplarSet, exemplarSet);
933 uset_close(exemplarSet);
934 }
935 exemplarStatus = U_ZERO_ERROR;
936 exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_PUNCTUATION, &exemplarStatus);
937 if (U_SUCCESS(exemplarStatus)) {
938 uset_addAll(mergedExemplarSet, exemplarSet);
939 uset_close(exemplarSet);
940 }
941 } else {
942 log_err("error ulocdata_getExemplarSet (main) for locale %s returned %s\n", currLoc, u_errorName(errorCode));
943 }
944 ulocdata_close(uld);
945 } else {
946 log_err("error ulocdata_open for locale %s returned %s\n", currLoc, u_errorName(errorCode));
947 }
948 }
949 if (mergedExemplarSet == NULL /*|| (getTestOption(QUICK_OPTION) && uset_size() > 2048)*/) {
950 log_verbose("skipping test for %s\n", currLoc);
951 }
952 //else if (uprv_strncmp(currLoc,"bem",3) == 0 || uprv_strncmp(currLoc,"mgo",3) == 0 || uprv_strncmp(currLoc,"nl",2) == 0) {
953 // log_verbose("skipping test for %s, some month and country names known to use aux exemplars\n", currLoc);
954 //}
955 else {
956 UChar langBuffer[128];
957 int32_t langSize;
958 int32_t strIdx;
959 UChar badChar;
960 langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
961 if (U_FAILURE(errorCode)) {
962 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
963 }
964 else {
965 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, mergedExemplarSet, FALSE, &badChar);
966 if (strIdx >= 0) {
967 char bbuf[256];
968 log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters: %04X in \"%s\"\n",
969 currLoc, strIdx, badChar, u_austrncpy(bbuf,langBuffer,langSize));
970 }
971 }
972 langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
973 if (U_FAILURE(errorCode)) {
974 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
975 }
976 {
977 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
978 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
979 UResourceBundle* names = ures_getByKeyWithFallback(greg, "dayNames", NULL, &errorCode);
980 UResourceBundle* format = ures_getByKeyWithFallback(names, "format", NULL, &errorCode);
981 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
982
983 if (U_FAILURE(errorCode)) {
984 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
985 }
986 if (getTestOption(QUICK_OPTION)) {
987 end = 1;
988 }
989 else {
990 end = ures_getSize(resArray);
991 }
992
993 if ((uprv_strncmp(currLoc,"lrc",3) == 0 || uprv_strncmp(currLoc,"mzn",3) == 0) &&
994 log_knownIssue("cldrbug:8899", "lrc and mzn locales don't have translated day names")) {
995 end = 0;
996 }
997
998 for (idx = 0; idx < end; idx++) {
999 const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1000 if (U_FAILURE(errorCode)) {
1001 log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1002 continue;
1003 }
1004 strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, TRUE, &badChar);
1005 if ( strIdx >= 0 ) {
1006 log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1007 currLoc, idx, strIdx, badChar);
1008 }
1009 }
1010 ures_close(resArray);
1011 ures_close(format);
1012 ures_close(names);
1013
1014 names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode);
1015 format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode);
1016 resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode);
1017 if (U_FAILURE(errorCode)) {
1018 log_err("error ures_getByKey returned %s\n", u_errorName(errorCode));
1019 }
1020 if (getTestOption(QUICK_OPTION)) {
1021 end = 1;
1022 }
1023 else {
1024 end = ures_getSize(resArray);
1025 }
1026
1027 for (idx = 0; idx < end; idx++) {
1028 const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode);
1029 if (U_FAILURE(errorCode)) {
1030 log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode));
1031 continue;
1032 }
1033 strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, mergedExemplarSet, TRUE, &badChar);
1034 if (strIdx >= 0) {
1035 log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters: %04X.\n",
1036 currLoc, idx, strIdx, badChar);
1037 }
1038 }
1039 ures_close(resArray);
1040 ures_close(format);
1041 ures_close(names);
1042 ures_close(greg);
1043 ures_close(cal);
1044 }
1045 errorCode = U_ZERO_ERROR;
1046 numScripts = uscript_getCode(currLoc, scripts, UPRV_LENGTHOF(scripts), &errorCode);
1047 if (strcmp(currLoc, "yi") == 0 && numScripts > 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1048 scripts[0] = USCRIPT_HEBREW;
1049 }
1050 if (numScripts == 0) {
1051 log_err("uscript_getCode(%s) doesn't work.\n", currLoc);
1052 }else if(scripts[0] == USCRIPT_COMMON){
1053 log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc);
1054 }
1055
1056 /* test that the scripts are a superset of exemplar characters. */
1057 {
1058 ULocaleData *uld = ulocdata_open(currLoc,&errorCode);
1059 USet *exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode);
1060 /* test if exemplar characters are part of script code */
1061 findSetMatch(scripts, numScripts, exemplarSet, currLoc);
1062 uset_close(exemplarSet);
1063 ulocdata_close(uld);
1064 }
1065
1066 /* test that the paperSize API works */
1067 {
1068 int32_t height=0, width=0;
1069 ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1070 if(U_FAILURE(errorCode)){
1071 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1072 }
1073 if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){
1074 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1075 }
1076 }
1077 /* test that the MeasurementSystem API works */
1078 {
1079 char fullLoc[ULOC_FULLNAME_CAPACITY];
1080 UMeasurementSystem measurementSystem;
1081 int32_t height = 0, width = 0;
1082
1083 uloc_addLikelySubtags(currLoc, fullLoc, ULOC_FULLNAME_CAPACITY, &errorCode);
1084
1085 errorCode = U_ZERO_ERROR;
1086 measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode);
1087 if (U_FAILURE(errorCode)) {
1088 log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1089 } else {
1090 if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_MM")!=NULL || strstr(fullLoc, "_LR")!=NULL ) {
1091 if(measurementSystem != UMS_US){
1092 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1093 }
1094 } else if ( strstr(fullLoc, "_GB")!=NULL ) {
1095 if(measurementSystem != UMS_UK){
1096 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1097 }
1098 } else if (measurementSystem != UMS_SI) {
1099 log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc);
1100 }
1101 }
1102
1103 errorCode = U_ZERO_ERROR;
1104 ulocdata_getPaperSize(currLoc, &height, &width, &errorCode);
1105 if (U_FAILURE(errorCode)) {
1106 log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode));
1107 } else {
1108 if ( strstr(fullLoc, "_US")!=NULL || strstr(fullLoc, "_BZ")!=NULL || strstr(fullLoc, "_CA")!=NULL || strstr(fullLoc, "_CL")!=NULL ||
1109 strstr(fullLoc, "_CO")!=NULL || strstr(fullLoc, "_CR")!=NULL || strstr(fullLoc, "_GT")!=NULL || strstr(fullLoc, "_MX")!=NULL ||
1110 strstr(fullLoc, "_NI")!=NULL || strstr(fullLoc, "_PA")!=NULL || strstr(fullLoc, "_PH")!=NULL || strstr(fullLoc, "_PR")!=NULL ||
1111 strstr(fullLoc, "_SV")!=NULL || strstr(fullLoc, "_VE")!=NULL ) {
1112 if (height != 279 || width != 216) {
1113 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1114 }
1115 } else if (height != 297 || width != 210) {
1116 log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc);
1117 }
1118 }
1119 }
1120 }
1121 if (mergedExemplarSet != NULL) {
1122 uset_close(mergedExemplarSet);
1123 }
1124 ures_close(currentLocale);
1125 }
1126
1127 ures_close(root);
1128 }
1129
1130 /* adjust this limit as appropriate */
1131 #define MAX_SCRIPTS_PER_LOCALE 8
1132
1133 static void TestExemplarSet(void){
1134 int32_t i, j, k, m, n;
1135 int32_t equalCount = 0;
1136 UErrorCode ec = U_ZERO_ERROR;
1137 UEnumeration* avail;
1138 USet* exemplarSets[2];
1139 USet* unassignedSet;
1140 UScriptCode code[MAX_SCRIPTS_PER_LOCALE];
1141 USet* codeSets[MAX_SCRIPTS_PER_LOCALE];
1142 int32_t codeLen;
1143 char cbuf[32]; /* 9 should be enough */
1144 UChar ubuf[64]; /* adjust as needed */
1145 UBool existsInScript;
1146 int32_t itemCount;
1147 int32_t strLen;
1148 UChar32 start, end;
1149
1150 unassignedSet = NULL;
1151 exemplarSets[0] = NULL;
1152 exemplarSets[1] = NULL;
1153 for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1154 codeSets[i] = NULL;
1155 }
1156
1157 avail = ures_openAvailableLocales(NULL, &ec);
1158 if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END;
1159 n = uenum_count(avail, &ec);
1160 if (!assertSuccess("uenum_count", &ec)) goto END;
1161
1162 u_uastrcpy(ubuf, "[:unassigned:]");
1163 unassignedSet = uset_openPattern(ubuf, -1, &ec);
1164 if (!assertSuccess("uset_openPattern", &ec)) goto END;
1165
1166 for(i=0; i<n; i++){
1167 const char* locale = uenum_next(avail, NULL, &ec);
1168 if (!assertSuccess("uenum_next", &ec)) goto END;
1169 log_verbose("%s\n", locale);
1170 for (k=0; k<2; ++k) {
1171 uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE;
1172 ULocaleData *uld = ulocdata_open(locale,&ec);
1173 USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec);
1174 uset_close(exemplarSets[k]);
1175 ulocdata_close(uld);
1176 exemplarSets[k] = exemplarSet;
1177 if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END;
1178
1179 if (uset_containsSome(exemplarSet, unassignedSet)) {
1180 log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale);
1181 }
1182 codeLen = uscript_getCode(locale, code, 8, &ec);
1183 if (strcmp(locale, "yi") == 0 && codeLen > 0 && log_knownIssue("11217", "Fix result of uscript_getCode for yi: USCRIPT_YI -> USCRIPT_HEBREW")) {
1184 code[0] = USCRIPT_HEBREW;
1185 }
1186 if (!assertSuccess("uscript_getCode", &ec)) goto END;
1187
1188 for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) {
1189 uset_close(codeSets[j]);
1190 codeSets[j] = NULL;
1191 }
1192 for (j=0; j<codeLen; ++j) {
1193 uprv_strcpy(cbuf, "[:");
1194 if(code[j]==-1){
1195 log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale);
1196 continue;
1197 }
1198 uprv_strcat(cbuf, uscript_getShortName(code[j]));
1199 uprv_strcat(cbuf, ":]");
1200 u_uastrcpy(ubuf, cbuf);
1201 codeSets[j] = uset_openPattern(ubuf, -1, &ec);
1202 }
1203 if (!assertSuccess("uset_openPattern", &ec)) goto END;
1204
1205 existsInScript = FALSE;
1206 itemCount = uset_getItemCount(exemplarSet);
1207 for (m=0; m<itemCount && !existsInScript; ++m) {
1208 strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf,
1209 UPRV_LENGTHOF(ubuf), &ec);
1210 /* failure here might mean str[] needs to be larger */
1211 if (!assertSuccess("uset_getItem", &ec)) goto END;
1212 if (strLen == 0) {
1213 for (j=0; j<codeLen; ++j) {
1214 if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) {
1215 existsInScript = TRUE;
1216 break;
1217 }
1218 }
1219 } else {
1220 for (j=0; j<codeLen; ++j) {
1221 if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) {
1222 existsInScript = TRUE;
1223 break;
1224 }
1225 }
1226 }
1227 }
1228
1229 if (existsInScript == FALSE){
1230 log_err("ExemplarSet containment failed for locale : %s\n", locale);
1231 }
1232 }
1233 assertTrue("case-folded is a superset",
1234 uset_containsAll(exemplarSets[1], exemplarSets[0]));
1235 if (uset_equals(exemplarSets[1], exemplarSets[0])) {
1236 ++equalCount;
1237 }
1238 }
1239 /* Note: The case-folded set should sometimes be a strict superset
1240 and sometimes be equal. */
1241 assertTrue("case-folded is sometimes a strict superset, and sometimes equal",
1242 equalCount > 0 && equalCount < n);
1243
1244 END:
1245 uenum_close(avail);
1246 uset_close(exemplarSets[0]);
1247 uset_close(exemplarSets[1]);
1248 uset_close(unassignedSet);
1249 for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) {
1250 uset_close(codeSets[i]);
1251 }
1252 }
1253
1254 enum { kUBufMax = 32 };
1255 static void TestLocaleDisplayPattern(void){
1256 UErrorCode status;
1257 UChar pattern[kUBufMax] = {0,};
1258 UChar separator[kUBufMax] = {0,};
1259 ULocaleData *uld;
1260 static const UChar enExpectPat[] = { 0x007B,0x0030,0x007D,0x0020,0x0028,0x007B,0x0031,0x007D,0x0029,0 }; /* "{0} ({1})" */
1261 static const UChar enExpectSep[] = { 0x002C,0x0020,0 }; /* ", " */
1262 static const UChar zhExpectPat[] = { 0x007B,0x0030,0x007D,0xFF08,0x007B,0x0031,0x007D,0xFF09,0 };
1263 static const UChar zhExpectSep[] = { 0x3001,0 };
1264
1265 status = U_ZERO_ERROR;
1266 uld = ulocdata_open("en", &status);
1267 if(U_FAILURE(status)){
1268 log_data_err("ulocdata_open en error %s", u_errorName(status));
1269 } else {
1270 ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1271 if (U_FAILURE(status)){
1272 log_err("ulocdata_getLocaleDisplayPattern en error %s", u_errorName(status));
1273 } else if (u_strcmp(pattern, enExpectPat) != 0) {
1274 log_err("ulocdata_getLocaleDisplayPattern en returns unexpected pattern");
1275 }
1276 status = U_ZERO_ERROR;
1277 ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1278 if (U_FAILURE(status)){
1279 log_err("ulocdata_getLocaleSeparator en error %s", u_errorName(status));
1280 } else if (u_strcmp(separator, enExpectSep) != 0) {
1281 log_err("ulocdata_getLocaleSeparator en returns unexpected string ");
1282 }
1283 ulocdata_close(uld);
1284 }
1285
1286 status = U_ZERO_ERROR;
1287 uld = ulocdata_open("zh", &status);
1288 if(U_FAILURE(status)){
1289 log_data_err("ulocdata_open zh error %s", u_errorName(status));
1290 } else {
1291 ulocdata_getLocaleDisplayPattern(uld, pattern, kUBufMax, &status);
1292 if (U_FAILURE(status)){
1293 log_err("ulocdata_getLocaleDisplayPattern zh error %s", u_errorName(status));
1294 } else if (u_strcmp(pattern, zhExpectPat) != 0) {
1295 log_err("ulocdata_getLocaleDisplayPattern zh returns unexpected pattern");
1296 }
1297 status = U_ZERO_ERROR;
1298 ulocdata_getLocaleSeparator(uld, separator, kUBufMax, &status);
1299 if (U_FAILURE(status)){
1300 log_err("ulocdata_getLocaleSeparator zh error %s", u_errorName(status));
1301 } else if (u_strcmp(separator, zhExpectSep) != 0) {
1302 log_err("ulocdata_getLocaleSeparator zh returns unexpected string ");
1303 }
1304 ulocdata_close(uld);
1305 }
1306 }
1307
1308 static void TestCoverage(void){
1309 ULocaleDataDelimiterType types[] = {
1310 ULOCDATA_QUOTATION_START, /* Quotation start */
1311 ULOCDATA_QUOTATION_END, /* Quotation end */
1312 ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */
1313 ULOCDATA_ALT_QUOTATION_END, /* Alternate quotation end */
1314 ULOCDATA_DELIMITER_COUNT
1315 };
1316 int i;
1317 UBool sub;
1318 UErrorCode status = U_ZERO_ERROR;
1319 ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status);
1320
1321 if(U_FAILURE(status)){
1322 log_data_err("ulocdata_open error");
1323 return;
1324 }
1325
1326
1327 for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){
1328 UChar result[32] = {0,};
1329 status = U_ZERO_ERROR;
1330 ulocdata_getDelimiter(uld, types[i], result, 32, &status);
1331 if (U_FAILURE(status)){
1332 log_err("ulocdata_getgetDelimiter error with type %d", types[i]);
1333 }
1334 }
1335
1336 sub = ulocdata_getNoSubstitute(uld);
1337 ulocdata_setNoSubstitute(uld,sub);
1338 ulocdata_close(uld);
1339 }
1340
1341 static void TestIndexChars(void) {
1342 /* Very basic test of ULOCDATA_ES_INDEX.
1343 * No comprehensive test of data, just basic check that the code path is alive.
1344 */
1345 UErrorCode status = U_ZERO_ERROR;
1346 ULocaleData *uld;
1347 USet *exemplarChars;
1348 USet *indexChars;
1349
1350 uld = ulocdata_open("en", &status);
1351 exemplarChars = uset_openEmpty();
1352 indexChars = uset_openEmpty();
1353 ulocdata_getExemplarSet(uld, exemplarChars, 0, ULOCDATA_ES_STANDARD, &status);
1354 ulocdata_getExemplarSet(uld, indexChars, 0, ULOCDATA_ES_INDEX, &status);
1355 if (U_FAILURE(status)) {
1356 log_data_err("File %s, line %d, Failure opening exemplar chars: %s", __FILE__, __LINE__, u_errorName(status));
1357 goto close_sets;
1358 }
1359 /* en data, standard exemplars are [a-z], lower case. */
1360 /* en data, index characters are [A-Z], upper case. */
1361 if ((uset_contains(exemplarChars, (UChar32)0x41) || uset_contains(indexChars, (UChar32)0x61))) {
1362 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1363 goto close_sets;
1364 }
1365 if (!(uset_contains(exemplarChars, (UChar32)0x61) && uset_contains(indexChars, (UChar32)0x41) )) {
1366 log_err("File %s, line %d, Exemplar characters incorrect.", __FILE__, __LINE__ );
1367 goto close_sets;
1368 }
1369
1370 close_sets:
1371 uset_close(exemplarChars);
1372 uset_close(indexChars);
1373 ulocdata_close(uld);
1374 }
1375
1376
1377
1378 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1379 static void TestCurrencyList(void){
1380 #if !UCONFIG_NO_FORMATTING
1381 UErrorCode errorCode = U_ZERO_ERROR;
1382 int32_t structLocaleCount, currencyCount;
1383 UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &errorCode);
1384 const char *isoCode, *structISOCode;
1385 UResourceBundle *subBundle;
1386 UResourceBundle *currencies = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode);
1387 if(U_FAILURE(errorCode)) {
1388 log_data_err("Can't open structLocale\n");
1389 return;
1390 }
1391 currencies = ures_getByKey(currencies, "Currencies", currencies, &errorCode);
1392 currencyCount = uenum_count(en, &errorCode);
1393 structLocaleCount = ures_getSize(currencies);
1394 if (currencyCount != structLocaleCount) {
1395 log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount, currencyCount);
1396 #if U_CHARSET_FAMILY == U_ASCII_FAMILY
1397 ures_resetIterator(currencies);
1398 while ((isoCode = uenum_next(en, NULL, &errorCode)) != NULL && ures_hasNext(currencies)) {
1399 subBundle = ures_getNextResource(currencies, NULL, &errorCode);
1400 structISOCode = ures_getKey(subBundle);
1401 ures_close(subBundle);
1402 if (strcmp(structISOCode, isoCode) != 0) {
1403 log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode, isoCode);
1404 break;
1405 }
1406 }
1407 #endif
1408 }
1409 ures_close(currencies);
1410 uenum_close(en);
1411 #endif
1412 }
1413 #endif
1414
1415 static void TestAvailableIsoCodes(void){
1416 #if !UCONFIG_NO_FORMATTING
1417 UErrorCode errorCode = U_ZERO_ERROR;
1418 const char* eurCode = "EUR";
1419 const char* usdCode = "USD";
1420 const char* lastCode = "RHD";
1421 const char* zzzCode = "ZZZ";
1422 UDate date1950 = (UDate)-630720000000.0;/* year 1950 */
1423 UDate date1970 = (UDate)0.0; /* year 1970 */
1424 UDate date1975 = (UDate)173448000000.0; /* year 1975 */
1425 UDate date1978 = (UDate)260172000000.0; /* year 1978 */
1426 UDate date1981 = (UDate)346896000000.0; /* year 1981 */
1427 UDate date1992 = (UDate)693792000000.0; /* year 1992 */
1428 UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
1429
1430 /* testing available codes with no time ranges */
1431 u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
1432 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1433 log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
1434 }
1435
1436 u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
1437 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1438 log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
1439 }
1440
1441 u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
1442 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
1443 log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
1444 }
1445
1446 u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
1447 if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
1448 log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
1449 }
1450
1451 /* RHD was used from 1970-02-17 to 1980-04-18*/
1452
1453 /* to = null */
1454 if (ucurr_isAvailable(isoCode, date1970, U_DATE_MAX, &errorCode) == FALSE) {
1455 log_data_err("FAIL: ISO code (%s) was available in time range >1970-01-01.\n", lastCode);
1456 }
1457
1458 if (ucurr_isAvailable(isoCode, date1975, U_DATE_MAX, &errorCode) == FALSE) {
1459 log_data_err("FAIL: ISO code (%s) was available in time range >1975.\n", lastCode);
1460 }
1461
1462 if (ucurr_isAvailable(isoCode, date1981, U_DATE_MAX, &errorCode) == TRUE) {
1463 log_err("FAIL: ISO code (%s) was not available in time range >1981.\n", lastCode);
1464 }
1465
1466 /* from = null */
1467 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1970, &errorCode) == TRUE) {
1468 log_err("FAIL: ISO code (%s) was not available in time range <1970.\n", lastCode);
1469 }
1470
1471 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1975, &errorCode) == FALSE) {
1472 log_data_err("FAIL: ISO code (%s) was available in time range <1975.\n", lastCode);
1473 }
1474
1475 if (ucurr_isAvailable(isoCode, U_DATE_MIN, date1981, &errorCode) == FALSE) {
1476 log_data_err("FAIL: ISO code (%s) was available in time range <1981.\n", lastCode);
1477 }
1478
1479 /* full ranges */
1480 if (ucurr_isAvailable(isoCode, date1975, date1978, &errorCode) == FALSE) {
1481 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1978.\n", lastCode);
1482 }
1483
1484 if (ucurr_isAvailable(isoCode, date1970, date1975, &errorCode) == FALSE) {
1485 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1975.\n", lastCode);
1486 }
1487
1488 if (ucurr_isAvailable(isoCode, date1975, date1981, &errorCode) == FALSE) {
1489 log_data_err("FAIL: ISO code (%s) was available in time range 1975-1981.\n", lastCode);
1490 }
1491
1492 if (ucurr_isAvailable(isoCode, date1970, date1981, &errorCode) == FALSE) {
1493 log_data_err("FAIL: ISO code (%s) was available in time range 1970-1981.\n", lastCode);
1494 }
1495
1496 if (ucurr_isAvailable(isoCode, date1981, date1992, &errorCode) == TRUE) {
1497 log_err("FAIL: ISO code (%s) was not available in time range 1981-1992.\n", lastCode);
1498 }
1499
1500 if (ucurr_isAvailable(isoCode, date1950, date1970, &errorCode) == TRUE) {
1501 log_err("FAIL: ISO code (%s) was not available in time range 1950-1970.\n", lastCode);
1502 }
1503
1504 /* wrong range - from > to*/
1505 if (ucurr_isAvailable(isoCode, date1975, date1970, &errorCode) == TRUE) {
1506 log_err("FAIL: Wrong range 1975-1970 for ISO code (%s) was not reported.\n", lastCode);
1507 } else if (errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
1508 log_data_err("FAIL: Error code not reported for wrong range 1975-1970 for ISO code (%s).\n", lastCode);
1509 }
1510
1511 free(isoCode);
1512 #endif
1513 }
1514
1515 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
1516
1517 void addCLDRTest(TestNode** root);
1518
1519 void addCLDRTest(TestNode** root)
1520 {
1521 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1522 TESTCASE(TestLocaleStructure);
1523 TESTCASE(TestCurrencyList);
1524 #endif
1525 TESTCASE(TestConsistentCountryInfo);
1526 TESTCASE(VerifyTranslation);
1527 TESTCASE(TestExemplarSet);
1528 TESTCASE(TestLocaleDisplayPattern);
1529 TESTCASE(TestCoverage);
1530 TESTCASE(TestIndexChars);
1531 TESTCASE(TestAvailableIsoCodes);
1532 }
1533