1 /********************************************************************
3 * Copyright (c) 1997-2013, 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"
32 #include "unicode/ulocdata.h"
35 #include "unicode/ctest.h"
42 /*****************************************************************************/
44 * Return a random unsigned long l where 0N <= l <= ULONG_MAX.
52 static UBool initialized
= FALSE
;
55 srand((unsigned)time(NULL
));
58 /* Assume rand has at least 12 bits of precision */
60 for (i
=0; i
<sizeof(l
); ++i
)
61 ((char*)&l
)[i
] = (char)((rand() & 0x0FF0) >> 4);
66 * Return a random double x where 0.0 <= x < 1.0.
71 return ((double)randul()) / UINT32_MAX
;
75 * Return a random integer i where 0 <= i < n.
77 static int32_t randi(int32_t n
)
79 return (int32_t)(randd() * n
);
81 /***************************************************************************************/
83 * Convert an integer, positive or negative, to a character string radix 10.
86 itoa1(int32_t i
, char* buf
)
96 /* Output digits in reverse order */
99 *p
++ = (char)('0' + (i
% 10));
105 /* Reverse the string */
114 static const int32_t kERROR_COUNT
= -1234567;
115 static const UChar kERROR
[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/,
116 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/};
118 /*****************************************************************************/
127 typedef enum E_Where E_Where
;
128 /*****************************************************************************/
130 #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)); }
131 #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); }
132 #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); }
133 #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); }
134 /*#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)); } */
136 CONFIRM_ErrorCode(UErrorCode actual
,UErrorCode expected
)
138 if ((expected
)==(actual
))
143 /*log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); */
144 log_err("returned %s instead of %s\n", myErrorName(actual
), myErrorName(expected
));
149 /* Array of our test objects */
154 UErrorCode expected_constructor_status
;
156 UBool like
[e_Where_count
];
157 UBool inherits
[e_Where_count
];
161 /* "te" means test */
162 /* "IN" means inherits */
163 /* "NE" or "ne" means "does not exist" */
165 { "root", U_ZERO_ERROR
, e_Root
, { TRUE
, FALSE
, FALSE
}, { TRUE
, FALSE
, FALSE
} },
166 { "te", U_ZERO_ERROR
, e_te
, { FALSE
, TRUE
, FALSE
}, { TRUE
, TRUE
, FALSE
} },
167 { "te_IN", U_ZERO_ERROR
, e_te_IN
, { FALSE
, FALSE
, TRUE
}, { TRUE
, TRUE
, TRUE
} },
168 { "te_NE", U_USING_FALLBACK_WARNING
, e_te
, { FALSE
, TRUE
, FALSE
}, { TRUE
, TRUE
, FALSE
} },
169 { "te_IN_NE", U_USING_FALLBACK_WARNING
, e_te_IN
, { FALSE
, FALSE
, TRUE
}, { TRUE
, TRUE
, TRUE
} },
170 { "ne", U_USING_DEFAULT_WARNING
, e_Root
, { TRUE
, FALSE
, FALSE
}, { TRUE
, FALSE
, FALSE
} }
173 static int32_t bundles_count
= sizeof(param
) / sizeof(param
[0]);
177 /*static void printUChars(UChar*);*/
178 static void TestDecodedBundle(void);
179 static void TestGetKeywordValues(void);
180 static void TestGetFunctionalEquivalent(void);
181 static void TestCLDRStyleAliases(void);
182 static void TestFallbackCodes(void);
183 static void TestGetUTF8String(void);
184 static void TestCLDRVersion(void);
186 /***************************************************************************************/
188 /* Array of our test objects */
190 void addNEWResourceBundleTest(TestNode
** root
)
192 addTest(root
, &TestErrorCodes
, "tsutil/creststn/TestErrorCodes");
193 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
194 addTest(root
, &TestEmptyBundle
, "tsutil/creststn/TestEmptyBundle");
195 addTest(root
, &TestConstruction1
, "tsutil/creststn/TestConstruction1");
196 addTest(root
, &TestResourceBundles
, "tsutil/creststn/TestResourceBundles");
197 addTest(root
, &TestNewTypes
, "tsutil/creststn/TestNewTypes");
198 addTest(root
, &TestEmptyTypes
, "tsutil/creststn/TestEmptyTypes");
199 addTest(root
, &TestBinaryCollationData
, "tsutil/creststn/TestBinaryCollationData");
200 addTest(root
, &TestAPI
, "tsutil/creststn/TestAPI");
201 addTest(root
, &TestErrorConditions
, "tsutil/creststn/TestErrorConditions");
202 addTest(root
, &TestDecodedBundle
, "tsutil/creststn/TestDecodedBundle");
203 addTest(root
, &TestResourceLevelAliasing
, "tsutil/creststn/TestResourceLevelAliasing");
204 addTest(root
, &TestDirectAccess
, "tsutil/creststn/TestDirectAccess");
205 addTest(root
, &TestTicket9804
, "tsutil/creststn/TestTicket9804");
206 addTest(root
, &TestXPath
, "tsutil/creststn/TestXPath");
207 addTest(root
, &TestCLDRStyleAliases
, "tsutil/creststn/TestCLDRStyleAliases");
208 addTest(root
, &TestFallbackCodes
, "tsutil/creststn/TestFallbackCodes");
209 addTest(root
, &TestGetUTF8String
, "tsutil/creststn/TestGetUTF8String");
210 addTest(root
, &TestCLDRVersion
, "tsutil/creststn/TestCLDRVersion");
212 addTest(root
, &TestFallback
, "tsutil/creststn/TestFallback");
213 addTest(root
, &TestGetVersion
, "tsutil/creststn/TestGetVersion");
214 addTest(root
, &TestGetVersionColl
, "tsutil/creststn/TestGetVersionColl");
215 addTest(root
, &TestAliasConflict
, "tsutil/creststn/TestAliasConflict");
216 addTest(root
, &TestGetKeywordValues
, "tsutil/creststn/TestGetKeywordValues");
217 addTest(root
, &TestGetFunctionalEquivalent
,"tsutil/creststn/TestGetFunctionalEquivalent");
218 addTest(root
, &TestJB3763
, "tsutil/creststn/TestJB3763");
219 addTest(root
, &TestStackReuse
, "tsutil/creststn/TestStackReuse");
223 /***************************************************************************************/
224 static const char* norwayNames
[] = {
234 static const char* norwayLocales
[] = {
244 static void checkStatus(int32_t line
, UErrorCode expected
, UErrorCode status
) {
245 if(U_FAILURE(status
)) {
246 log_data_err("Resource not present, cannot test (%s:%d)\n", __FILE__
, line
);
248 if(status
!= expected
) {
249 log_err_status(status
, "%s:%d: Expected error code %s, got error code %s\n", __FILE__
, line
, u_errorName(expected
), u_errorName(status
));
253 static void TestErrorCodes(void) {
254 UErrorCode status
= U_USING_DEFAULT_WARNING
;
256 UResourceBundle
*r
= NULL
, *r2
= NULL
;
258 /* First check with ICUDATA */
259 /* first bundle should return fallback warning */
260 r
= ures_open(NULL
, "ti_ER_ASSAB", &status
);
261 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
264 /* this bundle should return zero error, so it shouldn't change the status */
265 status
= U_USING_DEFAULT_WARNING
;
266 r
= ures_open(NULL
, "ti_ER", &status
);
267 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
269 /* we look up the resource which is aliased, but it lives in fallback */
271 if(U_SUCCESS(status
) && r
!= NULL
) {
272 status
= U_USING_DEFAULT_WARNING
;
273 r2
= ures_getByKey(r
, "LocaleScript", NULL
, &status
); /* LocaleScript lives in ti */
274 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
278 /* this bundle should return zero error, so it shouldn't change the status */
279 status
= U_USING_DEFAULT_WARNING
;
280 r
= ures_open(U_ICUDATA_REGION
, "ti", &status
);
281 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
283 /* we look up the resource which is aliased and at our level */
284 /* TODO: restore the following test when cldrbug 3058: is fixed - but CldrBug:3058 is WONTFIX */
285 if(U_SUCCESS(status
) && r
!= NULL
&& isICUVersionAtLeast(52, 0, 1)) {
286 status
= U_USING_DEFAULT_WARNING
;
287 r2
= ures_getByKey(r
, "Countries", r2
, &status
);
288 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
292 status
= U_USING_FALLBACK_WARNING
;
293 r
= ures_open(NULL
, "nolocale", &status
);
294 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
298 /** Now, with the collation bundle **/
300 /* first bundle should return fallback warning */
301 r
= ures_open(U_ICUDATA_COLL
, "sr_YU_VOJVODINA", &status
);
302 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
305 /* this bundle should return zero error, so it shouldn't change the status */
306 status
= U_USING_FALLBACK_WARNING
;
307 r
= ures_open(U_ICUDATA_COLL
, "sr", &status
);
308 checkStatus(__LINE__
, U_USING_FALLBACK_WARNING
, status
);
310 /* we look up the resource which is aliased */
311 if(U_SUCCESS(status
) && r
!= NULL
) {
312 status
= U_USING_DEFAULT_WARNING
;
313 r2
= ures_getByKey(r
, "collations", NULL
, &status
);
314 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
318 /* this bundle should return zero error, so it shouldn't change the status */
319 status
= U_USING_DEFAULT_WARNING
;
320 r
= ures_open(U_ICUDATA_COLL
, "sr", &status
);
321 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
323 /* we look up the resource which is aliased and at our level */
324 if(U_SUCCESS(status
) && r
!= NULL
) {
325 status
= U_USING_DEFAULT_WARNING
;
326 r2
= ures_getByKey(r
, "collations", r2
, &status
);
327 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
331 status
= U_USING_FALLBACK_WARNING
;
332 r
= ures_open(U_ICUDATA_COLL
, "nolocale", &status
);
333 checkStatus(__LINE__
, U_USING_DEFAULT_WARNING
, status
);
338 static void TestAliasConflict(void) {
339 UErrorCode status
= U_ZERO_ERROR
;
340 UResourceBundle
*he
= NULL
;
341 UResourceBundle
*iw
= NULL
;
342 UResourceBundle
*norway
= NULL
;
343 const UChar
*result
= NULL
;
347 const char *realName
= NULL
;
349 he
= ures_open(NULL
, "he", &status
);
350 iw
= ures_open(NULL
, "iw", &status
);
351 if(U_FAILURE(status
)) {
352 log_err_status(status
, "Failed to get resource with %s\n", myErrorName(status
));
355 result
= ures_getStringByKey(he
, "ExemplarCharacters", &resultLen
, &status
);
356 if(U_FAILURE(status
) || result
== NULL
) {
357 log_err_status(status
, "Failed to get resource ExemplarCharacters with %s\n", myErrorName(status
));
361 size
= sizeof(norwayNames
)/sizeof(norwayNames
[0]);
362 for(i
= 0; i
< size
; i
++) {
363 status
= U_ZERO_ERROR
;
364 norway
= ures_open(NULL
, norwayNames
[i
], &status
);
365 if(U_FAILURE(status
)) {
366 log_err_status(status
, "Failed to get resource with %s for %s\n", myErrorName(status
), norwayNames
[i
]);
369 realName
= ures_getLocale(norway
, &status
);
370 log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames
[i
], realName
);
371 if(realName
== NULL
|| strcmp(norwayLocales
[i
], realName
) != 0) {
372 log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames
[i
], norwayLocales
[i
], realName
);
378 static void TestDecodedBundle(){
380 UErrorCode error
= U_ZERO_ERROR
;
382 UResourceBundle
* resB
;
384 const UChar
* srcFromRes
;
386 static const UChar uSrc
[] = {
387 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F,
388 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928,
389 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A,
390 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938,
391 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020,
392 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938,
393 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947,
394 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020,
395 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915,
396 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E,
397 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917,
398 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D,
399 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020,
400 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915,
401 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B,
402 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E,
403 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902,
404 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932,
405 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F,
406 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938,
407 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930,
408 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020,
409 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020,
410 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F,
411 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C,
412 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941,
413 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917,
414 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E,
415 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930,
416 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E,
417 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,
418 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,
419 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935,
420 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915,
421 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F,
422 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033,
423 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F,
424 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915,
425 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020,
431 const char *testdatapath
= loadTestData(&error
);
432 resB
= ures_open(testdatapath
, "iscii", &error
);
433 srcFromRes
=tres_getString(resB
,-1,"str",&len
,&error
);
434 if(U_FAILURE(error
)){
435 #if UCONFIG_NO_LEGACY_CONVERSION
436 log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION is turned on)\n");
438 log_data_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error
));
443 if(u_strncmp(srcFromRes
,uSrc
,len
)!=0){
444 log_err("Genrb produced res files after decoding failed\n");
447 if(uSrc
[num
]!=srcFromRes
[num
]){
448 log_verbose(" Expected: 0x%04X Got: 0x%04X \n", uSrc
[num
],srcFromRes
[num
]);
452 if (len
!= u_strlen(uSrc
)) {
453 log_err("Genrb produced a string larger than expected\n");
458 static void TestNewTypes() {
459 UResourceBundle
* theBundle
= NULL
;
461 const char* testdatapath
;
462 UErrorCode status
= U_ZERO_ERROR
;
463 UResourceBundle
* res
= NULL
;
464 uint8_t *binResult
= NULL
;
467 int32_t intResult
= 0;
468 uint32_t uintResult
= 0;
469 const UChar
*empty
= NULL
;
470 const UChar
*zeroString
;
471 UChar expected
[] = { 'a','b','c','\0','d','e','f' };
472 const char* expect
="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
475 testdatapath
=loadTestData(&status
);
477 if(U_FAILURE(status
))
479 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
483 theBundle
= ures_open(testdatapath
, "testtypes", &status
);
485 empty
= tres_getString(theBundle
, -1, "emptystring", &len
, &status
);
486 if(empty
&& (*empty
!= 0 || len
!= 0)) {
487 log_err("Empty string returned invalid value\n");
490 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
492 CONFIRM_INT_NE(theBundle
, NULL
);
494 /* This test reads the string "abc\u0000def" from the bundle */
495 /* if everything is working correctly, the size of this string */
496 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
498 strcpy(action
, "getting and testing of string with embeded zero");
499 res
= ures_getByKey(theBundle
, "zerotest", res
, &status
);
500 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
501 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
502 zeroString
=tres_getString(res
, -1, NULL
, &len
, &status
);
503 if(U_SUCCESS(status
)){
504 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
505 CONFIRM_INT_EQ(len
, 7);
506 CONFIRM_INT_NE(len
, 3);
509 if(zeroString
[i
]!= expected
[i
]){
510 log_verbose("Output did not match Expected: \\u%4X Got: \\u%4X", expected
[i
], zeroString
[i
]);
514 strcpy(action
, "getting and testing of binary type");
515 res
= ures_getByKey(theBundle
, "binarytest", res
, &status
);
516 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
517 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
518 binResult
=(uint8_t*)ures_getBinary(res
, &len
, &status
);
519 if(U_SUCCESS(status
)){
520 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
521 CONFIRM_INT_EQ(len
, 15);
522 for(i
= 0; i
<15; i
++) {
523 CONFIRM_INT_EQ(binResult
[i
], i
);
527 strcpy(action
, "getting and testing of imported binary type");
528 res
= ures_getByKey(theBundle
, "importtest", res
, &status
);
529 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
530 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
531 binResult
=(uint8_t*)ures_getBinary(res
, &len
, &status
);
532 if(U_SUCCESS(status
)){
533 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
534 CONFIRM_INT_EQ(len
, 15);
535 for(i
= 0; i
<15; i
++) {
536 CONFIRM_INT_EQ(binResult
[i
], i
);
540 strcpy(action
, "getting and testing of integer types");
541 res
= ures_getByKey(theBundle
, "one", res
, &status
);
542 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
543 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
544 intResult
=ures_getInt(res
, &status
);
545 uintResult
= ures_getUInt(res
, &status
);
546 if(U_SUCCESS(status
)){
547 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
548 CONFIRM_INT_EQ(uintResult
, (uint32_t)intResult
);
549 CONFIRM_INT_EQ(intResult
, 1);
552 strcpy(action
, "getting minusone");
553 res
= ures_getByKey(theBundle
, "minusone", res
, &status
);
554 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
555 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
556 intResult
=ures_getInt(res
, &status
);
557 uintResult
= ures_getUInt(res
, &status
);
558 if(U_SUCCESS(status
)){
559 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
560 CONFIRM_INT_EQ(uintResult
, 0x0FFFFFFF); /* a 28 bit integer */
561 CONFIRM_INT_EQ(intResult
, -1);
562 CONFIRM_INT_NE(uintResult
, (uint32_t)intResult
);
565 strcpy(action
, "getting plusone");
566 res
= ures_getByKey(theBundle
, "plusone", 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 uintResult
= ures_getUInt(res
, &status
);
571 if(U_SUCCESS(status
)){
572 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
573 CONFIRM_INT_EQ(uintResult
, (uint32_t)intResult
);
574 CONFIRM_INT_EQ(intResult
, 1);
577 res
= ures_getByKey(theBundle
, "onehundredtwentythree", res
, &status
);
578 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
579 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
580 intResult
=ures_getInt(res
, &status
);
581 if(U_SUCCESS(status
)){
582 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
583 CONFIRM_INT_EQ(intResult
, 123);
586 /* this tests if escapes are preserved or not */
588 const UChar
* str
= tres_getString(theBundle
,-1,"testescape",&len
,&status
);
589 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
590 if(U_SUCCESS(status
)){
591 u_charsToUChars(expect
,uExpect
,(int32_t)strlen(expect
)+1);
592 if(u_strcmp(uExpect
,str
)){
593 log_err("Did not get the expected string for testescape\n");
597 /* this tests if unescaping works are expected */
600 char pattern
[2048] = "";
602 UChar
* expectedEscaped
;
606 /* This strcpy fixes compiler warnings about long strings */
607 strcpy(pattern
, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
608 "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F "
609 "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 "
610 "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD "
611 "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF "
614 "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF "
615 "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF "
616 "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF "
617 "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB "
618 "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C "
621 "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F "
625 patternLen
= (int32_t)uprv_strlen(pattern
);
626 expectedEscaped
= (UChar
*)malloc(U_SIZEOF_UCHAR
* patternLen
);
627 got
= tres_getString(theBundle
,-1,"test_unescaping",&len
,&status
);
628 expectedLen
= u_unescape(pattern
,expectedEscaped
,patternLen
);
629 if(got
==NULL
|| u_strncmp(expectedEscaped
,got
,expectedLen
)!=0 || expectedLen
!= len
){
630 log_err("genrb failed to unescape string\n");
633 for(i
=0;i
<expectedLen
;i
++){
634 if(expectedEscaped
[i
] != got
[i
]){
635 log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped
[i
], got
[i
]);
639 free(expectedEscaped
);
640 status
= U_ZERO_ERROR
;
642 /* test for jitterbug#1435 */
644 const UChar
* str
= tres_getString(theBundle
,-1,"test_underscores",&len
,&status
);
645 expect
="test message ....";
646 u_charsToUChars(expect
,uExpect
,(int32_t)strlen(expect
)+1);
647 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
648 if(str
== NULL
|| u_strcmp(uExpect
,str
)){
649 log_err("Did not get the expected string for test_underscores.\n");
652 /* test for jitterbug#2626 */
653 #if !UCONFIG_NO_COLLATION
655 UResourceBundle
* resB
= NULL
;
656 const UChar
* str
= NULL
;
657 int32_t strLength
= 0;
658 const UChar my
[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */
659 status
= U_ZERO_ERROR
;
660 resB
= ures_getByKey(theBundle
, "collations", resB
, &status
);
661 resB
= ures_getByKey(resB
, "standard", resB
, &status
);
662 str
= tres_getString(resB
,-1,"Sequence",&strLength
,&status
);
663 if(!str
|| U_FAILURE(status
)) {
664 log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status
));
665 } else if(u_strcmp(my
,str
) != 0){
666 log_err("Did not get the expected string for escaped \\u0075\n");
672 const char *sourcePath
= ctest_dataSrcDir();
673 int32_t srcPathLen
= (int32_t)strlen(sourcePath
);
674 const char *deltaPath
= ".."U_FILE_SEP_STRING
"test"U_FILE_SEP_STRING
"testdata"U_FILE_SEP_STRING
;
675 int32_t deltaPathLen
= (int32_t)strlen(deltaPath
);
676 char *testDataFileName
= (char *) malloc( srcPathLen
+ deltaPathLen
+ 50 );
677 char *path
= testDataFileName
;
679 strcpy(path
, sourcePath
);
681 strcpy(path
, deltaPath
);
682 path
+= deltaPathLen
;
683 status
= U_ZERO_ERROR
;
686 const UChar
* str
= tres_getString(theBundle
, -1, "testincludeUTF",&strLen
,&status
);
687 strcpy(path
, "riwords.txt");
688 path
[strlen("riwords.txt")]=0;
689 if(U_FAILURE(status
)){
690 log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status
));
693 const char* cp
= NULL
;
694 UCHARBUF
* ucbuf
= ucbuf_open(testDataFileName
,&cp
,FALSE
,FALSE
,&status
);
696 if(U_SUCCESS(status
)){
697 const UChar
* buffer
= ucbuf_getBuffer(ucbuf
,&len
,&status
);
698 if(U_SUCCESS(status
)){
699 /* verify the contents */
701 log_err("Did not get the expected len for riwords. Expected: %i , Got: %i\n", len
,strLen
);
703 /* test string termination */
704 if(u_strlen(str
) != strLen
|| str
[strLen
]!= 0 ){
705 log_err("testinclude not null terminated!\n");
707 if(u_strncmp(str
, buffer
,strLen
)!=0){
708 log_err("Did not get the expected string from riwords. Include functionality failed for genrb.\n");
711 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName
, u_errorName(status
));
716 log_err("Could not get riwords.txt (path : %s). Error: %s\n",testDataFileName
,u_errorName(status
));
720 status
= U_ZERO_ERROR
;
723 const UChar
* str
= tres_getString(theBundle
, -1, "testinclude",&strLen
,&status
);
724 strcpy(path
, "translit_rules.txt");
725 path
[strlen("translit_rules.txt")]=0;
727 if(U_FAILURE(status
)){
728 log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status
));
732 UCHARBUF
* ucbuf
= ucbuf_open(testDataFileName
,&cp
,FALSE
,FALSE
,&status
);
734 if(U_SUCCESS(status
)){
735 const UChar
* buffer
= ucbuf_getBuffer(ucbuf
,&len
,&status
);
736 if(U_SUCCESS(status
)){
737 /* verify the contents */
739 log_err("Did not get the expected len for translit_rules. Expected: %i , Got: %i\n", len
,strLen
);
741 if(u_strncmp(str
, buffer
,strLen
)!=0){
742 log_err("Did not get the expected string from translit_rules. Include functionality failed for genrb.\n");
745 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName
, u_errorName(status
));
749 log_err("Could not get translit_rules.txt (path : %s). Error: %s\n",testDataFileName
,u_errorName(status
));
753 free(testDataFileName
);
756 ures_close(theBundle
);
760 static void TestEmptyTypes() {
761 UResourceBundle
* theBundle
= NULL
;
763 const char* testdatapath
;
764 UErrorCode status
= U_ZERO_ERROR
;
765 UResourceBundle
* res
= NULL
;
766 UResourceBundle
* resArray
= NULL
;
767 const uint8_t *binResult
= NULL
;
769 int32_t intResult
= 0;
770 const UChar
*zeroString
;
771 const int32_t *zeroIntVect
;
773 strcpy(action
, "Construction of testtypes bundle");
774 testdatapath
=loadTestData(&status
);
775 if(U_FAILURE(status
))
777 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
781 theBundle
= ures_open(testdatapath
, "testtypes", &status
);
783 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
785 CONFIRM_INT_NE(theBundle
, NULL
);
787 /* This test reads the string "abc\u0000def" from the bundle */
788 /* if everything is working correctly, the size of this string */
789 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
791 status
= U_ZERO_ERROR
;
792 strcpy(action
, "getting and testing of explicit string of zero length string");
793 res
= ures_getByKey(theBundle
, "emptyexplicitstring", res
, &status
);
794 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
795 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
796 zeroString
=tres_getString(res
, -1, NULL
, &len
, &status
);
797 if(U_SUCCESS(status
)){
798 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
799 CONFIRM_INT_EQ(len
, 0);
800 CONFIRM_INT_EQ(u_strlen(zeroString
), 0);
803 log_err("Couldn't get emptyexplicitstring\n");
806 status
= U_ZERO_ERROR
;
807 strcpy(action
, "getting and testing of normal string of zero length string");
808 res
= ures_getByKey(theBundle
, "emptystring", res
, &status
);
809 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
810 CONFIRM_INT_EQ(ures_getType(res
), URES_STRING
);
811 zeroString
=tres_getString(res
, -1, NULL
, &len
, &status
);
812 if(U_SUCCESS(status
)){
813 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
814 CONFIRM_INT_EQ(len
, 0);
815 CONFIRM_INT_EQ(u_strlen(zeroString
), 0);
818 log_err("Couldn't get emptystring\n");
821 status
= U_ZERO_ERROR
;
822 strcpy(action
, "getting and testing of empty int");
823 res
= ures_getByKey(theBundle
, "emptyint", res
, &status
);
824 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
825 CONFIRM_INT_EQ(ures_getType(res
), URES_INT
);
826 intResult
=ures_getInt(res
, &status
);
827 if(U_SUCCESS(status
)){
828 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
829 CONFIRM_INT_EQ(intResult
, 0);
832 log_err("Couldn't get emptystring\n");
835 status
= U_ZERO_ERROR
;
836 strcpy(action
, "getting and testing of zero length intvector");
837 res
= ures_getByKey(theBundle
, "emptyintv", res
, &status
);
838 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
839 CONFIRM_INT_EQ(ures_getType(res
), URES_INT_VECTOR
);
841 if(U_FAILURE(status
)){
842 log_err("Couldn't get emptyintv key %s\n", u_errorName(status
));
845 zeroIntVect
=ures_getIntVector(res
, &len
, &status
);
846 if(!U_SUCCESS(status
) || resArray
!= NULL
|| len
!= 0) {
847 log_err("Shouldn't get emptyintv\n");
851 status
= U_ZERO_ERROR
;
852 strcpy(action
, "getting and testing of zero length emptybin");
853 res
= ures_getByKey(theBundle
, "emptybin", res
, &status
);
854 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
855 CONFIRM_INT_EQ(ures_getType(res
), URES_BINARY
);
857 if(U_FAILURE(status
)){
858 log_err("Couldn't get emptybin key %s\n", u_errorName(status
));
861 binResult
=ures_getBinary(res
, &len
, &status
);
862 if(!U_SUCCESS(status
) || len
!= 0) {
863 log_err("Couldn't get emptybin, or it's not empty\n");
867 status
= U_ZERO_ERROR
;
868 strcpy(action
, "getting and testing of zero length emptyarray");
869 res
= ures_getByKey(theBundle
, "emptyarray", res
, &status
);
870 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
871 CONFIRM_INT_EQ(ures_getType(res
), URES_ARRAY
);
873 if(U_FAILURE(status
)){
874 log_err("Couldn't get emptyarray key %s\n", u_errorName(status
));
877 resArray
=ures_getByIndex(res
, 0, resArray
, &status
);
878 if(U_SUCCESS(status
) || resArray
!= NULL
){
879 log_err("Shouldn't get emptyarray[0]\n");
883 status
= U_ZERO_ERROR
;
884 strcpy(action
, "getting and testing of zero length emptytable");
885 res
= ures_getByKey(theBundle
, "emptytable", res
, &status
);
886 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
887 CONFIRM_INT_EQ(ures_getType(res
), URES_TABLE
);
889 if(U_FAILURE(status
)){
890 log_err("Couldn't get emptytable key %s\n", u_errorName(status
));
893 resArray
=ures_getByIndex(res
, 0, resArray
, &status
);
894 if(U_SUCCESS(status
) || resArray
!= NULL
){
895 log_err("Shouldn't get emptytable[0]\n");
900 ures_close(theBundle
);
903 static void TestEmptyBundle(){
904 UErrorCode status
= U_ZERO_ERROR
;
905 const char* testdatapath
=NULL
;
906 UResourceBundle
*resb
=0, *dResB
=0;
908 testdatapath
=loadTestData(&status
);
909 if(U_FAILURE(status
))
911 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
914 resb
= ures_open(testdatapath
, "testempty", &status
);
916 if(U_SUCCESS(status
)){
917 dResB
= ures_getByKey(resb
,"test",dResB
,&status
);
918 if(status
!= U_MISSING_RESOURCE_ERROR
){
919 log_err("Did not get the expected error from an empty resource bundle. Expected : %s Got: %s\n",
920 u_errorName(U_MISSING_RESOURCE_ERROR
),u_errorName(status
));
927 static void TestBinaryCollationData(){
928 UErrorCode status
=U_ZERO_ERROR
;
929 const char* locale
="te";
930 #if !UCONFIG_NO_COLLATION
931 const char* testdatapath
;
933 UResourceBundle
*teRes
= NULL
;
934 UResourceBundle
*coll
=NULL
;
935 UResourceBundle
*binColl
= NULL
;
936 uint8_t *binResult
= NULL
;
938 const char* action
="testing the binary collaton data";
940 #if !UCONFIG_NO_COLLATION
941 log_verbose("Testing binary collation data resource......\n");
943 testdatapath
=loadTestData(&status
);
944 if(U_FAILURE(status
))
946 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
951 teRes
=ures_open(testdatapath
, locale
, &status
);
952 if(U_FAILURE(status
)){
953 log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status
));
957 coll
= ures_getByKey(teRes
, "collations", coll
, &status
);
958 coll
= ures_getByKey(coll
, "standard", coll
, &status
);
959 if(U_SUCCESS(status
)){
960 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
961 CONFIRM_INT_EQ(ures_getType(coll
), URES_TABLE
);
962 binColl
=ures_getByKey(coll
, "%%CollationBin", binColl
, &status
);
963 if(U_SUCCESS(status
)){
964 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
965 CONFIRM_INT_EQ(ures_getType(binColl
), URES_BINARY
);
966 binResult
=(uint8_t*)ures_getBinary(binColl
, &len
, &status
);
967 if(U_SUCCESS(status
)){
968 CONFIRM_ErrorCode(status
, U_ZERO_ERROR
);
969 CONFIRM_INT_GE(len
, 1);
973 log_err("ERROR: ures_getByKey(locale(te), %%CollationBin) failed\n");
977 log_err("ERROR: ures_getByKey(locale(te), collations) failed\n");
986 static void TestAPI() {
987 UErrorCode status
=U_ZERO_ERROR
;
989 const char* key
=NULL
;
990 const UChar
* value
=NULL
;
991 const char* testdatapath
;
992 UChar
* utestdatapath
=NULL
;
993 char convOutput
[256];
994 UChar largeBuffer
[1025];
995 UResourceBundle
*teRes
= NULL
;
996 UResourceBundle
*teFillin
=NULL
;
997 UResourceBundle
*teFillin2
=NULL
;
999 log_verbose("Testing ures_openU()......\n");
1001 testdatapath
=loadTestData(&status
);
1002 if(U_FAILURE(status
))
1004 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1007 len
=(int32_t)strlen(testdatapath
);
1008 utestdatapath
= (UChar
*) malloc((len
+10)*sizeof(UChar
));
1010 u_charsToUChars(testdatapath
, utestdatapath
, (int32_t)strlen(testdatapath
)+1);
1011 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) && U_FILE_SEP_CHAR == '\\'
1013 /* Convert all backslashes to forward slashes so that we can make sure that ures_openU
1014 can handle invariant characters. */
1016 while ((backslash
= u_strchr(utestdatapath
, 0x005C))) {
1017 *backslash
= 0x002F;
1022 u_memset(largeBuffer
, 0x0030, sizeof(largeBuffer
)/sizeof(largeBuffer
[0]));
1023 largeBuffer
[sizeof(largeBuffer
)/sizeof(largeBuffer
[0])-1] = 0;
1025 /*Test ures_openU */
1027 status
= U_ZERO_ERROR
;
1028 ures_close(ures_openU(largeBuffer
, "root", &status
));
1029 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1030 log_err("ERROR: ures_openU() worked when the path is very large. It returned %s\n", myErrorName(status
));
1033 status
= U_ZERO_ERROR
;
1034 ures_close(ures_openU(NULL
, "root", &status
));
1035 if(U_FAILURE(status
)){
1036 log_err_status(status
, "ERROR: ures_openU() failed path = NULL with %s\n", myErrorName(status
));
1039 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1040 if(ures_openU(NULL
, "root", &status
) != NULL
){
1041 log_err("ERROR: ures_openU() worked with error status with %s\n", myErrorName(status
));
1044 status
= U_ZERO_ERROR
;
1045 teRes
=ures_openU(utestdatapath
, "te", &status
);
1046 if(U_FAILURE(status
)){
1047 log_err_status(status
, "ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath
), myErrorName(status
));
1050 /*Test ures_getLocale() */
1051 log_verbose("Testing ures_getLocale() .....\n");
1052 if(strcmp(ures_getLocale(teRes
, &status
), "te") != 0){
1053 log_err("ERROR: ures_getLocale() failed. Expected = te_TE Got = %s\n", ures_getLocale(teRes
, &status
));
1055 /*Test ures_getNextString() */
1056 teFillin
=ures_getByKey(teRes
, "tagged_array_in_te_te_IN", teFillin
, &status
);
1057 key
=ures_getKey(teFillin
);
1058 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1059 ures_resetIterator(NULL
);
1060 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1061 if(status
!=U_INDEX_OUTOFBOUNDS_ERROR
){
1062 log_err("ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1063 myErrorName(status
));
1065 ures_resetIterator(teRes
);
1066 /*Test ures_getNextResource() where resource is table*/
1067 status
=U_ZERO_ERROR
;
1068 #if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
1069 /* The next key varies depending on the charset. */
1070 teFillin
=ures_getNextResource(teRes
, teFillin
, &status
);
1071 if(U_FAILURE(status
)){
1072 log_err("ERROR: ures_getNextResource() failed \n");
1074 key
=ures_getKey(teFillin
);
1075 /*if(strcmp(key, "%%CollationBin") != 0){*/
1076 /*if(strcmp(key, "array_2d_in_Root_te") != 0){*/ /* added "aliasClient" that goes first */
1077 if(strcmp(key
, "a") != 0){
1078 log_err("ERROR: ures_getNextResource() failed\n");
1082 /*Test ures_getByIndex on string Resource*/
1083 teFillin
=ures_getByKey(teRes
, "string_only_in_te", teFillin
, &status
);
1084 teFillin2
=ures_getByIndex(teFillin
, 0, teFillin2
, &status
);
1085 if(U_FAILURE(status
)){
1086 log_err("ERROR: ures_getByIndex on string resource failed\n");
1088 if(strcmp(u_austrcpy(convOutput
, tres_getString(teFillin2
, -1, NULL
, &len
, &status
)), "TE") != 0){
1089 status
=U_ZERO_ERROR
;
1090 log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2
, &len
, &status
)));
1093 /*ures_close(teRes);*/
1095 /*Test ures_openFillIn*/
1096 log_verbose("Testing ures_openFillIn......\n");
1097 status
=U_ZERO_ERROR
;
1098 ures_openFillIn(teRes
, testdatapath
, "te", &status
);
1099 if(U_FAILURE(status
)){
1100 log_err("ERROR: ures_openFillIn failed\n");
1103 if(strcmp(ures_getLocale(teRes
, &status
), "te") != 0){
1104 log_err("ERROR: ures_openFillIn did not open the ResourceBundle correctly\n");
1106 ures_getByKey(teRes
, "string_only_in_te", teFillin
, &status
);
1107 teFillin2
=ures_getNextResource(teFillin
, teFillin2
, &status
);
1108 if(ures_getType(teFillin2
) != URES_STRING
){
1109 log_err("ERROR: getType for getNextResource after ures_openFillIn failed\n");
1111 teFillin2
=ures_getNextResource(teFillin
, teFillin2
, &status
);
1112 if(status
!=U_INDEX_OUTOFBOUNDS_ERROR
){
1113 log_err("ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
1114 myErrorName(status
));
1117 ures_close(teFillin
);
1118 ures_close(teFillin2
);
1121 /* Test that ures_getLocale() returns the "real" locale ID */
1122 status
=U_ZERO_ERROR
;
1123 teRes
=ures_open(NULL
, "dE_At_NOWHERE_TO_BE_FOUND", &status
);
1124 if(U_FAILURE(status
)) {
1125 log_data_err("unable to open a locale resource bundle from \"dE_At_NOWHERE_TO_BE_FOUND\"(%s)\n", u_errorName(status
));
1127 if(0!=strcmp("de_AT", ures_getLocale(teRes
, &status
))) {
1128 log_data_err("ures_getLocale(\"dE_At_NOWHERE_TO_BE_FOUND\")=%s but must be de_AT\n", ures_getLocale(teRes
, &status
));
1133 /* same test, but with an aliased locale resource bundle */
1134 status
=U_ZERO_ERROR
;
1135 teRes
=ures_open(NULL
, "iW_Il_depRecaTed_HebreW", &status
);
1136 if(U_FAILURE(status
)) {
1137 log_data_err("unable to open a locale resource bundle from \"iW_Il_depRecaTed_HebreW\"(%s)\n", u_errorName(status
));
1139 if(0!=strcmp("he_IL", ures_getLocale(teRes
, &status
))) {
1140 log_data_err("ures_getLocale(\"iW_Il_depRecaTed_HebreW\")=%s but must be he_IL\n", ures_getLocale(teRes
, &status
));
1144 free(utestdatapath
);
1147 static void TestErrorConditions(){
1148 UErrorCode status
=U_ZERO_ERROR
;
1149 const char *key
=NULL
;
1150 const UChar
*value
=NULL
;
1151 const char* testdatapath
;
1152 UChar
* utestdatapath
;
1154 UResourceBundle
*teRes
= NULL
;
1155 UResourceBundle
*coll
=NULL
;
1156 UResourceBundle
*binColl
= NULL
;
1157 UResourceBundle
*teFillin
=NULL
;
1158 UResourceBundle
*teFillin2
=NULL
;
1159 uint8_t *binResult
= NULL
;
1163 testdatapath
= loadTestData(&status
);
1164 if(U_FAILURE(status
))
1166 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1169 len
= (int32_t)strlen(testdatapath
);
1170 utestdatapath
= (UChar
*) malloc(sizeof(UChar
) *(len
+10));
1171 u_uastrcpy(utestdatapath
, testdatapath
);
1173 /*Test ures_openU with status != U_ZERO_ERROR*/
1174 log_verbose("Testing ures_openU() with status != U_ZERO_ERROR.....\n");
1175 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1176 teRes
=ures_openU(utestdatapath
, "te", &status
);
1177 if(U_FAILURE(status
)){
1178 log_verbose("ures_openU() failed as expected path =%s with status != U_ZERO_ERROR\n", testdatapath
);
1180 log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath
));
1183 /*Test ures_openFillIn with UResourceBundle = NULL*/
1184 log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
1185 status
=U_ZERO_ERROR
;
1186 ures_openFillIn(NULL
, testdatapath
, "te", &status
);
1187 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1188 log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1189 myErrorName(status
));
1191 /*Test ures_getLocale() with status != U_ZERO_ERROR*/
1192 status
=U_ZERO_ERROR
;
1193 teRes
=ures_openU(utestdatapath
, "te", &status
);
1194 if(U_FAILURE(status
)){
1195 log_err("ERROR: ures_openU() failed path =%s with %s\n", austrdup(utestdatapath
), myErrorName(status
));
1198 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1199 if(ures_getLocale(teRes
, &status
) != NULL
){
1200 log_err("ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR\n");
1202 /*Test ures_getLocale() with UResourceBundle = NULL*/
1203 status
=U_ZERO_ERROR
;
1204 if(ures_getLocale(NULL
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1205 log_err("ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1206 myErrorName(status
));
1208 /*Test ures_getSize() with UResourceBundle = NULL */
1209 status
=U_ZERO_ERROR
;
1210 if(ures_getSize(NULL
) != 0){
1211 log_err("ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d\n", ures_getSize(NULL
));
1213 /*Test ures_getType() with UResourceBundle = NULL should return URES_NONE==-1*/
1214 status
=U_ZERO_ERROR
;
1215 if(ures_getType(NULL
) != URES_NONE
){
1216 log_err("ERROR: ures_getType() should return URES_NONE when UResourceBundle=NULL. Got =%d\n", ures_getType(NULL
));
1218 /*Test ures_getKey() with UResourceBundle = NULL*/
1219 status
=U_ZERO_ERROR
;
1220 if(ures_getKey(NULL
) != NULL
){
1221 log_err("ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d\n", ures_getKey(NULL
));
1223 /*Test ures_hasNext() with UResourceBundle = NULL*/
1224 status
=U_ZERO_ERROR
;
1225 if(ures_hasNext(NULL
) != FALSE
){
1226 log_err("ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d\n", ures_hasNext(NULL
));
1228 /*Test ures_get() with UResourceBundle = NULL*/
1229 status
=U_ZERO_ERROR
;
1230 if(ures_getStringByKey(NULL
, "string_only_in_te", &resultLen
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1231 log_err("ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1232 myErrorName(status
));
1234 /*Test ures_getByKey() with UResourceBundle = NULL*/
1235 status
=U_ZERO_ERROR
;
1236 teFillin
=ures_getByKey(NULL
, "string_only_in_te", teFillin
, &status
);
1237 if( teFillin
!= NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1238 log_err("ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1239 myErrorName(status
));
1241 /*Test ures_getByKey() with status != U_ZERO_ERROR*/
1242 teFillin
=ures_getByKey(NULL
, "string_only_in_te", teFillin
, &status
);
1243 if(teFillin
!= NULL
){
1244 log_err("ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR\n");
1246 /*Test ures_getStringByKey() with UResourceBundle = NULL*/
1247 status
=U_ZERO_ERROR
;
1248 if(ures_getStringByKey(NULL
, "string_only_in_te", &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1249 log_err("ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1250 myErrorName(status
));
1252 /*Test ures_getStringByKey() with status != U_ZERO_ERROR*/
1253 if(ures_getStringByKey(teRes
, "string_only_in_te", &len
, &status
) != NULL
){
1254 log_err("ERROR: ures_getStringByKey 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_getString() with UResourceBundle = NULL*/
1258 status
=U_ZERO_ERROR
;
1259 if(ures_getString(NULL
, &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1260 log_err("ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1261 myErrorName(status
));
1263 /*Test ures_getString() with status != U_ZERO_ERROR*/
1264 if(ures_getString(teRes
, &len
, &status
) != NULL
){
1265 log_err("ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1266 myErrorName(status
));
1268 /*Test ures_getBinary() with UResourceBundle = NULL*/
1269 status
=U_ZERO_ERROR
;
1270 if(ures_getBinary(NULL
, &len
, &status
) != NULL
&& status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1271 log_err("ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1272 myErrorName(status
));
1274 /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
1275 status
=U_ZERO_ERROR
;
1276 coll
= ures_getByKey(teRes
, "collations", coll
, &status
);
1277 coll
= ures_getByKey(teRes
, "standard", coll
, &status
);
1278 binColl
=ures_getByKey(coll
, "%%CollationBin", binColl
, &status
);
1280 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1281 binResult
=(uint8_t*)ures_getBinary(binColl
, &len
, &status
);
1282 if(binResult
!= NULL
){
1283 log_err("ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail\n");
1286 /*Test ures_getNextResource() with status != U_ZERO_ERROR*/
1287 teFillin
=ures_getNextResource(teRes
, teFillin
, &status
);
1288 if(teFillin
!= NULL
){
1289 log_err("ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1291 /*Test ures_getNextResource() with UResourceBundle = NULL*/
1292 status
=U_ZERO_ERROR
;
1293 teFillin
=ures_getNextResource(NULL
, teFillin
, &status
);
1294 if(teFillin
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1295 log_err("ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s\n",
1296 myErrorName(status
));
1298 /*Test ures_getNextString with errorCode != U_ZERO_ERROR*/
1299 teFillin
=ures_getByKey(teRes
, "tagged_array_in_te_te_IN", teFillin
, &status
);
1300 key
=ures_getKey(teFillin
);
1301 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1302 value
=(UChar
*)ures_getNextString(teFillin
, &len
, &key
, &status
);
1304 log_err("ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1306 /*Test ures_getNextString with UResourceBundle = NULL*/
1307 status
=U_ZERO_ERROR
;
1308 value
=(UChar
*)ures_getNextString(NULL
, &len
, &key
, &status
);
1309 if(value
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1310 log_err("ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1311 myErrorName(status
));
1313 /*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/
1314 status
=U_ZERO_ERROR
;
1315 teFillin
=ures_getByKey(teRes
, "array_only_in_te", teFillin
, &status
);
1316 if(ures_countArrayItems(teRes
, "array_only_in_te", &status
) != 4) {
1317 log_err("ERROR: Wrong number of items in an array!\n");
1319 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1320 teFillin2
=ures_getByIndex(teFillin
, 0, teFillin2
, &status
);
1321 if(teFillin2
!= NULL
){
1322 log_err("ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1324 /*Test ures_getByIndex with UResourceBundle = NULL */
1325 status
=U_ZERO_ERROR
;
1326 teFillin2
=ures_getByIndex(NULL
, 0, teFillin2
, &status
);
1327 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1328 log_err("ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1329 myErrorName(status
));
1331 /*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/
1332 status
=U_ZERO_ERROR
;
1333 teFillin
=ures_getByKey(teRes
, "array_only_in_te", teFillin
, &status
);
1334 status
=U_ILLEGAL_ARGUMENT_ERROR
;
1335 value
=(UChar
*)ures_getStringByIndex(teFillin
, 0, &len
, &status
);
1337 log_err("ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1339 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1340 status
=U_ZERO_ERROR
;
1341 value
=(UChar
*)ures_getStringByIndex(NULL
, 0, &len
, &status
);
1342 if(value
!= NULL
|| status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1343 log_err("ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1344 myErrorName(status
));
1346 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1347 status
=U_ZERO_ERROR
;
1348 value
=(UChar
*)ures_getStringByIndex(teFillin
, 9999, &len
, &status
);
1349 if(value
!= NULL
|| status
!= U_MISSING_RESOURCE_ERROR
){
1350 log_err("ERROR: ures_getStringByIndex() with index that is too big is supposed to fail\n Expected: U_MISSING_RESOURCE_ERROR, Got: %s\n",
1351 myErrorName(status
));
1353 /*Test ures_getInt() where UResourceBundle = NULL */
1354 status
=U_ZERO_ERROR
;
1355 if(ures_getInt(NULL
, &status
) != -1 && status
!= U_ILLEGAL_ARGUMENT_ERROR
){
1356 log_err("ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s\n",
1357 myErrorName(status
));
1359 /*Test ures_getInt() where status != U_ZERO_ERROR */
1360 if(ures_getInt(teRes
, &status
) != -1){
1361 log_err("ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail\n");
1364 ures_close(teFillin
);
1365 ures_close(teFillin2
);
1367 ures_close(binColl
);
1369 free(utestdatapath
);
1374 static void TestGetVersion(){
1375 UVersionInfo minVersionArray
= {0x01, 0x00, 0x00, 0x00};
1376 UVersionInfo maxVersionArray
= {0x50, 0xff, 0xcf, 0xcf};
1377 UVersionInfo versionArray
;
1378 UErrorCode status
= U_ZERO_ERROR
;
1379 UResourceBundle
* resB
= NULL
;
1381 int locCount
= uloc_countAvailable();
1382 const char *locName
= "root";
1384 log_verbose("The ures_getVersion tests begin : \n");
1386 for(j
= -1; j
< locCount
; j
++) {
1388 locName
= uloc_getAvailable(j
);
1390 log_verbose("Testing version number for locale %s\n", locName
);
1391 resB
= ures_open(NULL
,locName
, &status
);
1392 if (U_FAILURE(status
)) {
1393 log_err_status(status
, "Resource bundle creation for locale %s failed.: %s\n", locName
, myErrorName(status
));
1397 ures_getVersion(resB
, versionArray
);
1398 for (i
=0; i
<4; ++i
) {
1399 if (versionArray
[i
] < minVersionArray
[i
] ||
1400 versionArray
[i
] > maxVersionArray
[i
])
1402 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1403 locName
, versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
1412 static void TestGetVersionColl(){
1413 UVersionInfo minVersionArray
= {0x00, 0x00, 0x00, 0x00};
1414 UVersionInfo maxVersionArray
= {0x50, 0x80, 0xcf, 0xcf};
1415 UVersionInfo versionArray
;
1416 UErrorCode status
= U_ZERO_ERROR
;
1417 UResourceBundle
* resB
= NULL
;
1418 UEnumeration
*locs
= NULL
;
1420 const char *locName
= "root";
1422 const UChar
* rules
=NULL
;
1425 log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL
);
1426 locs
= ures_openAvailableLocales(U_ICUDATA_COLL
, &status
);
1427 if (U_FAILURE(status
)) {
1428 log_err_status(status
, "enumeration of %s failed.: %s\n", U_ICUDATA_COLL
, myErrorName(status
));
1433 log_verbose("Testing version number for locale %s\n", locName
);
1434 resB
= ures_open(U_ICUDATA_COLL
,locName
, &status
);
1435 if (U_FAILURE(status
)) {
1436 log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL
, locName
, myErrorName(status
));
1440 /* test NUL termination of UCARules */
1441 rules
= tres_getString(resB
,-1,"UCARules",&len
, &status
);
1442 if(!rules
|| U_FAILURE(status
)) {
1443 log_data_err("Could not load UCARules for locale %s\n", locName
);
1446 if(u_strlen(rules
) != len
){
1447 log_err("UCARules string not nul terminated! \n");
1449 ures_getVersion(resB
, versionArray
);
1450 for (i
=0; i
<4; ++i
) {
1451 if (versionArray
[i
] < minVersionArray
[i
] ||
1452 versionArray
[i
] > maxVersionArray
[i
])
1454 log_err("Testing ures_getVersion(%-5s) - unexpected result: %d.%d.%d.%d\n",
1455 locName
, versionArray
[0], versionArray
[1], versionArray
[2], versionArray
[3]);
1460 } while((locName
= uenum_next(locs
,&locLen
,&status
))&&U_SUCCESS(status
));
1462 if(U_FAILURE(status
)) {
1463 log_err("Err %s testing Collation locales.\n", u_errorName(status
));
1468 static void TestResourceBundles()
1470 UErrorCode status
= U_ZERO_ERROR
;
1471 loadTestData(&status
);
1472 if(U_FAILURE(status
)) {
1473 log_data_err("Could not load testdata.dat, status = %s\n", u_errorName(status
));
1477 testTag("only_in_Root", TRUE
, FALSE
, FALSE
);
1478 testTag("in_Root_te", TRUE
, TRUE
, FALSE
);
1479 testTag("in_Root_te_te_IN", TRUE
, TRUE
, TRUE
);
1480 testTag("in_Root_te_IN", TRUE
, FALSE
, TRUE
);
1481 testTag("only_in_te", FALSE
, TRUE
, FALSE
);
1482 testTag("only_in_te_IN", FALSE
, FALSE
, TRUE
);
1483 testTag("in_te_te_IN", FALSE
, TRUE
, TRUE
);
1484 testTag("nonexistent", FALSE
, FALSE
, FALSE
);
1486 log_verbose("Passed:= %d Failed= %d \n", pass
, fail
);
1491 static void TestConstruction1()
1493 UResourceBundle
*test1
= 0, *test2
= 0,*empty
= 0;
1494 const UChar
*result1
, *result2
;
1495 UErrorCode status
= U_ZERO_ERROR
;
1496 UErrorCode err
= U_ZERO_ERROR
;
1497 const char* locale
="te_IN";
1498 const char* testdatapath
;
1502 UVersionInfo versionInfo
;
1503 char versionString
[256];
1504 char verboseOutput
[256];
1506 U_STRING_DECL(rootVal
, "ROOT", 4);
1507 U_STRING_DECL(te_inVal
, "TE_IN", 5);
1509 U_STRING_INIT(rootVal
, "ROOT", 4);
1510 U_STRING_INIT(te_inVal
, "TE_IN", 5);
1512 testdatapath
=loadTestData(&status
);
1513 if(U_FAILURE(status
))
1515 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1519 log_verbose("Testing ures_open()......\n");
1521 empty
= ures_open(testdatapath
, "testempty", &status
);
1522 if(empty
== NULL
|| U_FAILURE(status
)) {
1523 log_err("opening empty failed!\n");
1527 test1
=ures_open(testdatapath
, NULL
, &err
);
1531 log_err("construction of NULL did not succeed : %s \n", myErrorName(status
));
1534 test2
=ures_open(testdatapath
, locale
, &err
);
1537 log_err("construction of %s did not succeed : %s \n", locale
, myErrorName(status
));
1540 result1
= tres_getString(test1
, -1, "string_in_Root_te_te_IN", &len1
, &err
);
1541 result2
= tres_getString(test2
, -1, "string_in_Root_te_te_IN", &len2
, &err
);
1542 if (U_FAILURE(err
) || len1
==0 || len2
==0) {
1543 log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status
));
1546 log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput
, result1
));
1547 log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput
, result2
));
1548 if(u_strcmp(result1
, rootVal
) !=0 || u_strcmp(result2
, te_inVal
) !=0 ){
1549 log_err("construction test failed. Run Verbose for more information");
1553 /* Test getVersionNumber*/
1554 log_verbose("Testing version number\n");
1555 log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1
));
1557 log_verbose("Testing version \n");
1558 ures_getVersion(test1
, versionInfo
);
1559 u_versionToString(versionInfo
, versionString
);
1561 log_verbose("for getVersion : %s\n", versionString
);
1563 if(strcmp(versionString
, ures_getVersionNumber(test1
)) != 0) {
1564 log_err("Versions differ: %s vs %s\n", versionString
, ures_getVersionNumber(test1
));
1572 /*****************************************************************************/
1573 /*****************************************************************************/
1575 static UBool
testTag(const char* frag
,
1580 int32_t failNum
= fail
;
1582 /* Make array from input params */
1585 const char *NAME
[] = { "ROOT", "TE", "TE_IN" };
1587 /* Now try to load the desired items */
1588 UResourceBundle
* theBundle
= NULL
;
1591 UErrorCode expected_status
,status
= U_ZERO_ERROR
,expected_resource_status
= U_ZERO_ERROR
;
1593 UChar
* expected_string
= NULL
;
1594 const UChar
* string
= NULL
;
1597 int32_t i
,j
,row
,col
, len
;
1598 int32_t actual_bundle
;
1600 int32_t row_count
=0;
1601 int32_t column_count
=0;
1603 int32_t tag_count
= 0;
1604 const char* testdatapath
;
1605 char verboseOutput
[256];
1606 UResourceBundle
* array
=NULL
;
1607 UResourceBundle
* array2d
=NULL
;
1608 UResourceBundle
* tags
=NULL
;
1609 UResourceBundle
* arrayItem1
=NULL
;
1611 testdatapath
= loadTestData(&status
);
1612 if(U_FAILURE(status
))
1614 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
1620 is_in
[2] = in_te_IN
;
1622 strcpy(item_tag
, "tag");
1624 for (i
=0; i
<bundles_count
; ++i
)
1626 strcpy(action
,"construction for ");
1627 strcat(action
, param
[i
].name
);
1630 status
= U_ZERO_ERROR
;
1632 theBundle
= ures_open(testdatapath
, param
[i
].name
, &status
);
1633 CONFIRM_ErrorCode(status
,param
[i
].expected_constructor_status
);
1636 actual_bundle
= 0; /* ne -> default */
1638 actual_bundle
= 1; /* te_NE -> te */
1640 actual_bundle
= 2; /* te_IN_NE -> te_IN */
1644 expected_resource_status
= U_MISSING_RESOURCE_ERROR
;
1645 for (j
=e_te_IN
; j
>=e_Root
; --j
)
1647 if (is_in
[j
] && param
[i
].inherits
[j
])
1650 if(j
== actual_bundle
) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
1651 expected_resource_status
= U_ZERO_ERROR
;
1653 expected_resource_status
= U_USING_DEFAULT_WARNING
;
1655 expected_resource_status
= U_USING_FALLBACK_WARNING
;
1657 log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n",
1662 is_in
[j
]?"Yes":"No",
1664 param
[i
].inherits
[j
]?"Yes":"No",
1665 param
[actual_bundle
].name
);
1671 for (j
=param
[i
].where
; j
>=0; --j
)
1679 base
=(UChar
*)malloc(sizeof(UChar
)*(strlen(NAME
[j
]) + 1));
1680 u_uastrcpy(base
,NAME
[j
]);
1689 base
= (UChar
*) malloc(sizeof(UChar
) * 1);
1694 /*----string---------------------------------------------------------------- */
1696 strcpy(tag
,"string_");
1699 strcpy(action
,param
[i
].name
);
1700 strcat(action
, ".ures_getStringByKey(" );
1702 strcat(action
, ")");
1705 status
= U_ZERO_ERROR
;
1708 string
=tres_getString(theBundle
, -1, tag
, &len
, &status
);
1709 if(U_SUCCESS(status
)) {
1710 expected_string
=(UChar
*)malloc(sizeof(UChar
)*(u_strlen(base
) + 4));
1711 u_strcpy(expected_string
,base
);
1712 CONFIRM_INT_EQ(len
, u_strlen(expected_string
));
1714 expected_string
= (UChar
*)malloc(sizeof(UChar
)*(u_strlen(kERROR
) + 1));
1715 u_strcpy(expected_string
,kERROR
);
1718 log_verbose("%s got %d, expected %d\n", action
, status
, expected_resource_status
);
1720 CONFIRM_ErrorCode(status
, expected_resource_status
);
1721 CONFIRM_EQ(string
, expected_string
);
1725 /*--------------array------------------------------------------------- */
1727 strcpy(tag
,"array_");
1730 strcpy(action
,param
[i
].name
);
1731 strcat(action
, ".ures_getByKey(" );
1733 strcat(action
, ")");
1737 count
= kERROR_COUNT
;
1738 status
= U_ZERO_ERROR
;
1739 array
=ures_getByKey(theBundle
, tag
, array
, &status
);
1740 CONFIRM_ErrorCode(status
,expected_resource_status
);
1741 if (U_SUCCESS(status
)) {
1742 /*confirm the resource type is an array*/
1743 CONFIRM_INT_EQ(ures_getType(array
), URES_ARRAY
);
1744 /*confirm the size*/
1745 count
=ures_getSize(array
);
1746 CONFIRM_INT_GE(count
,1);
1747 for (j
=0; j
<count
; ++j
) {
1749 u_strcpy(expected_string
, base
);
1750 u_uastrcpy(element
, itoa1(j
,buf
));
1751 u_strcat(expected_string
, element
);
1752 arrayItem1
=ures_getNextResource(array
, arrayItem1
, &status
);
1753 if(U_SUCCESS(status
)){
1754 CONFIRM_EQ(tres_getString(arrayItem1
, -1, NULL
, &len
, &status
),expected_string
);
1760 CONFIRM_INT_EQ(count
,kERROR_COUNT
);
1761 CONFIRM_ErrorCode(status
, U_MISSING_RESOURCE_ERROR
);
1762 /*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/
1766 /*--------------arrayItem------------------------------------------------- */
1768 strcpy(tag
,"array_");
1771 strcpy(action
,param
[i
].name
);
1772 strcat(action
, ".ures_getStringByIndex(");
1773 strcat(action
, tag
);
1774 strcat(action
, ")");
1777 for (j
=0; j
<10; ++j
){
1778 idx
= count
? (randi(count
* 3) - count
) : (randi(200) - 100);
1779 status
= U_ZERO_ERROR
;
1781 array
=ures_getByKey(theBundle
, tag
, array
, &status
);
1782 if(!U_FAILURE(status
)){
1784 t
=(UChar
*)ures_getStringByIndex(array
, idx
, &len
, &status
);
1785 if(!U_FAILURE(status
)){
1788 u_strcpy(expected_string
, base
);
1789 u_uastrcpy(element
, itoa1(idx
,buf
));
1790 u_strcat(expected_string
, element
);
1792 u_strcpy(expected_string
, kERROR
);
1796 expected_status
= (idx
>= 0 && idx
< count
) ? expected_resource_status
: U_MISSING_RESOURCE_ERROR
;
1797 CONFIRM_ErrorCode(status
,expected_status
);
1798 CONFIRM_EQ(string
,expected_string
);
1803 /*--------------2dArray------------------------------------------------- */
1805 strcpy(tag
,"array_2d_");
1808 strcpy(action
,param
[i
].name
);
1809 strcat(action
, ".ures_getByKey(" );
1811 strcat(action
, ")");
1815 row_count
= kERROR_COUNT
, column_count
= kERROR_COUNT
;
1816 status
= U_ZERO_ERROR
;
1817 array2d
=ures_getByKey(theBundle
, tag
, array2d
, &status
);
1819 CONFIRM_ErrorCode(status
,expected_resource_status
);
1820 if (U_SUCCESS(status
))
1822 /*confirm the resource type is an 2darray*/
1823 CONFIRM_INT_EQ(ures_getType(array2d
), URES_ARRAY
);
1824 row_count
=ures_getSize(array2d
);
1825 CONFIRM_INT_GE(row_count
,1);
1827 for(row
=0; row
<row_count
; ++row
){
1828 UResourceBundle
*tableRow
=NULL
;
1829 tableRow
=ures_getByIndex(array2d
, row
, tableRow
, &status
);
1830 CONFIRM_ErrorCode(status
, expected_resource_status
);
1831 if(U_SUCCESS(status
)){
1832 /*confirm the resourcetype of each table row is an array*/
1833 CONFIRM_INT_EQ(ures_getType(tableRow
), URES_ARRAY
);
1834 column_count
=ures_getSize(tableRow
);
1835 CONFIRM_INT_GE(column_count
,1);
1837 for (col
=0; j
<column_count
; ++j
) {
1839 u_strcpy(expected_string
, base
);
1840 u_uastrcpy(element
, itoa1(row
, buf
));
1841 u_strcat(expected_string
, element
);
1842 u_uastrcpy(element
, itoa1(col
, buf
));
1843 u_strcat(expected_string
, element
);
1844 arrayItem1
=ures_getNextResource(tableRow
, arrayItem1
, &status
);
1845 if(U_SUCCESS(status
)){
1846 const UChar
*stringValue
=tres_getString(arrayItem1
, -1, NULL
, &len
, &status
);
1847 CONFIRM_EQ(stringValue
, expected_string
);
1851 ures_close(tableRow
);
1854 CONFIRM_INT_EQ(row_count
,kERROR_COUNT
);
1855 CONFIRM_INT_EQ(column_count
,kERROR_COUNT
);
1856 row_count
=column_count
=0;
1860 /*------2dArrayItem-------------------------------------------------------------- */
1862 for (j
=0; j
<10; ++j
)
1864 row
= row_count
? (randi(row_count
* 3) - row_count
) : (randi(200) - 100);
1865 col
= column_count
? (randi(column_count
* 3) - column_count
) : (randi(200) - 100);
1866 status
= U_ZERO_ERROR
;
1869 array2d
=ures_getByKey(theBundle
, tag
, array2d
, &status
);
1870 if(U_SUCCESS(status
)){
1871 UResourceBundle
*tableRow
=NULL
;
1872 tableRow
=ures_getByIndex(array2d
, row
, tableRow
, &status
);
1873 if(U_SUCCESS(status
)) {
1875 t
=(UChar
*)ures_getStringByIndex(tableRow
, col
, &len
, &status
);
1876 if(U_SUCCESS(status
)){
1880 ures_close(tableRow
);
1882 expected_status
= (row
>= 0 && row
< row_count
&& col
>= 0 && col
< column_count
) ?
1883 expected_resource_status
: U_MISSING_RESOURCE_ERROR
;
1884 CONFIRM_ErrorCode(status
,expected_status
);
1886 if (U_SUCCESS(status
)){
1888 u_strcpy(expected_string
, base
);
1889 u_uastrcpy(element
, itoa1(row
, buf
));
1890 u_strcat(expected_string
, element
);
1891 u_uastrcpy(element
, itoa1(col
, buf
));
1892 u_strcat(expected_string
, element
);
1894 u_strcpy(expected_string
,kERROR
);
1896 CONFIRM_EQ(string
,expected_string
);
1901 /*--------------taggedArray----------------------------------------------- */
1902 strcpy(tag
,"tagged_array_");
1905 strcpy(action
,param
[i
].name
);
1906 strcat(action
,".ures_getByKey(");
1907 strcat(action
, tag
);
1911 status
= U_ZERO_ERROR
;
1913 tags
=ures_getByKey(theBundle
, tag
, tags
, &status
);
1914 CONFIRM_ErrorCode(status
, expected_resource_status
);
1915 if (U_SUCCESS(status
)) {
1916 UResType bundleType
=ures_getType(tags
);
1917 CONFIRM_INT_EQ(bundleType
, URES_TABLE
);
1919 tag_count
=ures_getSize(tags
);
1920 CONFIRM_INT_GE((int32_t)tag_count
, (int32_t)0);
1922 for(idx
=0; idx
<tag_count
; idx
++){
1923 UResourceBundle
*tagelement
=NULL
;
1924 const char *key
=NULL
;
1926 tagelement
=ures_getByIndex(tags
, idx
, tagelement
, &status
);
1927 key
=ures_getKey(tagelement
);
1928 value
=(UChar
*)ures_getNextString(tagelement
, &len
, &key
, &status
);
1929 log_verbose("tag = %s, value = %s\n", key
, u_austrcpy(verboseOutput
, value
));
1930 if(strncmp(key
, "tag", 3) == 0 && u_strncmp(value
, base
, u_strlen(base
)) == 0){
1935 ures_close(tagelement
);
1941 /*---------taggedArrayItem----------------------------------------------*/
1943 for (idx
=-20; idx
<20; ++idx
)
1946 status
= U_ZERO_ERROR
;
1948 strcpy(item_tag
, "tag");
1949 strcat(item_tag
, itoa1(idx
,buf
));
1950 tags
=ures_getByKey(theBundle
, tag
, tags
, &status
);
1951 if(U_SUCCESS(status
)){
1952 UResourceBundle
*tagelement
=NULL
;
1954 tagelement
=ures_getByKey(tags
, item_tag
, tagelement
, &status
);
1955 if(!U_FAILURE(status
)){
1956 UResType elementType
=ures_getType(tagelement
);
1957 CONFIRM_INT_EQ(elementType
, URES_STRING
);
1958 if(strcmp(ures_getKey(tagelement
), item_tag
) == 0){
1963 t
=(UChar
*)tres_getString(tagelement
, -1, NULL
, &len
, &status
);
1964 if(!U_FAILURE(status
)){
1969 CONFIRM_ErrorCode(status
,U_MISSING_RESOURCE_ERROR
);
1972 if (status
!= U_MISSING_RESOURCE_ERROR
) {
1974 u_strcpy(expected_string
, base
);
1975 u_uastrcpy(element
, itoa1(idx
,buf
));
1976 u_strcat(expected_string
, element
);
1977 CONFIRM_EQ(string
,expected_string
);
1981 ures_close(tagelement
);
1984 CONFIRM_INT_EQ(count
, tag_count
);
1986 free(expected_string
);
1987 ures_close(theBundle
);
1990 ures_close(array2d
);
1992 ures_close(arrayItem1
);
1994 return (UBool
)(failNum
== fail
);
1997 static void record_pass()
2002 static void record_fail()
2008 * Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR
2012 static void TestFallback()
2014 UErrorCode status
= U_ZERO_ERROR
;
2015 UResourceBundle
*fr_FR
= NULL
;
2016 UResourceBundle
*subResource
= NULL
;
2017 const UChar
*junk
; /* ignored */
2020 log_verbose("Opening fr_FR..");
2021 fr_FR
= ures_open(NULL
, "fr_FR", &status
);
2022 if(U_FAILURE(status
))
2024 log_err_status(status
, "Couldn't open fr_FR - %s\n", u_errorName(status
));
2028 status
= U_ZERO_ERROR
;
2031 /* clear it out.. just do some calls to get the gears turning */
2032 junk
= tres_getString(fr_FR
, -1, "LocaleID", &resultLen
, &status
);
2033 status
= U_ZERO_ERROR
;
2034 junk
= tres_getString(fr_FR
, -1, "LocaleString", &resultLen
, &status
);
2035 status
= U_ZERO_ERROR
;
2036 junk
= tres_getString(fr_FR
, -1, "LocaleID", &resultLen
, &status
);
2037 status
= U_ZERO_ERROR
;
2039 /* OK first one. This should be a Default value. */
2040 subResource
= ures_getByKey(fr_FR
, "MeasurementSystem", NULL
, &status
);
2041 if(status
!= U_USING_DEFAULT_WARNING
)
2043 log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get CurrencyMap from fr_FR, got %s\n",
2044 u_errorName(status
));
2047 status
= U_ZERO_ERROR
;
2048 ures_close(subResource
);
2050 /* and this is a Fallback, to fr */
2051 junk
= tres_getString(fr_FR
, -1, "ExemplarCharacters", &resultLen
, &status
);
2052 if(status
!= U_USING_FALLBACK_WARNING
)
2054 log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get ExemplarCharacters from fr_FR, got %d\n",
2058 status
= U_ZERO_ERROR
;
2061 /* Temporary hack err actually should be U_USING_FALLBACK_ERROR */
2062 /* Test Jitterbug 552 fallback mechanism of aliased data */
2064 UErrorCode err
=U_ZERO_ERROR
;
2065 UResourceBundle
* myResB
= ures_open(NULL
,"no_NO_NY",&err
);
2066 UResourceBundle
* resLocID
= ures_getByKey(myResB
, "Version", NULL
, &err
);
2067 UResourceBundle
* tResB
;
2068 UResourceBundle
* zoneResource
;
2069 const UChar
* version
= NULL
;
2070 static const UChar versionStr
[] = { 0x0032, 0x002E, 0x0030, 0x002E, 0x0038, 0x0032, 0x002E, 0x0034, 0x0035, 0x0000};
2072 if(err
!= U_ZERO_ERROR
){
2073 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
));
2076 version
= tres_getString(resLocID
, -1, NULL
, &resultLen
, &err
);
2077 if(u_strcmp(version
, versionStr
) != 0){
2080 u_austrcpy(x
, versionStr
);
2081 u_austrcpy(g
, version
);
2082 log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value. Expected '%s', but got '%s'\n",
2085 zoneResource
= ures_open(U_ICUDATA_ZONE
, "no_NO_NY", &err
);
2086 tResB
= ures_getByKey(zoneResource
, "zoneStrings", NULL
, &err
);
2087 if(err
!= U_USING_FALLBACK_WARNING
){
2088 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
));
2091 ures_close(zoneResource
);
2092 ures_close(resLocID
);
2098 /* static void printUChars(UChar* uchars){
2100 / for(i=0; i<u_strlen(uchars); i++){
2101 / log_err("%04X ", *(uchars+i));
2105 static void TestResourceLevelAliasing(void) {
2106 UErrorCode status
= U_ZERO_ERROR
;
2107 UResourceBundle
*aliasB
= NULL
, *tb
= NULL
;
2108 UResourceBundle
*en
= NULL
, *uk
= NULL
, *testtypes
= NULL
;
2109 const char* testdatapath
= NULL
;
2110 const UChar
*string
= NULL
, *sequence
= NULL
;
2111 /*const uint8_t *binary = NULL, *binSequence = NULL;*/
2112 int32_t strLen
= 0, seqLen
= 0;/*, binLen = 0, binSeqLen = 0;*/
2116 testdatapath
=loadTestData(&status
);
2117 if(U_FAILURE(status
))
2119 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
2123 aliasB
= ures_open(testdatapath
, "testaliases", &status
);
2125 if(U_FAILURE(status
))
2127 log_data_err("Could not load testaliases.res %s \n",myErrorName(status
));
2130 /* this should fail - circular alias */
2131 tb
= ures_getByKey(aliasB
, "aaa", tb
, &status
);
2132 if(status
!= U_TOO_MANY_ALIASES_ERROR
) {
2133 log_err("Failed to detect circular alias\n");
2136 status
= U_ZERO_ERROR
;
2138 tb
= ures_getByKey(aliasB
, "aab", tb
, &status
);
2139 if(status
!= U_TOO_MANY_ALIASES_ERROR
) {
2140 log_err("Failed to detect circular alias\n");
2142 status
= U_ZERO_ERROR
;
2144 if(U_FAILURE(status
) ) {
2145 log_data_err("err loading tb resource\n");
2147 /* testing aliasing to a non existing resource */
2148 tb
= ures_getByKey(aliasB
, "nonexisting", tb
, &status
);
2149 if(status
!= U_MISSING_RESOURCE_ERROR
) {
2150 log_err("Managed to find an alias to non-existing resource\n");
2152 status
= U_ZERO_ERROR
;
2154 /* testing referencing/composed alias */
2155 uk
= ures_findResource("ja/LocaleScript/2", uk
, &status
);
2156 if((uk
== NULL
) || U_FAILURE(status
)) {
2157 log_err_status(status
, "Couldn't findResource('ja/LocaleScript/2') err %s\n", u_errorName(status
));
2161 sequence
= tres_getString(uk
, -1, NULL
, &seqLen
, &status
);
2163 tb
= ures_getByKey(aliasB
, "referencingalias", tb
, &status
);
2164 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2166 if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2167 log_err("Referencing alias didn't get the right string (1)\n");
2170 string
= tres_getString(aliasB
, -1, "referencingalias", &strLen
, &status
);
2171 if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2172 log_err("Referencing alias didn't get the right string (2)\n");
2175 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2176 tb
= ures_getByKey(aliasB
, "LocaleScript", tb
, &status
);
2177 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2178 tb
= ures_getByIndex(tb
, 2, tb
, &status
);
2179 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2180 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2181 checkStatus(__LINE__
, U_ZERO_ERROR
, status
);
2183 if(U_FAILURE(status
)) {
2184 log_err("%s trying to get string via separate getters\n", u_errorName(status
));
2185 } else if(seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2186 log_err("Referencing alias didn't get the right string (3)\n");
2190 testtypes
= ures_open(testdatapath
, "testtypes", &status
);
2191 strcpy(buffer
, "menu/file/open");
2193 uk
= ures_findSubResource(testtypes
, s
, uk
, &status
);
2194 sequence
= tres_getString(uk
, -1, NULL
, &seqLen
, &status
);
2196 tb
= ures_getByKey(aliasB
, "simplealias", tb
, &status
);
2197 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2199 if(U_FAILURE(status
) || seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2200 log_err("Referencing alias didn't get the right string (4)\n");
2203 /* test indexed aliasing */
2205 tb
= ures_getByKey(aliasB
, "zoneTests", tb
, &status
);
2206 tb
= ures_getByKey(tb
, "zoneAlias2", tb
, &status
);
2207 string
= tres_getString(tb
, -1, NULL
, &strLen
, &status
);
2209 en
= ures_findResource("/ICUDATA-zone/en/zoneStrings/3/0", en
, &status
);
2210 sequence
= tres_getString(en
, -1, NULL
, &seqLen
, &status
);
2212 if(U_FAILURE(status
) || seqLen
!= strLen
|| u_strncmp(sequence
, string
, seqLen
) != 0) {
2213 log_err("Referencing alias didn't get the right string (5)\n");
2216 /* test getting aliased string by index */
2218 const char* keys
[] = {
2220 "KeyAlias1PacificStandardTime",
2222 "KeyAlias3LosAngeles"
2225 const char* strings
[] = {
2226 "America/Los_Angeles",
2227 "Pacific Standard Time",
2232 const UChar
* result
;
2233 int32_t uBufferLen
= 0, resultLen
= 0;
2235 const char *key
= NULL
;
2236 tb
= ures_getByKey(aliasB
, "testGetStringByKeyAliasing", tb
, &status
);
2237 if(U_FAILURE(status
)) {
2238 log_err("FAIL: Couldn't get testGetStringByKeyAliasing resource: %s\n", u_errorName(status
));
2240 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2241 result
= tres_getString(tb
, -1, keys
[i
], &resultLen
, &status
);
2242 if(U_FAILURE(status
)){
2243 log_err("(1) Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2246 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2247 if(resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2248 log_err("(1) Didn't get correct string while accessing alias table by key (%s)\n", keys
[i
]);
2251 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2252 result
= tres_getString(tb
, i
, NULL
, &resultLen
, &status
);
2253 if(U_FAILURE(status
)){
2254 log_err("(2) Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2257 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2258 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2259 log_err("(2) Didn't get correct string while accesing alias table by index (%s)\n", strings
[i
]);
2262 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2263 result
= ures_getNextString(tb
, &resultLen
, &key
, &status
);
2264 if(U_FAILURE(status
)){
2265 log_err("(3) Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2268 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2269 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2270 log_err("(3) Didn't get correct string while iterating over alias table (%s)\n", strings
[i
]);
2274 tb
= ures_getByKey(aliasB
, "testGetStringByIndexAliasing", tb
, &status
);
2275 if(U_FAILURE(status
)) {
2276 log_err("FAIL: Couldn't get testGetStringByIndexAliasing resource: %s\n", u_errorName(status
));
2278 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2279 result
= tres_getString(tb
, i
, NULL
, &resultLen
, &status
);
2280 if(U_FAILURE(status
)){
2281 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2284 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2285 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2286 log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings
[i
]);
2289 for(i
= 0; i
< sizeof(strings
)/sizeof(strings
[0]); i
++) {
2290 result
= ures_getNextString(tb
, &resultLen
, &key
, &status
);
2291 if(U_FAILURE(status
)){
2292 log_err("Fetching the resource with key %s failed. Error: %s\n", keys
[i
], u_errorName(status
));
2295 uBufferLen
= u_unescape(strings
[i
], uBuffer
, 256);
2296 if(result
==NULL
|| resultLen
!= uBufferLen
|| u_strncmp(result
, uBuffer
, resultLen
) != 0) {
2297 log_err("Didn't get correct string while iterating over aliases in an array (%s)\n", strings
[i
]);
2302 tb
= ures_getByKey(aliasB
, "testAliasToTree", tb
, &status
);
2303 if(U_FAILURE(status
)){
2304 log_err("Fetching the resource with key \"testAliasToTree\" failed. Error: %s\n", u_errorName(status
));
2307 if (strcmp(ures_getKey(tb
), "collations") != 0) {
2308 log_err("ures_getKey(aliasB) unexpectedly returned %s instead of \"collations\"\n", ures_getKey(tb
));
2315 ures_close(testtypes
);
2318 static void TestDirectAccess(void) {
2319 UErrorCode status
= U_ZERO_ERROR
;
2320 UResourceBundle
*t
= NULL
, *t2
= NULL
;
2321 const char* key
= NULL
;
2325 /*const char* testdatapath=loadTestData(&status);
2326 if(U_FAILURE(status)){
2327 log_err("Could not load testdata.dat %s \n",myErrorName(status));
2331 t
= ures_findResource("/testdata/te/zoneStrings/3/2", t
, &status
);
2332 if(U_FAILURE(status
)) {
2333 log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status
));
2334 status
= U_ZERO_ERROR
;
2336 key
= ures_getKey(t
);
2338 log_err("Got a strange key, expected NULL, got %s\n", key
);
2341 t
= ures_findResource("en/calendar/gregorian/DateTimePatterns/3", t
, &status
);
2342 if(U_FAILURE(status
)) {
2343 log_data_err("Couldn't access indexed resource, error %s\n", u_errorName(status
));
2344 status
= U_ZERO_ERROR
;
2346 key
= ures_getKey(t
);
2348 log_err("Got a strange key, expected NULL, got %s\n", key
);
2352 t
= ures_findResource("ja/LocaleScript", t
, &status
);
2353 if(U_FAILURE(status
)) {
2354 log_data_err("Couldn't access keyed resource, error %s\n", u_errorName(status
));
2355 status
= U_ZERO_ERROR
;
2357 key
= ures_getKey(t
);
2358 if(strcmp(key
, "LocaleScript")!=0) {
2359 log_err("Got a strange key, expected 'LocaleScript', got %s\n", key
);
2363 t2
= ures_open(U_ICUDATA_LANG
, "sr", &status
);
2364 if(U_FAILURE(status
)) {
2365 log_err_status(status
, "Couldn't open 'sr' resource bundle, error %s\n", u_errorName(status
));
2366 log_data_err("No 'sr', no test - you have bigger problems than testing direct access. "
2367 "You probably have no data! Aborting this test\n");
2370 if(U_SUCCESS(status
)) {
2371 strcpy(buffer
, "Languages/hr");
2373 t
= ures_findSubResource(t2
, s
, t
, &status
);
2374 if(U_FAILURE(status
)) {
2375 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status
));
2376 status
= U_ZERO_ERROR
;
2378 key
= ures_getKey(t
);
2379 if(strcmp(key
, "hr")!=0) {
2380 log_err("Got a strange key, expected 'hr', got %s\n", key
);
2385 t
= ures_findResource("root/calendar/islamic-civil/DateTime", t
, &status
);
2386 if(U_SUCCESS(status
)) {
2387 log_data_err("This resource does not exist. How did it get here?\n");
2389 status
= U_ZERO_ERROR
;
2391 /* this one will freeze */
2392 t
= ures_findResource("root/calendar/islamic-civil/eras/abbreviated/0/mikimaus/pera", t
, &status
);
2393 if(U_SUCCESS(status
)) {
2394 log_data_err("Second resource does not exist. How did it get here?\n");
2396 status
= U_ZERO_ERROR
;
2399 t2
= ures_open(NULL
, "he", &status
);
2400 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2401 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2402 t2
= ures_getByKeyWithFallback(t2
, "DateTime", t2
, &status
);
2403 if(U_SUCCESS(status
)) {
2404 log_err("This resource does not exist. How did it get here?\n");
2406 status
= U_ZERO_ERROR
;
2409 t2
= ures_open(NULL
, "he", &status
);
2411 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2412 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2413 t2
= ures_getByKeyWithFallback(t2
, "eras", t2
, &status
);
2414 if(U_FAILURE(status
)) {
2415 log_err_status(status
, "Didn't get Eras. I know they are there!\n");
2417 status
= U_ZERO_ERROR
;
2420 t2
= ures_open(NULL
, "root", &status
);
2421 t2
= ures_getByKeyWithFallback(t2
, "calendar", t2
, &status
);
2422 t2
= ures_getByKeyWithFallback(t2
, "islamic-civil", t2
, &status
);
2423 t2
= ures_getByKeyWithFallback(t2
, "DateTime", t2
, &status
);
2424 if(U_SUCCESS(status
)) {
2425 log_err("This resource does not exist. How did it get here?\n");
2427 status
= U_ZERO_ERROR
;
2433 static void TestTicket9804(void) {
2434 UErrorCode status
= U_ZERO_ERROR
;
2435 UResourceBundle
*t
= NULL
;
2436 t
= ures_open(NULL
, "he", &status
);
2437 t
= ures_getByKeyWithFallback(t
, "calendar/islamic-civil/DateTime", t
, &status
);
2438 if(U_SUCCESS(status
)) {
2439 log_err("This resource does not exist. How did it get here?\n");
2441 status
= U_ZERO_ERROR
;
2443 t
= ures_open(NULL
, "he", &status
);
2444 t
= ures_getByKeyWithFallback(t
, "calendar/islamic-civil/eras", t
, &status
);
2445 if(U_FAILURE(status
)) {
2446 log_err_status(status
, "Didn't get Eras. I know they are there!\n");
2448 const char *locale
= ures_getLocaleByType(t
, ULOC_ACTUAL_LOCALE
, &status
);
2449 if (uprv_strcmp("he", locale
) != 0) {
2450 log_err("Eras should be in the 'he' locale, but was in: %s", locale
);
2453 status
= U_ZERO_ERROR
;
2457 static void TestJB3763(void) {
2458 /* Nasty bug prevented using parent as fill-in, since it would
2459 * stomp the path information.
2461 UResourceBundle
*t
= NULL
;
2462 UErrorCode status
= U_ZERO_ERROR
;
2463 t
= ures_open(NULL
, "sr_Latn", &status
);
2464 t
= ures_getByKeyWithFallback(t
, "calendar", t
, &status
);
2465 t
= ures_getByKeyWithFallback(t
, "gregorian", t
, &status
);
2466 t
= ures_getByKeyWithFallback(t
, "AmPmMarkers", t
, &status
);
2467 if(U_FAILURE(status
)) {
2468 log_err_status(status
, "This resource should be available?\n");
2470 status
= U_ZERO_ERROR
;
2476 static void TestGetKeywordValues(void) {
2477 UEnumeration
*kwVals
;
2478 UBool foundStandard
= FALSE
;
2479 UErrorCode status
= U_ZERO_ERROR
;
2481 #if !UCONFIG_NO_COLLATION
2482 kwVals
= ures_getKeywordValues( U_ICUDATA_COLL
, "collations", &status
);
2484 log_verbose("Testing getting collation keyword values:\n");
2486 while((kw
=uenum_next(kwVals
, NULL
, &status
))) {
2487 log_verbose(" %s\n", kw
);
2488 if(!strcmp(kw
,"standard")) {
2489 if(foundStandard
== FALSE
) {
2490 foundStandard
= TRUE
;
2492 log_err("'standard' was found twice in the keyword list.\n");
2496 if(foundStandard
== FALSE
) {
2497 log_err_status(status
, "'standard' was not found in the keyword list.\n");
2499 uenum_close(kwVals
);
2500 if(U_FAILURE(status
)) {
2501 log_err_status(status
, "err %s getting collation values\n", u_errorName(status
));
2503 status
= U_ZERO_ERROR
;
2505 foundStandard
= FALSE
;
2506 kwVals
= ures_getKeywordValues( "ICUDATA", "calendar", &status
);
2508 log_verbose("Testing getting calendar keyword values:\n");
2510 while((kw
=uenum_next(kwVals
, NULL
, &status
))) {
2511 log_verbose(" %s\n", kw
);
2512 if(!strcmp(kw
,"japanese")) {
2513 if(foundStandard
== FALSE
) {
2514 foundStandard
= TRUE
;
2516 log_err("'japanese' was found twice in the calendar keyword list.\n");
2520 if(foundStandard
== FALSE
) {
2521 log_err_status(status
, "'japanese' was not found in the calendar keyword list.\n");
2523 uenum_close(kwVals
);
2524 if(U_FAILURE(status
)) {
2525 log_err_status(status
, "err %s getting calendar values\n", u_errorName(status
));
2529 static void TestGetFunctionalEquivalentOf(const char *path
, const char *resName
, const char *keyword
, UBool truncate
, const char * const testCases
[]) {
2531 for(i
=0;testCases
[i
];i
+=3) {
2532 UBool expectAvail
= (testCases
[i
][0]=='t')?TRUE
:FALSE
;
2533 UBool gotAvail
= FALSE
;
2534 const char *inLocale
= testCases
[i
+1];
2535 const char *expectLocale
= testCases
[i
+2];
2536 char equivLocale
[256];
2538 UErrorCode status
= U_ZERO_ERROR
;
2539 log_verbose("%d: %c %s\texpect %s\n",i
/3, expectAvail
?'t':'f', inLocale
, expectLocale
);
2540 len
= ures_getFunctionalEquivalent(equivLocale
, 255, path
,
2541 resName
, keyword
, inLocale
,
2542 &gotAvail
, truncate
, &status
);
2543 if(U_FAILURE(status
) || (len
<= 0)) {
2544 log_err_status(status
, "FAIL: got len %d, err %s on #%d: %c\t%s\t%s\n",
2545 len
, u_errorName(status
),
2546 i
/3,expectAvail
?'t':'f', inLocale
, expectLocale
);
2548 log_verbose("got: %c %s\n", expectAvail
?'t':'f',equivLocale
);
2550 if((gotAvail
!= expectAvail
) || strcmp(equivLocale
, expectLocale
)) {
2551 log_err("FAIL: got avail=%c, loc=%s but expected #%d: %c\t%s\t-> loc=%s\n",
2552 gotAvail
?'t':'f', equivLocale
,
2554 expectAvail
?'t':'f', inLocale
, expectLocale
);
2561 static void TestGetFunctionalEquivalent(void) {
2562 static const char * const collCases
[] = {
2563 /* avail locale equiv */
2564 "f", "de_US_CALIFORNIA", "de",
2565 "f", "zh_TW@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_TW */
2566 "t", "zh_Hant_TW@collation=stroke", "zh@collation=stroke",
2567 "f", "de_CN@collation=pinyin", "de",
2568 "t", "zh@collation=pinyin", "zh",
2569 "f", "zh_CN@collation=pinyin", "zh", /* alias of zh_Hans_CN */
2570 "t", "zh_Hans_CN@collation=pinyin", "zh",
2571 "f", "zh_HK@collation=pinyin", "zh", /* alias of zh_Hant_HK */
2572 "t", "zh_Hant_HK@collation=pinyin", "zh",
2573 "f", "zh_HK@collation=stroke", "zh@collation=stroke", /* alias of zh_Hant_HK */
2574 "t", "zh_Hant_HK@collation=stroke", "zh@collation=stroke",
2575 "f", "zh_HK", "zh@collation=stroke", /* alias of zh_Hant_HK */
2576 "t", "zh_Hant_HK", "zh@collation=stroke",
2577 "f", "zh_MO", "zh@collation=stroke", /* alias of zh_Hant_MO */
2578 "t", "zh_Hant_MO", "zh@collation=stroke",
2579 "f", "zh_TW_STROKE", "zh@collation=stroke",
2580 "f", "zh_TW_STROKE@collation=big5han", "zh@collation=big5han",
2581 "f", "de_CN@calendar=japanese", "de",
2582 "t", "de@calendar=japanese", "de",
2583 "f", "zh_TW@collation=big5han", "zh@collation=big5han", /* alias of zh_Hant_TW */
2584 "t", "zh_Hant_TW@collation=big5han", "zh@collation=big5han",
2585 "f", "zh_TW@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hant_TW */
2586 "t", "zh_Hant_TW@collation=gb2312han", "zh@collation=gb2312han",
2587 "f", "zh_CN@collation=big5han", "zh@collation=big5han", /* alias of zh_Hans_CN */
2588 "t", "zh_Hans_CN@collation=big5han", "zh@collation=big5han",
2589 "f", "zh_CN@collation=gb2312han", "zh@collation=gb2312han", /* alias of zh_Hans_CN */
2590 "t", "zh_Hans_CN@collation=gb2312han", "zh@collation=gb2312han",
2591 "t", "zh@collation=big5han", "zh@collation=big5han",
2592 "t", "zh@collation=gb2312han", "zh@collation=gb2312han",
2593 "t", "hi@collation=standard", "hi",
2594 "f", "hi_AU@collation=standard;currency=CHF;calendar=buddhist", "hi",
2595 "t", "de_DE@collation=pinyin", "de", /* bug 4582 tests */
2596 "f", "de_DE_BONN@collation=pinyin", "de",
2598 "t", "nl_NL", "root",
2599 "f", "nl_NL_EEXT", "root",
2600 "t", "nl@collation=stroke", "root",
2601 "t", "nl_NL@collation=stroke", "root",
2602 "f", "nl_NL_EEXT@collation=stroke", "root",
2606 static const char *calCases
[] = {
2607 /* avail locale equiv */
2608 "t", "en_US_POSIX", "en@calendar=gregorian",
2609 "f", "ja_JP_TOKYO", "ja@calendar=gregorian",
2610 "f", "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
2611 "t", "sr@calendar=gregorian", "sr@calendar=gregorian",
2612 "t", "en", "en@calendar=gregorian",
2616 #if !UCONFIG_NO_COLLATION
2617 TestGetFunctionalEquivalentOf(U_ICUDATA_COLL
, "collations", "collation", TRUE
, collCases
);
2619 TestGetFunctionalEquivalentOf("ICUDATA", "calendar", "calendar", FALSE
, calCases
);
2621 #if !UCONFIG_NO_COLLATION
2622 log_verbose("Testing error conditions:\n");
2624 char equivLocale
[256] = "???";
2626 UErrorCode status
= U_ZERO_ERROR
;
2627 UBool gotAvail
= FALSE
;
2629 len
= ures_getFunctionalEquivalent(equivLocale
, 255, U_ICUDATA_COLL
,
2630 "calendar", "calendar", "ar_EG@calendar=islamic",
2631 &gotAvail
, FALSE
, &status
);
2633 if(status
== U_MISSING_RESOURCE_ERROR
) {
2634 log_verbose("PASS: Got expected U_MISSING_RESOURCE_ERROR\n");
2636 log_err("ures_getFunctionalEquivalent returned locale %s, avail %c, err %s, but expected U_MISSING_RESOURCE_ERROR \n",
2637 equivLocale
, gotAvail
?'t':'f', u_errorName(status
));
2643 static void TestXPath(void) {
2644 UErrorCode status
= U_ZERO_ERROR
;
2645 UResourceBundle
*rb
= NULL
, *alias
= NULL
;
2647 const UChar
* result
= NULL
;
2648 const UChar expResult
[] = { 0x0063, 0x006F, 0x0072, 0x0072, 0x0065, 0x0063, 0x0074, 0x0000 }; /* "correct" */
2649 /*const UChar expResult[] = { 0x0074, 0x0065, 0x0069, 0x006E, 0x0064, 0x0065, 0x0073, 0x0074, 0x0000 }; *//*teindest*/
2651 const char *testdatapath
=loadTestData(&status
);
2652 if(U_FAILURE(status
))
2654 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
2658 log_verbose("Testing ures_open()......\n");
2660 rb
= ures_open(testdatapath
, "te_IN", &status
);
2661 if(U_FAILURE(status
)) {
2662 log_err("Could not open te_IN (%s)\n", myErrorName(status
));
2665 alias
= ures_getByKey(rb
, "rootAliasClient", alias
, &status
);
2666 if(U_FAILURE(status
)) {
2667 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status
));
2672 result
= tres_getString(alias
, -1, NULL
, &len
, &status
);
2673 if(U_FAILURE(status
) || result
== NULL
|| u_strcmp(result
, expResult
)) {
2674 log_err("Couldn't get correct string value (%s)\n", myErrorName(status
));
2677 alias
= ures_getByKey(rb
, "aliasClient", alias
, &status
);
2678 if(U_FAILURE(status
)) {
2679 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status
));
2684 result
= tres_getString(alias
, -1, NULL
, &len
, &status
);
2685 if(U_FAILURE(status
) || result
== NULL
|| u_strcmp(result
, expResult
)) {
2686 log_err("Couldn't get correct string value (%s)\n", myErrorName(status
));
2689 alias
= ures_getByKey(rb
, "nestedRootAliasClient", alias
, &status
);
2690 if(U_FAILURE(status
)) {
2691 log_err("Couldn't find the aliased resource (%s)\n", myErrorName(status
));
2696 result
= tres_getString(alias
, -1, NULL
, &len
, &status
);
2697 if(U_FAILURE(status
) || result
== NULL
|| u_strcmp(result
, expResult
)) {
2698 log_err("Couldn't get correct string value (%s)\n", myErrorName(status
));
2704 static void TestCLDRStyleAliases(void) {
2705 UErrorCode status
= U_ZERO_ERROR
;
2706 UResourceBundle
*rb
= NULL
, *alias
= NULL
, *a
=NULL
;
2709 const UChar
*result
= NULL
;
2710 UChar expected
[256];
2711 const char *expects
[7] = { "", "a41", "a12", "a03", "ar4" };
2712 const char *testdatapath
=loadTestData(&status
);
2713 if(U_FAILURE(status
)) {
2714 log_data_err("Could not load testdata.dat %s \n",myErrorName(status
));
2717 log_verbose("Testing CLDR style aliases......\n");
2719 rb
= ures_open(testdatapath
, "te_IN_REVISED", &status
);
2720 if(U_FAILURE(status
)) {
2721 log_err("Could not open te_IN (%s)\n", myErrorName(status
));
2724 alias
= ures_getByKey(rb
, "a", alias
, &status
);
2725 if(U_FAILURE(status
)) {
2726 log_err("Couldn't find the aliased with name \"a\" resource (%s)\n", myErrorName(status
));
2730 for(i
= 1; i
< 5 ; i
++) {
2734 /* instead of sprintf(resource, "a%i", i); */
2735 a
= ures_getByKeyWithFallback(alias
, resource
, a
, &status
);
2736 result
= tres_getString(a
, -1, NULL
, &len
, &status
);
2737 u_charsToUChars(expects
[i
], expected
, strlen(expects
[i
])+1);
2738 if(U_FAILURE(status
) || !result
|| u_strcmp(result
, expected
)) {
2739 log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource
, expects
[i
], result
, myErrorName(status
));
2740 status
= U_ZERO_ERROR
;
2749 static void TestFallbackCodes(void) {
2750 UErrorCode status
= U_ZERO_ERROR
;
2751 const char *testdatapath
=loadTestData(&status
);
2753 UResourceBundle
*res
= ures_open(testdatapath
, "te_IN", &status
);
2755 UResourceBundle
*r
= NULL
, *fall
= NULL
;
2757 r
= ures_getByKey(res
, "tagged_array_in_Root_te_te_IN", r
, &status
);
2759 status
= U_ZERO_ERROR
;
2760 fall
= ures_getByKeyWithFallback(r
, "tag2", fall
, &status
);
2762 if(status
!= U_ZERO_ERROR
) {
2763 log_data_err("Expected error code to be U_ZERO_ERROR, got %s\n", u_errorName(status
));
2764 status
= U_ZERO_ERROR
;
2767 fall
= ures_getByKeyWithFallback(r
, "tag7", fall
, &status
);
2769 if(status
!= U_USING_FALLBACK_WARNING
) {
2770 log_data_err("Expected error code to be U_USING_FALLBACK_WARNING, got %s\n", u_errorName(status
));
2772 status
= U_ZERO_ERROR
;
2774 fall
= ures_getByKeyWithFallback(r
, "tag1", fall
, &status
);
2776 if(status
!= U_USING_DEFAULT_WARNING
) {
2777 log_data_err("Expected error code to be U_USING_DEFAULT_WARNING, got %s\n", u_errorName(status
));
2779 status
= U_ZERO_ERROR
;
2786 /* This test will crash if this doesn't work. Results don't need testing. */
2787 static void TestStackReuse(void) {
2788 UResourceBundle table
;
2789 UErrorCode errorCode
= U_ZERO_ERROR
;
2790 UResourceBundle
*rb
= ures_open(NULL
, "en_US", &errorCode
);
2792 if(U_FAILURE(errorCode
)) {
2793 log_data_err("Could not load en_US locale. status=%s\n",myErrorName(errorCode
));
2796 ures_initStackObject(&table
);
2797 ures_getByKeyWithFallback(rb
, "Types", &table
, &errorCode
);
2798 ures_getByKeyWithFallback(&table
, "collation", &table
, &errorCode
);
2803 /* Test ures_getUTF8StringXYZ() --------------------------------------------- */
2806 * Replace most ures_getStringXYZ() with this function which wraps the
2807 * desired call and also calls the UTF-8 variant and checks that it works.
2809 extern const UChar
*
2810 tres_getString(const UResourceBundle
*resB
,
2811 int32_t idx
, const char *key
,
2813 UErrorCode
*status
) {
2819 int32_t length16
, length8
, i16
, i8
;
2822 if(length
== NULL
) {
2826 s16
= ures_getStringByIndex(resB
, idx
, length
, status
);
2827 } else if(key
!= NULL
) {
2828 s16
= ures_getStringByKey(resB
, key
, length
, status
);
2830 s16
= ures_getString(resB
, length
, status
);
2832 if(U_FAILURE(*status
)) {
2837 /* try the UTF-8 variant of ures_getStringXYZ() */
2838 for(forceCopy
= FALSE
; forceCopy
<= TRUE
; ++forceCopy
) {
2840 length8
= (int32_t)sizeof(buffer8
);
2842 s8
= ures_getUTF8StringByIndex(resB
, idx
, 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
);
2848 if(*status
== U_INVALID_CHAR_FOUND
) {
2849 /* the UTF-16 string contains an unpaired surrogate, can't test UTF-8 variant */
2852 if(*status
== U_BUFFER_OVERFLOW_ERROR
) {
2853 *status
= U_ZERO_ERROR
;
2854 p8
= (char *)malloc(++length8
);
2859 s8
= ures_getUTF8StringByIndex(resB
, idx
, p8
, &length8
, forceCopy
, status
);
2860 } else if(key
!= NULL
) {
2861 s8
= ures_getUTF8StringByKey(resB
, key
, p8
, &length8
, forceCopy
, status
);
2863 s8
= ures_getUTF8String(resB
, p8
, &length8
, forceCopy
, status
);
2866 if(U_FAILURE(*status
)) {
2867 /* something unexpected happened */
2874 if(forceCopy
&& s8
!= p8
) {
2875 log_err("ures_getUTF8String(%p, %ld, '%s') did not write the string to dest\n",
2876 resB
, (long)idx
, key
);
2879 /* verify NUL-termination */
2880 if((p8
!= buffer8
|| length8
< sizeof(buffer8
)) && s8
[length8
] != 0) {
2881 log_err("ures_getUTF8String(%p, %ld, '%s') did not NUL-terminate\n",
2882 resB
, (long)idx
, key
);
2884 /* verify correct string */
2886 while(i16
< length16
&& i8
< length8
) {
2887 U16_NEXT(s16
, i16
, length16
, c16
);
2888 U8_NEXT(s8
, i8
, length8
, c8
);
2890 log_err("ures_getUTF8String(%p, %ld, '%s') got a bad string, c16=U+%04lx!=U+%04lx=c8 before i16=%ld\n",
2891 resB
, (long)idx
, key
, (long)c16
, (long)c8
, (long)i16
);
2894 /* verify correct length */
2895 if(i16
< length16
) {
2896 log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too short, length8=%ld, length16=%ld\n",
2897 resB
, (long)idx
, key
, (long)length8
, (long)length16
);
2900 log_err("ures_getUTF8String(%p, %ld, '%s') UTF-8 string too long, length8=%ld, length16=%ld\n",
2901 resB
, (long)idx
, key
, (long)length8
, (long)length16
);
2913 * API tests for ures_getUTF8String().
2914 * Most cases are handled by tres_getString(), which leaves argument checking
2915 * to be tested here.
2916 * Since the variants share most of their implementation, we only need to test
2918 * We also need not test for checking arguments which will be checked by the
2919 * UTF-16 ures_getStringXYZ() that are called internally.
2922 TestGetUTF8String() {
2923 UResourceBundle
*res
;
2924 const char *testdatapath
;
2930 status
= U_ZERO_ERROR
;
2931 testdatapath
= loadTestData(&status
);
2932 if(U_FAILURE(status
)) {
2933 log_data_err("Could not load testdata.dat - %s\n", u_errorName(status
));
2937 res
= ures_open(testdatapath
, "", &status
);
2938 if(U_FAILURE(status
)) {
2939 log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status
));
2944 status
= U_ZERO_ERROR
;
2945 length8
= (int32_t)sizeof(buffer8
);
2946 s8
= ures_getUTF8StringByKey(res
, "string_only_in_Root", buffer8
, &length8
, FALSE
, &status
);
2947 if(status
!= U_ZERO_ERROR
) {
2948 log_err("ures_getUTF8StringByKey(testdata/root string) malfunctioned - %s\n", u_errorName(status
));
2951 /* negative capacity */
2952 status
= U_ZERO_ERROR
;
2954 s8
= ures_getUTF8StringByKey(res
, "string_only_in_Root", buffer8
, &length8
, FALSE
, &status
);
2955 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
2956 log_err("ures_getUTF8StringByKey(capacity<0) malfunctioned - %s\n", u_errorName(status
));
2959 /* capacity>0 but dest=NULL */
2960 status
= U_ZERO_ERROR
;
2961 length8
= (int32_t)sizeof(buffer8
);
2962 s8
= ures_getUTF8StringByKey(res
, "string_only_in_Root", NULL
, &length8
, FALSE
, &status
);
2963 if(status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
2964 log_err("ures_getUTF8StringByKey(dest=NULL capacity>0) malfunctioned - %s\n", u_errorName(status
));
2970 static void TestCLDRVersion(void) {
2971 UVersionInfo zeroVersion
;
2972 UVersionInfo testExpect
;
2973 UVersionInfo testCurrent
;
2974 UVersionInfo cldrVersion
;
2976 UErrorCode status
= U_ZERO_ERROR
;
2978 /* setup the constant value */
2979 u_versionFromString(zeroVersion
, "0.0.0.0");
2981 /* test CLDR value from API */
2982 ulocdata_getCLDRVersion(cldrVersion
, &status
);
2983 if(U_FAILURE(status
)) {
2984 /* the show is pretty much over at this point */
2985 log_err_status(status
, "FAIL: ulocdata_getCLDRVersion() returned %s\n", u_errorName(status
));
2988 u_versionToString(cldrVersion
, tmp
);
2989 log_info("ulocdata_getCLDRVersion() returned: '%s'\n", tmp
);
2993 /* setup from resource bundle */
2995 UResourceBundle
*res
;
2996 const char *testdatapath
;
2998 status
= U_ZERO_ERROR
;
2999 testdatapath
= loadTestData(&status
);
3000 if(U_FAILURE(status
)) {
3001 log_data_err("Could not load testdata.dat - %s\n", u_errorName(status
));
3005 res
= ures_openDirect(testdatapath
, "root", &status
);
3006 if(U_FAILURE(status
)) {
3007 log_err("Unable to ures_open(testdata, \"\") - %s\n", u_errorName(status
3011 ures_getVersionByKey(res
, "ExpectCLDRVersionAtLeast", testExpect
, &status
);
3012 ures_getVersionByKey(res
, "CurrentCLDRVersion", testCurrent
, &status
);
3014 if(U_FAILURE(status
)) {
3015 log_err("Unable to get test data for CLDR version - %s\n", u_errorName(status
));
3018 if(U_FAILURE(status
)) return;
3021 u_versionToString(testExpect
,tmp
);
3022 log_verbose("(data) ExpectCLDRVersionAtLeast { %s }\n", tmp
);
3023 if(memcmp(cldrVersion
, testExpect
, sizeof(UVersionInfo
)) < 0) {
3024 log_data_err("CLDR version is too old, expect at least %s.", tmp
);
3026 u_versionToString(testCurrent
,tmp
);
3027 log_verbose("(data) CurrentCLDRVersion { %s }\n", tmp
);
3028 switch(memcmp(cldrVersion
, testCurrent
, sizeof(UVersionInfo
))) {
3029 case 0: break; /* OK- current. */
3030 case -1: log_info("CLDR version is behind 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp
); break;
3031 case 1: log_info("CLDR version is ahead of 'current' (for testdata/root.txt) %s. Some things may fail.\n", tmp
); break;