]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/restsnew.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / restsnew.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f 3/********************************************************************
2ca993e8 4 * Copyright (c) 1997-2016, International Business Machines
46f4442e 5 * Corporation and others. All Rights Reserved.
b75a7d8f
A
6 ********************************************************************/
7
8#include "unicode/utypes.h"
9
2ca993e8 10#include "cmemory.h"
b75a7d8f
A
11#include "cstring.h"
12#include "unicode/unistr.h"
13#include "unicode/resbund.h"
14#include "restsnew.h"
15
16#include <stdlib.h>
17#include <time.h>
18#include <string.h>
19#include <limits.h>
20
21//***************************************************************************************
22
23static const UChar kErrorUChars[] = { 0x45, 0x52, 0x52, 0x4f, 0x52, 0 };
24static const int32_t kErrorLength = 5;
25static const int32_t kERROR_COUNT = -1234567;
26
27//***************************************************************************************
28
29enum E_Where
30{
31 e_Root,
32 e_te,
33 e_te_IN,
34 e_Where_count
35};
36
37//***************************************************************************************
38
46f4442e
A
39#define CONFIRM_EQ(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); errln(action + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of " + (expected)); }
40#define CONFIRM_GE(actual,expected) if ((actual)>=(expected)) { record_pass(); } else { record_fail(); errln(action + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x >= " + (expected)); }
41#define CONFIRM_NE(actual,expected) if ((expected)!=(actual)) { record_pass(); } else { record_fail(); errln(action + (UnicodeString)" returned " + (actual) + (UnicodeString)" instead of x != " + (expected)); }
b75a7d8f 42
46f4442e 43#define CONFIRM_UErrorCode(actual,expected) if ((expected)==(actual)) { record_pass(); } else { record_fail(); errln(action + (UnicodeString)" returned " + (UnicodeString)u_errorName(actual) + (UnicodeString)" instead of " + (UnicodeString)u_errorName(expected)); }
b75a7d8f
A
44
45//***************************************************************************************
46
47/**
48 * Convert an integer, positive or negative, to a character string radix 10.
49 */
50static char*
51itoa(int32_t i, char* buf)
52{
53 char* result = buf;
54
55 // Handle negative
56 if (i < 0)
57 {
58 *buf++ = '-';
59 i = -i;
60 }
61
62 // Output digits in reverse order
63 char* p = buf;
64 do
65 {
66 *p++ = (char)('0' + (i % 10));
67 i /= 10;
68 }
69 while (i);
70 *p-- = 0;
71
72 // Reverse the string
73 while (buf < p)
74 {
75 char c = *buf;
76 *buf++ = *p;
77 *p-- = c;
78 }
79
80 return result;
81}
82
83
84
85//***************************************************************************************
86
87// Array of our test objects
88
89static struct
90{
91 const char* name;
92 Locale *locale;
93 UErrorCode expected_constructor_status;
94 E_Where where;
95 UBool like[e_Where_count];
96 UBool inherits[e_Where_count];
97}
98param[] =
99{
100 // "te" means test
101 // "IN" means inherits
102 // "NE" or "ne" means "does not exist"
103
104 { "root", 0, U_ZERO_ERROR, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } },
105 { "te", 0, U_ZERO_ERROR, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
106 { "te_IN", 0, U_ZERO_ERROR, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
107 { "te_NE", 0, U_USING_FALLBACK_WARNING, e_te, { FALSE, TRUE, FALSE }, { TRUE, TRUE, FALSE } },
108 { "te_IN_NE", 0, U_USING_FALLBACK_WARNING, e_te_IN, { FALSE, FALSE, TRUE }, { TRUE, TRUE, TRUE } },
109 { "ne", 0, U_USING_DEFAULT_WARNING, e_Root, { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
110};
111
2ca993e8 112static int32_t bundles_count = UPRV_LENGTHOF(param);
b75a7d8f
A
113
114//***************************************************************************************
115
116/**
117 * Return a random unsigned long l where 0N <= l <= ULONG_MAX.
118 */
119
120static uint32_t
121randul()
122{
123 static UBool initialized = FALSE;
124 if (!initialized)
125 {
126 srand((unsigned)time(NULL));
127 initialized = TRUE;
128 }
129 // Assume rand has at least 12 bits of precision
130 uint32_t l = 0;
131 for (uint32_t i=0; i<sizeof(l); ++i)
132 ((char*)&l)[i] = (char)((rand() & 0x0FF0) >> 4);
133 return l;
134}
135
136/**
137 * Return a random double x where 0.0 <= x < 1.0.
138 */
139static double
140randd()
141{
142 return (double)(randul() / ULONG_MAX);
143}
144
145/**
146 * Return a random integer i where 0 <= i < n.
147 */
148static int32_t randi(int32_t n)
149{
150 return (int32_t)(randd() * n);
151}
152
153//***************************************************************************************
154
155/*
156 Don't use more than one of these at a time because of the Locale names
157*/
158NewResourceBundleTest::NewResourceBundleTest()
159: pass(0),
374ca955 160 fail(0)
b75a7d8f
A
161{
162 if (param[5].locale == NULL) {
163 param[0].locale = new Locale("root");
164 param[1].locale = new Locale("te");
165 param[2].locale = new Locale("te", "IN");
166 param[3].locale = new Locale("te", "NE");
167 param[4].locale = new Locale("te", "IN", "NE");
168 param[5].locale = new Locale("ne");
169 }
170}
171
172NewResourceBundleTest::~NewResourceBundleTest()
173{
174 if (param[5].locale) {
175 int idx;
2ca993e8 176 for (idx = 0; idx < UPRV_LENGTHOF(param); idx++) {
b75a7d8f
A
177 delete param[idx].locale;
178 param[idx].locale = NULL;
179 }
180 }
181}
182
183void NewResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
184{
185 if (exec) logln("TestSuite ResourceBundleTest: ");
186 switch (index) {
729e4ab9 187#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
b75a7d8f
A
188 case 0: name = "TestResourceBundles"; if (exec) TestResourceBundles(); break;
189 case 1: name = "TestConstruction"; if (exec) TestConstruction(); break;
190 case 2: name = "TestIteration"; if (exec) TestIteration(); break;
191 case 3: name = "TestOtherAPI"; if(exec) TestOtherAPI(); break;
192 case 4: name = "TestNewTypes"; if(exec) TestNewTypes(); break;
729e4ab9
A
193#else
194 case 0: case 1: case 2: case 3: case 4: name = "skip"; break;
195#endif
196
73c04bcf 197 case 5: name = "TestGetByFallback"; if(exec) TestGetByFallback(); break;
3d1f044b
A
198 case 6: name = "TestFilter"; if(exec) TestFilter(); break;
199
b75a7d8f
A
200 default: name = ""; break; //needed to end loop
201 }
202}
203
204//***************************************************************************************
205
206void
207NewResourceBundleTest::TestResourceBundles()
208{
46f4442e
A
209 UErrorCode status = U_ZERO_ERROR;
210 loadTestData(status);
211 if(U_FAILURE(status))
212 {
729e4ab9 213 dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
46f4442e
A
214 return;
215 }
216
217 /* Make sure that users using te_IN for the default locale don't get test failures. */
218 Locale originalDefault;
219 if (Locale::getDefault() == Locale("te_IN")) {
220 Locale::setDefault(Locale("en_US"), status);
221 }
222
b75a7d8f
A
223 testTag("only_in_Root", TRUE, FALSE, FALSE);
224 testTag("only_in_te", FALSE, TRUE, FALSE);
225 testTag("only_in_te_IN", FALSE, FALSE, TRUE);
226 testTag("in_Root_te", TRUE, TRUE, FALSE);
227 testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE);
228 testTag("in_Root_te_IN", TRUE, FALSE, TRUE);
229 testTag("in_te_te_IN", FALSE, TRUE, TRUE);
230 testTag("nonexistent", FALSE, FALSE, FALSE);
231 logln("Passed: %d\nFailed: %d", pass, fail);
46f4442e
A
232
233 /* Restore the default locale for the other tests. */
234 Locale::setDefault(originalDefault, status);
b75a7d8f
A
235}
236
237void
238NewResourceBundleTest::TestConstruction()
239{
46f4442e
A
240 UErrorCode err = U_ZERO_ERROR;
241 Locale locale("te", "IN");
242
243 const char* testdatapath;
244 testdatapath=loadTestData(err);
245 if(U_FAILURE(err))
b75a7d8f 246 {
729e4ab9 247 dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
46f4442e
A
248 return;
249 }
b75a7d8f 250
46f4442e
A
251 /* Make sure that users using te_IN for the default locale don't get test failures. */
252 Locale originalDefault;
253 if (Locale::getDefault() == Locale("te_IN")) {
254 Locale::setDefault(Locale("en_US"), err);
255 }
b75a7d8f 256
46f4442e
A
257 ResourceBundle test1((UnicodeString)testdatapath, err);
258 ResourceBundle test2(testdatapath, locale, err);
259
260 UnicodeString result1;
261 UnicodeString result2;
b75a7d8f 262
46f4442e
A
263 result1 = test1.getStringEx("string_in_Root_te_te_IN", err);
264 result2 = test2.getStringEx("string_in_Root_te_te_IN", err);
265 if (U_FAILURE(err)) {
266 errln("Something threw an error in TestConstruction()");
267 return;
268 }
b75a7d8f 269
46f4442e
A
270 logln("for string_in_Root_te_te_IN, root.txt had " + result1);
271 logln("for string_in_Root_te_te_IN, te_IN.txt had " + result2);
b75a7d8f 272
46f4442e
A
273 if (result1 != "ROOT" || result2 != "TE_IN") {
274 errln("Construction test failed; run verbose for more information");
275 }
b75a7d8f 276
46f4442e
A
277 const char* version1;
278 const char* version2;
b75a7d8f 279
46f4442e
A
280 version1 = test1.getVersionNumber();
281 version2 = test2.getVersionNumber();
b75a7d8f 282
46f4442e
A
283 char *versionID1 = new char[1 + strlen(U_ICU_VERSION) + strlen(version1)]; // + 1 for zero byte
284 char *versionID2 = new char[1 + strlen(U_ICU_VERSION) + strlen(version2)]; // + 1 for zero byte
b75a7d8f 285
46f4442e 286 strcpy(versionID1, "44.0"); // hardcoded, please change if the default.txt file or ResourceBundle::kVersionSeparater is changed.
b75a7d8f 287
46f4442e
A
288 strcpy(versionID2, "55.0"); // hardcoded, please change if the te_IN.txt file or ResourceBundle::kVersionSeparater is changed.
289
290 logln(UnicodeString("getVersionNumber on default.txt returned ") + version1 + UnicodeString(" Expect: " ) + versionID1);
291 logln(UnicodeString("getVersionNumber on te_IN.txt returned ") + version2 + UnicodeString(" Expect: " ) + versionID2);
292
293 if (strcmp(version1, versionID1) != 0) {
294 errln("getVersionNumber(version1) failed. %s != %s", version1, versionID1);
b75a7d8f 295 }
46f4442e
A
296 if (strcmp(version2, versionID2) != 0) {
297 errln("getVersionNumber(version2) failed. %s != %s", version2, versionID2);
298 }
299 delete[] versionID1;
300 delete[] versionID2;
301
302 /* Restore the default locale for the other tests. */
303 Locale::setDefault(originalDefault, err);
b75a7d8f
A
304}
305
306void
307NewResourceBundleTest::TestIteration()
308{
309 UErrorCode err = U_ZERO_ERROR;
310 const char* testdatapath;
311 const char* data[]={
312 "string_in_Root_te_te_IN", "1",
313 "array_in_Root_te_te_IN", "5",
314 "array_2d_in_Root_te_te_IN", "4",
315 };
316
317 Locale *locale=new Locale("te_IN");
318
319 testdatapath=loadTestData(err);
320 if(U_FAILURE(err))
321 {
729e4ab9 322 dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
b75a7d8f
A
323 return;
324 }
325
326 ResourceBundle test1(testdatapath, *locale, err);
327 if(U_FAILURE(err)){
328 errln("Construction failed");
329 }
330 uint32_t i;
331 int32_t count, row=0, col=0;
332 char buf[5];
333 UnicodeString expected;
334 UnicodeString element("TE_IN");
335 UnicodeString action;
336
337
2ca993e8 338 for(i=0; i<UPRV_LENGTHOF(data); i=i+2){
b75a7d8f
A
339 action = "te_IN";
340 action +=".get(";
341 action += data[i];
342 action +=", err)";
343 err=U_ZERO_ERROR;
344 ResourceBundle bundle = test1.get(data[i], err);
345 if(!U_FAILURE(err)){
346 action = "te_IN";
347 action +=".getKey()";
348
349 CONFIRM_EQ((UnicodeString)bundle.getKey(), (UnicodeString)data[i]);
350
351 count=0;
352 row=0;
353 while(bundle.hasNext()){
354 action = data[i];
355 action +=".getNextString(err)";
356 row=count;
357 UnicodeString got=bundle.getNextString(err);
358 if(U_SUCCESS(err)){
359 expected=element;
360 if(bundle.getSize() > 1){
361 CONFIRM_EQ(bundle.getType(), URES_ARRAY);
362 expected+=itoa(row, buf);
363 ResourceBundle rowbundle=bundle.get(row, err);
364 if(!U_FAILURE(err) && rowbundle.getSize()>1){
365 col=0;
366 while(rowbundle.hasNext()){
367 expected=element;
368 got=rowbundle.getNextString(err);
369 if(!U_FAILURE(err)){
370 expected+=itoa(row, buf);
371 expected+=itoa(col, buf);
372 col++;
373 CONFIRM_EQ(got, expected);
374 }
375 }
376 CONFIRM_EQ(col, rowbundle.getSize());
377 }
378 }
379 else{
380 CONFIRM_EQ(bundle.getType(), (int32_t)URES_STRING);
381 }
382 }
383 CONFIRM_EQ(got, expected);
384 count++;
385 }
386 action = data[i];
387 action +=".getSize()";
388 CONFIRM_EQ(bundle.getSize(), count);
389 CONFIRM_EQ(count, atoi(data[i+1]));
390 //after reaching the end
391 err=U_ZERO_ERROR;
392 ResourceBundle errbundle=bundle.getNext(err);
393 action = "After reaching the end of the Iterator:- ";
394 action +=data[i];
395 action +=".getNext()";
396 CONFIRM_NE(err, (int32_t)U_ZERO_ERROR);
397 CONFIRM_EQ(u_errorName(err), u_errorName(U_INDEX_OUTOFBOUNDS_ERROR));
398 //reset the iterator
399 err = U_ZERO_ERROR;
400 bundle.resetIterator();
401 /* The following code is causing a crash
402 ****CRASH******
403 */
404
405 bundle.getNext(err);
406 if(U_FAILURE(err)){
407 errln("ERROR: getNext() throw an error");
46f4442e 408 }
b75a7d8f 409 }
b75a7d8f
A
410 }
411 delete locale;
412}
413
374ca955
A
414// TODO: add operator== and != to ResourceBundle
415static UBool
416equalRB(ResourceBundle &a, ResourceBundle &b) {
417 UResType type;
418 UErrorCode status;
419
420 type=a.getType();
421 status=U_ZERO_ERROR;
422 return
423 type==b.getType() &&
424 a.getLocale()==b.getLocale() &&
425 0==strcmp(a.getName(), b.getName()) &&
426 type==URES_STRING ?
427 a.getString(status)==b.getString(status) :
428 type==URES_INT ?
429 a.getInt(status)==b.getInt(status) :
430 TRUE;
431}
432
b75a7d8f
A
433void
434NewResourceBundleTest::TestOtherAPI(){
435 UErrorCode err = U_ZERO_ERROR;
46f4442e 436 const char* testdatapath=loadTestData(err);
b75a7d8f
A
437 UnicodeString tDataPathUS = UnicodeString(testdatapath, "");
438
439 if(U_FAILURE(err))
440 {
729e4ab9 441 dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err)));
b75a7d8f
A
442 return;
443 }
46f4442e
A
444
445 /* Make sure that users using te_IN for the default locale don't get test failures. */
446 Locale originalDefault;
447 if (Locale::getDefault() == Locale("te_IN")) {
448 Locale::setDefault(Locale("en_US"), err);
449 }
450
b75a7d8f
A
451 Locale *locale=new Locale("te_IN");
452
453 ResourceBundle test0(tDataPathUS, *locale, err);
454 if(U_FAILURE(err)){
455 errln("Construction failed");
456 return;
457 }
458
459 ResourceBundle test1(testdatapath, *locale, err);
460 if(U_FAILURE(err)){
461 errln("Construction failed");
462 return;
463 }
464
465 logln("Testing getLocale()\n");
466 if(strcmp(test1.getLocale().getName(), locale->getName()) !=0 ){
467 errln("FAIL: ResourceBundle::getLocale() failed\n");
468 }
469
470 delete locale;
471
472 logln("Testing ResourceBundle(UErrorCode)\n");
473 ResourceBundle defaultresource(err);
46f4442e 474 ResourceBundle explicitdefaultresource(NULL, Locale::getDefault(), err);
b75a7d8f 475 if(U_FAILURE(err)){
729e4ab9 476 errcheckln(err, "Construction of default resourcebundle failed - %s", u_errorName(err));
b75a7d8f
A
477 return;
478 }
46f4442e
A
479 // You can't compare the default locale to the resolved locale in the
480 // resource bundle due to aliasing, keywords in the default locale
481 // or the chance that the machine running these tests is using a locale
482 // that isn't available in ICU.
483 if(strcmp(defaultresource.getLocale().getName(), explicitdefaultresource.getLocale().getName()) != 0){
484 errln("Construction of default resourcebundle didn't take the defaultlocale. Expected %s Got %s err=%s\n",
485 explicitdefaultresource.getLocale().getName(), defaultresource.getLocale().getName(), u_errorName(err));
b75a7d8f
A
486 }
487
488
489 ResourceBundle copyRes(defaultresource);
490 if(strcmp(copyRes.getName(), defaultresource.getName() ) !=0 ||
491 strcmp(test1.getName(), defaultresource.getName() ) ==0 ||
492 strcmp(copyRes.getLocale().getName(), defaultresource.getLocale().getName() ) !=0 ||
46f4442e
A
493 strcmp(test1.getLocale().getName(), defaultresource.getLocale().getName() ) ==0 )
494 {
b75a7d8f
A
495 errln("copy construction failed\n");
496 }
497
46f4442e 498 ResourceBundle defaultSub = defaultresource.get((int32_t)0, err);
b75a7d8f
A
499 ResourceBundle defSubCopy(defaultSub);
500 if(strcmp(defSubCopy.getName(), defaultSub.getName() ) !=0 ||
501 strcmp(defSubCopy.getLocale().getName(), defaultSub.getLocale().getName() ) !=0 ){
502 errln("copy construction for subresource failed\n");
503 }
504
374ca955 505 ResourceBundle *p;
b75a7d8f 506
374ca955
A
507 p = defaultresource.clone();
508 if(p == &defaultresource || !equalRB(*p, defaultresource)) {
509 errln("ResourceBundle.clone() failed");
510 }
511 delete p;
512
513 p = defaultSub.clone();
514 if(p == &defaultSub || !equalRB(*p, defaultSub)) {
515 errln("2nd ResourceBundle.clone() failed");
516 }
517 delete p;
b75a7d8f
A
518
519 UVersionInfo ver;
520 copyRes.getVersion(ver);
521
522 logln("Version returned: [%d.%d.%d.%d]\n", ver[0], ver[1], ver[2], ver[3]);
523
524 logln("Testing C like UnicodeString APIs\n");
525
526 UResourceBundle *testCAPI = NULL, *bundle = NULL, *rowbundle = NULL, *temp = NULL;
527 err = U_ZERO_ERROR;
528 const char* data[]={
529 "string_in_Root_te_te_IN", "1",
530 "array_in_Root_te_te_IN", "5",
531 "array_2d_in_Root_te_te_IN", "4",
532 };
533
534
b75a7d8f
A
535 testCAPI = ures_open(testdatapath, "te_IN", &err);
536
537 if(U_SUCCESS(err)) {
46f4442e
A
538 // Do the testing
539 // first iteration
b75a7d8f 540
46f4442e
A
541 uint32_t i;
542 int32_t count, row=0, col=0;
543 char buf[5];
544 UnicodeString expected;
545 UnicodeString element("TE_IN");
546 UnicodeString action;
b75a7d8f
A
547
548
2ca993e8 549 for(i=0; i<UPRV_LENGTHOF(data); i=i+2){
46f4442e
A
550 action = "te_IN";
551 action +=".get(";
552 action += data[i];
553 action +=", err)";
554 err=U_ZERO_ERROR;
555 bundle = ures_getByKey(testCAPI, data[i], bundle, &err);
556 if(!U_FAILURE(err)){
557 const char* key = NULL;
558 action = "te_IN";
559 action +=".getKey()";
560
561 CONFIRM_EQ((UnicodeString)ures_getKey(bundle), (UnicodeString)data[i]);
562
563 count=0;
564 row=0;
565 while(ures_hasNext(bundle)){
566 action = data[i];
567 action +=".getNextString(err)";
568 row=count;
569 UnicodeString got=ures_getNextUnicodeString(bundle, &key, &err);
570 if(U_SUCCESS(err)){
571 expected=element;
572 if(ures_getSize(bundle) > 1){
573 CONFIRM_EQ(ures_getType(bundle), URES_ARRAY);
574 expected+=itoa(row, buf);
575 rowbundle=ures_getByIndex(bundle, row, rowbundle, &err);
576 if(!U_FAILURE(err) && ures_getSize(rowbundle)>1){
577 col=0;
578 while(ures_hasNext(rowbundle)){
579 expected=element;
580 got=ures_getNextUnicodeString(rowbundle, &key, &err);
581 temp = ures_getByIndex(rowbundle, col, temp, &err);
582 UnicodeString bla = ures_getUnicodeString(temp, &err);
583 UnicodeString bla2 = ures_getUnicodeStringByIndex(rowbundle, col, &err);
584 if(!U_FAILURE(err)){
585 expected+=itoa(row, buf);
586 expected+=itoa(col, buf);
587 col++;
588 CONFIRM_EQ(got, expected);
589 CONFIRM_EQ(bla, expected);
590 CONFIRM_EQ(bla2, expected);
591 }
592 }
593 CONFIRM_EQ(col, ures_getSize(rowbundle));
594 }
595 }
596 else{
597 CONFIRM_EQ(ures_getType(bundle), (int32_t)URES_STRING);
598 }
599 }
600 CONFIRM_EQ(got, expected);
601 count++;
602 }
603 }
604 }
2ca993e8
A
605
606 // Check that ures_getUnicodeString() & variants return a bogus string if failure.
607 // Same relevant code path whether the failure code is passed in
608 // or comes from a lookup error.
609 UErrorCode failure = U_INTERNAL_PROGRAM_ERROR;
610 assertTrue("ures_getUnicodeString(failure).isBogus()",
611 ures_getUnicodeString(testCAPI, &failure).isBogus());
612 assertTrue("ures_getNextUnicodeString(failure).isBogus()",
613 ures_getNextUnicodeString(testCAPI, NULL, &failure).isBogus());
614 assertTrue("ures_getUnicodeStringByIndex(failure).isBogus()",
615 ures_getUnicodeStringByIndex(testCAPI, 999, &failure).isBogus());
616 assertTrue("ures_getUnicodeStringByKey(failure).isBogus()",
617 ures_getUnicodeStringByKey(testCAPI, "bogus key", &failure).isBogus());
618
46f4442e
A
619 ures_close(temp);
620 ures_close(rowbundle);
621 ures_close(bundle);
622 ures_close(testCAPI);
623 } else {
624 errln("failed to open a resource bundle\n");
625 }
b75a7d8f 626
46f4442e
A
627 /* Restore the default locale for the other tests. */
628 Locale::setDefault(originalDefault, err);
b75a7d8f
A
629}
630
631
632
633
b75a7d8f
A
634//***************************************************************************************
635
636UBool
637NewResourceBundleTest::testTag(const char* frag,
638 UBool in_Root,
639 UBool in_te,
640 UBool in_te_IN)
641{
642 int32_t failOrig = fail;
643
644 // Make array from input params
645
646 UBool is_in[] = { in_Root, in_te, in_te_IN };
647
648 const char* NAME[] = { "ROOT", "TE", "TE_IN" };
649
650 // Now try to load the desired items
651
652 char tag[100];
653 UnicodeString action;
654
655 int32_t i,j,row,col, actual_bundle;
656 int32_t index;
657 const char* testdatapath;
658
659 UErrorCode status = U_ZERO_ERROR;
660 testdatapath=loadTestData(status);
661 if(U_FAILURE(status))
662 {
729e4ab9 663 dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status)));
b75a7d8f
A
664 return FALSE;
665 }
666
667 for (i=0; i<bundles_count; ++i)
668 {
669 action = "Constructor for ";
670 action += param[i].name;
671
672 status = U_ZERO_ERROR;
673 ResourceBundle theBundle( testdatapath, *param[i].locale, status);
674 //ResourceBundle theBundle( "c:\\icu\\icu\\source\\test\\testdata\\testdata", *param[i].locale, status);
675 CONFIRM_UErrorCode(status,param[i].expected_constructor_status);
676
677 if(i == 5)
678 actual_bundle = 0; /* ne -> default */
679 else if(i == 3)
680 actual_bundle = 1; /* te_NE -> te */
681 else if(i == 4)
682 actual_bundle = 2; /* te_IN_NE -> te_IN */
683 else
684 actual_bundle = i;
685
686
687 UErrorCode expected_resource_status = U_MISSING_RESOURCE_ERROR;
688 for (j=e_te_IN; j>=e_Root; --j)
689 {
690 if (is_in[j] && param[i].inherits[j])
691 {
692 if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
693 expected_resource_status = U_ZERO_ERROR;
694 else if(j == 0)
695 expected_resource_status = U_USING_DEFAULT_WARNING;
696 else
697 expected_resource_status = U_USING_FALLBACK_WARNING;
698
699 break;
700 }
701 }
702
703 UErrorCode expected_status;
704
705 UnicodeString base;
706 for (j=param[i].where; j>=0; --j)
707 {
708 if (is_in[j])
709 {
710 base = NAME[j];
711 break;
712 }
713 }
714
715 //--------------------------------------------------------------------------
716 // string
717
718 uprv_strcpy(tag, "string_");
719 uprv_strcat(tag, frag);
720
721 action = param[i].name;
722 action += ".getStringEx(";
723 action += tag;
724 action += ")";
725
726
727 status = U_ZERO_ERROR;
728 UnicodeString string = theBundle.getStringEx(tag, status);
729 if(U_FAILURE(status)) {
730 string.setTo(TRUE, kErrorUChars, kErrorLength);
731 }
732
733 CONFIRM_UErrorCode(status, expected_resource_status);
734
735 UnicodeString expected_string(kErrorUChars);
736 if (U_SUCCESS(status)) {
737 expected_string = base;
738 }
739
740 CONFIRM_EQ(string, expected_string);
741
742 //--------------------------------------------------------------------------
743 // array ResourceBundle using the key
744
745 uprv_strcpy(tag, "array_");
746 uprv_strcat(tag, frag);
747
748 action = param[i].name;
749 action += ".get(";
750 action += tag;
751 action += ")";
752
753 int32_t count = kERROR_COUNT;
754 status = U_ZERO_ERROR;
755 ResourceBundle array = theBundle.get(tag, status);
756 CONFIRM_UErrorCode(status,expected_resource_status);
757
758
759 if (U_SUCCESS(status))
760 {
761 //confirm the resource type is an array
762 UResType bundleType=array.getType();
763 CONFIRM_EQ(bundleType, URES_ARRAY);
764
765 count=array.getSize();
766 CONFIRM_GE(count,1);
767
768 for (j=0; j<count; ++j)
769 {
770 char buf[32];
771 expected_string = base;
772 expected_string += itoa(j,buf);
773 CONFIRM_EQ(array.getNextString(status),expected_string);
774 }
775
776 }
777 else
778 {
779 CONFIRM_EQ(count,kERROR_COUNT);
780 // CONFIRM_EQ((int32_t)(unsigned long)array,(int32_t)0);
781 count = 0;
782 }
783
784 //--------------------------------------------------------------------------
785 // arrayItem ResourceBundle using the index
786
787
788 for (j=0; j<100; ++j)
789 {
790 index = count ? (randi(count * 3) - count) : (randi(200) - 100);
791 status = U_ZERO_ERROR;
792 string = kErrorUChars;
793 ResourceBundle array = theBundle.get(tag, status);
794 if(!U_FAILURE(status)){
795 UnicodeString t = array.getStringEx(index, status);
796 if(!U_FAILURE(status)) {
797 string=t;
798 }
799 }
800
801 expected_status = (index >= 0 && index < count) ? expected_resource_status : U_MISSING_RESOURCE_ERROR;
802 CONFIRM_UErrorCode(status,expected_status);
803
804 if (U_SUCCESS(status)){
805 char buf[32];
806 expected_string = base;
807 expected_string += itoa(index,buf);
808 } else {
809 expected_string = kErrorUChars;
810 }
811 CONFIRM_EQ(string,expected_string);
812
813 }
814
815 //--------------------------------------------------------------------------
816 // 2dArray
817
818 uprv_strcpy(tag, "array_2d_");
819 uprv_strcat(tag, frag);
820
821 action = param[i].name;
822 action += ".get(";
823 action += tag;
824 action += ")";
825
826
827 int32_t row_count = kERROR_COUNT, column_count = kERROR_COUNT;
828 status = U_ZERO_ERROR;
829 ResourceBundle array2d=theBundle.get(tag, status);
830
831 //const UnicodeString** array2d = theBundle.get2dArray(tag, row_count, column_count, status);
832 CONFIRM_UErrorCode(status,expected_resource_status);
833
834 if (U_SUCCESS(status))
835 {
836 //confirm the resource type is an 2darray
837 UResType bundleType=array2d.getType();
838 CONFIRM_EQ(bundleType, URES_ARRAY);
839
840 row_count=array2d.getSize();
841 CONFIRM_GE(row_count,1);
842
843 for(row=0; row<row_count; ++row){
844 ResourceBundle tablerow=array2d.get(row, status);
845 CONFIRM_UErrorCode(status, expected_resource_status);
846 if(U_SUCCESS(status)){
847 //confirm the resourcetype of each table row is an array
848 UResType rowType=tablerow.getType();
849 CONFIRM_EQ(rowType, URES_ARRAY);
850
851 column_count=tablerow.getSize();
852 CONFIRM_GE(column_count,1);
853
854 for (col=0; j<column_count; ++j) {
855 char buf[32];
856 expected_string = base;
857 expected_string += itoa(row,buf);
858 expected_string += itoa(col,buf);
859 CONFIRM_EQ(tablerow.getNextString(status),expected_string);
860 }
861 }
862 }
863 }else{
864 CONFIRM_EQ(row_count,kERROR_COUNT);
865 CONFIRM_EQ(column_count,kERROR_COUNT);
866 row_count=column_count=0;
867 }
868
869
870
871
872 //--------------------------------------------------------------------------
873 // 2dArrayItem
874 for (j=0; j<200; ++j)
875 {
876 row = row_count ? (randi(row_count * 3) - row_count) : (randi(200) - 100);
877 col = column_count ? (randi(column_count * 3) - column_count) : (randi(200) - 100);
878 status = U_ZERO_ERROR;
879 string = kErrorUChars;
880 ResourceBundle array2d=theBundle.get(tag, status);
881 if(U_SUCCESS(status)){
882 ResourceBundle tablerow=array2d.get(row, status);
883 if(U_SUCCESS(status)) {
884 UnicodeString t=tablerow.getStringEx(col, status);
885 if(U_SUCCESS(status)){
886 string=t;
887 }
888 }
889 }
890 expected_status = (row >= 0 && row < row_count && col >= 0 && col < column_count) ?
891 expected_resource_status: U_MISSING_RESOURCE_ERROR;
892 CONFIRM_UErrorCode(status,expected_status);
893
894 if (U_SUCCESS(status)){
895 char buf[32];
896 expected_string = base;
897 expected_string += itoa(row,buf);
898 expected_string += itoa(col,buf);
899 } else {
900 expected_string = kErrorUChars;
901 }
902 CONFIRM_EQ(string,expected_string);
903
904 }
905
906 //--------------------------------------------------------------------------
907 // taggedArray
908
909 uprv_strcpy(tag, "tagged_array_");
910 uprv_strcat(tag, frag);
911
912 action = param[i].name;
913 action += ".get(";
914 action += tag;
915 action += ")";
916
917 int32_t tag_count;
918 status = U_ZERO_ERROR;
919
920 ResourceBundle tags=theBundle.get(tag, status);
921 CONFIRM_UErrorCode(status, expected_resource_status);
922
923 if (U_SUCCESS(status)) {
924 UResType bundleType=tags.getType();
925 CONFIRM_EQ(bundleType, URES_TABLE);
926
927 tag_count=tags.getSize();
928 CONFIRM_GE((int32_t)tag_count, (int32_t)0);
929
930 for(index=0; index <tag_count; index++){
931 ResourceBundle tagelement=tags.get(index, status);
932 UnicodeString key=tagelement.getKey();
933 UnicodeString value=tagelement.getNextString(status);
934 logln("tag = " + key + ", value = " + value );
935 if(key.startsWith("tag") && value.startsWith(base)){
936 record_pass();
937 }else{
938 record_fail();
939 }
940
941 }
942
943 for(index=0; index <tag_count; index++){
944 ResourceBundle tagelement=tags.get(index, status);
945 const char *tkey=NULL;
946 UnicodeString value=tagelement.getNextString(&tkey, status);
947 UnicodeString key(tkey);
948 logln("tag = " + key + ", value = " + value );
949 if(value.startsWith(base)){
950 record_pass();
951 }else{
952 record_fail();
953 }
954 }
955
956 }else{
957 tag_count=0;
958 }
959
960
961
962
963 //--------------------------------------------------------------------------
964 // taggedArrayItem
965
966 action = param[i].name;
967 action += ".get(";
968 action += tag;
969 action += ")";
970
971 count = 0;
972 for (index=-20; index<20; ++index)
973 {
974 char buf[32];
975 status = U_ZERO_ERROR;
976 string = kErrorUChars;
977 char item_tag[8];
978 uprv_strcpy(item_tag, "tag");
979 uprv_strcat(item_tag, itoa(index,buf));
980 ResourceBundle tags=theBundle.get(tag, status);
981 if(U_SUCCESS(status)){
982 ResourceBundle tagelement=tags.get(item_tag, status);
983 if(!U_FAILURE(status)){
984 UResType elementType=tagelement.getType();
985 CONFIRM_EQ(elementType, (int32_t)URES_STRING);
986 const char* key=tagelement.getKey();
987 CONFIRM_EQ((UnicodeString)key, (UnicodeString)item_tag);
988 UnicodeString t=tagelement.getString(status);
989 if(!U_FAILURE(status)){
990 string=t;
991 }
992 }
993 if (index < 0) {
994 CONFIRM_UErrorCode(status,U_MISSING_RESOURCE_ERROR);
995 }
996 else{
997 if (status != U_MISSING_RESOURCE_ERROR) {
998 count++;
999 expected_string = base;
1000 expected_string += buf;
1001 CONFIRM_EQ(string,expected_string);
1002 }
1003 }
1004 }
1005
1006 }
1007 CONFIRM_EQ(count, tag_count);
1008
1009 }
1010 return (UBool)(failOrig == fail);
1011}
1012
1013void
1014NewResourceBundleTest::record_pass()
1015{
1016 ++pass;
1017}
1018void
1019NewResourceBundleTest::record_fail()
1020{
1021 err();
1022 ++fail;
1023}
1024
1025
1026void
1027NewResourceBundleTest::TestNewTypes() {
1028 char action[256];
1029 const char* testdatapath;
1030 UErrorCode status = U_ZERO_ERROR;
1031 uint8_t *binResult = NULL;
1032 int32_t len = 0;
1033 int32_t i = 0;
1034 int32_t intResult = 0;
1035 uint32_t uintResult = 0;
1036 UChar expected[] = { 'a','b','c','\0','d','e','f' };
1037 const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
1038 UChar uExpect[200];
1039
1040 testdatapath=loadTestData(status);
1041
1042 if(U_FAILURE(status))
1043 {
729e4ab9 1044 dataerrln("Could not load testdata.dat %s \n",u_errorName(status));
b75a7d8f
A
1045 return;
1046 }
1047
1048 ResourceBundle theBundle(testdatapath, "testtypes", status);
374ca955 1049 ResourceBundle bundle(testdatapath, Locale("te_IN"),status);
b75a7d8f
A
1050
1051 UnicodeString emptyStr = theBundle.getStringEx("emptystring", status);
57a6839d 1052 if(emptyStr.length() != 0) {
b75a7d8f
A
1053 logln("Empty string returned invalid value\n");
1054 }
1055
1056 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1057
1058 /* This test reads the string "abc\u0000def" from the bundle */
1059 /* if everything is working correctly, the size of this string */
1060 /* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
1061
1062 strcpy(action, "getting and testing of string with embeded zero");
1063 ResourceBundle res = theBundle.get("zerotest", status);
1064 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1065 CONFIRM_EQ(res.getType(), URES_STRING);
1066 UnicodeString zeroString=res.getString(status);
374ca955 1067 len = zeroString.length();
b75a7d8f
A
1068 if(U_SUCCESS(status)){
1069 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1070 CONFIRM_EQ(len, 7);
1071 CONFIRM_NE(len, 3);
1072 }
1073 for(i=0;i<len;i++){
1074 if(zeroString[i]!= expected[i]){
1075 logln("Output didnot match Expected: \\u%4X Got: \\u%4X", expected[i], zeroString[i]);
1076 }
1077 }
1078
1079 strcpy(action, "getting and testing of binary type");
1080 res = theBundle.get("binarytest", status);
1081 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1082 CONFIRM_EQ(res.getType(), URES_BINARY);
1083 binResult=(uint8_t*)res.getBinary(len, status);
1084 if(U_SUCCESS(status)){
1085 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1086 CONFIRM_EQ(len, 15);
1087 for(i = 0; i<15; i++) {
1088 CONFIRM_EQ(binResult[i], i);
1089 }
1090 }
1091
1092 strcpy(action, "getting and testing of imported binary type");
1093 res = theBundle.get("importtest",status);
1094 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1095 CONFIRM_EQ(res.getType(), URES_BINARY);
1096 binResult=(uint8_t*)res.getBinary(len, status);
1097 if(U_SUCCESS(status)){
1098 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1099 CONFIRM_EQ(len, 15);
1100 for(i = 0; i<15; i++) {
1101 CONFIRM_EQ(binResult[i], i);
1102 }
1103 }
1104
1105 strcpy(action, "getting and testing of integer types");
1106 res = theBundle.get("one", status);
1107 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1108 CONFIRM_EQ(res.getType(), URES_INT);
1109 intResult=res.getInt(status);
1110 uintResult = res.getUInt(status);
1111 if(U_SUCCESS(status)){
1112 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1113 CONFIRM_EQ(uintResult, (uint32_t)intResult);
1114 CONFIRM_EQ(intResult, 1);
1115 }
1116
1117 strcpy(action, "getting minusone");
1118 res = theBundle.get((const char*)"minusone", status);
1119 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1120 CONFIRM_EQ(res.getType(), URES_INT);
1121 intResult=res.getInt(status);
1122 uintResult = res.getUInt(status);
1123 if(U_SUCCESS(status)){
1124 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1125 CONFIRM_EQ(uintResult, 0x0FFFFFFF); /* a 28 bit integer */
1126 CONFIRM_EQ(intResult, -1);
1127 CONFIRM_NE(uintResult, (uint32_t)intResult);
1128 }
1129
1130 strcpy(action, "getting plusone");
1131 res = theBundle.get("plusone",status);
1132 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1133 CONFIRM_EQ(res.getType(), URES_INT);
1134 intResult=res.getInt(status);
1135 uintResult = res.getUInt(status);
1136 if(U_SUCCESS(status)){
1137 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1138 CONFIRM_EQ(uintResult, (uint32_t)intResult);
1139 CONFIRM_EQ(intResult, 1);
1140 }
1141
1142 res = theBundle.get("onehundredtwentythree",status);
1143 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1144 CONFIRM_EQ(res.getType(), URES_INT);
1145 intResult=res.getInt(status);
1146 if(U_SUCCESS(status)){
1147 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1148 CONFIRM_EQ(intResult, 123);
1149 }
1150
1151 /* this tests if escapes are preserved or not */
1152 {
1153 UnicodeString str = theBundle.getStringEx("testescape",status);
1154 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
1155 if(U_SUCCESS(status)){
374ca955 1156 u_charsToUChars(expect,uExpect,(int32_t)uprv_strlen(expect)+1);
b75a7d8f
A
1157 if(str.compare(uExpect)!=0){
1158 errln("Did not get the expected string for testescape expected. Expected : "
374ca955 1159 +UnicodeString(uExpect )+ " Got: " + str);
b75a7d8f
A
1160 }
1161 }
1162 }
1163 /* test for jitterbug#1435 */
1164 {
1165 UnicodeString str = theBundle.getStringEx("test_underscores",status);
1166 expect ="test message ....";
1167 CONFIRM_UErrorCode(status, U_ZERO_ERROR);
374ca955 1168 u_charsToUChars(expect,uExpect,(int32_t)uprv_strlen(expect)+1);
b75a7d8f
A
1169 if(str.compare(uExpect)!=0){
1170 errln("Did not get the expected string for test_underscores.\n");
1171 }
1172 }
1173
1174
73c04bcf
A
1175}
1176
1177void
1178NewResourceBundleTest::TestGetByFallback() {
1179 UErrorCode status = U_ZERO_ERROR;
1180
1181 ResourceBundle heRes(NULL, "he", status);
1182
1183 heRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("DateTime", status);
1184 if(U_SUCCESS(status)) {
1185 errln("he locale's Islamic-civil DateTime resource exists. How did it get here?\n");
1186 }
1187 status = U_ZERO_ERROR;
1188
1189 heRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("eras", status);
1190 if(U_FAILURE(status)) {
729e4ab9 1191 dataerrln("Didn't get Islamic Eras. I know they are there! - %s", u_errorName(status));
73c04bcf
A
1192 }
1193 status = U_ZERO_ERROR;
1194
1195 ResourceBundle rootRes(NULL, "root", status);
1196 rootRes.getWithFallback("calendar", status).getWithFallback("islamic-civil", status).getWithFallback("DateTime", status);
1197 if(U_SUCCESS(status)) {
1198 errln("Root's Islamic-civil's DateTime resource exists. How did it get here?\n");
1199 }
1200 status = U_ZERO_ERROR;
1201
b75a7d8f 1202}
3d1f044b
A
1203
1204
1205#define REQUIRE_SUCCESS(status) { \
1206 if (status.errIfFailureAndReset("line %d", __LINE__)) { \
1207 return; \
1208 } \
1209}
1210
1211#define REQUIRE_ERROR(expected, status) { \
1212 if (!status.expectErrorAndReset(expected, "line %d", __LINE__)) { \
1213 return; \
1214 } \
1215}
1216
1217/**
1218 * Tests the --filterDir option in genrb.
1219 *
1220 * Input resource text file: test/testdata/filtertest.txt
1221 * Input filter rule file: test/testdata/filters/filtertest.txt
1222 *
1223 * The resource bundle should contain no keys matched by the filter
1224 * and should contain all other keys.
1225 */
1226void NewResourceBundleTest::TestFilter() {
1227 IcuTestErrorCode status(*this, "TestFilter");
1228
1229 ResourceBundle rb(loadTestData(status), "filtertest", status);
1230 REQUIRE_SUCCESS(status);
1231 assertEquals("rb", rb.getType(), URES_TABLE);
1232
1233 ResourceBundle alabama = rb.get("alabama", status);
1234 REQUIRE_SUCCESS(status);
1235 assertEquals("alabama", alabama.getType(), URES_TABLE);
1236
1237 {
1238 ResourceBundle alaska = alabama.get("alaska", status);
1239 REQUIRE_SUCCESS(status);
1240 assertEquals("alaska", alaska.getType(), URES_TABLE);
1241
1242 {
1243 ResourceBundle arizona = alaska.get("arizona", status);
1244 REQUIRE_SUCCESS(status);
1245 assertEquals("arizona", arizona.getType(), URES_STRING);
1246 assertEquals("arizona", u"arkansas", arizona.getString(status));
1247 REQUIRE_SUCCESS(status);
1248
1249 // Filter: california should not be included
1250 ResourceBundle california = alaska.get("california", status);
1251 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1252 }
1253
1254 // Filter: connecticut should not be included
1255 ResourceBundle connecticut = alabama.get("connecticut", status);
1256 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1257 }
1258
1259 ResourceBundle fornia = rb.get("fornia", status);
1260 REQUIRE_SUCCESS(status);
1261 assertEquals("fornia", fornia.getType(), URES_TABLE);
1262
1263 {
1264 ResourceBundle hawaii = fornia.get("hawaii", status);
1265 REQUIRE_SUCCESS(status);
1266 assertEquals("hawaii", hawaii.getType(), URES_STRING);
1267 assertEquals("hawaii", u"idaho", hawaii.getString(status));
1268 REQUIRE_SUCCESS(status);
1269
1270 // Filter: illinois should not be included
1271 ResourceBundle illinois = fornia.get("illinois", status);
1272 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1273 }
1274
1275 ResourceBundle mississippi = rb.get("mississippi", status);
1276 REQUIRE_SUCCESS(status);
1277 assertEquals("mississippi", mississippi.getType(), URES_TABLE);
1278
1279 {
1280 ResourceBundle louisiana = mississippi.get("louisiana", status);
1281 REQUIRE_SUCCESS(status);
1282 assertEquals("louisiana", louisiana.getType(), URES_TABLE);
1283
1284 {
1285 ResourceBundle maine = louisiana.get("maine", status);
1286 REQUIRE_SUCCESS(status);
1287 assertEquals("maine", maine.getType(), URES_STRING);
1288 assertEquals("maine", u"maryland", maine.getString(status));
1289 REQUIRE_SUCCESS(status);
1290
1291 ResourceBundle iowa = louisiana.get("iowa", status);
1292 REQUIRE_SUCCESS(status);
1293 assertEquals("iowa", iowa.getType(), URES_STRING);
1294 assertEquals("iowa", u"kansas", iowa.getString(status));
1295 REQUIRE_SUCCESS(status);
1296
1297 // Filter: missouri should not be included
1298 ResourceBundle missouri = louisiana.get("missouri", status);
1299 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1300 }
1301
1302 ResourceBundle michigan = mississippi.get("michigan", status);
1303 REQUIRE_SUCCESS(status);
1304 assertEquals("michigan", michigan.getType(), URES_TABLE);
1305
1306 {
1307 ResourceBundle maine = michigan.get("maine", status);
1308 REQUIRE_SUCCESS(status);
1309 assertEquals("maine", maine.getType(), URES_STRING);
1310 assertEquals("maine", u"minnesota", maine.getString(status));
1311 REQUIRE_SUCCESS(status);
1312
1313 // Filter: iowa should not be included
1314 ResourceBundle iowa = michigan.get("iowa", status);
1315 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1316
1317 ResourceBundle missouri = michigan.get("missouri", status);
1318 REQUIRE_SUCCESS(status);
1319 assertEquals("missouri", missouri.getType(), URES_STRING);
1320 assertEquals("missouri", u"nebraska", missouri.getString(status));
1321 REQUIRE_SUCCESS(status);
1322 }
1323
1324 ResourceBundle nevada = mississippi.get("nevada", status);
1325 REQUIRE_SUCCESS(status);
1326 assertEquals("nevada", nevada.getType(), URES_TABLE);
1327
1328 {
1329 ResourceBundle maine = nevada.get("maine", status);
1330 REQUIRE_SUCCESS(status);
1331 assertEquals("maine", maine.getType(), URES_STRING);
1332 assertEquals("maine", u"new-hampshire", maine.getString(status));
1333 REQUIRE_SUCCESS(status);
1334
1335 // Filter: iowa should not be included
1336 ResourceBundle iowa = nevada.get("iowa", status);
1337 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1338
1339 // Filter: missouri should not be included
1340 ResourceBundle missouri = nevada.get("missouri", status);
1341 REQUIRE_ERROR(U_MISSING_RESOURCE_ERROR, status);
1342 }
1343 }
1344}
1345
b75a7d8f
A
1346//eof
1347