• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  *******************************************************************************
3  * Copyright (C) 2001-2015, International Business Machines Corporation and
4  * others. All Rights Reserved.
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.test.util;
8 
9 import java.io.BufferedReader;
10 import java.io.InputStreamReader;
11 import java.net.JarURLConnection;
12 import java.net.URL;
13 import java.net.URLConnection;
14 import java.nio.ByteBuffer;
15 import java.util.Enumeration;
16 import java.util.Locale;
17 import java.util.MissingResourceException;
18 import java.util.NoSuchElementException;
19 import java.util.Set;
20 import java.util.TreeSet;
21 import java.util.jar.JarEntry;
22 
23 import com.ibm.icu.dev.test.TestFmwk;
24 import com.ibm.icu.impl.ICUResourceBundle;
25 import com.ibm.icu.impl.Utility;
26 import com.ibm.icu.text.BreakIterator;
27 import com.ibm.icu.text.UTF16;
28 import com.ibm.icu.util.Calendar;
29 import com.ibm.icu.util.Holiday;
30 import com.ibm.icu.util.ULocale;
31 import com.ibm.icu.util.UResourceBundle;
32 import com.ibm.icu.util.UResourceBundleIterator;
33 import com.ibm.icu.util.UResourceTypeMismatchException;
34 
35 public final class ICUResourceBundleTest extends TestFmwk {
36     private static final ClassLoader testLoader = ICUResourceBundleTest.class.getClassLoader();
37 
main(String args[])38     public static void main(String args[]) throws Exception {
39         ICUResourceBundleTest test = new ICUResourceBundleTest();
40         test.run(args);
41     }
TestGetResources()42     public void TestGetResources(){
43         try{
44             // It does not work well in eclipse plug-in test because of class loader configuration??
45             // For now, specify resource path explicitly in this test case
46             //Enumeration en = testLoader.getResources("META-INF");
47             Enumeration en = testLoader.getResources("com.ibm.icu.dev.data");
48             for(;en.hasMoreElements();) {
49                 URL url = (URL)en.nextElement();
50                 if (url == null) {
51                     warnln("could not load resource data");
52                     return;
53                 }
54                 URLConnection c = url.openConnection();
55 
56                 if (c instanceof JarURLConnection) {
57                     JarURLConnection jc = (JarURLConnection)c;
58                     JarEntry je = jc.getJarEntry();
59                     logln("jar entry: " + je.toString());
60                 } else {
61                     BufferedReader br = new BufferedReader(
62                             new InputStreamReader(c.getInputStream()));
63                     logln("input stream:");
64                     try {
65                         String line = null;
66                         int n = 0;
67                         while ((line = br.readLine()) != null) {
68                             logln("  " + ++n + ": " + line);
69                         }
70                     } finally {
71                         br.close();
72                     }
73                 }
74             }
75         }catch(SecurityException ex) {
76             warnln("could not load resource data: " + ex);
77             ex.printStackTrace();
78     }catch(NullPointerException ex) {
79         // thrown by ibm 1.4.2 windows jvm security manager
80         warnln("could not load resource data: " + ex);
81         }catch(Exception ex){
82         ex.printStackTrace();
83             errln("Unexpected exception: "+ ex);
84         }
85     }
TestResourceBundleWrapper()86     public void TestResourceBundleWrapper(){
87         UResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", "da_DK");
88         Object o = bundle.getObject("holidays");
89         if(o instanceof Holiday[] ){
90             logln("wrapper mechanism works for Weekend data");
91         }else{
92             errln("Did not get the expected output for Weekend data");
93         }
94 
95         bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "bogus");
96         if(bundle instanceof UResourceBundle && bundle.getULocale().getName().equals("en_US")){
97             logln("wrapper mechanism works for bogus locale");
98         }else{
99             errln("wrapper mechanism failed for bogus locale.");
100         }
101 
102         try{
103             bundle = UResourceBundle.getBundleInstance("bogus", "bogus");
104             if(bundle!=null){
105               errln("Did not get the expected exception");
106             }
107         }catch(MissingResourceException ex){
108             logln("got the expected exception");
109         }
110 
111 
112     }
TestJB3879()113     public void TestJB3879(){
114         // this tests tests loading of root bundle when a resource bundle
115         // for the default locale is requested
116         try {
117             UResourceBundle bundle = (UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", ULocale.getDefault().toString(), testLoader);
118             if(bundle==null){
119                 errln("could not create the resource bundle");
120             }
121         }
122         catch (MissingResourceException ex) {
123             warnln("could not load test data: " + ex.getMessage());
124         }
125     }
TestOpen()126     public void TestOpen(){
127         UResourceBundle bundle = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "en_US_POSIX");
128 
129         if(bundle==null){
130             errln("could not create the resource bundle");
131         }
132 
133         UResourceBundle obj =  bundle.get("NumberElements").get("latn").get("patterns");
134 
135         int size = obj.getSize();
136         int type = obj.getType();
137         if(type == UResourceBundle.TABLE){
138             UResourceBundle sub;
139             for(int i=0; i<size; i++) {
140                 sub = obj.get(i);
141                 String temp =sub.getString();
142                 if(temp.length()==0){
143                     errln("Failed to get the items from number patterns table in bundle: "+
144                             bundle.getULocale().getBaseName());
145                 }
146                 //System.out.println("\""+prettify(temp)+"\"");
147             }
148         }
149 
150         obj =  bundle.get("NumberElements").get("latn").get("symbols");
151 
152         size = obj.getSize();
153         type = obj.getType();
154         if(type == UResourceBundle.TABLE){
155             UResourceBundle sub;
156             for(int i=0; i<size; i++){
157                 sub = obj.get(i);
158                 String temp =sub.getString();
159                 if(temp.length()==0){
160                     errln("Failed to get the items from number symbols table in bundle: "+
161                             bundle.getULocale().getBaseName());
162                 }
163                    // System.out.println("\""+prettify(temp)+"\"");
164             }
165         }
166 
167         if(bundle==null){
168             errln("could not create the resource bundle");
169         }
170 
171         bundle = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zzz_ZZ_very_very_very_long_bogus_bundle");
172         if(!bundle.getULocale().equals(ULocale.getDefault())){
173             errln("UResourceBundle did not load the default bundle when bundle was not found. Default: " + ULocale.getDefault() +
174                         ", Bundle locale: " + bundle.getULocale());
175         }
176     }
177 
TestBasicTypes()178     public void TestBasicTypes(){
179         UResourceBundle bundle = null;
180         try {
181             bundle = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes", testLoader);
182         }
183         catch (MissingResourceException e) {
184             warnln("could not load test data: " + e.getMessage());
185             return;
186         }
187         {
188             String expected = "abc\u0000def";
189             UResourceBundle sub = bundle.get("zerotest");
190             if(!expected.equals(sub.getString())){
191                 errln("Did not get the expected string for key zerotest in bundle testtypes");
192             }
193             sub = bundle.get("emptyexplicitstring");
194             expected ="";
195             if(!expected.equals(sub.getString())){
196                 errln("Did not get the expected string for key emptyexplicitstring in bundle testtypes");
197             }
198             sub = bundle.get("emptystring");
199             expected ="";
200             if(!expected.equals(sub.getString())){
201                 errln("Did not get the expected string for key emptystring in bundle testtypes");
202             }
203         }
204         {
205             int expected = 123;
206             UResourceBundle sub = bundle.get("onehundredtwentythree");
207             if(expected!=sub.getInt()){
208                 errln("Did not get the expected int value for key onehundredtwentythree in bundle testtypes");
209             }
210             sub = bundle.get("emptyint");
211             expected=0;
212             if(expected!=sub.getInt()){
213                 errln("Did not get the expected int value for key emptyint in bundle testtypes");
214             }
215         }
216         {
217             int expected = 1;
218             UResourceBundle sub = bundle.get("one");
219             if(expected!=sub.getInt()){
220                 errln("Did not get the expected int value for key one in bundle testtypes");
221             }
222         }
223         {
224             int expected = -1;
225             UResourceBundle sub = bundle.get("minusone");
226             int got = sub.getInt();
227             if(expected!=got){
228                 errln("Did not get the expected int value for key minusone in bundle testtypes");
229             }
230             expected = 0xFFFFFFF;
231             got = sub.getUInt();
232             if(expected!=got){
233                 errln("Did not get the expected int value for key minusone in bundle testtypes");
234             }
235         }
236         {
237             int expected = 1;
238             UResourceBundle sub = bundle.get("plusone");
239             if(expected!=sub.getInt()){
240                 errln("Did not get the expected int value for key minusone in bundle testtypes");
241             }
242 
243         }
244         {
245             int[] expected = new int[]{ 1, 2, 3, -3, 4, 5, 6, 7 }   ;
246             UResourceBundle sub = bundle.get("integerarray");
247             if(!Utility.arrayEquals(expected,sub.getIntVector())){
248                 errln("Did not get the expected int vector value for key integerarray in bundle testtypes");
249             }
250             sub = bundle.get("emptyintv");
251             expected = new int[0];
252             if(!Utility.arrayEquals(expected,sub.getIntVector())){
253                 errln("Did not get the expected int vector value for key emptyintv in bundle testtypes");
254             }
255 
256         }
257         {
258             UResourceBundle sub = bundle.get("binarytest");
259             ByteBuffer got = sub.getBinary();
260             if(got.remaining()!=15){
261                 errln("Did not get the expected length for the binary ByteBuffer");
262             }
263             for(int i=0; i< got.remaining(); i++){
264                 byte b = got.get();
265                 if(b!=i){
266                     errln("Did not get the expected value for binary buffer at index: "+i);
267                 }
268             }
269             sub = bundle.get("emptybin");
270             got = sub.getBinary();
271             if(got.remaining()!=0){
272                 errln("Did not get the expected length for the emptybin ByteBuffer");
273             }
274 
275         }
276         {
277             UResourceBundle sub = bundle.get("emptyarray");
278             String key = sub.getKey();
279             if(!key.equals("emptyarray")){
280                 errln("Did not get the expected key for emptytable item");
281             }
282             if(sub.getSize()!=0){
283                 errln("Did not get the expected length for emptytable item");
284             }
285         }
286         {
287             UResourceBundle sub = bundle.get("menu");
288             String key = sub.getKey();
289             if(!key.equals("menu")){
290                 errln("Did not get the expected key for menu item");
291             }
292             UResourceBundle sub1 = sub.get("file");
293             key = sub1.getKey();
294             if(!key.equals("file")){
295                 errln("Did not get the expected key for file item");
296             }
297             UResourceBundle sub2 = sub1.get("open");
298             key = sub2.getKey();
299             if(!key.equals("open")){
300                 errln("Did not get the expected key for file item");
301             }
302             String value = sub2.getString();
303             if(!value.equals("Open")){
304                 errln("Did not get the expected value for key for oen item");
305             }
306 
307             sub = bundle.get("emptytable");
308             key = sub.getKey();
309             if(!key.equals("emptytable")){
310                 errln("Did not get the expected key for emptytable item");
311             }
312             if(sub.getSize()!=0){
313                 errln("Did not get the expected length for emptytable item");
314             }
315             sub = bundle.get("menu").get("file");
316             int size = sub.getSize();
317             String expected;
318             for(int i=0; i<size; i++){
319                 sub1 = sub.get(i);
320 
321                 switch(i){
322                     case 0:
323                         expected = "exit";
324                         break;
325                     case 1:
326                         expected = "open";
327                         break;
328                     case 2:
329                         expected = "save";
330                         break;
331                     default:
332                         expected ="";
333                 }
334                 String got = sub1.getKey();
335                 if(!expected.equals(got)){
336                     errln("Did not get the expected key at index"+i+". Expected: "+expected+" Got: "+got);
337                 }else{
338                     logln("Got the expected key at index: "+i);
339                 }
340             }
341         }
342 
343     }
344     private static final class TestCase{
345         String key;
346         int value;
TestCase(String key, int value)347         TestCase(String key, int value){
348             this.key = key;
349             this.value = value;
350         }
351     }
TestTable32()352     public void TestTable32(){
353         TestCase[] arr = new TestCase[]{
354           new TestCase  ( "ooooooooooooooooo", 0 ),
355           new TestCase  ( "oooooooooooooooo1", 1 ),
356           new TestCase  ( "ooooooooooooooo1o", 2 ),
357           new TestCase  ( "oo11ooo1ooo11111o", 25150 ),
358           new TestCase  ( "oo11ooo1ooo111111", 25151 ),
359           new TestCase  ( "o1111111111111111", 65535 ),
360           new TestCase  ( "1oooooooooooooooo", 65536 ),
361           new TestCase  ( "1ooooooo11o11ooo1", 65969 ),
362           new TestCase  ( "1ooooooo11o11oo1o", 65970 ),
363           new TestCase  ( "1ooooooo111oo1111", 65999 )
364         };
365         UResourceBundle bundle = null;
366         try {
367             bundle = UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testtable32", testLoader);
368         }
369         catch (MissingResourceException ex) {
370             warnln("could not load resource data: " + ex.getMessage());
371             return;
372         }
373 
374         if(bundle.getType()!= UResourceBundle.TABLE){
375             errln("Could not get the correct type for bundle testtable32");
376         }
377 
378         int size =bundle.getSize();
379         if(size!=66000){
380             errln("Could not get the correct size for bundle testtable32");
381         }
382 
383         int number = -1;
384 
385         // get the items by index
386         for(int i =0; i<size; i++){
387             UResourceBundle item = bundle.get(i);
388             String key = item.getKey();
389             int parsedNumber = parseTable32Key(key);
390             switch(item.getType()){
391                 case UResourceBundle.STRING:
392                     String value = item.getString();
393                     number = UTF16.charAt(value,0);
394                     break;
395                 case UResourceBundle.INT:
396                     number = item.getInt();
397                     break;
398                 default:
399                     errln("Got unexpected resource type in testtable32");
400             }
401             if(number!=parsedNumber){
402                 errln("Did not get expected value in testtypes32 for key"+
403                       key+". Expected: "+parsedNumber+" Got:"+number);
404             }
405 
406         }
407 
408         // search for some items by key
409         for(int i=0;i<arr.length; i++){
410             UResourceBundle item = bundle.get(arr[i].key);
411             switch(item.getType()){
412                 case UResourceBundle.STRING:
413                     String value = item.getString();
414                     number = UTF16.charAt(value,0);
415                     break;
416                  case UResourceBundle.INT:
417                     number = item.getInt();
418                     break;
419                 default:
420                     errln("Got unexpected resource type in testtable32");
421             }
422 
423             if(number != arr[i].value){
424                 errln("Did not get expected value in testtypes32 for key" +
425                       arr[i].key +". Expected: " + arr[i].value + " Got:" + number);
426             }
427         }
428     }
parseTable32Key(String key)429     private static int  parseTable32Key(String key) {
430         int number;
431         char c;
432 
433         number=0;
434         for(int i=0; i<key.length(); i++){
435             c = key.charAt(i);
436             number<<=1;
437             if(c=='1') {
438                 number|=1;
439             }
440         }
441         return number;
442     }
443 
TestAliases()444     public void TestAliases(){
445        String simpleAlias   = "Open";
446 
447        UResourceBundle rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases", testLoader);
448        if (rb == null) {
449            warnln("could not load testaliases data");
450            return;
451        }
452         UResourceBundle sub = rb.get("simplealias");
453         String s1 = sub.getString("simplealias");
454         if(s1.equals(simpleAlias)){
455             logln("Alias mechanism works for simplealias");
456         }else{
457             errln("Did not get the expected output for simplealias");
458         }
459         {
460             try{
461                 rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
462                 sub = rb.get("nonexisting");
463                 errln("Did not get the expected exception for nonexisting");
464             }catch(MissingResourceException ex){
465                 logln("Alias mechanism works for nonexisting alias");
466             }
467         }
468         {
469             rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
470             sub = rb.get("referencingalias");
471             s1 = sub.getString();
472             if(s1.equals("H:mm:ss")){
473                 logln("Alias mechanism works for referencingalias");
474             }else{
475                 errln("Did not get the expected output for referencingalias");
476             }
477         }
478         {
479             UResourceBundle rb1 = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
480             if(rb1!=rb){
481                 errln("Caching of the resource bundle failed");
482             }else{
483                 logln("Caching of resource bundle passed");
484             }
485             sub = rb1.get("testGetStringByKeyAliasing" );
486 
487             s1 = sub.get("KeyAlias0PST").getString();
488             if(s1.equals("America/Los_Angeles")){
489                 logln("Alias mechanism works for KeyAlias0PST");
490             }else{
491                 errln("Did not get the expected output for KeyAlias0PST");
492             }
493 
494             s1 = sub.getString("KeyAlias1PacificStandardTime");
495             if(s1.equals("Pacific Standard Time")){
496                 logln("Alias mechanism works for KeyAlias1PacificStandardTime");
497             }else{
498                 errln("Did not get the expected output for KeyAlias1PacificStandardTime");
499             }
500             s1 = sub.getString("KeyAlias2PDT");
501             if(s1.equals("PDT")){
502                 logln("Alias mechanism works for KeyAlias2PDT");
503             }else{
504                 errln("Did not get the expected output for KeyAlias2PDT");
505             }
506 
507             s1 = sub.getString("KeyAlias3LosAngeles");
508             if(s1.equals("Los Angeles")){
509                 logln("Alias mechanism works for KeyAlias3LosAngeles. Got: "+s1);
510             }else{
511                 errln("Did not get the expected output for KeyAlias3LosAngeles. Got: "+s1);
512             }
513         }
514         {
515             sub = rb.get("testGetStringByIndexAliasing" );
516             s1 = sub.getString(0);
517             if(s1.equals("America/Los_Angeles")){
518                 logln("Alias mechanism works for testGetStringByIndexAliasing/0. Got: "+s1);
519             }else{
520                 errln("Did not get the expected output for testGetStringByIndexAliasing/0. Got: "+s1);
521             }
522             s1 = sub.getString(1);
523             if(s1.equals("Pacific Standard Time")){
524                 logln("Alias mechanism works for testGetStringByIndexAliasing/1");
525             }else{
526                 errln("Did not get the expected output for testGetStringByIndexAliasing/1");
527             }
528             s1 = sub.getString(2);
529             if(s1.equals("PDT")){
530                 logln("Alias mechanism works for testGetStringByIndexAliasing/2");
531             }else{
532                 errln("Did not get the expected output for testGetStringByIndexAliasing/2");
533             }
534 
535             s1 = sub.getString(3);
536             if(s1.equals("Los Angeles")){
537                 logln("Alias mechanism works for testGetStringByIndexAliasing/3. Got: "+s1);
538             }else{
539                 errln("Did not get the expected output for testGetStringByIndexAliasing/3. Got: "+s1);
540             }
541         }
542 
543 // Note: Following test cases are no longer working because collation data is now in the collation module
544 //        {
545 //            sub = rb.get("testAliasToTree" );
546 //
547 //            ByteBuffer buf = sub.get("standard").get("%%CollationBin").getBinary();
548 //            if(buf==null){
549 //                errln("Did not get the expected output for %%CollationBin");
550 //            }
551 //        }
552 //
553 //        rb = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"zh_TW");
554 //        UResourceBundle b = (UResourceBundle) rb.getObject("collations");
555 //        if(b != null){
556 //            if(b.get(0).getKey().equals( "default")){
557 //                logln("Alias mechanism works");
558 //            }else{
559 //                errln("Alias mechanism failed for zh_TW collations");
560 //            }
561 //        }else{
562 //            errln("Did not get the expected object for collations");
563 //        }
564 
565         // Test case for #7996
566         {
567             UResourceBundle bundle = UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "te");
568             UResourceBundle table = bundle.get("tableT7996");
569             try {
570                 String s = table.getString("a7996");
571                 logln("Alias in nested table referring one in sh worked - " + s);
572             } catch (MissingResourceException e) {
573                 errln("Alias in nested table referring one in sh failed");
574             }
575 
576             try {
577                 String s = ((ICUResourceBundle)table).getStringWithFallback("b7996");
578                 logln("Alias with /LOCALE/ in nested table in root referring back to another key in the current locale bundle worked - " + s);
579             } catch (MissingResourceException e) {
580                 errln("Alias with /LOCALE/ in nested table in root referring back to another key in the current locale bundle failed");
581             }
582         }
583 
584     }
TestAlias()585     public void TestAlias(){
586         logln("Testing %%ALIAS");
587         UResourceBundle rb = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"iw_IL");
588         UResourceBundle b = rb.get("NumberElements");
589         if(b != null){
590             if(b.getSize()>0){
591                 logln("%%ALIAS mechanism works");
592             }else{
593                 errln("%%ALIAS mechanism failed for iw_IL NumberElements");
594             }
595         }else{
596             errln("%%ALIAS mechanism failed for iw_IL");
597         }
598     }
TestXPathAlias()599     public void TestXPathAlias(){
600         UResourceBundle rb = (UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN",testLoader);
601         UResourceBundle b = rb.get("aliasClient");
602         String result = b.getString();
603         String expResult= "correct";
604 
605         if(!result.equals(expResult)){
606             errln("Did not get the expected result for XPath style alias");
607         }
608         try{
609             UResourceBundle c = rb.get("rootAliasClient");
610             result = c.getString();
611             expResult = "correct";
612             if(!result.equals(expResult)){
613                 errln("Did not get the expected result for XPath style alias for rootAliasClient");
614             }
615         }catch( MissingResourceException ex){
616             errln("Could not get rootAliasClient");
617         }
618     }
TestCircularAliases()619     public void TestCircularAliases(){
620         try{
621             UResourceBundle rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
622             UResourceBundle sub = rb.get("aaa");
623             String s1 = sub.getString();
624             if(s1!=null){
625                 errln("Did not get the expected exception");
626             }
627         }catch(IllegalArgumentException ex){
628             logln("got expected exception for circular references");
629         }
630         catch (MissingResourceException ex) {
631             warnln("could not load resource data: " + ex.getMessage());
632         }
633     }
634 
TestPreventFallback()635     public void TestPreventFallback() {
636         String noFallbackResource = "string_in_te_no_te_IN_fallback";
637         ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN_NE",testLoader);
638         try {
639             rb.getStringWithFallback(noFallbackResource);
640             fail("Expected MissingResourceException.");
641         } catch (MissingResourceException e) {
642             // Expected
643         }
644         rb.getStringWithFallback("string_only_in_te");
645         rb = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te",testLoader);
646         rb.getStringWithFallback(noFallbackResource);
647     }
648 
TestGetWithFallback()649     public void TestGetWithFallback(){
650         /*
651         UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
652         String key = bundle.getStringWithFallback("Keys/collation");
653         if(!key.equals("COLLATION")){
654             errln("Did not get the expected result from getStringWithFallback method.");
655         }
656         String type = bundle.getStringWithFallback("Types/collation/direct");
657         if(!type.equals("DIRECT")){
658             errln("Did not get the expected result form getStringWithFallback method.");
659         }
660         */
661         ICUResourceBundle bundle = null;
662 
663         bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"fr_FR");
664         ICUResourceBundle b1 = bundle.getWithFallback("calendar");
665         String defaultCal = b1.getStringWithFallback("default");
666         if(!defaultCal.equals("gregorian")){
667             errln("Did not get the expected default calendar string: Expected: gregorian, Got: "+defaultCal);
668         }
669         ICUResourceBundle b2 = b1.getWithFallback(defaultCal);
670         ICUResourceBundle b3 = b2.getWithFallback("monthNames");
671         ICUResourceBundle b4 = b3.getWithFallback("format");
672         ICUResourceBundle b5 = b4.getWithFallback("narrow");
673         if(b5.getSize()!=12){
674             errln("Did not get the expected size for the monthNames");
675         }
676     }
677 
678     private static final String CALENDAR_RESNAME = "calendar";
679     private static final String CALENDAR_KEYWORD = "calendar";
680 
TestLocaleDisplayNames()681     public void TestLocaleDisplayNames() {
682         ULocale[] locales = ULocale.getAvailableLocales();
683         for (int i = 0; i < locales.length; ++i) {
684             if (!hasLocalizedCountryFor(ULocale.ENGLISH, locales[i]) && (locales[i].getLanguage().compareTo("ti") != 0)){ // TODO: restore test for ti_* when cldrbug 3058 is fixed
685                  errln("Could not get English localized country for " + locales[i]);
686             }
687             if(!hasLocalizedLanguageFor(ULocale.ENGLISH, locales[i])){
688                 errln("Could not get English localized language for " + locales[i]);
689             }
690             if(!hasLocalizedCountryFor(locales[i], locales[i]) &&
691                     !(locales[i].getLanguage().equals("ti") || // TODO: restore test for ti_* when cldrbug 3058 is fixed
692                     ((locales[i].getBaseName().equals("sah_RU") || locales[i].getBaseName().equals("smn_FI")) && logKnownIssue("cldrbug:7872", "No localized region name for sah_RU, smn_FI")))) {
693                 errln("Could not get native localized country for " + locales[i]);
694                 hasLocalizedCountryFor(locales[i], locales[i]);
695             }
696             if(!hasLocalizedLanguageFor(locales[i], locales[i]) && (locales[i].getLanguage().compareTo("nmg") != 0)){
697                 errln("Could not get native localized language for " + locales[i]);
698             }
699 
700             logln(locales[i] + "\t" + locales[i].getDisplayName(ULocale.ENGLISH) + "\t" + locales[i].getDisplayName(locales[i]));
701         }
702     }
703 
hasLocalizedLanguageFor(ULocale locale, ULocale otherLocale)704     private static boolean hasLocalizedLanguageFor(ULocale locale, ULocale otherLocale) {
705         String lang = otherLocale.getLanguage();
706         String localizedVersion = otherLocale.getDisplayLanguage(locale);
707         return !lang.equals(localizedVersion);
708     }
709 
hasLocalizedCountryFor(ULocale locale, ULocale otherLocale)710     private static boolean hasLocalizedCountryFor(ULocale locale, ULocale otherLocale) {
711         String country = otherLocale.getCountry();
712         if (country.equals("")) return true;
713         String localizedVersion = otherLocale.getDisplayCountry(locale);
714         return !country.equals(localizedVersion);
715     }
716 
TestFunctionalEquivalent()717     public void TestFunctionalEquivalent(){
718        // Android patch: Force default Gregorian calendar.
719        String[] calCases = {
720        //  avail    locale                              equiv
721            "t",     "en_US_POSIX",                      "en@calendar=gregorian",
722            "f",     "ja_JP_TOKYO",                      "ja@calendar=gregorian",
723            "f",     "ja_JP_TOKYO@calendar=japanese",    "ja@calendar=japanese",
724            "t",     "sr@calendar=gregorian",            "sr@calendar=gregorian",
725            "t",     "en",                               "en@calendar=gregorian",
726            "t",     "th_TH",                            "th@calendar=gregorian",
727            "t",     "th_TH@calendar=gregorian",         "th@calendar=gregorian",
728            "f",     "th_TH_Bangkok",                    "th@calendar=gregorian",
729        };
730        // Android patch end.
731 
732        logln("Testing functional equivalents for calendar...");
733        getFunctionalEquivalentTestCases(ICUResourceBundle.ICU_BASE_NAME,
734                                         Calendar.class.getClassLoader(),
735                CALENDAR_RESNAME, CALENDAR_KEYWORD, false, calCases);
736 
737        logln("Testing error conditions:");
738        try {
739            ClassLoader cl = BreakIterator.class.getClassLoader();
740            ICUResourceBundle.getFunctionalEquivalent(ICUResourceBundle.ICU_BRKITR_BASE_NAME, cl, "calendar",
741               "calendar", new ULocale("ar_EG@calendar=islamic"), new boolean[1], true);
742            errln("Err: expected MissingResourceException");
743        } catch ( MissingResourceException t ) {
744            logln("expected MissingResourceException caught (PASS): " + t.toString());
745        }
746     }
747 
getFunctionalEquivalentTestCases(String path, ClassLoader cl, String resName, String keyword, boolean truncate, String[] testCases)748     private void getFunctionalEquivalentTestCases(String path, ClassLoader cl, String resName, String keyword,
749             boolean truncate, String[] testCases) {
750         //String F_STR = "f";
751         String T_STR = "t";
752         boolean isAvail[] = new boolean[1];
753 
754         logln("Testing functional equivalents...");
755         for(int i = 0; i < testCases.length ;i+=3) {
756             boolean expectAvail = T_STR.equals(testCases[i+0]);
757             ULocale inLocale = new ULocale(testCases[i+1]);
758             ULocale expectLocale = new ULocale(testCases[i+2]);
759 
760             logln(new Integer(i/3).toString() + ": " + new Boolean(expectAvail).toString() + "\t\t" +
761                     inLocale.toString() + "\t\t" + expectLocale.toString());
762 
763             ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(path, cl, resName, keyword, inLocale, isAvail, truncate);
764             boolean gotAvail = isAvail[0];
765 
766             if((gotAvail != expectAvail) || !equivLocale.equals(expectLocale)) {
767                 errln(new Integer(i/3).toString() + ":  Error, expected  Equiv=" + new Boolean(expectAvail).toString() + "\t\t" +
768                         inLocale.toString() + "\t\t--> " + expectLocale.toString() + ",  but got " + new Boolean(gotAvail).toString() + " " +
769                         equivLocale.toString());
770             }
771         }
772     }
773 
TestNorwegian()774     public void TestNorwegian(){
775         try{
776             UResourceBundle rb = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_REGION_BASE_NAME, "no_NO_NY");
777             UResourceBundle sub = rb.get("Countries");
778             String s1 = sub.getString("NO");
779             if(s1.equals("Noreg")){
780                 logln("got expected output ");
781             }else{
782                 errln("did not get the expected result");
783             }
784         }catch(IllegalArgumentException ex){
785             errln("Caught an unexpected expected");
786         }
787     }
TestJB4102()788     public void TestJB4102(){
789         try {
790             ICUResourceBundle root =(ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "root");
791             ICUResourceBundle t = null;
792 // AmPmMarkers now exist in root/islamic calendar, so this test is rendered useless.
793 //          try{
794 //              t = root.getWithFallback("calendar/islamic-civil/AmPmMarkers");
795 //              errln("Second resource does not exist. How did it get here?\n");
796 //          }catch(MissingResourceException ex){
797 //              logln("Got the expected exception");
798 //          }
799             try{
800                 t = root.getWithFallback("calendar/islamic-civil/eras/abbreviated/0/mikimaus/pera");
801                 errln("Second resource does not exist. How did it get here?\n");
802             }catch(MissingResourceException ex){
803                 logln("Got the expected exception");
804             }
805             if(t!=null){
806                 errln("t is not null!");
807             }
808         } catch (MissingResourceException e) {
809            warnln("Could not load the locale data: " + e.getMessage());
810         }
811     }
812 
TestCLDRStyleAliases()813     public void TestCLDRStyleAliases() {
814         String result = null;
815         String expected = null;
816         String[]expects = new String[] { "", "a41", "a12", "a03", "ar4" };
817 
818         logln("Testing CLDR style aliases......\n");
819 
820         UResourceBundle rb = UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "te_IN_REVISED",testLoader);
821         ICUResourceBundle alias = (ICUResourceBundle)rb.get("a");
822 
823         for(int i = 1; i < 5 ; i++) {
824           String resource="a"+i;
825           UResourceBundle a = (alias).getWithFallback(resource);
826           result = a.getString();
827           if(result.equals(expected)) {
828               errln("CLDR style aliases failed resource with name "+resource+"resource, exp "+expects[i] +" , got " + result);
829           }
830         }
831 
832     }
getLSString(int status)833     private String getLSString(int status){
834         switch(status){
835             case ICUResourceBundle.FROM_FALLBACK:
836                 return "FROM_FALLBACK";
837             case ICUResourceBundle.FROM_DEFAULT:
838                 return "FROM_DEFAULT";
839             case ICUResourceBundle.FROM_ROOT:
840                 return "FROM_ROOT";
841             case ICUResourceBundle.FROM_LOCALE:
842                 return "FROM_LOCALE";
843             default:
844                 return "UNKNOWN";
845         }
846     }
847 
assertEqualLoadingStatus(String msg, int target, int result)848     private void assertEqualLoadingStatus(String msg, int target, int result) {
849         if (result != target) {
850             errln(msg + " expected: "+ getLSString(target)
851                     + " got: " + getLSString(result));
852         }
853     }
854 
855     @SuppressWarnings("unused")
assertDefaultLoadingStatus(String msg, int result)856     private void assertDefaultLoadingStatus(String msg, int result) {
857         assertEqualLoadingStatus(msg, ICUResourceBundle.FROM_DEFAULT, result);
858     }
859 
assertFallbackLoadingStatus(String msg, int result)860     private void assertFallbackLoadingStatus(String msg, int result) {
861         assertEqualLoadingStatus(msg, ICUResourceBundle.FROM_FALLBACK, result);
862     }
863 
assertRootLoadingStatus(String msg, int result)864     private void assertRootLoadingStatus(String msg, int result) {
865         assertEqualLoadingStatus(msg, ICUResourceBundle.FROM_ROOT, result);
866     }
867 
assertLocaleLoadingStatus(String msg, int result)868     private void assertLocaleLoadingStatus(String msg, int result) {
869         assertEqualLoadingStatus(msg, ICUResourceBundle.FROM_LOCALE, result);
870     }
871 
TestLoadingStatus()872     public void TestLoadingStatus(){
873         ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "yi_IL");
874         assertFallbackLoadingStatus("base/yi_IL", bundle.getLoadingStatus());
875 
876         bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "eo_DE");
877         assertFallbackLoadingStatus("base/eo_DE", bundle.getLoadingStatus());
878 
879         logln("Test to verify loading status of get(String)");
880         bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_LANG_BASE_NAME, "zh_Hant_TW");
881         ICUResourceBundle countries = (ICUResourceBundle) bundle.get("Languages");
882         assertFallbackLoadingStatus("lang/Languages/zh_Hant_TW", countries.getLoadingStatus());
883 
884         /*
885         UResourceBundle auxExemplar = bundle.get("AuxExemplarCharacters");
886         status = auxExemplar.getLoadingStatus();
887         if(status != UResourceBundle.FROM_ROOT){
888             errln("Did not get the expected value for loading status. Expected "+ getLSString(UResourceBundle.FROM_ROOT)
889                     + " Got: " + getLSString(status));
890         }
891         */
892 
893         logln("Test to verify root loading status of get()");
894         bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "te_IN");
895         ICUResourceBundle ms = (ICUResourceBundle) bundle.get("layout");
896         assertRootLoadingStatus("base/layout/te_IN", ms.getLoadingStatus());
897 
898         logln("Test to verify loading status of getwithFallback");
899         bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "sh_YU", testLoader);
900         ICUResourceBundle temp = (ICUResourceBundle) bundle.getWithFallback("a/a2");
901         assertLocaleLoadingStatus("testdata/a/a2/sh_YU", temp.getLoadingStatus());
902 
903         temp = bundle.getWithFallback("a/a1");
904         assertFallbackLoadingStatus("testdata/a/a1/sh_YU", temp.getLoadingStatus());
905 
906         temp = bundle.getWithFallback("a/a4");
907         assertRootLoadingStatus("testdata/a/a4/sh_YU", temp.getLoadingStatus());
908     }
909 
TestCoverage()910     public void TestCoverage(){
911         UResourceBundle bundle;
912         bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME);
913         if (bundle == null){
914             errln("UResourceBundle.getBundleInstance(String baseName) failed");
915         }
916         bundle = null;
917         bundle = UResourceBundle.getBundleInstance(ULocale.getDefault());
918         if (bundle == null){
919             errln("UResourceBundle.getBundleInstance(ULocale) failed");
920             return;
921         }
922         if (new UResourceTypeMismatchException("coverage") == null){
923             errln("Create UResourceTypeMismatchException error");
924         }
925         class Stub extends UResourceBundle{
926             public ULocale getULocale() {return ULocale.ROOT;}
927             protected String getLocaleID() {return null;}
928             protected String getBaseName() {return null;}
929             protected UResourceBundle getParent() {return null;}
930             protected void setLoadingStatus(int newStatus) {}
931             public Enumeration getKeys() {return null;}
932             protected Object handleGetObject(String aKey) {return null;}
933         }
934         Stub stub = new Stub();
935 
936         if (!stub.getLocale().equals(ULocale.ROOT.toLocale())){
937             errln("UResourceBundle.getLoclae(Locale) should delegate to (ULocale)");
938         }
939     }
TestJavaULocaleBundleLoading()940     public void TestJavaULocaleBundleLoading(){
941         String baseName="com.ibm.icu.dev.data.resources.TestDataElements";
942         String locName = "en_Latn_US";
943         UResourceBundle bundle = UResourceBundle.getBundleInstance(baseName, locName, testLoader);
944         String fromRoot = bundle.getString("from_root");
945         if(!fromRoot.equals("This data comes from root")){
946             errln("Did not get the expected string for from_root");
947         }
948         String fromEn = bundle.getString("from_en");
949         if(!fromEn.equals("This data comes from en")){
950             errln("Did not get the expected string for from_en");
951         }
952         String fromEnLatn = bundle.getString("from_en_Latn");
953         if(!fromEnLatn.equals("This data comes from en_Latn")){
954             errln("Did not get the expected string for from_en_Latn");
955         }
956         String fromEnLatnUs = bundle.getString("from_en_Latn_US");
957         if(!fromEnLatnUs.equals("This data comes from en_Latn_US")){
958             errln("Did not get the expected string for from_en_Latn_US");
959         }
960         UResourceBundle bundle1 = UResourceBundle.getBundleInstance(baseName, new ULocale(locName), testLoader);
961         if(!bundle1.equals(bundle)){
962             errln("Did not get the expected bundle for "+baseName +"."+locName);
963         }
964         if(bundle1!=bundle){
965             errln("Did not load the bundle from cache");
966         }
967 
968         UResourceBundle bundle2 = UResourceBundle.getBundleInstance(baseName, "en_IN", testLoader);
969         if(!bundle2.getLocale().toString().equals("en")){
970             errln("Did not get the expected fallback locale. Expected: en Got: "+bundle2.getLocale().toString());
971         }
972         UResourceBundle bundle3 = UResourceBundle.getBundleInstance(baseName, "te_IN", testLoader);
973         if(!bundle3.getLocale().toString().equals("te")){
974             errln("Did not get the expected fallback locale. Expected: te Got: "+bundle2.getLocale().toString());
975         }
976         // non-existent bundle .. should return default
977         UResourceBundle defaultBundle = UResourceBundle.getBundleInstance(baseName, "hi_IN", testLoader);
978         ULocale defaultLocale = ULocale.getDefault();
979         if(!defaultBundle.getULocale().equals(defaultLocale)){
980             errln("Did not get the default bundle for non-existent bundle");
981         }
982         // non-existent bundle, non-existent default locale
983         // so return the root bundle.
984         ULocale.setDefault(ULocale.CANADA_FRENCH);
985         UResourceBundle root = UResourceBundle.getBundleInstance(baseName, "hi_IN", testLoader);
986         if(!root.getULocale().toString().equals("")){
987             errln("Did not get the root bundle for non-existent default bundle for non-existent bundle");
988         }
989         //reset the default
990         ULocale.setDefault(defaultLocale);
991         Enumeration keys = bundle.getKeys();
992         int i=0;
993         while(keys.hasMoreElements()){
994             logln("key: "+ keys.nextElement());
995             i++;
996         }
997         if(i!=4){
998             errln("Did not get the expected number of keys: got " + i + ", expected 4");
999         }
1000         UResourceBundle bundle4 = UResourceBundle.getBundleInstance(baseName,"fr_Latn_FR", testLoader);
1001         if(bundle4==null){
1002             errln("Could not load bundle fr_Latn_FR");
1003         }
1004     }
TestAliasFallback()1005     public void TestAliasFallback(){
1006         try{
1007             ULocale loc = new ULocale("en_US");
1008             ICUResourceBundle b = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, loc);
1009             ICUResourceBundle b1 = (ICUResourceBundle)b.getWithFallback("calendar/hebrew/monthNames/format/abbreviated");
1010             if(b1!=null){
1011                 logln("loaded data for abbreviated month names: "+ b1.getKey());
1012             }
1013         }catch(MissingResourceException ex){
1014             warnln("Failed to load data for abbreviated month names");
1015         }
1016     }
setFromEnumeration(Enumeration<String> e)1017     private Set<String> setFromEnumeration(Enumeration<String> e) {
1018         TreeSet<String> set = new TreeSet<String>();
1019         while (e.hasMoreElements()) {
1020             set.add(e.nextElement());
1021         }
1022         return set;
1023     }
1024     /**
1025      * Test ICUResourceBundle.getKeys() for a whole bundle (top-level resource).
1026      * JDK JavaDoc for ResourceBundle.getKeys() says that it returns
1027      * "an Enumeration of the keys contained in this ResourceBundle and its parent bundles."
1028      */
TestICUGetKeysAtTopLevel()1029     public void TestICUGetKeysAtTopLevel() {
1030         String baseName="com/ibm/icu/dev/data/testdata";
1031         UResourceBundle te_IN = UResourceBundle.getBundleInstance(baseName, "te_IN", testLoader);
1032         UResourceBundle te = UResourceBundle.getBundleInstance(baseName, "te", testLoader);
1033         Set<String> te_set = setFromEnumeration(te.getKeys());
1034         Set<String> te_IN_set = setFromEnumeration(te_IN.getKeys());
1035         assertTrue("te.getKeys().contains(string_only_in_Root)", te_set.contains("string_only_in_Root"));
1036         assertTrue("te.getKeys().contains(string_only_in_te)", te_set.contains("string_only_in_te"));
1037         assertFalse("te.getKeys().contains(string_only_in_te_IN)", te_set.contains("string_only_in_te_IN"));
1038         assertTrue("te_IN.getKeys().contains(string_only_in_Root)", te_IN_set.contains("string_only_in_Root"));
1039         assertTrue("te_IN.getKeys().contains(string_only_in_te)", te_IN_set.contains("string_only_in_te"));
1040         assertTrue("te_IN.getKeys().contains(string_only_in_te_IN)", te_IN_set.contains("string_only_in_te_IN"));
1041         // TODO: Check for keys of alias resource items
1042     }
1043     /**
1044      * Test ICUResourceBundle.getKeys() for a resource item (not a whole bundle/top-level resource).
1045      * This does not take parent bundles into account.
1046      */
TestICUGetKeysForResourceItem()1047     public void TestICUGetKeysForResourceItem() {
1048         String baseName="com/ibm/icu/dev/data/testdata";
1049         UResourceBundle te = UResourceBundle.getBundleInstance(baseName, "te", testLoader);
1050         UResourceBundle tagged_array_in_Root_te = te.get("tagged_array_in_Root_te");
1051         Set<String> keys = setFromEnumeration(tagged_array_in_Root_te.getKeys());
1052         assertTrue("tagged_array_in_Root_te.getKeys().contains(tag0)", keys.contains("tag0"));
1053         assertTrue("tagged_array_in_Root_te.getKeys().contains(tag1)", keys.contains("tag1"));
1054         assertFalse("tagged_array_in_Root_te.getKeys().contains(tag7)", keys.contains("tag7"));
1055         assertFalse("tagged_array_in_Root_te.getKeys().contains(tag12)", keys.contains("tag12"));
1056         UResourceBundle array_in_Root_te = te.get("array_in_Root_te");
1057         assertFalse("array_in_Root_te.getKeys().hasMoreElements()", array_in_Root_te.getKeys().hasMoreElements());
1058         UResourceBundle string_in_Root_te = te.get("string_in_Root_te");
1059         assertFalse("string_in_Root_te.getKeys().hasMoreElements()", string_in_Root_te.getKeys().hasMoreElements());
1060     }
1061 
1062     /*
1063      * UResouceBundle should be able to load a resource bundle even if
1064      * a similarly named class (only case differences) exists in the
1065      * same package.  See Ticket#6844
1066      */
TestT6844()1067     public void TestT6844() {
1068         try {
1069             UResourceBundle rb1
1070                 = UResourceBundle.getBundleInstance("com.ibm.icu.dev.data.resources.TestMessages");
1071             assertEquals("bundleContainer in TestMessages", "TestMessages.class", rb1.getString("bundleContainer"));
1072 
1073             UResourceBundle rb2
1074                 = UResourceBundle.getBundleInstance("com.ibm.icu.dev.data.resources.testmessages");
1075             assertEquals("bundleContainer in testmessages", "testmessages.properties", rb2.getString("bundleContainer"));
1076         } catch (Throwable t) {
1077             errln(t.getMessage());
1078         }
1079     }
1080 
TestUResourceBundleCoverage()1081     public void TestUResourceBundleCoverage() {
1082         Locale locale = null;
1083         ULocale ulocale = null;
1084         String baseName = null;
1085         UResourceBundle rb1, rb2, rb3, rb4, rb5, rb6, rb7;
1086 
1087         rb1 = UResourceBundle.getBundleInstance(ulocale);
1088         rb2 = UResourceBundle.getBundleInstance(baseName);
1089         rb3 = UResourceBundle.getBundleInstance(baseName, ulocale);
1090         rb4 = UResourceBundle.getBundleInstance(baseName, locale);
1091 
1092         rb5 = UResourceBundle.getBundleInstance(baseName, ulocale, this.getClass().getClassLoader());
1093         rb6 = UResourceBundle.getBundleInstance(baseName, locale, this.getClass().getClassLoader());
1094         try {
1095             rb7 = UResourceBundle.getBundleInstance("bogus", Locale.getDefault(), this.getClass().getClassLoader());
1096             errln("Should have thrown exception with bogus baseName.");
1097         } catch (java.util.MissingResourceException ex) {
1098         }
1099         if (rb1 == null || rb2 == null || rb3 == null || rb4 == null || rb5 == null || rb6 == null) {
1100             errln("Error getting resource bundle.");
1101         }
1102 
1103         rb7 = UResourceBundle.getBundleInstance("com.ibm.icu.dev.data.resources.TestDataElements");
1104 
1105         UResourceBundle.resetBundleCache();
1106 
1107         try {
1108             rb1.getBinary();
1109             errln("getBinary() call should have thrown UResourceTypeMismatchException.");
1110         } catch (UResourceTypeMismatchException ex) {
1111         }
1112         try {
1113             rb1.getStringArray();
1114             errln("getStringArray() call should have thrown UResourceTypeMismatchException.");
1115         } catch (UResourceTypeMismatchException ex) {
1116         }
1117         try {
1118             byte [] ba = { 0x00 };
1119             rb1.getBinary(ba);
1120             errln("getBinary(byte[]) call should have thrown UResourceTypeMismatchException.");
1121         } catch (UResourceTypeMismatchException ex) {
1122         }
1123         try {
1124             rb1.getInt();
1125             errln("getInt() call should have thrown UResourceTypeMismatchException.");
1126         } catch (UResourceTypeMismatchException ex) {
1127         }
1128         try {
1129             rb1.getIntVector();
1130             errln("getIntVector() call should have thrown UResourceTypeMismatchException.");
1131         } catch (UResourceTypeMismatchException ex) {
1132         }
1133         try {
1134             rb1.getUInt();
1135             errln("getUInt() call should have thrown UResourceTypeMismatchException.");
1136         } catch (UResourceTypeMismatchException ex) {
1137         }
1138         if (rb1.getVersion() != null) {
1139             errln("getVersion() call should have returned null.");
1140         }
1141         if (rb7.getType() != UResourceBundle.NONE) {
1142             errln("getType() call should have returned NONE.");
1143         }
1144         if (rb7.getKey() != null) {
1145             errln("getKey() call should have returned null.");
1146         }
1147         if (((ICUResourceBundle)rb1).findTopLevel(0) == null) {
1148             errln("Error calling findTopLevel().");
1149         }
1150         if (ICUResourceBundle.getFullLocaleNameSet() == null) {
1151             errln("Error calling getFullLocaleNameSet().");
1152         }
1153         UResourceBundleIterator itr = rb1.getIterator();
1154         while (itr.hasNext()) {
1155             itr.next();
1156         }
1157         try {
1158             itr.next();
1159             errln("NoSuchElementException exception should have been thrown.");
1160         } catch (NoSuchElementException ex) {
1161         }
1162         try {
1163             itr.nextString();
1164             errln("NoSuchElementException exception should have been thrown.");
1165         } catch (NoSuchElementException ex) {
1166         }
1167     }
1168 }
1169