1 /********************************************************************
3 * Copyright (c) 1997-2008, 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 #include "ubrkimpl.h" /* for U_ICUDATA_BRKITR */
29 #define RESTEST_HEAP_CHECK 0
31 #include "unicode/uloc.h"
34 #include "unicode/ctest.h"
39 /*****************************************************************************/
41 * Return a random unsigned long l where 0N <= l <= ULONG_MAX.
49 static UBool initialized
= FALSE
;
52 srand((unsigned)time(NULL
));
55 /* Assume rand has at least 12 bits of precision */
57 for (i
=0; i
<sizeof(l
); ++i
)
58 ((char*)&l
)[i
] = (char)((rand() & 0x0FF0) >> 4);
63 * Return a random double x where 0.0 <= x < 1.0.
68 return ((double)randul()) / UINT32_MAX
;
72 * Return a random integer i where 0 <= i < n.
74 static int32_t randi(int32_t n
)
76 return (int32_t)(randd() * n
);
78 /***************************************************************************************/
80 * Convert an integer, positive or negative, to a character string radix 10.
83 itoa1(int32_t i
, char* buf
)
93 /* Output digits in reverse order */
96 *p
++ = (char)('0' + (i
% 10));
102 /* Reverse the string */
111 static const int32_t kERROR_COUNT
= -1234567;
112 static const UChar kERROR
[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/,
113 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/};
115 /*****************************************************************************/
124 typedef enum E_Where E_Where
;
125 /*****************************************************************************/
127 #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)); }
128 #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); }
129 #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); }
130 #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); }
131 /*#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 CONFIRM_ErrorCode(UErrorCode actual
,UErrorCode expected
)
135 if ((expected
)==(actual
))
140 /*log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); */
141 log_err("returned %s instead of %s\n", myErrorName(actual
), myErrorName(expected
));
146 /* Array of our test objects */
151 UErrorCode expected_constructor_status
;
153 UBool like
[e_Where_count
];
154 UBool inherits
[e_Where_count
];
158 /* "te" means test */
159 /* "IN" means inherits */
160 /* "NE" or "ne" means "does not exist" */
162 { "root", U_ZERO_ERROR
, e_Root
, { TRUE
, FALSE
, FALSE
}, { TRUE
, FALSE
, FALSE
} },
163 { "te", U_ZERO_ERROR
, e_te
, { FALSE
, TRUE
, FALSE
}, { TRUE
, TRUE
, FALSE
} },
164 { "te_IN", U_ZERO_ERROR
, e_te_IN
, { FALSE
, FALSE
, TRUE
}, { TRUE
, TRUE
, TRUE
} },
165 { "te_NE", U_USING_FALLBACK_WARNING
, e_te
, { FALSE
, TRUE
, FALSE
}, { TRUE
, TRUE
, FALSE
} },
166 { "te_IN_NE", U_USING_FALLBACK_WARNING
, e_te_IN
, { FALSE
, FALSE
, TRUE
}, { TRUE
, TRUE
, TRUE
} },
167 { "ne", U_USING_DEFAULT_WARNING
, e_Root
, { TRUE
, FALSE
, FALSE
}, { TRUE
, FALSE
, FALSE
} }
170 static int32_t bundles_count
= sizeof(param
) / sizeof(param
[0]);
173 /*static void printUChars(UChar*);*/
174 static void TestDecodedBundle(void);
175 static void TestGetKeywordValues(void);
176 static void TestGetFunctionalEquivalent(void);
177 static void TestCLDRStyleAliases(void);
178 static void TestFallbackCodes(void);
179 static void TestGetUTF8String(void);
181 /***************************************************************************************/
183 /* Array of our test objects */
185 void addNEWResourceBundleTest(TestNode
** root
)
187 addTest(root
, &TestErrorCodes
, "tsutil/creststn/TestErrorCodes");
188 addTest(root
, &TestEmptyBundle
, "tsutil/creststn/TestEmptyBundle");
189 addTest(root
, &TestConstruction1
, "tsutil/creststn/TestConstruction1");
190 addTest(root
, &TestResourceBundles
, "tsutil/creststn/TestResourceBundles");
191 addTest(root
, &TestFallback
, "tsutil/creststn/TestFallback");
192 addTest(root
, &TestGetVersion
, "tsutil/creststn/TestGetVersion");
193 addTest(root
, &TestGetVersionColl
, "tsutil/creststn/TestGetVersionColl");
194 addTest(root
, &TestAliasConflict
, "tsutil/creststn/TestAliasConflict");
195 addTest(root
, &TestNewTypes
, "tsutil/creststn/TestNewTypes");
196 addTest(root
, &TestEmptyTypes
, "tsutil/creststn/TestEmptyTypes");
197 addTest(root
, &TestBinaryCollationData
, "tsutil/creststn/TestBinaryCollationData");
198 addTest(root
, &TestAPI
, "tsutil/creststn/TestAPI");
199 addTest(root
, &TestErrorConditions
, "tsutil/creststn/TestErrorConditions");
200 addTest(root
, &TestDecodedBundle
, "tsutil/creststn/TestDecodedBundle");
201 addTest(root
, &TestResourceLevelAliasing
, "tsutil/creststn/TestResourceLevelAliasing");
202 addTest(root
, &TestDirectAccess
, "tsutil/creststn/TestDirectAccess");
203 addTest(root
, &TestGetKeywordValues
, "tsutil/creststn/TestGetKeywordValues");
204 addTest(root
, &TestGetFunctionalEquivalent
,"tsutil/creststn/TestGetFunctionalEquivalent");
205 addTest(root
, &TestJB3763
, "tsutil/creststn/TestJB3763");
206 addTest(root
, &TestXPath
, "tsutil/creststn/TestXPath");
207 addTest(root
, &TestCLDRStyleAliases
, "tsutil/creststn/TestCLDRStyleAliases");
208 addTest(root
, &TestFallbackCodes
, "tsutil/creststn/TestFallbackCodes");
209 addTest(root
, &TestStackReuse
, "tsutil/creststn/TestStackReuse");
210 addTest(root
, &TestGetUTF8String
, "tsutil/creststn/TestGetUTF8String");
214 /***************************************************************************************/
215 static const char* norwayNames
[] = {
225 static const char* norwayLocales
[] = {
235 static void checkStatus(int32_t line
, UErrorCode expected
, UErrorCode status
) {
236 if(U_FAILURE(status
)) {
237 log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__
, line
);
239 if(status
!= expected
) {
240 log_err("%s:%d: Expected error code %s, got error code %s\n", __FILE__
, line
, u_errorName(expected
), u_errorName(status
));
244 static void TestErrorCodes(void) {
245 UErrorCode status
= U_USING_DEFAULT_WARNING
;
247 UResourceBundle
*r
= NULL
, *r2
= NULL
;
249 /* First check with ICUDATA */
250 /* first bundle should return fallback warning */
251 r
= ures_open(NULL
, "ti_ER_ASSAB", &status
);
252 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
255 /* this bundle should return zero error, so it shouldn't change the status*/
256 status
= U_USING_DEFAULT_WARNING
;
257 r
= ures_open(NULL
, "ti_ER", &status
);
258 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
260 /* we look up the resource which is aliased, but it lives in fallback */
261 if(U_SUCCESS(status
) && r
!= NULL
) {
262 status
= U_USING_DEFAULT_WARNING
;
263 r2
= ures_getByKey(r
, "Languages", NULL
, &status
); /* languages of 'ti' aliases to 'am' */
264 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
268 /* this bundle should return zero error, so it shouldn't change the status*/
269 status
= U_USING_DEFAULT_WARNING
;
270 r
= ures_open(NULL
, "ti", &status
);
271 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
273 /* we look up the resource which is aliased and at our level */
274 if(U_SUCCESS(status
) && r
!= NULL
) {
275 status
= U_USING_DEFAULT_WARNING
;
276 r2
= ures_getByKey(r
, "Languages", r2
, &status
);
277 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
281 status
= U_USING_FALLBACK_WARNING
;
282 r
= ures_open(NULL
, "nolocale", &status
);
283 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
287 /** Now, with the collation bundle **/
289 /* first bundle should return fallback warning */
290 r
= ures_open(U_ICUDATA_COLL
, "sr_YU_VOJVODINA", &status
);
291 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
294 /* this bundle should return zero error, so it shouldn't change the status*/
295 status
= U_USING_FALLBACK_WARNING
;
296 r
= ures_open(U_ICUDATA_COLL
, "sr", &status
);
297 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
299 /* we look up the resource which is aliased */
300 if(U_SUCCESS(status
) && r
!= NULL
) {
301 status
= U_USING_DEFAULT_WARNING
;
302 r2
= ures_getByKey(r
, "collations", NULL
, &status
);
303 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
307 /* this bundle should return zero error, so it shouldn't change the status*/
308 status
= U_USING_DEFAULT_WARNING
;
309 r
= ures_open(U_ICUDATA_COLL
, "sr", &status
);
310 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
312 /* we look up the resource which is aliased and at our level */
313 if(U_SUCCESS(status
) && r
!= NULL
) {
314 status
= U_USING_DEFAULT_WARNING
;
315 r2
= ures_getByKey(r
, "collations", r2
, &status
);
316 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
320 status
= U_USING_FALLBACK_WARNING
;
321 r
= ures_open(U_ICUDATA_COLL
, "nolocale", &status
);
322 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
327 static void TestAliasConflict(void) {
328 UErrorCode status
= U_ZERO_ERROR
;
329 UResourceBundle
*he
= NULL
;
330 UResourceBundle
*iw
= NULL
;
331 UResourceBundle
*norway
= NULL
;
332 const UChar
*result
= NULL
;
336 const char *realName
= NULL
;
338 he
= ures_open(NULL
, "he", &status
);
339 iw
= ures_open(NULL
, "iw", &status
);
340 if(U_FAILURE(status
)) {
341 log_err("Failed to get resource with %s\n", myErrorName(status
));
344 result
= ures_getStringByKey(he
, "ExemplarCharacters", &resultLen
, &status
);
345 if(U_FAILURE(status
) || result
== NULL
) {
346 log_err("Failed to get resource ExemplarCharacters with %s\n", myErrorName(status
));
350 size
= sizeof(norwayNames
)/sizeof(norwayNames
[0]);
351 for(i
= 0; i
< size
; i
++) {
352 status
= U_ZERO_ERROR
;
353 norway
= ures_open(NULL
, norwayNames
[i
], &status
);
354 if(U_FAILURE(status
)) {
355 log_err("Failed to get resource with %s for %s\n", myErrorName(status
), norwayNames
[i
]);
358 realName
= ures_getLocale(norway
, &status
);
359 log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames
[i
], realName
);
360 if(realName
== NULL
|| strcmp(norwayLocales
[i
], realName
) != 0) {
361 log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames
[i
], norwayLocales
[i
], realName
);
367 static void TestDecodedBundle(){
369 UErrorCode error
= U_ZERO_ERROR
;
371 UResourceBundle
* resB
;
373 const UChar
* srcFromRes
;
375 static const UChar uSrc
[] = {
376 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F,
377 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928,
378 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A,
379 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938,
380 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020,
381 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938,
382 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947,
383 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020,
384 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915,
385 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E,
386 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917,
387 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D,
388 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020,
389 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915,
390 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B,
391 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E,
392 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902,
393 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932,
394 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F,
395 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938,
396 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930,
397 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020,
398 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020,
399 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F,
400 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C,
401 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941,
402 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917,
403 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E,
404 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930,
405 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E,
406 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,
407 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,
408 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935,
409 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915,
410 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F,
411 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033,
412 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F,
413 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915,
414 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020,
420 const char *testdatapath
= loadTestData(&error
);
421 resB
= ures_open(testdatapath
, "iscii", &error
);
422 srcFromRes
=tres_getString(resB
,-1,"str",&len
,&error
);
423 if(U_FAILURE(error
)){
424 #if UCONFIG_NO_LEGACY_CONVERSION
425 log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION is turned on)\n");
427 log_data_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error
));
432 if(u_strncmp(srcFromRes
,uSrc
,len
)!=0){
433 log_err("Genrb produced res files after decoding failed\n");
436 if(uSrc
[num
]!=srcFromRes
[num
]){
437 log_verbose(" Expected: 0x%04X Got: 0x%04X \n", uSrc
[num
],srcFromRes
[num
]);
441 if (len
!= u_strlen(uSrc
)) {
442 log_err("Genrb produced a string larger than expected\n");
447 static void TestNewTypes() {
448 UResourceBundle
* theBundle
= NULL
;
450 const char* testdatapath
;
451 UErrorCode status
= U_ZERO_ERROR
;
452 UResourceBundle
* res
= NULL
;
453 uint8_t *binResult
= NULL
;
456 int32_t intResult
= 0;
457 uint32_t uintResult
= 0;
458 const UChar
*empty
= NULL
;
459 const UChar
*zeroString
;
460 UChar expected
[] = { 'a','b','c','\0','d','e','f' };
461 const char* expect
="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
464 testdatapath
=loadTestData(&status
);
466 if(U_FAILURE(status
))
468 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
472 theBundle
= ures_open(testdatapath
, "testtypes", &status
);
474 empty
= tres_getString(theBundle
, -1, "emptystring", &len
, &status
);
475 if(empty
&& (*empty
!= 0 || len
!= 0)) {
476 log_err("Empty string returned invalid value\n");
479 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
481 CONFIRM_INT_NE(theBundle
, NULL
);
483 /* This test reads the string "abc\u0000def" from the bundle */
484 /* if everything is working correctly, the size of this string */
485 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
487 strcpy(action
, "getting and testing of string with embeded zero");
488 res
= ures_getByKey(theBundle
, "zerotest", res
, &status
);
489 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
490 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
491 zeroString
=tres_getString(res
, -1, NULL
, &len
, &status
);
492 if(U_SUCCESS(status
)){
493 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
494 CONFIRM_INT_EQ(len
, 7);
495 CONFIRM_INT_NE(len
, 3);
498 if(zeroString
[i
]!= expected
[i
]){
499 log_verbose("Output did not match Expected: \\u%4X Got: \\u%4X", expected
[i
], zeroString
[i
]);
503 strcpy(action
, "getting and testing of binary type");
504 res
= ures_getByKey(theBundle
, "binarytest", res
, &status
);
505 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
506 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
507 binResult
=(uint8_t*)ures_getBinary(res
, &len
, &status
);
508 if(U_SUCCESS(status
)){
509 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
510 CONFIRM_INT_EQ(len
, 15);
511 for(i
= 0; i
<15; i
++) {
512 CONFIRM_INT_EQ(binResult
[i
], i
);
516 strcpy(action
, "getting and testing of imported binary type");
517 res
= ures_getByKey(theBundle
, "importtest", res
, &status
);
518 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
519 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
520 binResult
=(uint8_t*)ures_getBinary(res
, &len
, &status
);
521 if(U_SUCCESS(status
)){
522 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
523 CONFIRM_INT_EQ(len
, 15);
524 for(i
= 0; i
<15; i
++) {
525 CONFIRM_INT_EQ(binResult
[i
], i
);
529 strcpy(action
, "getting and testing of integer types");
530 res
= ures_getByKey(theBundle
, "one", res
, &status
);
531 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
532 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
533 intResult
=ures_getInt(res
, &status
);
534 uintResult
= ures_getUInt(res
, &status
);
535 if(U_SUCCESS(status
)){
536 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
537 CONFIRM_INT_EQ(uintResult
, (uint32_t)intResult
);
538 CONFIRM_INT_EQ(intResult
, 1);
541 strcpy(action
, "getting minusone");
542 res
= ures_getByKey(theBundle
, "minusone", res
, &status
);
543 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
544 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
545 intResult
=ures_getInt(res
, &status
);
546 uintResult
= ures_getUInt(res
, &status
);
547 if(U_SUCCESS(status
)){
548 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
549 CONFIRM_INT_EQ(uintResult
, 0x0FFFFFFF); /* a 28 bit integer */
550 CONFIRM_INT_EQ(intResult
, -1);
551 CONFIRM_INT_NE(uintResult
, (uint32_t)intResult
);
554 strcpy(action
, "getting plusone");
555 res
= ures_getByKey(theBundle
, "plusone", res
, &status
);
556 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
557 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
558 intResult
=ures_getInt(res
, &status
);
559 uintResult
= ures_getUInt(res
, &status
);
560 if(U_SUCCESS(status
)){
561 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
562 CONFIRM_INT_EQ(uintResult
, (uint32_t)intResult
);
563 CONFIRM_INT_EQ(intResult
, 1);
566 res
= ures_getByKey(theBundle
, "onehundredtwentythree", res
, &status
);
567 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
568 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
569 intResult
=ures_getInt(res
, &status
);
570 if(U_SUCCESS(status
)){
571 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
572 CONFIRM_INT_EQ(intResult
, 123);
575 /* this tests if escapes are preserved or not */
577 const UChar
* str
= tres_getString(theBundle
,-1,"testescape",&len
,&status
);
578 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
579 if(U_SUCCESS(status
)){
580 u_charsToUChars(expect
,uExpect
,(int32_t)strlen(expect
)+1);
581 if(u_strcmp(uExpect
,str
)){
582 log_err("Did not get the expected string for testescape\n");
586 /* this tests if unescaping works are expected */
589 char pattern
[2048] = "";
591 UChar
* expectedEscaped
;
595 /* This strcpy fixes compiler warnings about long strings */
596 strcpy(pattern
, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
597 "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F "
598 "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 "
599 "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD "
600 "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF "
603 "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF "
604 "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF "
605 "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF "
606 "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB "
607 "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C "
610 "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F "
614 patternLen
= (int32_t)uprv_strlen(pattern
);
615 expectedEscaped
= (UChar
*)malloc(U_SIZEOF_UCHAR
* patternLen
);
616 got
= tres_getString(theBundle
,-1,"test_unescaping",&len
,&status
);
617 expectedLen
= u_unescape(pattern
,expectedEscaped
,patternLen
);
618 if(got
==NULL
|| u_strncmp(expectedEscaped
,got
,expectedLen
)!=0 || expectedLen
!= len
){
619 log_err("genrb failed to unescape string\n");
622 for(i
=0;i
<expectedLen
;i
++){
623 if(expectedEscaped
[i
] != got
[i
]){
624 log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped
[i
], got
[i
]);
628 free(expectedEscaped
);
629 status
= U_ZERO_ERROR
;
631 /* test for jitterbug#1435 */
633 const UChar
* str
= tres_getString(theBundle
,-1,"test_underscores",&len
,&status
);
634 expect
="test message ....";
635 u_charsToUChars(expect
,uExpect
,(int32_t)strlen(expect
)+1);
636 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
637 if(str
== NULL
|| u_strcmp(uExpect
,str
)){
638 log_err("Did not get the expected string for test_underscores.\n");
641 /* test for jitterbug#2626 */
642 #if !UCONFIG_NO_COLLATION
644 UResourceBundle
* resB
= NULL
;
645 const UChar
* str
= NULL
;
646 int32_t strLength
= 0;
647 const UChar my
[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */
648 status
= U_ZERO_ERROR
;
649 resB
= ures_getByKey(theBundle
, "collations", resB
, &status
);
650 resB
= ures_getByKey(resB
, "standard", resB
, &status
);
651 str
= tres_getString(resB
,-1,"Sequence",&strLength
,&status
);
652 if(!str
|| U_FAILURE(status
)) {
653 log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status
));
654 } else if(u_strcmp(my
,str
) != 0){
655 log_err("Did not get the expected string for escaped \\u0075\n");
661 const char *sourcePath
= ctest_dataSrcDir();
662 int32_t srcPathLen
= (int32_t)strlen(sourcePath
);
663 const char *deltaPath
= ".."U_FILE_SEP_STRING
"test"U_FILE_SEP_STRING
"testdata"U_FILE_SEP_STRING
;
664 int32_t deltaPathLen
= (int32_t)strlen(deltaPath
);
665 char *testDataFileName
= (char *) malloc( srcPathLen
+ deltaPathLen
+ 50 );
666 char *path
= testDataFileName
;
668 strcpy(path
, sourcePath
);
670 strcpy(path
, deltaPath
);
671 path
+= deltaPathLen
;
672 status
= U_ZERO_ERROR
;
675 const UChar
* str
= tres_getString(theBundle
, -1, "testincludeUTF",&strLen
,&status
);
676 strcpy(path
, "riwords.txt");
677 path
[strlen("riwords.txt")]=0;
678 if(U_FAILURE(status
)){
679 log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status
));
682 const char* cp
= NULL
;
683 UCHARBUF
* ucbuf
= ucbuf_open(testDataFileName
,&cp
,FALSE
,FALSE
,&status
);
685 if(U_SUCCESS(status
)){
686 const UChar
* buffer
= ucbuf_getBuffer(ucbuf
,&len
,&status
);
687 if(U_SUCCESS(status
)){
688 /* verify the contents */
690 log_err("Did not get the expected len for riwords. Expected: %i , Got: %i\n", len
,strLen
);
692 /* test string termination */
693 if(u_strlen(str
) != strLen
|| str
[strLen
]!= 0 ){
694 log_err("testinclude not null terminated!\n");
696 if(u_strncmp(str
, buffer
,strLen
)!=0){
697 log_err("Did not get the expected string from riwords. Include functionality failed for genrb.\n");
700 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName
, u_errorName(status
));
705 log_err("Could not get riwords.txt (path : %s). Error: %s\n",testDataFileName
,u_errorName(status
));
709 status
= U_ZERO_ERROR
;
712 const UChar
* str
= tres_getString(theBundle
, -1, "testinclude",&strLen
,&status
);
713 strcpy(path
, "translit_rules.txt");
714 path
[strlen("translit_rules.txt")]=0;
716 if(U_FAILURE(status
)){
717 log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status
));
721 UCHARBUF
* ucbuf
= ucbuf_open(testDataFileName
,&cp
,FALSE
,FALSE
,&status
);
723 if(U_SUCCESS(status
)){
724 const UChar
* buffer
= ucbuf_getBuffer(ucbuf
,&len
,&status
);
725 if(U_SUCCESS(status
)){
726 /* verify the contents */
728 log_err("Did not get the expected len for translit_rules. Expected: %i , Got: %i\n", len
,strLen
);
730 if(u_strncmp(str
, buffer
,strLen
)!=0){
731 log_err("Did not get the expected string from translit_rules. Include functionality failed for genrb.\n");
734 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName
, u_errorName(status
));
738 log_err("Could not get translit_rules.txt (path : %s). Error: %s\n",testDataFileName
,u_errorName(status
));
742 free(testDataFileName
);
745 ures_close(theBundle
);
749 static void TestEmptyTypes() {
750 UResourceBundle
* theBundle
= NULL
;
752 const char* testdatapath
;
753 UErrorCode status
= U_ZERO_ERROR
;
754 UResourceBundle
* res
= NULL
;
755 UResourceBundle
* resArray
= NULL
;
756 const uint8_t *binResult
= NULL
;
758 int32_t intResult
= 0;
759 const UChar
*zeroString
;
760 const int32_t *zeroIntVect
;
762 strcpy(action
, "Construction of testtypes bundle");
763 testdatapath
=loadTestData(&status
);
764 if(U_FAILURE(status
))
766 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
770 theBundle
= ures_open(testdatapath
, "testtypes", &status
);
772 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
774 CONFIRM_INT_NE(theBundle
, NULL
);
776 /* This test reads the string "abc\u0000def" from the bundle */
777 /* if everything is working correctly, the size of this string */
778 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
780 status
= U_ZERO_ERROR
;
781 strcpy(action
, "getting and testing of explicit string of zero length string");
782 res
= ures_getByKey(theBundle
, "emptyexplicitstring", res
, &status
);
783 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
784 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
785 zeroString
=tres_getString(res
, -1, NULL
, &len
, &status
);
786 if(U_SUCCESS(status
)){
787 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
788 CONFIRM_INT_EQ(len
, 0);
789 CONFIRM_INT_EQ(u_strlen(zeroString
), 0);
792 log_err("Couldn't get emptyexplicitstring\n");
795 status
= U_ZERO_ERROR
;
796 strcpy(action
, "getting and testing of normal string of zero length string");
797 res
= ures_getByKey(theBundle
, "emptystring", res
, &status
);
798 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
799 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
800 zeroString
=tres_getString(res
, -1, NULL
, &len
, &status
);
801 if(U_SUCCESS(status
)){
802 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
803 CONFIRM_INT_EQ(len
, 0);
804 CONFIRM_INT_EQ(u_strlen(zeroString
), 0);
807 log_err("Couldn't get emptystring\n");
810 status
= U_ZERO_ERROR
;
811 strcpy(action
, "getting and testing of empty int");
812 res
= ures_getByKey(theBundle
, "emptyint", res
, &status
);
813 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
814 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
815 intResult
=ures_getInt(res
, &status
);
816 if(U_SUCCESS(status
)){
817 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
818 CONFIRM_INT_EQ(intResult
, 0);
821 log_err("Couldn't get emptystring\n");
824 status
= U_ZERO_ERROR
;
825 strcpy(action
, "getting and testing of zero length intvector");
826 res
= ures_getByKey(theBundle
, "emptyintv", res
, &status
);
827 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
828 CONFIRM_INT_EQ(ures_getType(res
), URES_INT_VECTOR
);
830 if(U_FAILURE(status
)){
831 log_err("Couldn't get emptyintv key %s\n", u_errorName(status
));
834 zeroIntVect
=ures_getIntVector(res
, &len
, &status
);
835 if(!U_SUCCESS(status
) || resArray
!= NULL
|| len
!= 0) {
836 log_err("Shouldn't get emptyintv\n");
840 status
= U_ZERO_ERROR
;
841 strcpy(action
, "getting and testing of zero length emptybin");
842 res
= ures_getByKey(theBundle
, "emptybin", res
, &status
);
843 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
844 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
846 if(U_FAILURE(status
)){
847 log_err("Couldn't get emptybin key %s\n", u_errorName(status
));
850 binResult
=ures_getBinary(res
, &len
, &status
);
851 if(!U_SUCCESS(status
) || binResult
!= NULL
|| len
!= 0) {
852 log_err("Shouldn't get emptybin\n");
856 status
= U_ZERO_ERROR
;
857 strcpy(action
, "getting and testing of zero length emptyarray");
858 res
= ures_getByKey(theBundle
, "emptyarray", res
, &status
);
859 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
860 CONFIRM_INT_EQ(ures_getType(res
), URES_ARRAY
);
862 if(U_FAILURE(status
)){
863 log_err("Couldn't get emptyarray key %s\n", u_errorName(status
));
866 resArray
=ures_getByIndex(res
, 0, resArray
, &status
);
867 if(U_SUCCESS(status
) || resArray
!= NULL
){
868 log_err("Shouldn't get emptyarray\n");
872 status
= U_ZERO_ERROR
;
873 strcpy(action
, "getting and testing of zero length emptytable");
874 res
= ures_getByKey(theBundle
, "emptytable", res
, &status
);
875 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
876 CONFIRM_INT_EQ(ures_getType(res
), URES_TABLE
);
878 if(U_FAILURE(status
)){
879 log_err("Couldn't get emptytable key %s\n", u_errorName(status
));
882 resArray
=ures_getByIndex(res
, 0, resArray
, &status
);
883 if(U_SUCCESS(status
) || resArray
!= NULL
){
884 log_err("Shouldn't get emptytable\n");
889 ures_close(theBundle
);
892 static void TestEmptyBundle(){
893 UErrorCode status
= U_ZERO_ERROR
;
894 const char* testdatapath
=NULL
;
895 UResourceBundle
*resb
=0, *dResB
=0;
897 testdatapath
=loadTestData(&status
);
898 if(U_FAILURE(status
))
900 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
903 resb
= ures_open(testdatapath
, "testempty", &status
);
905 if(U_SUCCESS(status
)){
906 dResB
= ures_getByKey(resb
,"test",dResB
,&status
);
907 if(status
!= U_MISSING_RESOURCE_ERROR
){
908 log_err("Did not get the expected error from an empty resource bundle. Expected : %s Got: %s\n",
909 u_errorName(U_MISSING_RESOURCE_ERROR
),u_errorName(status
));
916 static void TestBinaryCollationData(){
917 UErrorCode status
=U_ZERO_ERROR
;
918 const char* locale
="te";
919 #if !UCONFIG_NO_COLLATION
920 const char* testdatapath
;
922 UResourceBundle
*teRes
= NULL
;
923 UResourceBundle
*coll
=NULL
;
924 UResourceBundle
*binColl
= NULL
;
925 uint8_t *binResult
= NULL
;
927 const char* action
="testing the binary collaton data";
929 #if !UCONFIG_NO_COLLATION
930 log_verbose("Testing binary collation data resource......\n");
932 testdatapath
=loadTestData(&status
);
933 if(U_FAILURE(status
))
935 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
940 teRes
=ures_open(testdatapath
, locale
, &status
);
941 if(U_FAILURE(status
)){
942 log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status
));
946 coll
= ures_getByKey(teRes
, "collations", coll
, &status
);
947 coll
= ures_getByKey(coll
, "standard", coll
, &status
);
948 if(U_SUCCESS(status
)){
949 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
950 CONFIRM_INT_EQ(ures_getType(coll
), URES_TABLE
);
951 binColl
=ures_getByKey(coll
, "%%CollationBin", binColl
, &status
);
952 if(U_SUCCESS(status
)){
953 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
954 CONFIRM_INT_EQ(ures_getType(binColl
), URES_BINARY
);
955 binResult
=(uint8_t*)ures_getBinary(binColl
, &len
, &status
);
956 if(U_SUCCESS(status
)){
957 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
958 CONFIRM_INT_GE(len
, 1);
962 log_err("ERROR: ures_getByKey(locale(te), %%CollationBin) failed\n");
966 log_err("ERROR: ures_getByKey(locale(te), collations) failed\n");
975 static void TestAPI() {
976 UErrorCode status
=U_ZERO_ERROR
;
978 const char* key
=NULL
;
979 const UChar
* value
=NULL
;
980 const char* testdatapath
;
981 UChar
* utestdatapath
=NULL
;
982 char convOutput
[256];
983 UChar largeBuffer
[1025];
984 UResourceBundle
*teRes
= NULL
;
985 UResourceBundle
*teFillin
=NULL
;
986 UResourceBundle
*teFillin2
=NULL
;
988 log_verbose("Testing ures_openU()......\n");
990 testdatapath
=loadTestData(&status
);
991 if(U_FAILURE(status
))
993 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
996 len
=(int32_t)strlen(testdatapath
);
997 utestdatapath
= (UChar
*) malloc((len
+10)*sizeof(UChar
));
999 u_charsToUChars(testdatapath
, utestdatapath
, (int32_t)strlen(testdatapath
)+1);
1000 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) && U_FILE_SEP_CHAR == '\\'
1002 /* Convert all backslashes to forward slashes so that we can make sure that ures_openU
1003 can handle invariant characters. */
1005 while ((backslash
= u_strchr(utestdatapath
, 0x005C))) {
1006 *backslash
= 0x002F;
1011 u_memset(largeBuffer
, 0x0030, sizeof(largeBuffer
)/sizeof(largeBuffer
[0]));
1012 largeBuffer
[sizeof(largeBuffer
)/sizeof(largeBuffer
[0])-1] = 0;
1014 /*Test ures_openU */
1016 status
= U_ZERO_ERROR
;
1017 ures_close(ures_openU(largeBuffer
, "root", &status
));
1018 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1019 log_err("ERROR: ures_openU() worked when the path is very large. It returned %s\n", myErrorName(status
));
1022 status
= U_ZERO_ERROR
;
1023 ures_close(ures_openU(NULL
, "root", &status
));
1024 if(U_FAILURE(status
)){
1025 log_err("ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status
));
1028 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1029 if(ures_openU(NULL
, "root", &status
) != NULL
){
1030 log_err("ERROR: ures_openU() worked with error status with %s\n", myErrorName(status
));
1033 status
= U_ZERO_ERROR
;
1034 teRes
=ures_openU(utestdatapath
, "te", &status
);
1035 if(U_FAILURE(status
)){
1036 log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath
), myErrorName(status
));
1039 /*Test ures_getLocale() */
1040 log_verbose("Testing ures_getLocale() .....\n");
1041 if(strcmp(ures_getLocale(teRes
, &status
), "te") != 0){
1042 log_err("ERROR: ures_getLocale() failed. Expected = te_TE Got = %s\n", ures_getLocale(teRes
, &status
));
1044 /*Test ures_getNextString() */
1045 teFillin
=ures_getByKey(teRes
, "tagged_array_in_te_te_IN", teFillin
, &status
);
1046 key
=ures_getKey(teFillin
);
1047 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1048 ures_resetIterator(NULL
);
1049 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1050 if(status
!=U_INDEX_OUTOFBOUNDS_ERROR
){
1051 log_err("ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1052 myErrorName(status
));
1054 ures_resetIterator(teRes
);
1055 /*Test ures_getNextResource() where resource is table*/
1056 status
=U_ZERO_ERROR
;
1057 #if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
1058 /* The next key varies depending on the charset. */
1059 teFillin
=ures_getNextResource(teRes
, teFillin
, &status
);
1060 if(U_FAILURE(status
)){
1061 log_err("ERROR: ures_getNextResource() failed \n");
1063 key
=ures_getKey(teFillin
);
1064 /*if(strcmp(key, "%%CollationBin") != 0){*/
1065 /*if(strcmp(key, "array_2d_in_Root_te") != 0){*/ /* added "aliasClient" that goes first */
1066 if(strcmp(key
, "a") != 0){
1067 log_err("ERROR: ures_getNextResource() failed\n");
1071 /*Test ures_getByIndex on string Resource*/
1072 teFillin
=ures_getByKey(teRes
, "string_only_in_te", teFillin
, &status
);
1073 teFillin2
=ures_getByIndex(teFillin
, 0, teFillin2
, &status
);
1074 if(U_FAILURE(status
)){
1075 log_err("ERROR: ures_getByIndex on string resource failed\n");
1077 if(strcmp(u_austrcpy(convOutput
, tres_getString(teFillin2
, -1, NULL
, &len
, &status
)), "TE") != 0){
1078 status
=U_ZERO_ERROR
;
1079 log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2
, &len
, &status
)));
1082 /*ures_close(teRes);*/
1084 /*Test ures_openFillIn*/
1085 log_verbose("Testing ures_openFillIn......\n");
1086 status
=U_ZERO_ERROR
;
1087 ures_openFillIn(teRes
, testdatapath
, "te", &status
);
1088 if(U_FAILURE(status
)){
1089 log_err("ERROR: ures_openFillIn failed\n");
1092 if(strcmp(ures_getLocale(teRes
, &status
), "te") != 0){
1093 log_err("ERROR: ures_openFillIn did not open the ResourceBundle correctly\n");
1095 ures_getByKey(teRes
, "string_only_in_te", teFillin
, &status
);
1096 teFillin2
=ures_getNextResource(teFillin
, teFillin2
, &status
);
1097 if(ures_getType(teFillin2
) != URES_STRING
){
1098 log_err("ERROR: getType for getNextResource after ures_openFillIn failed\n");
1100 teFillin2
=ures_getNextResource(teFillin
, teFillin2
, &status
);
1101 if(status
!=U_INDEX_OUTOFBOUNDS_ERROR
){
1102 log_err("ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1103 myErrorName(status
));
1106 ures_close(teFillin
);
1107 ures_close(teFillin2
);
1110 /* Test that ures_getLocale() returns the "real" locale ID */
1111 status
=U_ZERO_ERROR
;
1112 teRes
=ures_open(NULL
, "dE_At_NOWHERE_TO_BE_FOUND", &status
);
1113 if(U_FAILURE(status
)) {
1114 log_data_err("unable to open a locale resource bundle from \"dE_At_NOWHERE_TO_BE_FOUND\"(%s)\n", u_errorName(status
));
1116 if(0!=strcmp("de_AT", ures_getLocale(teRes
, &status
))) {
1117 log_data_err("ures_getLocale(\"dE_At_NOWHERE_TO_BE_FOUND\")=%s but must be de_AT\n", ures_getLocale(teRes
, &status
));
1122 /* same test, but with an aliased locale resource bundle */
1123 status
=U_ZERO_ERROR
;
1124 teRes
=ures_open(NULL
, "iW_Il_depRecaTed_HebreW", &status
);
1125 if(U_FAILURE(status
)) {
1126 log_data_err("unable to open a locale resource bundle from \"iW_Il_depRecaTed_HebreW\"(%s)\n", u_errorName(status
));
1128 if(0!=strcmp("he_IL", ures_getLocale(teRes
, &status
))) {
1129 log_data_err("ures_getLocale(\"iW_Il_depRecaTed_HebreW\")=%s but must be he_IL\n", ures_getLocale(teRes
, &status
));
1133 free(utestdatapath
);
1136 static void TestErrorConditions(){
1137 UErrorCode status
=U_ZERO_ERROR
;
1138 const char *key
=NULL
;
1139 const UChar
*value
=NULL
;
1140 const char* testdatapath
;
1141 UChar
* utestdatapath
;
1143 UResourceBundle
*teRes
= NULL
;
1144 UResourceBundle
*coll
=NULL
;
1145 UResourceBundle
*binColl
= NULL
;
1146 UResourceBundle
*teFillin
=NULL
;
1147 UResourceBundle
*teFillin2
=NULL
;
1148 uint8_t *binResult
= NULL
;
1152 testdatapath
= loadTestData(&status
);
1153 if(U_FAILURE(status
))
1155 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1158 len
= (int32_t)strlen(testdatapath
);
1159 utestdatapath
= (UChar
*) malloc(sizeof(UChar
) *(len
+10));
1160 u_uastrcpy(utestdatapath
, testdatapath
);
1162 /*Test ures_openU with status != U_ZERO_ERROR*/
1163 log_verbose("Testing ures_openU() with status != U_ZERO_ERROR.....\n");
1164 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1165 teRes
=ures_openU(utestdatapath
, "te", &status
);
1166 if(U_FAILURE(status
)){
1167 log_verbose("ures_openU() failed as expected path =%s with status != U_ZERO_ERROR\n", testdatapath
);
1169 log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath
));
1172 /*Test ures_openFillIn with UResourceBundle = NULL*/
1173 log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
1174 status
=U_ZERO_ERROR
;
1175 ures_openFillIn(NULL
, testdatapath
, "te", &status
);
1176 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1177 log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1178 myErrorName(status
));
1180 /*Test ures_getLocale() with status != U_ZERO_ERROR*/
1181 status
=U_ZERO_ERROR
;
1182 teRes
=ures_openU(utestdatapath
, "te", &status
);
1183 if(U_FAILURE(status
)){
1184 log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath
), myErrorName(status
));
1187 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1188 if(ures_getLocale(teRes
, &status
) != NULL
){
1189 log_err("ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR\n");
1191 /*Test ures_getLocale() with UResourceBundle = NULL*/
1192 status
=U_ZERO_ERROR
;
1193 if(ures_getLocale(NULL
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1194 log_err("ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1195 myErrorName(status
));
1197 /*Test ures_getSize() with UResourceBundle = NULL */
1198 status
=U_ZERO_ERROR
;
1199 if(ures_getSize(NULL
) != 0){
1200 log_err("ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d\n", ures_getSize(NULL
));
1202 /*Test ures_getType() with UResourceBundle = NULL should return URES_NONE==-1*/
1203 status
=U_ZERO_ERROR
;
1204 if(ures_getType(NULL
) != URES_NONE
){
1205 log_err("ERROR: ures_getType() should return URES_NONE when UResourceBundle=NULL. Got =%d\n", ures_getType(NULL
));
1207 /*Test ures_getKey() with UResourceBundle = NULL*/
1208 status
=U_ZERO_ERROR
;
1209 if(ures_getKey(NULL
) != NULL
){
1210 log_err("ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d\n", ures_getKey(NULL
));
1212 /*Test ures_hasNext() with UResourceBundle = NULL*/
1213 status
=U_ZERO_ERROR
;
1214 if(ures_hasNext(NULL
) != FALSE
){
1215 log_err("ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d\n", ures_hasNext(NULL
));
1217 /*Test ures_get() with UResourceBundle = NULL*/
1218 status
=U_ZERO_ERROR
;
1219 if(ures_getStringByKey(NULL
, "string_only_in_te", &resultLen
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1220 log_err("ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1221 myErrorName(status
));
1223 /*Test ures_getByKey() with UResourceBundle = NULL*/
1224 status
=U_ZERO_ERROR
;
1225 teFillin
=ures_getByKey(NULL
, "string_only_in_te", teFillin
, &status
);
1226 if( teFillin
!= NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1227 log_err("ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1228 myErrorName(status
));
1230 /*Test ures_getByKey() with status != U_ZERO_ERROR*/
1231 teFillin
=ures_getByKey(NULL
, "string_only_in_te", teFillin
, &status
);
1232 if(teFillin
!= NULL
){
1233 log_err("ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR\n");
1235 /*Test ures_getStringByKey() with UResourceBundle = NULL*/
1236 status
=U_ZERO_ERROR
;
1237 if(ures_getStringByKey(NULL
, "string_only_in_te", &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1238 log_err("ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1239 myErrorName(status
));
1241 /*Test ures_getStringByKey() with status != U_ZERO_ERROR*/
1242 if(ures_getStringByKey(teRes
, "string_only_in_te", &len
, &status
) != NULL
){
1243 log_err("ERROR: ures_getStringByKey is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1244 myErrorName(status
));
1246 /*Test ures_getString() with UResourceBundle = NULL*/
1247 status
=U_ZERO_ERROR
;
1248 if(ures_getString(NULL
, &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1249 log_err("ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1250 myErrorName(status
));
1252 /*Test ures_getString() with status != U_ZERO_ERROR*/
1253 if(ures_getString(teRes
, &len
, &status
) != NULL
){
1254 log_err("ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1255 myErrorName(status
));
1257 /*Test ures_getBinary() with UResourceBundle = NULL*/
1258 status
=U_ZERO_ERROR
;
1259 if(ures_getBinary(NULL
, &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1260 log_err("ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1261 myErrorName(status
));
1263 /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
1264 status
=U_ZERO_ERROR
;
1265 coll
= ures_getByKey(teRes
, "collations", coll
, &status
);
1266 coll
= ures_getByKey(teRes
, "standard", coll
, &status
);
1267 binColl
=ures_getByKey(coll
, "%%CollationBin", binColl
, &status
);
1269 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1270 binResult
=(uint8_t*)ures_getBinary(binColl
, &len
, &status
);
1271 if(binResult
!= NULL
){
1272 log_err("ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail\n");
1275 /*Test ures_getNextResource() with status != U_ZERO_ERROR*/
1276 teFillin
=ures_getNextResource(teRes
, teFillin
, &status
);
1277 if(teFillin
!= NULL
){
1278 log_err("ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1280 /*Test ures_getNextResource() with UResourceBundle = NULL*/
1281 status
=U_ZERO_ERROR
;
1282 teFillin
=ures_getNextResource(NULL
, teFillin
, &status
);
1283 if(teFillin
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1284 log_err("ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s\n",
1285 myErrorName(status
));
1287 /*Test ures_getNextString with errorCode != U_ZERO_ERROR*/
1288 teFillin
=ures_getByKey(teRes
, "tagged_array_in_te_te_IN", teFillin
, &status
);
1289 key
=ures_getKey(teFillin
);
1290 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1291 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1293 log_err("ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1295 /*Test ures_getNextString with UResourceBundle = NULL*/
1296 status
=U_ZERO_ERROR
;
1297 value
=(UChar
*)ures_getNextString(NULL
, &len
, &key
, &status
);
1298 if(value
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1299 log_err("ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1300 myErrorName(status
));
1302 /*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/
1303 status
=U_ZERO_ERROR
;
1304 teFillin
=ures_getByKey(teRes
, "array_only_in_te", teFillin
, &status
);
1305 if(ures_countArrayItems(teRes
, "array_only_in_te", &status
) != 4) {
1306 log_err("ERROR: Wrong number of items in an array!\n");
1308 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1309 teFillin2
=ures_getByIndex(teFillin
, 0, teFillin2
, &status
);
1310 if(teFillin2
!= NULL
){
1311 log_err("ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1313 /*Test ures_getByIndex with UResourceBundle = NULL */
1314 status
=U_ZERO_ERROR
;
1315 teFillin2
=ures_getByIndex(NULL
, 0, teFillin2
, &status
);
1316 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1317 log_err("ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1318 myErrorName(status
));
1320 /*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/
1321 status
=U_ZERO_ERROR
;
1322 teFillin
=ures_getByKey(teRes
, "array_only_in_te", teFillin
, &status
);
1323 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1324 value
=(UChar
*)ures_getStringByIndex(teFillin
, 0, &len
, &status
);
1326 log_err("ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1328 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1329 status
=U_ZERO_ERROR
;
1330 value
=(UChar
*)ures_getStringByIndex(NULL
, 0, &len
, &status
);
1331 if(value
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1332 log_err("ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1333 myErrorName(status
));
1335 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1336 status
=U_ZERO_ERROR
;
1337 value
=(UChar
*)ures_getStringByIndex(teFillin
, 9999, &len
, &status
);
1338 if(value
!= NULL
|| status
!= U_MISSING_RESOURCE_ERROR
){
1339 log_err("ERROR: ures_getStringByIndex() with index that is too big is supposed to fail\n Expected: U_MISSING_RESOURCE_ERROR, Got: %s\n",
1340 myErrorName(status
));
1342 /*Test ures_getInt() where UResourceBundle = NULL */
1343 status
=U_ZERO_ERROR
;
1344 if(ures_getInt(NULL
, &status
) != -1 && status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1345 log_err("ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s\n",
1346 myErrorName(status
));
1348 /*Test ures_getInt() where status != U_ZERO_ERROR */
1349 if(ures_getInt(teRes
, &status
) != -1){
1350 log_err("ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail\n");
1353 ures_close(teFillin
);
1354 ures_close(teFillin2
);
1356 ures_close(binColl
);
1358 free(utestdatapath
);
1363 static void TestGetVersion(){
1364 UVersionInfo minVersionArray
= {0x01, 0x00, 0x00, 0x00};
1365 UVersionInfo maxVersionArray
= {0x50, 0xff, 0xcf, 0xcf};
1366 UVersionInfo versionArray
;
1367 UErrorCode status
= U_ZERO_ERROR
;
1368 UResourceBundle
* resB
= NULL
;
1370 int locCount
= uloc_countAvailable();
1371 const char *locName
= "root";
1373 log_verbose("The ures_getVersion tests begin : \n");
1375 for(j
= -1; j
< locCount
; j
++) {
1377 locName
= uloc_getAvailable(j
);
1379 log_verbose("Testing version number for locale %s\n", locName
);
1380 resB
= ures_open(NULL
,locName
, &status
);
1381 if (U_FAILURE(status
)) {
1382 log_err("Resource bundle creation for locale %s failed.: %s\n", locName
, myErrorName(status
));
1386 ures_getVersion(resB
, versionArray
);
1387 for (i
=0; i
<4; ++i
) {
1388 if (versionArray
[i
] < minVersionArray
[i
] ||
1389 versionArray
[i
] > maxVersionArray
[i
])
1391 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1392 locName
, versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
1401 static void TestGetVersionColl(){
1402 UVersionInfo minVersionArray
= {0x00, 0x00, 0x00, 0x00};
1403 UVersionInfo maxVersionArray
= {0x50, 0x80, 0xcf, 0xcf};
1404 UVersionInfo versionArray
;
1405 UErrorCode status
= U_ZERO_ERROR
;
1406 UResourceBundle
* resB
= NULL
;
1407 UEnumeration
*locs
= NULL
;
1409 const char *locName
= "root";
1411 const UChar
* rules
=NULL
;
1414 log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL
);
1415 locs
= ures_openAvailableLocales(U_ICUDATA_COLL
, &status
);
1416 if (U_FAILURE(status
)) {
1417 log_err("enumeration of %s failed.: %s\n", U_ICUDATA_COLL
, myErrorName(status
));
1422 log_verbose("Testing version number for locale %s\n", locName
);
1423 resB
= ures_open(U_ICUDATA_COLL
,locName
, &status
);
1424 if (U_FAILURE(status
)) {
1425 log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL
, locName
, myErrorName(status
));
1429 /* test NUL termination of UCARules */
1430 rules
= tres_getString(resB
,-1,"UCARules",&len
, &status
);
1431 if(!rules
|| U_FAILURE(status
)) {
1432 log_data_err("Could not load UCARules for locale %s\n", locName
);
1435 if(u_strlen(rules
) != len
){
1436 log_err("UCARules string not nul terminated! \n");
1438 ures_getVersion(resB
, versionArray
);
1439 for (i
=0; i
<4; ++i
) {
1440 if (versionArray
[i
] < minVersionArray
[i
] ||
1441 versionArray
[i
] > maxVersionArray
[i
])
1443 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1444 locName
, versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
1449 } while((locName
= uenum_next(locs
,&locLen
,&status
))&&U_SUCCESS(status
));
1451 if(U_FAILURE(status
)) {
1452 log_err("Err %s testing Collation locales.\n", u_errorName(status
));
1457 static void TestResourceBundles()
1459 UErrorCode status
= U_ZERO_ERROR
;
1460 loadTestData(&status
);
1461 if(U_FAILURE(status
)) {
1462 log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status
));
1466 testTag("only_in_Root", TRUE
, FALSE
, FALSE
);
1467 testTag("in_Root_te", TRUE
, TRUE
, FALSE
);
1468 testTag("in_Root_te_te_IN", TRUE
, TRUE
, TRUE
);
1469 testTag("in_Root_te_IN", TRUE
, FALSE
, TRUE
);
1470 testTag("only_in_te", FALSE
, TRUE
, FALSE
);
1471 testTag("only_in_te_IN", FALSE
, FALSE
, TRUE
);
1472 testTag("in_te_te_IN", FALSE
, TRUE
, TRUE
);
1473 testTag("nonexistent", FALSE
, FALSE
, FALSE
);
1475 log_verbose("Passed:= %d Failed= %d \n", pass
, fail
);
1480 static void TestConstruction1()
1482 UResourceBundle
*test1
= 0, *test2
= 0,*empty
= 0;
1483 const UChar
*result1
, *result2
;
1484 UErrorCode status
= U_ZERO_ERROR
;
1485 UErrorCode err
= U_ZERO_ERROR
;
1486 const char* locale
="te_IN";
1487 const char* testdatapath
;
1491 UVersionInfo versionInfo
;
1492 char versionString
[256];
1493 char verboseOutput
[256];
1495 U_STRING_DECL(rootVal
, "ROOT", 4);
1496 U_STRING_DECL(te_inVal
, "TE_IN", 5);
1498 U_STRING_INIT(rootVal
, "ROOT", 4);
1499 U_STRING_INIT(te_inVal
, "TE_IN", 5);
1501 testdatapath
=loadTestData(&status
);
1502 if(U_FAILURE(status
))
1504 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1508 log_verbose("Testing ures_open()......\n");
1510 empty
= ures_open(testdatapath
, "testempty", &status
);
1511 if(empty
== NULL
|| U_FAILURE(status
)) {
1512 log_err("opening empty failed!\n");
1516 test1
=ures_open(testdatapath
, NULL
, &err
);
1520 log_err("construction of NULL did not succeed : %s \n", myErrorName(status
));
1523 test2
=ures_open(testdatapath
, locale
, &err
);
1526 log_err("construction of %s did not succeed : %s \n", locale
, myErrorName(status
));
1529 result1
= tres_getString(test1
, -1, "string_in_Root_te_te_IN", &len1
, &err
);
1530 result2
= tres_getString(test2
, -1, "string_in_Root_te_te_IN", &len2
, &err
);
1531 if (U_FAILURE(err
) || len1
==0 || len2
==0) {
1532 log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status
));
1535 log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput
, result1
));
1536 log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput
, result2
));
1537 if(u_strcmp(result1
, rootVal
) !=0 || u_strcmp(result2
, te_inVal
) !=0 ){
1538 log_err("construction test failed. Run Verbose for more information");
1542 /* Test getVersionNumber*/
1543 log_verbose("Testing version number\n");
1544 log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1
));
1546 log_verbose("Testing version \n");
1547 ures_getVersion(test1
, versionInfo
);
1548 u_versionToString(versionInfo
, versionString
);
1550 log_verbose("for getVersion : %s\n", versionString
);
1552 if(strcmp(versionString
, ures_getVersionNumber(test1
)) != 0) {
1553 log_err("Versions differ: %s vs %s\n", versionString
, ures_getVersionNumber(test1
));
1561 /*****************************************************************************/
1562 /*****************************************************************************/
1564 static UBool
testTag(const char* frag
,
1569 int32_t failNum
= fail
;
1571 /* Make array from input params */
1574 const char *NAME
[] = { "ROOT", "TE", "TE_IN" };
1576 /* Now try to load the desired items */
1577 UResourceBundle
* theBundle
= NULL
;
1580 UErrorCode expected_status
,status
= U_ZERO_ERROR
,expected_resource_status
= U_ZERO_ERROR
;
1582 UChar
* expected_string
= NULL
;
1583 const UChar
* string
= NULL
;
1586 int32_t i
,j
,row
,col
, len
;
1587 int32_t actual_bundle
;
1589 int32_t row_count
=0;
1590 int32_t column_count
=0;
1592 int32_t tag_count
= 0;
1593 const char* testdatapath
;
1594 char verboseOutput
[256];
1595 UResourceBundle
* array
=NULL
;
1596 UResourceBundle
* array2d
=NULL
;
1597 UResourceBundle
* tags
=NULL
;
1598 UResourceBundle
* arrayItem1
=NULL
;
1600 testdatapath
= loadTestData(&status
);
1601 if(U_FAILURE(status
))
1603 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1609 is_in
[2] = in_te_IN
;
1611 strcpy(item_tag
, "tag");
1613 for (i
=0; i
<bundles_count
; ++i
)
1615 strcpy(action
,"construction for ");
1616 strcat(action
, param
[i
].name
);
1619 status
= U_ZERO_ERROR
;
1621 theBundle
= ures_open(testdatapath
, param
[i
].name
, &status
);
1622 CONFIRM_ErrorCode(status
,param
[i
].expected_constructor_status
);
1625 actual_bundle
= 0; /* ne -> default */
1627 actual_bundle
= 1; /* te_NE -> te */
1629 actual_bundle
= 2; /* te_IN_NE -> te_IN */
1633 expected_resource_status
= U_MISSING_RESOURCE_ERROR
;
1634 for (j
=e_te_IN
; j
>=e_Root
; --j
)
1636 if (is_in
[j
] && param
[i
].inherits
[j
])
1639 if(j
== actual_bundle
) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
1640 expected_resource_status
= U_ZERO_ERROR
;
1642 expected_resource_status
= U_USING_DEFAULT_WARNING
;
1644 expected_resource_status
= U_USING_FALLBACK_WARNING
;
1646 log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n",
1651 is_in
[j
]?"Yes":"No",
1653 param
[i
].inherits
[j
]?"Yes":"No",
1654 param
[actual_bundle
].name
);
1660 for (j
=param
[i
].where
; j
>=0; --j
)
1668 base
=(UChar
*)malloc(sizeof(UChar
)*(strlen(NAME
[j
]) + 1));
1669 u_uastrcpy(base
,NAME
[j
]);
1678 base
= (UChar
*) malloc(sizeof(UChar
) * 1);
1683 /*----string---------------------------------------------------------------- */
1685 strcpy(tag
,"string_");
1688 strcpy(action
,param
[i
].name
);
1689 strcat(action
, ".ures_getStringByKey(" );
1691 strcat(action
, ")");
1694 status
= U_ZERO_ERROR
;
1697 string
=tres_getString(theBundle
, -1, tag
, &len
, &status
);
1698 if(U_SUCCESS(status
)) {
1699 expected_string
=(UChar
*)malloc(sizeof(UChar
)*(u_strlen(base
) + 4));
1700 u_strcpy(expected_string
,base
);
1701 CONFIRM_INT_EQ(len
, u_strlen(expected_string
));
1703 expected_string
= (UChar
*)malloc(sizeof(UChar
)*(u_strlen(kERROR
) + 1));
1704 u_strcpy(expected_string
,kERROR
);
1707 log_verbose("%s got %d, expected %d\n", action
, status
, expected_resource_status
);
1709 CONFIRM_ErrorCode(status
, expected_resource_status
);
1710 CONFIRM_EQ(string
, expected_string
);
1714 /*--------------array------------------------------------------------- */
1716 strcpy(tag
,"array_");
1719 strcpy(action
,param
[i
].name
);
1720 strcat(action
, ".ures_getByKey(" );
1722 strcat(action
, ")");
1726 count
= kERROR_COUNT
;
1727 status
= U_ZERO_ERROR
;
1728 array
=ures_getByKey(theBundle
, tag
, array
, &status
);
1729 CONFIRM_ErrorCode(status
,expected_resource_status
);
1730 if (U_SUCCESS(status
)) {
1731 /*confirm the resource type is an array*/
1732 CONFIRM_INT_EQ(ures_getType(array
), URES_ARRAY
);
1733 /*confirm the size*/
1734 count
=ures_getSize(array
);
1735 CONFIRM_INT_GE(count
,1);
1736 for (j
=0; j
<count
; ++j
) {
1738 u_strcpy(expected_string
, base
);
1739 u_uastrcpy(element
, itoa1(j
,buf
));
1740 u_strcat(expected_string
, element
);
1741 arrayItem1
=ures_getNextResource(array
, arrayItem1
, &status
);
1742 if(U_SUCCESS(status
)){
1743 CONFIRM_EQ(tres_getString(arrayItem1
, -1, NULL
, &len
, &status
),expected_string
);
1749 CONFIRM_INT_EQ(count
,kERROR_COUNT
);
1750 CONFIRM_ErrorCode(status
, U_MISSING_RESOURCE_ERROR
);
1751 /*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/
1755 /*--------------arrayItem------------------------------------------------- */
1757 strcpy(tag
,"array_");
1760 strcpy(action
,param
[i
].name
);
1761 strcat(action
, ".ures_getStringByIndex(");
1762 strcat(action
, tag
);
1763 strcat(action
, ")");
1766 for (j
=0; j
<10; ++j
){
1767 index
= count
? (randi(count
* 3) - count
) : (randi(200) - 100);
1768 status
= U_ZERO_ERROR
;
1770 array
=ures_getByKey(theBundle
, tag
, array
, &status
);
1771 if(!U_FAILURE(status
)){
1773 t
=(UChar
*)ures_getStringByIndex(array
, index
, &len
, &status
);
1774 if(!U_FAILURE(status
)){
1777 u_strcpy(expected_string
, base
);
1778 u_uastrcpy(element
, itoa1(index
,buf
));
1779 u_strcat(expected_string
, element
);
1781 u_strcpy(expected_string
, kERROR
);
1785 expected_status
= (index
>= 0 && index
< count
) ? expected_resource_status
: U_MISSING_RESOURCE_ERROR
;
1786 CONFIRM_ErrorCode(status
,expected_status
);
1787 CONFIRM_EQ(string
,expected_string
);
1792 /*--------------2dArray------------------------------------------------- */
1794 strcpy(tag
,"array_2d_");
1797 strcpy(action
,param
[i
].name
);
1798 strcat(action
, ".ures_getByKey(" );
1800 strcat(action
, ")");
1804 row_count
= kERROR_COUNT
, column_count
= kERROR_COUNT
;
1805 status
= U_ZERO_ERROR
;
1806 array2d
=ures_getByKey(theBundle
, tag
, array2d
, &status
);
1808 CONFIRM_ErrorCode(status
,expected_resource_status
);
1809 if (U_SUCCESS(status
))
1811 /*confirm the resource type is an 2darray*/
1812 CONFIRM_INT_EQ(ures_getType(array2d
), URES_ARRAY
);
1813 row_count
=ures_getSize(array2d
);
1814 CONFIRM_INT_GE(row_count
,1);
1816 for(row
=0; row
<row_count
; ++row
){
1817 UResourceBundle
*tableRow
=NULL
;
1818 tableRow
=ures_getByIndex(array2d
, row
, tableRow
, &status
);
1819 CONFIRM_ErrorCode(status
, expected_resource_status
);
1820 if(U_SUCCESS(status
)){
1821 /*confirm the resourcetype of each table row is an array*/
1822 CONFIRM_INT_EQ(ures_getType(tableRow
), URES_ARRAY
);
1823 column_count
=ures_getSize(tableRow
);
1824 CONFIRM_INT_GE(column_count
,1);
1826 for (col
=0; j
<column_count
; ++j
) {
1828 u_strcpy(expected_string
, base
);
1829 u_uastrcpy(element
, itoa1(row
, buf
));
1830 u_strcat(expected_string
, element
);
1831 u_uastrcpy(element
, itoa1(col
, buf
));
1832 u_strcat(expected_string
, element
);
1833 arrayItem1
=ures_getNextResource(tableRow
, arrayItem1
, &status
);
1834 if(U_SUCCESS(status
)){
1835 const UChar
*stringValue
=tres_getString(arrayItem1
, -1, NULL
, &len
, &status
);
1836 CONFIRM_EQ(stringValue
, expected_string
);
1840 ures_close(tableRow
);
1843 CONFIRM_INT_EQ(row_count
,kERROR_COUNT
);
1844 CONFIRM_INT_EQ(column_count
,kERROR_COUNT
);
1845 row_count
=column_count
=0;
1849 /*------2dArrayItem-------------------------------------------------------------- */
1851 for (j
=0; j
<10; ++j
)
1853 row
= row_count
? (randi(row_count
* 3) - row_count
) : (randi(200) - 100);
1854 col
= column_count
? (randi(column_count
* 3) - column_count
) : (randi(200) - 100);
1855 status
= U_ZERO_ERROR
;
1858 array2d
=ures_getByKey(theBundle
, tag
, array2d
, &status
);
1859 if(U_SUCCESS(status
)){
1860 UResourceBundle
*tableRow
=NULL
;
1861 tableRow
=ures_getByIndex(array2d
, row
, tableRow
, &status
);
1862 if(U_SUCCESS(status
)) {
1864 t
=(UChar
*)ures_getStringByIndex(tableRow
, col
, &len
, &status
);
1865 if(U_SUCCESS(status
)){
1869 ures_close(tableRow
);
1871 expected_status
= (row
>= 0 && row
< row_count
&& col
>= 0 && col
< column_count
) ?
1872 expected_resource_status
: U_MISSING_RESOURCE_ERROR
;
1873 CONFIRM_ErrorCode(status
,expected_status
);
1875 if (U_SUCCESS(status
)){
1877 u_strcpy(expected_string
, base
);
1878 u_uastrcpy(element
, itoa1(row
, buf
));
1879 u_strcat(expected_string
, element
);
1880 u_uastrcpy(element
, itoa1(col
, buf
));
1881 u_strcat(expected_string
, element
);
1883 u_strcpy(expected_string
,kERROR
);
1885 CONFIRM_EQ(string
,expected_string
);
1890 /*--------------taggedArray----------------------------------------------- */
1891 strcpy(tag
,"tagged_array_");
1894 strcpy(action
,param
[i
].name
);
1895 strcat(action
,".ures_getByKey(");
1896 strcat(action
, tag
);
1900 status
= U_ZERO_ERROR
;
1902 tags
=ures_getByKey(theBundle
, tag
, tags
, &status
);
1903 CONFIRM_ErrorCode(status
, expected_resource_status
);
1904 if (U_SUCCESS(status
)) {
1905 UResType bundleType
=ures_getType(tags
);
1906 CONFIRM_INT_EQ(bundleType
, URES_TABLE
);
1908 tag_count
=ures_getSize(tags
);
1909 CONFIRM_INT_GE((int32_t)tag_count
, (int32_t)0);
1911 for(index
=0; index
<tag_count
; index
++){
1912 UResourceBundle
*tagelement
=NULL
;
1913 const char *key
=NULL
;
1915 tagelement
=ures_getByIndex(tags
, index
, tagelement
, &status
);
1916 key
=ures_getKey(tagelement
);
1917 value
=(UChar
*)ures_getNextString(tagelement
, &len
, &key
, &status
);
1918 log_verbose("tag = %s, value = %s\n", key
, u_austrcpy(verboseOutput
, value
));
1919 if(strncmp(key
, "tag", 3) == 0 && u_strncmp(value
, base
, u_strlen(base
)) == 0){
1924 ures_close(tagelement
);
1930 /*---------taggedArrayItem----------------------------------------------*/
1932 for (index
=-20; index
<20; ++index
)
1935 status
= U_ZERO_ERROR
;
1937 strcpy(item_tag
, "tag");
1938 strcat(item_tag
, itoa1(index
,buf
));
1939 tags
=ures_getByKey(theBundle
, tag
, tags
, &status
);
1940 if(U_SUCCESS(status
)){
1941 UResourceBundle
*tagelement
=NULL
;
1943 tagelement
=ures_getByKey(tags
, item_tag
, tagelement
, &status
);
1944 if(!U_FAILURE(status
)){
1945 UResType elementType
=ures_getType(tagelement
);
1946 CONFIRM_INT_EQ(elementType
, URES_STRING
);
1947 if(strcmp(ures_getKey(tagelement
), item_tag
) == 0){
1952 t
=(UChar
*)tres_getString(tagelement
, -1, NULL
, &len
, &status
);
1953 if(!U_FAILURE(status
)){
1958 CONFIRM_ErrorCode(status
,U_MISSING_RESOURCE_ERROR
);
1961 if (status
!= U_MISSING_RESOURCE_ERROR
) {
1963 u_strcpy(expected_string
, base
);
1964 u_uastrcpy(element
, itoa1(index
,buf
));
1965 u_strcat(expected_string
, element
);
1966 CONFIRM_EQ(string
,expected_string
);
1970 ures_close(tagelement
);
1973 CONFIRM_INT_EQ(count
, tag_count
);
1975 free(expected_string
);
1976 ures_close(theBundle
);
1979 ures_close(array2d
);
1981 ures_close(arrayItem1
);
1983 return (UBool
)(failNum
== fail
);
1986 static void record_pass()
1991 static void record_fail()
1997 * Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR
2001 static void TestFallback()
2003 UErrorCode status
= U_ZERO_ERROR
;
2004 UResourceBundle
*fr_FR
= NULL
;
2005 UResourceBundle
*subResource
= NULL
;
2006 const UChar
*junk
; /* ignored */
2009 log_verbose("Opening fr_FR..");
2010 fr_FR
= ures_open(NULL
, "fr_FR", &status
);
2011 if(U_FAILURE(status
))
2013 log_err("Couldn't open fr_FR - %d\n", status
);
2017 status
= U_ZERO_ERROR
;
2020 /* clear it out.. just do some calls to get the gears turning */
2021 junk
= tres_getString(fr_FR
, -1, "LocaleID", &resultLen
, &status
);
2022 status
= U_ZERO_ERROR
;
2023 junk
= tres_getString(fr_FR
, -1, "LocaleString", &resultLen
, &status
);
2024 status
= U_ZERO_ERROR
;
2025 junk
= tres_getString(fr_FR
, -1, "LocaleID", &resultLen
, &status
);
2026 status
= U_ZERO_ERROR
;
2028 /* OK first one. This should be a Default value. */
2029 subResource
= ures_getByKey(fr_FR
, "MeasurementSystem", NULL
, &status
);
2030 if(status
!= U_USING_DEFAULT_WARNING
)
2032 log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get CurrencyMap from fr_FR, got %s\n",
2033 u_errorName(status
));
2036 status
= U_ZERO_ERROR
;
2037 ures_close(subResource
);
2039 /* and this is a Fallback, to fr */
2040 junk
= tres_getString(fr_FR
, -1, "Countries", &resultLen
, &status
);
2041 if(status
!= U_USING_FALLBACK_WARNING
)
2043 log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get Countries from fr_FR, got %d\n",
2047 status
= U_ZERO_ERROR
;
2050 /* Temporary hack err actually should be U_USING_FALLBACK_ERROR */
2051 /* Test Jitterbug 552 fallback mechanism of aliased data */
2053 UErrorCode err
=U_ZERO_ERROR
;
2054 UResourceBundle
* myResB
= ures_open(NULL
,"no_NO_NY",&err
);
2055 UResourceBundle
* resLocID
= ures_getByKey(myResB
, "Version", NULL
, &err
);
2056 UResourceBundle
* tResB
;
2057 const UChar
* version
= NULL
;
2058 static const UChar versionStr
[] = { 0x0031, 0x002E, 0x0034, 0x0035, 0x0000};
2060 if(err
!= U_ZERO_ERROR
){
2061 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
));
2064 version
= tres_getString(resLocID
, -1, NULL
, &resultLen
, &err
);
2065 if(u_strcmp(version
, versionStr
) != 0){
2068 u_austrcpy(x
, versionStr
);
2069 u_austrcpy(g
, version
);
2070 log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value. Expected '%s', but got '%s'\n",
2073 tResB
= ures_getByKey(myResB
, "zoneStrings", NULL
, &err
);
2074 if(err
!= U_USING_FALLBACK_WARNING
){
2075 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
));
2077 ures_close(resLocID
);
2085 /* static void printUChars(UChar* uchars){
2087 / for(i=0; i<u_strlen(uchars); i++){
2088 / log_err("%04X ", *(uchars+i));
2092 static void TestResourceLevelAliasing(void) {
2093 UErrorCode status
= U_ZERO_ERROR
;
2094 UResourceBundle
*aliasB
= NULL
, *tb
= NULL
;
2095 UResourceBundle
*en
= NULL
, *uk
= NULL
, *testtypes
= NULL
;
2096 const char* testdatapath
= NULL
;
2097 const UChar
*string
= NULL
, *sequence
= NULL
;
2098 /*const uint8_t *binary = NULL, *binSequence = NULL;*/
2099 int32_t strLen
= 0, seqLen
= 0;/*, binLen = 0, binSeqLen = 0;*/
2103 testdatapath
=loadTestData(&status
);
2104 if(U_FAILURE(status
))
2106 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
2110 aliasB
= ures_open(testdatapath
, "testaliases", &status
);
2112 if(U_FAILURE(status
))
2114 log_data_err("Could not load testaliases.res %s \n",myErrorName(status
));
2117 /* this should fail - circular alias */
2118 tb
= ures_getByKey(aliasB
, "aaa", tb
, &status
);
2119 if(status
!= U_TOO_MANY_ALIASES_ERROR
) {
2120 log_err("Failed to detect circular alias\n");
2123 status
= U_ZERO_ERROR
;
2125 tb
= ures_getByKey(aliasB
, "aab", tb
, &status
);
2126 if(status
!= U_TOO_MANY_ALIASES_ERROR
) {
2127 log_err("Failed to detect circular alias\n");
2129 status
= U_ZERO_ERROR
;
2131 if(U_FAILURE(status
) ) {
2132 log_data_err("err loading tb resource\n");
2134 /* testing aliasing to a non existing resource */
2135 tb
= ures_getByKey(aliasB
, "nonexisting", tb
, &status
);
2136 if(status
!= U_MISSING_RESOURCE_ERROR
) {
2137 log_err("Managed to find an alias to non-existing resource\n");
2139 status
= U_ZERO_ERROR
;
2141 /* testing referencing/composed alias */
2142 uk
= ures_findResource("ja/LocaleScript/2", uk
, &status
);
2143 if((uk
== NULL
) || U_FAILURE(status
)) {
2144 log_err("Couldn't findResource('ja/LocaleScript/2') err %s\n", u_errorName(status
));
2148 sequence
= tres_getString(uk
, -1, NULL
, &seqLen
, &status
);
2150 tb
= ures_getByKey(aliasB
, "referencingalias", tb
, &status
);
2151 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2153 if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2154 log_err("Referencing alias didn't get the right string\n");
2157 string
= tres_getString(aliasB
, -1, "referencingalias", &strLen
, &status
);
2158 if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2159 log_err("Referencing alias didn't get the right string\n");
2162 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2163 tb
= ures_getByKey(aliasB
, "LocaleScript", tb
, &status
);
2164 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2165 tb
= ures_getByIndex(tb
, 2, tb
, &status
);
2166 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2167 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2168 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2170 if(U_FAILURE(status
)) {
2171 log_err("%s trying to get string via separate getters\n", u_errorName(status
));
2172 } else if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2173 log_err("Referencing alias didn't get the right string\n");
2178 UResourceBundle
* ja
= ures_open(U_ICUDATA_BRKITR
,"ja", &status
);
2179 const UChar
*got
= NULL
, *exp
=NULL
;
2180 int32_t gotLen
= 0, expLen
=0;
2181 ja
= ures_getByKey(ja
, "boundaries", ja
, &status
);
2182 exp
= tres_getString(ja
, -1, "word", &expLen
, &status
);
2184 tb
= ures_getByKey(aliasB
, "boundaries", tb
, &status
);
2185 got
= tres_getString(tb
, -1, "word", &gotLen
, &status
);
2187 if(U_FAILURE(status
)) {
2188 log_err("%s trying to read str boundaries\n", u_errorName(status
));
2189 } else if(gotLen
!= expLen
|| u_strncmp(exp
, got
, gotLen
) != 0) {
2190 log_err("Referencing alias didn't get the right data\n");
2193 status
= U_ZERO_ERROR
;
2196 testtypes
= ures_open(testdatapath
, "testtypes", &status
);
2197 strcpy(buffer
, "menu/file/open");
2199 uk
= ures_findSubResource(testtypes
, s
, uk
, &status
);
2200 sequence
= tres_getString(uk
, -1, NULL
, &seqLen
, &status
);
2202 tb
= ures_getByKey(aliasB
, "simplealias", tb
, &status
);
2203 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2205 if(U_FAILURE(status
) || seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2206 log_err("Referencing alias didn't get the right string\n");
2209 /* test indexed aliasing */
2211 tb
= ures_getByKey(aliasB
, "zoneTests", tb
, &status
);
2212 tb
= ures_getByKey(tb
, "zoneAlias2", tb
, &status
);
2213 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2215 en
= ures_findResource("en/zoneStrings/3/0", en
, &status
);
2216 sequence
= tres_getString(en
, -1, NULL
, &seqLen
, &status
);
2218 if(U_FAILURE(status
) || seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2219 log_err("Referencing alias didn't get the right string\n");
2222 /* test getting aliased string by index */
2224 const char* keys
[] = {
2226 "KeyAlias1PacificStandardTime",
2228 "KeyAlias3LosAngeles"
2231 const char* strings
[] = {
2232 "America/Los_Angeles",
2233 "Pacific Standard Time",
2238 const UChar
* result
;
2239 int32_t uBufferLen
= 0, resultLen
= 0;
2241 const char *key
= NULL
;
2242 tb
= ures_getByKey(aliasB
, "testGetStringByKeyAliasing", tb
, &status
);
2243 if(U_FAILURE(status
)) {
2244 log_err("Couldn't get testGetStringByKeyAliasing resource\n");
2246 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2247 result
= tres_getString(tb
, -1, keys
[i
], &resultLen
, &status
);
2248 if(U_FAILURE(status
)){
2249 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2252 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2253 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2254 log_err("Didn't get correct string while accesing alias table by key (%s)\n", keys
[i
]);
2257 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2258 result
= tres_getString(tb
, i
, NULL
, &resultLen
, &status
);
2259 if(U_FAILURE(status
)){
2260 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2263 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2264 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2265 log_err("Didn't get correct string while accesing alias table by index (%s)\n", strings
[i
]);
2268 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2269 result
= ures_getNextString(tb
, &resultLen
, &key
, &status
);
2270 if(U_FAILURE(status
)){
2271 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2274 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2275 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2276 log_err("Didn't get correct string while iterating over alias table (%s)\n", strings
[i
]);
2279 tb
= ures_getByKey(aliasB
, "testGetStringByIndexAliasing", tb
, &status
);
2280 if(U_FAILURE(status
)) {
2281 log_err("Couldn't get testGetStringByIndexAliasing resource\n");
2283 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2284 result
= tres_getString(tb
, i
, NULL
, &resultLen
, &status
);
2285 if(U_FAILURE(status
)){
2286 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2289 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2290 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2291 log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings
[i
]);
2294 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2295 result
= ures_getNextString(tb
, &resultLen
, &key
, &status
);
2296 if(U_FAILURE(status
)){
2297 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2300 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2301 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2302 log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings
[i
]);
2306 tb
= ures_getByKey(aliasB
, "testAliasToTree", tb
, &status
);
2307 if(U_FAILURE(status
)){
2308 log_err("Fetching the resource with key \"testAliasToTree\" failed. Error: %s\n", u_errorName(status
));
2311 if (strcmp(ures_getKey(tb
), "collations") != 0) {
2312 log_err("ures_getKey(aliasB) unexpectedly returned %s instead of \"collations\"\n", ures_getKey(tb
));
2319 ures_close(testtypes
);
2322 static void TestDirectAccess(void) {
2323 UErrorCode status
= U_ZERO_ERROR
;
2324 UResourceBundle
*t
= NULL
, *t2
= NULL
;
2325 const char* key
= NULL
;
2329 /*const char* testdatapath=loadTestData(&status);
2330 if(U_FAILURE(status)){
2331 log_err("Could not load testdata.dat %s \n",myErrorName(status));
2335 t
= ures_findResource("/testdata/te/zoneStrings/3/2", t
, &status
);
2336 if(U_FAILURE(status
)) {
2337 log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status
));
2338 status
= U_ZERO_ERROR
;
2340 key
= ures_getKey(t
);
2342 log_err("Got a strange key, expected NULL, got %s\n", key
);
2345 t
= ures_findResource("en/calendar/gregorian/DateTimePatterns/3", t
, &status
);
2346 if(U_FAILURE(status
)) {
2347 log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status
));
2348 status
= U_ZERO_ERROR
;
2350 key
= ures_getKey(t
);
2352 log_err("Got a strange key, expected NULL, got %s\n", key
);
2356 t
= ures_findResource("ja/LocaleScript", t
, &status
);
2357 if(U_FAILURE(status
)) {
2358 log_data_err("Couldn't access keyed resource, error %s\n", u_errorName(status
));
2359 status
= U_ZERO_ERROR
;
2361 key
= ures_getKey(t
);
2362 if(strcmp(key
, "LocaleScript")!=0) {
2363 log_err("Got a strange key, expected 'LocaleScript', got %s\n", key
);
2367 t2
= ures_open(NULL
, "sr", &status
);
2368 if(U_FAILURE(status
)) {
2369 log_err("Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status
));
2370 log_data_err("No 'sr', no test - you have bigger problems than testing direct access. "
2371 "You probably have no data! Aborting this test\n");
2374 if(U_SUCCESS(status
)) {
2375 strcpy(buffer
, "Languages/hr");
2377 t
= ures_findSubResource(t2
, s
, t
, &status
);
2378 if(U_FAILURE(status
)) {
2379 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status
));
2380 status
= U_ZERO_ERROR
;
2382 key
= ures_getKey(t
);
2383 if(strcmp(key
, "hr")!=0) {
2384 log_err("Got a strange key, expected 'hr', got %s\n", key
);
2389 t
= ures_findResource("root/calendar/islamic-civil/DateTime", t
, &status
);
2390 if(U_SUCCESS(status
)) {
2391 log_data_err("This resource does not exist. How did it get here?\n");
2393 status
= U_ZERO_ERROR
;
2395 /* this one will freeze */
2396 t
= ures_findResource("root/calendar/islamic-civil/eras/abbreviated/0/mikimaus/pera", t
, &status
);
2397 if(U_SUCCESS(status
)) {
2398 log_data_err("Second resource does not exist. How did it get here?\n");
2400 status
= U_ZERO_ERROR
;
2403 t2
= ures_open(NULL
, "he", &status
);
2404 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2405 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2406 t2
= ures_getByKeyWithFallback(t2
, "DateTime", t2
, &status
);
2407 if(U_SUCCESS(status
)) {
2408 log_err("This resource does not exist. How did it get here?\n");
2410 status
= U_ZERO_ERROR
;
2413 t2
= ures_open(NULL
, "he", &status
);
2415 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2416 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2417 t2
= ures_getByKeyWithFallback(t2
, "eras", t2
, &status
);
2418 if(U_FAILURE(status
)) {
2419 log_err("Didn't get Eras. I know they are there!\n");
2421 status
= U_ZERO_ERROR
;
2424 t2
= ures_open(NULL
, "root", &status
);
2425 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2426 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2427 t2
= ures_getByKeyWithFallback(t2
, "DateTime", t2
, &status
);
2428 if(U_SUCCESS(status
)) {
2429 log_err("This resource does not exist. How did it get here?\n");
2431 status
= U_ZERO_ERROR
;
2437 static void TestJB3763(void) {
2438 /* Nasty bug prevented using parent as fill-in, since it would
2439 * stomp the path information.
2441 UResourceBundle
*t
= NULL
;
2442 UErrorCode status
= U_ZERO_ERROR
;
2443 t
= ures_open(NULL
, "sr_Latn", &status
);
2444 t
= ures_getByKeyWithFallback(t
, "calendar", t
, &status
);
2445 t
= ures_getByKeyWithFallback(t
, "gregorian", t
, &status
);
2446 t
= ures_getByKeyWithFallback(t
, "AmPmMarkers", t
, &status
);
2447 if(U_FAILURE(status
)) {
2448 log_err("This resource should be available?\n");
2450 status
= U_ZERO_ERROR
;
2456 static void TestGetKeywordValues(void) {
2457 UEnumeration
*kwVals
;
2458 UBool foundStandard
= FALSE
;
2459 UErrorCode status
= U_ZERO_ERROR
;
2461 #if !UCONFIG_NO_COLLATION
2462 kwVals
= ures_getKeywordValues( U_ICUDATA_COLL
, "collations", &status
);
2464 log_verbose("Testing getting collation keyword values:\n");
2466 while((kw
=uenum_next(kwVals
, NULL
, &status
))) {
2467 log_verbose(" %s\n", kw
);
2468 if(!strcmp(kw
,"standard")) {
2469 if(foundStandard
== FALSE
) {
2470 foundStandard
= TRUE
;
2472 log_err("'standard' was found twice in the keyword list.\n");
2476 if(foundStandard
== FALSE
) {
2477 log_err("'standard' was not found in the keyword list.\n");
2479 uenum_close(kwVals
);
2480 if(U_FAILURE(status
)) {
2481 log_err("err %s getting collation values\n", u_errorName(status
));
2483 status
= U_ZERO_ERROR
;
2485 foundStandard
= FALSE
;
2486 kwVals
= ures_getKeywordValues( "ICUDATA", "calendar", &status
);
2488 log_verbose("Testing getting calendar keyword values:\n");
2490 while((kw
=uenum_next(kwVals
, NULL
, &status
))) {
2491 log_verbose(" %s\n", kw
);
2492 if(!strcmp(kw
,"japanese")) {
2493 if(foundStandard
== FALSE
) {
2494 foundStandard
= TRUE
;
2496 log_err("'japanese' was found twice in the calendar keyword list.\n");
2500 if(foundStandard
== FALSE
) {
2501 log_err("'japanese' was not found in the calendar keyword list.\n");
2503 uenum_close(kwVals
);
2504 if(U_FAILURE(status
)) {
2505 log_err("err %s getting calendar values\n", u_errorName(status
));
2509 static void TestGetFunctionalEquivalentOf(const char *path
, const char *resName
, const char *keyword
, UBool truncate
, const char * const testCases
[]) {
2511 for(i
=0;testCases
[i
];i
+=3) {
2512 UBool expectAvail
= (testCases
[i
][0]=='t')?TRUE
:FALSE
;
2513 UBool gotAvail
= FALSE
;
2514 const char *inLocale
= testCases
[i
+1];
2515 const char *expectLocale
= testCases
[i
+2];
2516 char equivLocale
[256];
2518 UErrorCode status
= U_ZERO_ERROR
;
2519 log_verbose("%d: %c %s\texpect %s\n",i
/3, expectAvail
?'t':'f', inLocale
, expectLocale
);
2520 len
= ures_getFunctionalEquivalent(equivLocale
, 255, path
,
2521 resName
, keyword
, inLocale
,
2522 &gotAvail
, truncate
, &status
);
2523 if(U_FAILURE(status
) || (len
<= 0)) {
2524 log_err("FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n",
2525 len
, u_errorName(status
),
2526 i
/3,expectAvail
?'t':'f', inLocale
, expectLocale
);
2528 log_verbose("got: %c %s\n", expectAvail
?'t':'f',equivLocale
);
2530 if((gotAvail
!= expectAvail
) || strcmp(equivLocale
, expectLocale
)) {
2531 log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
2532 gotAvail
?'t':'f', equivLocale
,
2534 expectAvail
?'t':'f', inLocale
, expectLocale
);
2541 static void TestGetFunctionalEquivalent(void) {
2542 static const char * const collCases
[] = {
2543 /* avail locale equiv */
2544 "f", "de_US_CALIFORNIA", "de",
2545 "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */
2546 "t", "zh_Hant_TW@collation=stroke", "zh@collation=stroke",
2547 "f", "de_CN@collation=pinyin", "de",
2548 "t", "zh@collation=pinyin", "zh",
2549 "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */
2550 "t", "zh_Hans_CN@collation=pinyin", "zh",
2551 "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */
2552 "t", "zh_Hant_HK@collation=pinyin", "zh",
2553 "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */
2554 "t", "zh_Hant_HK@collation=stroke", "zh@collation=stroke",
2555 "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */
2556 "t", "zh_Hant_HK", "zh@collation=stroke",
2557 "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */
2558 "t", "zh_Hant_MO", "zh@collation=stroke",
2559 "f", "zh_TW_STROKE", "zh@collation=stroke",
2560 "f", "zh_TW_STROKE@collation=big5han", "zh@collation=big5han",
2561 "f", "de_CN@calendar=japanese", "de",
2562 "t", "de@calendar=japanese", "de",
2563 "f", "zh_TW@collation=big5han", "zh@collation=big5han", /* alias of zh_Hant_TW */
2564 "t", "zh_Hant_TW@collation=big5han", "zh@collation=big5han",
2565 "f", "zh_TW@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hant_TW */
2566 "t", "zh_Hant_TW@collation=gb2312han", "zh@collation=gb2312han",
2567 "f", "zh_CN@collation=big5han", "zh@collation=big5han", /* alias of zh_Hans_CN */
2568 "t", "zh_Hans_CN@collation=big5han", "zh@collation=big5han",
2569 "f", "zh_CN@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hans_CN */
2570 "t", "zh_Hans_CN@collation=gb2312han", "zh@collation=gb2312han",
2571 "t", "zh@collation=big5han", "zh@collation=big5han",
2572 "t", "zh@collation=gb2312han", "zh@collation=gb2312han",
2573 "t", "hi_IN@collation=direct", "hi@collation=direct",
2574 "t", "hi@collation=standard", "hi",
2575 "t", "hi@collation=direct", "hi@collation=direct",
2576 "f", "hi_AU@collation=direct;currency=CHF;calendar=buddhist", "hi@collation=direct",
2577 "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
2578 "t", "de_DE@collation=pinyin", "de", /* bug 4582 tests */
2579 "f", "de_DE_BONN@collation=pinyin", "de",
2581 "t", "nl_NL", "root",
2582 "f", "nl_NL_EEXT", "root",
2583 "t", "nl@collation=stroke", "root",
2584 "t", "nl_NL@collation=stroke", "root",
2585 "f", "nl_NL_EEXT@collation=stroke", "root",
2589 static const char *calCases
[] = {
2590 /* avail locale equiv */
2591 "t", "en_US_POSIX", "en_US@calendar=gregorian",
2592 "f", "ja_JP_TOKYO", "ja_JP@calendar=gregorian",
2593 "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
2594 "t", "sr@calendar=gregorian", "sr@calendar=gregorian",
2595 "t", "en", "en@calendar=gregorian",
2599 #if !UCONFIG_NO_COLLATION
2600 TestGetFunctionalEquivalentOf(U_ICUDATA_COLL
, "collations", "collation", TRUE
, collCases
);
2602 TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE
, calCases
);
2604 #if !UCONFIG_NO_COLLATION
2605 log_verbose("Testing error conditions:\n");
2607 char equivLocale
[256] = "???";
2609 UErrorCode status
= U_ZERO_ERROR
;
2610 UBool gotAvail
= FALSE
;
2612 len
= ures_getFunctionalEquivalent(equivLocale
, 255, U_ICUDATA_COLL
,
2613 "calendar", "calendar", "ar_EG@calendar=islamic",
2614 &gotAvail
, FALSE
, &status
);
2616 if(status
== U_MISSING_RESOURCE_ERROR
) {
2617 log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n");
2619 log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n",
2620 equivLocale
, gotAvail
?'t':'f', u_errorName(status
));
2626 static void TestXPath(void) {
2627 UErrorCode status
= U_ZERO_ERROR
;
2628 UResourceBundle
*rb
= NULL
, *alias
= NULL
;
2630 const UChar
* result
= NULL
;
2631 const UChar expResult
[] = { 0x0063, 0x006F, 0x0072, 0x0072, 0x0065, 0x0063, 0x0074, 0x0000 }; /* "correct" */
2632 /*const UChar expResult[] = { 0x0074, 0x0065, 0x0069, 0x006E, 0x0064, 0x0065, 0x0073, 0x0074, 0x0000 }; *//*teindest*/
2634 const char *testdatapath
=loadTestData(&status
);
2635 if(U_FAILURE(status
))
2637 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
2641 log_verbose("Testing ures_open()......\n");
2643 rb
= ures_open(testdatapath
, "te_IN", &status
);
2644 if(U_FAILURE(status
)) {
2645 log_err("Could not open te_IN (%s)\n", myErrorName(status
));
2648 alias
= ures_getByKey(rb
, "rootAliasClient", alias
, &status
);
2649 if(U_FAILURE(status
)) {
2650 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status
));
2655 result
= tres_getString(alias
, -1, NULL
, &len
, &status
);
2656 if(U_FAILURE(status
) || result
== NULL
|| u_strcmp(result
, expResult
)) {
2657 log_err("Couldn't get correct string value (%s)\n", myErrorName(status
));
2660 alias
= ures_getByKey(rb
, "aliasClient", alias
, &status
);
2661 if(U_FAILURE(status
)) {
2662 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status
));
2667 result
= tres_getString(alias
, -1, NULL
, &len
, &status
);
2668 if(U_FAILURE(status
) || result
== NULL
|| u_strcmp(result
, expResult
)) {
2669 log_err("Couldn't get correct string value (%s)\n", myErrorName(status
));
2672 alias
= ures_getByKey(rb
, "nestedRootAliasClient", alias
, &status
);
2673 if(U_FAILURE(status
)) {
2674 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status
));
2679 result
= tres_getString(alias
, -1, NULL
, &len
, &status
);
2680 if(U_FAILURE(status
) || result
== NULL
|| u_strcmp(result
, expResult
)) {
2681 log_err("Couldn't get correct string value (%s)\n", myErrorName(status
));
2687 static void TestCLDRStyleAliases(void) {
2688 UErrorCode status
= U_ZERO_ERROR
;
2689 UResourceBundle
*rb
= NULL
, *alias
= NULL
, *a
=NULL
;
2692 const UChar
*result
= NULL
;
2693 UChar expected
[256];
2694 const char *expects
[7] = { "", "a41", "a12", "a03", "ar4" };
2695 const char *testdatapath
=loadTestData(&status
);
2696 if(U_FAILURE(status
)) {
2697 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
2700 log_verbose("Testing CLDR style aliases......\n");
2702 rb
= ures_open(testdatapath
, "te_IN_REVISED", &status
);
2703 if(U_FAILURE(status
)) {
2704 log_err("Could not open te_IN (%s)\n", myErrorName(status
));
2707 alias
= ures_getByKey(rb
, "a", alias
, &status
);
2708 if(U_FAILURE(status
)) {
2709 log_err("Couldn't find the aliased with name \"a\" resource (%s)\n", myErrorName(status
));
2713 for(i
= 1; i
< 5 ; i
++) {
2717 /* instead of sprintf(resource, "a%i", i); */
2718 a
= ures_getByKeyWithFallback(alias
, resource
, a
, &status
);
2719 result
= tres_getString(a
, -1, NULL
, &len
, &status
);
2720 u_charsToUChars(expects
[i
], expected
, strlen(expects
[i
])+1);
2721 if(U_FAILURE(status
) || !result
|| u_strcmp(result
, expected
)) {
2722 log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource
, expects
[i
], result
, myErrorName(status
));
2723 status
= U_ZERO_ERROR
;
2732 static void TestFallbackCodes(void) {
2733 UErrorCode status
= U_ZERO_ERROR
;
2734 const char *testdatapath
=loadTestData(&status
);
2736 UResourceBundle
*res
= ures_open(testdatapath
, "te_IN", &status
);
2738 UResourceBundle
*r
= NULL
, *fall
= NULL
;
2740 r
= ures_getByKey(res
, "tagged_array_in_Root_te_te_IN", r
, &status
);
2742 status
= U_ZERO_ERROR
;
2743 fall
= ures_getByKeyWithFallback(r
, "tag2", fall
, &status
);
2745 if(status
!= U_ZERO_ERROR
) {
2746 log_data_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status
));
2747 status
= U_ZERO_ERROR
;
2750 fall
= ures_getByKeyWithFallback(r
, "tag7", fall
, &status
);
2752 if(status
!= U_USING_FALLBACK_WARNING
) {
2753 log_data_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status
));
2755 status
= U_ZERO_ERROR
;
2757 fall
= ures_getByKeyWithFallback(r
, "tag1", fall
, &status
);
2759 if(status
!= U_USING_DEFAULT_WARNING
) {
2760 log_data_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status
));
2762 status
= U_ZERO_ERROR
;
2769 /* This test will crash if this doesn't work. Results don't need testing. */
2770 static void TestStackReuse(void) {
2771 UResourceBundle table
;
2772 UErrorCode errorCode
= U_ZERO_ERROR
;
2773 UResourceBundle
*rb
= ures_open(NULL
, "en_US", &errorCode
);
2775 if(U_FAILURE(errorCode
)) {
2776 log_data_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode
));
2779 ures_initStackObject(&table
);
2780 ures_getByKeyWithFallback(rb
, "Types", &table
, &errorCode
);
2781 ures_getByKeyWithFallback(&table
, "collation", &table
, &errorCode
);
2786 /* Test ures_getUTF8StringXYZ() --------------------------------------------- */
2789 * Replace most ures_getStringXYZ() with this function which wraps the
2790 * desired call and also calls the UTF-8 variant and checks that it works.
2792 extern const UChar
*
2793 tres_getString(const UResourceBundle
*resB
,
2794 int32_t index
, const char *key
,
2796 UErrorCode
*status
) {
2802 int32_t length16
, length8
, i16
, i8
;
2805 if(length
== NULL
) {
2809 s16
= ures_getStringByIndex(resB
, index
, length
, status
);
2810 } else if(key
!= NULL
) {
2811 s16
= ures_getStringByKey(resB
, key
, length
, status
);
2813 s16
= ures_getString(resB
, length
, status
);
2815 if(U_FAILURE(*status
)) {
2820 /* try the UTF-8 variant of ures_getStringXYZ() */
2821 for(forceCopy
= FALSE
; forceCopy
<= TRUE
; ++forceCopy
) {
2823 length8
= (int32_t)sizeof(buffer8
);
2825 s8
= ures_getUTF8StringByIndex(resB
, index
, p8
, &length8
, forceCopy
, status
);
2826 } else if(key
!= NULL
) {
2827 s8
= ures_getUTF8StringByKey(resB
, key
, p8
, &length8
, forceCopy
, status
);
2829 s8
= ures_getUTF8String(resB
, p8
, &length8
, forceCopy
, status
);
2831 if(*status
== U_INVALID_CHAR_FOUND
) {
2832 /* the UTF-16 string contains an unpaired surrogate, can't test UTF-8 variant */
2835 if(*status
== U_BUFFER_OVERFLOW_ERROR
) {
2836 *status
= U_ZERO_ERROR
;
2837 p8
= (char *)malloc(++length8
);
2842 s8
= ures_getUTF8StringByIndex(resB
, index
, p8
, &length8
, forceCopy
, status
);
2843 } else if(key
!= NULL
) {
2844 s8
= ures_getUTF8StringByKey(resB
, key
, p8
, &length8
, forceCopy
, status
);
2846 s8
= ures_getUTF8String(resB
, p8
, &length8
, forceCopy
, status
);
2849 if(U_FAILURE(*status
)) {
2850 /* something unexpected happened */
2857 if(forceCopy
&& s8
!= p8
) {
2858 log_err("ures_getUTF8String(%p, %ld, '%s') did not write the string to dest\n",
2859 resB
, (long)index
, key
);
2862 /* verify NUL-termination */
2863 if((p8
!= buffer8
|| length8
< sizeof(buffer8
)) && s8
[length8
] != 0) {
2864 log_err("ures_getUTF8String(%p, %ld, '%s') did not NUL-terminate\n",
2865 resB
, (long)index
, key
);
2867 /* verify correct string */
2869 while(i16
< length16
&& i8
< length8
) {
2870 U16_NEXT(s16
, i16
, length16
, c16
);
2871 U8_NEXT(s8
, i8
, length8
, c8
);
2873 log_err("ures_getUTF8String(%p, %ld, '%s') got a bad string, c16=U+%04lx!=U+%04lx=c8 before i16=%ld\n",
2874 resB
, (long)index
, key
, (long)c16
, (long)c8
, (long)i16
);
2877 /* verify correct length */
2878 if(i16
< length16
) {
2879 log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too short, length8=%ld, length16=%ld\n",
2880 resB
, (long)index
, key
, (long)length8
, (long)length16
);
2883 log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too long, length8=%ld, length16=%ld\n",
2884 resB
, (long)index
, key
, (long)length8
, (long)length16
);
2896 * API tests for ures_getUTF8String().
2897 * Most cases are handled by tres_getString(), which leaves argument checking
2898 * to be tested here.
2899 * Since the variants share most of their implementation, we only need to test
2901 * We also need not test for checking arguments which will be checked by the
2902 * UTF-16 ures_getStringXYZ() that are called internally.
2905 TestGetUTF8String() {
2906 UResourceBundle
*res
;
2907 const char *testdatapath
;
2913 status
= U_ZERO_ERROR
;
2914 testdatapath
= loadTestData(&status
);
2915 if(U_FAILURE(status
)) {
2916 log_data_err("Could not load testdata.dat - %s\n", u_errorName(status
));
2920 res
= ures_open(testdatapath
, "", &status
);
2921 if(U_FAILURE(status
)) {
2922 log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status
));
2927 status
= U_ZERO_ERROR
;
2928 length8
= (int32_t)sizeof(buffer8
);
2929 s8
= ures_getUTF8StringByKey(res
, "string_only_in_Root", buffer8
, &length8
, FALSE
, &status
);
2930 if(status
!= U_ZERO_ERROR
) {
2931 log_err("ures_getUTF8StringByKey(testdata/root string) malfunctioned - %s\n", u_errorName(status
));
2934 /* negative capacity */
2935 status
= U_ZERO_ERROR
;
2937 s8
= ures_getUTF8StringByKey(res
, "string_only_in_Root", buffer8
, &length8
, FALSE
, &status
);
2938 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
2939 log_err("ures_getUTF8StringByKey(capacity<0) malfunctioned - %s\n", u_errorName(status
));
2942 /* capacity>0 but dest=NULL */
2943 status
= U_ZERO_ERROR
;
2944 length8
= (int32_t)sizeof(buffer8
);
2945 s8
= ures_getUTF8StringByKey(res
, "string_only_in_Root", NULL
, &length8
, FALSE
, &status
);
2946 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
2947 log_err("ures_getUTF8StringByKey(dest=NULL capacity>0) malfunctioned - %s\n", u_errorName(status
));