Source Code Cross Referenced for LocaleAliasTest.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) 2005-2006, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:
008:        /*
009:         * New added, 2005-5-10 [Terry/SGL]
010:         * Major modification by Ram
011:         */
012:
013:        package com.ibm.icu.dev.test.util;
014:
015:        import java.util.HashMap;
016:
017:        import com.ibm.icu.impl.ICUResourceBundle;
018:        import com.ibm.icu.text.Collator;
019:        import com.ibm.icu.text.DateFormat;
020:        import com.ibm.icu.util.Calendar;
021:        import com.ibm.icu.util.ULocale;
022:        import com.ibm.icu.util.UResourceBundle;
023:
024:        public class LocaleAliasTest extends com.ibm.icu.dev.test.TestFmwk {
025:            private static final ULocale[][] _LOCALES = {
026:
027:            { new ULocale("en", "RH"), new ULocale("en", "ZW") },
028:                    { new ULocale("in"), new ULocale("id") },
029:                    { new ULocale("in", "ID"), new ULocale("id", "ID") },
030:                    { new ULocale("iw"), new ULocale("he") },
031:                    { new ULocale("iw", "IL"), new ULocale("he", "IL") },
032:                    { new ULocale("ji"), new ULocale("yi") },
033:
034:                    { new ULocale("en", "BU"), new ULocale("en", "MM") },
035:                    { new ULocale("en", "DY"), new ULocale("en", "BJ") },
036:                    { new ULocale("en", "HV"), new ULocale("en", "BF") },
037:                    { new ULocale("en", "NH"), new ULocale("en", "VU") },
038:                    { new ULocale("en", "TP"), new ULocale("en", "TL") },
039:                    { new ULocale("en", "ZR"), new ULocale("en", "CD") } };
040:
041:            private static final int _LOCALE_NUMBER = _LOCALES.length;
042:            private static ULocale[] available = null;
043:            private HashMap availableMap = new HashMap();
044:            private static final ULocale _DEFAULT_LOCALE = ULocale.US;
045:
046:            public LocaleAliasTest() {
047:            }
048:
049:            protected void init() {
050:                available = ULocale.getAvailableLocales();
051:                for (int i = 0; i < available.length; i++) {
052:                    availableMap.put(available[i].toString(), "");
053:                }
054:            }
055:
056:            public static void main(String[] args) {
057:                new LocaleAliasTest().run(args);
058:            }
059:
060:            public void TestCalendar() {
061:                ULocale defLoc = ULocale.getDefault();
062:                ULocale.setDefault(_DEFAULT_LOCALE);
063:                for (int i = 0; i < _LOCALE_NUMBER; i++) {
064:                    ULocale oldLoc = _LOCALES[i][0];
065:                    ULocale newLoc = _LOCALES[i][1];
066:                    if (availableMap.get(_LOCALES[i][1]) == null) {
067:                        logln(_LOCALES[i][1] + " is not available. Skipping!");
068:                        continue;
069:                    }
070:                    Calendar c1 = Calendar.getInstance(oldLoc);
071:                    Calendar c2 = Calendar.getInstance(newLoc);
072:                    c1.setTime(c2.getTime());
073:                    //Test function "getFirstDayOfWeek"
074:                    //        int firstDayOfWeek1 = c1.getFirstDayOfWeek();
075:                    //        int firstDayOfWeek2 = c2.getFirstDayOfWeek();
076:                    //        if (firstDayOfWeek1 != firstDayOfWeek2) {
077:                    //            this.logln("Calendar(getFirstDayOfWeek) old:"
078:                    //                    +firstDayOfWeek1+"   new:"+firstDayOfWeek2);
079:                    //            pass = false;
080:                    //        }
081:
082:                    //Test function "getLocale(ULocale.VALID_LOCALE)"
083:                    ULocale l1 = c1.getLocale(ULocale.VALID_LOCALE);
084:                    ULocale l2 = c2.getLocale(ULocale.VALID_LOCALE);
085:                    if (!newLoc.equals(l1)) {
086:                        errln("CalendarTest: newLoc!=l1: newLoc= " + newLoc
087:                                + " l1= " + l1);
088:                    }
089:                    if (!l1.equals(l2)) {
090:                        errln("CalendarTest: l1!=l2: l1= " + l1 + " l2= " + l2);
091:                    }
092:                    if (!c1.equals(c2)) {
093:                        errln("CalendarTest: c1!=c2.  newLoc= " + newLoc
094:                                + " oldLoc= " + oldLoc);
095:                    }
096:                    logln("Calendar(getLocale) old:" + l1 + "   new:" + l2);
097:                }
098:
099:            }
100:
101:            public void TestDateFormat() {
102:                ULocale defLoc = ULocale.getDefault();
103:                ULocale.setDefault(_DEFAULT_LOCALE);
104:                for (int i = 0; i < _LOCALE_NUMBER; i++) {
105:                    ULocale oldLoc = _LOCALES[i][0];
106:                    ULocale newLoc = _LOCALES[i][1];
107:                    if (availableMap.get(_LOCALES[i][1]) == null) {
108:                        logln(_LOCALES[i][1] + " is not available. Skipping!");
109:                        continue;
110:                    }
111:                    DateFormat df1 = DateFormat.getDateInstance(
112:                            DateFormat.FULL, oldLoc);
113:                    DateFormat df2 = DateFormat.getDateInstance(
114:                            DateFormat.FULL, newLoc);
115:
116:                    //Test function "getLocale"
117:                    ULocale l1 = df1.getLocale(ULocale.VALID_LOCALE);
118:                    ULocale l2 = df2.getLocale(ULocale.VALID_LOCALE);
119:                    if (!newLoc.equals(l1)) {
120:                        errln("DateFormatTest: newLoc!=l1: newLoc= " + newLoc
121:                                + " l1= " + l1);
122:                    }
123:                    if (!l1.equals(l2)) {
124:                        errln("DateFormatTest: l1!=l2: l1= " + l1 + " l2= "
125:                                + l2);
126:                    }
127:                    if (!df1.equals(df2)) {
128:                        errln("DateFormatTest: df1!=df2: newLoc= " + newLoc
129:                                + " oldLoc= " + oldLoc);
130:                    }
131:                    this .logln("DateFormat(getLocale) old:" + l1 + "   new:"
132:                            + l2);
133:
134:                    //Test function "format"
135:                    //        Date d = new Date();
136:                    //        String d1 = df1.format(d);
137:                    //        String d2 = df2.format(d);
138:                    //        if (!d1.equals(d2)) {
139:                    //            pass = false;
140:                    //        }
141:                    //        this.logln("DateFormat(format) old:"+d1+"   new:"+d2);
142:                }
143:            }
144:
145:            public void TestCollation() {
146:                ULocale defLoc = ULocale.getDefault();
147:                ULocale.setDefault(_DEFAULT_LOCALE);
148:                for (int i = 0; i < _LOCALE_NUMBER; i++) {
149:                    ULocale oldLoc = _LOCALES[i][0];
150:                    ULocale newLoc = _LOCALES[i][1];
151:                    if (availableMap.get(_LOCALES[i][1]) == null) {
152:                        logln(_LOCALES[i][1] + " is not available. Skipping!");
153:                        continue;
154:                    }
155:                    Collator c1 = Collator.getInstance(oldLoc);
156:                    Collator c2 = Collator.getInstance(newLoc);
157:
158:                    if (!c1.equals(c2)) {
159:                        errln("CollationTest: c1!=c2: newLoc= " + newLoc
160:                                + " oldLoc= " + oldLoc);
161:                    }
162:
163:                    logln("Collation old:" + oldLoc + "   new:" + newLoc);
164:                }
165:            }
166:
167:            public void TestULocale() {
168:                ULocale defLoc = ULocale.getDefault();
169:                ULocale.setDefault(_DEFAULT_LOCALE);
170:                for (int i = 0; i < _LOCALE_NUMBER; i++) {
171:                    ULocale oldLoc = _LOCALES[i][0];
172:                    ULocale newLoc = _LOCALES[i][1];
173:                    if (availableMap.get(_LOCALES[i][1]) == null) {
174:                        logln(_LOCALES[i][1] + " is not available. Skipping!");
175:                        continue;
176:                    }
177:                    ULocale ul1 = new ULocale(oldLoc.toString());
178:                    ULocale ul2 = new ULocale(newLoc.toString());
179:
180:                    String name1 = ul1.getDisplayName();
181:                    String name2 = ul2.getDisplayName();
182:                    if (!name1.equals(name2)) {
183:                        errln("name1!=name2. name1 = " + name1 + " name2 = "
184:                                + name2);
185:                    }
186:                    logln("ULocale(getDisplayName) old:" + name1 + "   new:"
187:                            + name2);
188:                }
189:            }
190:
191:            public void TestDisplayName() {
192:                ULocale defLoc = ULocale.getDefault();
193:                ULocale.setDefault(_DEFAULT_LOCALE);
194:                for (int i = 0; i < _LOCALE_NUMBER; i++) {
195:                    ULocale oldLoc = _LOCALES[i][0];
196:                    ULocale newLoc = _LOCALES[i][1];
197:
198:                    for (int j = 0; j < available.length; j++) {
199:                        String oldCountry = oldLoc
200:                                .getDisplayCountry(available[j]);
201:                        String newCountry = newLoc
202:                                .getDisplayCountry(available[j]);
203:                        String oldLang = oldLoc
204:                                .getDisplayLanguage(available[j]);
205:                        String newLang = newLoc
206:                                .getDisplayLanguage(available[j]);
207:
208:                        // is  there  display name for the current country ID               
209:                        if (!newCountry.equals(newLoc.getCountry())) {
210:                            if (!oldCountry.equals(newCountry)) {
211:                                errln("getCountry() failed for " + oldLoc
212:                                        + " oldCountry= "
213:                                        + prettify(oldCountry)
214:                                        + " newCountry = "
215:                                        + prettify(newCountry)
216:                                        + " in display locale "
217:                                        + available[j].toString());
218:                            }
219:                        }
220:                        //there is a display name for the current lang ID               
221:                        if (!newLang.equals(newLoc.getLanguage())) {
222:                            if (!oldLang.equals(newLang)) {
223:                                errln("getLanguage() failed for " + oldLoc
224:                                        + " oldLang = " + prettify(oldLang)
225:                                        + " newLang = " + prettify(newLang)
226:                                        + " in display locale "
227:                                        + available[j].toString());
228:                            }
229:                        }
230:                    }
231:                }
232:            }
233:
234:            public void TestUResourceBundle() {
235:                ULocale defLoc = ULocale.getDefault();
236:                ULocale.setDefault(_DEFAULT_LOCALE);
237:                for (int i = 0; i < _LOCALE_NUMBER; i++) {
238:                    if (availableMap.get(_LOCALES[i][1]) == null) {
239:                        logln(_LOCALES[i][1] + " is not available. Skipping!");
240:                        continue;
241:                    }
242:                    ULocale oldLoc = _LOCALES[i][0];
243:                    ULocale newLoc = _LOCALES[i][1];
244:                    UResourceBundle urb1 = null;
245:                    UResourceBundle urb2 = null;
246:
247:                    urb1 = UResourceBundle.getBundleInstance(
248:                            ICUResourceBundle.ICU_BASE_NAME, oldLoc);
249:                    urb2 = UResourceBundle.getBundleInstance(
250:                            ICUResourceBundle.ICU_BASE_NAME, newLoc);
251:                    ULocale l1 = urb1.getULocale();
252:                    ULocale l2 = urb2.getULocale();
253:                    if (!newLoc.equals(l1)) {
254:                        errln("ResourceBundleTest: newLoc!=l1: newLoc= "
255:                                + newLoc + " l1= " + l1);
256:                    }
257:                    if (!l1.equals(l2)) {
258:                        errln("ResourceBundleTest: l1!=l2: l1= " + l1 + " l2= "
259:                                + l2);
260:                    }
261:                    this .logln("UResourceBundle old:" + l1 + "   new:" + l2);
262:                }
263:            }
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.