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