]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/test/cintltst/creststn.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / test / cintltst / creststn.c
... / ...
CommitLineData
1/********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6/********************************************************************************
7*
8* File CRESTST.C
9*
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*********************************************************************************
15*/
16
17
18#include <time.h>
19#include "unicode/utypes.h"
20#include "cintltst.h"
21#include "unicode/utypes.h"
22#include "unicode/ustring.h"
23#include "unicode/ucnv.h"
24#include "string.h"
25#include "cstring.h"
26#include "unicode/uchar.h"
27
28#define RESTEST_HEAP_CHECK 0
29
30#include "unicode/uloc.h"
31#include "uresimp.h"
32#include "creststn.h"
33#include "unicode/ctest.h"
34#include "ucbuf.h"
35static int32_t pass;
36static int32_t fail;
37
38/*****************************************************************************/
39/**
40 * Return a random unsigned long l where 0N <= l <= ULONG_MAX.
41 */
42
43static uint32_t
44randul()
45{
46 uint32_t l=0;
47 int32_t i;
48 static UBool initialized = FALSE;
49 if (!initialized)
50 {
51 srand((unsigned)time(NULL));
52 initialized = TRUE;
53 }
54 /* Assume rand has at least 12 bits of precision */
55
56 for (i=0; i<sizeof(l); ++i)
57 ((char*)&l)[i] = (char)((rand() & 0x0FF0) >> 4);
58 return l;
59}
60
61/**
62 * Return a random double x where 0.0 <= x < 1.0.
63 */
64static double
65randd()
66{
67 return ((double)randul()) / UINT32_MAX;
68}
69
70/**
71 * Return a random integer i where 0 <= i < n.
72 */
73static int32_t randi(int32_t n)
74{
75 return (int32_t)(randd() * n);
76}
77/***************************************************************************************/
78/**
79 * Convert an integer, positive or negative, to a character string radix 10.
80 */
81static char*
82itoa1(int32_t i, char* buf)
83{
84 char *p = 0;
85 char* result = buf;
86 /* Handle negative */
87 if(i < 0) {
88 *buf++ = '-';
89 i = -i;
90 }
91
92 /* Output digits in reverse order */
93 p = buf;
94 do {
95 *p++ = (char)('0' + (i % 10));
96 i /= 10;
97 }
98 while(i);
99 *p-- = 0;
100
101 /* Reverse the string */
102 while(buf < p) {
103 char c = *buf;
104 *buf++ = *p;
105 *p-- = c;
106 }
107
108 return result;
109}
110static const int32_t kERROR_COUNT = -1234567;
111static const UChar kERROR[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/,
112 0x004F /*'O'*/, 0x0052/*'R'*/, 0x0000 /*'\0'*/};
113
114/*****************************************************************************/
115
116enum E_Where
117{
118 e_Root,
119 e_te,
120 e_te_IN,
121 e_Where_count
122};
123typedef enum E_Where E_Where;
124/*****************************************************************************/
125
126#define CONFIRM_EQ(actual,expected) if (u_strcmp(expected,actual)==0){ record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, austrdup(actual), austrdup(expected)); }
127#define CONFIRM_INT_EQ(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of %d\n", action, actual, expected); }
128#define CONFIRM_INT_GE(actual,expected) if ((actual)>=(expected)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x >= %d\n", action, actual, expected); }
129#define CONFIRM_INT_NE(actual,expected) if ((expected)!=(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %d instead of x != %d\n", action, actual, expected); }
130#define CONFIRM_ErrorCode(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); log_err("%s returned %s instead of %s\n", action, myErrorName(actual), myErrorName(expected)); }
131
132
133/* Array of our test objects */
134
135static struct
136{
137 const char* name;
138 UErrorCode expected_constructor_status;
139 E_Where where;
140 UBool like[e_Where_count];
141 UBool inherits[e_Where_count];
142}
143param[] =
144{
145 /* "te" means test */
146 /* "IN" means inherits */
147 /* "NE" or "ne" means "does not exist" */
148
149 { "root", U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } },
150 { "te", U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
151 { "te_IN", U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
152 { "te_NE", U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
153 { "te_IN_NE", U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
154 { "ne", U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
155};
156
157static int32_t bundles_count = sizeof(param) / sizeof(param[0]);
158
159
160static void printUChars(UChar*);
161static void TestDecodedBundle(void);
162
163/***************************************************************************************/
164
165/* Array of our test objects */
166
167void addNEWResourceBundleTest(TestNode** root)
168{
169 addTest(root, &TestErrorCodes, "tsutil/creststn/TestErrorCodes");
170 addTest(root, &TestEmptyBundle, "tsutil/creststn/TestEmptyBundle");
171 addTest(root, &TestConstruction1, "tsutil/creststn/TestConstruction1");
172 addTest(root, &TestResourceBundles, "tsutil/creststn/TestResourceBundle");
173 addTest(root, &TestFallback, "tsutil/creststn/TestFallback");
174 addTest(root, &TestGetVersion, "tsutil/creststn/TestGetVersion");
175 addTest(root, &TestAliasConflict, "tsutil/creststn/TestAliasConflict");
176 addTest(root, &TestNewTypes, "tsutil/creststn/TestNewTypes");
177 addTest(root, &TestEmptyTypes, "tsutil/creststn/TestEmptyTypes");
178 addTest(root, &TestBinaryCollationData, "tsutil/creststn/TestBinaryCollationData");
179 addTest(root, &TestAPI, "tsutil/creststn/TestAPI");
180 addTest(root, &TestErrorConditions, "tsutil/creststn/TestErrorConditions");
181 addTest(root, &TestDecodedBundle, "tsutil/creststn/TestDecodedBundle");
182 addTest(root, &TestResourceLevelAliasing, "tsutil/creststn/TestResourceLevelAliasing");
183 addTest(root, &TestDirectAccess, "tsutil/creststn/TestDirectAccess");
184
185}
186
187
188/***************************************************************************************/
189static const char* norwayNames[] = {
190 "no_NO_NY",
191 "no_NO",
192 "no",
193 "nn_NO",
194 "nn",
195 "nb_NO",
196 "nb"
197};
198
199static const char* norwayLocales[] = {
200 "nn_NO",
201 "nb_NO",
202 "nb",
203 "nn_NO",
204 "nn",
205 "nb_NO",
206 "nb"
207};
208
209static void checkStatus(UErrorCode expected, UErrorCode status) {
210 if(U_FAILURE(status)) {
211 log_data_err("Resource not present, cannot test\n");
212 }
213 if(status != expected) {
214 log_err("Expected error code %s, got error code %s\n", u_errorName(expected), u_errorName(status));
215 }
216}
217
218static void TestErrorCodes(void) {
219 UErrorCode status = U_USING_DEFAULT_WARNING;
220
221 UResourceBundle *r = NULL, *r2 = NULL;
222
223 /* first bundle should return fallback warning */
224 r = ures_open(NULL, "sr_YU_VOJVODINA", &status);
225 checkStatus(U_USING_FALLBACK_WARNING, status);
226 ures_close(r);
227
228 /* this bundle should return zero error, so it shouldn't change the status*/
229 status = U_USING_DEFAULT_WARNING;
230 r = ures_open(NULL, "sr_YU", &status);
231 checkStatus(U_USING_DEFAULT_WARNING, status);
232
233 /* we look up the resource which is aliased, but it lives in fallback */
234 if(U_SUCCESS(status) && r != NULL) {
235 status = U_USING_DEFAULT_WARNING;
236 r2 = ures_getByKey(r, "CollationElements", NULL, &status);
237 checkStatus(U_USING_FALLBACK_WARNING, status);
238 }
239 ures_close(r);
240
241 /* this bundle should return zero error, so it shouldn't change the status*/
242 status = U_USING_DEFAULT_WARNING;
243 r = ures_open(NULL, "sr", &status);
244 checkStatus(U_USING_DEFAULT_WARNING, status);
245
246 /* we look up the resource which is aliased and at our level */
247 if(U_SUCCESS(status) && r != NULL) {
248 status = U_USING_DEFAULT_WARNING;
249 r2 = ures_getByKey(r, "CollationElements", r2, &status);
250 checkStatus(U_USING_DEFAULT_WARNING, status);
251 }
252 ures_close(r);
253
254 status = U_USING_FALLBACK_WARNING;
255 r = ures_open(NULL, "nolocale", &status);
256 checkStatus(U_USING_DEFAULT_WARNING, status);
257 ures_close(r);
258 ures_close(r2);
259}
260
261static void TestAliasConflict(void) {
262 UErrorCode status = U_ZERO_ERROR;
263 UResourceBundle *he = NULL;
264 UResourceBundle *iw = NULL;
265 UResourceBundle *norway = NULL;
266 const UChar *result = NULL;
267 int32_t resultLen;
268 uint32_t size = 0;
269 uint32_t i = 0;
270 const char *realName = NULL;
271
272 he = ures_open(NULL, "he", &status);
273 iw = ures_open(NULL, "iw", &status);
274 if(U_FAILURE(status)) {
275 log_err("Failed to get resource with %s\n", myErrorName(status));
276 }
277 ures_close(iw);
278 result = ures_getStringByKey(he, "localPatternChars", &resultLen, &status);
279 if(U_FAILURE(status) || result == NULL) {
280 log_err("Failed to get resource localPatternChars with %s\n", myErrorName(status));
281 }
282 ures_close(he);
283
284 size = sizeof(norwayNames)/sizeof(norwayNames[0]);
285 for(i = 0; i < size; i++) {
286 status = U_ZERO_ERROR;
287 norway = ures_open(NULL, norwayNames[i], &status);
288 if(U_FAILURE(status)) {
289 log_err("Failed to get resource with %s for %s\n", myErrorName(status), norwayNames[i]);
290 continue;
291 }
292 realName = ures_getLocale(norway, &status);
293 log_verbose("ures_getLocale(\"%s\")=%s\n", norwayNames[i], realName);
294 if(realName == NULL || strcmp(norwayLocales[i], realName) != 0) {
295 log_data_err("Wrong locale name for %s, expected %s, got %s\n", norwayNames[i], norwayLocales[i], realName);
296 }
297 ures_close(norway);
298 }
299}
300
301static void TestDecodedBundle(){
302
303 UErrorCode error = U_ZERO_ERROR;
304
305 UResourceBundle* resB;
306
307 const UChar* srcFromRes;
308 int32_t len;
309 static const UChar uSrc[] = {
310 0x0009,0x092F,0x0941,0x0928,0x0947,0x0938,0x094D,0x0915,0x094B,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x090F,
311 0x0915,0x0020,0x002E,0x0905,0x0927,0x094D,0x092F,0x092F,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x0905,0x0928,
312 0x0941,0x0938,0x093E,0x0930,0x0020,0x0031,0x0039,0x0039,0x0030,0x0020,0x0924,0x0915,0x0020,0x0915,0x0902,0x092A,
313 0x094D,0x092F,0x0942,0x091F,0x0930,0x002D,0x092A,0x094D,0x0930,0x092C,0x0902,0x0927,0x093F,0x0924,0x0020,0x0938,
314 0x0942,0x091A,0x0928,0x093E,0x092A,0x094D,0x0930,0x0923,0x093E,0x0932,0x0940,0x0020,0x002E,0x0915,0x0947,0x0020,
315 0x002E,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0915,0x0947,0x0020,0x002E,0x092B,0x0932,0x0938,
316 0x094D,0x0935,0x0930,0x0942,0x092A,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,0x0020,0x002E,0x092E,0x0947,
317 0x0902,0x0020,0x002E,0x0938,0x093E,0x0932,0x093E,0x0928,0x093E,0x0020,0x002E,0x0032,0x0032,0x0030,0x0030,0x0020,
318 0x0905,0x0930,0x092C,0x0020,0x0930,0x0941,0x092A,0x092F,0x0947,0x0020,0x092E,0x0942,0x0932,0x094D,0x092F,0x0915,
319 0x0940,0x0020,0x002E,0x0034,0x0935,0x0938,0x094D,0x0924,0x0941,0x0913,0x0902,0x0020,0x002E,0x0034,0x0915,0x093E,
320 0x0020,0x002E,0x0034,0x0909,0x0924,0x094D,0x092A,0x093E,0x0926,0x0928,0x0020,0x002E,0x0034,0x0939,0x094B,0x0917,
321 0x093E,0x002C,0x0020,0x002E,0x0033,0x091C,0x092C,0x0915,0x093F,0x0020,0x002E,0x0033,0x0915,0x0902,0x092A,0x094D,
322 0x092F,0x0942,0x091F,0x0930,0x0020,0x002E,0x0033,0x0915,0x093E,0x0020,0x002E,0x0033,0x0915,0x0941,0x0932,0x0020,
323 0x002E,0x0033,0x092F,0x094B,0x0917,0x0926,0x093E,0x0928,0x0020,0x002E,0x0033,0x0907,0x0938,0x0938,0x0947,0x0915,
324 0x0939,0x093F,0x0020,0x002E,0x002F,0x091C,0x094D,0x092F,0x093E,0x0926,0x093E,0x0020,0x002E,0x002F,0x0939,0x094B,
325 0x0917,0x093E,0x0964,0x0020,0x002E,0x002F,0x0905,0x0928,0x0941,0x0938,0x0902,0x0927,0x093E,0x0928,0x0020,0x002E,
326 0x002F,0x0915,0x0940,0x0020,0x002E,0x002F,0x091A,0x0930,0x092E,0x0020,0x0938,0x0940,0x092E,0x093E,0x0913,0x0902,
327 0x0020,0x092A,0x0930,0x0020,0x092A,0x0939,0x0941,0x0902,0x091A,0x0928,0x0947,0x0020,0x0915,0x0947,0x0020,0x0932,
328 0x093F,0x090F,0x0020,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x090F,0x0915,0x0020,0x002E,0x002F,
329 0x0906,0x092E,0x0020,0x002E,0x002F,0x091C,0x0930,0x0942,0x0930,0x0924,0x0020,0x002E,0x002F,0x091C,0x0948,0x0938,
330 0x093E,0x0020,0x092C,0x0928,0x0020,0x0917,0x092F,0x093E,0x0020,0x0939,0x0948,0x0964,0x0020,0x092D,0x093E,0x0930,
331 0x0924,0x0020,0x092E,0x0947,0x0902,0x0020,0x092D,0x0940,0x002C,0x0020,0x0916,0x093E,0x0938,0x0915,0x0930,0x0020,
332 0x092E,0x094C,0x091C,0x0942,0x0926,0x093E,0x0020,0x0938,0x0930,0x0915,0x093E,0x0930,0x0928,0x0947,0x002C,0x0020,
333 0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,0x0915,0x0947,0x0020,0x092A,0x094D,0x0930,0x092F,
334 0x094B,0x0917,0x0020,0x092A,0x0930,0x0020,0x091C,0x092C,0x0930,0x0926,0x0938,0x094D,0x0924,0x0020,0x090F,0x095C,
335 0x0020,0x0932,0x0917,0x093E,0x092F,0x0940,0x0020,0x0939,0x0948,0x002C,0x0020,0x0915,0x093F,0x0902,0x0924,0x0941,
336 0x0020,0x0907,0x0938,0x0915,0x0947,0x0020,0x0938,0x0930,0x092A,0x091F,0x0020,0x0926,0x094C,0x095C,0x0932,0x0917,
337 0x093E,0x0928,0x0947,0x0020,0x002E,0x0032,0x0915,0x0947,0x0020,0x002E,0x0032,0x0932,0x093F,0x090F,0x0020,0x002E,
338 0x0032,0x0915,0x094D,0x092F,0x093E,0x0020,0x002E,0x0032,0x0938,0x092A,0x093E,0x091F,0x0020,0x002E,0x0032,0x0930,
339 0x093E,0x0938,0x094D,0x0924,0x093E,0x0020,0x002E,0x0032,0x0909,0x092A,0x0932,0x092C,0x094D,0x0927,0x0020,0x002E,
340 0x0939,0x0948,0x002C,0x0020,0x002E,0x0905,0x0925,0x0935,0x093E,0x0020,0x002E,0x0935,0x093F,0x0936,0x094D,0x0935,
341 0x0020,0x002E,0x092E,0x0947,0x0902,0x0020,0x002E,0x0915,0x0902,0x092A,0x094D,0x092F,0x0942,0x091F,0x0930,0x0020,
342 0x002E,0x0915,0x0940,0x0938,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0935,0x0020,0x002E,0x0033,0x0935,
343 0x093F,0x092B,0x0932,0x0924,0x093E,0x0020,0x002E,0x0033,0x0938,0x0947,0x0020,0x002E,0x0033,0x0938,0x092C,0x0915,
344 0x0020,0x002E,0x0033,0x0932,0x0947,0x0020,0x002E,0x0033,0x0915,0x0930,0x0020,0x002E,0x0033,0x0915,0x094D,0x092F,
345 0x093E,0x0020,0x002E,0x0033,0x0939,0x092E,0x0020,0x002E,0x0033,0x0907,0x0938,0x0915,0x093E,0x0020,0x002E,0x0033,
346 0x092F,0x0941,0x0915,0x094D,0x0924,0x093F,0x092A,0x0942,0x0930,0x094D,0x0923,0x0020,0x002E,0x0032,0x0935,0x093F,
347 0x0938,0x094D,0x0924,0x093E,0x0930,0x0020,0x0905,0x092A,0x0947,0x0915,0x094D,0x0937,0x093F,0x0924,0x0020,0x0915,
348 0x0930,0x0020,0x0938,0x0915,0x0947,0x0902,0x0917,0x0947,0x0020,0x003F,0x0020,
349 0
350 };
351
352 /* pre-flight */
353 int32_t num =0;
354 const char *testdatapath = loadTestData(&error);
355 resB = ures_open(testdatapath, "iscii", &error);
356 srcFromRes=ures_getStringByKey(resB,"str",&len,&error);
357 if(U_FAILURE(error)){
358#if UCONFIG_NO_LEGACY_CONVERSION
359 log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION is turned on)\n");
360#else
361 log_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error));
362#endif
363 ures_close(resB);
364 return;
365 }
366 if(u_strncmp(srcFromRes,uSrc,len)!=0){
367 log_err("Genrb produced res files after decoding failed\n");
368 }
369 while(num<len){
370 if(uSrc[num]!=srcFromRes[num]){
371 log_verbose(" Expected: 0x%04X Got: 0x%04X \n", uSrc[num],srcFromRes[num]);
372 }
373 num++;
374 }
375 if (len != u_strlen(uSrc)) {
376 log_err("Genrb produced a string larger than expected\n");
377 }
378 ures_close(resB);
379}
380
381static void TestNewTypes() {
382 UResourceBundle* theBundle = NULL;
383 char action[256];
384 const char* testdatapath;
385 UErrorCode status = U_ZERO_ERROR;
386 UResourceBundle* res = NULL;
387 uint8_t *binResult = NULL;
388 int32_t len = 0;
389 int32_t i = 0;
390 int32_t intResult = 0;
391 uint32_t uintResult = 0;
392 const UChar *empty = NULL;
393 const UChar *zeroString;
394 UChar expected[] = { 'a','b','c','\0','d','e','f' };
395 const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
396 UChar uExpect[200];
397
398 testdatapath=loadTestData(&status);
399
400 if(U_FAILURE(status))
401 {
402 log_err("Could not load testdata.dat %s \n",myErrorName(status));
403 return;
404 }
405
406 theBundle = ures_open(testdatapath, "testtypes", &status);
407
408 empty = ures_getStringByKey(theBundle, "emptystring", &len, &status);
409 if(empty && (*empty != 0 || len != 0)) {
410 log_err("Empty string returned invalid value\n");
411 }
412
413 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
414
415 CONFIRM_INT_NE(theBundle, NULL);
416
417 /* This test reads the string "abc\u0000def" from the bundle */
418 /* if everything is working correctly, the size of this string */
419 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
420
421 strcpy(action, "getting and testing of string with embeded zero");
422 res = ures_getByKey(theBundle, "zerotest", res, &status);
423 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
424 CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
425 zeroString=ures_getString(res, &len, &status);
426 if(U_SUCCESS(status)){
427 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
428 CONFIRM_INT_EQ(len, 7);
429 CONFIRM_INT_NE(len, 3);
430 }
431 for(i=0;i<len;i++){
432 if(zeroString[i]!= expected[i]){
433 log_verbose("Output did not match Expected: \\u%4X Got: \\u%4X", expected[i], zeroString[i]);
434 }
435 }
436
437 strcpy(action, "getting and testing of binary type");
438 res = ures_getByKey(theBundle, "binarytest", res, &status);
439 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
440 CONFIRM_INT_EQ(ures_getType(res), URES_BINARY);
441 binResult=(uint8_t*)ures_getBinary(res, &len, &status);
442 if(U_SUCCESS(status)){
443 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
444 CONFIRM_INT_EQ(len, 15);
445 for(i = 0; i<15; i++) {
446 CONFIRM_INT_EQ(binResult[i], i);
447 }
448 }
449
450 strcpy(action, "getting and testing of imported binary type");
451 res = ures_getByKey(theBundle, "importtest", res, &status);
452 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
453 CONFIRM_INT_EQ(ures_getType(res), URES_BINARY);
454 binResult=(uint8_t*)ures_getBinary(res, &len, &status);
455 if(U_SUCCESS(status)){
456 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
457 CONFIRM_INT_EQ(len, 15);
458 for(i = 0; i<15; i++) {
459 CONFIRM_INT_EQ(binResult[i], i);
460 }
461 }
462
463 strcpy(action, "getting and testing of integer types");
464 res = ures_getByKey(theBundle, "one", res, &status);
465 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
466 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
467 intResult=ures_getInt(res, &status);
468 uintResult = ures_getUInt(res, &status);
469 if(U_SUCCESS(status)){
470 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
471 CONFIRM_INT_EQ(uintResult, (uint32_t)intResult);
472 CONFIRM_INT_EQ(intResult, 1);
473 }
474
475 strcpy(action, "getting minusone");
476 res = ures_getByKey(theBundle, "minusone", res, &status);
477 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
478 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
479 intResult=ures_getInt(res, &status);
480 uintResult = ures_getUInt(res, &status);
481 if(U_SUCCESS(status)){
482 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
483 CONFIRM_INT_EQ(uintResult, 0x0FFFFFFF); /* a 28 bit integer */
484 CONFIRM_INT_EQ(intResult, -1);
485 CONFIRM_INT_NE(uintResult, (uint32_t)intResult);
486 }
487
488 strcpy(action, "getting plusone");
489 res = ures_getByKey(theBundle, "plusone", res, &status);
490 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
491 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
492 intResult=ures_getInt(res, &status);
493 uintResult = ures_getUInt(res, &status);
494 if(U_SUCCESS(status)){
495 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
496 CONFIRM_INT_EQ(uintResult, (uint32_t)intResult);
497 CONFIRM_INT_EQ(intResult, 1);
498 }
499
500 res = ures_getByKey(theBundle, "onehundredtwentythree", res, &status);
501 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
502 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
503 intResult=ures_getInt(res, &status);
504 if(U_SUCCESS(status)){
505 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
506 CONFIRM_INT_EQ(intResult, 123);
507 }
508
509 /* this tests if escapes are preserved or not */
510 {
511 const UChar* str = ures_getStringByKey(theBundle,"testescape",&len,&status);
512 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
513 if(U_SUCCESS(status)){
514 u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1);
515 if(u_strcmp(uExpect,str)){
516 log_err("Did not get the expected string for testescape\n");
517 }
518 }
519 }
520 /* this tests if unescaping works are expected */
521 len=0;
522 {
523 static const char pattern[] = "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
524 "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F "
525 "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 "
526 "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD "
527 "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF "
528 "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF "
529 "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF "
530 "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF "
531 "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB "
532 "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C "
533 "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F "
534 "]";
535
536 int32_t patternLen = uprv_strlen(pattern);
537 UChar* expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen);
538 const UChar* got = ures_getStringByKey(theBundle,"test_unescaping",&len,&status);
539 int32_t expectedLen = u_unescape(pattern,expectedEscaped,patternLen);
540 if(u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){
541 log_err("genrb failed to unescape string\n");
542 }
543 for(i=0;i<expectedLen;i++){
544 if(expectedEscaped[i] != got[i]){
545 log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped[i], got[i]);
546 }
547 }
548 free(expectedEscaped);
549 status = U_ZERO_ERROR;
550 }
551 /* test for jitterbug#1435 */
552 {
553 const UChar* str = ures_getStringByKey(theBundle,"test_underscores",&len,&status);
554 expect ="test message ....";
555 u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1);
556 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
557 if(u_strcmp(uExpect,str)){
558 log_err("Did not get the expected string for test_underscores.\n");
559 }
560 }
561 /* test for jitterbug#2626 */
562 {
563 UResourceBundle* resB = NULL;
564 const UChar* str = NULL;
565 int32_t strLength = 0;
566 const UChar my[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */
567 status = U_ZERO_ERROR;
568 resB = ures_getByKey(theBundle,"CollationElements", resB,&status);
569 str = ures_getStringByKey(resB,"Sequence",&strLength,&status);
570 if(!str || U_FAILURE(status)) {
571 log_data_err("Could not load CollationElements from theBundle: %s\n", u_errorName(status));
572 } else if(u_strcmp(my,str) != 0){
573 log_err("Did not get the expected string for escaped \\u0075\n");
574 }
575 ures_close(resB);
576 }
577 {
578 const char *sourcePath = ctest_dataSrcDir();
579 int32_t srcPathLen = strlen(sourcePath);
580 const char *deltaPath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
581 int32_t deltaPathLen = strlen(deltaPath);
582 char *testDataFileName = (char *) malloc( srcPathLen+ deltaPathLen + 50 );
583 char *path = testDataFileName;
584
585 strcpy(path, sourcePath);
586 path += srcPathLen;
587 strcpy(path, deltaPath);
588 path += deltaPathLen;
589 status = U_ZERO_ERROR;
590 {
591 int32_t strLen =0;
592 const UChar* str = ures_getStringByKey(theBundle, "testincludeUTF",&strLen,&status);
593 strcpy(path, "th18057.txt");
594 path[strlen("th18057.txt")]=0;
595 if(U_FAILURE(status)){
596 log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status));
597 }else{
598 /* open the file */
599 const char* cp = NULL;
600 UCHARBUF* ucbuf = ucbuf_open(testDataFileName,&cp,FALSE,FALSE,&status);
601 len = 0;
602 if(U_SUCCESS(status)){
603 const UChar* buffer = ucbuf_getBuffer(ucbuf,&len,&status);
604 if(U_SUCCESS(status)){
605 /* verify the contents */
606 if(strLen != len ){
607 log_err("Did not get the expected len for th18057. Expected: %i , Got: %i\n", len ,strLen);
608 }
609 if(u_strncmp(str, buffer,strLen)!=0){
610 log_err("Did not get the expected string from th18057. Include functionality failed for genrb.\n");
611 }
612 }else{
613 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status));
614 }
615
616 ucbuf_close(ucbuf);
617 }else{
618 log_err("Could not get th18057.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status));
619 }
620 }
621 }
622 status = U_ZERO_ERROR;
623 {
624 int32_t strLen =0;
625 const UChar* str = ures_getStringByKey(theBundle, "testinclude",&strLen,&status);
626 strcpy(path, "translit_rules.txt");
627 path[strlen("translit_rules.txt")]=0;
628
629 if(U_FAILURE(status)){
630 log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status));
631 }else{
632 /* open the file */
633 const char* cp=NULL;
634 UCHARBUF* ucbuf = ucbuf_open(testDataFileName,&cp,FALSE,FALSE,&status);
635 len = 0;
636 if(U_SUCCESS(status)){
637 const UChar* buffer = ucbuf_getBuffer(ucbuf,&len,&status);
638 if(U_SUCCESS(status)){
639 /* verify the contents */
640 if(strLen != len ){
641 log_err("Did not get the expected len for translit_rules. Expected: %i , Got: %i\n", len ,strLen);
642 }
643 if(u_strncmp(str, buffer,strLen)!=0){
644 log_err("Did not get the expected string from translit_rules. Include functionality failed for genrb.\n");
645 }
646 }else{
647 log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status));
648 }
649 ucbuf_close(ucbuf);
650 }else{
651 log_err("Could not get translit_rules.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status));
652 }
653 }
654 }
655 free(testDataFileName);
656 }
657 ures_close(res);
658 ures_close(theBundle);
659
660}
661
662static void TestEmptyTypes() {
663 UResourceBundle* theBundle = NULL;
664 char action[256];
665 const char* testdatapath;
666 UErrorCode status = U_ZERO_ERROR;
667 UResourceBundle* res = NULL;
668 UResourceBundle* resArray = NULL;
669 const uint8_t *binResult = NULL;
670 int32_t len = 0;
671 int32_t intResult = 0;
672 const UChar *zeroString;
673 const int32_t *zeroIntVect;
674
675 strcpy(action, "Construction of testtypes bundle");
676 testdatapath=loadTestData(&status);
677 if(U_FAILURE(status))
678 {
679 log_err("Could not load testdata.dat %s \n",myErrorName(status));
680 return;
681 }
682
683 theBundle = ures_open(testdatapath, "testtypes", &status);
684
685 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
686
687 CONFIRM_INT_NE(theBundle, NULL);
688
689 /* This test reads the string "abc\u0000def" from the bundle */
690 /* if everything is working correctly, the size of this string */
691 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
692
693 status = U_ZERO_ERROR;
694 strcpy(action, "getting and testing of explicit string of zero length string");
695 res = ures_getByKey(theBundle, "emptyexplicitstring", res, &status);
696 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
697 CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
698 zeroString=ures_getString(res, &len, &status);
699 if(U_SUCCESS(status)){
700 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
701 CONFIRM_INT_EQ(len, 0);
702 CONFIRM_INT_EQ(u_strlen(zeroString), 0);
703 }
704 else {
705 log_err("Couldn't get emptyexplicitstring\n");
706 }
707
708 status = U_ZERO_ERROR;
709 strcpy(action, "getting and testing of normal string of zero length string");
710 res = ures_getByKey(theBundle, "emptystring", res, &status);
711 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
712 CONFIRM_INT_EQ(ures_getType(res), URES_STRING);
713 zeroString=ures_getString(res, &len, &status);
714 if(U_SUCCESS(status)){
715 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
716 CONFIRM_INT_EQ(len, 0);
717 CONFIRM_INT_EQ(u_strlen(zeroString), 0);
718 }
719 else {
720 log_err("Couldn't get emptystring\n");
721 }
722
723 status = U_ZERO_ERROR;
724 strcpy(action, "getting and testing of empty int");
725 res = ures_getByKey(theBundle, "emptyint", res, &status);
726 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
727 CONFIRM_INT_EQ(ures_getType(res), URES_INT);
728 intResult=ures_getInt(res, &status);
729 if(U_SUCCESS(status)){
730 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
731 CONFIRM_INT_EQ(intResult, 0);
732 }
733 else {
734 log_err("Couldn't get emptystring\n");
735 }
736
737 status = U_ZERO_ERROR;
738 strcpy(action, "getting and testing of zero length intvector");
739 res = ures_getByKey(theBundle, "emptyintv", res, &status);
740 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
741 CONFIRM_INT_EQ(ures_getType(res), URES_INT_VECTOR);
742
743 if(U_FAILURE(status)){
744 log_err("Couldn't get emptyintv key %s\n", u_errorName(status));
745 }
746 else {
747 zeroIntVect=ures_getIntVector(res, &len, &status);
748 if(!U_SUCCESS(status) || resArray != NULL || len != 0) {
749 log_err("Shouldn't get emptyintv\n");
750 }
751 }
752
753 status = U_ZERO_ERROR;
754 strcpy(action, "getting and testing of zero length emptybin");
755 res = ures_getByKey(theBundle, "emptybin", res, &status);
756 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
757 CONFIRM_INT_EQ(ures_getType(res), URES_BINARY);
758
759 if(U_FAILURE(status)){
760 log_err("Couldn't get emptybin key %s\n", u_errorName(status));
761 }
762 else {
763 binResult=ures_getBinary(res, &len, &status);
764 if(!U_SUCCESS(status) || binResult != NULL || len != 0) {
765 log_err("Shouldn't get emptybin\n");
766 }
767 }
768
769 status = U_ZERO_ERROR;
770 strcpy(action, "getting and testing of zero length emptyarray");
771 res = ures_getByKey(theBundle, "emptyarray", res, &status);
772 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
773 CONFIRM_INT_EQ(ures_getType(res), URES_ARRAY);
774
775 if(U_FAILURE(status)){
776 log_err("Couldn't get emptyarray key %s\n", u_errorName(status));
777 }
778 else {
779 resArray=ures_getByIndex(res, 0, resArray, &status);
780 if(U_SUCCESS(status) || resArray != NULL){
781 log_err("Shouldn't get emptyarray\n");
782 }
783 }
784
785 status = U_ZERO_ERROR;
786 strcpy(action, "getting and testing of zero length emptytable");
787 res = ures_getByKey(theBundle, "emptytable", res, &status);
788 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
789 CONFIRM_INT_EQ(ures_getType(res), URES_TABLE);
790
791 if(U_FAILURE(status)){
792 log_err("Couldn't get emptytable key %s\n", u_errorName(status));
793 }
794 else {
795 resArray=ures_getByIndex(res, 0, resArray, &status);
796 if(U_SUCCESS(status) || resArray != NULL){
797 log_err("Shouldn't get emptytable\n");
798 }
799 }
800
801 ures_close(res);
802 ures_close(theBundle);
803}
804
805static void TestEmptyBundle(){
806 UErrorCode status = U_ZERO_ERROR;
807 const char* testdatapath=NULL;
808 UResourceBundle *resb=0, *dResB=0;
809
810 testdatapath=loadTestData(&status);
811 if(U_FAILURE(status))
812 {
813 log_err("Could not load testdata.dat %s \n",myErrorName(status));
814 return;
815 }
816 resb = ures_open(testdatapath, "testempty", &status);
817
818 if(U_SUCCESS(status)){
819 dResB = ures_getByKey(resb,"test",dResB,&status);
820 if(status!= U_MISSING_RESOURCE_ERROR){
821 log_err("Did not get the expected error from an empty resource bundle. Expected : %s Got: %s\n",
822 u_errorName(U_MISSING_RESOURCE_ERROR),u_errorName(status));
823 }
824 }
825 ures_close(dResB);
826 ures_close(resb);
827}
828
829static void TestBinaryCollationData(){
830 UErrorCode status=U_ZERO_ERROR;
831 const char* locale="te";
832 const char* testdatapath;
833 UResourceBundle *teRes = NULL;
834 UResourceBundle *coll=NULL;
835 UResourceBundle *binColl = NULL;
836 uint8_t *binResult = NULL;
837 int32_t len=0;
838 const char* action="testing the binary collaton data";
839
840#if !UCONFIG_NO_COLLATION
841 log_verbose("Testing binary collation data resource......\n");
842
843 testdatapath=loadTestData(&status);
844 if(U_FAILURE(status))
845 {
846 log_err("Could not load testdata.dat %s \n",myErrorName(status));
847 return;
848 }
849
850
851 teRes=ures_open(testdatapath, locale, &status);
852 if(U_FAILURE(status)){
853 log_err("ERROR: Failed to get resource for \"te\" with %s", myErrorName(status));
854 return;
855 }
856 status=U_ZERO_ERROR;
857 coll = ures_getByKey(teRes, "CollationElements", coll, &status);
858 if(U_SUCCESS(status)){
859 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
860 CONFIRM_INT_EQ(ures_getType(coll), URES_TABLE);
861 binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status);
862 if(U_SUCCESS(status)){
863 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
864 CONFIRM_INT_EQ(ures_getType(binColl), URES_BINARY);
865 binResult=(uint8_t*)ures_getBinary(binColl, &len, &status);
866 if(U_SUCCESS(status)){
867 CONFIRM_ErrorCode(status, U_ZERO_ERROR);
868 CONFIRM_INT_GE(len, 1);
869 }
870
871 }else{
872 log_err("ERROR: ures_getByKey(locale(te), %%CollationBin) failed\n");
873 }
874 }
875 else{
876 log_err("ERROR: ures_getByKey(locale(te), CollationElements) failed\n");
877 return;
878 }
879 ures_close(binColl);
880 ures_close(coll);
881 ures_close(teRes);
882#endif
883}
884
885static void TestAPI() {
886 UErrorCode status=U_ZERO_ERROR;
887 int32_t len=0;
888 const char* key=NULL;
889 const UChar* value=NULL;
890 const char* testdatapath;
891 UChar* utestdatapath=NULL;
892 char convOutput[256];
893 UResourceBundle *teRes = NULL;
894 UResourceBundle *teFillin=NULL;
895 UResourceBundle *teFillin2=NULL;
896
897 log_verbose("Testing ures_openU()......\n");
898
899 testdatapath=loadTestData(&status);
900 if(U_FAILURE(status))
901 {
902 log_err("Could not load testdata.dat %s \n",myErrorName(status));
903 return;
904 }
905 len =strlen(testdatapath);
906 utestdatapath = (UChar*) malloc((len+10)*sizeof(UChar));
907
908 u_charsToUChars(testdatapath, utestdatapath, strlen(testdatapath)+1);
909 /*u_uastrcpy(utestdatapath, testdatapath);*/
910
911 /*Test ures_openU */
912
913 teRes=ures_openU(utestdatapath, "te", &status);
914 if(U_FAILURE(status)){
915 log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath), myErrorName(status));
916 return;
917 }
918 /*Test ures_getLocale() */
919 log_verbose("Testing ures_getLocale() .....\n");
920 if(strcmp(ures_getLocale(teRes, &status), "te") != 0){
921 log_err("ERROR: ures_getLocale() failed. Expected = te_TE Got = %s\n", ures_getLocale(teRes, &status));
922 }
923 /*Test ures_getNextString() */
924 teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status);
925 key=ures_getKey(teFillin);
926 value=(UChar*)ures_getNextString(teFillin, &len, &key, &status);
927 ures_resetIterator(NULL);
928 value=(UChar*)ures_getNextString(teFillin, &len, &key, &status);
929 if(status !=U_INDEX_OUTOFBOUNDS_ERROR){
930 log_err("ERROR: calling getNextString where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
931 myErrorName(status));
932 }
933 ures_resetIterator(teRes);
934 /*Test ures_getNextResource() where resource is table*/
935 status=U_ZERO_ERROR;
936#if (U_CHARSET_FAMILY == U_ASCII_FAMILY)
937 /* The next key varies depending on the charset. */
938 teFillin=ures_getNextResource(teRes, teFillin, &status);
939 if(U_FAILURE(status)){
940 log_err("ERROR: ures_getNextResource() failed \n");
941 }
942 key=ures_getKey(teFillin);
943 /*if(strcmp(key, "%%CollationBin") != 0){*/
944 if(strcmp(key, "CollationElements") != 0){
945 log_err("ERROR: ures_getNextResource() failed\n");
946 }
947#endif
948
949 /*Test ures_getByIndex on string Resource*/
950 teFillin=ures_getByKey(teRes, "string_only_in_te", teFillin, &status);
951 teFillin2=ures_getByIndex(teFillin, 0, teFillin2, &status);
952 if(U_FAILURE(status)){
953 log_err("ERROR: ures_getByIndex on string resource failed\n");
954 }
955 if(strcmp(u_austrcpy(convOutput, ures_getString(teFillin2, &len, &status)), "TE") != 0){
956 status=U_ZERO_ERROR;
957 log_err("ERROR: ures_getByIndex on string resource fetched the key=%s, expected \"TE\" \n", austrdup(ures_getString(teFillin2, &len, &status)));
958 }
959
960 /*ures_close(teRes);*/
961
962 /*Test ures_openFillIn*/
963 log_verbose("Testing ures_openFillIn......\n");
964 status=U_ZERO_ERROR;
965 ures_openFillIn(teRes, testdatapath, "te", &status);
966 if(U_FAILURE(status)){
967 log_err("ERROR: ures_openFillIn failed\n");
968 return;
969 }
970 if(strcmp(ures_getLocale(teRes, &status), "te") != 0){
971 log_err("ERROR: ures_openFillIn did not open the ResourceBundle correctly\n");
972 }
973 ures_getByKey(teRes, "string_only_in_te", teFillin, &status);
974 teFillin2=ures_getNextResource(teFillin, teFillin2, &status);
975 if(ures_getType(teFillin2) != URES_STRING){
976 log_err("ERROR: getType for getNextResource after ures_openFillIn failed\n");
977 }
978 teFillin2=ures_getNextResource(teFillin, teFillin2, &status);
979 if(status !=U_INDEX_OUTOFBOUNDS_ERROR){
980 log_err("ERROR: calling getNextResource where index out of bounds should return U_INDEX_OUTOFBOUNDS_ERROR, Got : %s\n",
981 myErrorName(status));
982 }
983
984 ures_close(teFillin);
985 ures_close(teFillin2);
986 ures_close(teRes);
987
988 /* Test that ures_getLocale() returns the "real" locale ID */
989 status=U_ZERO_ERROR;
990 teRes=ures_open(NULL, "dE_At_NOWHERE_TO_BE_FOUND", &status);
991 if(U_FAILURE(status)) {
992 log_data_err("unable to open a locale resource bundle from \"dE_At_NOWHERE_TO_BE_FOUND\"(%s)\n", u_errorName(status));
993 } else {
994 if(0!=strcmp("de_AT", ures_getLocale(teRes, &status))) {
995 log_data_err("ures_getLocale(\"dE_At_NOWHERE_TO_BE_FOUND\")=%s but must be de_AT\n", ures_getLocale(teRes, &status));
996 }
997 ures_close(teRes);
998 }
999
1000 /* same test, but with an aliased locale resource bundle */
1001 status=U_ZERO_ERROR;
1002 teRes=ures_open(NULL, "iW_Il_depRecaTed_HebreW", &status);
1003 if(U_FAILURE(status)) {
1004 log_data_err("unable to open a locale resource bundle from \"iW_Il_depRecaTed_HebreW\"(%s)\n", u_errorName(status));
1005 } else {
1006 if(0!=strcmp("he_IL", ures_getLocale(teRes, &status))) {
1007 log_data_err("ures_getLocale(\"iW_Il_depRecaTed_HebreW\")=%s but must be he_IL\n", ures_getLocale(teRes, &status));
1008 }
1009 ures_close(teRes);
1010 }
1011 free(utestdatapath);
1012}
1013
1014static void TestErrorConditions(){
1015 UErrorCode status=U_ZERO_ERROR;
1016 const char *key=NULL;
1017 const UChar *value=NULL;
1018 const char* testdatapath;
1019 UChar* utestdatapath;
1020 int32_t len=0;
1021 UResourceBundle *teRes = NULL;
1022 UResourceBundle *coll=NULL;
1023 UResourceBundle *binColl = NULL;
1024 UResourceBundle *teFillin=NULL;
1025 UResourceBundle *teFillin2=NULL;
1026 uint8_t *binResult = NULL;
1027 int32_t resultLen;
1028
1029
1030 testdatapath = loadTestData(&status);
1031 if(U_FAILURE(status))
1032 {
1033 log_err("Could not load testdata.dat %s \n",myErrorName(status));
1034 return;
1035 }
1036 len = strlen(testdatapath);
1037 utestdatapath = (UChar*) malloc(sizeof(UChar) *(len+10));
1038 u_uastrcpy(utestdatapath, testdatapath);
1039
1040 /*Test ures_openU with status != U_ZERO_ERROR*/
1041 log_verbose("Testing ures_openU() with status != U_ZERO_ERROR.....\n");
1042 status=U_ILLEGAL_ARGUMENT_ERROR;
1043 teRes=ures_openU(utestdatapath, "te", &status);
1044 if(U_FAILURE(status)){
1045 log_verbose("ures_openU() failed as expected path =%s with status != U_ZERO_ERROR\n", testdatapath);
1046 }else{
1047 log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath));
1048 ures_close(teRes);
1049 }
1050 /*Test ures_openFillIn with UResourceBundle = NULL*/
1051 log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
1052 status=U_ZERO_ERROR;
1053 ures_openFillIn(NULL, testdatapath, "te", &status);
1054 if(status != U_INTERNAL_PROGRAM_ERROR){
1055 log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail. Expected U_INTERNAL_PROGRAM_ERROR, Got: %s\n",
1056 myErrorName(status));
1057 }
1058 /*Test ures_getLocale() with status != U_ZERO_ERROR*/
1059 status=U_ZERO_ERROR;
1060 teRes=ures_openU(utestdatapath, "te", &status);
1061 if(U_FAILURE(status)){
1062 log_err("ERROR: ures_openU() failed path =%s with %s", austrdup(utestdatapath), myErrorName(status));
1063 return;
1064 }
1065 status=U_ILLEGAL_ARGUMENT_ERROR;
1066 if(ures_getLocale(teRes, &status) != NULL){
1067 log_err("ERROR: ures_getLocale is supposed to fail with errorCode != U_ZERO_ERROR\n");
1068 }
1069 /*Test ures_getLocale() with UResourceBundle = NULL*/
1070 status=U_ZERO_ERROR;
1071 if(ures_getLocale(NULL, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1072 log_err("ERROR: ures_getLocale is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1073 myErrorName(status));
1074 }
1075 /*Test ures_getSize() with UResourceBundle = NULL */
1076 status=U_ZERO_ERROR;
1077 if(ures_getSize(NULL) != 0){
1078 log_err("ERROR: ures_getSize() should return 0 when UResourceBundle=NULL. Got =%d\n", ures_getSize(NULL));
1079 }
1080 /*Test ures_getType() with UResourceBundle = NULL should return URES_NONE==-1*/
1081 status=U_ZERO_ERROR;
1082 if(ures_getType(NULL) != URES_NONE){
1083 log_err("ERROR: ures_getType() should return URES_NONE when UResourceBundle=NULL. Got =%d\n", ures_getType(NULL));
1084 }
1085 /*Test ures_getKey() with UResourceBundle = NULL*/
1086 status=U_ZERO_ERROR;
1087 if(ures_getKey(NULL) != NULL){
1088 log_err("ERROR: ures_getKey() should return NULL when UResourceBundle=NULL. Got =%d\n", ures_getKey(NULL));
1089 }
1090 /*Test ures_hasNext() with UResourceBundle = NULL*/
1091 status=U_ZERO_ERROR;
1092 if(ures_hasNext(NULL) != FALSE){
1093 log_err("ERROR: ures_hasNext() should return FALSE when UResourceBundle=NULL. Got =%d\n", ures_hasNext(NULL));
1094 }
1095 /*Test ures_get() with UResourceBundle = NULL*/
1096 status=U_ZERO_ERROR;
1097 if(ures_getStringByKey(NULL, "string_only_in_te", &resultLen, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1098 log_err("ERROR: ures_get is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1099 myErrorName(status));
1100 }
1101 /*Test ures_getByKey() with UResourceBundle = NULL*/
1102 status=U_ZERO_ERROR;
1103 teFillin=ures_getByKey(NULL, "string_only_in_te", teFillin, &status);
1104 if( teFillin != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1105 log_err("ERROR: ures_getByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1106 myErrorName(status));
1107 }
1108 /*Test ures_getByKey() with status != U_ZERO_ERROR*/
1109 teFillin=ures_getByKey(NULL, "string_only_in_te", teFillin, &status);
1110 if(teFillin != NULL ){
1111 log_err("ERROR: ures_getByKey is supposed to fail when errorCode != U_ZERO_ERROR\n");
1112 }
1113 /*Test ures_getStringByKey() with UResourceBundle = NULL*/
1114 status=U_ZERO_ERROR;
1115 if(ures_getStringByKey(NULL, "string_only_in_te", &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1116 log_err("ERROR: ures_getStringByKey is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1117 myErrorName(status));
1118 }
1119 /*Test ures_getStringByKey() with status != U_ZERO_ERROR*/
1120 if(ures_getStringByKey(teRes, "string_only_in_te", &len, &status) != NULL){
1121 log_err("ERROR: ures_getStringByKey is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1122 myErrorName(status));
1123 }
1124 /*Test ures_getString() with UResourceBundle = NULL*/
1125 status=U_ZERO_ERROR;
1126 if(ures_getString(NULL, &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1127 log_err("ERROR: ures_getString is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1128 myErrorName(status));
1129 }
1130 /*Test ures_getString() with status != U_ZERO_ERROR*/
1131 if(ures_getString(teRes, &len, &status) != NULL){
1132 log_err("ERROR: ures_getString is supposed to fail when status != U_ZERO_ERROR. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1133 myErrorName(status));
1134 }
1135 /*Test ures_getBinary() with UResourceBundle = NULL*/
1136 status=U_ZERO_ERROR;
1137 if(ures_getBinary(NULL, &len, &status) != NULL && status != U_ILLEGAL_ARGUMENT_ERROR){
1138 log_err("ERROR: ures_getBinary is supposed to fail when UResourceBundle = NULL. Expected: errorCode = U_ILLEGAL_ARGUMENT_ERROR, Got: errorCode=%s\n",
1139 myErrorName(status));
1140 }
1141 /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
1142 status=U_ZERO_ERROR;
1143 coll = ures_getByKey(teRes, "CollationElements", coll, &status);
1144 binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status);
1145
1146 status=U_ILLEGAL_ARGUMENT_ERROR;
1147 binResult=(uint8_t*)ures_getBinary(binColl, &len, &status);
1148 if(binResult != NULL){
1149 log_err("ERROR: ures_getBinary() with status != U_ZERO_ERROR is supposed to fail\n");
1150 }
1151
1152 /*Test ures_getNextResource() with status != U_ZERO_ERROR*/
1153 teFillin=ures_getNextResource(teRes, teFillin, &status);
1154 if(teFillin != NULL){
1155 log_err("ERROR: ures_getNextResource() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1156 }
1157 /*Test ures_getNextResource() with UResourceBundle = NULL*/
1158 status=U_ZERO_ERROR;
1159 teFillin=ures_getNextResource(NULL, teFillin, &status);
1160 if(teFillin != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){
1161 log_err("ERROR: ures_getNextResource() with UResourceBundle = NULL is supposed to fail. Expected : U_IILEGAL_ARGUMENT_ERROR, Got : %s\n",
1162 myErrorName(status));
1163 }
1164 /*Test ures_getNextString with errorCode != U_ZERO_ERROR*/
1165 teFillin=ures_getByKey(teRes, "tagged_array_in_te_te_IN", teFillin, &status);
1166 key=ures_getKey(teFillin);
1167 status = U_ILLEGAL_ARGUMENT_ERROR;
1168 value=(UChar*)ures_getNextString(teFillin, &len, &key, &status);
1169 if(value != NULL){
1170 log_err("ERROR: ures_getNextString() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1171 }
1172 /*Test ures_getNextString with UResourceBundle = NULL*/
1173 status=U_ZERO_ERROR;
1174 value=(UChar*)ures_getNextString(NULL, &len, &key, &status);
1175 if(value != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){
1176 log_err("ERROR: ures_getNextString() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1177 myErrorName(status));
1178 }
1179 /*Test ures_getByIndex with errorCode != U_ZERO_ERROR*/
1180 status=U_ZERO_ERROR;
1181 teFillin=ures_getByKey(teRes, "array_only_in_te", teFillin, &status);
1182 if(ures_countArrayItems(teRes, "array_only_in_te", &status) != 4) {
1183 log_err("ERROR: Wrong number of items in an array!\n");
1184 }
1185 status=U_ILLEGAL_ARGUMENT_ERROR;
1186 teFillin2=ures_getByIndex(teFillin, 0, teFillin2, &status);
1187 if(teFillin2 != NULL){
1188 log_err("ERROR: ures_getByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1189 }
1190 /*Test ures_getByIndex with UResourceBundle = NULL */
1191 status=U_ZERO_ERROR;
1192 teFillin2=ures_getByIndex(NULL, 0, teFillin2, &status);
1193 if(status != U_ILLEGAL_ARGUMENT_ERROR){
1194 log_err("ERROR: ures_getByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1195 myErrorName(status));
1196 }
1197 /*Test ures_getStringByIndex with errorCode != U_ZERO_ERROR*/
1198 status=U_ZERO_ERROR;
1199 teFillin=ures_getByKey(teRes, "array_only_in_te", teFillin, &status);
1200 status=U_ILLEGAL_ARGUMENT_ERROR;
1201 value=(UChar*)ures_getStringByIndex(teFillin, 0, &len, &status);
1202 if( value != NULL){
1203 log_err("ERROR: ures_getSringByIndex() with errorCode != U_ZERO_ERROR is supposed to fail\n");
1204 }
1205 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1206 status=U_ZERO_ERROR;
1207 value=(UChar*)ures_getStringByIndex(NULL, 0, &len, &status);
1208 if(value != NULL || status != U_ILLEGAL_ARGUMENT_ERROR){
1209 log_err("ERROR: ures_getStringByIndex() with UResourceBundle=NULL is supposed to fail\n Expected: U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
1210 myErrorName(status));
1211 }
1212 /*Test ures_getStringByIndex with UResourceBundle = NULL */
1213 status=U_ZERO_ERROR;
1214 value=(UChar*)ures_getStringByIndex(teFillin, 9999, &len, &status);
1215 if(value != NULL || status != U_MISSING_RESOURCE_ERROR){
1216 log_err("ERROR: ures_getStringByIndex() with index that is too big is supposed to fail\n Expected: U_MISSING_RESOURCE_ERROR, Got: %s\n",
1217 myErrorName(status));
1218 }
1219 /*Test ures_getInt() where UResourceBundle = NULL */
1220 status=U_ZERO_ERROR;
1221 if(ures_getInt(NULL, &status) != -1 && status != U_ILLEGAL_ARGUMENT_ERROR){
1222 log_err("ERROR: ures_getInt() with UResourceBundle = NULL should fail. Expected: U_IILEGAL_ARGUMENT_ERROR, Got: %s\n",
1223 myErrorName(status));
1224 }
1225 /*Test ures_getInt() where status != U_ZERO_ERROR */
1226 if(ures_getInt(teRes, &status) != -1){
1227 log_err("ERROR: ures_getInt() with errorCode != U_ZERO_ERROR should fail\n");
1228 }
1229
1230 ures_close(teFillin);
1231 ures_close(teFillin2);
1232 ures_close(coll);
1233 ures_close(binColl);
1234 ures_close(teRes);
1235 free(utestdatapath);
1236
1237
1238}
1239
1240static void TestGetVersion(){
1241 UVersionInfo minVersionArray = {0x01, 0x00, 0x00, 0x00};
1242 UVersionInfo maxVersionArray = {0x50, 0x80, 0xcf, 0xcf};
1243 UVersionInfo versionArray;
1244 UErrorCode status= U_ZERO_ERROR;
1245 UResourceBundle* resB = NULL;
1246 int i=0, j = 0;
1247 int locCount = uloc_countAvailable();
1248 const char *locName = "root";
1249 log_verbose("The ures_getVersion tests begin : \n");
1250
1251 for(j = -1; j < locCount; j++) {
1252 if(j >= 0) {
1253 locName = uloc_getAvailable(j);
1254 }
1255 log_verbose("Testing version number for locale %s\n", locName);
1256 resB = ures_open(NULL,locName, &status);
1257 if (U_FAILURE(status)) {
1258 log_err("Resource bundle creation for locale %s failed.: %s\n", locName, myErrorName(status));
1259 ures_close(resB);
1260 return;
1261 }
1262 ures_getVersion(resB, versionArray);
1263 for (i=0; i<4; ++i) {
1264 if (versionArray[i] < minVersionArray[i] ||
1265 versionArray[i] > maxVersionArray[i])
1266 {
1267 log_err("Testing ures_getVersion() - unexpected result: %d.%d.%d.%d\n",
1268 versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
1269 break;
1270 }
1271 }
1272 ures_close(resB);
1273 }
1274}
1275
1276static void TestResourceBundles()
1277{
1278
1279 testTag("only_in_Root", TRUE, FALSE, FALSE);
1280 testTag("in_Root_te", TRUE, TRUE, FALSE);
1281 testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE);
1282 testTag("in_Root_te_IN", TRUE, FALSE, TRUE);
1283 testTag("only_in_te", FALSE, TRUE, FALSE);
1284 testTag("only_in_te_IN", FALSE, FALSE, TRUE);
1285 testTag("in_te_te_IN", FALSE, TRUE, TRUE);
1286 testTag("nonexistent", FALSE, FALSE, FALSE);
1287
1288 log_verbose("Passed:= %d Failed= %d \n", pass, fail);
1289
1290}
1291
1292
1293static void TestConstruction1()
1294{
1295 UResourceBundle *test1 = 0, *test2 = 0,*empty = 0;
1296 const UChar *result1, *result2;
1297 UErrorCode status= U_ZERO_ERROR;
1298 UErrorCode err = U_ZERO_ERROR;
1299 const char* locale="te_IN";
1300 const char* testdatapath;
1301
1302 int32_t len1=0;
1303 int32_t len2=0;
1304 UVersionInfo versionInfo;
1305 char versionString[256];
1306 char verboseOutput[256];
1307
1308 U_STRING_DECL(rootVal, "ROOT", 4);
1309 U_STRING_DECL(te_inVal, "TE_IN", 5);
1310
1311 U_STRING_INIT(rootVal, "ROOT", 4);
1312 U_STRING_INIT(te_inVal, "TE_IN", 5);
1313
1314 testdatapath=loadTestData(&status);
1315 if(U_FAILURE(status))
1316 {
1317 log_err("Could not load testdata.dat %s \n",myErrorName(status));
1318 return;
1319 }
1320
1321 log_verbose("Testing ures_open()......\n");
1322
1323 empty = ures_open(testdatapath, "testempty", &status);
1324 if(empty == NULL || U_FAILURE(status)) {
1325 log_err("opening empty failed!\n");
1326 }
1327 ures_close(empty);
1328
1329 test1=ures_open(testdatapath, NULL, &err);
1330
1331 if(U_FAILURE(err))
1332 {
1333 log_err("construction of NULL did not succeed : %s \n", myErrorName(status));
1334 return;
1335 }
1336 test2=ures_open(testdatapath, locale, &err);
1337 if(U_FAILURE(err))
1338 {
1339 log_err("construction of %s did not succeed : %s \n", locale, myErrorName(status));
1340 return;
1341 }
1342 result1= ures_getStringByKey(test1, "string_in_Root_te_te_IN", &len1, &err);
1343 result2= ures_getStringByKey(test2, "string_in_Root_te_te_IN", &len2, &err);
1344 if (U_FAILURE(err) || len1==0 || len2==0) {
1345 log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(status));
1346 return;
1347 }
1348 log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", u_austrcpy(verboseOutput, result1));
1349 log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", u_austrcpy(verboseOutput, result2));
1350 if(u_strcmp(result1, rootVal) !=0 || u_strcmp(result2, te_inVal) !=0 ){
1351 log_err("construction test failed. Run Verbose for more information");
1352 }
1353
1354
1355 /* Test getVersionNumber*/
1356 log_verbose("Testing version number\n");
1357 log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1));
1358
1359 log_verbose("Testing version \n");
1360 ures_getVersion(test1, versionInfo);
1361 u_versionToString(versionInfo, versionString);
1362
1363 log_verbose("for getVersion : %s\n", versionString);
1364
1365 if(strcmp(versionString, ures_getVersionNumber(test1)) != 0) {
1366 log_err("Versions differ: %s vs %s\n", versionString, ures_getVersionNumber(test1));
1367 }
1368
1369 ures_close(test1);
1370 ures_close(test2);
1371
1372}
1373
1374/*****************************************************************************/
1375/*****************************************************************************/
1376
1377static UBool testTag(const char* frag,
1378 UBool in_Root,
1379 UBool in_te,
1380 UBool in_te_IN)
1381{
1382 int32_t failNum = fail;
1383
1384 /* Make array from input params */
1385
1386 UBool is_in[3];
1387 const char *NAME[] = { "ROOT", "TE", "TE_IN" };
1388
1389 /* Now try to load the desired items */
1390 UResourceBundle* theBundle = NULL;
1391 char tag[99];
1392 char action[256];
1393 UErrorCode expected_status,status = U_ZERO_ERROR,expected_resource_status = U_ZERO_ERROR;
1394 UChar* base = NULL;
1395 UChar* expected_string = NULL;
1396 const UChar* string = NULL;
1397 char buf[5];
1398 char item_tag[10];
1399 int32_t i,j,row,col, len;
1400 int32_t actual_bundle;
1401 int32_t count = 0;
1402 int32_t row_count=0;
1403 int32_t column_count=0;
1404 int32_t index = 0;
1405 int32_t tag_count= 0;
1406 const char* testdatapath;
1407 char verboseOutput[256];
1408 UResourceBundle* array=NULL;
1409 UResourceBundle* array2d=NULL;
1410 UResourceBundle* tags=NULL;
1411 UResourceBundle* arrayItem1=NULL;
1412
1413 testdatapath = loadTestData(&status);
1414 if(U_FAILURE(status))
1415 {
1416 log_err("Could not load testdata.dat %s \n",myErrorName(status));
1417 return FALSE;
1418 }
1419
1420 is_in[0] = in_Root;
1421 is_in[1] = in_te;
1422 is_in[2] = in_te_IN;
1423
1424 strcpy(item_tag, "tag");
1425
1426 for (i=0; i<bundles_count; ++i)
1427 {
1428 strcpy(action,"construction for ");
1429 strcat(action, param[i].name);
1430
1431
1432 status = U_ZERO_ERROR;
1433
1434 theBundle = ures_open(testdatapath, param[i].name, &status);
1435 CONFIRM_ErrorCode(status,param[i].expected_constructor_status);
1436
1437 if(i == 5)
1438 actual_bundle = 0; /* ne -> default */
1439 else if(i == 3)
1440 actual_bundle = 1; /* te_NE -> te */
1441 else if(i == 4)
1442 actual_bundle = 2; /* te_IN_NE -> te_IN */
1443 else
1444 actual_bundle = i;
1445
1446 expected_resource_status = U_MISSING_RESOURCE_ERROR;
1447 for (j=e_te_IN; j>=e_Root; --j)
1448 {
1449 if (is_in[j] && param[i].inherits[j])
1450 {
1451
1452 if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
1453 expected_resource_status = U_ZERO_ERROR;
1454 else if(j == 0)
1455 expected_resource_status = U_USING_DEFAULT_WARNING;
1456 else
1457 expected_resource_status = U_USING_FALLBACK_WARNING;
1458
1459 log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n",
1460 param[i].name,
1461 i,
1462 frag,
1463 j,
1464 is_in[j]?"Yes":"No",
1465 j,
1466 param[i].inherits[j]?"Yes":"No",
1467 param[actual_bundle].name);
1468
1469 break;
1470 }
1471 }
1472
1473 for (j=param[i].where; j>=0; --j)
1474 {
1475 if (is_in[j])
1476 {
1477 if(base != NULL) {
1478 free(base);
1479 base = NULL;
1480 }
1481 base=(UChar*)malloc(sizeof(UChar)*(strlen(NAME[j]) + 1));
1482 u_uastrcpy(base,NAME[j]);
1483
1484 break;
1485 }
1486 else {
1487 if(base != NULL) {
1488 free(base);
1489 base = NULL;
1490 }
1491 base = (UChar*) malloc(sizeof(UChar) * 1);
1492 *base = 0x0000;
1493 }
1494 }
1495
1496 /*----string---------------------------------------------------------------- */
1497
1498 strcpy(tag,"string_");
1499 strcat(tag,frag);
1500
1501 strcpy(action,param[i].name);
1502 strcat(action, ".ures_getStringByKey(" );
1503 strcat(action,tag);
1504 strcat(action, ")");
1505
1506
1507 status = U_ZERO_ERROR;
1508 len=0;
1509
1510 string=ures_getStringByKey(theBundle, tag, &len, &status);
1511 if(U_SUCCESS(status)) {
1512 expected_string=(UChar*)malloc(sizeof(UChar)*(u_strlen(base) + 4));
1513 u_strcpy(expected_string,base);
1514 CONFIRM_INT_EQ(len, u_strlen(expected_string));
1515 }else{
1516 expected_string = (UChar*)malloc(sizeof(UChar)*(u_strlen(kERROR) + 1));
1517 u_strcpy(expected_string,kERROR);
1518 string=kERROR;
1519 }
1520 log_verbose("%s got %d, expected %d\n", action, status, expected_resource_status);
1521
1522 CONFIRM_ErrorCode(status, expected_resource_status);
1523 CONFIRM_EQ(string, expected_string);
1524
1525
1526
1527 /*--------------array------------------------------------------------- */
1528
1529 strcpy(tag,"array_");
1530 strcat(tag,frag);
1531
1532 strcpy(action,param[i].name);
1533 strcat(action, ".ures_getByKey(" );
1534 strcat(action,tag);
1535 strcat(action, ")");
1536
1537 len=0;
1538
1539 count = kERROR_COUNT;
1540 status = U_ZERO_ERROR;
1541 array=ures_getByKey(theBundle, tag, array, &status);
1542 CONFIRM_ErrorCode(status,expected_resource_status);
1543 if (U_SUCCESS(status)) {
1544 /*confirm the resource type is an array*/
1545 CONFIRM_INT_EQ(ures_getType(array), URES_ARRAY);
1546 /*confirm the size*/
1547 count=ures_getSize(array);
1548 CONFIRM_INT_GE(count,1);
1549 for (j=0; j<count; ++j) {
1550 UChar element[3];
1551 u_strcpy(expected_string, base);
1552 u_uastrcpy(element, itoa1(j,buf));
1553 u_strcat(expected_string, element);
1554 arrayItem1=ures_getNextResource(array, arrayItem1, &status);
1555 if(U_SUCCESS(status)){
1556 CONFIRM_EQ(ures_getString(arrayItem1, &len, &status),expected_string);
1557 }
1558 }
1559
1560 }
1561 else {
1562 CONFIRM_INT_EQ(count,kERROR_COUNT);
1563 CONFIRM_ErrorCode(status, U_MISSING_RESOURCE_ERROR);
1564 /*CONFIRM_INT_EQ((int32_t)(unsigned long)array,(int32_t)0);*/
1565 count = 0;
1566 }
1567
1568 /*--------------arrayItem------------------------------------------------- */
1569
1570 strcpy(tag,"array_");
1571 strcat(tag,frag);
1572
1573 strcpy(action,param[i].name);
1574 strcat(action, ".ures_getStringByIndex(");
1575 strcat(action, tag);
1576 strcat(action, ")");
1577
1578
1579 for (j=0; j<10; ++j){
1580 index = count ? (randi(count * 3) - count) : (randi(200) - 100);
1581 status = U_ZERO_ERROR;
1582 string=kERROR;
1583 array=ures_getByKey(theBundle, tag, array, &status);
1584 if(!U_FAILURE(status)){
1585 UChar *t=NULL;
1586 t=(UChar*)ures_getStringByIndex(array, index, &len, &status);
1587 if(!U_FAILURE(status)){
1588 UChar element[3];
1589 string=t;
1590 u_strcpy(expected_string, base);
1591 u_uastrcpy(element, itoa1(index,buf));
1592 u_strcat(expected_string, element);
1593 } else {
1594 u_strcpy(expected_string, kERROR);
1595 }
1596
1597 }
1598 expected_status = (index >= 0 && index < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR;
1599 CONFIRM_ErrorCode(status,expected_status);
1600 CONFIRM_EQ(string,expected_string);
1601
1602 }
1603
1604
1605 /*--------------2dArray------------------------------------------------- */
1606
1607 strcpy(tag,"array_2d_");
1608 strcat(tag,frag);
1609
1610 strcpy(action,param[i].name);
1611 strcat(action, ".ures_getByKey(" );
1612 strcat(action,tag);
1613 strcat(action, ")");
1614
1615
1616
1617 row_count = kERROR_COUNT, column_count = kERROR_COUNT;
1618 status = U_ZERO_ERROR;
1619 array2d=ures_getByKey(theBundle, tag, array2d, &status);
1620
1621 CONFIRM_ErrorCode(status,expected_resource_status);
1622 if (U_SUCCESS(status))
1623 {
1624 /*confirm the resource type is an 2darray*/
1625 CONFIRM_INT_EQ(ures_getType(array2d), URES_ARRAY);
1626 row_count=ures_getSize(array2d);
1627 CONFIRM_INT_GE(row_count,1);
1628
1629 for(row=0; row<row_count; ++row){
1630 UResourceBundle *tableRow=NULL;
1631 tableRow=ures_getByIndex(array2d, row, tableRow, &status);
1632 CONFIRM_ErrorCode(status, expected_resource_status);
1633 if(U_SUCCESS(status)){
1634 /*confirm the resourcetype of each table row is an array*/
1635 CONFIRM_INT_EQ(ures_getType(tableRow), URES_ARRAY);
1636 column_count=ures_getSize(tableRow);
1637 CONFIRM_INT_GE(column_count,1);
1638
1639 for (col=0; j<column_count; ++j) {
1640 UChar element[3];
1641 u_strcpy(expected_string, base);
1642 u_uastrcpy(element, itoa1(row, buf));
1643 u_strcat(expected_string, element);
1644 u_uastrcpy(element, itoa1(col, buf));
1645 u_strcat(expected_string, element);
1646 arrayItem1=ures_getNextResource(tableRow, arrayItem1, &status);
1647 if(U_SUCCESS(status)){
1648 const UChar *stringValue=ures_getString(arrayItem1, &len, &status);
1649 CONFIRM_EQ(stringValue, expected_string);
1650 }
1651 }
1652 }
1653 ures_close(tableRow);
1654 }
1655 }else{
1656 CONFIRM_INT_EQ(row_count,kERROR_COUNT);
1657 CONFIRM_INT_EQ(column_count,kERROR_COUNT);
1658 row_count=column_count=0;
1659 }
1660
1661
1662 /*------2dArrayItem-------------------------------------------------------------- */
1663 /* 2dArrayItem*/
1664 for (j=0; j<10; ++j)
1665 {
1666 row = row_count ? (randi(row_count * 3) - row_count) : (randi(200) - 100);
1667 col = column_count ? (randi(column_count * 3) - column_count) : (randi(200) - 100);
1668 status = U_ZERO_ERROR;
1669 string = kERROR;
1670 len=0;
1671 array2d=ures_getByKey(theBundle, tag, array2d, &status);
1672 if(U_SUCCESS(status)){
1673 UResourceBundle *tableRow=NULL;
1674 tableRow=ures_getByIndex(array2d, row, tableRow, &status);
1675 if(U_SUCCESS(status)) {
1676 UChar *t=NULL;
1677 t=(UChar*)ures_getStringByIndex(tableRow, col, &len, &status);
1678 if(U_SUCCESS(status)){
1679 string=t;
1680 }
1681 }
1682 ures_close(tableRow);
1683 }
1684 expected_status = (row >= 0 && row < row_count && col >= 0 && col < column_count) ?
1685 expected_resource_status: U_MISSING_RESOURCE_ERROR;
1686 CONFIRM_ErrorCode(status,expected_status);
1687
1688 if (U_SUCCESS(status)){
1689 UChar element[3];
1690 u_strcpy(expected_string, base);
1691 u_uastrcpy(element, itoa1(row, buf));
1692 u_strcat(expected_string, element);
1693 u_uastrcpy(element, itoa1(col, buf));
1694 u_strcat(expected_string, element);
1695 } else {
1696 u_strcpy(expected_string,kERROR);
1697 }
1698 CONFIRM_EQ(string,expected_string);
1699
1700 }
1701
1702
1703 /*--------------taggedArray----------------------------------------------- */
1704 strcpy(tag,"tagged_array_");
1705 strcat(tag,frag);
1706
1707 strcpy(action,param[i].name);
1708 strcat(action,".ures_getByKey(");
1709 strcat(action, tag);
1710 strcat(action,")");
1711
1712
1713 status = U_ZERO_ERROR;
1714 tag_count=0;
1715 tags=ures_getByKey(theBundle, tag, tags, &status);
1716 CONFIRM_ErrorCode(status, expected_resource_status);
1717 if (U_SUCCESS(status)) {
1718 UResType bundleType=ures_getType(tags);
1719 CONFIRM_INT_EQ(bundleType, URES_TABLE);
1720
1721 tag_count=ures_getSize(tags);
1722 CONFIRM_INT_GE((int32_t)tag_count, (int32_t)0);
1723
1724 for(index=0; index <tag_count; index++){
1725 UResourceBundle *tagelement=NULL;
1726 const char *key=NULL;
1727 UChar* value=NULL;
1728 tagelement=ures_getByIndex(tags, index, tagelement, &status);
1729 key=ures_getKey(tagelement);
1730 value=(UChar*)ures_getNextString(tagelement, &len, &key, &status);
1731 log_verbose("tag = %s, value = %s\n", key, u_austrcpy(verboseOutput, value));
1732 if(strncmp(key, "tag", 3) == 0 && u_strncmp(value, base, u_strlen(base)) == 0){
1733 record_pass();
1734 }else{
1735 record_fail();
1736 }
1737 ures_close(tagelement);
1738 }
1739 }else{
1740 tag_count=0;
1741 }
1742
1743 /*---------taggedArrayItem----------------------------------------------*/
1744 count = 0;
1745 for (index=-20; index<20; ++index)
1746 {
1747
1748 status = U_ZERO_ERROR;
1749 string = kERROR;
1750 strcpy(item_tag, "tag");
1751 strcat(item_tag, itoa1(index,buf));
1752 tags=ures_getByKey(theBundle, tag, tags, &status);
1753 if(U_SUCCESS(status)){
1754 UResourceBundle *tagelement=NULL;
1755 UChar *t=NULL;
1756 tagelement=ures_getByKey(tags, item_tag, tagelement, &status);
1757 if(!U_FAILURE(status)){
1758 UResType elementType=ures_getType(tagelement);
1759 CONFIRM_INT_EQ(elementType, URES_STRING);
1760 if(strcmp(ures_getKey(tagelement), item_tag) == 0){
1761 record_pass();
1762 }else{
1763 record_fail();
1764 }
1765 t=(UChar*)ures_getString(tagelement, &len, &status);
1766 if(!U_FAILURE(status)){
1767 string=t;
1768 }
1769 }
1770 if (index < 0) {
1771 CONFIRM_ErrorCode(status,U_MISSING_RESOURCE_ERROR);
1772 }
1773 else{
1774 if (status != U_MISSING_RESOURCE_ERROR) {
1775 UChar element[3];
1776 u_strcpy(expected_string, base);
1777 u_uastrcpy(element, itoa1(index,buf));
1778 u_strcat(expected_string, element);
1779 CONFIRM_EQ(string,expected_string);
1780 count++;
1781 }
1782 }
1783 ures_close(tagelement);
1784 }
1785 }
1786 CONFIRM_INT_EQ(count, tag_count);
1787
1788 free(expected_string);
1789 ures_close(theBundle);
1790 }
1791 ures_close(array);
1792 ures_close(array2d);
1793 ures_close(tags);
1794 ures_close(arrayItem1);
1795 free(base);
1796 return (UBool)(failNum == fail);
1797}
1798
1799static void record_pass()
1800{
1801 ++pass;
1802}
1803
1804static void record_fail()
1805{
1806 ++fail;
1807}
1808
1809/**
1810 * Test to make sure that the U_USING_FALLBACK_ERROR and U_USING_DEFAULT_ERROR
1811 * are set correctly
1812 */
1813
1814static void TestFallback()
1815{
1816 UErrorCode status = U_ZERO_ERROR;
1817 UResourceBundle *fr_FR = NULL;
1818 const UChar *junk; /* ignored */
1819 int32_t resultLen;
1820
1821 log_verbose("Opening fr_FR..");
1822 fr_FR = ures_open(NULL, "fr_FR", &status);
1823 if(U_FAILURE(status))
1824 {
1825 log_err("Couldn't open fr_FR - %d\n", status);
1826 return;
1827 }
1828
1829 status = U_ZERO_ERROR;
1830
1831
1832 /* clear it out.. just do some calls to get the gears turning */
1833 junk = ures_getStringByKey(fr_FR, "LocaleID", &resultLen, &status);
1834 status = U_ZERO_ERROR;
1835 junk = ures_getStringByKey(fr_FR, "LocaleString", &resultLen, &status);
1836 status = U_ZERO_ERROR;
1837 junk = ures_getStringByKey(fr_FR, "LocaleID", &resultLen, &status);
1838 status = U_ZERO_ERROR;
1839
1840 /* OK first one. This should be a Default value. */
1841 junk = ures_getStringByKey(fr_FR, "%%PREEURO", &resultLen, &status);
1842 if(status != U_USING_DEFAULT_WARNING)
1843 {
1844 log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get %%PREEURO from fr_FR, got %s\n",
1845 u_errorName(status));
1846 }
1847
1848 status = U_ZERO_ERROR;
1849
1850 /* and this is a Fallback, to fr */
1851 junk = ures_getStringByKey(fr_FR, "DayNames", &resultLen, &status);
1852 if(status != U_USING_FALLBACK_WARNING)
1853 {
1854 log_data_err("Expected U_USING_FALLBACK_ERROR when trying to get DayNames from fr_FR, got %d\n",
1855 status);
1856 }
1857
1858 status = U_ZERO_ERROR;
1859
1860 ures_close(fr_FR);
1861 /* Temporary hack err actually should be U_USING_FALLBACK_ERROR */
1862 /* Test Jitterbug 552 fallback mechanism of aliased data */
1863 {
1864 UErrorCode err =U_ZERO_ERROR;
1865 UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err);
1866 UResourceBundle* resLocID = ures_getByKey(myResB, "LocaleID", NULL, &err);
1867 UResourceBundle* tResB;
1868 if(err != U_ZERO_ERROR){
1869 log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for LocaleID err=%s\n",u_errorName(err));
1870 return;
1871 }
1872 if(ures_getInt(resLocID, &err) != 0x814){
1873 log_data_err("Expected LocaleID=814, but got 0x%X\n", ures_getInt(resLocID, &err));
1874 }
1875 tResB = ures_getByKey(myResB, "DayNames", NULL, &err);
1876 if(err != U_USING_FALLBACK_WARNING){
1877 log_err("Expected U_USING_FALLBACK_ERROR when trying to test no_NO_NY aliased with nn_NO_NY for DayNames err=%s\n",u_errorName(err));
1878 }
1879 ures_close(resLocID);
1880 ures_close(myResB);
1881 ures_close(tResB);
1882
1883 }
1884
1885}
1886
1887static void printUChars(UChar* uchars){
1888 int16_t i=0;
1889 for(i=0; i<u_strlen(uchars); i++){
1890 log_err("%04X ", *(uchars+i));
1891 }
1892}
1893
1894static void TestResourceLevelAliasing(void) {
1895 UErrorCode status = U_ZERO_ERROR;
1896 UResourceBundle *aliasB = NULL, *tb = NULL;
1897 UResourceBundle *en = NULL, *uk = NULL, *testtypes = NULL;
1898 const char* testdatapath = NULL;
1899 const UChar *string = NULL, *sequence = NULL;
1900 const uint8_t *binary = NULL, *binSequence = NULL;
1901 int32_t strLen = 0, seqLen = 0, binLen = 0, binSeqLen = 0;
1902 testdatapath=loadTestData(&status);
1903 if(U_FAILURE(status))
1904 {
1905 log_err("Could not load testdata.dat %s \n",myErrorName(status));
1906 return;
1907 }
1908
1909 aliasB = ures_open(testdatapath, "testaliases", &status);
1910
1911 /* this should fail - circular alias */
1912 tb = ures_getByKey(aliasB, "aaa", tb, &status);
1913 if(status != U_TOO_MANY_ALIASES_ERROR) {
1914 log_err("Failed to detect circular alias\n");
1915 } else {
1916 status = U_ZERO_ERROR;
1917 }
1918 tb = ures_getByKey(aliasB, "aab", tb, &status);
1919 if(status != U_TOO_MANY_ALIASES_ERROR) {
1920 log_err("Failed to detect circular alias\n");
1921 } else {
1922 status = U_ZERO_ERROR;
1923 }
1924 if(U_FAILURE(status) ) {
1925 log_data_err("err loading tb resource\n");
1926 } else {
1927 /* testing aliasing to a non existing resource */
1928 tb = ures_getByKey(aliasB, "nonexisting", tb, &status);
1929 if(status != U_MISSING_RESOURCE_ERROR) {
1930 log_err("Managed to find an alias to non-existing resource\n");
1931 } else {
1932 status = U_ZERO_ERROR;
1933 }
1934
1935
1936 /* testing referencing/composed alias */
1937 uk = ures_findResource("uk/CollationElements/Sequence", uk, &status);
1938 if((uk == NULL) || U_FAILURE(status)) {
1939 log_err("Couldn't findResource('uk/collationelements/sequence') err %s\n", u_errorName(status));
1940 return;
1941 }
1942
1943 sequence = ures_getString(uk, &seqLen, &status);
1944
1945 tb = ures_getByKey(aliasB, "referencingalias", tb, &status);
1946 string = ures_getString(tb, &strLen, &status);
1947
1948 if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
1949 log_err("Referencing alias didn't get the right string\n");
1950 }
1951
1952 string = ures_getStringByKey(aliasB, "referencingalias", &strLen, &status);
1953 if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
1954 log_err("Referencing alias didn't get the right string\n");
1955 }
1956
1957 tb = ures_getByKey(aliasB, "CollationElements", tb, &status);
1958 tb = ures_getByKey(tb, "Sequence", tb, &status);
1959 string = ures_getString(tb, &strLen, &status);
1960
1961 if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
1962 log_err("Referencing alias didn't get the right string\n");
1963 }
1964
1965#if !UCONFIG_NO_COLLATION
1966
1967 /*
1968 * TODO for Vladimir: Make this test independent of UCONFIG_NO_xyz-switchable
1969 * modules like collation, so that it can be tested even when collation
1970 * data is not included in resource bundles.
1971 */
1972
1973 /* check whether the binary collation data is properly referenced by an alias */
1974 uk = ures_findResource("uk/CollationElements/%%CollationBin", uk, &status);
1975 binSequence = ures_getBinary(uk, &binSeqLen, &status);
1976
1977 tb = ures_getByKey(aliasB, "CollationElements", tb, &status);
1978 tb = ures_getByKey(tb, "%%CollationBin", tb, &status);
1979 binary = ures_getBinary(tb, &binLen, &status);
1980
1981 if(binSeqLen != binLen || uprv_memcmp(binSequence, binary, binSeqLen) != 0) {
1982 log_err("Referencing alias didn't get the right string\n");
1983 }
1984
1985 /* simple alias */
1986 testtypes = ures_open(testdatapath, "testtypes", &status);
1987 uk = ures_findSubResource(testtypes, "menu/file/open", uk, &status);
1988 sequence = ures_getString(uk, &seqLen, &status);
1989
1990 tb = ures_getByKey(aliasB, "simplealias", tb, &status);
1991 string = ures_getString(tb, &strLen, &status);
1992
1993 if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
1994 log_err("Referencing alias didn't get the right string\n");
1995 }
1996
1997 /* test indexed aliasing */
1998
1999 tb = ures_getByKey(aliasB, "zoneTests", tb, &status);
2000 tb = ures_getByKey(tb, "zoneAlias2", tb, &status);
2001 string = ures_getString(tb, &strLen, &status);
2002
2003 en = ures_findResource("en/zoneStrings/3/0", en, &status);
2004 sequence = ures_getString(en, &seqLen, &status);
2005
2006 if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
2007 log_err("Referencing alias didn't get the right string\n");
2008 }
2009
2010#endif
2011 }
2012 /* test getting aliased string by index */
2013 {
2014 const char* keys[] = {
2015 "KeyAlias0PST",
2016 "KeyAlias1PacificStandardTime",
2017 "KeyAlias2PDT",
2018 "KeyAlias3LosAngeles"
2019 };
2020
2021 const char* strings[] = {
2022 "PST",
2023 "Pacific Standard Time",
2024 "PDT",
2025 "Los Angeles",
2026 };
2027 UChar buffer[256];
2028 const UChar* result;
2029 int32_t bufferLen = 0, resultLen = 0;
2030 int32_t i = 0;
2031 const char *key = NULL;
2032 tb = ures_getByKey(aliasB, "testGetStringByKeyAliasing", tb, &status);
2033 if(U_FAILURE(status)) {
2034 log_err("Couldn't get testGetStringByKeyAliasing resource\n");
2035 }
2036 for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
2037 result = ures_getStringByKey(tb, keys[i], &resultLen, &status);
2038 bufferLen = u_unescape(strings[i], buffer, 256);
2039 if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
2040 log_err("Didn't get correct string while accesing alias table by key\n");
2041 }
2042 }
2043 for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
2044 result = ures_getStringByIndex(tb, i, &resultLen, &status);
2045 bufferLen = u_unescape(strings[i], buffer, 256);
2046 if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
2047 log_err("Didn't get correct string while accesing alias table by index\n");
2048 }
2049 }
2050 for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
2051 result = ures_getNextString(tb, &resultLen, &key, &status);
2052 bufferLen = u_unescape(strings[i], buffer, 256);
2053 if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
2054 log_err("Didn't get correct string while iterating over alias table\n");
2055 }
2056 }
2057 tb = ures_getByKey(aliasB, "testGetStringByIndexAliasing", tb, &status);
2058 if(U_FAILURE(status)) {
2059 log_err("Couldn't get testGetStringByIndexAliasing resource\n");
2060 }
2061 for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
2062 result = ures_getStringByIndex(tb, i, &resultLen, &status);
2063 bufferLen = u_unescape(strings[i], buffer, 256);
2064 if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
2065 log_err("Didn't get correct string while accesing alias by index in an array\n");
2066 }
2067 }
2068 for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
2069 result = ures_getNextString(tb, &resultLen, &key, &status);
2070 bufferLen = u_unescape(strings[i], buffer, 256);
2071 if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
2072 log_err("Didn't get correct string while iterating over aliases in an array\n");
2073 }
2074 }
2075 }
2076
2077 ures_close(aliasB);
2078 ures_close(tb);
2079 ures_close(en);
2080 ures_close(uk);
2081 ures_close(testtypes);
2082}
2083
2084static void TestDirectAccess(void) {
2085 UErrorCode status = U_ZERO_ERROR;
2086 UResourceBundle *t = NULL, *t2 = NULL;
2087 const char* key = NULL;
2088
2089 t = ures_findResource("en/zoneStrings/3/2", t, &status);
2090 if(U_FAILURE(status)) {
2091 log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
2092 status = U_ZERO_ERROR;
2093 } else {
2094 key = ures_getKey(t);
2095 if(key != NULL) {
2096 log_err("Got a strange key, expected NULL, got %s\n", key);
2097 }
2098 }
2099 t = ures_findResource("en/zoneStrings/3", t, &status);
2100 if(U_FAILURE(status)) {
2101 log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
2102 status = U_ZERO_ERROR;
2103 } else {
2104 key = ures_getKey(t);
2105 if(key != NULL) {
2106 log_err("Got a strange key, expected NULL, got %s\n", key);
2107 }
2108 }
2109
2110 t = ures_findResource("sh/CollationElements/Sequence", t, &status);
2111 if(U_FAILURE(status)) {
2112 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
2113 status = U_ZERO_ERROR;
2114 } else {
2115 key = ures_getKey(t);
2116 if(strcmp(key, "Sequence")!=0) {
2117 log_err("Got a strange key, expected 'Sequence', got %s\n", key);
2118 }
2119 }
2120
2121 t2 = ures_open(NULL, "sh", &status);
2122 if(U_FAILURE(status)) {
2123 log_err("Couldn't open 'sh' resource bundle, error %s\n", u_errorName(status));
2124 log_data_err("No 'sh', no test - you have bigger problems than testing direct access. You probably have no data! Aborting this test\n");
2125 }
2126
2127 if(U_SUCCESS(status)) {
2128 t = ures_findSubResource(t2, "CollationElements/Sequence", t, &status);
2129 if(U_FAILURE(status)) {
2130 log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
2131 status = U_ZERO_ERROR;
2132 } else {
2133 key = ures_getKey(t);
2134 if(strcmp(key, "Sequence")!=0) {
2135 log_err("Got a strange key, expected 'Sequence', got %s\n", key);
2136 }
2137 }
2138 }
2139
2140 ures_close(t);
2141 ures_close(t2);
2142}