1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 1997-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /*******************************************************************************
9 *
10 * File creststn.c
11 *
12 * Modification History:
13 * Name Date Description
14 * Madhu Katragadda 05/09/2000 Ported Tests for New ResourceBundle API
15 * Madhu Katragadda 05/24/2000 Added new tests to test RES_BINARY for collationElements
16 ********************************************************************************
17 */
18
19
20 #include <time.h>
21 #include "unicode/utypes.h"
22 #include "cintltst.h"
23 #include "unicode/putil.h"
24 #include "unicode/ustring.h"
25 #include "unicode/ucnv.h"
26 #include "unicode/utf8.h"
27 #include "unicode/utf16.h"
28 #include "string.h"
29 #include "cmemory.h"
30 #include "cstring.h"
31 #include "unicode/uchar.h"
32 #include "ucol_imp.h" /* for U_ICUDATA_COLL */
33 #include "ubrkimpl.h" /* for U_ICUDATA_BRKITR */
34 #define RESTEST_HEAP_CHECK 0
35
36 #include "unicode/uloc.h"
37 #include "unicode/ulocdata.h"
38 #include "uresimp.h"
39 #include "creststn.h"
40 #include "unicode/ctest.h"
41 #include "ucbuf.h"
42 #include "ureslocs.h"
43
44 static int32_t pass;
45 static int32_t fail;
46
47 /*****************************************************************************/
48 /**
49 * Return a random unsigned long l where 0N <= l <= ULONG_MAX.
50 */
51
52 static uint32_t
randul()53 randul()
54 {
55 uint32_t l=0;
56 int32_t i;
57 static UBool initialized = FALSE;
58 if (!initialized)
59 {
60 srand((unsigned)time(NULL));
61 initialized = TRUE;
62 }
63 /* Assume rand has at least 12 bits of precision */
64
65 for (i=0; i<(int32_t)sizeof(l); ++i)
66 ((char*)&l)[i] = (char)((rand() & 0x0FF0) >> 4);
67 return l;
68 }
69
70 /**
71 * Return a random double x where 0.0 <= x < 1.0.
72 */
73 static double
randd()74 randd()
75 {
76 return ((double)randul()) / UINT32_MAX;
77 }
78
79 /**
80 * Return a random integer i where 0 <= i < n.
81 */
randi(int32_t n)82 static int32_t randi(int32_t n)
83 {
84 return (int32_t)(randd() * n);
85 }
86 /***************************************************************************************/
87 /**
88 * Convert an integer, positive or negative, to a character string radix 10.
89 */
90 static char*
itoa1(int32_t i,char * buf)91 itoa1(int32_t i, char* buf)
92 {
93 char *p = 0;
94 char* result = buf;
95 /* Handle negative */
96 if(i < 0) {
97 *buf++ = '-';
98 i = -i;
99 }
100
101 /* Output digits in reverse order */
102 p = buf;
103 do {
104 *p++ = (char)('0' + (i % 10));
105 i /= 10;
106 }
107 while(i);
108 *p-- = 0;
109
110 /* Reverse the string */
111 while(buf < p) {
112 char c = *buf;
113 *buf++ = *p;
114 *p-- = c;
115 }
116
117 return result;
118 }
119 static const int32_t kERROR_COUNT = -1234567;
120 static const UChar kERROR[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/,
121 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/};
122
123 /*****************************************************************************/
124
125 enum E_Where
126 {
127 e_Root,
128 e_te,
129 e_te_IN,
130 e_Where_count
131 };
132 typedef enum E_Where E_Where;
133 /*****************************************************************************/
134
135 #define CONFIRM_EQ(actual,expected) UPRV_BLOCK_MACRO_BEGIN { \
136 if (u_strcmp(expected,actual)==0) { \
137 record_pass(); \
138 } else { \
139 record_fail(); \
140 log_err("%s returned %s instead of %s\n", action, austrdup(actual), austrdup(expected)); \
141 } \
142 } UPRV_BLOCK_MACRO_END
143 #define CONFIRM_INT_EQ(actual,expected) UPRV_BLOCK_MACRO_BEGIN { \
144 if ((expected)==(actual)) { \
145 record_pass(); \
146 } else { \
147 record_fail(); \
148 log_err("%s returned %d instead of %d\n", action, actual, expected); \
149 } \
150 } UPRV_BLOCK_MACRO_END
151 #define CONFIRM_INT_GE(actual,expected) UPRV_BLOCK_MACRO_BEGIN { \
152 if ((actual)>=(expected)) { \
153 record_pass(); \
154 } else { \
155 record_fail(); \
156 log_err("%s returned %d instead of x >= %d\n", action, actual, expected); \
157 } \
158 } UPRV_BLOCK_MACRO_END
159 #define CONFIRM_INT_NE(actual,expected) UPRV_BLOCK_MACRO_BEGIN { \
160 if ((expected)!=(actual)) { \
161 record_pass(); \
162 } else { \
163 record_fail(); \
164 log_err("%s returned %d instead of x != %d\n", action, actual, expected); \
165 } \
166 } UPRV_BLOCK_MACRO_END
167 /*#define CONFIRM_ErrorCode(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); } */
168 static void
CONFIRM_ErrorCode(UErrorCode actual,UErrorCode expected)169 CONFIRM_ErrorCode(UErrorCode actual,UErrorCode expected)
170 {
171 if ((expected)==(actual))
172 {
173 record_pass();
174 } else {
175 record_fail();
176 /*log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); */
177 log_err("returned %s instead of %s\n", myErrorName(actual), myErrorName(expected));
178 }
179 }
180
181
182 /* Array of our test objects */
183
184 static struct
185 {
186 const char* name;
187 UErrorCode expected_constructor_status;
188 E_Where where;
189 UBool like[e_Where_count];
190 UBool inherits[e_Where_count];
191 }
192 param[] =
193 {
194 /* "te" means test */
195 /* "IN" means inherits */
196 /* "NE" or "ne" means "does not exist" */
197
198 { "root", U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } },
199 { "te", U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
200 { "te_IN", U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
201 { "te_NE", U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
202 { "te_IN_NE", U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
203 { "ne", U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
204 };
205
206 static int32_t bundles_count = UPRV_LENGTHOF(param);
207
208
209
210 /*static void printUChars(UChar*);*/
211 static void TestDecodedBundle(void);
212 static void TestGetKeywordValues(void);
213 static void TestGetFunctionalEquivalent(void);
214 static void TestCLDRStyleAliases(void);
215 static void TestFallbackCodes(void);
216 static void TestGetUTF8String(void);
217 static void TestCLDRVersion(void);
218
219 /***************************************************************************************/
220
221 /* Array of our test objects */
222
addNEWResourceBundleTest(TestNode ** root)223 void addNEWResourceBundleTest(TestNode** root)
224 {
225 addTest(root, &TestErrorCodes, "tsutil/creststn/TestErrorCodes");
226 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
227 addTest(root, &TestEmptyBundle, "tsutil/creststn/TestEmptyBundle");
228 addTest(root, &TestConstruction1, "tsutil/creststn/TestConstruction1");
229 addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundles");
230 addTest(root, &TestNewTypes, "tsutil/creststn/TestNewTypes");
231 addTest(root, &TestEmptyTypes, "tsutil/creststn/TestEmptyTypes");
232 addTest(root, &TestBinaryCollationData, "tsutil/creststn/TestBinaryCollationData");
233 addTest(root, &TestAPI, "tsutil/creststn/TestAPI");
234 addTest(root, &TestErrorConditions, "tsutil/creststn/TestErrorConditions");
235 addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle");
236 addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing");
237 addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess");
238 addTest(root, &TestTicket9804, "tsutil/creststn/TestTicket9804");
239 addTest(root, &TestXPath, "tsutil/creststn/TestXPath");
240 addTest(root, &TestCLDRStyleAliases, "tsutil/creststn/TestCLDRStyleAliases");
241 addTest(root, &TestFallbackCodes, "tsutil/creststn/TestFallbackCodes");
242 addTest(root, &TestGetUTF8String, "tsutil/creststn/TestGetUTF8String");
243 addTest(root, &TestCLDRVersion, "tsutil/creststn/TestCLDRVersion");
244 addTest(root, &TestPreventFallback, "tsutil/creststn/TestPreventFallback");
245 #endif
246 addTest(root, &TestFallback, "tsutil/creststn/TestFallback");
247 addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion");
248 addTest(root, &TestGetVersionColl, "tsutil/creststn/TestGetVersionColl");
249 addTest(root, &TestAliasConflict, "tsutil/creststn/TestAliasConflict");
250 addTest(root, &TestGetKeywordValues, "tsutil/creststn/TestGetKeywordValues");
251 addTest(root, &TestGetFunctionalEquivalent,"tsutil/creststn/TestGetFunctionalEquivalent");
252 addTest(root, &TestJB3763, "tsutil/creststn/TestJB3763");
253 addTest(root, &TestStackReuse, "tsutil/creststn/TestStackReuse");
254 }
255
256
257 /***************************************************************************************/
258 static const char* norwayNames[] = {
259 "no_NO_NY",
260 "no_NO",
261 "no",
262 "nn_NO",
263 "nn",
264 "nb_NO",
265 "nb"
266 };
267
268 static const char* norwayLocales[] = {
269 "nn_NO",
270 "nb_NO",
271 "nb",
272 "nn_NO",
273 "nn",
274 "nb_NO",
275 "nb"
276 };
277
checkStatus(int32_t line,UErrorCode expected,UErrorCode status)278 static void checkStatus(int32_t line, UErrorCode expected, UErrorCode status) {
279 if(U_FAILURE(status)) {
280 log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__, line);
281 }
282 if(status != expected) {
283 log_err_status(status, "%s:%d: Expected error code %s, got error code %s\n", __FILE__, line, u_errorName(expected), u_errorName(status));
284 }
285 }
286
TestErrorCodes(void)287 static void TestErrorCodes(void) {
288 UErrorCode status = U_USING_DEFAULT_WARNING;
289
290 UResourceBundle *r = NULL, *r2 = NULL;
291
292 /* First check with ICUDATA */
293 /* first bundle should return fallback warning */
294 r = ures_open(NULL, "ti_ER_ASSAB", &status);
295 checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status);
296 ures_close(r);
297
298 /* this bundle should return zero error, so it shouldn't change the status */
299 status = U_USING_DEFAULT_WARNING;
300 r = ures_open(NULL, "ti_ER", &status);
301 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
302
303 /* we look up the resource which is aliased, but it lives in fallback */
304
305 if(U_SUCCESS(status) && r != NULL) {
306 status = U_USING_DEFAULT_WARNING;
307 r2 = ures_getByKey(r, "ExemplarCharacters", NULL, &status); /* ExemplarCharacters lives in ti */
308 checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status);
309 }
310 ures_close(r);
311
312 /* this bundle should return zero error, so it shouldn't change the status */
313 status = U_USING_DEFAULT_WARNING;
314 r = ures_open(U_ICUDATA_REGION, "ti", &status);
315 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
316 ures_close(r);
317
318 status = U_USING_FALLBACK_WARNING;
319 r = ures_open(NULL, "nolocale", &status);
320 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
321 ures_close(r);
322 ures_close(r2);
323
324 #if !UCONFIG_NO_COLLATION
325 /** Now, with the collation bundle **/
326
327 /* first bundle should return fallback warning */
328 r = ures_open(U_ICUDATA_COLL, "sr_YU_VOJVODINA", &status);
329 checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status);
330 ures_close(r);
331
332 /* this bundle should return zero error, so it shouldn't change the status */
333 status = U_USING_FALLBACK_WARNING;
334 r = ures_open(U_ICUDATA_COLL, "sr", &status);
335 checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status);
336
337 /* we look up the resource which is aliased */
338 if(U_SUCCESS(status) && r != NULL) {
339 status = U_USING_DEFAULT_WARNING;
340 r2 = ures_getByKey(r, "collations", NULL, &status);
341 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
342 }
343 ures_close(r);
344
345 /* this bundle should return zero error, so it shouldn't change the status */
346 status = U_USING_DEFAULT_WARNING;
347 r = ures_open(U_ICUDATA_COLL, "sr", &status);
348 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
349
350 /* we look up the resource which is aliased and at our level */
351 if(U_SUCCESS(status) && r != NULL) {
352 status = U_USING_DEFAULT_WARNING;
353 r2 = ures_getByKey(r, "collations", r2, &status);
354 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
355 }
356 ures_close(r);
357
358 status = U_USING_FALLBACK_WARNING;
359 r = ures_open(U_ICUDATA_COLL, "nolocale", &status);
360 checkStatus(__LINE__, U_USING_DEFAULT_WARNING, status);
361 ures_close(r);
362 ures_close(r2);
363 #endif /* !UCONFIG_NO_COLLATION */
364 }
365
TestAliasConflict(void)366 static void TestAliasConflict(void) {
367 UErrorCode status = U_ZERO_ERROR;
368 UResourceBundle *he = NULL;
369 UResourceBundle *iw = NULL;
370 UResourceBundle *norway = NULL;
371 const UChar *result = NULL;
372 int32_t resultLen;
373 uint32_t size = 0;
374 uint32_t i = 0;
375 const char *realName = NULL;
376
377 he = ures_open(NULL, "he", &status);
378 iw = ures_open(NULL, "iw", &status);
379 if(U_FAILURE(status)) {
380 log_err_status(status, "Failed to get resource with %s\n", myErrorName(status));
381 }
382 ures_close(iw);
383 result = ures_getStringByKey(he, "ExemplarCharacters", &resultLen, &status);
384 if(U_FAILURE(status) || result == NULL) {
385 log_err_status(status, "Failed to get resource ExemplarCharacters with %s\n", myErrorName(status));
386 }
387 ures_close(he);
388
389 size = UPRV_LENGTHOF(norwayNames);
390 for(i = 0; i < size; i++) {
391 status = U_ZERO_ERROR;
392 norway = ures_open(NULL, norwayNames[i], &status);
393 if(U_FAILURE(status)) {
394 log_err_status(status, "Failed to get resource with %s for %s\n", myErrorName(status), norwayNames[i]);
395 continue;
396 }
397 realName = ures_getLocale(norway, &status);
398 log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames[i], realName);
399 if(realName == NULL || strcmp(norwayLocales[i], realName) != 0) {
400 log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames[i], norwayLocales[i], realName);
401 }
402 ures_close(norway);
403 }
404 }
405
TestDecodedBundle()406 static void TestDecodedBundle(){
407
408 UErrorCode error = U_ZERO_ERROR;
409
410 UResourceBundle* resB;
411
412 const UChar* srcFromRes;
413 int32_t len;
414 static const UChar uSrc[] = {
415 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F,
416 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928,
417 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A,
418 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938,
419 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020,
420 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938,
421 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947,
422 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020,
423 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915,
424 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E,
425 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917,
426 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D,
427 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020,
428 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915,
429 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B,
430 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E,
431 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902,
432 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932,
433 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F,
434 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938,
435 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930,
436 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020,
437 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020,
438 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F,
439 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C,
440 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941,
441 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917,
442 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E,
443 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930,
444 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E,
445 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,
446 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,
447 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935,
448 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915,
449 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F,
450 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033,
451 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F,
452 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915,
453 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020,
454 0
455 };
456
457 /* pre-flight */
458 int32_t num =0;
459 const char *testdatapath = loadTestData(&error);
460 resB = ures_open(testdatapath, "encoded", &error);
461 srcFromRes=tres_getString(resB,-1,"str",&len,&error);
462 if(U_FAILURE(error)){
463 log_data_err("Could not find encoded.res from test data bundle. Error: %s\n", u_errorName(error));
464 ures_close(resB);
465 return;
466 }
467 if(u_strncmp(srcFromRes,uSrc,len)!=0){
468 log_err("Genrb produced res files after decoding failed\n");
469 }
470 while(num<len){
471 if(uSrc[num]!=srcFromRes[num]){
472 log_verbose(" Expected: 0x%04X Got: 0x%04X \n", uSrc[num],srcFromRes[num]);
473 }
474 num++;
475 }
476 if (len != u_strlen(uSrc)) {
477 log_err("Genrb produced a string larger than expected\n");
478 }
479 ures_close(resB);
480 }
481
TestNewTypes()482 static void TestNewTypes() {
483 UResourceBundle* theBundle = NULL;
484 char action[256];
485 const char* testdatapath;
486 UErrorCode status = U_ZERO_ERROR;
487 UResourceBundle* res = NULL;
488 uint8_t *binResult = NULL;
489 int32_t len = 0;
490 int32_t i = 0;
491 int32_t intResult = 0;
492 uint32_t uintResult = 0;
493 const UChar *empty = NULL;
494 const UChar *zeroString;
495 UChar expected[] = { 'a','b','c','\0','d','e','f' };
496 const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
497 UChar uExpect[200];
498
499 testdatapath=loadTestData(&status);
500
501 if(U_FAILURE(status))
502 {
503 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
504 return;
505 }
506
507 theBundle = ures_open(testdatapath, "testtypes", &status);
508
509 empty = tres_getString(theBundle, -1, "emptystring", &len, &status);
510 if(empty && (*empty != 0 || len != 0)) {
511 log_err("Empty string returned invalid value\n");
512 }
513
514 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
515
516 CONFIRM_INT_NE(theBundle, NULL);
517
518 /* This test reads the string "abc\u0000def" from the bundle */
519 /* if everything is working correctly, the size of this string */
520 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
521
522 strcpy(action, "getting and testing of string with embeded zero");
523 res = ures_getByKey(theBundle, "zerotest", res, &status);
524 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
525 CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
526 zeroString=tres_getString(res, -1, NULL, &len, &status);
527 if(U_SUCCESS(status)){
528 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
529 CONFIRM_INT_EQ(len, 7);
530 CONFIRM_INT_NE(len, 3);
531 }
532 for(i=0;i<len;i++){
533 if(zeroString[i]!= expected[i]){
534 log_verbose("Output did not match Expected: \\u%4X Got: \\u%4X", expected[i], zeroString[i]);
535 }
536 }
537
538 strcpy(action, "getting and testing of binary type");
539 res = ures_getByKey(theBundle, "binarytest", res, &status);
540 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
541 CONFIRM_INT_EQ(ures_getType(res), URES_BINARY);
542 binResult=(uint8_t*)ures_getBinary(res, &len, &status);
543 if(U_SUCCESS(status)){
544 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
545 CONFIRM_INT_EQ(len, 15);
546 for(i = 0; i<15; i++) {
547 CONFIRM_INT_EQ(binResult[i], i);
548 }
549 }
550
551 strcpy(action, "getting and testing of imported binary type");
552 res = ures_getByKey(theBundle, "importtest", res, &status);
553 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
554 CONFIRM_INT_EQ(ures_getType(res), URES_BINARY);
555 binResult=(uint8_t*)ures_getBinary(res, &len, &status);
556 if(U_SUCCESS(status)){
557 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
558 CONFIRM_INT_EQ(len, 15);
559 for(i = 0; i<15; i++) {
560 CONFIRM_INT_EQ(binResult[i], i);
561 }
562 }
563
564 strcpy(action, "getting and testing of integer types");
565 res = ures_getByKey(theBundle, "one", res, &status);
566 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
567 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
568 intResult=ures_getInt(res, &status);
569 uintResult = ures_getUInt(res, &status);
570 if(U_SUCCESS(status)){
571 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
572 CONFIRM_INT_EQ(uintResult, (uint32_t)intResult);
573 CONFIRM_INT_EQ(intResult, 1);
574 }
575
576 strcpy(action, "getting minusone");
577 res = ures_getByKey(theBundle, "minusone", res, &status);
578 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
579 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
580 intResult=ures_getInt(res, &status);
581 uintResult = ures_getUInt(res, &status);
582 if(U_SUCCESS(status)){
583 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
584 CONFIRM_INT_EQ(uintResult, 0x0FFFFFFF); /* a 28 bit integer */
585 CONFIRM_INT_EQ(intResult, -1);
586 CONFIRM_INT_NE(uintResult, (uint32_t)intResult);
587 }
588
589 strcpy(action, "getting plusone");
590 res = ures_getByKey(theBundle, "plusone", res, &status);
591 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
592 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
593 intResult=ures_getInt(res, &status);
594 uintResult = ures_getUInt(res, &status);
595 if(U_SUCCESS(status)){
596 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
597 CONFIRM_INT_EQ(uintResult, (uint32_t)intResult);
598 CONFIRM_INT_EQ(intResult, 1);
599 }
600
601 res = ures_getByKey(theBundle, "onehundredtwentythree", res, &status);
602 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
603 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
604 intResult=ures_getInt(res, &status);
605 if(U_SUCCESS(status)){
606 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
607 CONFIRM_INT_EQ(intResult, 123);
608 }
609
610 /* this tests if escapes are preserved or not */
611 {
612 const UChar* str = tres_getString(theBundle,-1,"testescape",&len,&status);
613 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
614 if(U_SUCCESS(status)){
615 u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1);
616 if(u_strcmp(uExpect,str)){
617 log_err("Did not get the expected string for testescape\n");
618 }
619 }
620 }
621 /* this tests if unescaping works are expected */
622 len=0;
623 {
624 char pattern[2048] = "";
625 int32_t patternLen;
626 UChar* expectedEscaped;
627 const UChar* got;
628 int32_t expectedLen;
629
630 /* This strcpy fixes compiler warnings about long strings */
631 strcpy(pattern, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
632 "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F "
633 "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 "
634 "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD "
635 "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF "
636 );
637 strcat(pattern,
638 "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF "
639 "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF "
640 "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF "
641 "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB "
642 "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C "
643 );
644 strcat(pattern,
645 "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F "
646 "]"
647 );
648
649 patternLen = (int32_t)uprv_strlen(pattern);
650 expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen);
651 got = tres_getString(theBundle,-1,"test_unescaping",&len,&status);
652 expectedLen = u_unescape(pattern,expectedEscaped,patternLen);
653 if(got==NULL || u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){
654 log_err("genrb failed to unescape string\n");
655 }
656 if(got != NULL){
657 for(i=0;i<expectedLen;i++){
658 if(expectedEscaped[i] != got[i]){
659 log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped[i], got[i]);
660 }
661 }
662 }
663 free(expectedEscaped);
664 status = U_ZERO_ERROR;
665 }
666 /* test for jitterbug#1435 */
667 {
668 const UChar* str = tres_getString(theBundle,-1,"test_underscores",&len,&status);
669 expect ="test message ....";
670 u_charsToUChars(expect,uExpect,(int32_t)strlen(expect)+1);
671 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
672 if(str == NULL || u_strcmp(uExpect,str)){
673 log_err("Did not get the expected string for test_underscores.\n");
674 }
675 }
676 /* test for jitterbug#2626 */
677 #if !UCONFIG_NO_COLLATION
678 {
679 UResourceBundle* resB = NULL;
680 const UChar* str = NULL;
681 int32_t strLength = 0;
682 const UChar my[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */
683 status = U_ZERO_ERROR;
684 resB = ures_getByKey(theBundle, "collations", resB, &status);
685 resB = ures_getByKey(resB, "standard", resB, &status);
686 str = tres_getString(resB,-1,"Sequence",&strLength,&status);
687 if(!str || U_FAILURE(status)) {
688 log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status));
689 } else if(u_strcmp(my,str) != 0){
690 log_err("Did not get the expected string for escaped \\u0075\n");
691 }
692 ures_close(resB);
693 }
694 #endif
695 {
696 const char *sourcePath = ctest_dataSrcDir();
697 int32_t srcPathLen = (int32_t)strlen(sourcePath);
698 const char *deltaPath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
699 int32_t deltaPathLen = (int32_t)strlen(deltaPath);
700 char *testDataFileName = (char *) malloc( srcPathLen+ deltaPathLen + 50 );
701 char *path = testDataFileName;
702
703 strcpy(path, sourcePath);
704 path += srcPathLen;
705 strcpy(path, deltaPath);
706 path += deltaPathLen;
707 status = U_ZERO_ERROR;
708 {
709 int32_t strLen =0;
710 const UChar* str = tres_getString(theBundle, -1, "testincludeUTF",&strLen,&status);
711 strcpy(path, "riwords.txt");
712 path[strlen("riwords.txt")]=0;
713 if(U_FAILURE(status)){
714 log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status));
715 }else{
716 /* open the file */
717 const char* cp = NULL;
718 UCHARBUF* ucbuf = ucbuf_open(testDataFileName,&cp,FALSE,FALSE,&status);
719 len = 0;
720 if(U_SUCCESS(status)){
721 const UChar* buffer = ucbuf_getBuffer(ucbuf,&len,&status);
722 if(U_SUCCESS(status)){
723 /* verify the contents */
724 if(strLen != len ){
725 log_err("Did not get the expected len for riwords. Expected: %i , Got: %i\n", len ,strLen);
726 }
727 /* test string termination */
728 if(u_strlen(str) != strLen || str[strLen]!= 0 ){
729 log_err("testinclude not null terminated!\n");
730 }
731 if(u_strncmp(str, buffer,strLen)!=0){
732 log_err("Did not get the expected string from riwords. Include functionality failed for genrb.\n");
733 }
734 }else{
735 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status));
736 }
737
738 ucbuf_close(ucbuf);
739 }else{
740 log_err("Could not get riwords.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status));
741 }
742 }
743 }
744 status = U_ZERO_ERROR;
745 {
746 int32_t strLen =0;
747 const UChar* str = tres_getString(theBundle, -1, "testinclude",&strLen,&status);
748 strcpy(path, "translit_rules.txt");
749 path[strlen("translit_rules.txt")]=0;
750
751 if(U_FAILURE(status)){
752 log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status));
753 }else{
754 /* open the file */
755 const char* cp=NULL;
756 UCHARBUF* ucbuf = ucbuf_open(testDataFileName,&cp,FALSE,FALSE,&status);
757 len = 0;
758 if(U_SUCCESS(status)){
759 const UChar* buffer = ucbuf_getBuffer(ucbuf,&len,&status);
760 if(U_SUCCESS(status)){
761 /* verify the contents */
762 if(strLen != len ){
763 log_err("Did not get the expected len for translit_rules. Expected: %i , Got: %i\n", len ,strLen);
764 }
765 if(u_strncmp(str, buffer,strLen)!=0){
766 log_err("Did not get the expected string from translit_rules. Include functionality failed for genrb.\n");
767 }
768 }else{
769 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status));
770 }
771 ucbuf_close(ucbuf);
772 }else{
773 log_err("Could not get translit_rules.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status));
774 }
775 }
776 }
777 free(testDataFileName);
778 }
779 ures_close(res);
780 ures_close(theBundle);
781
782 }
783
TestEmptyTypes()784 static void TestEmptyTypes() {
785 UResourceBundle* theBundle = NULL;
786 char action[256];
787 const char* testdatapath;
788 UErrorCode status = U_ZERO_ERROR;
789 UResourceBundle* res = NULL;
790 UResourceBundle* resArray = NULL;
791 const uint8_t *binResult = NULL;
792 int32_t len = 0;
793 int32_t intResult = 0;
794 const UChar *zeroString;
795 const int32_t *zeroIntVect = NULL;
796
797 strcpy(action, "Construction of testtypes bundle");
798 testdatapath=loadTestData(&status);
799 if(U_FAILURE(status))
800 {
801 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
802 return;
803 }
804
805 theBundle = ures_open(testdatapath, "testtypes", &status);
806
807 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
808
809 CONFIRM_INT_NE(theBundle, NULL);
810
811 /* This test reads the string "abc\u0000def" from the bundle */
812 /* if everything is working correctly, the size of this string */
813 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
814
815 status = U_ZERO_ERROR;
816 strcpy(action, "getting and testing of explicit string of zero length string");
817 res = ures_getByKey(theBundle, "emptyexplicitstring", res, &status);
818 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
819 CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
820 zeroString=tres_getString(res, -1, NULL, &len, &status);
821 if(U_SUCCESS(status)){
822 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
823 CONFIRM_INT_EQ(len, 0);
824 CONFIRM_INT_EQ(u_strlen(zeroString), 0);
825 }
826 else {
827 log_err("Couldn't get emptyexplicitstring\n");
828 }
829
830 status = U_ZERO_ERROR;
831 strcpy(action, "getting and testing of normal string of zero length string");
832 res = ures_getByKey(theBundle, "emptystring", res, &status);
833 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
834 CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
835 zeroString=tres_getString(res, -1, NULL, &len, &status);
836 if(U_SUCCESS(status)){
837 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
838 CONFIRM_INT_EQ(len, 0);
839 CONFIRM_INT_EQ(u_strlen(zeroString), 0);
840 }
841 else {
842 log_err("Couldn't get emptystring\n");
843 }
844
845 status = U_ZERO_ERROR;
846 strcpy(action, "getting and testing of empty int");
847 res = ures_getByKey(theBundle, "emptyint", res, &status);
848 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
849 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
850 intResult=ures_getInt(res, &status);
851 if(U_SUCCESS(status)){
852 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
853 CONFIRM_INT_EQ(intResult, 0);
854 }
855 else {
856 log_err("Couldn't get emptystring\n");
857 }
858
859 status = U_ZERO_ERROR;
860 strcpy(action, "getting and testing of zero length intvector");
861 res = ures_getByKey(theBundle, "emptyintv", res, &status);
862 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
863 CONFIRM_INT_EQ(ures_getType(res), URES_INT_VECTOR);
864
865 if(U_FAILURE(status)){
866 log_err("Couldn't get emptyintv key %s\n", u_errorName(status));
867 }
868 else {
869 zeroIntVect=ures_getIntVector(res, &len, &status);
870 (void)zeroIntVect; /* Suppress set but not used warning. */
871 if(!U_SUCCESS(status) || resArray != NULL || len != 0) {
872 log_err("Shouldn't get emptyintv\n");
873 }
874 }
875
876 status = U_ZERO_ERROR;
877 strcpy(action, "getting and testing of zero length emptybin");
878 res = ures_getByKey(theBundle, "emptybin", res, &status);
879 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
880 CONFIRM_INT_EQ(ures_getType(res), URES_BINARY);
881
882 if(U_FAILURE(status)){
883 log_err("Couldn't get emptybin key %s\n", u_errorName(status));
884 }
885 else {
886 binResult=ures_getBinary(res, &len, &status);
887 (void)binResult; /* Suppress set but not used warning. */
888 if(!U_SUCCESS(status) || len != 0) {
889 log_err("Couldn't get emptybin, or it's not empty\n");
890 }
891 }
892
893 status = U_ZERO_ERROR;
894 strcpy(action, "getting and testing of zero length emptyarray");
895 res = ures_getByKey(theBundle, "emptyarray", res, &status);
896 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
897 CONFIRM_INT_EQ(ures_getType(res), URES_ARRAY);
898
899 if(U_FAILURE(status)){
900 log_err("Couldn't get emptyarray key %s\n", u_errorName(status));
901 }
902 else {
903 resArray=ures_getByIndex(res, 0, resArray, &status);
904 if(U_SUCCESS(status) || resArray != NULL){
905 log_err("Shouldn't get emptyarray[0]\n");
906 }
907 }
908
909 status = U_ZERO_ERROR;
910 strcpy(action, "getting and testing of zero length emptytable");
911 res = ures_getByKey(theBundle, "emptytable", res, &status);
912 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
913 CONFIRM_INT_EQ(ures_getType(res), URES_TABLE);
914
915 if(U_FAILURE(status)){
916 log_err("Couldn't get emptytable key %s\n", u_errorName(status));
917 }
918 else {
919 resArray=ures_getByIndex(res, 0, resArray, &status);
920 if(U_SUCCESS(status) || resArray != NULL){
921 log_err("Shouldn't get emptytable[0]\n");
922 }
923 }
924
925 ures_close(res);
926 ures_close(theBundle);
927 }
928
TestEmptyBundle()929 static void TestEmptyBundle(){
930 UErrorCode status = U_ZERO_ERROR;
931 const char* testdatapath=NULL;
932 UResourceBundle *resb=0, *dResB=0;
933
934 testdatapath=loadTestData(&status);
935 if(U_FAILURE(status))
936 {
937 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
938 return;
939 }
940 resb = ures_open(testdatapath, "testempty", &status);
941
942 if(U_SUCCESS(status)){
943 dResB = ures_getByKey(resb,"test",dResB,&status);
944 if(status!= U_MISSING_RESOURCE_ERROR){
945 log_err("Did not get the expected error from an empty resource bundle. Expected : %s Got: %s\n",
946 u_errorName(U_MISSING_RESOURCE_ERROR),u_errorName(status));
947 }
948 }
949 ures_close(dResB);
950 ures_close(resb);
951 }
952
TestBinaryCollationData()953 static void TestBinaryCollationData(){
954 #if !UCONFIG_NO_COLLATION
955 UErrorCode status=U_ZERO_ERROR;
956 const char* locale="te";
957 const char* testdatapath;
958 UResourceBundle *teRes = NULL;
959 UResourceBundle *coll=NULL;
960 UResourceBundle *binColl = NULL;
961 uint8_t *binResult = NULL;
962 int32_t len=0;
963 const char* action="testing the binary collaton data";
964
965 log_verbose("Testing binary collation data resource......\n");
966
967 testdatapath=loadTestData(&status);
968 if(U_FAILURE(status))
969 {
970 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
971 return;
972 }
973
974
975 teRes=ures_open(testdatapath, locale, &status);
976 if(U_FAILURE(status)){
977 log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status));
978 return;
979 }
980 status=U_ZERO_ERROR;
981 coll = ures_getByKey(teRes, "collations", coll, &status);
982 coll = ures_getByKey(coll, "standard", coll, &status);
983 if(U_SUCCESS(status)){
984 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
985 CONFIRM_INT_EQ(ures_getType(coll), URES_TABLE);
986 binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status);
987 if(U_SUCCESS(status)){
988 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
989 CONFIRM_INT_EQ(ures_getType(binColl), URES_BINARY);
990 binResult=(uint8_t*)ures_getBinary(binColl, &len, &status);
991 (void)binResult; /* Suppress set but not used warning. */
992 if(U_SUCCESS(status)){
993 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
994 CONFIRM_INT_GE(len, 1);
995 }
996
997 }else{
998 log_err("ERROR: ures_getByKey(locale(te), %%CollationBin) failed\n");
999 }
1000 }
1001 else{
1002 log_err("ERROR: ures_getByKey(locale(te), collations) failed\n");
1003 return;
1004 }
1005 ures_close(binColl);
1006 ures_close(coll);
1007 ures_close(teRes);
1008 #endif
1009 }
1010
TestAPI()1011 static void TestAPI() {
1012 UErrorCode status=U_ZERO_ERROR;
1013 int32_t len=0;
1014 const char* key=NULL;
1015 const UChar* value=NULL;
1016 const char* testdatapath;
1017 UChar* utestdatapath=NULL;
1018 char convOutput[256];
1019 UChar largeBuffer[1025];
1020 UResourceBundle *teRes = NULL;
1021 UResourceBundle *teFillin=NULL;
1022 UResourceBundle *teFillin2=NULL;
1023
1024 log_verbose("Testing ures_openU()......\n");
1025
1026 testdatapath=loadTestData(&status);
1027 if(U_FAILURE(status))
1028 {
1029 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
1030 return;
1031 }
1032 len =(int32_t)strlen(testdatapath);
1033 utestdatapath = (UChar*) malloc((len+10)*sizeof(UChar));
1034
1035 u_charsToUChars(testdatapath, utestdatapath, (int32_t)strlen(testdatapath)+1);
1036 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) && U_FILE_SEP_CHAR == '\\'
1037 {
1038 /* Convert all backslashes to forward slashes so that we can make sure that ures_openU
1039 can handle invariant characters. */
1040 UChar *backslash;
1041 while ((backslash = u_strchr(utestdatapath, 0x005C))) {
1042 *backslash = 0x002F;
1043 }
1044 }
1045 #endif
1046
1047 u_memset(largeBuffer, 0x0030, UPRV_LENGTHOF(largeBuffer));
1048 largeBuffer[UPRV_LENGTHOF(largeBuffer)-1] = 0;
1049
1050 /*Test ures_openU */
1051
1052 status = U_ZERO_ERROR;
1053 ures_close(ures_openU(largeBuffer, "root", &status));
1054 if(status != U_ILLEGAL_ARGUMENT_ERROR){
1055 log_err("ERROR: ures_openU() worked when the path is very large. It returned %s\n", myErrorName(status));
1056 }
1057
1058 status = U_ZERO_ERROR;
1059 ures_close(ures_openU(NULL, "root", &status));
1060 if(U_FAILURE(status)){
1061 log_err_status(status, "ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status));
1062 }
1063
1064 status = U_ILLEGAL_ARGUMENT_ERROR;
1065 if(ures_openU(NULL, "root", &status) != NULL){
1066 log_err("ERROR: ures_openU() worked with error status with %s\n", myErrorName(status));
1067 }
1068
1069 status = U_ZERO_ERROR;
1070 teRes=ures_openU(utestdatapath, "te", &status);
1071 if(U_FAILURE(status)){
1072 log_err_status(status, "ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status));
1073 return;
1074 }
1075 /*Test ures_getLocale() */
1076 log_verbose("Testing ures_getLocale() .....\n");
1077 if(strcmp(ures_getLocale(teRes, &status), "te") != 0){
1078 log_err("ERROR: ures_getLocale() failed. Expected = te_TE Got = %s\n", ures_getLocale(teRes, &status));
1079 }
1080 /*Test ures_getNextString() */
1081 teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status);
1082 key=ures_getKey(teFillin);
1083 value=(UChar*)ures_getNextString(teFillin, &len, &key, &status);
1084 (void)value; /* Suppress set but not used warning. */
1085 ures_resetIterator(NULL);
1086 value=(UChar*)ures_getNextString(teFillin, &len, &key, &status);
1087 if(status !=U_INDEX_OUTOFBOUNDS_ERROR){
1088 log_err("ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1089 myErrorName(status));
1090 }
1091 ures_resetIterator(teRes);
1092 /*Test ures_getNextResource() where resource is table*/
1093 status=U_ZERO_ERROR;
1094 #if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
1095 /* The next key varies depending on the charset. */
1096 teFillin=ures_getNextResource(teRes, teFillin, &status);
1097 if(U_FAILURE(status)){
1098 log_err("ERROR: ures_getNextResource() failed \n");
1099 }
1100 key=ures_getKey(teFillin);
1101 /*if(strcmp(key, "%%CollationBin") != 0){*/
1102 /*if(strcmp(key, "array_2d_in_Root_te") != 0){*/ /* added "aliasClient" that goes first */
1103 if(strcmp(key, "a") != 0){
1104 log_err("ERROR: ures_getNextResource() failed\n");
1105 }
1106 #endif
1107
1108 /*Test ures_getByIndex on string Resource*/
1109 teFillin=ures_getByKey(teRes, "string_only_in_te", teFillin, &status);
1110 teFillin2=ures_getByIndex(teFillin, 0, teFillin2, &status);
1111 if(U_FAILURE(status)){
1112 log_err("ERROR: ures_getByIndex on string resource failed\n");
1113 }
1114 if(strcmp(u_austrcpy(convOutput, tres_getString(teFillin2, -1, NULL, &len, &status)), "TE") != 0){
1115 status=U_ZERO_ERROR;
1116 log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2, &len, &status)));
1117 }
1118
1119 /*ures_close(teRes);*/
1120
1121 /*Test ures_openFillIn*/
1122 log_verbose("Testing ures_openFillIn......\n");
1123 status=U_ZERO_ERROR;
1124 ures_openFillIn(teRes, testdatapath, "te", &status);
1125 if(U_FAILURE(status)){
1126 log_err("ERROR: ures_openFillIn failed\n");
1127 return;
1128 }
1129 if(strcmp(ures_getLocale(teRes, &status), "te") != 0){
1130 log_err("ERROR: ures_openFillIn did not open the ResourceBundle correctly\n");
1131 }
1132 ures_getByKey(teRes, "string_only_in_te", teFillin, &status);
1133 teFillin2=ures_getNextResource(teFillin, teFillin2, &status);
1134 if(ures_getType(teFillin2) != URES_STRING){
1135 log_err("ERROR: getType for getNextResource after ures_openFillIn failed\n");
1136 }
1137 teFillin2=ures_getNextResource(teFillin, teFillin2, &status);
1138 if(status !=U_INDEX_OUTOFBOUNDS_ERROR){
1139 log_err("ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1140 myErrorName(status));
1141 }
1142
1143 ures_close(teFillin);
1144 ures_close(teFillin2);
1145 ures_close(teRes);
1146
1147 /* Test that ures_getLocale() returns the "real" locale ID */
1148 status=U_ZERO_ERROR;
1149 teRes=ures_open(NULL, "dE_At_NOWHERE_TO_BE_FOUND", &status);
1150 if(U_FAILURE(status)) {
1151 log_data_err("unable to open a locale resource bundle from \"dE_At_NOWHERE_TO_BE_FOUND\"(%s)\n", u_errorName(status));
1152 } else {
1153 if(0!=strcmp("de_AT", ures_getLocale(teRes, &status))) {
1154 log_data_err("ures_getLocale(\"dE_At_NOWHERE_TO_BE_FOUND\")=%s but must be de_AT\n", ures_getLocale(teRes, &status));
1155 }
1156 ures_close(teRes);
1157 }
1158
1159 /* same test, but with an aliased locale resource bundle */
1160 status=U_ZERO_ERROR;
1161 teRes=ures_open(NULL, "iW_Il_depRecaTed_HebreW", &status);
1162 if(U_FAILURE(status)) {
1163 log_data_err("unable to open a locale resource bundle from \"iW_Il_depRecaTed_HebreW\"(%s)\n", u_errorName(status));
1164 } else {
1165 if(0!=strcmp("he_IL", ures_getLocale(teRes, &status))) {
1166 log_data_err("ures_getLocale(\"iW_Il_depRecaTed_HebreW\")=%s but must be he_IL\n", ures_getLocale(teRes, &status));
1167 }
1168 ures_close(teRes);
1169 }
1170 free(utestdatapath);
1171 }
1172
TestErrorConditions()1173 static void TestErrorConditions(){
1174 UErrorCode status=U_ZERO_ERROR;
1175 const char *key=NULL;
1176 const UChar *value=NULL;
1177 const char* testdatapath;
1178 UChar* utestdatapath;
1179 int32_t len=0;
1180 UResourceBundle *teRes = NULL;
1181 UResourceBundle *coll=NULL;
1182 UResourceBundle *binColl = NULL;
1183 UResourceBundle *teFillin=NULL;
1184 UResourceBundle *teFillin2=NULL;
1185 uint8_t *binResult = NULL;
1186 int32_t resultLen;
1187
1188
1189 testdatapath = loadTestData(&status);
1190 if(U_FAILURE(status))
1191 {
1192 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
1193 return;
1194 }
1195 len = (int32_t)strlen(testdatapath);
1196 utestdatapath = (UChar*) malloc(sizeof(UChar) *(len+10));
1197 u_uastrcpy(utestdatapath, testdatapath);
1198
1199 /*Test ures_openU with status != U_ZERO_ERROR*/
1200 log_verbose("Testing ures_openU() with status != U_ZERO_ERROR.....\n");
1201 status=U_ILLEGAL_ARGUMENT_ERROR;
1202 teRes=ures_openU(utestdatapath, "te", &status);
1203 if(U_FAILURE(status)){
1204 log_verbose("ures_openU() failed as expected path =%s with status != U_ZERO_ERROR\n", testdatapath);
1205 }else{
1206 log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath));
1207 ures_close(teRes);
1208 }
1209 /*Test ures_openFillIn fails when input UResourceBundle parameter is NULL*/
1210 log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
1211 status=U_ZERO_ERROR;
1212 ures_openFillIn(NULL, testdatapath, "te", &status);
1213 if(status != U_ILLEGAL_ARGUMENT_ERROR){
1214 log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1215 myErrorName(status));
1216 }
1217 /*Test ures_openDirectFillIn fails when input UResourceBundle parameter is NULL*/
1218 log_verbose("Testing ures_openDirectFillIn with UResourceBundle = NULL.....\n");
1219 status=U_ZERO_ERROR;
1220 ures_openDirectFillIn(NULL, testdatapath, "te", &status);
1221 if(status != U_ILLEGAL_ARGUMENT_ERROR){
1222 log_err("ERROR: ures_openDirectFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1223 myErrorName(status));
1224 }
1225 /*Test ures_getLocale() with status != U_ZERO_ERROR*/
1226 status=U_ZERO_ERROR;
1227 teRes=ures_openU(utestdatapath, "te", &status);
1228 if(U_FAILURE(status)){
1229 log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath), myErrorName(status));
1230 return;
1231 }
1232 status=U_ILLEGAL_ARGUMENT_ERROR;
1233 if(ures_getLocale(teRes, &status) != NULL){
1234 log_err("ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR\n");
1235 }
1236 /*Test ures_getLocale() with UResourceBundle = NULL*/
1237 status=U_ZERO_ERROR;
1238 if(ures_getLocale(NULL, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1239 log_err("ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1240 myErrorName(status));
1241 }
1242 /*Test ures_getSize() with UResourceBundle = NULL */
1243 status=U_ZERO_ERROR;
1244 if(ures_getSize(NULL) != 0){
1245 log_err("ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d\n", ures_getSize(NULL));
1246 }
1247 /*Test ures_getType() with UResourceBundle = NULL should return URES_NONE==-1*/
1248 status=U_ZERO_ERROR;
1249 if(ures_getType(NULL) != URES_NONE){
1250 log_err("ERROR: ures_getType() should return URES_NONE when UResourceBundle=NULL. Got =%d\n", ures_getType(NULL));
1251 }
1252 /*Test ures_getKey() with UResourceBundle = NULL*/
1253 status=U_ZERO_ERROR;
1254 if(ures_getKey(NULL) != NULL){
1255 log_err("ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d\n", ures_getKey(NULL));
1256 }
1257 /*Test ures_hasNext() with UResourceBundle = NULL*/
1258 status=U_ZERO_ERROR;
1259 if(ures_hasNext(NULL) != FALSE){
1260 log_err("ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d\n", ures_hasNext(NULL));
1261 }
1262 /*Test ures_get() with UResourceBundle = NULL*/
1263 status=U_ZERO_ERROR;
1264 if(ures_getStringByKey(NULL, "string_only_in_te", &resultLen, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1265 log_err("ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1266 myErrorName(status));
1267 }
1268 /*Test ures_getByKey() with UResourceBundle = NULL*/
1269 status=U_ZERO_ERROR;
1270 teFillin=ures_getByKey(NULL, "string_only_in_te", teFillin, &status);
1271 if( teFillin != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1272 log_err("ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1273 myErrorName(status));
1274 }
1275 /*Test ures_getByKey() with status != U_ZERO_ERROR*/
1276 teFillin=ures_getByKey(NULL, "string_only_in_te", teFillin, &status);
1277 if(teFillin != NULL ){
1278 log_err("ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR\n");
1279 }
1280 /*Test ures_getStringByKey() with UResourceBundle = NULL*/
1281 status=U_ZERO_ERROR;
1282 if(ures_getStringByKey(NULL, "string_only_in_te", &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1283 log_err("ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1284 myErrorName(status));
1285 }
1286 /*Test ures_getStringByKey() with status != U_ZERO_ERROR*/
1287 if(ures_getStringByKey(teRes, "string_only_in_te", &len, &status) != NULL){
1288 log_err("ERROR: ures_getStringByKey is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1289 myErrorName(status));
1290 }
1291 /*Test ures_getString() with UResourceBundle = NULL*/
1292 status=U_ZERO_ERROR;
1293 if(ures_getString(NULL, &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1294 log_err("ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1295 myErrorName(status));
1296 }
1297 /*Test ures_getString() with status != U_ZERO_ERROR*/
1298 if(ures_getString(teRes, &len, &status) != NULL){
1299 log_err("ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1300 myErrorName(status));
1301 }
1302 /*Test ures_getBinary() with UResourceBundle = NULL*/
1303 status=U_ZERO_ERROR;
1304 if(ures_getBinary(NULL, &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1305 log_err("ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1306 myErrorName(status));
1307 }
1308 /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
1309 status=U_ZERO_ERROR;
1310 coll = ures_getByKey(teRes, "collations", coll, &status);
1311 coll = ures_getByKey(teRes, "standard", coll, &status);
1312 binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status);
1313
1314 status=U_ILLEGAL_ARGUMENT_ERROR;
1315 binResult=(uint8_t*)ures_getBinary(binColl, &len, &status);
1316 if(binResult != NULL){
1317 log_err("ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail\n");
1318 }
1319
1320 /*Test ures_getNextResource() with status != U_ZERO_ERROR*/
1321 teFillin=ures_getNextResource(teRes, teFillin, &status);
1322 if(teFillin != NULL){
1323 log_err("ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1324 }
1325 /*Test ures_getNextResource() with UResourceBundle = NULL*/
1326 status=U_ZERO_ERROR;
1327 teFillin=ures_getNextResource(NULL, teFillin, &status);
1328 if(teFillin != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){
1329 log_err("ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s\n",
1330 myErrorName(status));
1331 }
1332 /*Test ures_getNextString with errorCode != U_ZERO_ERROR*/
1333 teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status);
1334 key=ures_getKey(teFillin);
1335 status = U_ILLEGAL_ARGUMENT_ERROR;
1336 value=(UChar*)ures_getNextString(teFillin, &len, &key, &status);
1337 if(value != NULL){
1338 log_err("ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1339 }
1340 /*Test ures_getNextString with UResourceBundle = NULL*/
1341 status=U_ZERO_ERROR;
1342 value=(UChar*)ures_getNextString(NULL, &len, &key, &status);
1343 if(value != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){
1344 log_err("ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1345 myErrorName(status));
1346 }
1347 /*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/
1348 status=U_ZERO_ERROR;
1349 teFillin=ures_getByKey(teRes, "array_only_in_te", teFillin, &status);
1350 if(ures_countArrayItems(teRes, "array_only_in_te", &status) != 4) {
1351 log_err("ERROR: Wrong number of items in an array!\n");
1352 }
1353 status=U_ILLEGAL_ARGUMENT_ERROR;
1354 teFillin2=ures_getByIndex(teFillin, 0, teFillin2, &status);
1355 if(teFillin2 != NULL){
1356 log_err("ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1357 }
1358 /*Test ures_getByIndex with UResourceBundle = NULL */
1359 status=U_ZERO_ERROR;
1360 teFillin2=ures_getByIndex(NULL, 0, teFillin2, &status);
1361 if(status != U_ILLEGAL_ARGUMENT_ERROR){
1362 log_err("ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1363 myErrorName(status));
1364 }
1365 /*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/
1366 status=U_ZERO_ERROR;
1367 teFillin=ures_getByKey(teRes, "array_only_in_te", teFillin, &status);
1368 status=U_ILLEGAL_ARGUMENT_ERROR;
1369 value=(UChar*)ures_getStringByIndex(teFillin, 0, &len, &status);
1370 if( value != NULL){
1371 log_err("ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1372 }
1373 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1374 status=U_ZERO_ERROR;
1375 value=(UChar*)ures_getStringByIndex(NULL, 0, &len, &status);
1376 if(value != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){
1377 log_err("ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1378 myErrorName(status));
1379 }
1380 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1381 status=U_ZERO_ERROR;
1382 value=(UChar*)ures_getStringByIndex(teFillin, 9999, &len, &status);
1383 if(value != NULL || status != U_MISSING_RESOURCE_ERROR){
1384 log_err("ERROR: ures_getStringByIndex() with index that is too big is supposed to fail\n Expected: U_MISSING_RESOURCE_ERROR, Got: %s\n",
1385 myErrorName(status));
1386 }
1387 /*Test ures_getInt() where UResourceBundle = NULL */
1388 status=U_ZERO_ERROR;
1389 if(ures_getInt(NULL, &status) != -1 && status != U_ILLEGAL_ARGUMENT_ERROR){
1390 log_err("ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s\n",
1391 myErrorName(status));
1392 }
1393 /*Test ures_getInt() where status != U_ZERO_ERROR */
1394 if(ures_getInt(teRes, &status) != -1){
1395 log_err("ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail\n");
1396 }
1397
1398 ures_close(teFillin);
1399 ures_close(teFillin2);
1400 ures_close(coll);
1401 ures_close(binColl);
1402 ures_close(teRes);
1403 free(utestdatapath);
1404
1405
1406 }
1407
TestGetVersion()1408 static void TestGetVersion(){
1409 UVersionInfo minVersionArray = {0x01, 0x00, 0x00, 0x00};
1410 UVersionInfo maxVersionArray = {0x50, 0xff, 0xcf, 0xcf};
1411 UVersionInfo versionArray;
1412 UErrorCode status= U_ZERO_ERROR;
1413 UResourceBundle* resB = NULL;
1414 int i=0, j = 0;
1415 int locCount = uloc_countAvailable();
1416 const char *locName = "root";
1417
1418 log_verbose("The ures_getVersion tests begin : \n");
1419
1420 for(j = -1; j < locCount; j++) {
1421 if(j >= 0) {
1422 locName = uloc_getAvailable(j);
1423 }
1424 log_verbose("Testing version number for locale %s\n", locName);
1425 resB = ures_open(NULL,locName, &status);
1426 if (U_FAILURE(status)) {
1427 log_err_status(status, "Resource bundle creation for locale %s failed.: %s\n", locName, myErrorName(status));
1428 ures_close(resB);
1429 return;
1430 }
1431 ures_getVersion(resB, versionArray);
1432 for (i=0; i<4; ++i) {
1433 if (versionArray[i] < minVersionArray[i] ||
1434 versionArray[i] > maxVersionArray[i])
1435 {
1436 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1437 locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
1438 break;
1439 }
1440 }
1441 ures_close(resB);
1442 }
1443 }
1444
1445
TestGetVersionColl()1446 static void TestGetVersionColl(){
1447 #if !UCONFIG_NO_COLLATION
1448 UVersionInfo minVersionArray = {0x00, 0x00, 0x00, 0x00};
1449 UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf};
1450 UVersionInfo versionArray;
1451 UErrorCode status= U_ZERO_ERROR;
1452 UResourceBundle* resB = NULL;
1453 UEnumeration *locs= NULL;
1454 int i=0;
1455 const char *locName = "root";
1456 int32_t locLen;
1457 const UChar* rules =NULL;
1458 int32_t len = 0;
1459
1460 /* test NUL termination of UCARules */
1461 resB = ures_open(U_ICUDATA_COLL,locName, &status);
1462 rules = tres_getString(resB,-1,"UCARules",&len, &status);
1463 if(!rules || U_FAILURE(status)) {
1464 log_data_err("Could not load UCARules for locale %s\n", locName);
1465 status = U_ZERO_ERROR;
1466 } else if(u_strlen(rules) != len){
1467 log_err("UCARules string not nul terminated! \n");
1468 }
1469 ures_close(resB);
1470
1471 log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL);
1472 locs = ures_openAvailableLocales(U_ICUDATA_COLL, &status);
1473 if (U_FAILURE(status)) {
1474 log_err_status(status, "enumeration of %s failed.: %s\n", U_ICUDATA_COLL, myErrorName(status));
1475 return;
1476 }
1477
1478 for (;;) {
1479 log_verbose("Testing version number for locale %s\n", locName);
1480 resB = ures_open(U_ICUDATA_COLL,locName, &status);
1481 if (U_FAILURE(status)) {
1482 log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL, locName, myErrorName(status));
1483 ures_close(resB);
1484 break;
1485 }
1486 ures_getVersion(resB, versionArray);
1487 for (i=0; i<4; ++i) {
1488 if (versionArray[i] < minVersionArray[i] ||
1489 versionArray[i] > maxVersionArray[i])
1490 {
1491 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1492 locName, versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
1493 break;
1494 }
1495 }
1496 ures_close(resB);
1497 locName = uenum_next(locs, &locLen, &status);
1498 if(U_FAILURE(status)) {
1499 log_err("uenum_next(locs) error %s\n", u_errorName(status));
1500 break;
1501 }
1502 if(locName == NULL) {
1503 break;
1504 }
1505 }
1506 uenum_close(locs);
1507 #endif /* !UCONFIG_NO_COLLATION */
1508 }
1509
TestResourceBundles()1510 static void TestResourceBundles()
1511 {
1512 // The test expectation only works if the default locale is not one of the
1513 // locale bundle in the testdata which have those info. Therefore, we skip
1514 // the test if the default locale is te, sh, mc, or them with subtags.
1515 if ( uprv_strncmp(uloc_getDefault(), "te", 2) == 0 ||
1516 uprv_strncmp(uloc_getDefault(), "sh", 2) == 0 ||
1517 uprv_strncmp(uloc_getDefault(), "mc", 2) == 0) {
1518 return;
1519 }
1520
1521 UErrorCode status = U_ZERO_ERROR;
1522 loadTestData(&status);
1523 if(U_FAILURE(status)) {
1524 log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status));
1525 return;
1526 }
1527
1528 testTag("only_in_Root", TRUE, FALSE, FALSE);
1529 testTag("in_Root_te", TRUE, TRUE, FALSE);
1530 testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE);
1531 testTag("in_Root_te_IN", TRUE, FALSE, TRUE);
1532 testTag("only_in_te", FALSE, TRUE, FALSE);
1533 testTag("only_in_te_IN", FALSE, FALSE, TRUE);
1534 testTag("in_te_te_IN", FALSE, TRUE, TRUE);
1535 testTag("nonexistent", FALSE, FALSE, FALSE);
1536
1537 log_verbose("Passed:= %d Failed= %d \n", pass, fail);
1538
1539 }
1540
1541
TestConstruction1()1542 static void TestConstruction1()
1543 {
1544 // The test expectation only works if the default locale is not one of the
1545 // locale bundle in the testdata which have those info. Therefore, we skip
1546 // the test if the default locale is te, sh, mc, or them with subtags.
1547 if ( uprv_strncmp(uloc_getDefault(), "te", 2) == 0 ||
1548 uprv_strncmp(uloc_getDefault(), "sh", 2) == 0 ||
1549 uprv_strncmp(uloc_getDefault(), "mc", 2) == 0) {
1550 return;
1551 }
1552
1553 UResourceBundle *test1 = 0, *test2 = 0,*empty = 0;
1554 const UChar *result1, *result2;
1555 UErrorCode status= U_ZERO_ERROR;
1556 UErrorCode err = U_ZERO_ERROR;
1557 const char* locale="te_IN";
1558 const char* testdatapath;
1559
1560 int32_t len1=0;
1561 int32_t len2=0;
1562 UVersionInfo versionInfo;
1563 char versionString[256];
1564 char verboseOutput[256];
1565
1566 U_STRING_DECL(rootVal, "ROOT", 4);
1567 U_STRING_DECL(te_inVal, "TE_IN", 5);
1568
1569 U_STRING_INIT(rootVal, "ROOT", 4);
1570 U_STRING_INIT(te_inVal, "TE_IN", 5);
1571
1572 testdatapath=loadTestData(&status);
1573 if(U_FAILURE(status))
1574 {
1575 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
1576 return;
1577 }
1578
1579 log_verbose("Testing ures_open()......\n");
1580
1581 empty = ures_open(testdatapath, "testempty", &status);
1582 if(empty == NULL || U_FAILURE(status)) {
1583 log_err("opening empty failed!\n");
1584 }
1585 ures_close(empty);
1586
1587 test1=ures_open(testdatapath, NULL, &err);
1588
1589 if(U_FAILURE(err))
1590 {
1591 log_err("construction of NULL did not succeed : %s \n", myErrorName(status));
1592 return;
1593 }
1594 test2=ures_open(testdatapath, locale, &err);
1595 if(U_FAILURE(err))
1596 {
1597 log_err("construction of %s did not succeed : %s \n", locale, myErrorName(status));
1598 return;
1599 }
1600 result1= tres_getString(test1, -1, "string_in_Root_te_te_IN", &len1, &err);
1601 result2= tres_getString(test2, -1, "string_in_Root_te_te_IN", &len2, &err);
1602 if (U_FAILURE(err) || len1==0 || len2==0) {
1603 log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status));
1604 return;
1605 }
1606 log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput, result1));
1607 log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput, result2));
1608 if(u_strcmp(result1, rootVal) !=0 || u_strcmp(result2, te_inVal) !=0 ){
1609 log_err("construction test failed. Run Verbose for more information");
1610 }
1611
1612
1613 /* Test getVersionNumber*/
1614 log_verbose("Testing version number\n");
1615 log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1));
1616
1617 log_verbose("Testing version \n");
1618 ures_getVersion(test1, versionInfo);
1619 u_versionToString(versionInfo, versionString);
1620
1621 log_verbose("for getVersion : %s\n", versionString);
1622
1623 if(strcmp(versionString, ures_getVersionNumber(test1)) != 0) {
1624 log_err("Versions differ: %s vs %s\n", versionString, ures_getVersionNumber(test1));
1625 }
1626
1627 ures_close(test1);
1628 ures_close(test2);
1629
1630 }
1631
1632 /*****************************************************************************/
1633 /*****************************************************************************/
1634
testTag(const char * frag,UBool in_Root,UBool in_te,UBool in_te_IN)1635 static UBool testTag(const char* frag,
1636 UBool in_Root,
1637 UBool in_te,
1638 UBool in_te_IN)
1639 {
1640 int32_t failNum = fail;
1641
1642 /* Make array from input params */
1643
1644 UBool is_in[3];
1645 const char *NAME[] = { "ROOT", "TE", "TE_IN" };
1646
1647 /* Now try to load the desired items */
1648 UResourceBundle* theBundle = NULL;
1649 char tag[99];
1650 char action[256];
1651 UErrorCode expected_status,status = U_ZERO_ERROR,expected_resource_status = U_ZERO_ERROR;
1652 UChar* base = NULL;
1653 UChar* expected_string = NULL;
1654 const UChar* string = NULL;
1655 char buf[5];
1656 char item_tag[10];
1657 int32_t i,j,row,col, len;
1658 int32_t actual_bundle;
1659 int32_t count = 0;
1660 int32_t row_count=0;
1661 int32_t column_count=0;
1662 int32_t idx = 0;
1663 int32_t tag_count= 0;
1664 const char* testdatapath;
1665 char verboseOutput[256];
1666 UResourceBundle* array=NULL;
1667 UResourceBundle* array2d=NULL;
1668 UResourceBundle* tags=NULL;
1669 UResourceBundle* arrayItem1=NULL;
1670
1671 testdatapath = loadTestData(&status);
1672 if(U_FAILURE(status))
1673 {
1674 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
1675 return FALSE;
1676 }
1677
1678 is_in[0] = in_Root;
1679 is_in[1] = in_te;
1680 is_in[2] = in_te_IN;
1681
1682 strcpy(item_tag, "tag");
1683
1684 for (i=0; i<bundles_count; ++i)
1685 {
1686 strcpy(action,"construction for ");
1687 strcat(action, param[i].name);
1688
1689
1690 status = U_ZERO_ERROR;
1691
1692 theBundle = ures_open(testdatapath, param[i].name, &status);
1693 CONFIRM_ErrorCode(status,param[i].expected_constructor_status);
1694
1695 if(i == 5)
1696 actual_bundle = 0; /* ne -> default */
1697 else if(i == 3)
1698 actual_bundle = 1; /* te_NE -> te */
1699 else if(i == 4)
1700 actual_bundle = 2; /* te_IN_NE -> te_IN */
1701 else
1702 actual_bundle = i;
1703
1704 expected_resource_status = U_MISSING_RESOURCE_ERROR;
1705 for (j=e_te_IN; j>=e_Root; --j)
1706 {
1707 if (is_in[j] && param[i].inherits[j])
1708 {
1709
1710 if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
1711 expected_resource_status = U_ZERO_ERROR;
1712 else if(j == 0)
1713 expected_resource_status = U_USING_DEFAULT_WARNING;
1714 else
1715 expected_resource_status = U_USING_FALLBACK_WARNING;
1716
1717 log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n",
1718 param[i].name,
1719 i,
1720 frag,
1721 j,
1722 is_in[j]?"Yes":"No",
1723 j,
1724 param[i].inherits[j]?"Yes":"No",
1725 param[actual_bundle].name);
1726
1727 break;
1728 }
1729 }
1730
1731 for (j=param[i].where; j>=0; --j)
1732 {
1733 if (is_in[j])
1734 {
1735 if(base != NULL) {
1736 free(base);
1737 base = NULL;
1738 }
1739 base=(UChar*)malloc(sizeof(UChar)*(strlen(NAME[j]) + 1));
1740 u_uastrcpy(base,NAME[j]);
1741
1742 break;
1743 }
1744 else {
1745 if(base != NULL) {
1746 free(base);
1747 base = NULL;
1748 }
1749 base = (UChar*) malloc(sizeof(UChar) * 1);
1750 *base = 0x0000;
1751 }
1752 }
1753
1754 /*----string---------------------------------------------------------------- */
1755
1756 strcpy(tag,"string_");
1757 strcat(tag,frag);
1758
1759 strcpy(action,param[i].name);
1760 strcat(action, ".ures_getStringByKey(" );
1761 strcat(action,tag);
1762 strcat(action, ")");
1763
1764
1765 status = U_ZERO_ERROR;
1766 len=0;
1767
1768 string=tres_getString(theBundle, -1, tag, &len, &status);
1769 if(U_SUCCESS(status)) {
1770 expected_string=(UChar*)malloc(sizeof(UChar)*(u_strlen(base) + 4));
1771 u_strcpy(expected_string,base);
1772 CONFIRM_INT_EQ(len, u_strlen(expected_string));
1773 }else{
1774 expected_string = (UChar*)malloc(sizeof(UChar)*(u_strlen(kERROR) + 1));
1775 u_strcpy(expected_string,kERROR);
1776 string=kERROR;
1777 }
1778 log_verbose("%s got %d, expected %d\n", action, status, expected_resource_status);
1779
1780 CONFIRM_ErrorCode(status, expected_resource_status);
1781 CONFIRM_EQ(string, expected_string);
1782
1783
1784
1785 /*--------------array------------------------------------------------- */
1786
1787 strcpy(tag,"array_");
1788 strcat(tag,frag);
1789
1790 strcpy(action,param[i].name);
1791 strcat(action, ".ures_getByKey(" );
1792 strcat(action,tag);
1793 strcat(action, ")");
1794
1795 len=0;
1796
1797 count = kERROR_COUNT;
1798 status = U_ZERO_ERROR;
1799 array=ures_getByKey(theBundle, tag, array, &status);
1800 CONFIRM_ErrorCode(status,expected_resource_status);
1801 if (U_SUCCESS(status)) {
1802 /*confirm the resource type is an array*/
1803 CONFIRM_INT_EQ(ures_getType(array), URES_ARRAY);
1804 /*confirm the size*/
1805 count=ures_getSize(array);
1806 CONFIRM_INT_GE(count,1);
1807 for (j=0; j<count; ++j) {
1808 UChar element[3];
1809 u_strcpy(expected_string, base);
1810 u_uastrcpy(element, itoa1(j,buf));
1811 u_strcat(expected_string, element);
1812 arrayItem1=ures_getNextResource(array, arrayItem1, &status);
1813 if(U_SUCCESS(status)){
1814 CONFIRM_EQ(tres_getString(arrayItem1, -1, NULL, &len, &status),expected_string);
1815 }
1816 }
1817
1818 }
1819 else {
1820 CONFIRM_INT_EQ(count,kERROR_COUNT);
1821 CONFIRM_ErrorCode(status, U_MISSING_RESOURCE_ERROR);
1822 /*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/
1823 count = 0;
1824 }
1825
1826 /*--------------arrayItem------------------------------------------------- */
1827
1828 strcpy(tag,"array_");
1829 strcat(tag,frag);
1830
1831 strcpy(action,param[i].name);
1832 strcat(action, ".ures_getStringByIndex(");
1833 strcat(action, tag);
1834 strcat(action, ")");
1835
1836
1837 for (j=0; j<10; ++j){
1838 idx = count ? (randi(count * 3) - count) : (randi(200) - 100);
1839 status = U_ZERO_ERROR;
1840 string=kERROR;
1841 array=ures_getByKey(theBundle, tag, array, &status);
1842 if(!U_FAILURE(status)){
1843 UChar *t=NULL;
1844 t=(UChar*)ures_getStringByIndex(array, idx, &len, &status);
1845 if(!U_FAILURE(status)){
1846 UChar element[3];
1847 string=t;
1848 u_strcpy(expected_string, base);
1849 u_uastrcpy(element, itoa1(idx,buf));
1850 u_strcat(expected_string, element);
1851 } else {
1852 u_strcpy(expected_string, kERROR);
1853 }
1854
1855 }
1856 expected_status = (idx >= 0 && idx < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR;
1857 CONFIRM_ErrorCode(status,expected_status);
1858 CONFIRM_EQ(string,expected_string);
1859
1860 }
1861
1862
1863 /*--------------2dArray------------------------------------------------- */
1864
1865 strcpy(tag,"array_2d_");
1866 strcat(tag,frag);
1867
1868 strcpy(action,param[i].name);
1869 strcat(action, ".ures_getByKey(" );
1870 strcat(action,tag);
1871 strcat(action, ")");
1872
1873
1874
1875 row_count = kERROR_COUNT, column_count = kERROR_COUNT;
1876 status = U_ZERO_ERROR;
1877 array2d=ures_getByKey(theBundle, tag, array2d, &status);
1878
1879 CONFIRM_ErrorCode(status,expected_resource_status);
1880 if (U_SUCCESS(status))
1881 {
1882 /*confirm the resource type is an 2darray*/
1883 CONFIRM_INT_EQ(ures_getType(array2d), URES_ARRAY);
1884 row_count=ures_getSize(array2d);
1885 CONFIRM_INT_GE(row_count,1);
1886
1887 for(row=0; row<row_count; ++row){
1888 UResourceBundle *tableRow=NULL;
1889 tableRow=ures_getByIndex(array2d, row, tableRow, &status);
1890 CONFIRM_ErrorCode(status, expected_resource_status);
1891 if(U_SUCCESS(status)){
1892 /*confirm the resourcetype of each table row is an array*/
1893 CONFIRM_INT_EQ(ures_getType(tableRow), URES_ARRAY);
1894 column_count=ures_getSize(tableRow);
1895 CONFIRM_INT_GE(column_count,1);
1896
1897 for (col=0; j<column_count; ++j) {
1898 UChar element[3];
1899 u_strcpy(expected_string, base);
1900 u_uastrcpy(element, itoa1(row, buf));
1901 u_strcat(expected_string, element);
1902 u_uastrcpy(element, itoa1(col, buf));
1903 u_strcat(expected_string, element);
1904 arrayItem1=ures_getNextResource(tableRow, arrayItem1, &status);
1905 if(U_SUCCESS(status)){
1906 const UChar *stringValue=tres_getString(arrayItem1, -1, NULL, &len, &status);
1907 CONFIRM_EQ(stringValue, expected_string);
1908 }
1909 }
1910 }
1911 ures_close(tableRow);
1912 }
1913 }else{
1914 CONFIRM_INT_EQ(row_count,kERROR_COUNT);
1915 CONFIRM_INT_EQ(column_count,kERROR_COUNT);
1916 row_count=column_count=0;
1917 }
1918
1919
1920 /*------2dArrayItem-------------------------------------------------------------- */
1921 /* 2dArrayItem*/
1922 for (j=0; j<10; ++j)
1923 {
1924 row = row_count ? (randi(row_count * 3) - row_count) : (randi(200) - 100);
1925 col = column_count ? (randi(column_count * 3) - column_count) : (randi(200) - 100);
1926 status = U_ZERO_ERROR;
1927 string = kERROR;
1928 len=0;
1929 array2d=ures_getByKey(theBundle, tag, array2d, &status);
1930 if(U_SUCCESS(status)){
1931 UResourceBundle *tableRow=NULL;
1932 tableRow=ures_getByIndex(array2d, row, tableRow, &status);
1933 if(U_SUCCESS(status)) {
1934 UChar *t=NULL;
1935 t=(UChar*)ures_getStringByIndex(tableRow, col, &len, &status);
1936 if(U_SUCCESS(status)){
1937 string=t;
1938 }
1939 }
1940 ures_close(tableRow);
1941 }
1942 expected_status = (row >= 0 && row < row_count && col >= 0 && col < column_count) ?
1943 expected_resource_status: U_MISSING_RESOURCE_ERROR;
1944 CONFIRM_ErrorCode(status,expected_status);
1945
1946 if (U_SUCCESS(status)){
1947 UChar element[3];
1948 u_strcpy(expected_string, base);
1949 u_uastrcpy(element, itoa1(row, buf));
1950 u_strcat(expected_string, element);
1951 u_uastrcpy(element, itoa1(col, buf));
1952 u_strcat(expected_string, element);
1953 } else {
1954 u_strcpy(expected_string,kERROR);
1955 }
1956 CONFIRM_EQ(string,expected_string);
1957
1958 }
1959
1960
1961 /*--------------taggedArray----------------------------------------------- */
1962 strcpy(tag,"tagged_array_");
1963 strcat(tag,frag);
1964
1965 strcpy(action,param[i].name);
1966 strcat(action,".ures_getByKey(");
1967 strcat(action, tag);
1968 strcat(action,")");
1969
1970
1971 status = U_ZERO_ERROR;
1972 tag_count=0;
1973 tags=ures_getByKey(theBundle, tag, tags, &status);
1974 CONFIRM_ErrorCode(status, expected_resource_status);
1975 if (U_SUCCESS(status)) {
1976 UResType bundleType=ures_getType(tags);
1977 CONFIRM_INT_EQ(bundleType, URES_TABLE);
1978
1979 tag_count=ures_getSize(tags);
1980 CONFIRM_INT_GE((int32_t)tag_count, (int32_t)0);
1981
1982 for(idx=0; idx <tag_count; idx++){
1983 UResourceBundle *tagelement=NULL;
1984 const char *key=NULL;
1985 UChar* value=NULL;
1986 tagelement=ures_getByIndex(tags, idx, tagelement, &status);
1987 key=ures_getKey(tagelement);
1988 value=(UChar*)ures_getNextString(tagelement, &len, &key, &status);
1989 log_verbose("tag = %s, value = %s\n", key, u_austrcpy(verboseOutput, value));
1990 if(strncmp(key, "tag", 3) == 0 && u_strncmp(value, base, u_strlen(base)) == 0){
1991 record_pass();
1992 }else{
1993 record_fail();
1994 }
1995 ures_close(tagelement);
1996 }
1997 }else{
1998 tag_count=0;
1999 }
2000
2001 /*---------taggedArrayItem----------------------------------------------*/
2002 count = 0;
2003 for (idx=-20; idx<20; ++idx)
2004 {
2005
2006 status = U_ZERO_ERROR;
2007 string = kERROR;
2008 strcpy(item_tag, "tag");
2009 strcat(item_tag, itoa1(idx,buf));
2010 tags=ures_getByKey(theBundle, tag, tags, &status);
2011 if(U_SUCCESS(status)){
2012 UResourceBundle *tagelement=NULL;
2013 UChar *t=NULL;
2014 tagelement=ures_getByKey(tags, item_tag, tagelement, &status);
2015 if(!U_FAILURE(status)){
2016 UResType elementType=ures_getType(tagelement);
2017 CONFIRM_INT_EQ(elementType, URES_STRING);
2018 if(strcmp(ures_getKey(tagelement), item_tag) == 0){
2019 record_pass();
2020 }else{
2021 record_fail();
2022 }
2023 t=(UChar*)tres_getString(tagelement, -1, NULL, &len, &status);
2024 if(!U_FAILURE(status)){
2025 string=t;
2026 }
2027 }
2028 if (idx < 0) {
2029 CONFIRM_ErrorCode(status,U_MISSING_RESOURCE_ERROR);
2030 }
2031 else{
2032 if (status != U_MISSING_RESOURCE_ERROR) {
2033 UChar element[3];
2034 u_strcpy(expected_string, base);
2035 u_uastrcpy(element, itoa1(idx,buf));
2036 u_strcat(expected_string, element);
2037 CONFIRM_EQ(string,expected_string);
2038 count++;
2039 }
2040 }
2041 ures_close(tagelement);
2042 }
2043 }
2044 CONFIRM_INT_EQ(count, tag_count);
2045
2046 free(expected_string);
2047 ures_close(theBundle);
2048 }
2049 ures_close(array);
2050 ures_close(array2d);
2051 ures_close(tags);
2052 ures_close(arrayItem1);
2053 free(base);
2054 return (UBool)(failNum == fail);
2055 }
2056
record_pass()2057 static void record_pass()
2058 {
2059 ++pass;
2060 }
2061
record_fail()2062 static void record_fail()
2063 {
2064 ++fail;
2065 }
2066
TestPreventFallback()2067 static void TestPreventFallback() {
2068 UResourceBundle* theBundle = NULL;
2069 const char* testdatapath;
2070 UErrorCode status = U_ZERO_ERROR;
2071 int32_t unused_len = 0;
2072
2073 testdatapath=loadTestData(&status);
2074 if(U_FAILURE(status))
2075 {
2076 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
2077 return;
2078 }
2079
2080 // In te_IN locale, fallback of string_in_te_no_te_IN_fallback is blocked
2081 // with the three empty-set (U+2205) chars.
2082 theBundle = ures_open(testdatapath, "te_IN_NE", &status);
2083 if(U_FAILURE(status))
2084 {
2085 log_data_err("Could not open resource bundle te_IN_NE %s \n",myErrorName(status));
2086 return;
2087 }
2088
2089 // Fallback is blocked
2090 ures_getStringByKeyWithFallback(theBundle, "string_in_te_no_te_IN_fallback", &unused_len, &status);
2091 if (status != U_MISSING_RESOURCE_ERROR)
2092 {
2093 log_err("Expected missing resource error for string_in_te_no_te_IN_fallback.");
2094 }
2095 status = U_ZERO_ERROR;
2096
2097 // This fallback should succeed
2098 ures_getStringByKeyWithFallback(theBundle, "string_only_in_te", &unused_len, &status);
2099 if(U_FAILURE(status))
2100 {
2101 log_err("Expected to find string_only_in_te %s \n",myErrorName(status));
2102 }
2103 status = U_ZERO_ERROR;
2104 ures_close(theBundle);
2105
2106 // From te locale, we should be able to fetch string_in_te_no_te_IN_fallback.
2107 theBundle = ures_open(testdatapath, "te", &status);
2108 if(U_FAILURE(status))
2109 {
2110 log_data_err("Could not open resource bundle te_IN_NE %s \n",myErrorName(status));
2111 return;
2112 }
2113 ures_getStringByKeyWithFallback(theBundle, "string_in_te_no_te_IN_fallback", &unused_len, &status);
2114 if(U_FAILURE(status))
2115 {
2116 log_err("Expected to find string_in_te_no_te_IN_fallback %s \n",myErrorName(status));
2117 }
2118 status = U_ZERO_ERROR;
2119 ures_close(theBundle);
2120 }
2121
2122 /**
2123 * Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR
2124 * are set correctly
2125 */
2126
TestFallback()2127 static void TestFallback()
2128 {
2129 UErrorCode status = U_ZERO_ERROR;
2130 UResourceBundle *fr_FR = NULL;
2131 UResourceBundle *subResource = NULL;
2132 const UChar *junk; /* ignored */
2133 int32_t resultLen;
2134
2135 log_verbose("Opening fr_FR..");
2136 fr_FR = ures_open(NULL, "fr_FR", &status);
2137 if(U_FAILURE(status))
2138 {
2139 log_err_status(status, "Couldn't open fr_FR - %s\n", u_errorName(status));
2140 return;
2141 }
2142
2143 status = U_ZERO_ERROR;
2144
2145
2146 /* clear it out.. just do some calls to get the gears turning */
2147 junk = tres_getString(fr_FR, -1, "LocaleID", &resultLen, &status);
2148 status = U_ZERO_ERROR;
2149 junk = tres_getString(fr_FR, -1, "LocaleString", &resultLen, &status);
2150 status = U_ZERO_ERROR;
2151 junk = tres_getString(fr_FR, -1, "LocaleID", &resultLen, &status);
2152 status = U_ZERO_ERROR;
2153 (void)junk; /* Suppress set but not used warning. */
2154
2155 /* OK first one. This should be a Default value. */
2156 subResource = ures_getByKey(fr_FR, "layout", NULL, &status);
2157 if(status != U_USING_DEFAULT_WARNING)
2158 {
2159 log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get layout from fr_FR, got %s\n",
2160 u_errorName(status));
2161 }
2162
2163 status = U_ZERO_ERROR;
2164 ures_close(subResource);
2165
2166 /* and this is a Fallback, to fr */
2167 junk = tres_getString(fr_FR, -1, "ExemplarCharacters", &resultLen, &status);
2168 if(status != U_USING_FALLBACK_WARNING)
2169 {
2170 log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get ExemplarCharacters from fr_FR, got %d\n",
2171 status);
2172 }
2173
2174 status = U_ZERO_ERROR;
2175
2176 ures_close(fr_FR);
2177 /* Temporary hack err actually should be U_USING_FALLBACK_ERROR */
2178 /* Test Jitterbug 552 fallback mechanism of aliased data */
2179 {
2180 UErrorCode err =U_ZERO_ERROR;
2181 UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err);
2182 UResourceBundle* resLocID = ures_getByKey(myResB, "Version", NULL, &err);
2183 const UChar* version = NULL;
2184 static const UChar versionStr[] = u"38.1"; // 38.1 in nn_NO or in a parent bundle/root
2185
2186 if(U_FAILURE(err)) {
2187 log_data_err("Expected success when trying to test no_NO_NY aliased to nn_NO for Version "
2188 "err=%s\n",
2189 u_errorName(err));
2190 return;
2191 }
2192 version = tres_getString(resLocID, -1, NULL, &resultLen, &err);
2193 if(u_strcmp(version, versionStr) != 0){
2194 char x[100];
2195 char g[100];
2196 u_austrcpy(x, versionStr);
2197 u_austrcpy(g, version);
2198 log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected "
2199 "version value. Expected '%s', but got '%s'\n",
2200 x, g);
2201 }
2202 UResourceBundle* zoneResource = ures_open(U_ICUDATA_ZONE, "no_NO_NY", &err);
2203 UResourceBundle* tResB = ures_getByKey(zoneResource, "zoneStrings", NULL, &err);
2204 if(err != U_USING_FALLBACK_WARNING){
2205 log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for zoneStrings err=%s\n",u_errorName(err));
2206 }
2207 ures_close(tResB);
2208 ures_close(zoneResource);
2209 ures_close(resLocID);
2210 ures_close(myResB);
2211 }
2212
2213 }
2214
2215 /* static void printUChars(UChar* uchars){
2216 / int16_t i=0;
2217 / for(i=0; i<u_strlen(uchars); i++){
2218 / log_err("%04X ", *(uchars+i));
2219 / }
2220 / } */
2221
TestResourceLevelAliasing(void)2222 static void TestResourceLevelAliasing(void) {
2223 UErrorCode status = U_ZERO_ERROR;
2224 UResourceBundle *aliasB = NULL, *tb = NULL;
2225 UResourceBundle *en = NULL, *uk = NULL, *testtypes = NULL;
2226 const char* testdatapath = NULL;
2227 const UChar *string = NULL, *sequence = NULL;
2228 /*const uint8_t *binary = NULL, *binSequence = NULL;*/
2229 int32_t strLen = 0, seqLen = 0;/*, binLen = 0, binSeqLen = 0;*/
2230 char buffer[100];
2231 char *s;
2232
2233 testdatapath=loadTestData(&status);
2234 if(U_FAILURE(status))
2235 {
2236 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
2237 return;
2238 }
2239
2240 aliasB = ures_open(testdatapath, "testaliases", &status);
2241
2242 if(U_FAILURE(status))
2243 {
2244 log_data_err("Could not load testaliases.res %s \n",myErrorName(status));
2245 return;
2246 }
2247 /* this should fail - circular alias */
2248 tb = ures_getByKey(aliasB, "aaa", tb, &status);
2249 if(status != U_TOO_MANY_ALIASES_ERROR) {
2250 log_err("Failed to detect circular alias\n");
2251 }
2252 else {
2253 status = U_ZERO_ERROR;
2254 }
2255 tb = ures_getByKey(aliasB, "aab", tb, &status);
2256 if(status != U_TOO_MANY_ALIASES_ERROR) {
2257 log_err("Failed to detect circular alias\n");
2258 } else {
2259 status = U_ZERO_ERROR;
2260 }
2261 if(U_FAILURE(status) ) {
2262 log_data_err("err loading tb resource\n");
2263 } else {
2264 /* testing aliasing to a non existing resource */
2265 tb = ures_getByKey(aliasB, "nonexisting", tb, &status);
2266 if(status != U_MISSING_RESOURCE_ERROR) {
2267 log_err("Managed to find an alias to non-existing resource\n");
2268 } else {
2269 status = U_ZERO_ERROR;
2270 }
2271 /* testing referencing/composed alias */
2272 uk = ures_findResource("ja/calendar/gregorian/DateTimePatterns/2", uk, &status);
2273 if((uk == NULL) || U_FAILURE(status)) {
2274 log_err_status(status, "Couldn't findResource('ja/calendar/gregorian/DateTimePatterns/2') err %s\n", u_errorName(status));
2275 goto cleanup;
2276 }
2277
2278 sequence = tres_getString(uk, -1, NULL, &seqLen, &status);
2279
2280 tb = ures_getByKey(aliasB, "referencingalias", tb, &status);
2281 string = tres_getString(tb, -1, NULL, &strLen, &status);
2282
2283 if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
2284 log_err("Referencing alias didn't get the right string (1)\n");
2285 }
2286
2287 string = tres_getString(aliasB, -1, "referencingalias", &strLen, &status);
2288 if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
2289 log_err("Referencing alias didn't get the right string (2)\n");
2290 }
2291
2292 checkStatus(__LINE__, U_ZERO_ERROR, status);
2293 tb = ures_getByKey(aliasB, "DateTimePatterns", tb, &status);
2294 checkStatus(__LINE__, U_ZERO_ERROR, status);
2295 tb = ures_getByIndex(tb, 2, tb, &status);
2296 checkStatus(__LINE__, U_ZERO_ERROR, status);
2297 string = tres_getString(tb, -1, NULL, &strLen, &status);
2298 checkStatus(__LINE__, U_ZERO_ERROR, status);
2299
2300 if(U_FAILURE(status)) {
2301 log_err("%s trying to get string via separate getters\n", u_errorName(status));
2302 } else if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
2303 log_err("Referencing alias didn't get the right string (3)\n");
2304 }
2305
2306 /* simple alias */
2307 testtypes = ures_open(testdatapath, "testtypes", &status);
2308 strcpy(buffer, "menu/file/open");
2309 s = buffer;
2310 uk = ures_findSubResource(testtypes, s, uk, &status);
2311 sequence = tres_getString(uk, -1, NULL, &seqLen, &status);
2312
2313 tb = ures_getByKey(aliasB, "simplealias", tb, &status);
2314 string = tres_getString(tb, -1, NULL, &strLen, &status);
2315
2316 if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
2317 log_err("Referencing alias didn't get the right string (4)\n");
2318 }
2319
2320 /* test indexed aliasing */
2321
2322 tb = ures_getByKey(aliasB, "zoneTests", tb, &status);
2323 tb = ures_getByKey(tb, "zoneAlias2", tb, &status);
2324 string = tres_getString(tb, -1, NULL, &strLen, &status);
2325
2326 en = ures_findResource("/ICUDATA-zone/en/zoneStrings/3/0", en, &status);
2327 sequence = tres_getString(en, -1, NULL, &seqLen, &status);
2328
2329 if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
2330 log_err("Referencing alias didn't get the right string (5)\n");
2331 }
2332 }
2333 /* test getting aliased string by index */
2334 {
2335 const char* keys[] = {
2336 "KeyAlias0PST",
2337 "KeyAlias1PacificStandardTime",
2338 "KeyAlias2PDT",
2339 "KeyAlias3LosAngeles"
2340 };
2341
2342 const char* strings[] = {
2343 "America/Los_Angeles",
2344 "Pacific Standard Time",
2345 "PDT",
2346 "Los Angeles",
2347 };
2348 UChar uBuffer[256];
2349 const UChar* result;
2350 int32_t uBufferLen = 0, resultLen = 0;
2351 int32_t i = 0;
2352 const char *key = NULL;
2353 tb = ures_getByKey(aliasB, "testGetStringByKeyAliasing", tb, &status);
2354 if(U_FAILURE(status)) {
2355 log_err("FAIL: Couldn't get testGetStringByKeyAliasing resource: %s\n", u_errorName(status));
2356 } else {
2357 for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
2358 result = tres_getString(tb, -1, keys[i], &resultLen, &status);
2359 if(U_FAILURE(status)){
2360 log_err("(1) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
2361 continue;
2362 }
2363 uBufferLen = u_unescape(strings[i], uBuffer, 256);
2364 if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
2365 log_err("(1) Didn't get correct string while accessing alias table by key (%s)\n", keys[i]);
2366 }
2367 }
2368 for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
2369 result = tres_getString(tb, i, NULL, &resultLen, &status);
2370 if(U_FAILURE(status)){
2371 log_err("(2) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
2372 continue;
2373 }
2374 uBufferLen = u_unescape(strings[i], uBuffer, 256);
2375 if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
2376 log_err("(2) Didn't get correct string while accesing alias table by index (%s)\n", strings[i]);
2377 }
2378 }
2379 for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
2380 result = ures_getNextString(tb, &resultLen, &key, &status);
2381 if(U_FAILURE(status)){
2382 log_err("(3) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
2383 continue;
2384 }
2385 uBufferLen = u_unescape(strings[i], uBuffer, 256);
2386 if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
2387 log_err("(3) Didn't get correct string while iterating over alias table (%s)\n", strings[i]);
2388 }
2389 }
2390 }
2391 tb = ures_getByKey(aliasB, "testGetStringByIndexAliasing", tb, &status);
2392 if(U_FAILURE(status)) {
2393 log_err("FAIL: Couldn't get testGetStringByIndexAliasing resource: %s\n", u_errorName(status));
2394 } else {
2395 for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
2396 result = tres_getString(tb, i, NULL, &resultLen, &status);
2397 if(U_FAILURE(status)){
2398 log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
2399 continue;
2400 }
2401 uBufferLen = u_unescape(strings[i], uBuffer, 256);
2402 if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
2403 log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings[i]);
2404 }
2405 }
2406 for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
2407 result = ures_getNextString(tb, &resultLen, &key, &status);
2408 if(U_FAILURE(status)){
2409 log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
2410 continue;
2411 }
2412 uBufferLen = u_unescape(strings[i], uBuffer, 256);
2413 if(result==NULL || resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
2414 log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings[i]);
2415 }
2416 }
2417 }
2418 }
2419 tb = ures_getByKey(aliasB, "testAliasToTree", tb, &status);
2420 if(U_FAILURE(status)){
2421 log_err("Fetching the resource with key \"testAliasToTree\" failed. Error: %s\n", u_errorName(status));
2422 goto cleanup;
2423 }
2424 if (strcmp(ures_getKey(tb), "collations") != 0) {
2425 log_err("ures_getKey(aliasB) unexpectedly returned %s instead of \"collations\"\n", ures_getKey(tb));
2426 }
2427 cleanup:
2428 ures_close(aliasB);
2429 ures_close(tb);
2430 ures_close(en);
2431 ures_close(uk);
2432 ures_close(testtypes);
2433 }
2434
TestDirectAccess(void)2435 static void TestDirectAccess(void) {
2436 UErrorCode status = U_ZERO_ERROR;
2437 UResourceBundle *t = NULL, *t2 = NULL;
2438 const char* key = NULL;
2439
2440 char buffer[100];
2441 char *s;
2442 /*const char* testdatapath=loadTestData(&status);
2443 if(U_FAILURE(status)){
2444 log_err("Could not load testdata.dat %s \n",myErrorName(status));
2445 return;
2446 }*/
2447
2448 t = ures_findResource("/testdata/te/zoneStrings/3/2", t, &status);
2449 if(U_FAILURE(status)) {
2450 log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
2451 status = U_ZERO_ERROR;
2452 } else {
2453 key = ures_getKey(t);
2454 if(key != NULL) {
2455 log_err("Got a strange key, expected NULL, got %s\n", key);
2456 }
2457 }
2458 t = ures_findResource("en/calendar/gregorian/DateTimePatterns/3", t, &status);
2459 if(U_FAILURE(status)) {
2460 log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
2461 status = U_ZERO_ERROR;
2462 } else {
2463 key = ures_getKey(t);
2464 if(key != NULL) {
2465 log_err("Got a strange key, expected NULL, got %s\n", key);
2466 }
2467 }
2468
2469 t = ures_findResource("ja/ExemplarCharacters", t, &status);
2470 if(U_FAILURE(status)) {
2471 log_data_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
2472 status = U_ZERO_ERROR;
2473 } else {
2474 key = ures_getKey(t);
2475 if(strcmp(key, "ExemplarCharacters")!=0) {
2476 log_err("Got a strange key, expected 'ExemplarCharacters', got %s\n", key);
2477 }
2478 }
2479
2480 t2 = ures_open(U_ICUDATA_LANG, "sr", &status);
2481 if(U_FAILURE(status)) {
2482 log_err_status(status, "Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status));
2483 log_data_err("No 'sr', no test - you have bigger problems than testing direct access. "
2484 "You probably have no data! Aborting this test\n");
2485 }
2486
2487 if(U_SUCCESS(status)) {
2488 strcpy(buffer, "Languages/hr");
2489 s = buffer;
2490 t = ures_findSubResource(t2, s, t, &status);
2491 if(U_FAILURE(status)) {
2492 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
2493 status = U_ZERO_ERROR;
2494 } else {
2495 key = ures_getKey(t);
2496 if(strcmp(key, "hr")!=0) {
2497 log_err("Got a strange key, expected 'hr', got %s\n", key);
2498 }
2499 }
2500 }
2501
2502 t = ures_findResource("root/calendar/islamic-civil/DateTime", t, &status);
2503 if(U_SUCCESS(status)) {
2504 log_data_err("This resource does not exist. How did it get here?\n");
2505 }
2506 status = U_ZERO_ERROR;
2507
2508 /* this one will freeze */
2509 t = ures_findResource("root/calendar/islamic-civil/eras/abbreviated/0/mikimaus/pera", t, &status);
2510 if(U_SUCCESS(status)) {
2511 log_data_err("Second resource does not exist. How did it get here?\n");
2512 }
2513 status = U_ZERO_ERROR;
2514
2515 ures_close(t2);
2516 t2 = ures_open(NULL, "he", &status);
2517 t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status);
2518 t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status);
2519 t2 = ures_getByKeyWithFallback(t2, "DateTime", t2, &status);
2520 if(U_SUCCESS(status)) {
2521 log_err("This resource does not exist. How did it get here?\n");
2522 }
2523 status = U_ZERO_ERROR;
2524
2525 ures_close(t2);
2526 t2 = ures_open(NULL, "he", &status);
2527 /* George's fix */
2528 t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status);
2529 t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status);
2530 t2 = ures_getByKeyWithFallback(t2, "eras", t2, &status);
2531 if(U_FAILURE(status)) {
2532 log_err_status(status, "Didn't get Eras. I know they are there!\n");
2533 }
2534 status = U_ZERO_ERROR;
2535
2536 ures_close(t2);
2537 t2 = ures_open(NULL, "root", &status);
2538 t2 = ures_getByKeyWithFallback(t2, "calendar", t2, &status);
2539 t2 = ures_getByKeyWithFallback(t2, "islamic-civil", t2, &status);
2540 t2 = ures_getByKeyWithFallback(t2, "DateTime", t2, &status);
2541 if(U_SUCCESS(status)) {
2542 log_err("This resource does not exist. How did it get here?\n");
2543 }
2544 status = U_ZERO_ERROR;
2545
2546 ures_close(t2);
2547 ures_close(t);
2548 }
2549
TestTicket9804(void)2550 static void TestTicket9804(void) {
2551 UErrorCode status = U_ZERO_ERROR;
2552 UResourceBundle *t = NULL;
2553 t = ures_open(NULL, "he", &status);
2554 t = ures_getByKeyWithFallback(t, "calendar/islamic-civil/DateTime", t, &status);
2555 if(U_SUCCESS(status)) {
2556 log_err("This resource does not exist. How did it get here?\n");
2557 }
2558 status = U_ZERO_ERROR;
2559 ures_close(t);
2560 t = ures_open(NULL, "he", &status);
2561 t = ures_getByKeyWithFallback(t, "calendar/islamic-civil/eras", t, &status);
2562 if(U_FAILURE(status)) {
2563 log_err_status(status, "Didn't get Eras. I know they are there!\n");
2564 } else {
2565 const char *locale = ures_getLocaleByType(t, ULOC_ACTUAL_LOCALE, &status);
2566 if (uprv_strcmp("he", locale) != 0) {
2567 log_err("Eras should be in the 'he' locale, but was in: %s", locale);
2568 }
2569 }
2570 status = U_ZERO_ERROR;
2571 ures_close(t);
2572 }
2573
TestJB3763(void)2574 static void TestJB3763(void) {
2575 /* Nasty bug prevented using parent as fill-in, since it would
2576 * stomp the path information.
2577 */
2578 UResourceBundle *t = NULL;
2579 UErrorCode status = U_ZERO_ERROR;
2580 t = ures_open(NULL, "sr_Latn", &status);
2581 t = ures_getByKeyWithFallback(t, "calendar", t, &status);
2582 t = ures_getByKeyWithFallback(t, "gregorian", t, &status);
2583 t = ures_getByKeyWithFallback(t, "AmPmMarkers", t, &status);
2584 if(U_FAILURE(status)) {
2585 log_err_status(status, "This resource should be available?\n");
2586 }
2587 status = U_ZERO_ERROR;
2588
2589 ures_close(t);
2590
2591 }
2592
TestGetKeywordValues(void)2593 static void TestGetKeywordValues(void) {
2594 UEnumeration *kwVals;
2595 UBool foundStandard = FALSE;
2596 UErrorCode status = U_ZERO_ERROR;
2597 const char *kw;
2598 #if !UCONFIG_NO_COLLATION
2599 kwVals = ures_getKeywordValues( U_ICUDATA_COLL, "collations", &status);
2600
2601 log_verbose("Testing getting collation keyword values:\n");
2602
2603 while((kw=uenum_next(kwVals, NULL, &status))) {
2604 log_verbose(" %s\n", kw);
2605 if(!strcmp(kw,"standard")) {
2606 if(foundStandard == FALSE) {
2607 foundStandard = TRUE;
2608 } else {
2609 log_err("'standard' was found twice in the keyword list.\n");
2610 }
2611 }
2612 }
2613 if(foundStandard == FALSE) {
2614 log_err_status(status, "'standard' was not found in the keyword list.\n");
2615 }
2616 uenum_close(kwVals);
2617 if(U_FAILURE(status)) {
2618 log_err_status(status, "err %s getting collation values\n", u_errorName(status));
2619 }
2620 status = U_ZERO_ERROR;
2621 #endif
2622 foundStandard = FALSE;
2623 kwVals = ures_getKeywordValues( "ICUDATA", "calendar", &status);
2624
2625 log_verbose("Testing getting calendar keyword values:\n");
2626
2627 while((kw=uenum_next(kwVals, NULL, &status))) {
2628 log_verbose(" %s\n", kw);
2629 if(!strcmp(kw,"japanese")) {
2630 if(foundStandard == FALSE) {
2631 foundStandard = TRUE;
2632 } else {
2633 log_err("'japanese' was found twice in the calendar keyword list.\n");
2634 }
2635 }
2636 }
2637 if(foundStandard == FALSE) {
2638 log_err_status(status, "'japanese' was not found in the calendar keyword list.\n");
2639 }
2640 uenum_close(kwVals);
2641 if(U_FAILURE(status)) {
2642 log_err_status(status, "err %s getting calendar values\n", u_errorName(status));
2643 }
2644 }
2645
TestGetFunctionalEquivalentOf(const char * path,const char * resName,const char * keyword,UBool truncate,const char * const testCases[])2646 static void TestGetFunctionalEquivalentOf(const char *path, const char *resName, const char *keyword, UBool truncate, const char * const testCases[]) {
2647 int32_t i;
2648 for(i=0;testCases[i];i+=3) {
2649 UBool expectAvail = (testCases[i][0]=='t')?TRUE:FALSE;
2650 UBool gotAvail = FALSE;
2651 const char *inLocale = testCases[i+1];
2652 const char *expectLocale = testCases[i+2];
2653 char equivLocale[256];
2654 int32_t len;
2655 UErrorCode status = U_ZERO_ERROR;
2656 log_verbose("%d: %c %s\texpect %s\n",i/3, expectAvail?'t':'f', inLocale, expectLocale);
2657 len = ures_getFunctionalEquivalent(equivLocale, 255, path,
2658 resName, keyword, inLocale,
2659 &gotAvail, truncate, &status);
2660 if(U_FAILURE(status) || (len <= 0)) {
2661 log_err_status(status, "FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n",
2662 len, u_errorName(status),
2663 i/3,expectAvail?'t':'f', inLocale, expectLocale);
2664 } else {
2665 log_verbose("got: %c %s\n", expectAvail?'t':'f',equivLocale);
2666
2667 if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) {
2668 log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
2669 gotAvail?'t':'f', equivLocale,
2670 i/3,
2671 expectAvail?'t':'f', inLocale, expectLocale);
2672
2673 }
2674 }
2675 }
2676 }
2677
TestGetFunctionalEquivalent(void)2678 static void TestGetFunctionalEquivalent(void) {
2679 #if !UCONFIG_NO_COLLATION
2680 static const char * const collCases[] = {
2681 /* avail locale equiv */
2682 /* note: in ICU 64, empty locales are shown as available for collation */
2683 "f", "sv_US_CALIFORNIA", "sv",
2684 "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */
2685 "t", "zh_Hant_TW@collation=stroke", "zh@collation=stroke",
2686 "f", "sv_CN@collation=pinyin", "sv",
2687 "t", "zh@collation=pinyin", "zh",
2688 "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */
2689 "t", "zh_Hans_CN@collation=pinyin", "zh",
2690 "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */
2691 "t", "zh_Hant_HK@collation=pinyin", "zh",
2692 "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */
2693 "t", "zh_Hant_HK@collation=stroke", "zh@collation=stroke",
2694 "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */
2695 "t", "zh_Hant_HK", "zh@collation=stroke",
2696 "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */
2697 "t", "zh_Hant_MO", "zh@collation=stroke",
2698 "f", "zh_TW_STROKE", "zh@collation=stroke",
2699 "f", "zh_TW_STROKE@collation=pinyin", "zh",
2700 "f", "sv_CN@calendar=japanese", "sv",
2701 "t", "sv@calendar=japanese", "sv",
2702 "f", "zh_TW@collation=pinyin", "zh", /* alias of zh_Hant_TW */
2703 "t", "zh_Hant_TW@collation=pinyin", "zh",
2704 "f", "zh_CN@collation=stroke", "zh@collation=stroke", /* alias of zh_Hans_CN */
2705 "t", "zh_Hans_CN@collation=stroke", "zh@collation=stroke",
2706 "t", "de@collation=phonebook", "de@collation=phonebook",
2707 "t", "hi@collation=standard", "hi",
2708 "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
2709 "f", "sv_SE@collation=pinyin", "sv", /* bug 4582 tests */
2710 "f", "sv_SE_BONN@collation=pinyin", "sv",
2711 "t", "nl", "root",
2712 "f", "nl_NL", "root",
2713 "f", "nl_NL_EEXT", "root",
2714 "t", "nl@collation=stroke", "root",
2715 "f", "nl_NL@collation=stroke", "root",
2716 "f", "nl_NL_EEXT@collation=stroke", "root",
2717 NULL
2718 };
2719 #endif /* !UCONFIG_NO_COLLATION */
2720
2721 static const char *calCases[] = {
2722 /* avail locale equiv */
2723 "t", "en_US_POSIX", "en@calendar=gregorian",
2724 "f", "ja_JP_TOKYO", "ja@calendar=gregorian",
2725 "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
2726 "t", "sr@calendar=gregorian", "sr@calendar=gregorian",
2727 "t", "en", "en@calendar=gregorian",
2728 NULL
2729 };
2730
2731 #if !UCONFIG_NO_COLLATION
2732 TestGetFunctionalEquivalentOf(U_ICUDATA_COLL, "collations", "collation", TRUE, collCases);
2733 #endif
2734 TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE, calCases);
2735
2736 #if !UCONFIG_NO_COLLATION
2737 log_verbose("Testing error conditions:\n");
2738 {
2739 char equivLocale[256] = "???";
2740 int32_t len;
2741 UErrorCode status = U_ZERO_ERROR;
2742 UBool gotAvail = FALSE;
2743
2744 len = ures_getFunctionalEquivalent(equivLocale, 255, U_ICUDATA_COLL,
2745 "calendar", "calendar", "ar_EG@calendar=islamic",
2746 &gotAvail, FALSE, &status);
2747 (void)len; /* Suppress set but not used warning. */
2748
2749 if(status == U_MISSING_RESOURCE_ERROR) {
2750 log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n");
2751 } else {
2752 log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n",
2753 equivLocale, gotAvail?'t':'f', u_errorName(status));
2754 }
2755 }
2756 #endif
2757 }
2758
TestXPath(void)2759 static void TestXPath(void) {
2760 UErrorCode status = U_ZERO_ERROR;
2761 UResourceBundle *rb = NULL, *alias = NULL;
2762 int32_t len = 0;
2763 const UChar* result = NULL;
2764 const UChar expResult[] = { 0x0063, 0x006F, 0x0072, 0x0072, 0x0065, 0x0063, 0x0074, 0x0000 }; /* "correct" */
2765 /*const UChar expResult[] = { 0x0074, 0x0065, 0x0069, 0x006E, 0x0064, 0x0065, 0x0073, 0x0074, 0x0000 }; *//*teindest*/
2766
2767 const char *testdatapath=loadTestData(&status);
2768 if(U_FAILURE(status))
2769 {
2770 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
2771 return;
2772 }
2773
2774 log_verbose("Testing ures_open()......\n");
2775
2776 rb = ures_open(testdatapath, "te_IN", &status);
2777 if(U_FAILURE(status)) {
2778 log_err("Could not open te_IN (%s)\n", myErrorName(status));
2779 return;
2780 }
2781 alias = ures_getByKey(rb, "rootAliasClient", alias, &status);
2782 if(U_FAILURE(status)) {
2783 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status));
2784 ures_close(rb);
2785 return;
2786 }
2787
2788 result = tres_getString(alias, -1, NULL, &len, &status);
2789 if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) {
2790 log_err("Couldn't get correct string value (%s)\n", myErrorName(status));
2791 }
2792
2793 alias = ures_getByKey(rb, "aliasClient", alias, &status);
2794 if(U_FAILURE(status)) {
2795 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status));
2796 ures_close(rb);
2797 return;
2798 }
2799
2800 result = tres_getString(alias, -1, NULL, &len, &status);
2801 if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) {
2802 log_err("Couldn't get correct string value (%s)\n", myErrorName(status));
2803 }
2804
2805 alias = ures_getByKey(rb, "nestedRootAliasClient", alias, &status);
2806 if(U_FAILURE(status)) {
2807 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status));
2808 ures_close(rb);
2809 return;
2810 }
2811
2812 result = tres_getString(alias, -1, NULL, &len, &status);
2813 if(U_FAILURE(status) || result == NULL || u_strcmp(result, expResult)) {
2814 log_err("Couldn't get correct string value (%s)\n", myErrorName(status));
2815 }
2816
2817 ures_close(alias);
2818 ures_close(rb);
2819 }
TestCLDRStyleAliases(void)2820 static void TestCLDRStyleAliases(void) {
2821 UErrorCode status = U_ZERO_ERROR;
2822 UResourceBundle *rb = NULL, *alias = NULL, *a=NULL;
2823 int32_t i, len;
2824 char resource[256];
2825 const UChar *result = NULL;
2826 UChar expected[256];
2827 const char *expects[7] = { "", "a41", "a12", "a03", "ar4" };
2828 const char *testdatapath=loadTestData(&status);
2829 if(U_FAILURE(status)) {
2830 log_data_err("Could not load testdata.dat %s \n",myErrorName(status));
2831 return;
2832 }
2833 log_verbose("Testing CLDR style aliases......\n");
2834
2835 rb = ures_open(testdatapath, "te_IN_REVISED", &status);
2836 if(U_FAILURE(status)) {
2837 log_err("Could not open te_IN (%s)\n", myErrorName(status));
2838 return;
2839 }
2840 alias = ures_getByKey(rb, "a", alias, &status);
2841 if(U_FAILURE(status)) {
2842 log_err("Couldn't find the aliased with name \"a\" resource (%s)\n", myErrorName(status));
2843 ures_close(rb);
2844 return;
2845 }
2846 for(i = 1; i < 5 ; i++) {
2847 resource[0]='a';
2848 resource[1]='0'+i;
2849 resource[2]=0;
2850 /* instead of sprintf(resource, "a%i", i); */
2851 a = ures_getByKeyWithFallback(alias, resource, a, &status);
2852 result = tres_getString(a, -1, NULL, &len, &status);
2853 u_charsToUChars(expects[i], expected, (int32_t)strlen(expects[i])+1);
2854 if(U_FAILURE(status) || !result || u_strcmp(result, expected)) {
2855 log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource, expects[i], result, myErrorName(status));
2856 status = U_ZERO_ERROR;
2857 }
2858 }
2859
2860 ures_close(a);
2861 ures_close(alias);
2862 ures_close(rb);
2863 }
2864
TestFallbackCodes(void)2865 static void TestFallbackCodes(void) {
2866 UErrorCode status = U_ZERO_ERROR;
2867 const char *testdatapath=loadTestData(&status);
2868
2869 UResourceBundle *res = ures_open(testdatapath, "te_IN", &status);
2870
2871 UResourceBundle *r = NULL, *fall = NULL;
2872
2873 r = ures_getByKey(res, "tagged_array_in_Root_te_te_IN", r, &status);
2874
2875 status = U_ZERO_ERROR;
2876 fall = ures_getByKeyWithFallback(r, "tag2", fall, &status);
2877
2878 if(status != U_ZERO_ERROR) {
2879 log_data_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status));
2880 status = U_ZERO_ERROR;
2881 }
2882
2883 fall = ures_getByKeyWithFallback(r, "tag7", fall, &status);
2884
2885 if(status != U_USING_FALLBACK_WARNING) {
2886 log_data_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status));
2887 }
2888 status = U_ZERO_ERROR;
2889
2890 fall = ures_getByKeyWithFallback(r, "tag1", fall, &status);
2891
2892 if(status != U_USING_DEFAULT_WARNING) {
2893 log_data_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status));
2894 }
2895 status = U_ZERO_ERROR;
2896
2897 ures_close(fall);
2898 ures_close(r);
2899 ures_close(res);
2900 }
2901
2902 /* This test will crash if this doesn't work. Results don't need testing. */
TestStackReuse(void)2903 static void TestStackReuse(void) {
2904 UResourceBundle table;
2905 UErrorCode errorCode = U_ZERO_ERROR;
2906 UResourceBundle *rb = ures_open(NULL, "en_US", &errorCode);
2907
2908 if(U_FAILURE(errorCode)) {
2909 log_data_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode));
2910 return;
2911 }
2912 ures_initStackObject(&table);
2913 ures_getByKeyWithFallback(rb, "Types", &table, &errorCode);
2914 ures_getByKeyWithFallback(&table, "collation", &table, &errorCode);
2915 ures_close(rb);
2916 ures_close(&table);
2917 }
2918
2919 /* Test ures_getUTF8StringXYZ() --------------------------------------------- */
2920
2921 /*
2922 * Replace most ures_getStringXYZ() with this function which wraps the
2923 * desired call and also calls the UTF-8 variant and checks that it works.
2924 */
2925 extern const UChar *
tres_getString(const UResourceBundle * resB,int32_t idx,const char * key,int32_t * length,UErrorCode * status)2926 tres_getString(const UResourceBundle *resB,
2927 int32_t idx, const char *key,
2928 int32_t *length,
2929 UErrorCode *status) {
2930 char buffer8[16];
2931 char *p8;
2932 const UChar *s16;
2933 const char *s8;
2934 UChar32 c16, c8;
2935 int32_t length16, length8, i16, i8;
2936 UBool forceCopy;
2937
2938 if(length == NULL) {
2939 length = &length16;
2940 }
2941 if(idx >= 0) {
2942 s16 = ures_getStringByIndex(resB, idx, length, status);
2943 } else if(key != NULL) {
2944 s16 = ures_getStringByKey(resB, key, length, status);
2945 } else {
2946 s16 = ures_getString(resB, length, status);
2947 }
2948 if(U_FAILURE(*status)) {
2949 return s16;
2950 }
2951 length16 = *length;
2952
2953 /* try the UTF-8 variant of ures_getStringXYZ() */
2954 for(forceCopy = FALSE; forceCopy <= TRUE; ++forceCopy) {
2955 p8 = buffer8;
2956 length8 = (int32_t)sizeof(buffer8);
2957 if(idx >= 0) {
2958 s8 = ures_getUTF8StringByIndex(resB, idx, p8, &length8, forceCopy, status);
2959 } else if(key != NULL) {
2960 s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status);
2961 } else {
2962 s8 = ures_getUTF8String(resB, p8, &length8, forceCopy, status);
2963 }
2964 if(*status == U_INVALID_CHAR_FOUND) {
2965 /* the UTF-16 string contains an unpaired surrogate, can't test UTF-8 variant */
2966 return s16;
2967 }
2968 if(*status == U_BUFFER_OVERFLOW_ERROR) {
2969 *status = U_ZERO_ERROR;
2970 p8 = (char *)malloc(++length8);
2971 if(p8 == NULL) {
2972 return s16;
2973 }
2974 if(idx >= 0) {
2975 s8 = ures_getUTF8StringByIndex(resB, idx, p8, &length8, forceCopy, status);
2976 } else if(key != NULL) {
2977 s8 = ures_getUTF8StringByKey(resB, key, p8, &length8, forceCopy, status);
2978 } else {
2979 s8 = ures_getUTF8String(resB, p8, &length8, forceCopy, status);
2980 }
2981 }
2982 if(U_FAILURE(*status)) {
2983 /* something unexpected happened */
2984 if(p8 != buffer8) {
2985 free(p8);
2986 }
2987 return s16;
2988 }
2989
2990 if(forceCopy && s8 != p8) {
2991 log_err("ures_getUTF8String(%p, %ld, '%s') did not write the string to dest\n",
2992 resB, (long)idx, key);
2993 }
2994
2995 /* verify NUL-termination */
2996 if((p8 != buffer8 || length8 < (int32_t)sizeof(buffer8)) && s8[length8] != 0) {
2997 log_err("ures_getUTF8String(%p, %ld, '%s') did not NUL-terminate\n",
2998 resB, (long)idx, key);
2999 }
3000 /* verify correct string */
3001 i16 = i8 = 0;
3002 while(i16 < length16 && i8 < length8) {
3003 U16_NEXT(s16, i16, length16, c16);
3004 U8_NEXT(s8, i8, length8, c8);
3005 if(c16 != c8) {
3006 log_err("ures_getUTF8String(%p, %ld, '%s') got a bad string, c16=U+%04lx!=U+%04lx=c8 before i16=%ld\n",
3007 resB, (long)idx, key, (long)c16, (long)c8, (long)i16);
3008 }
3009 }
3010 /* verify correct length */
3011 if(i16 < length16) {
3012 log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too short, length8=%ld, length16=%ld\n",
3013 resB, (long)idx, key, (long)length8, (long)length16);
3014 }
3015 if(i8 < length8) {
3016 log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too long, length8=%ld, length16=%ld\n",
3017 resB, (long)idx, key, (long)length8, (long)length16);
3018 }
3019
3020 /* clean up */
3021 if(p8 != buffer8) {
3022 free(p8);
3023 }
3024 }
3025 return s16;
3026 }
3027
3028 /*
3029 * API tests for ures_getUTF8String().
3030 * Most cases are handled by tres_getString(), which leaves argument checking
3031 * to be tested here.
3032 * Since the variants share most of their implementation, we only need to test
3033 * one of them.
3034 * We also need not test for checking arguments which will be checked by the
3035 * UTF-16 ures_getStringXYZ() that are called internally.
3036 */
3037 static void
TestGetUTF8String()3038 TestGetUTF8String() {
3039 UResourceBundle *res;
3040 const char *testdatapath;
3041 char buffer8[16];
3042 const char *s8;
3043 int32_t length8;
3044 UErrorCode status;
3045
3046 status = U_ZERO_ERROR;
3047 testdatapath = loadTestData(&status);
3048 if(U_FAILURE(status)) {
3049 log_data_err("Could not load testdata.dat - %s\n", u_errorName(status));
3050 return;
3051 }
3052
3053 res = ures_open(testdatapath, "", &status);
3054 if(U_FAILURE(status)) {
3055 log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status));
3056 return;
3057 }
3058
3059 /* one good call */
3060 status = U_ZERO_ERROR;
3061 length8 = (int32_t)sizeof(buffer8);
3062 s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status);
3063 (void)s8; /* Suppress set but not used warning. */
3064 if(status != U_ZERO_ERROR) {
3065 log_err("ures_getUTF8StringByKey(testdata/root string) malfunctioned - %s\n", u_errorName(status));
3066 }
3067
3068 /* negative capacity */
3069 status = U_ZERO_ERROR;
3070 length8 = -1;
3071 s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", buffer8, &length8, FALSE, &status);
3072 if(status != U_ILLEGAL_ARGUMENT_ERROR) {
3073 log_err("ures_getUTF8StringByKey(capacity<0) malfunctioned - %s\n", u_errorName(status));
3074 }
3075
3076 /* capacity>0 but dest=NULL */
3077 status = U_ZERO_ERROR;
3078 length8 = (int32_t)sizeof(buffer8);
3079 s8 = ures_getUTF8StringByKey(res, "string_only_in_Root", NULL, &length8, FALSE, &status);
3080 if(status != U_ILLEGAL_ARGUMENT_ERROR) {
3081 log_err("ures_getUTF8StringByKey(dest=NULL capacity>0) malfunctioned - %s\n", u_errorName(status));
3082 }
3083
3084 ures_close(res);
3085 }
3086
TestCLDRVersion(void)3087 static void TestCLDRVersion(void) {
3088 UVersionInfo zeroVersion;
3089 UVersionInfo testExpect;
3090 UVersionInfo testCurrent;
3091 UVersionInfo cldrVersion;
3092 char tmp[200];
3093 UErrorCode status = U_ZERO_ERROR;
3094
3095 /* setup the constant value */
3096 u_versionFromString(zeroVersion, "0.0.0.0");
3097
3098 /* test CLDR value from API */
3099 ulocdata_getCLDRVersion(cldrVersion, &status);
3100 if(U_FAILURE(status)) {
3101 /* the show is pretty much over at this point */
3102 log_err_status(status, "FAIL: ulocdata_getCLDRVersion() returned %s\n", u_errorName(status));
3103 return;
3104 } else {
3105 u_versionToString(cldrVersion, tmp);
3106 log_info("ulocdata_getCLDRVersion() returned: '%s'\n", tmp);
3107 }
3108
3109
3110 /* setup from resource bundle */
3111 {
3112 UResourceBundle *res;
3113 const char *testdatapath;
3114
3115 status = U_ZERO_ERROR;
3116 testdatapath = loadTestData(&status);
3117 if(U_FAILURE(status)) {
3118 log_data_err("Could not load testdata.dat - %s\n", u_errorName(status));
3119 return;
3120 }
3121
3122 res = ures_openDirect(testdatapath, "root", &status);
3123 if(U_FAILURE(status)) {
3124 log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status
3125 ));
3126 return;
3127 }
3128 ures_getVersionByKey(res, "ExpectCLDRVersionAtLeast", testExpect, &status);
3129 ures_getVersionByKey(res, "CurrentCLDRVersion", testCurrent, &status);
3130 ures_close(res);
3131 if(U_FAILURE(status)) {
3132 log_err("Unable to get test data for CLDR version - %s\n", u_errorName(status));
3133 }
3134 }
3135 if(U_FAILURE(status)) return;
3136
3137
3138 u_versionToString(testExpect,tmp);
3139 log_verbose("(data) ExpectCLDRVersionAtLeast { %s }\n", tmp);
3140 if(memcmp(cldrVersion, testExpect, sizeof(UVersionInfo)) < 0) {
3141 log_data_err("CLDR version is too old, expect at least %s.", tmp);
3142 }
3143 u_versionToString(testCurrent,tmp);
3144 log_verbose("(data) CurrentCLDRVersion { %s }\n", tmp);
3145 switch(memcmp(cldrVersion, testCurrent, sizeof(UVersionInfo))) {
3146 case 0: break; /* OK- current. */
3147 case -1: log_info("CLDR version is behind 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break;
3148 case 1: log_info("CLDR version is ahead of 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp); break;
3149 }
3150
3151 }
3152