Source Code Cross Referenced for GlobalizationPreferencesTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » format » 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.format 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        //##header
0002:        /*
0003:         *******************************************************************************
0004:         * Copyright (C) 2004-2006, International Business Machines Corporation and    *
0005:         * others. All Rights Reserved.                                                *
0006:         *******************************************************************************
0007:         */
0008:
0009:        package com.ibm.icu.dev.test.format;
0010:
0011:        import java.util.ArrayList;
0012:        import java.util.List;
0013:        import java.util.MissingResourceException;
0014:        import java.util.ResourceBundle;
0015:
0016:        import com.ibm.icu.dev.test.TestFmwk;
0017:        import com.ibm.icu.text.BreakIterator;
0018:        import com.ibm.icu.text.Collator;
0019:        import com.ibm.icu.text.DateFormat;
0020:        import com.ibm.icu.text.NumberFormat;
0021:        import com.ibm.icu.text.SimpleDateFormat;
0022:        import com.ibm.icu.util.BuddhistCalendar;
0023:        import com.ibm.icu.util.Calendar;
0024:        import com.ibm.icu.util.Currency;
0025:        import com.ibm.icu.util.GlobalizationPreferences;
0026:        import com.ibm.icu.util.GregorianCalendar;
0027:        import com.ibm.icu.util.IslamicCalendar;
0028:        import com.ibm.icu.util.JapaneseCalendar;
0029:        import com.ibm.icu.util.TimeZone;
0030:        import com.ibm.icu.util.ULocale;
0031:
0032:        public class GlobalizationPreferencesTest extends TestFmwk {
0033:
0034:            public static void main(String[] args) throws Exception {
0035:                new GlobalizationPreferencesTest().run(args);
0036:            }
0037:
0038:            public void TestDefault() {
0039:                GlobalizationPreferences gp = new GlobalizationPreferences();
0040:                ULocale defLocale = new ULocale("en_US");
0041:                ULocale defFallbackLocale = new ULocale("en");
0042:
0043:                if (!defLocale.equals(ULocale.getDefault())) {
0044:                    // Locale.US is always used as the default locale in the test environment
0045:                    // If not, some test cases will fail...
0046:                    errln("FAIL: The default locale of the test environment must be en_US");
0047:                }
0048:
0049:                logln("Default locale: " + defLocale.toString());
0050:
0051:                // First locale is en_US
0052:                ULocale gpLocale0 = gp.getLocale(0);
0053:                logln("Primary locale: " + gpLocale0.toString());
0054:                if (!gpLocale0.equals(defLocale)) {
0055:                    errln("FAIL: The primary locale is not en_US");
0056:                }
0057:
0058:                // Second locale is en
0059:                ULocale gpLocale1 = gp.getLocale(1);
0060:                logln("Secondary locale: " + gpLocale1.toString());
0061:                if (!gpLocale1.equals(defFallbackLocale)) {
0062:                    errln("FAIL: The secondary locale is not en");
0063:                }
0064:
0065:                // Third locale is null
0066:                ULocale gpLocale2 = gp.getLocale(2);
0067:                if (gpLocale2 != null) {
0068:                    errln("FAIL: Number of locales must be 2");
0069:                }
0070:
0071:                // Calendar locale
0072:                Calendar cal = gp.getCalendar();
0073:                ULocale calLocale = cal.getLocale(ULocale.VALID_LOCALE);
0074:                logln("Calendar locale: " + calLocale.toString());
0075:                if (!calLocale.equals(defLocale)) {
0076:                    errln("FAIL: The calendar locale must match with the default JVM locale");
0077:                }
0078:
0079:                // Collator locale
0080:                Collator coll = gp.getCollator();
0081:                ULocale collLocale = coll.getLocale(ULocale.VALID_LOCALE);
0082:                logln("Collator locale: " + collLocale.toString());
0083:                if (!collLocale.equals(defLocale)) {
0084:                    errln("FAIL: The collator locale must match with the default JVM locale");
0085:                }
0086:
0087:                // BreakIterator locale
0088:                BreakIterator brk = gp
0089:                        .getBreakIterator(GlobalizationPreferences.BI_CHARACTER);
0090:                ULocale brkLocale = brk.getLocale(ULocale.VALID_LOCALE);
0091:                logln("BreakIterator locale: " + brkLocale.toString());
0092:                if (!brkLocale.equals(defLocale)) {
0093:                    errln("FAIL: The break iterator locale must match with the default JVM locale");
0094:                }
0095:
0096:                /* Skip - Bug#5209
0097:                // DateFormat locale
0098:                DateFormat df = gp.getDateFormat(GlobalizationPreferences.DF_FULL, GlobalizationPreferences.DF_NONE);
0099:                ULocale dfLocale = df.getLocale(ULocale.VALID_LOCALE);
0100:                logln("DateFormat locale: " + dfLocale.toString());
0101:                if (!dfLocale.equals(defLocale)) {
0102:                    errln("FAIL: The date format locale must match with the default JVM locale");
0103:                }
0104:                 */
0105:
0106:                // NumberFormat locale
0107:                NumberFormat nf = gp
0108:                        .getNumberFormat(GlobalizationPreferences.NF_NUMBER);
0109:                ULocale nfLocale = nf.getLocale(ULocale.VALID_LOCALE);
0110:                logln("NumberFormat locale: " + nfLocale.toString());
0111:                if (!nfLocale.equals(defLocale)) {
0112:                    errln("FAIL: The number format locale must match with the default JVM locale");
0113:                }
0114:            }
0115:
0116:            public void TestFreezable() {
0117:                logln("Create a new GlobalizationPreference object");
0118:                GlobalizationPreferences gp = new GlobalizationPreferences();
0119:                if (gp.isFrozen()) {
0120:                    errln("FAIL: This object is not yet frozen");
0121:                }
0122:
0123:                logln("Call reset()");
0124:                boolean bSet = true;
0125:                try {
0126:                    gp.reset();
0127:                } catch (UnsupportedOperationException uoe) {
0128:                    bSet = false;
0129:                }
0130:                if (!bSet) {
0131:                    errln("FAIL: reset() must not throw an exception before frozen");
0132:                }
0133:
0134:                // Freeze the object
0135:                logln("Freeze the object");
0136:                gp.freeze();
0137:                if (!gp.isFrozen()) {
0138:                    errln("FAIL: This object is already fronzen");
0139:                }
0140:
0141:                // reset()
0142:                logln("Call reset() after frozen");
0143:                bSet = true;
0144:                try {
0145:                    gp.reset();
0146:                } catch (UnsupportedOperationException uoe) {
0147:                    bSet = false;
0148:                }
0149:                if (bSet) {
0150:                    errln("FAIL: reset() must be blocked after frozen");
0151:                }
0152:
0153:                // setLocales(ULocale[])
0154:                logln("Call setLocales(ULocale[]) after frozen");
0155:                bSet = true;
0156:                try {
0157:                    gp.setLocales(new ULocale[] { new ULocale("fr_FR") });
0158:                } catch (UnsupportedOperationException uoe) {
0159:                    bSet = false;
0160:                }
0161:                if (bSet) {
0162:                    errln("FAIL: setLocales(ULocale[]) must be blocked after frozen");
0163:                }
0164:
0165:                // setLocales(ULocale[])
0166:                logln("Call setLocales(List) after frozen");
0167:                bSet = true;
0168:                ArrayList list = new ArrayList(1);
0169:                list.add(new ULocale("fr_FR"));
0170:                try {
0171:                    gp.setLocales(list);
0172:                } catch (UnsupportedOperationException uoe) {
0173:                    bSet = false;
0174:                }
0175:                if (bSet) {
0176:                    errln("FAIL: setLocales(List) must be blocked after frozen");
0177:                }
0178:
0179:                //#ifndef FOUNDATION
0180:                // setLocales(String)
0181:                logln("Call setLocales(String) after frozen");
0182:                bSet = true;
0183:                try {
0184:                    gp.setLocales("pt-BR,es;q=0.7");
0185:                } catch (UnsupportedOperationException uoe) {
0186:                    bSet = false;
0187:                }
0188:                if (bSet) {
0189:                    errln("FAIL: setLocales(String) must be blocked after frozen");
0190:                }
0191:                //#endif
0192:
0193:                // setLocale(ULocale)
0194:                logln("Call setLocale(ULocale) after frozen");
0195:                bSet = true;
0196:                try {
0197:                    gp.setLocale(new ULocale("fi_FI"));
0198:                } catch (UnsupportedOperationException uoe) {
0199:                    bSet = false;
0200:                }
0201:                if (bSet) {
0202:                    errln("FAIL: setLocale(ULocale) must be blocked after frozen");
0203:                }
0204:
0205:                // setTerritory(String)
0206:                logln("Call setTerritory(String) after frozen");
0207:                bSet = true;
0208:                try {
0209:                    gp.setTerritory("AU");
0210:                } catch (UnsupportedOperationException uoe) {
0211:                    bSet = false;
0212:                }
0213:                if (bSet) {
0214:                    errln("FAIL: setTerritory(String) must be blocked after frozen");
0215:                }
0216:
0217:                // Modifiable clone
0218:                logln("Create a modifiable clone");
0219:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0220:                        .cloneAsThawed();
0221:
0222:                if (gp1.isFrozen()) {
0223:                    errln("FAIL: The object returned by cloneAsThawed() must not be frozen yet");
0224:                }
0225:
0226:                // setLocale(ULocale)
0227:                logln("Call setLocale(ULocale) of the modifiable clone");
0228:                bSet = true;
0229:                try {
0230:                    gp1.setLocale(new ULocale("fr_FR"));
0231:                } catch (UnsupportedOperationException uoe) {
0232:                    bSet = false;
0233:                }
0234:                if (!bSet) {
0235:                    errln("FAIL: setLocales(ULocale) must not throw an exception before frozen");
0236:                }
0237:            }
0238:
0239:            static String[][] INPUT_LOCALEIDS = { { "en_US" },
0240:                    { "fr_CA", "fr" }, { "fr", "fr_CA" },
0241:                    { "es", "fr", "en_US" },
0242:                    { "zh_CN", "zh_Hans", "zh_Hans_CN" } };
0243:
0244:            static String[] ACCEPT_LANGUAGES = { "en-US", "fr-CA,fr;q=0.5",
0245:                    "fr_CA;q=0.5,fr", "es,fr;q=0.76,en_US;q=0.75",
0246:                    "zh-CN,zh-Hans;q=0.5,zh-Hans-CN;q=0.1" };
0247:
0248:            static String[][] RESULTS_LOCALEIDS = { { "en_US", "en" },
0249:                    { "fr_CA", "fr" }, { "fr_CA", "fr" },
0250:                    { "es", "fr", "en_US", "en" },
0251:                    { "zh_Hans_CN", "zh_CN", "zh_Hans", "zh" } };
0252:
0253:            public void TestSetLocales() {
0254:                GlobalizationPreferences gp = new GlobalizationPreferences();
0255:
0256:                // setLocales(List)
0257:                for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
0258:                    String[] localeStrings = INPUT_LOCALEIDS[i];
0259:                    ArrayList locales = new ArrayList();
0260:                    StringBuffer sb = new StringBuffer();
0261:                    for (int j = 0; j < localeStrings.length; j++) {
0262:                        locales.add(new ULocale(localeStrings[j]));
0263:                        if (j != 0) {
0264:                            sb.append(", ");
0265:                        }
0266:                        sb.append(localeStrings[j]);
0267:                    }
0268:                    logln("Input locales: " + sb.toString());
0269:
0270:                    gp.reset();
0271:                    gp.setLocales(locales);
0272:
0273:                    List resultLocales = gp.getLocales();
0274:                    if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
0275:                        errln("FAIL: Number of locales mismatch - GP:"
0276:                                + resultLocales.size() + " Expected:"
0277:                                + RESULTS_LOCALEIDS[i].length);
0278:                    } else {
0279:
0280:                        for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
0281:                            ULocale loc = gp.getLocale(j);
0282:                            logln("Locale[" + j + "]: " + loc.toString());
0283:                            if (!gp.getLocale(j).toString().equals(
0284:                                    RESULTS_LOCALEIDS[i][j])) {
0285:                                errln("FAIL: Locale index(" + j
0286:                                        + ") does not match - GP:"
0287:                                        + loc.toString() + " Expected:"
0288:                                        + RESULTS_LOCALEIDS[i][j]);
0289:                            }
0290:                        }
0291:                    }
0292:                }
0293:
0294:                // setLocales(ULocale[])
0295:                for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
0296:                    String[] localeStrings = INPUT_LOCALEIDS[i];
0297:                    ULocale[] localeArray = new ULocale[INPUT_LOCALEIDS[i].length];
0298:                    StringBuffer sb = new StringBuffer();
0299:                    for (int j = 0; j < localeStrings.length; j++) {
0300:                        localeArray[j] = new ULocale(localeStrings[j]);
0301:                        if (j != 0) {
0302:                            sb.append(", ");
0303:                        }
0304:                        sb.append(localeStrings[j]);
0305:                    }
0306:                    logln("Input locales: " + sb.toString());
0307:
0308:                    gp.reset();
0309:                    gp.setLocales(localeArray);
0310:
0311:                    List resultLocales = gp.getLocales();
0312:                    if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
0313:                        errln("FAIL: Number of locales mismatch - GP:"
0314:                                + resultLocales.size() + " Expected:"
0315:                                + RESULTS_LOCALEIDS[i].length);
0316:                    } else {
0317:
0318:                        for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
0319:                            ULocale loc = gp.getLocale(j);
0320:                            logln("Locale[" + j + "]: " + loc.toString());
0321:                            if (!gp.getLocale(j).toString().equals(
0322:                                    RESULTS_LOCALEIDS[i][j])) {
0323:                                errln("FAIL: Locale index(" + j
0324:                                        + ") does not match - GP:"
0325:                                        + loc.toString() + " Expected:"
0326:                                        + RESULTS_LOCALEIDS[i][j]);
0327:                            }
0328:                        }
0329:                    }
0330:                }
0331:
0332:                //#ifndef FOUNDATION
0333:                // setLocales(String)
0334:                for (int i = 0; i < ACCEPT_LANGUAGES.length; i++) {
0335:                    String acceptLanguage = ACCEPT_LANGUAGES[i];
0336:                    logln("Accept language: " + acceptLanguage);
0337:
0338:                    gp.reset();
0339:                    gp.setLocales(acceptLanguage);
0340:
0341:                    List resultLocales = gp.getLocales();
0342:                    if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
0343:                        errln("FAIL: Number of locales mismatch - GP:"
0344:                                + resultLocales.size() + " Expected:"
0345:                                + RESULTS_LOCALEIDS[i].length);
0346:                    } else {
0347:
0348:                        for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
0349:                            ULocale loc = gp.getLocale(j);
0350:                            logln("Locale[" + j + "]: " + loc.toString());
0351:                            if (!gp.getLocale(j).toString().equals(
0352:                                    RESULTS_LOCALEIDS[i][j])) {
0353:                                errln("FAIL: Locale index(" + j
0354:                                        + ") does not match - GP:"
0355:                                        + loc.toString() + " Expected:"
0356:                                        + RESULTS_LOCALEIDS[i][j]);
0357:                            }
0358:                        }
0359:                    }
0360:                }
0361:
0362:                // accept-language without q-value
0363:                logln("Set accept-language - de,de-AT");
0364:                gp.setLocales("de,de-AT");
0365:                if (!gp.getLocale(0).toString().equals("de_AT")) {
0366:                    errln("FAIL: getLocale(0) returns "
0367:                            + gp.getLocale(0).toString() + " Expected: de_AT");
0368:                }
0369:
0370:                // Invalid accept-language
0371:                logln("Set locale - ko_KR");
0372:                gp.setLocale(new ULocale("ko_KR"));
0373:                boolean bException = false;
0374:                try {
0375:                    logln("Set invlaid accept-language - ko=100");
0376:                    gp.setLocales("ko=100");
0377:                } catch (IllegalArgumentException iae) {
0378:                    logln("IllegalArgumentException was thrown");
0379:                    bException = true;
0380:                }
0381:                if (!bException) {
0382:                    errln("FAIL: IllegalArgumentException was not thrown for illegal accept-language - ko=100");
0383:                }
0384:                if (!gp.getLocale(0).toString().equals("ko_KR")) {
0385:                    errln("FAIL: Previous valid locale list had gone");
0386:                }
0387:                //#endif
0388:            }
0389:
0390:            public void TestResourceBundle() {
0391:                String baseName = "com.ibm.icu.dev.data.resources.TestDataElements";
0392:                ResourceBundle rb;
0393:
0394:                logln("Get a resource bundle "
0395:                        + baseName
0396:                        + " using GlobalizationPreferences initialized by locales - en_GB, en_US");
0397:                GlobalizationPreferences gp = new GlobalizationPreferences();
0398:                ULocale[] locales = new ULocale[2];
0399:                locales[0] = new ULocale("en_GB");
0400:                locales[1] = new ULocale("en_US");
0401:                gp.setLocales(locales);
0402:
0403:                try {
0404:                    rb = gp.getResourceBundle(baseName);
0405:                    String str = rb.getString("from_en_US");
0406:                    if (!str.equals("This data comes from en_US")) {
0407:                        errln("FAIL: from_en_US is not from en_US bundle");
0408:                    }
0409:                } catch (MissingResourceException mre) {
0410:                    errln("FAIL: Missing resouces");
0411:                }
0412:
0413:                gp.reset();
0414:
0415:                logln("Get a resource bundle "
0416:                        + baseName
0417:                        + " using GlobalizationPreferences initialized by locales - ja, en_US_California");
0418:
0419:                locales = new ULocale[2];
0420:                locales[0] = new ULocale("ja");
0421:                locales[1] = new ULocale("en_US_California");
0422:                gp.setLocales(locales);
0423:
0424:                try {
0425:                    rb = gp.getResourceBundle(baseName, Thread.currentThread()
0426:                            .getContextClassLoader());
0427:                    String str = rb.getString("from_en_US");
0428:                    if (!str.equals("This data comes from en_US")) {
0429:                        errln("FAIL: from_en_US is not from en_US bundle");
0430:                    }
0431:                } catch (MissingResourceException mre) {
0432:                    errln("FAIL: Missing resouces");
0433:                }
0434:
0435:                logln("Get a resource bundle which does not exist");
0436:                boolean bException = false;
0437:                try {
0438:                    rb = gp.getResourceBundle("foo.bar.XXX");
0439:                } catch (MissingResourceException mre) {
0440:                    logln("Missing resource exception for getting resource bundle - foo.bar.XXX");
0441:                    bException = true;
0442:                }
0443:                if (!bException) {
0444:                    errln("FAIL: MissingResourceException must be thrown for RB - foo.bar.XXX");
0445:                }
0446:            }
0447:
0448:            public void TestTerritory() {
0449:                GlobalizationPreferences gp = new GlobalizationPreferences();
0450:
0451:                // Territory for unsupported language locale
0452:                logln("Set locale - ang");
0453:                gp.setLocale(new ULocale("ang"));
0454:                String territory = gp.getTerritory();
0455:                if (!territory.equals("US")) {
0456:                    errln("FAIL: Territory is " + territory + " - Expected: US");
0457:                }
0458:
0459:                // Territory for language only locale "fr"
0460:                logln("Set locale - fr");
0461:                gp.setLocale(new ULocale("fr"));
0462:                territory = gp.getTerritory();
0463:                if (!territory.equals("FR")) {
0464:                    errln("FAIL: Territory is " + territory + " - Expected: FR");
0465:                }
0466:
0467:                // Set explicity territory
0468:                logln("Set explicit territory - CA");
0469:                gp.setTerritory("CA");
0470:                territory = gp.getTerritory();
0471:                if (!territory.equals("CA")) {
0472:                    errln("FAIL: Territory is " + territory + " - Expected: CA");
0473:                }
0474:
0475:                // Freeze
0476:                logln("Freeze this object");
0477:                gp.freeze();
0478:
0479:                boolean bFrozen = false;
0480:                try {
0481:                    gp.setTerritory("FR");
0482:                } catch (UnsupportedOperationException uoe) {
0483:                    logln("setTerritory is blocked");
0484:                    bFrozen = true;
0485:                }
0486:                if (!bFrozen) {
0487:                    errln("FAIL: setTerritory must be blocked after frozen");
0488:                }
0489:                territory = gp.getTerritory();
0490:                if (!territory.equals("CA")) {
0491:                    errln("FAIL: Territory is not CA");
0492:                }
0493:
0494:                // Safe clone
0495:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0496:                        .cloneAsThawed();
0497:                territory = gp1.getTerritory();
0498:                if (!territory.equals("CA")) {
0499:                    errln("FAIL: Territory is " + territory + " - Expected: CA");
0500:                }
0501:
0502:                gp1.reset();
0503:                ULocale[] locales = new ULocale[2];
0504:                locales[0] = new ULocale("ja");
0505:                locales[1] = new ULocale("zh_Hant_TW");
0506:
0507:                logln("Set locales - ja, zh_Hant_TW");
0508:                gp1.setLocales(locales);
0509:
0510:                territory = gp1.getTerritory();
0511:                if (!territory.equals("TW")) {
0512:                    errln("FAIL: Territory is " + territory + " - Expected: TW");
0513:                }
0514:            }
0515:
0516:            public void TestCurrency() {
0517:                GlobalizationPreferences gp = new GlobalizationPreferences();
0518:
0519:                // Set language only locale - ja
0520:                logln("Set locale - ja");
0521:                gp.setLocale(new ULocale("ja"));
0522:                Currency cur = gp.getCurrency();
0523:                String code = cur.getCurrencyCode();
0524:                if (!code.equals("JPY")) {
0525:                    errln("FAIL: Currency is " + code + " - Expected: JPY");
0526:                }
0527:
0528:                gp.reset();
0529:                // Set locales with territory
0530:                logln("Set locale - ja_US");
0531:                gp.setLocale(new ULocale("ja_US"));
0532:                cur = gp.getCurrency();
0533:                code = cur.getCurrencyCode();
0534:                if (!code.equals("USD")) {
0535:                    errln("FAIL: Currency is " + code + " - Expected: USD");
0536:                }
0537:
0538:                // Set locales with territory in the second locale
0539:                logln("Set locales - it, en_US");
0540:                ULocale[] locales = new ULocale[2];
0541:                locales[0] = new ULocale("it");
0542:                locales[1] = new ULocale("en_US");
0543:                gp.setLocales(locales);
0544:                cur = gp.getCurrency();
0545:                code = cur.getCurrencyCode();
0546:                if (!code.equals("USD")) {
0547:                    errln("FAIL: Currency is " + code + " - Expected: USD");
0548:                }
0549:
0550:                // Set explicit territory
0551:                logln("Set territory - DE");
0552:                gp.setTerritory("DE");
0553:                cur = gp.getCurrency();
0554:                code = cur.getCurrencyCode();
0555:                if (!code.equals("EUR")) {
0556:                    errln("FAIL: Currency is " + code + " - Expected: EUR");
0557:                }
0558:
0559:                // Set explicit currency
0560:                Currency ecur = Currency.getInstance("BRL");
0561:                gp.setCurrency(ecur);
0562:                logln("Set explicit currency - BRL");
0563:                cur = gp.getCurrency();
0564:                code = cur.getCurrencyCode();
0565:                if (!code.equals("BRL")) {
0566:                    errln("FAIL: Currency is " + code + " - Expected: BRL");
0567:                }
0568:
0569:                // Set explicit territory again
0570:                logln("Set territory - JP");
0571:                cur = gp.getCurrency();
0572:                code = cur.getCurrencyCode();
0573:                if (!code.equals("BRL")) {
0574:                    errln("FAIL: Currency is " + code + " - Expected: BRL");
0575:                }
0576:
0577:                // Freeze
0578:                logln("Freeze this object");
0579:                Currency ecur2 = Currency.getInstance("CHF");
0580:                boolean bFrozen = false;
0581:                gp.freeze();
0582:                try {
0583:                    gp.setCurrency(ecur2);
0584:                } catch (UnsupportedOperationException uoe) {
0585:                    logln("setCurrency is blocked");
0586:                    bFrozen = true;
0587:                }
0588:                if (!bFrozen) {
0589:                    errln("FAIL: setCurrency must be blocked");
0590:                }
0591:
0592:                // Safe clone
0593:                logln("cloneAsThawed");
0594:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0595:                        .cloneAsThawed();
0596:                cur = gp.getCurrency();
0597:                code = cur.getCurrencyCode();
0598:                if (!code.equals("BRL")) {
0599:                    errln("FAIL: Currency is " + code + " - Expected: BRL");
0600:                }
0601:
0602:                // Set ecplicit currency
0603:                gp1.setCurrency(ecur2);
0604:                cur = gp1.getCurrency();
0605:                code = cur.getCurrencyCode();
0606:                if (!code.equals("CHF")) {
0607:                    errln("FAIL: Currency is " + code + " - Expected: CHF");
0608:                }
0609:            }
0610:
0611:            public void TestCalendar() {
0612:                GlobalizationPreferences gp = new GlobalizationPreferences();
0613:
0614:                // Set locale - pt_BR
0615:                logln("Set locale - pt");
0616:                gp.setLocale(new ULocale("pt"));
0617:                Calendar cal = gp.getCalendar();
0618:                String calType = cal.getType();
0619:                if (!calType.equals("gregorian")) {
0620:                    errln("FAIL: Calendar type is " + calType
0621:                            + " Expected: gregorian");
0622:                }
0623:
0624:                // Set a list of locales
0625:                logln("Set locales - en, en_JP, en_GB");
0626:                ULocale[] locales = new ULocale[3];
0627:                locales[0] = new ULocale("en");
0628:                locales[1] = new ULocale("en_JP");
0629:                locales[2] = new ULocale("en_GB");
0630:                gp.setLocales(locales);
0631:
0632:                cal = gp.getCalendar();
0633:                ULocale calLocale = cal.getLocale(ULocale.VALID_LOCALE);
0634:                if (!calLocale.equals(locales[2])) {
0635:                    errln("FAIL: Calendar locale is " + calLocale.toString()
0636:                            + " - Expected: en_GB");
0637:                }
0638:
0639:                // Set ecplicit calendar
0640:                logln("Set Japanese calendar to this object");
0641:                JapaneseCalendar jcal = new JapaneseCalendar();
0642:                gp.setCalendar(jcal);
0643:                cal = gp.getCalendar();
0644:                calType = cal.getType();
0645:                if (!calType.equals("japanese")) {
0646:                    errln("FAIL: Calendar type is " + calType
0647:                            + " Expected: japanese");
0648:                }
0649:
0650:                jcal.setFirstDayOfWeek(3);
0651:                if (cal.getFirstDayOfWeek() == jcal.getFirstDayOfWeek()) {
0652:                    errln("FAIL: Calendar returned by getCalendar must be a safe copy");
0653:                }
0654:                cal.setFirstDayOfWeek(3);
0655:                Calendar cal1 = gp.getCalendar();
0656:                if (cal1.getFirstDayOfWeek() == cal.getFirstDayOfWeek()) {
0657:                    errln("FAIL: Calendar returned by getCalendar must be a safe copy");
0658:                }
0659:
0660:                // Freeze
0661:                logln("Freeze this object");
0662:                IslamicCalendar ical = new IslamicCalendar();
0663:                boolean bFrozen = false;
0664:                gp.freeze();
0665:                try {
0666:                    gp.setCalendar(ical);
0667:                } catch (UnsupportedOperationException uoe) {
0668:                    logln("setCalendar is blocked");
0669:                    bFrozen = true;
0670:                }
0671:                if (!bFrozen) {
0672:                    errln("FAIL: setCalendar must be blocked");
0673:                }
0674:
0675:                // Safe clone
0676:                logln("cloneAsThawed");
0677:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0678:                        .cloneAsThawed();
0679:                cal = gp.getCalendar();
0680:                calType = cal.getType();
0681:                if (!calType.equals("japanese")) {
0682:                    errln("FAIL: Calendar type afte clone is " + calType
0683:                            + " Expected: japanese");
0684:                }
0685:
0686:                logln("Set islamic calendar");
0687:                gp1.setCalendar(ical);
0688:                cal = gp1.getCalendar();
0689:                calType = cal.getType();
0690:                if (!calType.equals("islamic")) {
0691:                    errln("FAIL: Calendar type afte clone is " + calType
0692:                            + " Expected: islamic");
0693:                }
0694:            }
0695:
0696:            public void TestTimeZone() {
0697:                GlobalizationPreferences gp = new GlobalizationPreferences();
0698:
0699:                // Set locale - zh_CN 
0700:                logln("Set locale - zh_CN");
0701:                gp.setLocale(new ULocale("zh_CN"));
0702:                TimeZone tz = gp.getTimeZone();
0703:                String tzid = tz.getID();
0704:                if (!tzid.equals("Asia/Shanghai")) {
0705:                    errln("FAIL: Time zone ID is " + tzid
0706:                            + " Expected: Asia/Shanghai");
0707:                }
0708:
0709:                // Set locale - en
0710:                logln("Set locale - en");
0711:                gp.setLocale(new ULocale("en"));
0712:                tz = gp.getTimeZone();
0713:                tzid = tz.getID();
0714:                if (!tzid.equals("America/New_York")) {
0715:                    errln("FAIL: Time zone ID is " + tzid
0716:                            + " Expected: America/New_York");
0717:                }
0718:
0719:                // Set territory - GB
0720:                logln("Set territory - GB");
0721:                gp.setTerritory("GB");
0722:                tz = gp.getTimeZone();
0723:                tzid = tz.getID();
0724:                if (!tzid.equals("Europe/London")) {
0725:                    errln("FAIL: Time zone ID is " + tzid
0726:                            + " Expected: Europe/London");
0727:                }
0728:
0729:                // Check if getTimeZone returns a safe clone
0730:                tz.setID("Bad_ID");
0731:                tz = gp.getTimeZone();
0732:                tzid = tz.getID();
0733:                if (!tzid.equals("Europe/London")) {
0734:                    errln("FAIL: Time zone ID is " + tzid
0735:                            + " Expected: Europe/London");
0736:                }
0737:
0738:                // Set explicit time zone
0739:                TimeZone jst = TimeZone.getTimeZone("Asia/Tokyo");
0740:                String customJstId = "Japan_Standard_Time";
0741:                jst.setID(customJstId);
0742:                gp.setTimeZone(jst);
0743:                tz = gp.getTimeZone();
0744:                tzid = tz.getID();
0745:                if (!tzid.equals(customJstId)) {
0746:                    errln("FAIL: Time zone ID is " + tzid + " Expected: "
0747:                            + customJstId);
0748:                }
0749:
0750:                // Freeze
0751:                logln("Freeze this object");
0752:                TimeZone cst = TimeZone.getTimeZone("Europe/Paris");
0753:                boolean bFrozen = false;
0754:                gp.freeze();
0755:                try {
0756:                    gp.setTimeZone(cst);
0757:                } catch (UnsupportedOperationException uoe) {
0758:                    logln("setTimeZone is blocked");
0759:                    bFrozen = true;
0760:                }
0761:                if (!bFrozen) {
0762:                    errln("FAIL: setTimeZone must be blocked");
0763:                }
0764:
0765:                // Modifiable clone
0766:                logln("cloneAsThawed");
0767:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0768:                        .cloneAsThawed();
0769:                tz = gp1.getTimeZone();
0770:                tzid = tz.getID();
0771:                if (!tzid.equals(customJstId)) {
0772:                    errln("FAIL: Time zone ID is " + tzid + " Expected: "
0773:                            + customJstId);
0774:                }
0775:
0776:                // Set explicit time zone
0777:                gp1.setTimeZone(cst);
0778:                tz = gp1.getTimeZone();
0779:                tzid = tz.getID();
0780:                if (!tzid.equals(cst.getID())) {
0781:                    errln("FAIL: Time zone ID is " + tzid + " Expected: "
0782:                            + cst.getID());
0783:                }
0784:            }
0785:
0786:            public void TestCollator() {
0787:                GlobalizationPreferences gp = new GlobalizationPreferences();
0788:
0789:                // Set locale - tr
0790:                logln("Set locale - tr");
0791:                gp.setLocale(new ULocale("tr"));
0792:                Collator coll = gp.getCollator();
0793:                String locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
0794:                if (!locStr.equals("tr")) {
0795:                    errln("FAIL: Collator locale is " + locStr
0796:                            + " Expected: tr");
0797:                }
0798:
0799:                // Unsupported collator locale - zun
0800:                logln("Set locale - zun");
0801:                gp.setLocale(new ULocale("zun"));
0802:                coll = gp.getCollator();
0803:                locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
0804:                if (!locStr.equals("root")) {
0805:                    errln("FAIL: Collator locale is " + locStr
0806:                            + " Expected: root");
0807:                }
0808:
0809:                // Set locales - en_JP, fr, en_US, fr_FR
0810:                logln("Set locale - en_JP, fr, en_US, fr_FR");
0811:                ULocale[] locales = new ULocale[4];
0812:                locales[0] = new ULocale("en_JP");
0813:                locales[1] = new ULocale("fr");
0814:                locales[2] = new ULocale("en_US");
0815:                locales[3] = new ULocale("fr_FR");
0816:                gp.setLocales(locales);
0817:                coll = gp.getCollator();
0818:                locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
0819:                if (!locStr.equals("fr_FR")) {
0820:                    errln("FAIL: Collator locale is " + locStr
0821:                            + " Expected: fr_FR");
0822:                }
0823:
0824:                // Set explicit Collator
0825:                Collator coll1 = Collator.getInstance(new ULocale("it"));
0826:                coll1.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
0827:                logln("Set collator for it in canonical deconposition mode");
0828:                gp.setCollator(coll1);
0829:                coll1.setStrength(Collator.IDENTICAL);
0830:                coll = gp.getCollator();
0831:                locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
0832:                if (!locStr.equals("it")) {
0833:                    errln("FAIL: Collator locale is " + locStr
0834:                            + " Expected: it");
0835:                }
0836:                if (coll1.equals(coll)) {
0837:                    errln("FAIL: setCollator must use a safe copy of a Collator");
0838:                }
0839:
0840:                // Freeze
0841:                logln("Freeze this object");
0842:                boolean isFrozen = false;
0843:                gp.freeze();
0844:                try {
0845:                    gp.setCollator(coll1);
0846:                } catch (UnsupportedOperationException uoe) {
0847:                    logln("setCollator is blocked");
0848:                    isFrozen = true;
0849:                }
0850:                if (!isFrozen) {
0851:                    errln("FAIL: setCollator must be blocked after freeze");
0852:                }
0853:
0854:                // Modifiable clone
0855:                logln("cloneAsThawed");
0856:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0857:                        .cloneAsThawed();
0858:                coll = gp1.getCollator();
0859:                locStr = coll.getLocale(ULocale.VALID_LOCALE).toString();
0860:                if (!locStr.equals("it")) {
0861:                    errln("FAIL: Collator locale is " + locStr
0862:                            + " Expected: it");
0863:                }
0864:                if (coll.getDecomposition() != Collator.CANONICAL_DECOMPOSITION) {
0865:                    errln("FAIL: Decomposition mode is not CANONICAL_DECOMPOSITION");
0866:                }
0867:
0868:                // Set custom collator again
0869:                gp1.setCollator(coll1);
0870:                coll = gp1.getCollator();
0871:                if (coll.getStrength() != Collator.IDENTICAL) {
0872:                    errln("FAIL: Strength is not IDENTICAL");
0873:                }
0874:            }
0875:
0876:            public void TestBreakIterator() {
0877:                GlobalizationPreferences gp = new GlobalizationPreferences();
0878:
0879:                // Unsupported break iterator locale - aar
0880:                logln("Set locale - aar");
0881:                gp.setLocale(new ULocale("aar"));
0882:                BreakIterator brk = gp
0883:                        .getBreakIterator(GlobalizationPreferences.BI_LINE);
0884:                String locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
0885:                if (!locStr.equals("root")) {
0886:                    errln("FAIL: Line break iterator locale is " + locStr
0887:                            + " Expected: root");
0888:                }
0889:
0890:                // Set locale - es
0891:                logln("Set locale - es");
0892:                gp.setLocale(new ULocale("es"));
0893:                brk = gp
0894:                        .getBreakIterator(GlobalizationPreferences.BI_CHARACTER);
0895:                /* TODO: JB#5383
0896:                locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
0897:                if (!locStr.equals("es")) {
0898:                    errln("FAIL: Character break iterator locale is " + locStr + " Expected: es");
0899:                }
0900:                 */
0901:
0902:                // Set explicit break sentence iterator
0903:                logln("Set break iterator for sentence using locale hu_HU");
0904:                BreakIterator brk1 = BreakIterator
0905:                        .getSentenceInstance(new ULocale("hu_HU"));
0906:                gp.setBreakIterator(GlobalizationPreferences.BI_SENTENCE, brk1);
0907:
0908:                brk = gp.getBreakIterator(GlobalizationPreferences.BI_SENTENCE);
0909:                /* TODO: JB#5210
0910:                locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
0911:                if (!locStr.equals("hu_HU")) {
0912:                    errln("FAIL: Sentence break locale is " + locStr + " Expected: hu_HU");
0913:                }
0914:                 */
0915:                brk.setText("This is a test case.  Is this a new instance?");
0916:                brk.next();
0917:                if (brk1.current() == brk.current()) {
0918:                    errln("FAIL: getBreakIterator must return a new instance");
0919:                }
0920:
0921:                // Illegal argument
0922:                logln("Get break iterator type 100");
0923:                boolean illegalArg = false;
0924:                try {
0925:                    brk = gp.getBreakIterator(100);
0926:                } catch (IllegalArgumentException iae) {
0927:                    logln("Break iterator type 100 is illegal");
0928:                    illegalArg = true;
0929:                }
0930:                if (!illegalArg) {
0931:                    errln("FAIL: getBreakIterator must throw IllegalArgumentException for type 100");
0932:                }
0933:                logln("Set break iterator type -1");
0934:                illegalArg = false;
0935:                try {
0936:                    gp.setBreakIterator(-1, brk1);
0937:                } catch (IllegalArgumentException iae) {
0938:                    logln("Break iterator type -1 is illegal");
0939:                    illegalArg = true;
0940:                }
0941:                if (!illegalArg) {
0942:                    errln("FAIL: getBreakIterator must throw IllegalArgumentException for type -1");
0943:                }
0944:
0945:                // Freeze
0946:                logln("Freeze this object");
0947:                BreakIterator brk2 = BreakIterator
0948:                        .getTitleInstance(new ULocale("es_MX"));
0949:                boolean isFrozen = false;
0950:                gp.freeze();
0951:                try {
0952:                    gp
0953:                            .setBreakIterator(
0954:                                    GlobalizationPreferences.BI_TITLE, brk2);
0955:                } catch (UnsupportedOperationException uoe) {
0956:                    logln("setBreakIterator is blocked");
0957:                    isFrozen = true;
0958:                }
0959:                if (!isFrozen) {
0960:                    errln("FAIL: setBreakIterator must be blocked after frozen");
0961:                }
0962:
0963:                // Modifiable clone
0964:                logln("cloneAsThawed");
0965:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
0966:                        .cloneAsThawed();
0967:                brk = gp1.getBreakIterator(GlobalizationPreferences.BI_WORD);
0968:                /* TODO: JB#5383
0969:                locStr = brk.getLocale(ULocale.VALID_LOCALE).toString();
0970:                if (!locStr.equals("es")) {
0971:                    errln("FAIL: Word break iterator locale is " + locStr + " Expected: es");
0972:                }
0973:                 */
0974:
0975:                ULocale frFR = new ULocale("fr_FR");
0976:                BreakIterator brkC = BreakIterator.getCharacterInstance(frFR);
0977:                BreakIterator brkW = BreakIterator.getWordInstance(frFR);
0978:                BreakIterator brkL = BreakIterator.getLineInstance(frFR);
0979:                BreakIterator brkS = BreakIterator.getSentenceInstance(frFR);
0980:                BreakIterator brkT = BreakIterator.getTitleInstance(frFR);
0981:
0982:                gp1.setBreakIterator(GlobalizationPreferences.BI_CHARACTER,
0983:                        brkC);
0984:                gp1.setBreakIterator(GlobalizationPreferences.BI_WORD, brkW);
0985:                gp1.setBreakIterator(GlobalizationPreferences.BI_LINE, brkL);
0986:                gp1
0987:                        .setBreakIterator(GlobalizationPreferences.BI_SENTENCE,
0988:                                brkS);
0989:                gp1.setBreakIterator(GlobalizationPreferences.BI_TITLE, brkT);
0990:
0991:                /* TODO: JB#5210
0992:                locStr = brkC.getLocale(ULocale.VALID_LOCALE).toString();
0993:                if (!locStr.equals("ja_JP")) {
0994:                    errln("FAIL: Character break iterator locale is " + locStr + " Expected: fr_FR");
0995:                }
0996:                locStr = brkW.getLocale(ULocale.VALID_LOCALE).toString();
0997:                if (!locStr.equals("ja_JP")) {
0998:                    errln("FAIL: Word break iterator locale is " + locStr + " Expected: fr_FR");
0999:                }
1000:                locStr = brkL.getLocale(ULocale.VALID_LOCALE).toString();
1001:                if (!locStr.equals("ja_JP")) {
1002:                    errln("FAIL: Line break iterator locale is " + locStr + " Expected: fr_FR");
1003:                }
1004:                locStr = brkS.getLocale(ULocale.VALID_LOCALE).toString();
1005:                if (!locStr.equals("ja_JP")) {
1006:                    errln("FAIL: Sentence break iterator locale is " + locStr + " Expected: fr_FR");
1007:                }
1008:                locStr = brkT.getLocale(ULocale.VALID_LOCALE).toString();
1009:                if (!locStr.equals("ja_JP")) {
1010:                    errln("FAIL: Title break iterator locale is " + locStr + " Expected: fr_FR");
1011:                }
1012:                 */
1013:            }
1014:
1015:            public void TestDisplayName() {
1016:                GlobalizationPreferences gp = new GlobalizationPreferences();
1017:
1018:                ULocale loc_fr_FR_Paris = new ULocale("fr_FR_Paris");
1019:                ULocale loc_peo = new ULocale("peo");
1020:
1021:                // Locale list - fr_FR_Paris
1022:                ArrayList locales1 = new ArrayList(1);
1023:                locales1.add(loc_fr_FR_Paris);
1024:
1025:                // Locale list - ain, fr_FR_Paris
1026:                ArrayList locales2 = new ArrayList(2);
1027:                locales2.add(loc_peo);
1028:                locales2.add(loc_fr_FR_Paris);
1029:
1030:                logln("Locales: <default> | <fr_FR_Paris> | <ain, fr_FR_Paris>");
1031:
1032:                // ID_LOCALE
1033:                String id = "zh_Hant_HK";
1034:                String name1 = gp.getDisplayName(id,
1035:                        GlobalizationPreferences.ID_LOCALE);
1036:                gp.setLocales(locales1);
1037:                String name2 = gp.getDisplayName(id,
1038:                        GlobalizationPreferences.ID_LOCALE);
1039:                gp.setLocales(locales2);
1040:                String name3 = gp.getDisplayName(id,
1041:                        GlobalizationPreferences.ID_LOCALE);
1042:
1043:                logln("Locale[zh_Hant_HK]: " + name1 + " | " + name2 + " | "
1044:                        + name3);
1045:                if (name1.equals(name2) || !name2.equals(name3)) {
1046:                    errln("FAIL: Locale ID");
1047:                }
1048:
1049:                // ID_LANGUAGE
1050:                gp.reset();
1051:                id = "fr";
1052:                name1 = gp.getDisplayName(id,
1053:                        GlobalizationPreferences.ID_LANGUAGE);
1054:                gp.setLocales(locales1);
1055:                name2 = gp.getDisplayName(id,
1056:                        GlobalizationPreferences.ID_LANGUAGE);
1057:                gp.setLocales(locales2);
1058:                name3 = gp.getDisplayName(id,
1059:                        GlobalizationPreferences.ID_LANGUAGE);
1060:
1061:                logln("Language[fr]: " + name1 + " | " + name2 + " | " + name3);
1062:                if (name1.equals(name2) || !name2.equals(name3)) {
1063:                    errln("FAIL: Language ID");
1064:                }
1065:
1066:                // ID_SCRIPT
1067:                gp.reset();
1068:                id = "cyrl";
1069:                name1 = gp.getDisplayName(id,
1070:                        GlobalizationPreferences.ID_SCRIPT);
1071:                gp.setLocales(locales1);
1072:                name2 = gp.getDisplayName(id,
1073:                        GlobalizationPreferences.ID_SCRIPT);
1074:                gp.setLocales(locales2);
1075:                name3 = gp.getDisplayName(id,
1076:                        GlobalizationPreferences.ID_SCRIPT);
1077:
1078:                logln("Script[cyrl]: " + name1 + " | " + name2 + " | " + name3);
1079:                if (name1.equals(name2) || !name2.equals(name3)) {
1080:                    errln("FAIL: Script ID");
1081:                }
1082:
1083:                // ID_TERRITORY
1084:                gp.reset();
1085:                id = "JP";
1086:                name1 = gp.getDisplayName(id,
1087:                        GlobalizationPreferences.ID_TERRITORY);
1088:                gp.setLocales(locales1);
1089:                name2 = gp.getDisplayName(id,
1090:                        GlobalizationPreferences.ID_TERRITORY);
1091:                gp.setLocales(locales2);
1092:                name3 = gp.getDisplayName(id,
1093:                        GlobalizationPreferences.ID_TERRITORY);
1094:
1095:                logln("Territory[JP]: " + name1 + " | " + name2 + " | " + name3);
1096:                if (name1.equals(name2) || !name2.equals(name3)) {
1097:                    errln("FAIL: Territory ID");
1098:                }
1099:
1100:                // ID_VARIANT
1101:                gp.reset();
1102:                id = "NEDIS";
1103:                name1 = gp.getDisplayName(id,
1104:                        GlobalizationPreferences.ID_VARIANT);
1105:                gp.setLocales(locales1);
1106:                name2 = gp.getDisplayName(id,
1107:                        GlobalizationPreferences.ID_VARIANT);
1108:                gp.setLocales(locales2);
1109:                name3 = gp.getDisplayName(id,
1110:                        GlobalizationPreferences.ID_VARIANT);
1111:
1112:                logln("Variant[NEDIS]: " + name1 + " | " + name2 + " | "
1113:                        + name3);
1114:                if (name1.equals(name2) || !name2.equals(name3)) {
1115:                    errln("FAIL: Variant ID");
1116:                }
1117:
1118:                // ID_KEYWORD
1119:                gp.reset();
1120:                id = "collation";
1121:                name1 = gp.getDisplayName(id,
1122:                        GlobalizationPreferences.ID_KEYWORD);
1123:                gp.setLocales(locales1);
1124:                name2 = gp.getDisplayName(id,
1125:                        GlobalizationPreferences.ID_KEYWORD);
1126:                gp.setLocales(locales2);
1127:                name3 = gp.getDisplayName(id,
1128:                        GlobalizationPreferences.ID_KEYWORD);
1129:
1130:                logln("Keyword[collation]: " + name1 + " | " + name2 + " | "
1131:                        + name3);
1132:                if (name1.equals(name2) || !name2.equals(name3)) {
1133:                    errln("FAIL: Keyword ID");
1134:                }
1135:
1136:                // ID_KEYWORD_VALUE
1137:                gp.reset();
1138:                id = "collation=traditional";
1139:                name1 = gp.getDisplayName(id,
1140:                        GlobalizationPreferences.ID_KEYWORD_VALUE);
1141:                gp.setLocales(locales1);
1142:                name2 = gp.getDisplayName(id,
1143:                        GlobalizationPreferences.ID_KEYWORD_VALUE);
1144:                gp.setLocales(locales2);
1145:                name3 = gp.getDisplayName(id,
1146:                        GlobalizationPreferences.ID_KEYWORD_VALUE);
1147:
1148:                logln("Keyword value[traditional]: " + name1 + " | " + name2
1149:                        + " | " + name3);
1150:                if (name1.equals(name2) || !name2.equals(name3)) {
1151:                    errln("FAIL: Keyword value ID");
1152:                }
1153:
1154:                // ID_CURRENCY_SYMBOL
1155:                gp.reset();
1156:                id = "USD";
1157:                name1 = gp.getDisplayName(id,
1158:                        GlobalizationPreferences.ID_CURRENCY_SYMBOL);
1159:                gp.setLocales(locales1);
1160:                name2 = gp.getDisplayName(id,
1161:                        GlobalizationPreferences.ID_CURRENCY_SYMBOL);
1162:                gp.setLocales(locales2);
1163:                name3 = gp.getDisplayName(id,
1164:                        GlobalizationPreferences.ID_CURRENCY_SYMBOL);
1165:
1166:                logln("Currency symbol[USD]: " + name1 + " | " + name2 + " | "
1167:                        + name3);
1168:                String dollar = "$";
1169:                if (!name1.equals(dollar) || !name2.equals(dollar)
1170:                        || !name3.equals(dollar)) {
1171:                    errln("FAIL: Currency symbol ID");
1172:                }
1173:
1174:                // ID_CURRENCY
1175:                gp.reset();
1176:                id = "USD";
1177:                name1 = gp.getDisplayName(id,
1178:                        GlobalizationPreferences.ID_CURRENCY);
1179:                gp.setLocales(locales1);
1180:                name2 = gp.getDisplayName(id,
1181:                        GlobalizationPreferences.ID_CURRENCY);
1182:                gp.setLocales(locales2);
1183:                name3 = gp.getDisplayName(id,
1184:                        GlobalizationPreferences.ID_CURRENCY);
1185:
1186:                logln("Currency[USD]: " + name1 + " | " + name2 + " | " + name3);
1187:                if (name1.equals(name2) || !name2.equals(name3)) {
1188:                    errln("FAIL: Currency ID");
1189:                }
1190:
1191:                // ID_TIMEZONE
1192:                gp.reset();
1193:                id = "Europe/Paris";
1194:                name1 = gp.getDisplayName(id,
1195:                        GlobalizationPreferences.ID_TIMEZONE);
1196:                gp.setLocales(locales1);
1197:                name2 = gp.getDisplayName(id,
1198:                        GlobalizationPreferences.ID_TIMEZONE);
1199:                gp.setLocales(locales2);
1200:                name3 = gp.getDisplayName(id,
1201:                        GlobalizationPreferences.ID_TIMEZONE);
1202:
1203:                logln("Timezone[Europe/Paris]: " + name1 + " | " + name2
1204:                        + " | " + name3);
1205:                if (name1.equals(name2) || !name2.equals(name3)) {
1206:                    errln("FAIL: Timezone ID");
1207:                }
1208:
1209:                // Illegal ID
1210:                gp.reset();
1211:                boolean illegalArg = false;
1212:                try {
1213:                    name1 = gp.getDisplayName(id, -1);
1214:                } catch (IllegalArgumentException iae) {
1215:                    logln("Illegal type -1");
1216:                    illegalArg = true;
1217:                }
1218:                if (!illegalArg) {
1219:                    errln("FAIL: getDisplayName must throw IllegalArgumentException for type -1");
1220:                }
1221:
1222:                illegalArg = false;
1223:                try {
1224:                    name1 = gp.getDisplayName(id, 100);
1225:                } catch (IllegalArgumentException iae) {
1226:                    logln("Illegal type 100");
1227:                    illegalArg = true;
1228:                }
1229:                if (!illegalArg) {
1230:                    errln("FAIL: getDisplayName must throw IllegalArgumentException for type 100");
1231:                }
1232:            }
1233:
1234:            public void TestDateFormat() {
1235:                GlobalizationPreferences gp = new GlobalizationPreferences();
1236:
1237:                String pattern;
1238:                DateFormat df;
1239:
1240:                // Set unsupported locale - ach
1241:                logln("Set locale - ach");
1242:                gp.setLocale(new ULocale("ach"));
1243:
1244:                // Date - short
1245:                df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT,
1246:                        GlobalizationPreferences.DF_NONE);
1247:                pattern = ((SimpleDateFormat) df).toPattern();
1248:                // root pattern must be used
1249:                if (!pattern.equals("yy/MM/dd")) {
1250:                    errln("FAIL: SHORT date pattern is " + pattern
1251:                            + " Expected: yy/MM/dd");
1252:                }
1253:
1254:                // Set locale - fr, fr_CA, fr_FR
1255:                ArrayList lcls = new ArrayList(3);
1256:                lcls.add(new ULocale("fr"));
1257:                lcls.add(new ULocale("fr_CA"));
1258:                lcls.add(new ULocale("fr_FR"));
1259:                logln("Set locales - fr, fr_CA, fr_FR");
1260:                gp.setLocales(lcls);
1261:                // Date - short
1262:                df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT,
1263:                        GlobalizationPreferences.DF_NONE);
1264:                pattern = ((SimpleDateFormat) df).toPattern();
1265:                // fr_CA pattern must be used
1266:                if (!pattern.equals("yy-MM-dd")) {
1267:                    errln("FAIL: FULL date pattern is " + pattern
1268:                            + " Expected: yy-MM-dd");
1269:                }
1270:
1271:                // Set locale - en_GB
1272:                logln("Set locale - en_GB");
1273:                gp.setLocale(new ULocale("en_GB"));
1274:
1275:                // Date - full
1276:                df = gp.getDateFormat(GlobalizationPreferences.DF_FULL,
1277:                        GlobalizationPreferences.DF_NONE);
1278:                pattern = ((SimpleDateFormat) df).toPattern();
1279:                if (!pattern.equals("EEEE, d MMMM yyyy")) {
1280:                    errln("FAIL: FULL date pattern is " + pattern
1281:                            + " Expected: EEEE, d MMMM yyyy");
1282:                }
1283:
1284:                // Date - long
1285:                df = gp.getDateFormat(GlobalizationPreferences.DF_LONG,
1286:                        GlobalizationPreferences.DF_NONE);
1287:                pattern = ((SimpleDateFormat) df).toPattern();
1288:                if (!pattern.equals("d MMMM yyyy")) {
1289:                    errln("FAIL: LONG date pattern is " + pattern
1290:                            + " Expected: d MMMM yyyy");
1291:                }
1292:
1293:                // Date - medium
1294:                df = gp.getDateFormat(GlobalizationPreferences.DF_MEDIUM,
1295:                        GlobalizationPreferences.DF_NONE);
1296:                pattern = ((SimpleDateFormat) df).toPattern();
1297:                if (!pattern.equals("d MMM yyyy")) {
1298:                    errln("FAIL: MEDIUM date pattern is " + pattern
1299:                            + " Expected: d MMM yyyy");
1300:                }
1301:
1302:                // Date - short
1303:                df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT,
1304:                        GlobalizationPreferences.DF_NONE);
1305:                pattern = ((SimpleDateFormat) df).toPattern();
1306:                if (!pattern.equals("dd/MM/yyyy")) {
1307:                    errln("FAIL: SHORT date pattern is " + pattern
1308:                            + " Expected: dd/MM/yyyy");
1309:                }
1310:
1311:                // Time - full
1312:                df = gp.getDateFormat(GlobalizationPreferences.DF_NONE,
1313:                        GlobalizationPreferences.DF_FULL);
1314:                pattern = ((SimpleDateFormat) df).toPattern();
1315:                if (!pattern.equals("HH:mm:ss z")) {
1316:                    errln("FAIL: FULL time pattern is " + pattern
1317:                            + " Expected: HH:mm:ss z");
1318:                }
1319:
1320:                // Time - long
1321:                df = gp.getDateFormat(GlobalizationPreferences.DF_NONE,
1322:                        GlobalizationPreferences.DF_LONG);
1323:                pattern = ((SimpleDateFormat) df).toPattern();
1324:                if (!pattern.equals("HH:mm:ss z")) {
1325:                    errln("FAIL: LONG time pattern is " + pattern
1326:                            + " Expected: HH:mm:ss z");
1327:                }
1328:
1329:                // Time - medium
1330:                df = gp.getDateFormat(GlobalizationPreferences.DF_NONE,
1331:                        GlobalizationPreferences.DF_MEDIUM);
1332:                pattern = ((SimpleDateFormat) df).toPattern();
1333:                if (!pattern.equals("HH:mm:ss")) {
1334:                    errln("FAIL: MEDIUM time pattern is " + pattern
1335:                            + " Expected: HH:mm:ss");
1336:                }
1337:
1338:                // Time - short
1339:                df = gp.getDateFormat(GlobalizationPreferences.DF_NONE,
1340:                        GlobalizationPreferences.DF_SHORT);
1341:                pattern = ((SimpleDateFormat) df).toPattern();
1342:                if (!pattern.equals("HH:mm")) {
1343:                    errln("FAIL: SHORT time pattern is " + pattern
1344:                            + " Expected: HH:mm");
1345:                }
1346:
1347:                // Date/Time - full
1348:                df = gp.getDateFormat(GlobalizationPreferences.DF_FULL,
1349:                        GlobalizationPreferences.DF_FULL);
1350:                pattern = ((SimpleDateFormat) df).toPattern();
1351:                if (!pattern.equals("EEEE, d MMMM yyyy HH:mm:ss z")) {
1352:                    errln("FAIL: FULL date/time pattern is " + pattern
1353:                            + " Expected: EEEE, d MMMM yyyy HH:mm:ss z");
1354:                }
1355:
1356:                // Invalid style
1357:                boolean illegalArg = false;
1358:                try {
1359:                    df = gp.getDateFormat(-1, GlobalizationPreferences.DF_NONE);
1360:                } catch (IllegalArgumentException iae) {
1361:                    logln("Illegal date style -1");
1362:                    illegalArg = true;
1363:                }
1364:                if (!illegalArg) {
1365:                    errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle -1");
1366:                }
1367:
1368:                illegalArg = false;
1369:                try {
1370:                    df = gp.getDateFormat(GlobalizationPreferences.DF_NONE,
1371:                            GlobalizationPreferences.DF_NONE);
1372:                } catch (IllegalArgumentException iae) {
1373:                    logln("Illegal style - dateStyle:DF_NONE / timeStyle:DF_NONE");
1374:                    illegalArg = true;
1375:                }
1376:                if (!illegalArg) {
1377:                    errln("FAIL: getDateFormat() must throw IllegalArgumentException for dateStyle:DF_NONE/timeStyle:DF_NONE");
1378:                }
1379:
1380:                // Set explicit time zone
1381:                logln("Set timezone - America/Sao_Paulo");
1382:                TimeZone tz = TimeZone.getTimeZone("America/Sao_Paulo");
1383:                gp.setTimeZone(tz);
1384:                df = gp.getDateFormat(GlobalizationPreferences.DF_LONG,
1385:                        GlobalizationPreferences.DF_MEDIUM);
1386:                String tzid = df.getTimeZone().getID();
1387:                if (!tzid.equals("America/Sao_Paulo")) {
1388:                    errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
1389:                }
1390:
1391:                // Set explicit calendar
1392:                logln("Set calendar - japanese");
1393:                Calendar jcal = new JapaneseCalendar();
1394:                jcal.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
1395:                gp.setCalendar(jcal);
1396:                df = gp.getDateFormat(GlobalizationPreferences.DF_SHORT,
1397:                        GlobalizationPreferences.DF_SHORT);
1398:                Calendar dfCal = df.getCalendar();
1399:                if (!(dfCal instanceof  JapaneseCalendar)) {
1400:                    errln("FAIL: The DateFormat instance must use Japanese calendar");
1401:                }
1402:                // TimeZone must be still America/Sao_Paulo
1403:                tzid = df.getTimeZone().getID();
1404:                if (!tzid.equals("America/Sao_Paulo")) {
1405:                    errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
1406:                }
1407:
1408:                // Set explicit DateFormat
1409:                logln("Set explicit date format - full date");
1410:                DateFormat customFD = DateFormat.getDateInstance(
1411:                        new IslamicCalendar(), DateFormat.FULL, new ULocale(
1412:                                "ar_SA"));
1413:                customFD.setTimeZone(TimeZone.getTimeZone("Asia/Riyadh"));
1414:                gp.setDateFormat(GlobalizationPreferences.DF_FULL,
1415:                        GlobalizationPreferences.DF_NONE, customFD);
1416:                df = gp.getDateFormat(GlobalizationPreferences.DF_FULL,
1417:                        GlobalizationPreferences.DF_NONE);
1418:                dfCal = df.getCalendar();
1419:                if (!(dfCal instanceof  IslamicCalendar)) {
1420:                    errln("FAIL: The DateFormat instance must use Islamic calendar");
1421:                }
1422:                // TimeZone in the custom DateFormat is overridden by GP's timezone setting
1423:                tzid = df.getTimeZone().getID();
1424:                if (!tzid.equals("America/Sao_Paulo")) {
1425:                    errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
1426:                }
1427:
1428:                // Freeze
1429:                logln("Freeze this object");
1430:                gp.freeze();
1431:                DateFormat customLD = DateFormat.getDateInstance(
1432:                        new BuddhistCalendar(), DateFormat.LONG, new ULocale(
1433:                                "th"));
1434:                customLD.setTimeZone(TimeZone.getTimeZone("Asia/Bangkok"));
1435:                boolean isFrozen = false;
1436:                try {
1437:                    gp.setDateFormat(GlobalizationPreferences.DF_LONG,
1438:                            GlobalizationPreferences.DF_NONE, customLD);
1439:                } catch (UnsupportedOperationException uoe) {
1440:                    logln("setDateFormat is blocked");
1441:                    isFrozen = true;
1442:                }
1443:                if (!isFrozen) {
1444:                    errln("FAIL: setDateFormat must be blocked after frozen");
1445:                }
1446:
1447:                // Modifiable clone
1448:                logln("cloneAsThawed");
1449:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
1450:                        .cloneAsThawed();
1451:                gp1.setDateFormat(GlobalizationPreferences.DF_LONG,
1452:                        GlobalizationPreferences.DF_NONE, customLD);
1453:
1454:                df = gp1.getDateFormat(GlobalizationPreferences.DF_SHORT,
1455:                        GlobalizationPreferences.DF_SHORT);
1456:                dfCal = df.getCalendar();
1457:                if (!(dfCal instanceof  JapaneseCalendar)) {
1458:                    errln("FAIL: The DateFormat instance must use Japanese calendar");
1459:                }
1460:                // TimeZone must be still America/Sao_Paulo
1461:                tzid = df.getTimeZone().getID();
1462:                if (!tzid.equals("America/Sao_Paulo")) {
1463:                    errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
1464:                }
1465:
1466:                df = gp1.getDateFormat(GlobalizationPreferences.DF_LONG,
1467:                        GlobalizationPreferences.DF_NONE);
1468:                dfCal = df.getCalendar();
1469:                if (!(dfCal instanceof  BuddhistCalendar)) {
1470:                    errln("FAIL: The DateFormat instance must use Buddhist calendar");
1471:                }
1472:                // TimeZone must be still America/Sao_Paulo
1473:                tzid = df.getTimeZone().getID();
1474:                if (!tzid.equals("America/Sao_Paulo")) {
1475:                    errln("FAIL: The DateFormat instance must use timezone America/Sao_Paulo");
1476:                }
1477:
1478:            }
1479:
1480:            public void TestNumberFormat() {
1481:                GlobalizationPreferences gp = new GlobalizationPreferences();
1482:
1483:                NumberFormat nf;
1484:                String numStr;
1485:                double num = 123456.789;
1486:
1487:                // Set unsupported locale with supported territory ang_KR
1488:                logln("Set locale - ang_KR");
1489:                gp.setLocale(new ULocale("ang_KR"));
1490:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
1491:                numStr = nf.format(num);
1492:                if (!numStr.equals("KRW 123,457")) {
1493:                    errln("FAIL: Number string is " + numStr
1494:                            + " Expected: KRW 123,457");
1495:                }
1496:
1497:                // Set locale - de_DE
1498:                logln("Set locale - de_DE");
1499:                gp.setLocale(new ULocale("de_DE"));
1500:
1501:                // NF_NUMBER
1502:                logln("NUMBER type");
1503:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
1504:                numStr = nf.format(num);
1505:                if (!numStr.equals("123.456,789")) {
1506:                    errln("FAIL: Number string is " + numStr
1507:                            + " Expected: 123.456,789");
1508:                }
1509:
1510:                // NF_CURRENCY
1511:                logln("CURRENCY type");
1512:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
1513:                numStr = nf.format(num);
1514:                if (!numStr.equals("123.456,79 \u20AC")) {
1515:                    errln("FAIL: Number string is " + numStr
1516:                            + " Expected: 123.456,79 \u20AC");
1517:                }
1518:
1519:                // NF_PERCENT
1520:                logln("PERCENT type");
1521:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_PERCENT);
1522:                numStr = nf.format(num);
1523:                if (!numStr.equals("12.345.679%")) {
1524:                    errln("FAIL: Number string is " + numStr
1525:                            + " Expected: 12.345.679%");
1526:                }
1527:
1528:                // NF_SCIENTIFIC
1529:                logln("SCIENTIFIC type");
1530:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC);
1531:                numStr = nf.format(num);
1532:                if (!numStr.equals("1,23456789E5")) {
1533:                    errln("FAIL: Number string is " + numStr
1534:                            + " Expected: 1,23456789E5");
1535:                }
1536:
1537:                // NF_INTEGER
1538:                logln("INTEGER type");
1539:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_INTEGER);
1540:                numStr = nf.format(num);
1541:                if (!numStr.equals("123.457")) {
1542:                    errln("FAIL: Number string is " + numStr
1543:                            + " Expected: 123.457");
1544:                }
1545:
1546:                // Invalid number type
1547:                logln("INVALID type");
1548:                boolean illegalArg = false;
1549:                try {
1550:                    nf = gp.getNumberFormat(100);
1551:                } catch (IllegalArgumentException iae) {
1552:                    logln("Illegal number format type 100");
1553:                    illegalArg = true;
1554:                }
1555:                if (!illegalArg) {
1556:                    errln("FAIL: getNumberFormat must throw IllegalArgumentException for type 100");
1557:                }
1558:                illegalArg = false;
1559:                try {
1560:                    nf = gp.getNumberFormat(-1);
1561:                } catch (IllegalArgumentException iae) {
1562:                    logln("Illegal number format type -1");
1563:                    illegalArg = true;
1564:                }
1565:                if (!illegalArg) {
1566:                    errln("FAIL: getNumberFormat must throw IllegalArgumentException for type -1");
1567:                }
1568:
1569:                // Set explicit territory
1570:                logln("Set territory - US");
1571:                gp.setTerritory("US");
1572:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
1573:                numStr = nf.format(num);
1574:                if (!numStr.equals("123.456,79 $")) {
1575:                    errln("FAIL: Number string is " + numStr
1576:                            + " Expected: 123.456,79 $");
1577:                }
1578:
1579:                // Set explicit currency
1580:                logln("Set currency - GBP");
1581:                gp.setCurrency(Currency.getInstance("GBP"));
1582:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
1583:                numStr = nf.format(num);
1584:                if (!numStr.equals("123.456,79 \u00A3")) {
1585:                    errln("FAIL: Number string is " + numStr
1586:                            + " Expected: 123.456,79 \u00A3");
1587:                }
1588:
1589:                // Set exliplicit NumberFormat
1590:                logln("Set explicit NumberFormat objects");
1591:                NumberFormat customNum = NumberFormat
1592:                        .getNumberInstance(new ULocale("he_IL"));
1593:                gp.setNumberFormat(GlobalizationPreferences.NF_NUMBER,
1594:                        customNum);
1595:                NumberFormat customCur = NumberFormat
1596:                        .getCurrencyInstance(new ULocale("zh_CN"));
1597:                gp.setNumberFormat(GlobalizationPreferences.NF_CURRENCY,
1598:                        customCur);
1599:                NumberFormat customPct = NumberFormat
1600:                        .getPercentInstance(new ULocale("el_GR"));
1601:                gp.setNumberFormat(GlobalizationPreferences.NF_PERCENT,
1602:                        customPct);
1603:                NumberFormat customSci = NumberFormat
1604:                        .getScientificInstance(new ULocale("ru_RU"));
1605:                gp.setNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC,
1606:                        customSci);
1607:                NumberFormat customInt = NumberFormat
1608:                        .getIntegerInstance(new ULocale("pt_PT"));
1609:                gp.setNumberFormat(GlobalizationPreferences.NF_INTEGER,
1610:                        customInt);
1611:
1612:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
1613:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1614:                        "he_IL")) {
1615:                    errln("FAIL: The NumberFormat instance must use locale he_IL");
1616:                }
1617:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_CURRENCY);
1618:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1619:                        "zh_CN")) {
1620:                    errln("FAIL: The NumberFormat instance must use locale zh_CN");
1621:                }
1622:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_PERCENT);
1623:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1624:                        "el_GR")) {
1625:                    errln("FAIL: The NumberFormat instance must use locale el_GR");
1626:                }
1627:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_SCIENTIFIC);
1628:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1629:                        "ru_RU")) {
1630:                    errln("FAIL: The NumberFormat instance must use locale ru_RU");
1631:                }
1632:                nf = gp.getNumberFormat(GlobalizationPreferences.NF_INTEGER);
1633:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1634:                        "pt_PT")) {
1635:                    errln("FAIL: The NumberFormat instance must use locale pt_PT");
1636:                }
1637:
1638:                NumberFormat customNum1 = NumberFormat
1639:                        .getNumberInstance(new ULocale("hi_IN"));
1640:
1641:                // Freeze
1642:                logln("Freeze this object");
1643:                boolean isFrozen = false;
1644:                gp.freeze();
1645:                try {
1646:                    gp.setNumberFormat(GlobalizationPreferences.NF_NUMBER,
1647:                            customNum1);
1648:                } catch (UnsupportedOperationException uoe) {
1649:                    logln("setNumberFormat is blocked");
1650:                    isFrozen = true;
1651:                }
1652:                if (!isFrozen) {
1653:                    errln("FAIL: setNumberFormat must be blocked after frozen");
1654:                }
1655:
1656:                // Create a modifiable clone
1657:                GlobalizationPreferences gp1 = (GlobalizationPreferences) gp
1658:                        .cloneAsThawed();
1659:
1660:                // Number type format's locale is still he_IL
1661:                nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
1662:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1663:                        "he_IL")) {
1664:                    errln("FAIL: The NumberFormat instance must use locale he_IL");
1665:                }
1666:
1667:                logln("Set custom number format using locale hi_IN");
1668:                gp1.setNumberFormat(GlobalizationPreferences.NF_NUMBER,
1669:                        customNum1);
1670:                nf = gp1.getNumberFormat(GlobalizationPreferences.NF_NUMBER);
1671:                if (!nf.getLocale(ULocale.VALID_LOCALE).toString().equals(
1672:                        "hi_IN")) {
1673:                    errln("FAIL: The NumberFormat instance must use locale hi_IN");
1674:                }
1675:            }
1676:
1677:            /*
1678:             * JB#5380 GlobalizationPreferences#getCalendar() should return a Calendar object
1679:             * initialized with the current time
1680:             */
1681:            public void TestJB5380() {
1682:                GlobalizationPreferences gp = new GlobalizationPreferences();
1683:                GregorianCalendar gcal = new GregorianCalendar();
1684:
1685:                // set way old date
1686:                gcal.set(Calendar.YEAR, 1950);
1687:
1688:                // set calendar to GP
1689:                gp.setCalendar(gcal);
1690:
1691:                Calendar cal = gp.getCalendar();
1692:                // Calendar instance returned from GP should be initialized
1693:                // by the current time
1694:                long timeDiff = System.currentTimeMillis()
1695:                        - gp.getCalendar().getTimeInMillis();
1696:                if (Math.abs(timeDiff) > 1000) {
1697:                    // if difference is more than 1 second..
1698:                    errln("FAIL: The Calendar was not initialized by current time - difference:"
1699:                            + timeDiff);
1700:                }
1701:            }
1702:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.