]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
73c04bcf | 3 | * Copyright (c) 1997-2006, International Business Machines Corporation and |
374ca955 A |
4 | * others. All Rights Reserved. |
5 | ********************************************************************/ | |
6 | ||
7 | #include "cintltst.h" | |
8 | #include "unicode/ures.h" | |
73c04bcf | 9 | #include "unicode/ucurr.h" |
374ca955 A |
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 "cstring.h" | |
16 | #include "locmap.h" | |
17 | #include "uresimp.h" | |
18 | ||
73c04bcf A |
19 | /*-------------------------------------------------------------------- |
20 | Time bomb - allows temporary behavior that expires at a given | |
21 | release | |
22 | ---------------------------------------------------------------------*/ | |
23 | static const UVersionInfo ICU_37 = {3,7,0,0}; | |
24 | ||
25 | /* | |
26 | returns a new UnicodeSet that is a flattened form of the original | |
27 | UnicodeSet. | |
28 | */ | |
29 | static USet* | |
30 | createFlattenSet(USet *origSet, UErrorCode *status) { | |
31 | ||
32 | ||
33 | USet *newSet = NULL; | |
34 | int32_t origItemCount = 0; | |
35 | int32_t idx, graphmeSize; | |
36 | UChar32 start, end; | |
37 | UChar graphme[64]; | |
38 | if (U_FAILURE(*status)) { | |
39 | log_err("createFlattenSet called with %s\n", u_errorName(*status)); | |
40 | return NULL; | |
41 | } | |
42 | newSet = uset_open(1, 0); | |
43 | origItemCount = uset_getItemCount(origSet); | |
44 | for (idx = 0; idx < origItemCount; idx++) { | |
45 | graphmeSize = uset_getItem(origSet, idx, | |
46 | &start, &end, | |
47 | graphme, (int32_t)(sizeof(graphme)/sizeof(graphme[0])), | |
48 | status); | |
49 | if (U_FAILURE(*status)) { | |
50 | log_err("ERROR: uset_getItem returned %s\n", u_errorName(*status)); | |
51 | *status = U_ZERO_ERROR; | |
52 | } | |
53 | if (graphmeSize) { | |
54 | uset_addAllCodePoints(newSet, graphme, graphmeSize); | |
55 | } | |
56 | else { | |
57 | uset_addRange(newSet, start, end); | |
58 | } | |
59 | } | |
60 | return newSet; | |
61 | } | |
62 | static UBool | |
63 | isCurrencyPreEuro(const char* currencyKey){ | |
374ca955 A |
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 || | |
73c04bcf A |
69 | strcmp(currencyKey, "ITL") == 0 || |
70 | strcmp(currencyKey, "EEK") == 0){ | |
374ca955 A |
71 | return TRUE; |
72 | } | |
73 | return FALSE; | |
74 | } | |
75 | static void | |
76 | TestKeyInRootRecursive(UResourceBundle *root, const char *rootName, | |
77 | UResourceBundle *currentBundle, const char *locale) { | |
78 | UErrorCode errorCode = U_ZERO_ERROR; | |
79 | UResourceBundle *subRootBundle = NULL, *subBundle = NULL; | |
80 | ||
81 | ures_resetIterator(root); | |
82 | ures_resetIterator(currentBundle); | |
83 | while (ures_hasNext(currentBundle)) { | |
84 | const char *subBundleKey = NULL; | |
85 | const char *currentBundleKey = NULL; | |
86 | ||
87 | errorCode = U_ZERO_ERROR; | |
88 | currentBundleKey = ures_getKey(currentBundle); | |
89 | subBundle = ures_getNextResource(currentBundle, NULL, &errorCode); | |
90 | if (U_FAILURE(errorCode)) { | |
91 | log_err("Can't open a resource for locale %s. Error: %s\n", locale, u_errorName(errorCode)); | |
92 | continue; | |
93 | } | |
94 | subBundleKey = ures_getKey(subBundle); | |
95 | ||
96 | ||
97 | subRootBundle = ures_getByKey(root, subBundleKey, NULL, &errorCode); | |
98 | if (U_FAILURE(errorCode)) { | |
99 | log_err("Can't open a resource with key \"%s\" in \"%s\" from %s for locale \"%s\"\n", | |
100 | subBundleKey, | |
101 | ures_getKey(currentBundle), | |
102 | rootName, | |
103 | locale); | |
104 | ures_close(subBundle); | |
105 | continue; | |
106 | } | |
107 | if (ures_getType(subRootBundle) != ures_getType(subBundle)) { | |
108 | log_err("key \"%s\" in \"%s\" has a different type from root for locale \"%s\"\n" | |
109 | "\troot=%d, locale=%d\n", | |
110 | subBundleKey, | |
111 | ures_getKey(currentBundle), | |
112 | locale, | |
113 | ures_getType(subRootBundle), | |
114 | ures_getType(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 | { | |
73c04bcf A |
164 | /* Here is one of the recursive parts */ |
165 | TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale); | |
374ca955 A |
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 | log_err("Got a NULL string with key \"%s\" in \"%s\" at index %d for root or locale \"%s\"\n", | |
208 | subBundleKey, | |
209 | ures_getKey(currentBundle), | |
210 | idx, | |
211 | locale); | |
212 | continue; | |
213 | } | |
214 | if (localeStr[0] == (UChar)0x20) { | |
215 | log_err("key \"%s\" at index %d in \"%s\" starts with a space in locale \"%s\"\n", | |
216 | subBundleKey, | |
217 | idx, | |
218 | ures_getKey(currentBundle), | |
219 | locale); | |
220 | } | |
221 | else if (localeStr[localeStrLen - 1] == (UChar)0x20) { | |
222 | log_err("key \"%s\" at index %d in \"%s\" ends with a space in locale \"%s\"\n", | |
223 | subBundleKey, | |
224 | idx, | |
225 | ures_getKey(currentBundle), | |
226 | locale); | |
227 | } | |
228 | else if (subBundleKey != NULL | |
229 | && strcmp(subBundleKey, "DateTimePatterns") == 0) | |
230 | { | |
231 | int32_t quoted = 0; | |
232 | const UChar *localeStrItr = localeStr; | |
233 | while (*localeStrItr) { | |
234 | if (*localeStrItr == (UChar)0x27 /* ' */) { | |
235 | quoted++; | |
236 | } | |
237 | else if ((quoted % 2) == 0) { | |
238 | /* Search for unquoted characters */ | |
239 | if (4 <= idx && idx <= 7 | |
240 | && (*localeStrItr == (UChar)0x6B /* k */ | |
241 | || *localeStrItr == (UChar)0x48 /* H */ | |
242 | || *localeStrItr == (UChar)0x6D /* m */ | |
243 | || *localeStrItr == (UChar)0x73 /* s */ | |
244 | || *localeStrItr == (UChar)0x53 /* S */ | |
245 | || *localeStrItr == (UChar)0x61 /* a */ | |
246 | || *localeStrItr == (UChar)0x68 /* h */ | |
247 | || *localeStrItr == (UChar)0x7A /* z */)) | |
248 | { | |
249 | log_err("key \"%s\" at index %d has time pattern chars in date for locale \"%s\"\n", | |
250 | subBundleKey, | |
251 | idx, | |
252 | locale); | |
253 | } | |
254 | else if (0 <= idx && idx <= 3 | |
255 | && (*localeStrItr == (UChar)0x47 /* G */ | |
256 | || *localeStrItr == (UChar)0x79 /* y */ | |
257 | || *localeStrItr == (UChar)0x4D /* M */ | |
258 | || *localeStrItr == (UChar)0x64 /* d */ | |
259 | || *localeStrItr == (UChar)0x45 /* E */ | |
260 | || *localeStrItr == (UChar)0x44 /* D */ | |
261 | || *localeStrItr == (UChar)0x46 /* F */ | |
262 | || *localeStrItr == (UChar)0x77 /* w */ | |
263 | || *localeStrItr == (UChar)0x57 /* W */)) | |
264 | { | |
265 | log_err("key \"%s\" at index %d has date pattern chars in time for locale \"%s\"\n", | |
266 | subBundleKey, | |
267 | idx, | |
268 | locale); | |
269 | } | |
270 | } | |
271 | localeStrItr++; | |
272 | } | |
273 | } | |
274 | else if (idx == 4 && subBundleKey != NULL | |
275 | && strcmp(subBundleKey, "NumberElements") == 0 | |
276 | && u_charDigitValue(localeStr[0]) != 0) | |
277 | { | |
278 | log_err("key \"%s\" at index %d has a non-zero based number for locale \"%s\"\n", | |
279 | subBundleKey, | |
280 | idx, | |
281 | locale); | |
282 | } | |
283 | } | |
284 | /* if (sameArray && strcmp(rootName, "root") == 0) { | |
285 | log_err("Arrays are the same with key \"%s\" in \"%s\" from root for locale \"%s\"\n", | |
286 | subBundleKey, | |
287 | ures_getKey(currentBundle), | |
288 | locale); | |
289 | }*/ | |
290 | } | |
291 | ures_close(subSubBundle); | |
292 | ures_close(subSubRootBundle); | |
293 | } | |
294 | else if (ures_getType(subBundle) == URES_STRING) { | |
295 | int32_t len = 0; | |
296 | const UChar *string = ures_getString(subBundle, &len, &errorCode); | |
297 | if (U_FAILURE(errorCode) || string == NULL) { | |
298 | log_err("Can't open a string with key \"%s\" in \"%s\" for locale \"%s\"\n", | |
299 | subBundleKey, | |
300 | ures_getKey(currentBundle), | |
301 | locale); | |
302 | } else if (string[0] == (UChar)0x20) { | |
303 | log_err("key \"%s\" in \"%s\" starts with a space in locale \"%s\"\n", | |
304 | subBundleKey, | |
305 | ures_getKey(currentBundle), | |
306 | locale); | |
307 | } else if (string[len - 1] == (UChar)0x20) { | |
308 | log_err("key \"%s\" in \"%s\" ends with a space in locale \"%s\"\n", | |
309 | subBundleKey, | |
310 | ures_getKey(currentBundle), | |
311 | locale); | |
73c04bcf A |
312 | } else if (strcmp(subBundleKey, "localPatternChars") == 0 && |
313 | isICUVersionAtLeast(ICU_37)) { | |
374ca955 A |
314 | /* Check well-formedness of localPatternChars. First, the |
315 | * length must match the number of fields defined by | |
316 | * DateFormat. Second, each character in the string must | |
317 | * be in the set [A-Za-z]. Finally, each character must be | |
318 | * unique. | |
319 | */ | |
320 | int32_t i,j; | |
321 | #if !UCONFIG_NO_FORMATTING | |
322 | if (len != UDAT_FIELD_COUNT) { | |
323 | log_err("key \"%s\" has the wrong number of characters in locale \"%s\"\n", | |
324 | subBundleKey, | |
325 | locale); | |
326 | } | |
327 | #endif | |
328 | /* Check char validity. */ | |
329 | for (i=0; i<len; ++i) { | |
330 | if (!((string[i] >= 65/*'A'*/ && string[i] <= 90/*'Z'*/) || | |
331 | (string[i] >= 97/*'a'*/ && string[i] <= 122/*'z'*/))) { | |
332 | log_err("key \"%s\" has illegal character '%c' in locale \"%s\"\n", | |
333 | subBundleKey, | |
334 | (char) string[i], | |
335 | locale); | |
336 | } | |
337 | /* Do O(n^2) check for duplicate chars. */ | |
338 | for (j=0; j<i; ++j) { | |
339 | if (string[j] == string[i]) { | |
340 | log_err("key \"%s\" has duplicate character '%c' in locale \"%s\"\n", | |
341 | subBundleKey, | |
342 | (char) string[i], | |
343 | locale); | |
344 | } | |
345 | } | |
346 | } | |
347 | } | |
348 | /* No fallback was done. Check for duplicate data */ | |
349 | /* The ures_* API does not do fallback of sub-resource bundles, | |
350 | So we can't do this now. */ | |
351 | #if 0 | |
352 | else if (strcmp(locale, "root") != 0 && errorCode == U_ZERO_ERROR) { | |
353 | ||
354 | const UChar *rootString = ures_getString(subRootBundle, &len, &errorCode); | |
355 | if (U_FAILURE(errorCode) || rootString == NULL) { | |
356 | log_err("Can't open a string with key \"%s\" in \"%s\" in root\n", | |
357 | ures_getKey(subRootBundle), | |
358 | ures_getKey(currentBundle)); | |
359 | continue; | |
360 | } else if (u_strcmp(string, rootString) == 0) { | |
361 | if (strcmp(locale, "de_CH") != 0 && strcmp(subBundleKey, "Countries") != 0 && | |
362 | strcmp(subBundleKey, "Version") != 0) { | |
363 | log_err("Found duplicate data with key \"%s\" in \"%s\" in locale \"%s\"\n", | |
364 | ures_getKey(subRootBundle), | |
365 | ures_getKey(currentBundle), | |
366 | locale); | |
367 | } | |
368 | else { | |
369 | /* Ignore for now. */ | |
370 | /* Can be fixed if fallback through de locale was done. */ | |
371 | log_verbose("Skipping key %s in %s\n", subBundleKey, locale); | |
372 | } | |
373 | } | |
374 | } | |
375 | #endif | |
376 | } | |
377 | else if (ures_getType(subBundle) == URES_TABLE) { | |
73c04bcf A |
378 | if (strcmp(subBundleKey, "availableFormats")!=0) { |
379 | /* Here is one of the recursive parts */ | |
380 | TestKeyInRootRecursive(subRootBundle, rootName, subBundle, locale); | |
381 | } | |
382 | else { | |
383 | log_verbose("Skipping key %s in %s\n", subBundleKey, locale); | |
384 | } | |
374ca955 A |
385 | } |
386 | else if (ures_getType(subBundle) == URES_BINARY || ures_getType(subBundle) == URES_INT) { | |
387 | /* Can't do anything to check it */ | |
388 | /* We'll assume it's all correct */ | |
389 | if (strcmp(subBundleKey, "MeasurementSystem") != 0) { | |
390 | log_verbose("Skipping key \"%s\" in \"%s\" for locale \"%s\"\n", | |
391 | subBundleKey, | |
392 | ures_getKey(currentBundle), | |
393 | locale); | |
394 | } | |
395 | /* Testing for MeasurementSystem is done in VerifyTranslation */ | |
396 | } | |
397 | else { | |
398 | log_err("Type %d for key \"%s\" in \"%s\" is unknown for locale \"%s\"\n", | |
399 | ures_getType(subBundle), | |
400 | subBundleKey, | |
401 | ures_getKey(currentBundle), | |
402 | locale); | |
403 | } | |
404 | ures_close(subRootBundle); | |
405 | ures_close(subBundle); | |
406 | } | |
407 | } | |
408 | ||
409 | ||
410 | static void | |
411 | testLCID(UResourceBundle *currentBundle, | |
412 | const char *localeName) | |
413 | { | |
414 | UErrorCode status = U_ZERO_ERROR; | |
415 | uint32_t expectedLCID; | |
416 | char lcidStringC[64] = {0}; | |
417 | ||
418 | expectedLCID = uloc_getLCID(localeName); | |
419 | if (expectedLCID == 0) { | |
420 | log_verbose("INFO: %-5s does not have any LCID mapping\n", | |
421 | localeName); | |
422 | return; | |
423 | } | |
424 | ||
425 | status = U_ZERO_ERROR; | |
426 | uprv_strcpy(lcidStringC, uprv_convertToPosix(expectedLCID, &status)); | |
427 | if (U_FAILURE(status)) { | |
428 | log_err("ERROR: %.4x does not have a POSIX mapping due to %s\n", | |
429 | expectedLCID, u_errorName(status)); | |
430 | } | |
431 | ||
432 | if(strcmp(localeName, lcidStringC) != 0) { | |
433 | char langName[1024]; | |
434 | char langLCID[1024]; | |
435 | uloc_getLanguage(localeName, langName, sizeof(langName), &status); | |
436 | uloc_getLanguage(lcidStringC, langLCID, sizeof(langLCID), &status); | |
437 | ||
438 | if (strcmp(langName, langLCID) == 0) { | |
439 | log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n", | |
440 | localeName, lcidStringC, expectedLCID); | |
441 | } | |
442 | else { | |
443 | log_err("ERROR: %-5s has 0x%.4x and the number resolves wrongfully to %s\n", | |
444 | localeName, expectedLCID, lcidStringC); | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
449 | static void | |
450 | TestLocaleStructure(void) { | |
451 | UResourceBundle *root, *currentLocale; | |
452 | int32_t locCount = uloc_countAvailable(); | |
453 | int32_t locIndex; | |
454 | UErrorCode errorCode = U_ZERO_ERROR; | |
73c04bcf | 455 | const char *currLoc, *resolvedLoc; |
374ca955 A |
456 | |
457 | /* TODO: Compare against parent's data too. This code can't handle fallbacks that some tools do already. */ | |
458 | /* char locName[ULOC_FULLNAME_CAPACITY]; | |
459 | char *locNamePtr; | |
460 | ||
461 | for (locIndex = 0; locIndex < locCount; locIndex++) { | |
462 | errorCode=U_ZERO_ERROR; | |
463 | strcpy(locName, uloc_getAvailable(locIndex)); | |
464 | locNamePtr = strrchr(locName, '_'); | |
465 | if (locNamePtr) { | |
466 | *locNamePtr = 0; | |
467 | } | |
468 | else { | |
469 | strcpy(locName, "root"); | |
470 | } | |
471 | ||
472 | root = ures_openDirect(NULL, locName, &errorCode); | |
473 | if(U_FAILURE(errorCode)) { | |
474 | log_err("Can't open %s\n", locName); | |
475 | continue; | |
476 | } | |
477 | */ | |
478 | if (locCount <= 1) { | |
479 | log_data_err("At least root needs to be installed\n"); | |
480 | } | |
481 | ||
482 | root = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode); | |
483 | if(U_FAILURE(errorCode)) { | |
484 | log_data_err("Can't open structLocale\n"); | |
485 | return; | |
486 | } | |
487 | for (locIndex = 0; locIndex < locCount; locIndex++) { | |
488 | errorCode=U_ZERO_ERROR; | |
489 | currLoc = uloc_getAvailable(locIndex); | |
490 | currentLocale = ures_open(NULL, currLoc, &errorCode); | |
491 | if(errorCode != U_ZERO_ERROR) { | |
492 | if(U_SUCCESS(errorCode)) { | |
493 | /* It's installed, but there is no data. | |
494 | It's installed for the g18n white paper [grhoten] */ | |
495 | log_err("ERROR: Locale %-5s not installed, and it should be!\n", | |
496 | uloc_getAvailable(locIndex)); | |
497 | } else { | |
498 | log_err("%%%%%%% Unexpected error %d in %s %%%%%%%", | |
499 | u_errorName(errorCode), | |
500 | uloc_getAvailable(locIndex)); | |
501 | } | |
502 | ures_close(currentLocale); | |
503 | continue; | |
504 | } | |
505 | ures_getStringByKey(currentLocale, "Version", NULL, &errorCode); | |
506 | if(errorCode != U_ZERO_ERROR) { | |
507 | log_err("No version information is available for locale %s, and it should be!\n", | |
508 | currLoc); | |
509 | } | |
510 | else if (ures_getStringByKey(currentLocale, "Version", NULL, &errorCode)[0] == (UChar)(0x78)) { | |
511 | log_verbose("WARNING: The locale %s is experimental! It shouldn't be listed as an installed locale.\n", | |
512 | currLoc); | |
513 | } | |
73c04bcf A |
514 | resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode); |
515 | if (strcmp(resolvedLoc, currLoc) != 0) { | |
516 | /* All locales have at least a Version resource. | |
517 | If it's absolutely empty, then the previous test will fail too.*/ | |
518 | log_err("Locale resolves to different locale. Is %s an alias of %s?\n", | |
519 | currLoc, resolvedLoc); | |
520 | } | |
374ca955 A |
521 | TestKeyInRootRecursive(root, "root", currentLocale, currLoc); |
522 | ||
523 | testLCID(currentLocale, currLoc); | |
524 | ||
525 | ures_close(currentLocale); | |
526 | } | |
527 | ||
528 | ures_close(root); | |
529 | } | |
530 | ||
531 | static void | |
532 | compareArrays(const char *keyName, | |
533 | UResourceBundle *fromArray, const char *fromLocale, | |
534 | UResourceBundle *toArray, const char *toLocale, | |
535 | int32_t start, int32_t end) | |
536 | { | |
537 | int32_t fromSize = ures_getSize(fromArray); | |
538 | int32_t toSize = ures_getSize(fromArray); | |
539 | int32_t idx; | |
540 | UErrorCode errorCode = U_ZERO_ERROR; | |
541 | ||
542 | if (fromSize > toSize) { | |
543 | fromSize = toSize; | |
544 | log_err("Arrays are different size from \"%s\" to \"%s\"\n", | |
545 | fromLocale, | |
546 | toLocale); | |
547 | } | |
548 | ||
549 | for (idx = start; idx <= end; idx++) { | |
550 | const UChar *fromBundleStr = ures_getStringByIndex(fromArray, idx, NULL, &errorCode); | |
551 | const UChar *toBundleStr = ures_getStringByIndex(toArray, idx, NULL, &errorCode); | |
552 | if (fromBundleStr && toBundleStr && u_strcmp(fromBundleStr, toBundleStr) != 0) | |
553 | { | |
554 | log_err("Difference for %s at index %d from %s= \"%s\" to %s= \"%s\"\n", | |
555 | keyName, | |
556 | idx, | |
557 | fromLocale, | |
558 | austrdup(fromBundleStr), | |
559 | toLocale, | |
560 | austrdup(toBundleStr)); | |
561 | } | |
562 | } | |
563 | } | |
564 | ||
565 | static void | |
566 | compareConsistentCountryInfo(const char *fromLocale, const char *toLocale) { | |
567 | UErrorCode errorCode = U_ZERO_ERROR; | |
568 | UResourceBundle *fromDateTimeElements, *toDateTimeElements, *fromWeekendData = NULL, *toWeekendData = NULL; | |
569 | UResourceBundle *fromArray, *toArray; | |
570 | UResourceBundle *fromLocaleBund = ures_open(NULL, fromLocale, &errorCode); | |
571 | UResourceBundle *toLocaleBund = ures_open(NULL, toLocale, &errorCode); | |
572 | UResourceBundle *toCalendar, *fromCalendar, *toGregorian, *fromGregorian; | |
573 | ||
574 | if(U_FAILURE(errorCode)) { | |
575 | log_err("Can't open resource bundle %s or %s - %s\n", fromLocale, toLocale, u_errorName(errorCode)); | |
576 | return; | |
577 | } | |
578 | fromCalendar = ures_getByKey(fromLocaleBund, "calendar", NULL, &errorCode); | |
579 | fromGregorian = ures_getByKeyWithFallback(fromCalendar, "gregorian", NULL, &errorCode); | |
580 | fromDateTimeElements = ures_getByKeyWithFallback(fromGregorian, "DateTimeElements", NULL, &errorCode); | |
581 | ||
582 | toCalendar = ures_getByKey(toLocaleBund, "calendar", NULL, &errorCode); | |
583 | toGregorian = ures_getByKeyWithFallback(toCalendar, "gregorian", NULL, &errorCode); | |
584 | toDateTimeElements = ures_getByKeyWithFallback(toGregorian, "DateTimeElements", NULL, &errorCode); | |
585 | ||
586 | if(U_FAILURE(errorCode)){ | |
587 | log_err("Did not get DateTimeElements from the bundle %s or %s\n", fromLocale, toLocale); | |
588 | goto cleanup; | |
589 | } | |
590 | ||
591 | fromWeekendData = ures_getByKeyWithFallback(fromGregorian, "weekend", NULL, &errorCode); | |
592 | if(U_FAILURE(errorCode)){ | |
593 | log_err("Did not get weekend data from the bundle %s to compare against %s\n", fromLocale, toLocale); | |
594 | goto cleanup; | |
595 | } | |
596 | toWeekendData = ures_getByKeyWithFallback(toGregorian, "weekend", NULL, &errorCode); | |
597 | if(U_FAILURE(errorCode)){ | |
598 | log_err("Did not get weekend data from the bundle %s to compare against %s\n", toLocale, fromLocale); | |
599 | goto cleanup; | |
600 | } | |
601 | ||
602 | if (strcmp(fromLocale, "ar_IN") != 0) | |
603 | { | |
604 | int32_t fromSize; | |
605 | int32_t toSize; | |
606 | int32_t idx; | |
607 | const int32_t *fromBundleArr = ures_getIntVector(fromDateTimeElements, &fromSize, &errorCode); | |
608 | const int32_t *toBundleArr = ures_getIntVector(toDateTimeElements, &toSize, &errorCode); | |
609 | ||
610 | if (fromSize > toSize) { | |
611 | fromSize = toSize; | |
612 | log_err("Arrays are different size with key \"DateTimeElements\" from \"%s\" to \"%s\"\n", | |
613 | fromLocale, | |
614 | toLocale); | |
615 | } | |
616 | ||
617 | for (idx = 0; idx < fromSize; idx++) { | |
618 | if (fromBundleArr[idx] != toBundleArr[idx]) { | |
619 | log_err("Difference with key \"DateTimeElements\" at index %d from \"%s\" to \"%s\"\n", | |
620 | idx, | |
621 | fromLocale, | |
622 | toLocale); | |
623 | } | |
624 | } | |
625 | } | |
626 | ||
627 | /* test for weekend data */ | |
628 | { | |
629 | int32_t fromSize; | |
630 | int32_t toSize; | |
631 | int32_t idx; | |
632 | const int32_t *fromBundleArr = ures_getIntVector(fromWeekendData, &fromSize, &errorCode); | |
633 | const int32_t *toBundleArr = ures_getIntVector(toWeekendData, &toSize, &errorCode); | |
634 | ||
635 | if (fromSize > toSize) { | |
636 | fromSize = toSize; | |
637 | log_err("Arrays are different size with key \"weekend\" data from \"%s\" to \"%s\"\n", | |
638 | fromLocale, | |
639 | toLocale); | |
640 | } | |
641 | ||
642 | for (idx = 0; idx < fromSize; idx++) { | |
643 | if (fromBundleArr[idx] != toBundleArr[idx]) { | |
644 | log_err("Difference with key \"weekend\" data at index %d from \"%s\" to \"%s\"\n", | |
645 | idx, | |
646 | fromLocale, | |
647 | toLocale); | |
648 | } | |
649 | } | |
650 | } | |
651 | ||
652 | fromArray = ures_getByKey(fromLocaleBund, "CurrencyElements", NULL, &errorCode); | |
653 | toArray = ures_getByKey(toLocaleBund, "CurrencyElements", NULL, &errorCode); | |
654 | if (strcmp(fromLocale, "en_CA") != 0) | |
655 | { | |
656 | /* The first one is probably localized. */ | |
657 | compareArrays("CurrencyElements", fromArray, fromLocale, toArray, toLocale, 1, 2); | |
658 | } | |
659 | ures_close(fromArray); | |
660 | ures_close(toArray); | |
661 | ||
662 | fromArray = ures_getByKey(fromLocaleBund, "NumberPatterns", NULL, &errorCode); | |
663 | toArray = ures_getByKey(toLocaleBund, "NumberPatterns", NULL, &errorCode); | |
664 | if (strcmp(fromLocale, "en_CA") != 0) | |
665 | { | |
666 | compareArrays("NumberPatterns", fromArray, fromLocale, toArray, toLocale, 0, 3); | |
667 | } | |
668 | ures_close(fromArray); | |
669 | ures_close(toArray); | |
670 | ||
671 | /* Difficult to test properly */ | |
672 | /* | |
673 | fromArray = ures_getByKey(fromLocaleBund, "DateTimePatterns", NULL, &errorCode); | |
674 | toArray = ures_getByKey(toLocaleBund, "DateTimePatterns", NULL, &errorCode); | |
675 | { | |
676 | compareArrays("DateTimePatterns", fromArray, fromLocale, toArray, toLocale); | |
677 | } | |
678 | ures_close(fromArray); | |
679 | ures_close(toArray);*/ | |
680 | ||
681 | fromArray = ures_getByKey(fromLocaleBund, "NumberElements", NULL, &errorCode); | |
682 | toArray = ures_getByKey(toLocaleBund, "NumberElements", NULL, &errorCode); | |
683 | if (strcmp(fromLocale, "en_CA") != 0) | |
684 | { | |
685 | compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 0, 3); | |
686 | /* Index 4 is a script based 0 */ | |
687 | compareArrays("NumberElements", fromArray, fromLocale, toArray, toLocale, 5, 10); | |
688 | } | |
689 | ures_close(fromArray); | |
690 | ures_close(toArray); | |
691 | ||
692 | cleanup: | |
693 | ures_close(fromDateTimeElements); | |
694 | ures_close(toDateTimeElements); | |
695 | ures_close(fromWeekendData); | |
696 | ures_close(toWeekendData); | |
697 | ||
698 | ures_close(fromCalendar); | |
699 | ures_close(toCalendar); | |
700 | ures_close(fromGregorian); | |
701 | ures_close(toGregorian); | |
702 | ||
703 | ures_close(fromLocaleBund); | |
704 | ures_close(toLocaleBund); | |
705 | } | |
706 | ||
707 | static void | |
708 | TestConsistentCountryInfo(void) { | |
709 | /* UResourceBundle *fromLocale, *toLocale;*/ | |
710 | int32_t locCount = uloc_countAvailable(); | |
711 | int32_t fromLocIndex, toLocIndex; | |
712 | ||
713 | int32_t fromCountryLen, toCountryLen; | |
714 | char fromCountry[ULOC_FULLNAME_CAPACITY], toCountry[ULOC_FULLNAME_CAPACITY]; | |
715 | ||
716 | int32_t fromVariantLen, toVariantLen; | |
717 | char fromVariant[ULOC_FULLNAME_CAPACITY], toVariant[ULOC_FULLNAME_CAPACITY]; | |
718 | ||
719 | UErrorCode errorCode = U_ZERO_ERROR; | |
720 | ||
721 | for (fromLocIndex = 0; fromLocIndex < locCount; fromLocIndex++) { | |
722 | const char *fromLocale = uloc_getAvailable(fromLocIndex); | |
723 | ||
724 | errorCode=U_ZERO_ERROR; | |
725 | fromCountryLen = uloc_getCountry(fromLocale, fromCountry, ULOC_FULLNAME_CAPACITY, &errorCode); | |
726 | if (fromCountryLen <= 0) { | |
727 | /* Ignore countryless locales */ | |
728 | continue; | |
729 | } | |
730 | fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode); | |
731 | if (fromVariantLen > 0) { | |
732 | /* Most variants are ignorable like PREEURO, or collation variants. */ | |
733 | continue; | |
734 | } | |
735 | /* Start comparing only after the current index. | |
736 | Previous loop should have already compared fromLocIndex. | |
737 | */ | |
738 | for (toLocIndex = fromLocIndex + 1; toLocIndex < locCount; toLocIndex++) { | |
739 | const char *toLocale = uloc_getAvailable(toLocIndex); | |
740 | ||
741 | toCountryLen = uloc_getCountry(toLocale, toCountry, ULOC_FULLNAME_CAPACITY, &errorCode); | |
742 | if(U_FAILURE(errorCode)) { | |
743 | log_err("Unknown failure fromLocale=%s toLocale=%s errorCode=%s\n", | |
744 | fromLocale, toLocale, u_errorName(errorCode)); | |
745 | continue; | |
746 | } | |
747 | ||
748 | if (toCountryLen <= 0) { | |
749 | /* Ignore countryless locales */ | |
750 | continue; | |
751 | } | |
752 | toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode); | |
753 | if (toVariantLen > 0) { | |
754 | /* Most variants are ignorable like PREEURO, or collation variants. */ | |
755 | /* They're a variant for a reason. */ | |
756 | continue; | |
757 | } | |
758 | if (strcmp(fromCountry, toCountry) == 0) { | |
759 | log_verbose("comparing fromLocale=%s toLocale=%s\n", | |
760 | fromLocale, toLocale); | |
761 | compareConsistentCountryInfo(fromLocale, toLocale); | |
762 | } | |
763 | } | |
764 | } | |
765 | } | |
766 | ||
767 | static int32_t | |
768 | findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize, | |
769 | const UChar *exemplarCharacters, int32_t exemplarLen, | |
770 | UBool ignoreNumbers) { | |
771 | UErrorCode errorCode = U_ZERO_ERROR; | |
73c04bcf A |
772 | USet *origSet = uset_openPatternOptions(exemplarCharacters, exemplarLen, USET_CASE_INSENSITIVE, &errorCode); |
773 | USet *exemplarSet = createFlattenSet(origSet, &errorCode); | |
374ca955 | 774 | int32_t strIdx; |
73c04bcf | 775 | uset_close(origSet); |
374ca955 | 776 | if (U_FAILURE(errorCode)) { |
73c04bcf | 777 | log_err("%s: error uset_openPattern returned %s\n", currLoc, u_errorName(errorCode)); |
374ca955 A |
778 | return -1; |
779 | } | |
780 | ||
781 | for (strIdx = 0; strIdx < langSize; strIdx++) { | |
782 | if (!uset_contains(exemplarSet, string[strIdx]) | |
73c04bcf A |
783 | && string[strIdx] != 0x0020 && string[strIdx] != 0x00A0 && string[strIdx] != 0x002e && string[strIdx] != 0x002c && string[strIdx] != 0x002d && string[strIdx] != 0x0027 |
784 | && string[strIdx] != 0x200C && string[strIdx] != 0x200D) { | |
374ca955 | 785 | if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) { |
73c04bcf | 786 | uset_close(exemplarSet); |
374ca955 A |
787 | return strIdx; |
788 | } | |
789 | } | |
790 | } | |
791 | uset_close(exemplarSet); | |
792 | return -1; | |
793 | } | |
73c04bcf A |
794 | /* include non-invariant chars */ |
795 | static int32_t | |
796 | myUCharsToChars(const UChar* us, char* cs, int32_t len){ | |
797 | int32_t i=0; | |
798 | for(; i< len; i++){ | |
799 | if(us[i] < 0x7f){ | |
800 | cs[i] = (char)us[i]; | |
801 | }else{ | |
802 | return -1; | |
803 | } | |
804 | } | |
805 | return i; | |
806 | } | |
374ca955 A |
807 | static void |
808 | findSetMatch( UScriptCode *scriptCodes, int32_t scriptsLen, | |
809 | USet *exemplarSet, | |
810 | const char *locale){ | |
811 | USet *scripts[10]= {0}; | |
812 | char pattern[256] = { '[', ':', 0x000 }; | |
813 | int32_t patternLen; | |
814 | UChar uPattern[256] = {0}; | |
815 | UErrorCode status = U_ZERO_ERROR; | |
816 | int32_t i; | |
817 | ||
818 | /* create the sets with script codes */ | |
819 | for(i = 0; i<scriptsLen; i++){ | |
820 | strcat(pattern, uscript_getShortName(scriptCodes[i])); | |
821 | strcat(pattern, ":]"); | |
822 | patternLen = (int32_t)strlen(pattern); | |
823 | u_charsToUChars(pattern, uPattern, patternLen); | |
824 | scripts[i] = uset_openPattern(uPattern, patternLen, &status); | |
825 | if(U_FAILURE(status)){ | |
826 | log_err("Could not create set for patter %s. Error: %s\n", pattern, u_errorName(status)); | |
827 | break; | |
828 | } | |
829 | pattern[2] = 0; | |
830 | } | |
831 | if (strcmp(locale, "uk") == 0 || strcmp(locale, "uk_UA") == 0) { | |
832 | /* Special addition. Add the modifying apostrophe, which isn't in Cyrillic. */ | |
833 | uset_add(scripts[0], 0x2bc); | |
834 | } | |
835 | if(U_SUCCESS(status)){ | |
836 | UBool existsInScript = FALSE; | |
837 | /* iterate over the exemplarSet and ascertain if all | |
838 | * UChars in exemplarSet belong to the scripts returned | |
839 | * by getScript | |
840 | */ | |
841 | int32_t count = uset_getItemCount(exemplarSet); | |
842 | ||
843 | for( i=0; i < count; i++){ | |
844 | UChar32 start = 0; | |
845 | UChar32 end = 0; | |
846 | UChar *str = NULL; | |
847 | int32_t strCapacity = 0; | |
73c04bcf | 848 | |
374ca955 A |
849 | strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status); |
850 | if(U_SUCCESS(status)){ | |
851 | int32_t j; | |
852 | if(strCapacity == 0){ | |
853 | /* ok the item is a range */ | |
854 | for( j = 0; j < scriptsLen; j++){ | |
855 | if(uset_containsRange(scripts[j], start, end) == TRUE){ | |
856 | existsInScript = TRUE; | |
857 | } | |
858 | } | |
859 | if(existsInScript == FALSE){ | |
73c04bcf A |
860 | for( j = 0; j < scriptsLen; j++){ |
861 | UChar toPattern[500]={'\0'}; | |
862 | char pat[500]={'\0'}; | |
863 | int32_t len = uset_toPattern(scripts[j], toPattern, 500, TRUE, &status); | |
864 | len = myUCharsToChars(toPattern, pat, len); | |
865 | 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)); | |
866 | if(len!=-1){ | |
867 | log_err("Pattern: %s\n",pat); | |
868 | } | |
869 | } | |
374ca955 A |
870 | log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale); |
871 | } | |
872 | }else{ | |
873 | strCapacity++; /* increment for NUL termination */ | |
874 | /* allocate the str and call the api again */ | |
875 | str = (UChar*) malloc(U_SIZEOF_UCHAR * strCapacity); | |
876 | strCapacity = uset_getItem(exemplarSet, i, &start, &end, str, strCapacity, &status); | |
877 | /* iterate over the scripts and figure out if the string contained is actually | |
878 | * in the script set | |
879 | */ | |
880 | for( j = 0; j < scriptsLen; j++){ | |
881 | if(uset_containsString(scripts[j],str, strCapacity) == TRUE){ | |
882 | existsInScript = TRUE; | |
883 | } | |
884 | } | |
885 | if(existsInScript == FALSE){ | |
886 | log_err("ExemplarCharacters and LocaleScript containment test failed for locale %s. \n", locale); | |
887 | } | |
888 | } | |
889 | } | |
890 | } | |
891 | ||
892 | } | |
893 | ||
894 | /* close the sets */ | |
895 | for(i = 0; i<scriptsLen; i++){ | |
896 | uset_close(scripts[i]); | |
897 | } | |
898 | } | |
899 | ||
900 | static void VerifyTranslation(void) { | |
901 | UResourceBundle *root, *currentLocale; | |
902 | int32_t locCount = uloc_countAvailable(); | |
903 | int32_t locIndex; | |
904 | UErrorCode errorCode = U_ZERO_ERROR; | |
905 | int32_t exemplarLen; | |
906 | const UChar *exemplarCharacters; | |
907 | const char *currLoc; | |
908 | UScriptCode scripts[USCRIPT_CODE_LIMIT]; | |
909 | int32_t numScripts; | |
910 | int32_t idx; | |
911 | int32_t end; | |
912 | UResourceBundle *resArray; | |
913 | ||
914 | if (locCount <= 1) { | |
915 | log_data_err("At least root needs to be installed\n"); | |
916 | } | |
917 | ||
918 | root = ures_openDirect(NULL, "root", &errorCode); | |
919 | if(U_FAILURE(errorCode)) { | |
920 | log_data_err("Can't open root\n"); | |
921 | return; | |
922 | } | |
923 | for (locIndex = 0; locIndex < locCount; locIndex++) { | |
924 | errorCode=U_ZERO_ERROR; | |
925 | currLoc = uloc_getAvailable(locIndex); | |
926 | currentLocale = ures_open(NULL, currLoc, &errorCode); | |
927 | if(errorCode != U_ZERO_ERROR) { | |
928 | if(U_SUCCESS(errorCode)) { | |
929 | /* It's installed, but there is no data. | |
930 | It's installed for the g18n white paper [grhoten] */ | |
931 | log_err("ERROR: Locale %-5s not installed, and it should be!\n", | |
932 | uloc_getAvailable(locIndex)); | |
933 | } else { | |
934 | log_err("%%%%%%% Unexpected error %d in %s %%%%%%%", | |
935 | u_errorName(errorCode), | |
936 | uloc_getAvailable(locIndex)); | |
937 | } | |
938 | ures_close(currentLocale); | |
939 | continue; | |
940 | } | |
941 | exemplarCharacters = ures_getStringByKey(currentLocale, "ExemplarCharacters", &exemplarLen, &errorCode); | |
942 | if (U_FAILURE(errorCode)) { | |
943 | log_err("error ures_getStringByKey returned %s\n", u_errorName(errorCode)); | |
944 | } | |
945 | else if (QUICK && exemplarLen > 2048) { | |
946 | log_verbose("skipping test for %s\n", currLoc); | |
947 | } | |
948 | else { | |
949 | UChar langBuffer[128]; | |
950 | int32_t langSize; | |
951 | int32_t strIdx; | |
952 | langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode); | |
953 | if (U_FAILURE(errorCode)) { | |
954 | log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode)); | |
955 | } | |
956 | else { | |
957 | strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE); | |
958 | if (strIdx >= 0) { | |
959 | log_err("getDisplayLanguage(%s) at index %d returned characters not in the exemplar characters.\n", | |
960 | currLoc, strIdx); | |
961 | } | |
962 | } | |
963 | langSize = uloc_getDisplayCountry(currLoc, currLoc, langBuffer, sizeof(langBuffer)/sizeof(langBuffer[0]), &errorCode); | |
964 | if (U_FAILURE(errorCode)) { | |
965 | log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode)); | |
966 | } | |
967 | else { | |
968 | strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, exemplarCharacters, exemplarLen, FALSE); | |
969 | if (strIdx >= 0) { | |
970 | log_err("getDisplayCountry(%s) at index %d returned characters not in the exemplar characters.\n", | |
971 | currLoc, strIdx); | |
972 | } | |
973 | } | |
974 | { | |
975 | UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode); | |
976 | UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode); | |
977 | UResourceBundle* names = ures_getByKeyWithFallback(greg, "dayNames", NULL, &errorCode); | |
978 | UResourceBundle* format = ures_getByKeyWithFallback(names, "format", NULL, &errorCode); | |
979 | resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode); | |
980 | ||
981 | if (U_FAILURE(errorCode)) { | |
982 | log_err("error ures_getByKey returned %s\n", u_errorName(errorCode)); | |
983 | } | |
984 | if (QUICK) { | |
985 | end = 1; | |
986 | } | |
987 | else { | |
988 | end = ures_getSize(resArray); | |
989 | } | |
990 | ||
991 | ||
992 | for (idx = 0; idx < end; idx++) { | |
993 | const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode); | |
994 | if (U_FAILURE(errorCode)) { | |
995 | log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode)); | |
996 | continue; | |
997 | } | |
998 | strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE); | |
999 | if (strIdx >= 0) { | |
1000 | log_err("getDayNames(%s, %d) at index %d returned characters not in the exemplar characters.\n", | |
1001 | currLoc, idx, strIdx); | |
1002 | } | |
1003 | } | |
1004 | ures_close(resArray); | |
1005 | ures_close(format); | |
1006 | ures_close(names); | |
1007 | ||
1008 | names = ures_getByKeyWithFallback(greg, "monthNames", NULL, &errorCode); | |
1009 | format = ures_getByKeyWithFallback(names,"format", NULL, &errorCode); | |
1010 | resArray = ures_getByKeyWithFallback(format, "wide", NULL, &errorCode); | |
1011 | if (U_FAILURE(errorCode)) { | |
1012 | log_err("error ures_getByKey returned %s\n", u_errorName(errorCode)); | |
1013 | } | |
1014 | if (QUICK) { | |
1015 | end = 1; | |
1016 | } | |
1017 | else { | |
1018 | end = ures_getSize(resArray); | |
1019 | } | |
1020 | ||
1021 | for (idx = 0; idx < end; idx++) { | |
1022 | const UChar *fromBundleStr = ures_getStringByIndex(resArray, idx, &langSize, &errorCode); | |
1023 | if (U_FAILURE(errorCode)) { | |
1024 | log_err("error ures_getStringByIndex(%d) returned %s\n", idx, u_errorName(errorCode)); | |
1025 | continue; | |
1026 | } | |
1027 | strIdx = findStringSetMismatch(currLoc, fromBundleStr, langSize, exemplarCharacters, exemplarLen, TRUE); | |
1028 | if (strIdx >= 0) { | |
1029 | log_err("getMonthNames(%s, %d) at index %d returned characters not in the exemplar characters.\n", | |
1030 | currLoc, idx, strIdx); | |
1031 | } | |
1032 | } | |
1033 | ures_close(resArray); | |
1034 | ures_close(format); | |
1035 | ures_close(names); | |
1036 | ures_close(greg); | |
1037 | ures_close(cal); | |
1038 | } | |
1039 | errorCode = U_ZERO_ERROR; | |
1040 | numScripts = uscript_getCode(currLoc, scripts, sizeof(scripts)/sizeof(scripts[0]), &errorCode); | |
1041 | if (numScripts == 0) { | |
1042 | log_err("uscript_getCode(%s) doesn't work.\n", currLoc); | |
1043 | }else if(scripts[0] == USCRIPT_COMMON){ | |
1044 | log_err("uscript_getCode(%s) returned USCRIPT_COMMON.\n", currLoc); | |
1045 | } | |
1046 | ||
1047 | /* test that the scripts are a superset of exemplar characters. */ | |
1048 | { | |
73c04bcf A |
1049 | ULocaleData *uld = ulocdata_open(currLoc,&errorCode); |
1050 | USet *exemplarSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &errorCode); | |
374ca955 A |
1051 | /* test if exemplar characters are part of script code */ |
1052 | findSetMatch(scripts, numScripts, exemplarSet, currLoc); | |
1053 | uset_close(exemplarSet); | |
73c04bcf | 1054 | ulocdata_close(uld); |
374ca955 A |
1055 | } |
1056 | ||
1057 | /* test that the paperSize API works */ | |
1058 | { | |
1059 | int32_t height=0, width=0; | |
1060 | ulocdata_getPaperSize(currLoc, &height, &width, &errorCode); | |
1061 | if(U_FAILURE(errorCode)){ | |
1062 | log_err("ulocdata_getPaperSize failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode)); | |
1063 | } | |
1064 | if(strstr(currLoc, "_US")!=NULL && height != 279 && width != 216 ){ | |
1065 | log_err("ulocdata_getPaperSize did not return expected data for locale %s \n", currLoc); | |
1066 | } | |
1067 | } | |
1068 | /* test that the MeasurementSystem works API works */ | |
1069 | { | |
1070 | UMeasurementSystem measurementSystem = ulocdata_getMeasurementSystem(currLoc, &errorCode); | |
1071 | if(U_FAILURE(errorCode)){ | |
1072 | log_err("ulocdata_getMeasurementSystem failed for locale %s with error: %s \n", currLoc, u_errorName(errorCode)); | |
1073 | } | |
1074 | if(strstr(currLoc, "_US")!=NULL){ | |
1075 | if(measurementSystem != UMS_US){ | |
1076 | log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc); | |
1077 | } | |
1078 | }else if(measurementSystem != UMS_SI){ | |
1079 | log_err("ulocdata_getMeasurementSystem did not return expected data for locale %s \n", currLoc); | |
1080 | } | |
1081 | } | |
1082 | } | |
1083 | ures_close(currentLocale); | |
1084 | } | |
1085 | ||
1086 | ures_close(root); | |
1087 | } | |
1088 | ||
1089 | /* adjust this limit as appropriate */ | |
1090 | #define MAX_SCRIPTS_PER_LOCALE 8 | |
1091 | ||
1092 | static void TestExemplarSet(void){ | |
1093 | int32_t i, j, k, m, n; | |
1094 | int32_t equalCount = 0; | |
1095 | UErrorCode ec = U_ZERO_ERROR; | |
1096 | UEnumeration* avail; | |
1097 | USet* exemplarSets[2]; | |
73c04bcf | 1098 | USet* unassignedSet; |
374ca955 A |
1099 | UScriptCode code[MAX_SCRIPTS_PER_LOCALE]; |
1100 | USet* codeSets[MAX_SCRIPTS_PER_LOCALE]; | |
1101 | int32_t codeLen; | |
1102 | char cbuf[32]; /* 9 should be enough */ | |
1103 | UChar ubuf[64]; /* adjust as needed */ | |
1104 | UBool existsInScript; | |
1105 | int32_t itemCount; | |
1106 | int32_t strLen; | |
1107 | UChar32 start, end; | |
1108 | ||
73c04bcf A |
1109 | unassignedSet = NULL; |
1110 | exemplarSets[0] = NULL; | |
1111 | exemplarSets[1] = NULL; | |
374ca955 A |
1112 | for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) { |
1113 | codeSets[i] = NULL; | |
1114 | } | |
1115 | ||
1116 | avail = ures_openAvailableLocales(NULL, &ec); | |
1117 | if (!assertSuccess("ures_openAvailableLocales", &ec)) goto END; | |
1118 | n = uenum_count(avail, &ec); | |
1119 | if (!assertSuccess("uenum_count", &ec)) goto END; | |
1120 | ||
73c04bcf A |
1121 | u_uastrcpy(ubuf, "[:unassigned:]"); |
1122 | unassignedSet = uset_openPattern(ubuf, -1, &ec); | |
1123 | if (!assertSuccess("uset_openPattern", &ec)) goto END; | |
1124 | ||
374ca955 A |
1125 | for(i=0; i<n; i++){ |
1126 | const char* locale = uenum_next(avail, NULL, &ec); | |
1127 | if (!assertSuccess("uenum_next", &ec)) goto END; | |
1128 | log_verbose("%s\n", locale); | |
1129 | for (k=0; k<2; ++k) { | |
1130 | uint32_t option = (k==0) ? 0 : USET_CASE_INSENSITIVE; | |
73c04bcf A |
1131 | ULocaleData *uld = ulocdata_open(locale,&ec); |
1132 | USet* exemplarSet = ulocdata_getExemplarSet(uld,NULL, option, ULOCDATA_ES_STANDARD, &ec); | |
374ca955 | 1133 | uset_close(exemplarSets[k]); |
73c04bcf | 1134 | ulocdata_close(uld); |
374ca955 A |
1135 | exemplarSets[k] = exemplarSet; |
1136 | if (!assertSuccess("ulocaledata_getExemplarSet", &ec)) goto END; | |
1137 | ||
73c04bcf A |
1138 | if (uset_containsSome(exemplarSet, unassignedSet)) { |
1139 | log_err("ExemplarSet contains unassigned characters for locale : %s\n", locale); | |
1140 | } | |
374ca955 A |
1141 | codeLen = uscript_getCode(locale, code, 8, &ec); |
1142 | if (!assertSuccess("uscript_getCode", &ec)) goto END; | |
1143 | ||
1144 | for (j=0; j<MAX_SCRIPTS_PER_LOCALE; ++j) { | |
1145 | uset_close(codeSets[j]); | |
1146 | codeSets[j] = NULL; | |
1147 | } | |
1148 | for (j=0; j<codeLen; ++j) { | |
1149 | uprv_strcpy(cbuf, "[:"); | |
73c04bcf A |
1150 | if(code[j]==-1){ |
1151 | log_err("USCRIPT_INVALID_CODE returned for locale: %s\n", locale); | |
1152 | continue; | |
1153 | } | |
374ca955 A |
1154 | uprv_strcat(cbuf, uscript_getShortName(code[j])); |
1155 | uprv_strcat(cbuf, ":]"); | |
1156 | u_uastrcpy(ubuf, cbuf); | |
1157 | codeSets[j] = uset_openPattern(ubuf, -1, &ec); | |
1158 | } | |
1159 | if (!assertSuccess("uset_openPattern", &ec)) goto END; | |
1160 | ||
1161 | existsInScript = FALSE; | |
1162 | itemCount = uset_getItemCount(exemplarSet); | |
1163 | for (m=0; m<itemCount && !existsInScript; ++m) { | |
1164 | strLen = uset_getItem(exemplarSet, m, &start, &end, ubuf, | |
1165 | sizeof(ubuf)/sizeof(ubuf[0]), &ec); | |
1166 | /* failure here might mean str[] needs to be larger */ | |
1167 | if (!assertSuccess("uset_getItem", &ec)) goto END; | |
1168 | if (strLen == 0) { | |
1169 | for (j=0; j<codeLen; ++j) { | |
73c04bcf | 1170 | if (codeSets[j]!=NULL && uset_containsRange(codeSets[j], start, end)) { |
374ca955 A |
1171 | existsInScript = TRUE; |
1172 | break; | |
1173 | } | |
1174 | } | |
1175 | } else { | |
1176 | for (j=0; j<codeLen; ++j) { | |
73c04bcf | 1177 | if (codeSets[j]!=NULL && uset_containsString(codeSets[j], ubuf, strLen)) { |
374ca955 A |
1178 | existsInScript = TRUE; |
1179 | break; | |
1180 | } | |
1181 | } | |
1182 | } | |
1183 | } | |
1184 | ||
1185 | if (existsInScript == FALSE){ | |
73c04bcf | 1186 | log_err("ExemplarSet containment failed for locale : %s\n", locale); |
374ca955 A |
1187 | } |
1188 | } | |
1189 | assertTrue("case-folded is a superset", | |
1190 | uset_containsAll(exemplarSets[1], exemplarSets[0])); | |
1191 | if (uset_equals(exemplarSets[1], exemplarSets[0])) { | |
1192 | ++equalCount; | |
1193 | } | |
1194 | } | |
1195 | /* Note: The case-folded set should sometimes be a strict superset | |
1196 | and sometimes be equal. */ | |
1197 | assertTrue("case-folded is sometimes a strict superset, and sometimes equal", | |
1198 | equalCount > 0 && equalCount < n); | |
1199 | ||
1200 | END: | |
1201 | uenum_close(avail); | |
1202 | uset_close(exemplarSets[0]); | |
1203 | uset_close(exemplarSets[1]); | |
73c04bcf | 1204 | uset_close(unassignedSet); |
374ca955 A |
1205 | for (i=0; i<MAX_SCRIPTS_PER_LOCALE; ++i) { |
1206 | uset_close(codeSets[i]); | |
1207 | } | |
1208 | } | |
1209 | ||
73c04bcf A |
1210 | static void TestCoverage(void){ |
1211 | ULocaleDataDelimiterType types[] = { | |
1212 | ULOCDATA_QUOTATION_START, /* Quotation start */ | |
1213 | ULOCDATA_QUOTATION_END, /* Quotation end */ | |
1214 | ULOCDATA_ALT_QUOTATION_START, /* Alternate quotation start */ | |
1215 | ULOCDATA_ALT_QUOTATION_END, /* Alternate quotation end */ | |
1216 | ULOCDATA_DELIMITER_COUNT | |
1217 | }; | |
1218 | int i; | |
1219 | UBool sub; | |
1220 | UErrorCode status = U_ZERO_ERROR; | |
1221 | ULocaleData *uld = ulocdata_open(uloc_getDefault(), &status); | |
1222 | ||
1223 | if(U_FAILURE(status)){ | |
1224 | log_err("ulocdata_open error"); | |
1225 | return; | |
1226 | } | |
1227 | ||
1228 | ||
1229 | for(i = 0; i < ULOCDATA_DELIMITER_COUNT; i++){ | |
1230 | UChar result[32] = {0,}; | |
1231 | status = U_ZERO_ERROR; | |
1232 | ulocdata_getDelimiter(uld, types[i], result, 32, &status); | |
1233 | if (U_FAILURE(status)){ | |
1234 | log_err("ulocdata_getgetDelimiter error with type %d", types[i]); | |
1235 | } | |
1236 | } | |
1237 | ||
1238 | sub = ulocdata_getNoSubstitute(uld); | |
1239 | ulocdata_setNoSubstitute(uld,sub); | |
1240 | ulocdata_close(uld); | |
1241 | } | |
1242 | ||
1243 | static void TestCurrencyList(void){ | |
1244 | #if !UCONFIG_NO_FORMATTING | |
1245 | UErrorCode errorCode = U_ZERO_ERROR; | |
1246 | int32_t structLocaleCount, currencyCount; | |
1247 | UEnumeration *en = ucurr_openISOCurrencies(UCURR_ALL, &errorCode); | |
1248 | const char *isoCode, *structISOCode; | |
1249 | UResourceBundle *subBundle; | |
1250 | UResourceBundle *currencies = ures_openDirect(loadTestData(&errorCode), "structLocale", &errorCode); | |
1251 | if(U_FAILURE(errorCode)) { | |
1252 | log_data_err("Can't open structLocale\n"); | |
1253 | return; | |
1254 | } | |
1255 | currencies = ures_getByKey(currencies, "Currencies", currencies, &errorCode); | |
1256 | currencyCount = uenum_count(en, &errorCode); | |
1257 | structLocaleCount = ures_getSize(currencies); | |
1258 | if (currencyCount != structLocaleCount) { | |
1259 | log_err("structLocale(%d) and ISO4217(%d) currency list are out of sync.\n", structLocaleCount, currencyCount); | |
1260 | #if U_CHARSET_FAMILY == U_ASCII_FAMILY | |
1261 | ures_resetIterator(currencies); | |
1262 | while ((isoCode = uenum_next(en, NULL, &errorCode)) != NULL && ures_hasNext(currencies)) { | |
1263 | subBundle = ures_getNextResource(currencies, NULL, &errorCode); | |
1264 | structISOCode = ures_getKey(subBundle); | |
1265 | ures_close(subBundle); | |
1266 | if (strcmp(structISOCode, isoCode) != 0) { | |
1267 | log_err("First difference found at structLocale(%s) and ISO4217(%s).\n", structISOCode, isoCode); | |
1268 | break; | |
1269 | } | |
1270 | } | |
1271 | #endif | |
1272 | } | |
1273 | ures_close(currencies); | |
1274 | uenum_close(en); | |
1275 | #endif | |
1276 | } | |
1277 | ||
374ca955 A |
1278 | #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name) |
1279 | ||
1280 | void addCLDRTest(TestNode** root); | |
1281 | ||
1282 | void addCLDRTest(TestNode** root) | |
1283 | { | |
1284 | TESTCASE(TestLocaleStructure); | |
1285 | TESTCASE(TestConsistentCountryInfo); | |
1286 | TESTCASE(VerifyTranslation); | |
1287 | TESTCASE(TestExemplarSet); | |
73c04bcf A |
1288 | TESTCASE(TestCurrencyList); |
1289 | TESTCASE(TestCoverage); | |
374ca955 | 1290 | } |