Source Code Cross Referenced for ICUListResourceBundleTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.dev.test.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *******************************************************************************
003:         * Copyright (C) 2001-2006, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */package com.ibm.icu.dev.test.util;
007:
008:        import java.util.ResourceBundle;
009:
010:        import com.ibm.icu.dev.test.TestFmwk;
011:        import com.ibm.icu.impl.Utility;
012:
013:        public final class ICUListResourceBundleTest extends TestFmwk {
014:            public static void main(String args[]) throws Exception {
015:                ICUListResourceBundleTest test = new ICUListResourceBundleTest();
016:                test.run(args);
017:
018:            }
019:
020:            public void TestReferences() {
021:                // ResourceBundle rb = ICULocaleData.getLocaleElements("th");
022:                //logln("got rb:" + rb);
023:                ResourceBundle rb = null;
024:                byte[] binaryData = null;//(byte[])rb.getObject("%%CollationBin");
025:                Object colElem = rb.getObject("collations");
026:                if (colElem instanceof  Object[][]) {
027:                    Object[][] colElemArr = (Object[][]) colElem;
028:                    if (((String) colElemArr[0][0]).equals("%%CollationBin")) {
029:                        binaryData = (byte[]) colElemArr[0][1];
030:                    }
031:                } else {
032:                    errln("Did not get the expected object");
033:                }
034:                logln("got binaryData: " + binaryData + " length: "
035:                        + (binaryData == null ? 0 : binaryData.length));
036:                Object[] stringArrayData = (Object[]) rb
037:                        .getObject("collations");
038:                //String[] collationData = new String[] {
039:                //   (String)stringArrayData[0],
040:                //   (String)stringArrayData[0]
041:                //};
042:                logln("got stringData: " + stringArrayData + " length: "
043:                        + stringArrayData.length);
044:                logln("got stringDataElement: " + stringArrayData[0]
045:                        + " length: " + stringArrayData.length);
046:                //System.out.println("got sdee: " + collationData[0]);
047:                //    System.out.println("char data length: " + stringArrayData.length());
048:            }
049:
050:            String simpleAlias = "Open";
051:
052:            Object[][] zoneTests = new Object[][] {
053:                    {
054:                            "zoneAlias",
055:                            new String[] { "PST", "Pacific Standard Time",
056:                                    "PST", "Pacific Daylight Time", "PDT",
057:                                    "Los Angeles", }, },
058:                    {
059:                            "zoneAlias1",
060:                            new String[] { "America/Denver",
061:                                    "Mountain Standard Time", "MST",
062:                                    "Mountain Daylight Time", "MDT", "Denver",
063:
064:                            }, }, { "zoneAlias2", "America/Denver", }, };
065:            Object[] zoneStrings = new Object[] {
066:                    new String[] {
067:
068:                    "PST", "Pacific Standard Time", "PST",
069:                            "Pacific Daylight Time", "PDT", "Los Angeles",
070:
071:                    },
072:                    new String[] { "America/Los_Angeles",
073:                            "Pacific Standard Time", "PST",
074:                            "Pacific Daylight Time", "PDT", "Los Angeles",
075:
076:                    }, };
077:            Object[] testGetStringByIndexAliasing = new String[] { "PST",
078:                    "Pacific Standard Time", "PDT", "Los Angeles", };
079:            Object[][] testGetStringByKeyAliasing = new Object[][] {
080:                    { "KeyAlias0PST", "PST", },
081:                    { "KeyAlias1PacificStandardTime", "Pacific Standard Time", },
082:                    { "KeyAlias2PDT", "PDT", },
083:                    { "KeyAlias3LosAngeles", "Los Angeles", }, };
084:
085:            private boolean arrayEquals(Object[][] s1, Object[][] s2) {
086:                boolean isEqual = true;
087:                if (s1.length != s2.length) {
088:                    return false;
089:                }
090:                for (int i = 0; i < s1.length; i++) {
091:                    if (s1[i] instanceof  Object[][]
092:                            && s2[i] instanceof  Object[][]) {
093:                        if (!arrayEquals((Object[][]) s1[i], (Object[][]) s2[i])) {
094:                            isEqual = false;
095:                        }
096:                    } else if (s1[i] instanceof  Object[]
097:                            && s2[i] instanceof  Object[]) {
098:                        if (!Utility.arrayEquals(s1[i], s2[i])) {
099:                            isEqual = false;
100:                        }
101:                    } else if (s1[i] instanceof  Object
102:                            && s2[i] instanceof  Object) {
103:                        if (!s1[i].equals(s2[i])) {
104:                            isEqual = false;
105:                        }
106:                    } else {
107:                        isEqual = false;
108:                        break;
109:                    }
110:                }
111:                return isEqual;
112:            }
113:
114:            /* 
115:            public void TestAliases(){
116:                ResourceBundle rb = ICULocaleData.getResourceBundle("com.ibm.icu.dev.data","TestDataElements","testaliases");
117:                //rb.getObject("CollationElements");
118:                String s1 = rb.getString("simplealias");
119:                if(s1.equals(simpleAlias)){
120:                    logln("Alias mechanism works for simplealias");
121:                }else{
122:                    errln("Did not get the expected output for simplealias");
123:                }
124:                {
125:                    Object o = null;
126:                    // test aliasing through another alias
127:                    s1 = rb.getString("referencingalias");
128:                    ResourceBundle uk = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","uk");
129:                    if(uk instanceof ICUListResourceBundle){
130:                        o = ((ICUListResourceBundle)uk).getObjectWithFallback("collations/standard");
131:                        if(o instanceof Object[][]){
132:                            Object[][] val = (Object[][]) o;
133:                            if(s1.equals(val[1][1])){
134:                                logln("Alias mechanism works for referencingalias");
135:                            }else{
136:                                errln("Did not get the expected result for referencingalias");
137:                            }
138:                        }else{
139:                            errln("Did not get the expected result for collations resource of uk bundle");
140:                        }
141:                    }
142:                    Object anotheralias = rb.getObject("anotheralias");
143:                    if(anotheralias instanceof Object[][]&& o instanceof Object[][]){
144:                        if(arrayEquals((Object[][])o, (Object[][])anotheralias)){
145:                            logln("Alias mechanism works for anotheralias");
146:                        }else{
147:                            errln("Did not get the expected output for anotheralias");
148:                        }
149:                    
150:                    }else{
151:                        errln("Alias mechanism failed for anotheralias in TestAlias");
152:                    }
153:                    o = ((ICUListResourceBundle)uk).getObject("collations");
154:                    Object o1 = rb.getObject("collations");
155:                    if(o1 instanceof Object[][]&& o instanceof Object[][]){
156:                        if(arrayEquals((Object[][])o, (Object[][])o1)){
157:                            logln("Alias mechanism works for CollationElements");
158:                        }else{
159:                            errln("Did not get the expected output for collations");
160:                        }
161:                    
162:                    }else{
163:                        errln("Alias mechanism failed for collations in TestAlias");
164:                    }
165:            
166:                }
167:                                
168:                Object o1 = rb.getObject("zoneTests");
169:                if(o1 instanceof Object[][]){
170:                    if(arrayEquals(zoneTests, (Object[][])o1)){
171:                        logln("Alias mechanism works for zoneTests");
172:                    }else{
173:                        errln("Did not get the expected output for zoneTests");
174:                    }
175:                    
176:                }else{
177:                    errln("Alias mechanism failed for zoneTest in TestAlias");
178:                }
179:                o1 = rb.getObject("zoneStrings");
180:                if(o1 instanceof Object[]){
181:                    if(Utility.arrayEquals(zoneStrings, (Object[])o1)){
182:                        logln("Alias mechanism works for zoneStrings");
183:                    }else{
184:                        errln("Did not get the expected output for zoneStrings");
185:                    }
186:                    
187:                }else{
188:                    errln("Alias mechanism failed for zoneStrings in TestAlias");
189:                }
190:                o1 = rb.getObject("testGetStringByIndexAliasing");
191:                if(o1 instanceof Object[]){
192:                    if(Utility.arrayEquals(testGetStringByIndexAliasing, (Object[])o1)){
193:                        logln("Alias mechanism works for testGetStringByIndexAliasing");
194:                    }else{
195:                        errln("Did not get the expected output for testGetStringByIndexAliasing");
196:                    }
197:                    
198:                }else{
199:                    errln("Alias mechanism failed for testGetStringByIndexAliasing in TestAlias");
200:                }
201:                
202:                o1 = rb.getObject("testGetStringByKeyAliasing");
203:                if(o1 instanceof Object[][]){
204:                    if(arrayEquals(testGetStringByKeyAliasing, (Object[][])o1)){
205:                        logln("Alias mechanism works for testGetStringByKeyAliasing");
206:                    }else{
207:                        errln("Did not get the expected output for testGetStringByKeyAliasing");
208:                    }
209:                    
210:                }else{
211:                    errln("Alias mechanism failed for testGetStringByKeyAliasing in TestAlias");
212:                }
213:                /* should not get an exception
214:                rb = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","fr_BE");
215:                Object o = rb.getObject("SpelloutRules");
216:                if(o instanceof String){
217:                    logln("Alias mechanism works");
218:                }else{
219:                    errln("Alias mechanism failed for fr_BE SpelloutRules");
220:                }
221:                rb = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","zh_TW");
222:                o = rb.getObject("collations");
223:                if(o instanceof Object[][]){
224:                    Object[][] arr = (Object[][])o;
225:                    if(((String)arr[0][0])== "default"){
226:                        logln("Alias mechanism works");
227:                    }else{
228:                        errln("Alias mechanism failed for zh_TW collations");
229:                    }
230:                }else{
231:                    errln("Did not get the expected object for collations");
232:                }
233:                
234:                
235:            }
236:             */
237:            /*
238:            public void TestCircularAliases(){
239:                try{
240:                    ResourceBundle rb = ICULocaleData.getResourceBundle("com.ibm.icu.dev.data","TestDataElements","testcircularalias");
241:                    rb.getObject("aaa");
242:                }catch(java.util.MissingResourceException e){
243:                    if(e.toString().indexOf("ircular")==-1){
244:                        errln("Did not get the expected Exception for circular aliases");
245:                    }
246:                    return;
247:                }
248:                errln("Did not get the expected Exception for circular aliases");
249:            }*/
250:            /*
251:            public void TestGetObjectWithFallback(){
252:                ResourceBundle bundle = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","te_IN");
253:                if(bundle instanceof ICUListResourceBundle){
254:                    ICUListResourceBundle ilrb = (ICUListResourceBundle) bundle;
255:                    String key = (String) ilrb.getObjectWithFallback("Keys/collation");
256:                    if(!key.equals("COLLATION")){
257:                        errln("Did not get the expected result from getObjectWithFallback method.");
258:                    }
259:                    String type = (String) ilrb.getObjectWithFallback("Types/collation/direct");
260:                    if(!type.equals("DIRECT")){
261:                        errln("Did not get the expected result form getObjectWithFallback method.");
262:                    }
263:                }else{
264:                    errln("Did not get the expected bundle.");
265:                }
266:
267:                try{
268:                    ResourceBundle bundle1 = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","de__PHONEBOOK");
269:                    if(bundle instanceof ICUListResourceBundle){
270:                        ICUListResourceBundle ilrb = (ICUListResourceBundle) bundle1;
271:                        String key = (String) ilrb.getObjectWithFallback("collations/collation/default");
272:                        if(!key.equals("phonebook")){
273:                            errln("Did not get the expected result from getObjectWithFallback method.");
274:                        }
275:            
276:                    }else{
277:                        errln("Did not get the expected bundle.");
278:                    } 
279:                    errln("Did not get the expected exception.");
280:                }catch(MissingResourceException ex){
281:                    logln("got the expected exception");
282:                }
283:
284:                
285:                ResourceBundle bundle1 = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","fr_FR");
286:                if(bundle instanceof ICUListResourceBundle){
287:                    ICUListResourceBundle ilrb = (ICUListResourceBundle) bundle1;
288:                    String key = (String) ilrb.getObjectWithFallback("collations/default");
289:                    if(!key.equals("standard")){
290:                        errln("Did not get the expected result from getObjectWithFallback method.");
291:                    }
292:
293:                }else{
294:                    errln("Did not get the expected bundle.");
295:                } 
296:                
297:                bundle1 = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","es_ES");
298:                if(bundle instanceof ICUListResourceBundle){
299:                    ICUListResourceBundle ilrb = (ICUListResourceBundle) bundle1;
300:                    String key = (String) ilrb.getObjectWithFallback("collations/default");
301:                    if(!key.equals("standard")){
302:                        errln("Did not get the expected result from getObjectWithFallback method.");
303:                    }
304:                    String nkey = "collations/" + key;
305:                    Object o = ilrb.getObjectWithFallback(nkey);
306:                    if(o instanceof Object[][]){
307:                        if(!((String) ((Object[][])o)[0][0]).equals("%%CollationBin")){
308:                            errln("Did not get the expected object for "+ nkey); 
309:                        }else{
310:                            logln("Got the expected object for "+ nkey); 
311:                        }
312:                    }else{
313:                        errln("Did not get the expected object for "+ nkey); 
314:                    }
315:                }else{
316:                    errln("Did not get the expected bundle.");
317:                }        
318:            }*/
319:
320:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.