1 /********************************************************************
3 * Copyright (c) 1997-2004, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
11 * Name Date Description
12 * Madhu Katragadda 05/09/2000 Ported Tests for New ResourceBundle API
13 * Madhu Katragadda 05/24/2000 Added new tests to test RES_BINARY for collationElements
14 *********************************************************************************
19 #include "unicode/utypes.h"
21 #include "unicode/putil.h"
22 #include "unicode/ustring.h"
23 #include "unicode/ucnv.h"
26 #include "unicode/uchar.h"
27 #include "ucol_imp.h" /* for U_ICUDATA_COLL */
28 #define RESTEST_HEAP_CHECK 0
30 #include "unicode/uloc.h"
33 #include "unicode/ctest.h"
38 /*****************************************************************************/
40 * Return a random unsigned long l where 0N <= l <= ULONG_MAX.
48 static UBool initialized
= FALSE
;
51 srand((unsigned)time(NULL
));
54 /* Assume rand has at least 12 bits of precision */
56 for (i
=0; i
<sizeof(l
); ++i
)
57 ((char*)&l
)[i
] = (char)((rand() & 0x0FF0) >> 4);
62 * Return a random double x where 0.0 <= x < 1.0.
67 return ((double)randul()) / UINT32_MAX
;
71 * Return a random integer i where 0 <= i < n.
73 static int32_t randi(int32_t n
)
75 return (int32_t)(randd() * n
);
77 /***************************************************************************************/
79 * Convert an integer, positive or negative, to a character string radix 10.
82 itoa1(int32_t i
, char* buf
)
92 /* Output digits in reverse order */
95 *p
++ = (char)('0' + (i
% 10));
101 /* Reverse the string */
110 static const int32_t kERROR_COUNT
= -1234567;
111 static const UChar kERROR
[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/,
112 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/};
114 /*****************************************************************************/
123 typedef enum E_Where E_Where
;
124 /*****************************************************************************/
126 #define CONFIRM_EQ(actual,expected) if (u_strcmp(expected,actual)==0){ record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, austrdup(actual), austrdup(expected)); }
127 #define CONFIRM_INT_EQ(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of %d\n", action, actual, expected); }
128 #define CONFIRM_INT_GE(actual,expected) if ((actual)>=(expected)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x >= %d\n", action, actual, expected); }
129 #define CONFIRM_INT_NE(actual,expected) if ((expected)!=(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x != %d\n", action, actual, expected); }
130 #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)); }
133 /* Array of our test objects */
138 UErrorCode expected_constructor_status
;
140 UBool like
[e_Where_count
];
141 UBool inherits
[e_Where_count
];
145 /* "te" means test */
146 /* "IN" means inherits */
147 /* "NE" or "ne" means "does not exist" */
149 { "root", U_ZERO_ERROR
, e_Root
, { TRUE
, FALSE
, FALSE
}, { TRUE
, FALSE
, FALSE
} },
150 { "te", U_ZERO_ERROR
, e_te
, { FALSE
, TRUE
, FALSE
}, { TRUE
, TRUE
, FALSE
} },
151 { "te_IN", U_ZERO_ERROR
, e_te_IN
, { FALSE
, FALSE
, TRUE
}, { TRUE
, TRUE
, TRUE
} },
152 { "te_NE", U_USING_FALLBACK_WARNING
, e_te
, { FALSE
, TRUE
, FALSE
}, { TRUE
, TRUE
, FALSE
} },
153 { "te_IN_NE", U_USING_FALLBACK_WARNING
, e_te_IN
, { FALSE
, FALSE
, TRUE
}, { TRUE
, TRUE
, TRUE
} },
154 { "ne", U_USING_DEFAULT_WARNING
, e_Root
, { TRUE
, FALSE
, FALSE
}, { TRUE
, FALSE
, FALSE
} }
157 static int32_t bundles_count
= sizeof(param
) / sizeof(param
[0]);
160 /*static void printUChars(UChar*);*/
161 static void TestDecodedBundle(void);
162 static void TestGetKeywordValues(void);
163 static void TestGetFunctionalEquivalent(void);
165 /***************************************************************************************/
167 /* Array of our test objects */
169 void addNEWResourceBundleTest(TestNode
** root
)
171 addTest(root
, &TestErrorCodes
, "tsutil/creststn/TestErrorCodes");
172 addTest(root
, &TestEmptyBundle
, "tsutil/creststn/TestEmptyBundle");
173 addTest(root
, &TestConstruction1
, "tsutil/creststn/TestConstruction1");
174 addTest(root
, &TestResourceBundles
, "tsutil/creststn/TestResourceBundle");
175 addTest(root
, &TestFallback
, "tsutil/creststn/TestFallback");
176 addTest(root
, &TestGetVersion
, "tsutil/creststn/TestGetVersion");
177 addTest(root
, &TestGetVersionColl
, "tsutil/creststn/TestGetVersionColl");
178 addTest(root
, &TestAliasConflict
, "tsutil/creststn/TestAliasConflict");
179 addTest(root
, &TestNewTypes
, "tsutil/creststn/TestNewTypes");
180 addTest(root
, &TestEmptyTypes
, "tsutil/creststn/TestEmptyTypes");
181 addTest(root
, &TestBinaryCollationData
, "tsutil/creststn/TestBinaryCollationData");
182 addTest(root
, &TestAPI
, "tsutil/creststn/TestAPI");
183 addTest(root
, &TestErrorConditions
, "tsutil/creststn/TestErrorConditions");
184 addTest(root
, &TestDecodedBundle
, "tsutil/creststn/TestDecodedBundle");
185 addTest(root
, &TestResourceLevelAliasing
, "tsutil/creststn/TestResourceLevelAliasing");
186 addTest(root
, &TestDirectAccess
, "tsutil/creststn/TestDirectAccess");
187 addTest(root
, &TestGetKeywordValues
, "tsutil/creststn/TestGetKeywordValues");
188 addTest(root
, &TestGetFunctionalEquivalent
,"tsutil/creststn/TestGetFunctionalEquivalent");
189 addTest(root
, &TestJB3763
, "tsutil/creststn/TestJB3763");
194 /***************************************************************************************/
195 static const char* norwayNames
[] = {
205 static const char* norwayLocales
[] = {
215 static void checkStatus(int32_t line
, UErrorCode expected
, UErrorCode status
) {
216 if(U_FAILURE(status
)) {
217 log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__
, line
);
219 if(status
!= expected
) {
220 log_err("%s:%d: Expected error code %s, got error code %s\n", __FILE__
, line
, u_errorName(expected
), u_errorName(status
));
224 static void TestErrorCodes(void) {
225 UErrorCode status
= U_USING_DEFAULT_WARNING
;
227 UResourceBundle
*r
= NULL
, *r2
= NULL
;
229 /* First check with ICUDATA */
230 /* first bundle should return fallback warning */
231 r
= ures_open(NULL
, "ti_ER_ASSAB", &status
);
232 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
235 /* this bundle should return zero error, so it shouldn't change the status*/
236 status
= U_USING_DEFAULT_WARNING
;
237 r
= ures_open(NULL
, "ti_ER", &status
);
238 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
240 /* we look up the resource which is aliased, but it lives in fallback */
241 if(U_SUCCESS(status
) && r
!= NULL
) {
242 status
= U_USING_DEFAULT_WARNING
;
243 r2
= ures_getByKey(r
, "Languages", NULL
, &status
); /* languages of 'ti' aliases to 'am' */
244 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
248 /* this bundle should return zero error, so it shouldn't change the status*/
249 status
= U_USING_DEFAULT_WARNING
;
250 r
= ures_open(NULL
, "ti", &status
);
251 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
253 /* we look up the resource which is aliased and at our level */
254 if(U_SUCCESS(status
) && r
!= NULL
) {
255 status
= U_USING_DEFAULT_WARNING
;
256 r2
= ures_getByKey(r
, "Languages", r2
, &status
);
257 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
261 status
= U_USING_FALLBACK_WARNING
;
262 r
= ures_open(NULL
, "nolocale", &status
);
263 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
267 /** Now, with the collation bundle **/
269 /* first bundle should return fallback warning */
270 r
= ures_open(U_ICUDATA_COLL
, "sr_YU_VOJVODINA", &status
);
271 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
274 /* this bundle should return zero error, so it shouldn't change the status*/
275 status
= U_USING_FALLBACK_WARNING
;
276 r
= ures_open(U_ICUDATA_COLL
, "sr", &status
);
277 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
279 /* we look up the resource which is aliased */
280 if(U_SUCCESS(status
) && r
!= NULL
) {
281 status
= U_USING_DEFAULT_WARNING
;
282 r2
= ures_getByKey(r
, "collations", NULL
, &status
);
283 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
287 /* this bundle should return zero error, so it shouldn't change the status*/
288 status
= U_USING_DEFAULT_WARNING
;
289 r
= ures_open(U_ICUDATA_COLL
, "sr", &status
);
290 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
292 /* we look up the resource which is aliased and at our level */
293 if(U_SUCCESS(status
) && r
!= NULL
) {
294 status
= U_USING_DEFAULT_WARNING
;
295 r2
= ures_getByKey(r
, "collations", r2
, &status
);
296 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
300 status
= U_USING_FALLBACK_WARNING
;
301 r
= ures_open(U_ICUDATA_COLL
, "nolocale", &status
);
302 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
307 static void TestAliasConflict(void) {
308 UErrorCode status
= U_ZERO_ERROR
;
309 UResourceBundle
*he
= NULL
;
310 UResourceBundle
*iw
= NULL
;
311 UResourceBundle
*norway
= NULL
;
312 const UChar
*result
= NULL
;
316 const char *realName
= NULL
;
318 he
= ures_open(NULL
, "he", &status
);
319 iw
= ures_open(NULL
, "iw", &status
);
320 if(U_FAILURE(status
)) {
321 log_err("Failed to get resource with %s\n", myErrorName(status
));
324 result
= ures_getStringByKey(he
, "localPatternChars", &resultLen
, &status
);
325 if(U_FAILURE(status
) || result
== NULL
) {
326 log_err("Failed to get resource localPatternChars with %s\n", myErrorName(status
));
330 size
= sizeof(norwayNames
)/sizeof(norwayNames
[0]);
331 for(i
= 0; i
< size
; i
++) {
332 status
= U_ZERO_ERROR
;
333 norway
= ures_open(NULL
, norwayNames
[i
], &status
);
334 if(U_FAILURE(status
)) {
335 log_err("Failed to get resource with %s for %s\n", myErrorName(status
), norwayNames
[i
]);
338 realName
= ures_getLocale(norway
, &status
);
339 log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames
[i
], realName
);
340 if(realName
== NULL
|| strcmp(norwayLocales
[i
], realName
) != 0) {
341 log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames
[i
], norwayLocales
[i
], realName
);
347 static void TestDecodedBundle(){
349 UErrorCode error
= U_ZERO_ERROR
;
351 UResourceBundle
* resB
;
353 const UChar
* srcFromRes
;
355 static const UChar uSrc
[] = {
356 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F,
357 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928,
358 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A,
359 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938,
360 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020,
361 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938,
362 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947,
363 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020,
364 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915,
365 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E,
366 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917,
367 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D,
368 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020,
369 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915,
370 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B,
371 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E,
372 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902,
373 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932,
374 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F,
375 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938,
376 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930,
377 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020,
378 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020,
379 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F,
380 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C,
381 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941,
382 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917,
383 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E,
384 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930,
385 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E,
386 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,
387 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,
388 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935,
389 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915,
390 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F,
391 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033,
392 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F,
393 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915,
394 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020,
400 const char *testdatapath
= loadTestData(&error
);
401 resB
= ures_open(testdatapath
, "iscii", &error
);
402 srcFromRes
=ures_getStringByKey(resB
,"str",&len
,&error
);
403 if(U_FAILURE(error
)){
404 #if UCONFIG_NO_LEGACY_CONVERSION
405 log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION is turned on)\n");
407 log_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error
));
412 if(u_strncmp(srcFromRes
,uSrc
,len
)!=0){
413 log_err("Genrb produced res files after decoding failed\n");
416 if(uSrc
[num
]!=srcFromRes
[num
]){
417 log_verbose(" Expected: 0x%04X Got: 0x%04X \n", uSrc
[num
],srcFromRes
[num
]);
421 if (len
!= u_strlen(uSrc
)) {
422 log_err("Genrb produced a string larger than expected\n");
427 static void TestNewTypes() {
428 UResourceBundle
* theBundle
= NULL
;
430 const char* testdatapath
;
431 UErrorCode status
= U_ZERO_ERROR
;
432 UResourceBundle
* res
= NULL
;
433 uint8_t *binResult
= NULL
;
436 int32_t intResult
= 0;
437 uint32_t uintResult
= 0;
438 const UChar
*empty
= NULL
;
439 const UChar
*zeroString
;
440 UChar expected
[] = { 'a','b','c','\0','d','e','f' };
441 const char* expect
="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
444 testdatapath
=loadTestData(&status
);
446 if(U_FAILURE(status
))
448 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
452 theBundle
= ures_open(testdatapath
, "testtypes", &status
);
454 empty
= ures_getStringByKey(theBundle
, "emptystring", &len
, &status
);
455 if(empty
&& (*empty
!= 0 || len
!= 0)) {
456 log_err("Empty string returned invalid value\n");
459 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
461 CONFIRM_INT_NE(theBundle
, NULL
);
463 /* This test reads the string "abc\u0000def" from the bundle */
464 /* if everything is working correctly, the size of this string */
465 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
467 strcpy(action
, "getting and testing of string with embeded zero");
468 res
= ures_getByKey(theBundle
, "zerotest", res
, &status
);
469 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
470 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
471 zeroString
=ures_getString(res
, &len
, &status
);
472 if(U_SUCCESS(status
)){
473 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
474 CONFIRM_INT_EQ(len
, 7);
475 CONFIRM_INT_NE(len
, 3);
478 if(zeroString
[i
]!= expected
[i
]){
479 log_verbose("Output did not match Expected: \\u%4X Got: \\u%4X", expected
[i
], zeroString
[i
]);
483 strcpy(action
, "getting and testing of binary type");
484 res
= ures_getByKey(theBundle
, "binarytest", res
, &status
);
485 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
486 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
487 binResult
=(uint8_t*)ures_getBinary(res
, &len
, &status
);
488 if(U_SUCCESS(status
)){
489 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
490 CONFIRM_INT_EQ(len
, 15);
491 for(i
= 0; i
<15; i
++) {
492 CONFIRM_INT_EQ(binResult
[i
], i
);
496 strcpy(action
, "getting and testing of imported binary type");
497 res
= ures_getByKey(theBundle
, "importtest", res
, &status
);
498 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
499 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
500 binResult
=(uint8_t*)ures_getBinary(res
, &len
, &status
);
501 if(U_SUCCESS(status
)){
502 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
503 CONFIRM_INT_EQ(len
, 15);
504 for(i
= 0; i
<15; i
++) {
505 CONFIRM_INT_EQ(binResult
[i
], i
);
509 strcpy(action
, "getting and testing of integer types");
510 res
= ures_getByKey(theBundle
, "one", res
, &status
);
511 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
512 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
513 intResult
=ures_getInt(res
, &status
);
514 uintResult
= ures_getUInt(res
, &status
);
515 if(U_SUCCESS(status
)){
516 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
517 CONFIRM_INT_EQ(uintResult
, (uint32_t)intResult
);
518 CONFIRM_INT_EQ(intResult
, 1);
521 strcpy(action
, "getting minusone");
522 res
= ures_getByKey(theBundle
, "minusone", res
, &status
);
523 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
524 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
525 intResult
=ures_getInt(res
, &status
);
526 uintResult
= ures_getUInt(res
, &status
);
527 if(U_SUCCESS(status
)){
528 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
529 CONFIRM_INT_EQ(uintResult
, 0x0FFFFFFF); /* a 28 bit integer */
530 CONFIRM_INT_EQ(intResult
, -1);
531 CONFIRM_INT_NE(uintResult
, (uint32_t)intResult
);
534 strcpy(action
, "getting plusone");
535 res
= ures_getByKey(theBundle
, "plusone", res
, &status
);
536 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
537 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
538 intResult
=ures_getInt(res
, &status
);
539 uintResult
= ures_getUInt(res
, &status
);
540 if(U_SUCCESS(status
)){
541 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
542 CONFIRM_INT_EQ(uintResult
, (uint32_t)intResult
);
543 CONFIRM_INT_EQ(intResult
, 1);
546 res
= ures_getByKey(theBundle
, "onehundredtwentythree", res
, &status
);
547 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
548 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
549 intResult
=ures_getInt(res
, &status
);
550 if(U_SUCCESS(status
)){
551 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
552 CONFIRM_INT_EQ(intResult
, 123);
555 /* this tests if escapes are preserved or not */
557 const UChar
* str
= ures_getStringByKey(theBundle
,"testescape",&len
,&status
);
558 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
559 if(U_SUCCESS(status
)){
560 u_charsToUChars(expect
,uExpect
,(int32_t)strlen(expect
)+1);
561 if(u_strcmp(uExpect
,str
)){
562 log_err("Did not get the expected string for testescape\n");
566 /* this tests if unescaping works are expected */
569 char pattern
[2048] = "";
571 UChar
* expectedEscaped
;
575 /* This strcpy fixes compiler warnings about long strings */
576 strcpy(pattern
, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
577 "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F "
578 "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 "
579 "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD "
580 "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF "
583 "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF "
584 "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF "
585 "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF "
586 "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB "
587 "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C "
590 "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F "
594 patternLen
= (int32_t)uprv_strlen(pattern
);
595 expectedEscaped
= (UChar
*)malloc(U_SIZEOF_UCHAR
* patternLen
);
596 got
= ures_getStringByKey(theBundle
,"test_unescaping",&len
,&status
);
597 expectedLen
= u_unescape(pattern
,expectedEscaped
,patternLen
);
598 if(got
==NULL
|| u_strncmp(expectedEscaped
,got
,expectedLen
)!=0 || expectedLen
!= len
){
599 log_err("genrb failed to unescape string\n");
602 for(i
=0;i
<expectedLen
;i
++){
603 if(expectedEscaped
[i
] != got
[i
]){
604 log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped
[i
], got
[i
]);
608 free(expectedEscaped
);
609 status
= U_ZERO_ERROR
;
611 /* test for jitterbug#1435 */
613 const UChar
* str
= ures_getStringByKey(theBundle
,"test_underscores",&len
,&status
);
614 expect
="test message ....";
615 u_charsToUChars(expect
,uExpect
,(int32_t)strlen(expect
)+1);
616 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
617 if(u_strcmp(uExpect
,str
)){
618 log_err("Did not get the expected string for test_underscores.\n");
621 /* test for jitterbug#2626 */
623 UResourceBundle
* resB
= NULL
;
624 const UChar
* str
= NULL
;
625 int32_t strLength
= 0;
626 const UChar my
[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */
627 status
= U_ZERO_ERROR
;
628 resB
= ures_getByKey(theBundle
, "collations", resB
, &status
);
629 resB
= ures_getByKey(resB
, "standard", resB
, &status
);
630 str
= ures_getStringByKey(resB
,"Sequence",&strLength
,&status
);
631 if(!str
|| U_FAILURE(status
)) {
632 log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status
));
633 } else if(u_strcmp(my
,str
) != 0){
634 log_err("Did not get the expected string for escaped \\u0075\n");
639 const char *sourcePath
= ctest_dataSrcDir();
640 int32_t srcPathLen
= (int32_t)strlen(sourcePath
);
641 const char *deltaPath
= ".."U_FILE_SEP_STRING
"test"U_FILE_SEP_STRING
"testdata"U_FILE_SEP_STRING
;
642 int32_t deltaPathLen
= (int32_t)strlen(deltaPath
);
643 char *testDataFileName
= (char *) malloc( srcPathLen
+ deltaPathLen
+ 50 );
644 char *path
= testDataFileName
;
646 strcpy(path
, sourcePath
);
648 strcpy(path
, deltaPath
);
649 path
+= deltaPathLen
;
650 status
= U_ZERO_ERROR
;
653 const UChar
* str
= ures_getStringByKey(theBundle
, "testincludeUTF",&strLen
,&status
);
654 strcpy(path
, "riwords.txt");
655 path
[strlen("riwords.txt")]=0;
656 if(U_FAILURE(status
)){
657 log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status
));
660 const char* cp
= NULL
;
661 UCHARBUF
* ucbuf
= ucbuf_open(testDataFileName
,&cp
,FALSE
,FALSE
,&status
);
663 if(U_SUCCESS(status
)){
664 const UChar
* buffer
= ucbuf_getBuffer(ucbuf
,&len
,&status
);
665 if(U_SUCCESS(status
)){
666 /* verify the contents */
668 log_err("Did not get the expected len for riwords. Expected: %i , Got: %i\n", len
,strLen
);
670 /* test string termination */
671 if(u_strlen(str
) != strLen
|| str
[strLen
]!= 0 ){
672 log_err("testinclude not null terminated!\n");
674 if(u_strncmp(str
, buffer
,strLen
)!=0){
675 log_err("Did not get the expected string from riwords. Include functionality failed for genrb.\n");
678 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName
, u_errorName(status
));
683 log_err("Could not get riwords.txt (path : %s). Error: %s\n",testDataFileName
,u_errorName(status
));
687 status
= U_ZERO_ERROR
;
690 const UChar
* str
= ures_getStringByKey(theBundle
, "testinclude",&strLen
,&status
);
691 strcpy(path
, "translit_rules.txt");
692 path
[strlen("translit_rules.txt")]=0;
694 if(U_FAILURE(status
)){
695 log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status
));
699 UCHARBUF
* ucbuf
= ucbuf_open(testDataFileName
,&cp
,FALSE
,FALSE
,&status
);
701 if(U_SUCCESS(status
)){
702 const UChar
* buffer
= ucbuf_getBuffer(ucbuf
,&len
,&status
);
703 if(U_SUCCESS(status
)){
704 /* verify the contents */
706 log_err("Did not get the expected len for translit_rules. Expected: %i , Got: %i\n", len
,strLen
);
708 if(u_strncmp(str
, buffer
,strLen
)!=0){
709 log_err("Did not get the expected string from translit_rules. Include functionality failed for genrb.\n");
712 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName
, u_errorName(status
));
716 log_err("Could not get translit_rules.txt (path : %s). Error: %s\n",testDataFileName
,u_errorName(status
));
720 free(testDataFileName
);
723 ures_close(theBundle
);
727 static void TestEmptyTypes() {
728 UResourceBundle
* theBundle
= NULL
;
730 const char* testdatapath
;
731 UErrorCode status
= U_ZERO_ERROR
;
732 UResourceBundle
* res
= NULL
;
733 UResourceBundle
* resArray
= NULL
;
734 const uint8_t *binResult
= NULL
;
736 int32_t intResult
= 0;
737 const UChar
*zeroString
;
738 const int32_t *zeroIntVect
;
740 strcpy(action
, "Construction of testtypes bundle");
741 testdatapath
=loadTestData(&status
);
742 if(U_FAILURE(status
))
744 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
748 theBundle
= ures_open(testdatapath
, "testtypes", &status
);
750 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
752 CONFIRM_INT_NE(theBundle
, NULL
);
754 /* This test reads the string "abc\u0000def" from the bundle */
755 /* if everything is working correctly, the size of this string */
756 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
758 status
= U_ZERO_ERROR
;
759 strcpy(action
, "getting and testing of explicit string of zero length string");
760 res
= ures_getByKey(theBundle
, "emptyexplicitstring", res
, &status
);
761 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
762 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
763 zeroString
=ures_getString(res
, &len
, &status
);
764 if(U_SUCCESS(status
)){
765 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
766 CONFIRM_INT_EQ(len
, 0);
767 CONFIRM_INT_EQ(u_strlen(zeroString
), 0);
770 log_err("Couldn't get emptyexplicitstring\n");
773 status
= U_ZERO_ERROR
;
774 strcpy(action
, "getting and testing of normal string of zero length string");
775 res
= ures_getByKey(theBundle
, "emptystring", res
, &status
);
776 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
777 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
778 zeroString
=ures_getString(res
, &len
, &status
);
779 if(U_SUCCESS(status
)){
780 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
781 CONFIRM_INT_EQ(len
, 0);
782 CONFIRM_INT_EQ(u_strlen(zeroString
), 0);
785 log_err("Couldn't get emptystring\n");
788 status
= U_ZERO_ERROR
;
789 strcpy(action
, "getting and testing of empty int");
790 res
= ures_getByKey(theBundle
, "emptyint", res
, &status
);
791 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
792 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
793 intResult
=ures_getInt(res
, &status
);
794 if(U_SUCCESS(status
)){
795 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
796 CONFIRM_INT_EQ(intResult
, 0);
799 log_err("Couldn't get emptystring\n");
802 status
= U_ZERO_ERROR
;
803 strcpy(action
, "getting and testing of zero length intvector");
804 res
= ures_getByKey(theBundle
, "emptyintv", res
, &status
);
805 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
806 CONFIRM_INT_EQ(ures_getType(res
), URES_INT_VECTOR
);
808 if(U_FAILURE(status
)){
809 log_err("Couldn't get emptyintv key %s\n", u_errorName(status
));
812 zeroIntVect
=ures_getIntVector(res
, &len
, &status
);
813 if(!U_SUCCESS(status
) || resArray
!= NULL
|| len
!= 0) {
814 log_err("Shouldn't get emptyintv\n");
818 status
= U_ZERO_ERROR
;
819 strcpy(action
, "getting and testing of zero length emptybin");
820 res
= ures_getByKey(theBundle
, "emptybin", res
, &status
);
821 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
822 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
824 if(U_FAILURE(status
)){
825 log_err("Couldn't get emptybin key %s\n", u_errorName(status
));
828 binResult
=ures_getBinary(res
, &len
, &status
);
829 if(!U_SUCCESS(status
) || binResult
!= NULL
|| len
!= 0) {
830 log_err("Shouldn't get emptybin\n");
834 status
= U_ZERO_ERROR
;
835 strcpy(action
, "getting and testing of zero length emptyarray");
836 res
= ures_getByKey(theBundle
, "emptyarray", res
, &status
);
837 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
838 CONFIRM_INT_EQ(ures_getType(res
), URES_ARRAY
);
840 if(U_FAILURE(status
)){
841 log_err("Couldn't get emptyarray key %s\n", u_errorName(status
));
844 resArray
=ures_getByIndex(res
, 0, resArray
, &status
);
845 if(U_SUCCESS(status
) || resArray
!= NULL
){
846 log_err("Shouldn't get emptyarray\n");
850 status
= U_ZERO_ERROR
;
851 strcpy(action
, "getting and testing of zero length emptytable");
852 res
= ures_getByKey(theBundle
, "emptytable", res
, &status
);
853 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
854 CONFIRM_INT_EQ(ures_getType(res
), URES_TABLE
);
856 if(U_FAILURE(status
)){
857 log_err("Couldn't get emptytable key %s\n", u_errorName(status
));
860 resArray
=ures_getByIndex(res
, 0, resArray
, &status
);
861 if(U_SUCCESS(status
) || resArray
!= NULL
){
862 log_err("Shouldn't get emptytable\n");
867 ures_close(theBundle
);
870 static void TestEmptyBundle(){
871 UErrorCode status
= U_ZERO_ERROR
;
872 const char* testdatapath
=NULL
;
873 UResourceBundle
*resb
=0, *dResB
=0;
875 testdatapath
=loadTestData(&status
);
876 if(U_FAILURE(status
))
878 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
881 resb
= ures_open(testdatapath
, "testempty", &status
);
883 if(U_SUCCESS(status
)){
884 dResB
= ures_getByKey(resb
,"test",dResB
,&status
);
885 if(status
!= U_MISSING_RESOURCE_ERROR
){
886 log_err("Did not get the expected error from an empty resource bundle. Expected : %s Got: %s\n",
887 u_errorName(U_MISSING_RESOURCE_ERROR
),u_errorName(status
));
894 static void TestBinaryCollationData(){
895 UErrorCode status
=U_ZERO_ERROR
;
896 const char* locale
="te";
897 #if !UCONFIG_NO_COLLATION
898 const char* testdatapath
;
900 UResourceBundle
*teRes
= NULL
;
901 UResourceBundle
*coll
=NULL
;
902 UResourceBundle
*binColl
= NULL
;
903 uint8_t *binResult
= NULL
;
905 const char* action
="testing the binary collaton data";
907 #if !UCONFIG_NO_COLLATION
908 log_verbose("Testing binary collation data resource......\n");
910 testdatapath
=loadTestData(&status
);
911 if(U_FAILURE(status
))
913 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
918 teRes
=ures_open(testdatapath
, locale
, &status
);
919 if(U_FAILURE(status
)){
920 log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status
));
924 coll
= ures_getByKey(teRes
, "collations", coll
, &status
);
925 coll
= ures_getByKey(coll
, "standard", coll
, &status
);
926 if(U_SUCCESS(status
)){
927 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
928 CONFIRM_INT_EQ(ures_getType(coll
), URES_TABLE
);
929 binColl
=ures_getByKey(coll
, "%%CollationBin", binColl
, &status
);
930 if(U_SUCCESS(status
)){
931 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
932 CONFIRM_INT_EQ(ures_getType(binColl
), URES_BINARY
);
933 binResult
=(uint8_t*)ures_getBinary(binColl
, &len
, &status
);
934 if(U_SUCCESS(status
)){
935 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
936 CONFIRM_INT_GE(len
, 1);
940 log_err("ERROR: ures_getByKey(locale(te), %%CollationBin) failed\n");
944 log_err("ERROR: ures_getByKey(locale(te), collations) failed\n");
953 static void TestAPI() {
954 UErrorCode status
=U_ZERO_ERROR
;
956 const char* key
=NULL
;
957 const UChar
* value
=NULL
;
958 const char* testdatapath
;
959 UChar
* utestdatapath
=NULL
;
960 char convOutput
[256];
961 UResourceBundle
*teRes
= NULL
;
962 UResourceBundle
*teFillin
=NULL
;
963 UResourceBundle
*teFillin2
=NULL
;
965 log_verbose("Testing ures_openU()......\n");
967 testdatapath
=loadTestData(&status
);
968 if(U_FAILURE(status
))
970 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
973 len
=(int32_t)strlen(testdatapath
);
974 utestdatapath
= (UChar
*) malloc((len
+10)*sizeof(UChar
));
976 u_charsToUChars(testdatapath
, utestdatapath
, (int32_t)strlen(testdatapath
)+1);
977 /*u_uastrcpy(utestdatapath, testdatapath);*/
981 teRes
=ures_openU(utestdatapath
, "te", &status
);
982 if(U_FAILURE(status
)){
983 log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath
), myErrorName(status
));
986 /*Test ures_getLocale() */
987 log_verbose("Testing ures_getLocale() .....\n");
988 if(strcmp(ures_getLocale(teRes
, &status
), "te") != 0){
989 log_err("ERROR: ures_getLocale() failed. Expected = te_TE Got = %s\n", ures_getLocale(teRes
, &status
));
991 /*Test ures_getNextString() */
992 teFillin
=ures_getByKey(teRes
, "tagged_array_in_te_te_IN", teFillin
, &status
);
993 key
=ures_getKey(teFillin
);
994 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
995 ures_resetIterator(NULL
);
996 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
997 if(status
!=U_INDEX_OUTOFBOUNDS_ERROR
){
998 log_err("ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
999 myErrorName(status
));
1001 ures_resetIterator(teRes
);
1002 /*Test ures_getNextResource() where resource is table*/
1003 status
=U_ZERO_ERROR
;
1004 #if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
1005 /* The next key varies depending on the charset. */
1006 teFillin
=ures_getNextResource(teRes
, teFillin
, &status
);
1007 if(U_FAILURE(status
)){
1008 log_err("ERROR: ures_getNextResource() failed \n");
1010 key
=ures_getKey(teFillin
);
1011 /*if(strcmp(key, "%%CollationBin") != 0){*/
1012 if(strcmp(key
, "array_2d_in_Root_te") != 0){
1013 log_err("ERROR: ures_getNextResource() failed\n");
1017 /*Test ures_getByIndex on string Resource*/
1018 teFillin
=ures_getByKey(teRes
, "string_only_in_te", teFillin
, &status
);
1019 teFillin2
=ures_getByIndex(teFillin
, 0, teFillin2
, &status
);
1020 if(U_FAILURE(status
)){
1021 log_err("ERROR: ures_getByIndex on string resource failed\n");
1023 if(strcmp(u_austrcpy(convOutput
, ures_getString(teFillin2
, &len
, &status
)), "TE") != 0){
1024 status
=U_ZERO_ERROR
;
1025 log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2
, &len
, &status
)));
1028 /*ures_close(teRes);*/
1030 /*Test ures_openFillIn*/
1031 log_verbose("Testing ures_openFillIn......\n");
1032 status
=U_ZERO_ERROR
;
1033 ures_openFillIn(teRes
, testdatapath
, "te", &status
);
1034 if(U_FAILURE(status
)){
1035 log_err("ERROR: ures_openFillIn failed\n");
1038 if(strcmp(ures_getLocale(teRes
, &status
), "te") != 0){
1039 log_err("ERROR: ures_openFillIn did not open the ResourceBundle correctly\n");
1041 ures_getByKey(teRes
, "string_only_in_te", teFillin
, &status
);
1042 teFillin2
=ures_getNextResource(teFillin
, teFillin2
, &status
);
1043 if(ures_getType(teFillin2
) != URES_STRING
){
1044 log_err("ERROR: getType for getNextResource after ures_openFillIn failed\n");
1046 teFillin2
=ures_getNextResource(teFillin
, teFillin2
, &status
);
1047 if(status
!=U_INDEX_OUTOFBOUNDS_ERROR
){
1048 log_err("ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1049 myErrorName(status
));
1052 ures_close(teFillin
);
1053 ures_close(teFillin2
);
1056 /* Test that ures_getLocale() returns the "real" locale ID */
1057 status
=U_ZERO_ERROR
;
1058 teRes
=ures_open(NULL
, "dE_At_NOWHERE_TO_BE_FOUND", &status
);
1059 if(U_FAILURE(status
)) {
1060 log_data_err("unable to open a locale resource bundle from \"dE_At_NOWHERE_TO_BE_FOUND\"(%s)\n", u_errorName(status
));
1062 if(0!=strcmp("de_AT", ures_getLocale(teRes
, &status
))) {
1063 log_data_err("ures_getLocale(\"dE_At_NOWHERE_TO_BE_FOUND\")=%s but must be de_AT\n", ures_getLocale(teRes
, &status
));
1068 /* same test, but with an aliased locale resource bundle */
1069 status
=U_ZERO_ERROR
;
1070 teRes
=ures_open(NULL
, "iW_Il_depRecaTed_HebreW", &status
);
1071 if(U_FAILURE(status
)) {
1072 log_data_err("unable to open a locale resource bundle from \"iW_Il_depRecaTed_HebreW\"(%s)\n", u_errorName(status
));
1074 if(0!=strcmp("he_IL", ures_getLocale(teRes
, &status
))) {
1075 log_data_err("ures_getLocale(\"iW_Il_depRecaTed_HebreW\")=%s but must be he_IL\n", ures_getLocale(teRes
, &status
));
1079 free(utestdatapath
);
1082 static void TestErrorConditions(){
1083 UErrorCode status
=U_ZERO_ERROR
;
1084 const char *key
=NULL
;
1085 const UChar
*value
=NULL
;
1086 const char* testdatapath
;
1087 UChar
* utestdatapath
;
1089 UResourceBundle
*teRes
= NULL
;
1090 UResourceBundle
*coll
=NULL
;
1091 UResourceBundle
*binColl
= NULL
;
1092 UResourceBundle
*teFillin
=NULL
;
1093 UResourceBundle
*teFillin2
=NULL
;
1094 uint8_t *binResult
= NULL
;
1098 testdatapath
= loadTestData(&status
);
1099 if(U_FAILURE(status
))
1101 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
1104 len
= (int32_t)strlen(testdatapath
);
1105 utestdatapath
= (UChar
*) malloc(sizeof(UChar
) *(len
+10));
1106 u_uastrcpy(utestdatapath
, testdatapath
);
1108 /*Test ures_openU with status != U_ZERO_ERROR*/
1109 log_verbose("Testing ures_openU() with status != U_ZERO_ERROR.....\n");
1110 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1111 teRes
=ures_openU(utestdatapath
, "te", &status
);
1112 if(U_FAILURE(status
)){
1113 log_verbose("ures_openU() failed as expected path =%s with status != U_ZERO_ERROR\n", testdatapath
);
1115 log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath
));
1118 /*Test ures_openFillIn with UResourceBundle = NULL*/
1119 log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
1120 status
=U_ZERO_ERROR
;
1121 ures_openFillIn(NULL
, testdatapath
, "te", &status
);
1122 if(status
!= U_INTERNAL_PROGRAM_ERROR
){
1123 log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_INTERNAL_PROGRAM_ERROR, Got: %s\n",
1124 myErrorName(status
));
1126 /*Test ures_getLocale() with status != U_ZERO_ERROR*/
1127 status
=U_ZERO_ERROR
;
1128 teRes
=ures_openU(utestdatapath
, "te", &status
);
1129 if(U_FAILURE(status
)){
1130 log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath
), myErrorName(status
));
1133 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1134 if(ures_getLocale(teRes
, &status
) != NULL
){
1135 log_err("ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR\n");
1137 /*Test ures_getLocale() with UResourceBundle = NULL*/
1138 status
=U_ZERO_ERROR
;
1139 if(ures_getLocale(NULL
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1140 log_err("ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1141 myErrorName(status
));
1143 /*Test ures_getSize() with UResourceBundle = NULL */
1144 status
=U_ZERO_ERROR
;
1145 if(ures_getSize(NULL
) != 0){
1146 log_err("ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d\n", ures_getSize(NULL
));
1148 /*Test ures_getType() with UResourceBundle = NULL should return URES_NONE==-1*/
1149 status
=U_ZERO_ERROR
;
1150 if(ures_getType(NULL
) != URES_NONE
){
1151 log_err("ERROR: ures_getType() should return URES_NONE when UResourceBundle=NULL. Got =%d\n", ures_getType(NULL
));
1153 /*Test ures_getKey() with UResourceBundle = NULL*/
1154 status
=U_ZERO_ERROR
;
1155 if(ures_getKey(NULL
) != NULL
){
1156 log_err("ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d\n", ures_getKey(NULL
));
1158 /*Test ures_hasNext() with UResourceBundle = NULL*/
1159 status
=U_ZERO_ERROR
;
1160 if(ures_hasNext(NULL
) != FALSE
){
1161 log_err("ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d\n", ures_hasNext(NULL
));
1163 /*Test ures_get() with UResourceBundle = NULL*/
1164 status
=U_ZERO_ERROR
;
1165 if(ures_getStringByKey(NULL
, "string_only_in_te", &resultLen
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1166 log_err("ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1167 myErrorName(status
));
1169 /*Test ures_getByKey() with UResourceBundle = NULL*/
1170 status
=U_ZERO_ERROR
;
1171 teFillin
=ures_getByKey(NULL
, "string_only_in_te", teFillin
, &status
);
1172 if( teFillin
!= NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1173 log_err("ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1174 myErrorName(status
));
1176 /*Test ures_getByKey() with status != U_ZERO_ERROR*/
1177 teFillin
=ures_getByKey(NULL
, "string_only_in_te", teFillin
, &status
);
1178 if(teFillin
!= NULL
){
1179 log_err("ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR\n");
1181 /*Test ures_getStringByKey() with UResourceBundle = NULL*/
1182 status
=U_ZERO_ERROR
;
1183 if(ures_getStringByKey(NULL
, "string_only_in_te", &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1184 log_err("ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1185 myErrorName(status
));
1187 /*Test ures_getStringByKey() with status != U_ZERO_ERROR*/
1188 if(ures_getStringByKey(teRes
, "string_only_in_te", &len
, &status
) != NULL
){
1189 log_err("ERROR: ures_getStringByKey is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1190 myErrorName(status
));
1192 /*Test ures_getString() with UResourceBundle = NULL*/
1193 status
=U_ZERO_ERROR
;
1194 if(ures_getString(NULL
, &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1195 log_err("ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1196 myErrorName(status
));
1198 /*Test ures_getString() with status != U_ZERO_ERROR*/
1199 if(ures_getString(teRes
, &len
, &status
) != NULL
){
1200 log_err("ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1201 myErrorName(status
));
1203 /*Test ures_getBinary() with UResourceBundle = NULL*/
1204 status
=U_ZERO_ERROR
;
1205 if(ures_getBinary(NULL
, &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1206 log_err("ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1207 myErrorName(status
));
1209 /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
1210 status
=U_ZERO_ERROR
;
1211 coll
= ures_getByKey(teRes
, "collations", coll
, &status
);
1212 coll
= ures_getByKey(teRes
, "standard", coll
, &status
);
1213 binColl
=ures_getByKey(coll
, "%%CollationBin", binColl
, &status
);
1215 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1216 binResult
=(uint8_t*)ures_getBinary(binColl
, &len
, &status
);
1217 if(binResult
!= NULL
){
1218 log_err("ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail\n");
1221 /*Test ures_getNextResource() with status != U_ZERO_ERROR*/
1222 teFillin
=ures_getNextResource(teRes
, teFillin
, &status
);
1223 if(teFillin
!= NULL
){
1224 log_err("ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1226 /*Test ures_getNextResource() with UResourceBundle = NULL*/
1227 status
=U_ZERO_ERROR
;
1228 teFillin
=ures_getNextResource(NULL
, teFillin
, &status
);
1229 if(teFillin
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1230 log_err("ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s\n",
1231 myErrorName(status
));
1233 /*Test ures_getNextString with errorCode != U_ZERO_ERROR*/
1234 teFillin
=ures_getByKey(teRes
, "tagged_array_in_te_te_IN", teFillin
, &status
);
1235 key
=ures_getKey(teFillin
);
1236 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1237 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1239 log_err("ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1241 /*Test ures_getNextString with UResourceBundle = NULL*/
1242 status
=U_ZERO_ERROR
;
1243 value
=(UChar
*)ures_getNextString(NULL
, &len
, &key
, &status
);
1244 if(value
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1245 log_err("ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1246 myErrorName(status
));
1248 /*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/
1249 status
=U_ZERO_ERROR
;
1250 teFillin
=ures_getByKey(teRes
, "array_only_in_te", teFillin
, &status
);
1251 if(ures_countArrayItems(teRes
, "array_only_in_te", &status
) != 4) {
1252 log_err("ERROR: Wrong number of items in an array!\n");
1254 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1255 teFillin2
=ures_getByIndex(teFillin
, 0, teFillin2
, &status
);
1256 if(teFillin2
!= NULL
){
1257 log_err("ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1259 /*Test ures_getByIndex with UResourceBundle = NULL */
1260 status
=U_ZERO_ERROR
;
1261 teFillin2
=ures_getByIndex(NULL
, 0, teFillin2
, &status
);
1262 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1263 log_err("ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1264 myErrorName(status
));
1266 /*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/
1267 status
=U_ZERO_ERROR
;
1268 teFillin
=ures_getByKey(teRes
, "array_only_in_te", teFillin
, &status
);
1269 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1270 value
=(UChar
*)ures_getStringByIndex(teFillin
, 0, &len
, &status
);
1272 log_err("ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1274 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1275 status
=U_ZERO_ERROR
;
1276 value
=(UChar
*)ures_getStringByIndex(NULL
, 0, &len
, &status
);
1277 if(value
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1278 log_err("ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1279 myErrorName(status
));
1281 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1282 status
=U_ZERO_ERROR
;
1283 value
=(UChar
*)ures_getStringByIndex(teFillin
, 9999, &len
, &status
);
1284 if(value
!= NULL
|| status
!= U_MISSING_RESOURCE_ERROR
){
1285 log_err("ERROR: ures_getStringByIndex() with index that is too big is supposed to fail\n Expected: U_MISSING_RESOURCE_ERROR, Got: %s\n",
1286 myErrorName(status
));
1288 /*Test ures_getInt() where UResourceBundle = NULL */
1289 status
=U_ZERO_ERROR
;
1290 if(ures_getInt(NULL
, &status
) != -1 && status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1291 log_err("ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s\n",
1292 myErrorName(status
));
1294 /*Test ures_getInt() where status != U_ZERO_ERROR */
1295 if(ures_getInt(teRes
, &status
) != -1){
1296 log_err("ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail\n");
1299 ures_close(teFillin
);
1300 ures_close(teFillin2
);
1302 ures_close(binColl
);
1304 free(utestdatapath
);
1309 static void TestGetVersion(){
1310 UVersionInfo minVersionArray
= {0x01, 0x00, 0x00, 0x00};
1311 UVersionInfo maxVersionArray
= {0x50, 0x80, 0xcf, 0xcf};
1312 UVersionInfo versionArray
;
1313 UErrorCode status
= U_ZERO_ERROR
;
1314 UResourceBundle
* resB
= NULL
;
1316 int locCount
= uloc_countAvailable();
1317 const char *locName
= "root";
1319 log_verbose("The ures_getVersion tests begin : \n");
1321 for(j
= -1; j
< locCount
; j
++) {
1323 locName
= uloc_getAvailable(j
);
1325 log_verbose("Testing version number for locale %s\n", locName
);
1326 resB
= ures_open(NULL
,locName
, &status
);
1327 if (U_FAILURE(status
)) {
1328 log_err("Resource bundle creation for locale %s failed.: %s\n", locName
, myErrorName(status
));
1332 ures_getVersion(resB
, versionArray
);
1333 for (i
=0; i
<4; ++i
) {
1334 if (versionArray
[i
] < minVersionArray
[i
] ||
1335 versionArray
[i
] > maxVersionArray
[i
])
1337 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1338 locName
, versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
1347 static void TestGetVersionColl(){
1348 UVersionInfo minVersionArray
= {0x00, 0x00, 0x00, 0x00};
1349 UVersionInfo maxVersionArray
= {0x50, 0x80, 0xcf, 0xcf};
1350 UVersionInfo versionArray
;
1351 UErrorCode status
= U_ZERO_ERROR
;
1352 UResourceBundle
* resB
= NULL
;
1353 UEnumeration
*locs
= NULL
;
1355 const char *locName
= "root";
1357 const UChar
* rules
=NULL
;
1360 log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL
);
1361 locs
= ures_openAvailableLocales(U_ICUDATA_COLL
, &status
);
1362 if (U_FAILURE(status
)) {
1363 log_err("enumeration of %s failed.: %s\n", U_ICUDATA_COLL
, myErrorName(status
));
1368 log_verbose("Testing version number for locale %s\n", locName
);
1369 resB
= ures_open(U_ICUDATA_COLL
,locName
, &status
);
1370 if (U_FAILURE(status
)) {
1371 log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL
, locName
, myErrorName(status
));
1375 /* test NUL termination of UCARules */
1376 rules
= ures_getStringByKey(resB
,"%%UCARULES",&len
, &status
);
1377 if(!rules
|| U_FAILURE(status
)) {
1378 log_data_err("Could not load %%UCARULES for locale %s\n", locName
);
1381 if(u_strlen(rules
) != len
){
1382 log_err("UCARules string not nul terminated! \n");
1384 ures_getVersion(resB
, versionArray
);
1385 for (i
=0; i
<4; ++i
) {
1386 if (versionArray
[i
] < minVersionArray
[i
] ||
1387 versionArray
[i
] > maxVersionArray
[i
])
1389 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1390 locName
, versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
1395 } while((locName
= uenum_next(locs
,&locLen
,&status
))&&U_SUCCESS(status
));
1397 if(U_FAILURE(status
)) {
1398 log_err("Err %s testing Collation locales.\n", u_errorName(status
));
1403 static void TestResourceBundles()
1406 testTag("only_in_Root", TRUE
, FALSE
, FALSE
);
1407 testTag("in_Root_te", TRUE
, TRUE
, FALSE
);
1408 testTag("in_Root_te_te_IN", TRUE
, TRUE
, TRUE
);
1409 testTag("in_Root_te_IN", TRUE
, FALSE
, TRUE
);
1410 testTag("only_in_te", FALSE
, TRUE
, FALSE
);
1411 testTag("only_in_te_IN", FALSE
, FALSE
, TRUE
);
1412 testTag("in_te_te_IN", FALSE
, TRUE
, TRUE
);
1413 testTag("nonexistent", FALSE
, FALSE
, FALSE
);
1415 log_verbose("Passed:= %d Failed= %d \n", pass
, fail
);
1420 static void TestConstruction1()
1422 UResourceBundle
*test1
= 0, *test2
= 0,*empty
= 0;
1423 const UChar
*result1
, *result2
;
1424 UErrorCode status
= U_ZERO_ERROR
;
1425 UErrorCode err
= U_ZERO_ERROR
;
1426 const char* locale
="te_IN";
1427 const char* testdatapath
;
1431 UVersionInfo versionInfo
;
1432 char versionString
[256];
1433 char verboseOutput
[256];
1435 U_STRING_DECL(rootVal
, "ROOT", 4);
1436 U_STRING_DECL(te_inVal
, "TE_IN", 5);
1438 U_STRING_INIT(rootVal
, "ROOT", 4);
1439 U_STRING_INIT(te_inVal
, "TE_IN", 5);
1441 testdatapath
=loadTestData(&status
);
1442 if(U_FAILURE(status
))
1444 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
1448 log_verbose("Testing ures_open()......\n");
1450 empty
= ures_open(testdatapath
, "testempty", &status
);
1451 if(empty
== NULL
|| U_FAILURE(status
)) {
1452 log_err("opening empty failed!\n");
1456 test1
=ures_open(testdatapath
, NULL
, &err
);
1460 log_err("construction of NULL did not succeed : %s \n", myErrorName(status
));
1463 test2
=ures_open(testdatapath
, locale
, &err
);
1466 log_err("construction of %s did not succeed : %s \n", locale
, myErrorName(status
));
1469 result1
= ures_getStringByKey(test1
, "string_in_Root_te_te_IN", &len1
, &err
);
1470 result2
= ures_getStringByKey(test2
, "string_in_Root_te_te_IN", &len2
, &err
);
1471 if (U_FAILURE(err
) || len1
==0 || len2
==0) {
1472 log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status
));
1475 log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput
, result1
));
1476 log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput
, result2
));
1477 if(u_strcmp(result1
, rootVal
) !=0 || u_strcmp(result2
, te_inVal
) !=0 ){
1478 log_err("construction test failed. Run Verbose for more information");
1482 /* Test getVersionNumber*/
1483 log_verbose("Testing version number\n");
1484 log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1
));
1486 log_verbose("Testing version \n");
1487 ures_getVersion(test1
, versionInfo
);
1488 u_versionToString(versionInfo
, versionString
);
1490 log_verbose("for getVersion : %s\n", versionString
);
1492 if(strcmp(versionString
, ures_getVersionNumber(test1
)) != 0) {
1493 log_err("Versions differ: %s vs %s\n", versionString
, ures_getVersionNumber(test1
));
1501 /*****************************************************************************/
1502 /*****************************************************************************/
1504 static UBool
testTag(const char* frag
,
1509 int32_t failNum
= fail
;
1511 /* Make array from input params */
1514 const char *NAME
[] = { "ROOT", "TE", "TE_IN" };
1516 /* Now try to load the desired items */
1517 UResourceBundle
* theBundle
= NULL
;
1520 UErrorCode expected_status
,status
= U_ZERO_ERROR
,expected_resource_status
= U_ZERO_ERROR
;
1522 UChar
* expected_string
= NULL
;
1523 const UChar
* string
= NULL
;
1526 int32_t i
,j
,row
,col
, len
;
1527 int32_t actual_bundle
;
1529 int32_t row_count
=0;
1530 int32_t column_count
=0;
1532 int32_t tag_count
= 0;
1533 const char* testdatapath
;
1534 char verboseOutput
[256];
1535 UResourceBundle
* array
=NULL
;
1536 UResourceBundle
* array2d
=NULL
;
1537 UResourceBundle
* tags
=NULL
;
1538 UResourceBundle
* arrayItem1
=NULL
;
1540 testdatapath
= loadTestData(&status
);
1541 if(U_FAILURE(status
))
1543 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
1549 is_in
[2] = in_te_IN
;
1551 strcpy(item_tag
, "tag");
1553 for (i
=0; i
<bundles_count
; ++i
)
1555 strcpy(action
,"construction for ");
1556 strcat(action
, param
[i
].name
);
1559 status
= U_ZERO_ERROR
;
1561 theBundle
= ures_open(testdatapath
, param
[i
].name
, &status
);
1562 CONFIRM_ErrorCode(status
,param
[i
].expected_constructor_status
);
1565 actual_bundle
= 0; /* ne -> default */
1567 actual_bundle
= 1; /* te_NE -> te */
1569 actual_bundle
= 2; /* te_IN_NE -> te_IN */
1573 expected_resource_status
= U_MISSING_RESOURCE_ERROR
;
1574 for (j
=e_te_IN
; j
>=e_Root
; --j
)
1576 if (is_in
[j
] && param
[i
].inherits
[j
])
1579 if(j
== actual_bundle
) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
1580 expected_resource_status
= U_ZERO_ERROR
;
1582 expected_resource_status
= U_USING_DEFAULT_WARNING
;
1584 expected_resource_status
= U_USING_FALLBACK_WARNING
;
1586 log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n",
1591 is_in
[j
]?"Yes":"No",
1593 param
[i
].inherits
[j
]?"Yes":"No",
1594 param
[actual_bundle
].name
);
1600 for (j
=param
[i
].where
; j
>=0; --j
)
1608 base
=(UChar
*)malloc(sizeof(UChar
)*(strlen(NAME
[j
]) + 1));
1609 u_uastrcpy(base
,NAME
[j
]);
1618 base
= (UChar
*) malloc(sizeof(UChar
) * 1);
1623 /*----string---------------------------------------------------------------- */
1625 strcpy(tag
,"string_");
1628 strcpy(action
,param
[i
].name
);
1629 strcat(action
, ".ures_getStringByKey(" );
1631 strcat(action
, ")");
1634 status
= U_ZERO_ERROR
;
1637 string
=ures_getStringByKey(theBundle
, tag
, &len
, &status
);
1638 if(U_SUCCESS(status
)) {
1639 expected_string
=(UChar
*)malloc(sizeof(UChar
)*(u_strlen(base
) + 4));
1640 u_strcpy(expected_string
,base
);
1641 CONFIRM_INT_EQ(len
, u_strlen(expected_string
));
1643 expected_string
= (UChar
*)malloc(sizeof(UChar
)*(u_strlen(kERROR
) + 1));
1644 u_strcpy(expected_string
,kERROR
);
1647 log_verbose("%s got %d, expected %d\n", action
, status
, expected_resource_status
);
1649 CONFIRM_ErrorCode(status
, expected_resource_status
);
1650 CONFIRM_EQ(string
, expected_string
);
1654 /*--------------array------------------------------------------------- */
1656 strcpy(tag
,"array_");
1659 strcpy(action
,param
[i
].name
);
1660 strcat(action
, ".ures_getByKey(" );
1662 strcat(action
, ")");
1666 count
= kERROR_COUNT
;
1667 status
= U_ZERO_ERROR
;
1668 array
=ures_getByKey(theBundle
, tag
, array
, &status
);
1669 CONFIRM_ErrorCode(status
,expected_resource_status
);
1670 if (U_SUCCESS(status
)) {
1671 /*confirm the resource type is an array*/
1672 CONFIRM_INT_EQ(ures_getType(array
), URES_ARRAY
);
1673 /*confirm the size*/
1674 count
=ures_getSize(array
);
1675 CONFIRM_INT_GE(count
,1);
1676 for (j
=0; j
<count
; ++j
) {
1678 u_strcpy(expected_string
, base
);
1679 u_uastrcpy(element
, itoa1(j
,buf
));
1680 u_strcat(expected_string
, element
);
1681 arrayItem1
=ures_getNextResource(array
, arrayItem1
, &status
);
1682 if(U_SUCCESS(status
)){
1683 CONFIRM_EQ(ures_getString(arrayItem1
, &len
, &status
),expected_string
);
1689 CONFIRM_INT_EQ(count
,kERROR_COUNT
);
1690 CONFIRM_ErrorCode(status
, U_MISSING_RESOURCE_ERROR
);
1691 /*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/
1695 /*--------------arrayItem------------------------------------------------- */
1697 strcpy(tag
,"array_");
1700 strcpy(action
,param
[i
].name
);
1701 strcat(action
, ".ures_getStringByIndex(");
1702 strcat(action
, tag
);
1703 strcat(action
, ")");
1706 for (j
=0; j
<10; ++j
){
1707 index
= count
? (randi(count
* 3) - count
) : (randi(200) - 100);
1708 status
= U_ZERO_ERROR
;
1710 array
=ures_getByKey(theBundle
, tag
, array
, &status
);
1711 if(!U_FAILURE(status
)){
1713 t
=(UChar
*)ures_getStringByIndex(array
, index
, &len
, &status
);
1714 if(!U_FAILURE(status
)){
1717 u_strcpy(expected_string
, base
);
1718 u_uastrcpy(element
, itoa1(index
,buf
));
1719 u_strcat(expected_string
, element
);
1721 u_strcpy(expected_string
, kERROR
);
1725 expected_status
= (index
>= 0 && index
< count
) ? expected_resource_status
: U_MISSING_RESOURCE_ERROR
;
1726 CONFIRM_ErrorCode(status
,expected_status
);
1727 CONFIRM_EQ(string
,expected_string
);
1732 /*--------------2dArray------------------------------------------------- */
1734 strcpy(tag
,"array_2d_");
1737 strcpy(action
,param
[i
].name
);
1738 strcat(action
, ".ures_getByKey(" );
1740 strcat(action
, ")");
1744 row_count
= kERROR_COUNT
, column_count
= kERROR_COUNT
;
1745 status
= U_ZERO_ERROR
;
1746 array2d
=ures_getByKey(theBundle
, tag
, array2d
, &status
);
1748 CONFIRM_ErrorCode(status
,expected_resource_status
);
1749 if (U_SUCCESS(status
))
1751 /*confirm the resource type is an 2darray*/
1752 CONFIRM_INT_EQ(ures_getType(array2d
), URES_ARRAY
);
1753 row_count
=ures_getSize(array2d
);
1754 CONFIRM_INT_GE(row_count
,1);
1756 for(row
=0; row
<row_count
; ++row
){
1757 UResourceBundle
*tableRow
=NULL
;
1758 tableRow
=ures_getByIndex(array2d
, row
, tableRow
, &status
);
1759 CONFIRM_ErrorCode(status
, expected_resource_status
);
1760 if(U_SUCCESS(status
)){
1761 /*confirm the resourcetype of each table row is an array*/
1762 CONFIRM_INT_EQ(ures_getType(tableRow
), URES_ARRAY
);
1763 column_count
=ures_getSize(tableRow
);
1764 CONFIRM_INT_GE(column_count
,1);
1766 for (col
=0; j
<column_count
; ++j
) {
1768 u_strcpy(expected_string
, base
);
1769 u_uastrcpy(element
, itoa1(row
, buf
));
1770 u_strcat(expected_string
, element
);
1771 u_uastrcpy(element
, itoa1(col
, buf
));
1772 u_strcat(expected_string
, element
);
1773 arrayItem1
=ures_getNextResource(tableRow
, arrayItem1
, &status
);
1774 if(U_SUCCESS(status
)){
1775 const UChar
*stringValue
=ures_getString(arrayItem1
, &len
, &status
);
1776 CONFIRM_EQ(stringValue
, expected_string
);
1780 ures_close(tableRow
);
1783 CONFIRM_INT_EQ(row_count
,kERROR_COUNT
);
1784 CONFIRM_INT_EQ(column_count
,kERROR_COUNT
);
1785 row_count
=column_count
=0;
1789 /*------2dArrayItem-------------------------------------------------------------- */
1791 for (j
=0; j
<10; ++j
)
1793 row
= row_count
? (randi(row_count
* 3) - row_count
) : (randi(200) - 100);
1794 col
= column_count
? (randi(column_count
* 3) - column_count
) : (randi(200) - 100);
1795 status
= U_ZERO_ERROR
;
1798 array2d
=ures_getByKey(theBundle
, tag
, array2d
, &status
);
1799 if(U_SUCCESS(status
)){
1800 UResourceBundle
*tableRow
=NULL
;
1801 tableRow
=ures_getByIndex(array2d
, row
, tableRow
, &status
);
1802 if(U_SUCCESS(status
)) {
1804 t
=(UChar
*)ures_getStringByIndex(tableRow
, col
, &len
, &status
);
1805 if(U_SUCCESS(status
)){
1809 ures_close(tableRow
);
1811 expected_status
= (row
>= 0 && row
< row_count
&& col
>= 0 && col
< column_count
) ?
1812 expected_resource_status
: U_MISSING_RESOURCE_ERROR
;
1813 CONFIRM_ErrorCode(status
,expected_status
);
1815 if (U_SUCCESS(status
)){
1817 u_strcpy(expected_string
, base
);
1818 u_uastrcpy(element
, itoa1(row
, buf
));
1819 u_strcat(expected_string
, element
);
1820 u_uastrcpy(element
, itoa1(col
, buf
));
1821 u_strcat(expected_string
, element
);
1823 u_strcpy(expected_string
,kERROR
);
1825 CONFIRM_EQ(string
,expected_string
);
1830 /*--------------taggedArray----------------------------------------------- */
1831 strcpy(tag
,"tagged_array_");
1834 strcpy(action
,param
[i
].name
);
1835 strcat(action
,".ures_getByKey(");
1836 strcat(action
, tag
);
1840 status
= U_ZERO_ERROR
;
1842 tags
=ures_getByKey(theBundle
, tag
, tags
, &status
);
1843 CONFIRM_ErrorCode(status
, expected_resource_status
);
1844 if (U_SUCCESS(status
)) {
1845 UResType bundleType
=ures_getType(tags
);
1846 CONFIRM_INT_EQ(bundleType
, URES_TABLE
);
1848 tag_count
=ures_getSize(tags
);
1849 CONFIRM_INT_GE((int32_t)tag_count
, (int32_t)0);
1851 for(index
=0; index
<tag_count
; index
++){
1852 UResourceBundle
*tagelement
=NULL
;
1853 const char *key
=NULL
;
1855 tagelement
=ures_getByIndex(tags
, index
, tagelement
, &status
);
1856 key
=ures_getKey(tagelement
);
1857 value
=(UChar
*)ures_getNextString(tagelement
, &len
, &key
, &status
);
1858 log_verbose("tag = %s, value = %s\n", key
, u_austrcpy(verboseOutput
, value
));
1859 if(strncmp(key
, "tag", 3) == 0 && u_strncmp(value
, base
, u_strlen(base
)) == 0){
1864 ures_close(tagelement
);
1870 /*---------taggedArrayItem----------------------------------------------*/
1872 for (index
=-20; index
<20; ++index
)
1875 status
= U_ZERO_ERROR
;
1877 strcpy(item_tag
, "tag");
1878 strcat(item_tag
, itoa1(index
,buf
));
1879 tags
=ures_getByKey(theBundle
, tag
, tags
, &status
);
1880 if(U_SUCCESS(status
)){
1881 UResourceBundle
*tagelement
=NULL
;
1883 tagelement
=ures_getByKey(tags
, item_tag
, tagelement
, &status
);
1884 if(!U_FAILURE(status
)){
1885 UResType elementType
=ures_getType(tagelement
);
1886 CONFIRM_INT_EQ(elementType
, URES_STRING
);
1887 if(strcmp(ures_getKey(tagelement
), item_tag
) == 0){
1892 t
=(UChar
*)ures_getString(tagelement
, &len
, &status
);
1893 if(!U_FAILURE(status
)){
1898 CONFIRM_ErrorCode(status
,U_MISSING_RESOURCE_ERROR
);
1901 if (status
!= U_MISSING_RESOURCE_ERROR
) {
1903 u_strcpy(expected_string
, base
);
1904 u_uastrcpy(element
, itoa1(index
,buf
));
1905 u_strcat(expected_string
, element
);
1906 CONFIRM_EQ(string
,expected_string
);
1910 ures_close(tagelement
);
1913 CONFIRM_INT_EQ(count
, tag_count
);
1915 free(expected_string
);
1916 ures_close(theBundle
);
1919 ures_close(array2d
);
1921 ures_close(arrayItem1
);
1923 return (UBool
)(failNum
== fail
);
1926 static void record_pass()
1931 static void record_fail()
1937 * Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR
1941 static void TestFallback()
1943 UErrorCode status
= U_ZERO_ERROR
;
1944 UResourceBundle
*fr_FR
= NULL
;
1945 UResourceBundle
*subResource
= NULL
;
1946 const UChar
*junk
; /* ignored */
1949 log_verbose("Opening fr_FR..");
1950 fr_FR
= ures_open(NULL
, "fr_FR", &status
);
1951 if(U_FAILURE(status
))
1953 log_err("Couldn't open fr_FR - %d\n", status
);
1957 status
= U_ZERO_ERROR
;
1960 /* clear it out.. just do some calls to get the gears turning */
1961 junk
= ures_getStringByKey(fr_FR
, "LocaleID", &resultLen
, &status
);
1962 status
= U_ZERO_ERROR
;
1963 junk
= ures_getStringByKey(fr_FR
, "LocaleString", &resultLen
, &status
);
1964 status
= U_ZERO_ERROR
;
1965 junk
= ures_getStringByKey(fr_FR
, "LocaleID", &resultLen
, &status
);
1966 status
= U_ZERO_ERROR
;
1968 /* OK first one. This should be a Default value. */
1969 subResource
= ures_getByKey(fr_FR
, "MeasurementSystem", NULL
, &status
);
1970 if(status
!= U_USING_DEFAULT_WARNING
)
1972 log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get CurrencyMap from fr_FR, got %s\n",
1973 u_errorName(status
));
1976 status
= U_ZERO_ERROR
;
1977 ures_close(subResource
);
1979 /* and this is a Fallback, to fr */
1980 junk
= ures_getStringByKey(fr_FR
, "Countries", &resultLen
, &status
);
1981 if(status
!= U_USING_FALLBACK_WARNING
)
1983 log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get Countries from fr_FR, got %d\n",
1987 status
= U_ZERO_ERROR
;
1990 /* Temporary hack err actually should be U_USING_FALLBACK_ERROR */
1991 /* Test Jitterbug 552 fallback mechanism of aliased data */
1993 UErrorCode err
=U_ZERO_ERROR
;
1994 UResourceBundle
* myResB
= ures_open(NULL
,"no_NO_NY",&err
);
1995 UResourceBundle
* resLocID
= ures_getByKey(myResB
, "Version", NULL
, &err
);
1996 UResourceBundle
* tResB
;
1997 static const UChar versionStr
[] = { 0x0031, 0x002E, 0x0032, 0};
1999 if(err
!= U_ZERO_ERROR
){
2000 log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for Version err=%s\n",u_errorName(err
));
2003 if(u_strcmp(ures_getString(resLocID
, &resultLen
, &err
), versionStr
) != 0){
2004 log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value\n");
2006 tResB
= ures_getByKey(myResB
, "calendar", NULL
, &err
);
2007 if(err
!= U_USING_FALLBACK_WARNING
){
2008 log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for calendar err=%s\n",u_errorName(err
));
2010 ures_close(resLocID
);
2018 /* static void printUChars(UChar* uchars){
2020 / for(i=0; i<u_strlen(uchars); i++){
2021 / log_err("%04X ", *(uchars+i));
2025 static void TestResourceLevelAliasing(void) {
2026 UErrorCode status
= U_ZERO_ERROR
;
2027 UResourceBundle
*aliasB
= NULL
, *tb
= NULL
;
2028 UResourceBundle
*en
= NULL
, *uk
= NULL
, *testtypes
= NULL
;
2029 const char* testdatapath
= NULL
;
2030 const UChar
*string
= NULL
, *sequence
= NULL
;
2031 const uint8_t *binary
= NULL
, *binSequence
= NULL
;
2032 int32_t strLen
= 0, seqLen
= 0, binLen
= 0, binSeqLen
= 0;
2036 testdatapath
=loadTestData(&status
);
2037 if(U_FAILURE(status
))
2039 log_err("Could not load testdata.dat %s \n",myErrorName(status
));
2043 aliasB
= ures_open(testdatapath
, "testaliases", &status
);
2045 /* this should fail - circular alias */
2046 tb
= ures_getByKey(aliasB
, "aaa", tb
, &status
);
2047 if(status
!= U_TOO_MANY_ALIASES_ERROR
) {
2048 log_err("Failed to detect circular alias\n");
2050 status
= U_ZERO_ERROR
;
2052 tb
= ures_getByKey(aliasB
, "aab", tb
, &status
);
2053 if(status
!= U_TOO_MANY_ALIASES_ERROR
) {
2054 log_err("Failed to detect circular alias\n");
2056 status
= U_ZERO_ERROR
;
2058 if(U_FAILURE(status
) ) {
2059 log_data_err("err loading tb resource\n");
2061 /* testing aliasing to a non existing resource */
2062 tb
= ures_getByKey(aliasB
, "nonexisting", tb
, &status
);
2063 if(status
!= U_MISSING_RESOURCE_ERROR
) {
2064 log_err("Managed to find an alias to non-existing resource\n");
2066 status
= U_ZERO_ERROR
;
2069 /* testing referencing/composed alias */
2070 uk
= ures_findResource("ja/LocaleScript/2", uk
, &status
);
2071 if((uk
== NULL
) || U_FAILURE(status
)) {
2072 log_err("Couldn't findResource('ja/LocaleScript/2') err %s\n", u_errorName(status
));
2076 sequence
= ures_getString(uk
, &seqLen
, &status
);
2078 tb
= ures_getByKey(aliasB
, "referencingalias", tb
, &status
);
2079 string
= ures_getString(tb
, &strLen
, &status
);
2081 if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2082 log_err("Referencing alias didn't get the right string\n");
2085 string
= ures_getStringByKey(aliasB
, "referencingalias", &strLen
, &status
);
2086 if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2087 log_err("Referencing alias didn't get the right string\n");
2090 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2091 tb
= ures_getByKey(aliasB
, "LocaleScript", tb
, &status
);
2092 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2093 tb
= ures_getByIndex(tb
, 2, tb
, &status
);
2094 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2095 string
= ures_getString(tb
, &strLen
, &status
);
2096 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2098 if(U_FAILURE(status
)) {
2099 log_err("%s trying to get string via separate getters\n", u_errorName(status
));
2100 } else if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2101 log_err("Referencing alias didn't get the right string\n");
2104 /* check whether the binary collation data is properly referenced by an alias */
2105 uk
= ures_findResource("th/BreakDictionaryData", uk
, &status
);
2106 binSequence
= ures_getBinary(uk
, &binSeqLen
, &status
);
2108 tb
= ures_getByKey(aliasB
, "BreakDictionaryData", tb
, &status
);
2109 binary
= ures_getBinary(tb
, &binLen
, &status
);
2111 if(U_FAILURE(status
)) {
2112 log_err("%s trying to read binary BreakDictionaryData\n");
2113 } else if(binSeqLen
!= binLen
|| uprv_memcmp(binSequence
, binary
, binSeqLen
) != 0) {
2114 log_err("Referencing alias didn't get the right data\n");
2118 testtypes
= ures_open(testdatapath
, "testtypes", &status
);
2119 strcpy(buffer
, "menu/file/open");
2121 uk
= ures_findSubResource(testtypes
, s
, uk
, &status
);
2122 sequence
= ures_getString(uk
, &seqLen
, &status
);
2124 tb
= ures_getByKey(aliasB
, "simplealias", tb
, &status
);
2125 string
= ures_getString(tb
, &strLen
, &status
);
2127 if(U_FAILURE(status
) || seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2128 log_err("Referencing alias didn't get the right string\n");
2131 /* test indexed aliasing */
2133 tb
= ures_getByKey(aliasB
, "zoneTests", tb
, &status
);
2134 tb
= ures_getByKey(tb
, "zoneAlias2", tb
, &status
);
2135 string
= ures_getString(tb
, &strLen
, &status
);
2137 en
= ures_findResource("en/zoneStrings/3/0", en
, &status
);
2138 sequence
= ures_getString(en
, &seqLen
, &status
);
2140 if(U_FAILURE(status
) || seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2141 log_err("Referencing alias didn't get the right string\n");
2144 /* test getting aliased string by index */
2146 const char* keys
[] = {
2148 "KeyAlias1PacificStandardTime",
2150 "KeyAlias3LosAngeles"
2153 const char* strings
[] = {
2154 "America/Los_Angeles",
2155 "Pacific Standard Time",
2160 const UChar
* result
;
2161 int32_t uBufferLen
= 0, resultLen
= 0;
2163 const char *key
= NULL
;
2164 tb
= ures_getByKey(aliasB
, "testGetStringByKeyAliasing", tb
, &status
);
2165 if(U_FAILURE(status
)) {
2166 log_err("Couldn't get testGetStringByKeyAliasing resource\n");
2168 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2169 result
= ures_getStringByKey(tb
, keys
[i
], &resultLen
, &status
);
2170 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2171 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2172 log_err("Didn't get correct string while accesing alias table by key (%s)\n", keys
[i
]);
2175 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2176 result
= ures_getStringByIndex(tb
, i
, &resultLen
, &status
);
2177 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2178 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2179 log_err("Didn't get correct string while accesing alias table by index (%s)\n", strings
[i
]);
2182 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2183 result
= ures_getNextString(tb
, &resultLen
, &key
, &status
);
2184 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2185 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2186 log_err("Didn't get correct string while iterating over alias table (%s)\n", strings
[i
]);
2189 tb
= ures_getByKey(aliasB
, "testGetStringByIndexAliasing", tb
, &status
);
2190 if(U_FAILURE(status
)) {
2191 log_err("Couldn't get testGetStringByIndexAliasing resource\n");
2193 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2194 result
= ures_getStringByIndex(tb
, i
, &resultLen
, &status
);
2195 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2196 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2197 log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings
[i
]);
2200 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2201 result
= ures_getNextString(tb
, &resultLen
, &key
, &status
);
2202 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2203 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2204 log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings
[i
]);
2213 ures_close(testtypes
);
2216 static void TestDirectAccess(void) {
2217 UErrorCode status
= U_ZERO_ERROR
;
2218 UResourceBundle
*t
= NULL
, *t2
= NULL
;
2219 const char* key
= NULL
;
2224 t
= ures_findResource("en/zoneStrings/3/2", t
, &status
);
2225 if(U_FAILURE(status
)) {
2226 log_err("Couldn't access indexed resource, error %s\n", u_errorName(status
));
2227 status
= U_ZERO_ERROR
;
2229 key
= ures_getKey(t
);
2231 log_err("Got a strange key, expected NULL, got %s\n", key
);
2234 t
= ures_findResource("en/zoneStrings/3", t
, &status
);
2235 if(U_FAILURE(status
)) {
2236 log_err("Couldn't access indexed resource, error %s\n", u_errorName(status
));
2237 status
= U_ZERO_ERROR
;
2239 key
= ures_getKey(t
);
2241 log_err("Got a strange key, expected NULL, got %s\n", key
);
2245 t
= ures_findResource("ja/LocaleScript", t
, &status
);
2246 if(U_FAILURE(status
)) {
2247 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status
));
2248 status
= U_ZERO_ERROR
;
2250 key
= ures_getKey(t
);
2251 if(strcmp(key
, "LocaleScript")!=0) {
2252 log_err("Got a strange key, expected 'LocaleScript', got %s\n", key
);
2256 t2
= ures_open(NULL
, "sr", &status
);
2257 if(U_FAILURE(status
)) {
2258 log_err("Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status
));
2259 log_data_err("No 'sr', no test - you have bigger problems than testing direct access. "
2260 "You probably have no data! Aborting this test\n");
2263 if(U_SUCCESS(status
)) {
2264 strcpy(buffer
, "Languages/hr");
2266 t
= ures_findSubResource(t2
, s
, t
, &status
);
2267 if(U_FAILURE(status
)) {
2268 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status
));
2269 status
= U_ZERO_ERROR
;
2271 key
= ures_getKey(t
);
2272 if(strcmp(key
, "hr")!=0) {
2273 log_err("Got a strange key, expected 'hr', got %s\n", key
);
2278 t
= ures_findResource("root/calendar/islamic-civil/DateTimePatterns", t
, &status
);
2279 if(U_SUCCESS(status
)) {
2280 log_err("This resource does not exist. How did it get here?\n");
2282 status
= U_ZERO_ERROR
;
2284 /* this one will freeze */
2285 t
= ures_findResource("root/calendar/islamic-civil/eras/abbreviated/0/mikimaus/pera", t
, &status
);
2286 if(U_SUCCESS(status
)) {
2287 log_err("Second resource does not exist. How did it get here?\n");
2289 status
= U_ZERO_ERROR
;
2292 t2
= ures_open(NULL
, "he", &status
);
2293 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2294 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2295 t2
= ures_getByKeyWithFallback(t2
, "DateTimePatterns", t2
, &status
);
2296 if(U_SUCCESS(status
)) {
2297 log_err("This resource does not exist. How did it get here?\n");
2299 status
= U_ZERO_ERROR
;
2302 t2
= ures_open(NULL
, "he", &status
);
2304 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2305 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2306 t2
= ures_getByKeyWithFallback(t2
, "eras", t2
, &status
);
2307 if(U_FAILURE(status
)) {
2308 log_err("Didn't get Eras. I know they are there!\n");
2310 status
= U_ZERO_ERROR
;
2313 t2
= ures_open(NULL
, "root", &status
);
2314 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2315 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2316 t2
= ures_getByKeyWithFallback(t2
, "DateTimePatterns", t2
, &status
);
2317 if(U_SUCCESS(status
)) {
2318 log_err("This resource does not exist. How did it get here?\n");
2320 status
= U_ZERO_ERROR
;
2326 static void TestJB3763(void) {
2327 /* Nasty bug prevented using parent as fill-in, since it would
2328 * stomp the path information.
2330 UResourceBundle
*t
= NULL
;
2331 UErrorCode status
= U_ZERO_ERROR
;
2332 t
= ures_open(NULL
, "sr_Latn", &status
);
2333 t
= ures_getByKeyWithFallback(t
, "calendar", t
, &status
);
2334 t
= ures_getByKeyWithFallback(t
, "gregorian", t
, &status
);
2335 t
= ures_getByKeyWithFallback(t
, "AmPmMarkers", t
, &status
);
2336 if(U_FAILURE(status
)) {
2337 log_err("This resource should be available?\n");
2339 status
= U_ZERO_ERROR
;
2345 static void TestGetKeywordValues(void) {
2346 UEnumeration
*kwVals
;
2347 UBool foundStandard
= FALSE
;
2348 UErrorCode status
= U_ZERO_ERROR
;
2350 #if !UCONFIG_NO_COLLATION
2351 kwVals
= ures_getKeywordValues( U_ICUDATA_COLL
, "collations", &status
);
2353 log_verbose("Testing getting collation keyword values:\n");
2355 while((kw
=uenum_next(kwVals
, NULL
, &status
))) {
2356 log_verbose(" %s\n", kw
);
2357 if(!strcmp(kw
,"standard")) {
2358 if(foundStandard
== FALSE
) {
2359 foundStandard
= TRUE
;
2361 log_err("'standard' was found twice in the keyword list.\n");
2365 if(foundStandard
== FALSE
) {
2366 log_err("'standard' was not found in the keyword list.\n");
2368 uenum_close(kwVals
);
2369 if(U_FAILURE(status
)) {
2370 log_err("err %s getting collation values\n", u_errorName(status
));
2372 status
= U_ZERO_ERROR
;
2374 foundStandard
= FALSE
;
2375 kwVals
= ures_getKeywordValues( "ICUDATA", "calendar", &status
);
2377 log_verbose("Testing getting calendar keyword values:\n");
2379 while((kw
=uenum_next(kwVals
, NULL
, &status
))) {
2380 log_verbose(" %s\n", kw
);
2381 if(!strcmp(kw
,"japanese")) {
2382 if(foundStandard
== FALSE
) {
2383 foundStandard
= TRUE
;
2385 log_err("'japanese' was found twice in the calendar keyword list.\n");
2389 if(foundStandard
== FALSE
) {
2390 log_err("'japanese' was not found in the calendar keyword list.\n");
2392 uenum_close(kwVals
);
2393 if(U_FAILURE(status
)) {
2394 log_err("err %s getting calendar values\n", u_errorName(status
));
2398 static void TestGetFunctionalEquivalentOf(const char *path
, const char *resName
, const char *keyword
, UBool truncate
, const char *testCases
[]) {
2400 for(i
=0;testCases
[i
];i
+=3) {
2401 UBool expectAvail
= (testCases
[i
][0]=='t')?TRUE
:FALSE
;
2402 UBool gotAvail
= FALSE
;
2403 const char *inLocale
= testCases
[i
+1];
2404 const char *expectLocale
= testCases
[i
+2];
2405 char equivLocale
[256];
2407 UErrorCode status
= U_ZERO_ERROR
;
2408 log_verbose("%d: %c %s\texpect %s\n",i
/3, expectAvail
?'t':'f', inLocale
, expectLocale
);
2409 len
= ures_getFunctionalEquivalent(equivLocale
, 255, path
,
2410 resName
, keyword
, inLocale
,
2411 &gotAvail
, truncate
, &status
);
2412 if(U_FAILURE(status
) || (len
<= 0)) {
2413 log_err("FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n",
2414 len
, u_errorName(status
),
2415 i
/3,expectAvail
?'t':'f', inLocale
, expectLocale
);
2417 log_verbose("got: %c %s\n", expectAvail
?'t':'f',equivLocale
);
2419 if((gotAvail
!= expectAvail
) || strcmp(equivLocale
, expectLocale
)) {
2420 log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
2421 gotAvail
?'t':'f', equivLocale
,
2423 expectAvail
?'t':'f', inLocale
, expectLocale
);
2430 static void TestGetFunctionalEquivalent(void) {
2431 static const char *collCases
[] = {
2432 /* avail locale equiv */
2433 "f", "de_US_CALIFORNIA", "de",
2434 "t", "zh_TW@collation=stroke", "zh@collation=stroke",
2435 "f", "de_CN@collation=pinyin", "de",
2436 "t", "zh@collation=pinyin", "zh",
2437 "t", "zh_CN@collation=pinyin", "zh", /* should be 'T' when validSubLocales works */
2438 "t", "zh_HK@collation=pinyin", "zh",
2439 "t", "zh_HK@collation=stroke", "zh@collation=stroke",
2440 "t", "zh_HK", "zh@collation=stroke",
2441 "t", "zh_MO", "zh@collation=stroke",
2442 "t", "zh_TW_STROKE", "zh@collation=stroke",
2443 "t", "zh_TW_STROKE@collation=big5han", "zh@collation=big5han",
2444 "f", "de_CN@calendar=japanese", "de",
2445 "t", "de@calendar=japanese", "de",
2446 "t", "zh_TW@collation=big5han", "zh@collation=big5han",
2447 "t", "zh_TW@collation=gb2312han", "zh@collation=gb2312han",
2448 "t", "zh_CN@collation=big5han", "zh@collation=big5han",
2449 "t", "zh_CN@collation=gb2312han", "zh@collation=gb2312han",
2450 "t", "zh@collation=big5han", "zh@collation=big5han",
2451 "t", "zh@collation=gb2312han", "zh@collation=gb2312han",
2452 "t", "hi_IN@collation=direct", "hi@collation=direct",
2453 "t", "hi@collation=standard", "hi",
2454 "t", "hi@collation=direct", "hi@collation=direct",
2455 "f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct",
2456 "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
2460 static const char *calCases
[] = {
2461 /* avail locale equiv */
2462 "t", "en_US", "en@calendar=gregorian",
2463 "f", "ja_JP_TOKYO", "ja@calendar=gregorian",
2464 "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
2465 "t", "sr@calendar=gregorian", "sr@calendar=gregorian",
2466 "t", "en", "en@calendar=gregorian",
2470 #if !UCONFIG_NO_COLLATION
2471 TestGetFunctionalEquivalentOf(U_ICUDATA_COLL
, "collations", "collation", TRUE
, collCases
);
2473 TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE
, calCases
);
2475 #if !UCONFIG_NO_COLLATION
2476 log_verbose("Testing error conditions:\n");
2478 char equivLocale
[256] = "???";
2480 UErrorCode status
= U_ZERO_ERROR
;
2481 UBool gotAvail
= FALSE
;
2483 len
= ures_getFunctionalEquivalent(equivLocale
, 255, U_ICUDATA_COLL
,
2484 "calendar", "calendar", "ar_EG@calendar=islamic",
2485 &gotAvail
, FALSE
, &status
);
2487 if(status
== U_MISSING_RESOURCE_ERROR
) {
2488 log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n");
2490 log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n",
2491 equivLocale
, gotAvail
?'t':'f', u_errorName(status
));