diff --git a/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java b/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java index eb1c3060345099d110598bd4090d973f0d0743ae..491a941084d7e5ba50ec52f2a23b647171b7a4e5 100644 --- a/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java +++ b/test/com/sun/org/apache/xml/internal/security/exceptions/LocaleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,15 +36,19 @@ public class LocaleTest { public static void main(String[] args) throws Exception { - Locale.setDefault(Locale.ITALY); - + Locale reservedLocale = Locale.getDefault(); try { + Locale.setDefault(Locale.ITALY); + throw new XMLSecurityException("foo"); } catch (XMLSecurityException xse) { System.out.println("Test PASSED"); } catch (Throwable t) { System.out.println("Test FAILED"); t.printStackTrace(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } } } diff --git a/test/java/beans/XMLDecoder/Test6341798.java b/test/java/beans/XMLDecoder/Test6341798.java index ce22846315e4fe04200e83a37fb1785f373cd83f..59480943379464f300c1b71e5df97033310f3e5d 100644 --- a/test/java/beans/XMLDecoder/Test6341798.java +++ b/test/java/beans/XMLDecoder/Test6341798.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -47,8 +47,14 @@ public class Test6341798 { + " "; public static void main(String[] args) { - test(ENGLISH, DATA.getBytes()); - test(TURKISH, DATA.getBytes()); + Locale reservedLocale = Locale.getDefault(); + try { + test(ENGLISH, DATA.getBytes()); + test(TURKISH, DATA.getBytes()); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } private static void test(Locale locale, byte[] data) { diff --git a/test/java/io/pathNames/win32/bug6344646.java b/test/java/io/pathNames/win32/bug6344646.java index 227adc87ed81dce0cfb096b12ae4b98281516b0e..d39dd40cf3604bdf93edeea64ace6b870851465b 100644 --- a/test/java/io/pathNames/win32/bug6344646.java +++ b/test/java/io/pathNames/win32/bug6344646.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,17 +32,24 @@ import java.util.*; public class bug6344646 { public static void main(String[] s) { - /* This test is only valid on win32 systems */ - if (File.separatorChar != '\\') { - return; - } + Locale reservedLocale = Locale.getDefault(); + try { + /* This test is only valid on win32 systems */ + if (File.separatorChar != '\\') { + return; + } - Locale.setDefault(new Locale("lt")); - File f1 = new File("J\u0301"); - File f2 = new File("j\u0301"); + Locale.setDefault(new Locale("lt")); + File f1 = new File("J\u0301"); + File f2 = new File("j\u0301"); - if (f1.hashCode() != f2.hashCode()) { - throw new RuntimeException("File.hashCode() for \"J\u0301\" and \"j\u0301\" should be the same"); + if (f1.hashCode() != f2.hashCode()) { + throw new RuntimeException("File.hashCode() for \"J\u0301\" " + + "and \"j\u0301\" should be the same"); + } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } } } diff --git a/test/java/net/CookieHandler/B6791927.java b/test/java/net/CookieHandler/B6791927.java index e4ee023250538348f3e1132e4501c6db596d9f3c..65b60cb2d25edef9256645e1b4391a8ebd02a113 100644 --- a/test/java/net/CookieHandler/B6791927.java +++ b/test/java/net/CookieHandler/B6791927.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,16 +33,23 @@ import java.util.Locale; public class B6791927 { public static final void main( String[] aaParamters ) throws Exception{ - // Forces a non US locale - Locale.setDefault(Locale.FRANCE); - List cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT"); - if (cookies == null || cookies.isEmpty()) { - throw new RuntimeException("No cookie found"); - } - for (HttpCookie c : cookies) { - if (c.getMaxAge() == 0) { - throw new RuntimeException("Expiration date shouldn't be 0"); + Locale reservedLocale = Locale.getDefault(); + try { + // Forces a non US locale + Locale.setDefault(Locale.FRANCE); + List cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT"); + if (cookies == null || cookies.isEmpty()) { + throw new RuntimeException("No cookie found"); + } + for (HttpCookie c : cookies) { + if (c.getMaxAge() == 0) { + throw new RuntimeException( + "Expiration date shouldn't be 0"); + } } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } } } diff --git a/test/java/net/URLConnection/SetIfModifiedSince.java b/test/java/net/URLConnection/SetIfModifiedSince.java index 597610e9108adeced6c5ef8a23796083beffe040..dac00c72005580ec98d2f2c6fa7ee3a89cff7520 100644 --- a/test/java/net/URLConnection/SetIfModifiedSince.java +++ b/test/java/net/URLConnection/SetIfModifiedSince.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,6 +73,7 @@ public class SetIfModifiedSince { } public static void main (String[] args) { + Locale reservedLocale = Locale.getDefault(); try { Locale.setDefault(Locale.JAPAN); ServerSocket serversocket = new ServerSocket (0); @@ -87,6 +88,10 @@ public class SetIfModifiedSince { int i=0, c; Thread.sleep (5000); } catch (Exception e) { + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } + } } diff --git a/test/java/util/Locale/LocaleCategory.java b/test/java/util/Locale/LocaleCategory.java index e083c62ef212d4a3a494611537b919d92cb47063..39f942e8b9bee1a3cc62ca3d85f54bc50816aa74 100644 --- a/test/java/util/Locale/LocaleCategory.java +++ b/test/java/util/Locale/LocaleCategory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,30 +29,37 @@ public class LocaleCategory { private static String enc = null; public static void main(String[] args) { - Locale.Builder builder = new Locale.Builder(); + Locale reservedLocale = Locale.getDefault(); + try { + Locale.Builder builder = new Locale.Builder(); - base = builder.setLanguage(System.getProperty("user.language", "")) - .setScript(System.getProperty("user.script", "")) - .setRegion(System.getProperty("user.country", "")) - .setVariant(System.getProperty("user.variant", "")).build(); - disp = builder.setLanguage(System.getProperty("user.language.display", - Locale.getDefault().getLanguage())) - .setScript(System.getProperty("user.script.display", - Locale.getDefault().getScript())) - .setRegion(System.getProperty("user.country.display", - Locale.getDefault().getCountry())) - .setVariant(System.getProperty("user.variant.display", - Locale.getDefault().getVariant())).build(); - fmt = builder.setLanguage(System.getProperty("user.language.format", - Locale.getDefault().getLanguage())) - .setScript(System.getProperty("user.script.format", - Locale.getDefault().getScript())) - .setRegion(System.getProperty("user.country.format", - Locale.getDefault().getCountry())) - .setVariant(System.getProperty("user.variant.format", - Locale.getDefault().getVariant())).build(); - checkDefault(); - testGetSetDefault(); + base = builder.setLanguage(System.getProperty("user.language", "")) + .setScript(System.getProperty("user.script", "")) + .setRegion(System.getProperty("user.country", "")) + .setVariant(System.getProperty("user.variant", "")).build(); + disp = builder.setLanguage( + System.getProperty("user.language.display", + Locale.getDefault().getLanguage())) + .setScript(System.getProperty("user.script.display", + Locale.getDefault().getScript())) + .setRegion(System.getProperty("user.country.display", + Locale.getDefault().getCountry())) + .setVariant(System.getProperty("user.variant.display", + Locale.getDefault().getVariant())).build(); + fmt = builder.setLanguage(System.getProperty("user.language.format", + Locale.getDefault().getLanguage())) + .setScript(System.getProperty("user.script.format", + Locale.getDefault().getScript())) + .setRegion(System.getProperty("user.country.format", + Locale.getDefault().getCountry())) + .setVariant(System.getProperty("user.variant.format", + Locale.getDefault().getVariant())).build(); + checkDefault(); + testGetSetDefault(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } static void checkDefault() { diff --git a/test/java/util/PluggableLocale/CurrencyNameProviderTest.java b/test/java/util/PluggableLocale/CurrencyNameProviderTest.java index 745b3b9f73924ec8ccd65328085f1d327397c952..3fd621a47fd0c1cf1bffdebe45f4a5c98a3afc62 100644 --- a/test/java/util/PluggableLocale/CurrencyNameProviderTest.java +++ b/test/java/util/PluggableLocale/CurrencyNameProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,13 @@ import sun.util.resources.*; public class CurrencyNameProviderTest extends ProviderTest { public static void main(String[] s) { - new CurrencyNameProviderTest(); + Locale reservedLocale = Locale.getDefault(); + try { + new CurrencyNameProviderTest(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } CurrencyNameProviderTest() { diff --git a/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java b/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java index 4f3dad025b3d34fd5be93621e8a9d0c76467c244..15f2890da7bf91fb4a5de352950072a3dd3cab4c 100644 --- a/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java +++ b/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -113,6 +113,7 @@ public class TimeZoneNameProviderTest extends ProviderTest { void test2() { Locale defaultLocale = Locale.getDefault(); + TimeZone reservedTimeZone = TimeZone.getDefault(); Date d = new Date(2005-1900, Calendar.DECEMBER, 22); String formatted; @@ -139,7 +140,6 @@ public class TimeZoneNameProviderTest extends ProviderTest { df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance()); System.out.println(formatted = df.format(d)); if(!formatted.equals(DISPLAY_NAMES_KYOTO[i])) { - Locale.setDefault(defaultLocale); throw new RuntimeException("Timezone " + TIMEZONES[i] + ": formatted zone names mismatch. " + formatted + " should match with " + @@ -148,10 +148,12 @@ public class TimeZoneNameProviderTest extends ProviderTest { df.parse(DISPLAY_NAMES_KYOTO[i]); } } catch (ParseException pe) { - Locale.setDefault(defaultLocale); throw new RuntimeException("parse error occured" + pe); + } finally { + // restore the reserved locale and time zone + Locale.setDefault(defaultLocale); + TimeZone.setDefault(reservedTimeZone); } - Locale.setDefault(defaultLocale); } final String LATIME = "America/Los_Angeles"; diff --git a/test/java/util/ResourceBundle/Bug6190861.java b/test/java/util/ResourceBundle/Bug6190861.java index dd9837f3fc30a97340740f4ee4b781aa0df3d23c..48dd92099223d71f0b54c1fb0787b47fdcfb5170 100644 --- a/test/java/util/ResourceBundle/Bug6190861.java +++ b/test/java/util/ResourceBundle/Bug6190861.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,27 +32,34 @@ import java.util.*; public class Bug6190861 { static public void main(String[] args) { - Locale.setDefault(new Locale("en", "US")); + Locale reservedLocale = Locale.getDefault(); + try { + Locale.setDefault(new Locale("en", "US")); - List localeList = new ArrayList(); - localeList.add(Locale.ENGLISH); - localeList.add(Locale.KOREA); - localeList.add(Locale.UK); - localeList.add(new Locale("en", "CA")); - localeList.add(Locale.ENGLISH); + List localeList = new ArrayList(); + localeList.add(Locale.ENGLISH); + localeList.add(Locale.KOREA); + localeList.add(Locale.UK); + localeList.add(new Locale("en", "CA")); + localeList.add(Locale.ENGLISH); - Iterator iter = localeList.iterator(); - while (iter.hasNext()){ - Locale currentLocale = (Locale) iter.next(); - System.out.println("\ncurrentLocale = " + Iterator iter = localeList.iterator(); + while (iter.hasNext()){ + Locale currentLocale = (Locale) iter.next(); + System.out.println("\ncurrentLocale = " + currentLocale.getDisplayName()); - ResourceBundle messages = ResourceBundle.getBundle("Bug6190861Data",currentLocale); + ResourceBundle messages = + ResourceBundle.getBundle("Bug6190861Data",currentLocale); - Locale messagesLocale = messages.getLocale(); - System.out.println("messagesLocale = " + Locale messagesLocale = messages.getLocale(); + System.out.println("messagesLocale = " + messagesLocale.getDisplayName()); - checkMessages(messages); + checkMessages(messages); + } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } } diff --git a/test/java/util/ResourceBundle/Control/Bug6530694.java b/test/java/util/ResourceBundle/Control/Bug6530694.java index b76f0aeb77eedfb3f8c058f5911bca28e4ed09bf..7f22cc98ae05a24725b2cce1c7f3f19bc131bdd5 100644 --- a/test/java/util/ResourceBundle/Control/Bug6530694.java +++ b/test/java/util/ResourceBundle/Control/Bug6530694.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,6 +43,12 @@ public class Bug6530694 { } public static void main(String[] args) { - new Bug6530694(); + Locale reservedLocale = Locale.getDefault(); + try { + new Bug6530694(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } } diff --git a/test/java/util/ResourceBundle/Control/StressTest.java b/test/java/util/ResourceBundle/Control/StressTest.java index 401f6b43091ec91b73ef1986eea77d2fabfcdbf3..abead81d2e5b2d1cfa2721c191d4cebd78d8cae0 100644 --- a/test/java/util/ResourceBundle/Control/StressTest.java +++ b/test/java/util/ResourceBundle/Control/StressTest.java @@ -69,36 +69,44 @@ public class StressTest { if (args.length > 1) { duration = Math.max(5, Integer.parseInt(args[1])); } - Locale.setDefault(Locale.US); - Thread[] tasks = new Thread[locales.length * threadsFactor]; - counters = new AtomicIntegerArray(tasks.length); - for (int i = 0; i < tasks.length; i++) { - tasks[i] = new Thread(new Worker(i)); - } - for (int i = 0; i < tasks.length; i++) { - tasks[i].start(); - } - - int nProcessors = Runtime.getRuntime().availableProcessors(); - intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1); - System.out.printf("%d processors, intervalForCounterCheck = %d [sec]%n", - nProcessors, intervalForCounterCheck); + Locale reservedLocale = Locale.getDefault(); try { - for (int i = 0; runrun && i < duration; i++) { - Thread.sleep(1000); // 1 second - if ((i % intervalForCounterCheck) == 0) { - checkCounters(); - } + Locale.setDefault(Locale.US); + Thread[] tasks = new Thread[locales.length * threadsFactor]; + counters = new AtomicIntegerArray(tasks.length); + + for (int i = 0; i < tasks.length; i++) { + tasks[i] = new Thread(new Worker(i)); } - runrun = false; for (int i = 0; i < tasks.length; i++) { - tasks[i].join(); + tasks[i].start(); } - } catch (InterruptedException e) { - } - printCounters(); + int nProcessors = Runtime.getRuntime().availableProcessors(); + intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1); + System.out.printf( + "%d processors, intervalForCounterCheck = %d [sec]%n", + nProcessors, intervalForCounterCheck); + try { + for (int i = 0; runrun && i < duration; i++) { + Thread.sleep(1000); // 1 second + if ((i % intervalForCounterCheck) == 0) { + checkCounters(); + } + } + runrun = false; + for (int i = 0; i < tasks.length; i++) { + tasks[i].join(); + } + } catch (InterruptedException e) { + } + + printCounters(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } static void checkCounters() { diff --git a/test/java/util/ResourceBundle/Test4314141.java b/test/java/util/ResourceBundle/Test4314141.java index f41a2dc0525e510dd5088759a6f3523b3a4b7be5..fc7d9ca086a74ed52fecb90c1fb6e5c8b955e6e9 100644 --- a/test/java/util/ResourceBundle/Test4314141.java +++ b/test/java/util/ResourceBundle/Test4314141.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,8 +35,14 @@ import java.util.MissingResourceException; public class Test4314141 { public static void main(String[] args) { - testCandidateOmission(); - testExample(); + Locale reservedLocale = Locale.getDefault(); + try { + testCandidateOmission(); + testExample(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } /** diff --git a/test/java/util/ResourceBundle/Test4318520.java b/test/java/util/ResourceBundle/Test4318520.java index 79605bd075ec44d59675f3d7378610517a485d36..6385486e2da37430b53072f32568a5390f78b6a2 100644 --- a/test/java/util/ResourceBundle/Test4318520.java +++ b/test/java/util/ResourceBundle/Test4318520.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,8 +36,14 @@ import java.util.Locale; public class Test4318520 { public static void main(String[] args) { - test(Locale.GERMAN); - test(Locale.ENGLISH); + Locale reservedLocale = Locale.getDefault(); + try { + test(Locale.GERMAN); + test(Locale.ENGLISH); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } private static void test(Locale locale) { diff --git a/test/java/util/jar/JarFile/TurkCert.java b/test/java/util/jar/JarFile/TurkCert.java index 0d084e2ea7c7746963d5c32dceca3a9f41427ded..210cf5d3c20faf0283408280ae905487d83db19b 100644 --- a/test/java/util/jar/JarFile/TurkCert.java +++ b/test/java/util/jar/JarFile/TurkCert.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,6 @@ * @bug 4624534 * @summary Make sure jar certificates work for Turkish locale * @author kladko - * @run main/othervm TurkCert */ import java.util.*; @@ -36,15 +35,24 @@ import java.io.*; public class TurkCert { public static void main(String[] args) throws Exception{ - Locale.setDefault(new Locale("TR", "tr")); - File f = new File(System.getProperty("test.src","."), "test.jar"); - JarFile jf = new JarFile(f, true); - JarEntry je = (JarEntry)jf.getEntry("test.class"); - InputStream is = jf.getInputStream(je); - byte[] b = new byte[1024]; - while (is.read(b) != -1) { + Locale reservedLocale = Locale.getDefault(); + try { + Locale.setDefault(new Locale("TR", "tr")); + File f = new File(System.getProperty("test.src","."), "test.jar"); + try (JarFile jf = new JarFile(f, true)) { + JarEntry je = (JarEntry)jf.getEntry("test.class"); + try (InputStream is = jf.getInputStream(je)) { + byte[] b = new byte[1024]; + while (is.read(b) != -1) { + } + } + if (je.getCertificates() == null) { + throw new Exception("Null certificate for test.class."); + } + } + } finally { + // restore the default locale + Locale.setDefault(reservedLocale); } - if (je.getCertificates() == null) - throw new Exception("Null certificate for test.class."); } } diff --git a/test/javax/crypto/Cipher/Turkish.java b/test/javax/crypto/Cipher/Turkish.java index b19b889b8399885102ac327560dc3ada9aa105e0..1f63ff86bc564be81663a9bfd3c03d8dc251773c 100644 --- a/test/javax/crypto/Cipher/Turkish.java +++ b/test/javax/crypto/Cipher/Turkish.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,15 +35,21 @@ import javax.crypto.Cipher; public class Turkish { public static void main(String[] args) throws Exception { - Locale.setDefault(new Locale("tr", "TR")); + Locale reservedLocale = Locale.getDefault(); + try { + Locale.setDefault(new Locale("tr", "TR")); - System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding")); - System.out.println(Cipher.getInstance("RSA/ECB/PKCS1PADDING")); - System.out.println(Cipher.getInstance("rsa/ecb/pkcs1padding")); - System.out.println(Cipher.getInstance("Blowfish")); - System.out.println(Cipher.getInstance("blowfish")); - System.out.println(Cipher.getInstance("BLOWFISH")); + System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding")); + System.out.println(Cipher.getInstance("RSA/ECB/PKCS1PADDING")); + System.out.println(Cipher.getInstance("rsa/ecb/pkcs1padding")); + System.out.println(Cipher.getInstance("Blowfish")); + System.out.println(Cipher.getInstance("blowfish")); + System.out.println(Cipher.getInstance("BLOWFISH")); - System.out.println("OK"); + System.out.println("OK"); + } finally { + // restore the default locale + Locale.setDefault(reservedLocale); + } } } diff --git a/test/javax/swing/JColorChooser/Test6524757.java b/test/javax/swing/JColorChooser/Test6524757.java index 09838b4b1c456bfde7c14962d269c9f82ce43634..779ef7ba88d543b6d82194689ea5527f56c71332 100644 --- a/test/javax/swing/JColorChooser/Test6524757.java +++ b/test/javax/swing/JColorChooser/Test6524757.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -98,17 +98,23 @@ public class Test6524757 { private static final Object[] FRENCH = convert(Locale.FRENCH, KEYS); public static void main(String[] args) { - // it affects Swing because it is not initialized - Locale.setDefault(Locale.KOREAN); - validate(KOREAN, create()); - - // it does not affect Swing because it is initialized - Locale.setDefault(Locale.CANADA); - validate(KOREAN, create()); - - // it definitely should affect Swing - JComponent.setDefaultLocale(Locale.FRENCH); - validate(FRENCH, create()); + Locale reservedLocale = Locale.getDefault(); + try { + // it affects Swing because it is not initialized + Locale.setDefault(Locale.KOREAN); + validate(KOREAN, create()); + + // it does not affect Swing because it is initialized + Locale.setDefault(Locale.CANADA); + validate(KOREAN, create()); + + // it definitely should affect Swing + JComponent.setDefaultLocale(Locale.FRENCH); + validate(FRENCH, create()); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } private static void validate(Object[] expected, Object[] actual) { diff --git a/test/sun/security/tools/keytool/KeyToolTest.java b/test/sun/security/tools/keytool/KeyToolTest.java index f6f3bcfb7648bf2ca7c69f88742312da9d47bdec..ab7474ae05bcf4fa14fa71890f382495af50a50f 100644 --- a/test/sun/security/tools/keytool/KeyToolTest.java +++ b/test/sun/security/tools/keytool/KeyToolTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1278,52 +1278,58 @@ public class KeyToolTest { } public static void main(String[] args) throws Exception { - // first test if HumanInputStream really acts like a human being - HumanInputStream.test(); - KeyToolTest t = new KeyToolTest(); - - if (System.getProperty("file") != null) { - t.sqeTest(); - t.testAll(); - t.i18nTest(); - t.v3extTest("RSA"); - t.v3extTest("DSA"); - boolean testEC = true; - try { - KeyPairGenerator.getInstance("EC"); - } catch (NoSuchAlgorithmException nae) { - testEC = false; + Locale reservedLocale = Locale.getDefault(); + try { + // first test if HumanInputStream really acts like a human being + HumanInputStream.test(); + KeyToolTest t = new KeyToolTest(); + + if (System.getProperty("file") != null) { + t.sqeTest(); + t.testAll(); + t.i18nTest(); + t.v3extTest("RSA"); + t.v3extTest("DSA"); + boolean testEC = true; + try { + KeyPairGenerator.getInstance("EC"); + } catch (NoSuchAlgorithmException nae) { + testEC = false; + } + if (testEC) t.v3extTest("EC"); } - if (testEC) t.v3extTest("EC"); - } - if (System.getProperty("nss") != null) { - t.srcP11Arg = NSS_SRC_P11_ARG; - t.p11Arg = NSS_P11_ARG; + if (System.getProperty("nss") != null) { + t.srcP11Arg = NSS_SRC_P11_ARG; + t.p11Arg = NSS_P11_ARG; - t.testPKCS11(); + t.testPKCS11(); - // FAIL: - // 1. we still don't have srcprovidername yet - // 2. cannot store privatekey into NSS keystore - // java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE. - //t.testPKCS11ImportKeyStore(); + // FAIL: + // 1. we still don't have srcprovidername yet + // 2. cannot store privatekey into NSS keystore + // java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE. + //t.testPKCS11ImportKeyStore(); - t.i18nPKCS11Test(); - //FAIL: currently PKCS11-NSS does not support 2 NSS KeyStores to be loaded at the same time - //t.sszzTest(); - } + t.i18nPKCS11Test(); + //FAIL: currently PKCS11-NSS does not support 2 NSS KeyStores to be loaded at the same time + //t.sszzTest(); + } - if (System.getProperty("solaris") != null) { - // For Solaris Cryptography Framework - t.srcP11Arg = SUN_SRC_P11_ARG; - t.p11Arg = SUN_P11_ARG; - t.testPKCS11(); - t.testPKCS11ImportKeyStore(); - t.i18nPKCS11Test(); - } + if (System.getProperty("solaris") != null) { + // For Solaris Cryptography Framework + t.srcP11Arg = SUN_SRC_P11_ARG; + t.p11Arg = SUN_P11_ARG; + t.testPKCS11(); + t.testPKCS11ImportKeyStore(); + t.i18nPKCS11Test(); + } - System.out.println("Test pass!!!"); + System.out.println("Test pass!!!"); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } } diff --git a/test/sun/text/resources/Collator/Bug4248694.java b/test/sun/text/resources/Collator/Bug4248694.java index 60b36edc9f5492e4741c006aa752a90297902d1d..b9339744f7eb494b5176bf230d43cae6c5a65171 100644 --- a/test/sun/text/resources/Collator/Bug4248694.java +++ b/test/sun/text/resources/Collator/Bug4248694.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,43 +35,49 @@ public class Bug4248694 { /******************************************************** *********************************************************/ public static void main (String[] args) { - int errors=0; + Locale reservedLocale = Locale.getDefault(); + try { + int errors=0; - Locale loc = new Locale ("is", "is"); // Icelandic + Locale loc = new Locale ("is", "is"); // Icelandic - Locale.setDefault (loc); - Collator col = Collator.getInstance (); + Locale.setDefault (loc); + Collator col = Collator.getInstance (); - String[] data = {"\u00e6ard", - "Zard", - "aard", - "\u00feard", - "vird", - "\u00c6ard", - "Zerd", - "\u00deard"}; + String[] data = {"\u00e6ard", + "Zard", + "aard", + "\u00feard", + "vird", + "\u00c6ard", + "Zerd", + "\u00deard"}; - String[] sortedData = {"aard", - "vird", - "Zard", - "Zerd", - "\u00feard", - "\u00deard", - "\u00e6ard", - "\u00c6ard"}; + String[] sortedData = {"aard", + "vird", + "Zard", + "Zerd", + "\u00feard", + "\u00deard", + "\u00e6ard", + "\u00c6ard"}; - Arrays.sort (data, col); + Arrays.sort (data, col); - System.out.println ("Using " + loc.getDisplayName()); - for (int i = 0; i < data.length; i++) { - System.out.println(data[i] + " : " + sortedData[i]); - if (sortedData[i].compareTo(data[i]) != 0) { - errors++; - } - }//end for + System.out.println ("Using " + loc.getDisplayName()); + for (int i = 0; i < data.length; i++) { + System.out.println(data[i] + " : " + sortedData[i]); + if (sortedData[i].compareTo(data[i]) != 0) { + errors++; + } + }//end for - if (errors > 0) - throw new RuntimeException(); + if (errors > 0) + throw new RuntimeException(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } }//end main }//end class CollatorTest diff --git a/test/sun/text/resources/Collator/Bug4804273.java b/test/sun/text/resources/Collator/Bug4804273.java index 0d1fa930f66df50943f9284c4bd8f4b9cf6ef9dd..0d60f3062e7fd442acae55bf5a49768717ec2e10 100644 --- a/test/sun/text/resources/Collator/Bug4804273.java +++ b/test/sun/text/resources/Collator/Bug4804273.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,82 +35,89 @@ public class Bug4804273 { /******************************************************** *********************************************************/ public static void main (String[] args) { - int errors=0; + Locale reservedLocale = Locale.getDefault(); + try { + int errors=0; - Locale loc = new Locale ("sv", "se"); // Swedish + Locale loc = new Locale ("sv", "se"); // Swedish - Locale.setDefault (loc); - Collator col = Collator.getInstance (); + Locale.setDefault (loc); + Collator col = Collator.getInstance (); - String[] data = {"A", - "Aa", - "Ae", - "B", - "Y", - "U\u0308", // U-umlaut - "Z", - "A\u030a", // A-ring - "A\u0308", // A-umlaut - "\u00c6", // AE ligature - "O\u0308", // O-umlaut - "a\u030b", // a-double-acute - "\u00d8", // O-stroke - "a", - "aa", - "ae", - "b", - "y", - "u\u0308", // u-umlaut - "z", - "A\u030b", // A-double-acute - "a\u030a", // a-ring - "a\u0308", // a-umlaut - "\u00e6", // ae ligature - "o\u0308", // o-umlaut - "\u00f8", // o-stroke - }; + String[] data = {"A", + "Aa", + "Ae", + "B", + "Y", + "U\u0308", // U-umlaut + "Z", + "A\u030a", // A-ring + "A\u0308", // A-umlaut + "\u00c6", // AE ligature + "O\u0308", // O-umlaut + "a\u030b", // a-double-acute + "\u00d8", // O-stroke + "a", + "aa", + "ae", + "b", + "y", + "u\u0308", // u-umlaut + "z", + "A\u030b", // A-double-acute + "a\u030a", // a-ring + "a\u0308", // a-umlaut + "\u00e6", // ae ligature + "o\u0308", // o-umlaut + "\u00f8", // o-stroke + }; - String[] sortedData = {"a", - "A", - "aa", - "Aa", - "ae", - "Ae", - "b", - "B", - "y", - "Y", - "u\u0308", // o-umlaut - "U\u0308", // o-umlaut - "z", - "Z", - "a\u030a", // a-ring - "A\u030a", // A-ring - "a\u0308", // a-umlaut - "A\u0308", // A-umlaut - "a\u030b", // a-double-acute - "A\u030b", // A-double-acute - "\u00e6", // ae ligature - "\u00c6", // AE ligature - "o\u0308", // o-umlaut - "O\u0308", // O-umlaut - "\u00f8", // o-stroke - "\u00d8", // O-stroke - }; + String[] sortedData = {"a", + "A", + "aa", + "Aa", + "ae", + "Ae", + "b", + "B", + "y", + "Y", + "u\u0308", // o-umlaut + "U\u0308", // o-umlaut + "z", + "Z", + "a\u030a", // a-ring + "A\u030a", // A-ring + "a\u0308", // a-umlaut + "A\u0308", // A-umlaut + "a\u030b", // a-double-acute + "A\u030b", // A-double-acute + "\u00e6", // ae ligature + "\u00c6", // AE ligature + "o\u0308", // o-umlaut + "O\u0308", // O-umlaut + "\u00f8", // o-stroke + "\u00d8", // O-stroke + }; - Arrays.sort (data, col); + Arrays.sort (data, col); - System.out.println ("Using " + loc.getDisplayName()); - for (int i = 0; i < data.length; i++) { - System.out.println(data[i] + " : " + sortedData[i]); - if (sortedData[i].compareTo(data[i]) != 0) { - errors++; - } - }//end for + System.out.println ("Using " + loc.getDisplayName()); + for (int i = 0; i < data.length; i++) { + System.out.println(data[i] + " : " + sortedData[i]); + if (sortedData[i].compareTo(data[i]) != 0) { + errors++; + } + }//end for - if (errors > 0) - throw new RuntimeException("There are " + errors + " words sorted incorrectly!"); + if (errors > 0) + throw new RuntimeException("There are " + errors + + " words sorted incorrectly!"); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } }//end main }//end class CollatorTest diff --git a/test/sun/text/resources/Collator/Bug4848897.java b/test/sun/text/resources/Collator/Bug4848897.java index 250c14a9a78e12192213ef4dffb4d57db53f263d..fdb36ff8ad60e99aa04a0618cac41b5a500e5378 100644 --- a/test/sun/text/resources/Collator/Bug4848897.java +++ b/test/sun/text/resources/Collator/Bug4848897.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,39 +35,44 @@ public class Bug4848897 { /******************************************************** *********************************************************/ public static void main (String[] args) { + Locale reservedLocale = Locale.getDefault(); + try { + int errors=0; + Locale loc = new Locale ("no", "NO"); // Norwegian - int errors=0; - Locale loc = new Locale ("no", "NO"); // Norwegian + Locale.setDefault (loc); + Collator col = Collator.getInstance (); - Locale.setDefault (loc); - Collator col = Collator.getInstance (); + String[] data = {"wird", + "vird", + "verd", + "werd", + "vard", + "ward"}; - String[] data = {"wird", - "vird", - "verd", - "werd", - "vard", - "ward"}; + String[] sortedData = {"vard", + "verd", + "vird", + "ward", + "werd", + "wird"}; - String[] sortedData = {"vard", - "verd", - "vird", - "ward", - "werd", - "wird"}; + Arrays.sort (data, col); - Arrays.sort (data, col); + System.out.println ("Using " + loc.getDisplayName()); + for (int i = 0; i < data.length; i++) { + System.out.println(data[i] + " : " + sortedData[i]); + if (sortedData[i].compareTo(data[i]) != 0) { + errors++; + } + }//end for - System.out.println ("Using " + loc.getDisplayName()); - for (int i = 0; i < data.length; i++) { - System.out.println(data[i] + " : " + sortedData[i]); - if (sortedData[i].compareTo(data[i]) != 0) { - errors++; - } - }//end for - - if (errors > 0) - throw new RuntimeException(); - }//end main + if (errors > 0) + throw new RuntimeException(); + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } + } // end main }//end class CollatorTest diff --git a/test/sun/text/resources/Format/Bug4651568.java b/test/sun/text/resources/Format/Bug4651568.java index 63b99ffbb99c31dea9a8faae830b7b10d1888ac3..510097e8a18f530b2dce3232b69fe56a8629d8e8 100644 --- a/test/sun/text/resources/Format/Bug4651568.java +++ b/test/sun/text/resources/Format/Bug4651568.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,23 +34,29 @@ import java.util.Locale; public class Bug4651568 { public static void main (String argv[] ) { - String expectedCurrencyPattern = "\u00A4 #.##0,00"; - - Locale locale = new Locale ("pt", "BR"); - Locale.setDefault(locale); - - DecimalFormat formatter = - (DecimalFormat) NumberFormat.getCurrencyInstance(locale); - - if (formatter.toLocalizedPattern().equals(expectedCurrencyPattern)) -{ - System.out.println ("Passed."); - } else { - System.out.println ("Failed Currency pattern." + - " Expected: " + expectedCurrencyPattern + - " Received: " + formatter.toLocalizedPattern() ); - throw new RuntimeException(); - - } + Locale reservedLocale = Locale.getDefault(); + try { + String expectedCurrencyPattern = "\u00A4 #.##0,00"; + + Locale locale = new Locale ("pt", "BR"); + Locale.setDefault(locale); + + DecimalFormat formatter = + (DecimalFormat) NumberFormat.getCurrencyInstance(locale); + + if (formatter.toLocalizedPattern().equals( + expectedCurrencyPattern)) { + System.out.println ("Passed."); + } else { + System.out.println ("Failed Currency pattern." + + " Expected: " + expectedCurrencyPattern + + " Received: " + formatter.toLocalizedPattern() ); + throw new RuntimeException(); + + } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } } diff --git a/test/sun/util/resources/Locale/Bug4965260.java b/test/sun/util/resources/Locale/Bug4965260.java index 177c4c3b5206338f865458e2b40d33f2c2ec2f72..16c88c2e932a8c2d02adc77b195354ba21d77fd3 100644 --- a/test/sun/util/resources/Locale/Bug4965260.java +++ b/test/sun/util/resources/Locale/Bug4965260.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,49 +30,55 @@ import java.util.Locale; public class Bug4965260 { - // Define supported locales - static Locale[] locales2Test = new Locale[] { - new Locale("de"), - new Locale("es"), - new Locale("fr"), - new Locale("it"), - new Locale("sv") - }; + // Define supported locales + static Locale[] locales2Test = new Locale[] { + new Locale("de"), + new Locale("es"), + new Locale("fr"), + new Locale("it"), + new Locale("sv") + }; - static String[] expectedNames = new String[] { - "Niederl\u00e4ndisch", - "neerland\u00e9s", - "n\u00e9erlandais", - "neerlandese", - "nederl\u00e4ndska" - }; + static String[] expectedNames = new String[] { + "Niederl\u00e4ndisch", + "neerland\u00e9s", + "n\u00e9erlandais", + "neerlandese", + "nederl\u00e4ndska" + }; - public static void main(String[] args) throws Exception { - Locale.setDefault(Locale.ENGLISH); - if (locales2Test.length != expectedNames.length) { - throw new Exception("\nData sizes does not match!\n"); - } + public static void main(String[] args) throws Exception { + Locale reservedLocale = Locale.getDefault(); + try { + Locale.setDefault(Locale.ENGLISH); + if (locales2Test.length != expectedNames.length) { + throw new Exception("\nData sizes does not match!\n"); + } - StringBuffer message = new StringBuffer(""); - Locale dutch = new Locale("nl", "BE"); - String current; - for (int i = 0; i < locales2Test.length; i++) { - Locale locale = locales2Test[i]; - current = dutch.getDisplayLanguage(locale); - if (!current.equals(expectedNames[i])) { - message.append("["); - message.append(locale.getDisplayLanguage()); - message.append("] "); - message.append("Language name is "); - message.append(current); - message.append(" should be "); - message.append(expectedNames[i]); - message.append("\n"); - } - } + StringBuffer message = new StringBuffer(""); + Locale dutch = new Locale("nl", "BE"); + String current; + for (int i = 0; i < locales2Test.length; i++) { + Locale locale = locales2Test[i]; + current = dutch.getDisplayLanguage(locale); + if (!current.equals(expectedNames[i])) { + message.append("["); + message.append(locale.getDisplayLanguage()); + message.append("] "); + message.append("Language name is "); + message.append(current); + message.append(" should be "); + message.append(expectedNames[i]); + message.append("\n"); + } + } - if (message.length() >0) { - throw new Exception("\n" + message.toString()); + if (message.length() >0) { + throw new Exception("\n" + message.toString()); + } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); + } } - } } diff --git a/test/sun/util/resources/TimeZone/Bug4640234.java b/test/sun/util/resources/TimeZone/Bug4640234.java index 1fa9c2a19ccf04290c7cb0d86ecd9abd11c5f19b..a8766ea1224fc25d6cbab2c07ca8ded76d589741 100644 --- a/test/sun/util/resources/TimeZone/Bug4640234.java +++ b/test/sun/util/resources/TimeZone/Bug4640234.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,11 +24,11 @@ /** * @test * @bug 4640234 4946057 4938151 4873691 5023181 - * @summary Verifies the translation of time zone names, this test will catch presence - * of country name for english and selected locales for all ISO country - * codes. - * The test program also displays which timezone, country and language names - * are not translated + * @summary Verifies the translation of time zone names, this test will catch + * presence of country name for english and selected locales for all + * ISO country codes. + * The test program also displays which timezone, country and + * language names are not translated */ @@ -51,230 +51,242 @@ import java.util.TimeZone; public class Bug4640234 { - static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US); - static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US); - static Locale locEn = Locale.ENGLISH; - - static SimpleDateFormat sdfLoc; - static SimpleDateFormat sdfLocShort; - static Date date = new Date(); - - // Define supported locales - static Locale[] locales2Test = new Locale[] { - new Locale("de"), - new Locale("es"), - new Locale("fr"), - new Locale("it"), - new Locale("ja"), - new Locale("ko"), - new Locale("sv"), - new Locale("zh", "CN"), - new Locale("zh", "TW") - }; - - public static void main(String[] args) throws Exception { - Locale.setDefault(Locale.ENGLISH); - - StringBuffer errors = new StringBuffer(""); - StringBuffer warnings = new StringBuffer(""); - - String[] timezones = TimeZone.getAvailableIDs(); - String[] countries = locEn.getISOCountries(); - String[] languages = locEn.getISOLanguages(); - - ResourceBundle resEn = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locEn); - Map countryMapEn = getList(resEn, true); - Map languageMapEn = getList(resEn, false); - - ResourceBundle resLoc; - Map countryMap; - Map languageMap; - - for (Locale locale : locales2Test) { - resLoc = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locale); - - sdfLoc = new SimpleDateFormat("zzzz", locale); - sdfLocShort = new SimpleDateFormat("z", locale); - - for (String timezone : timezones) { - if (isTZIgnored(timezone)) { - continue; - } - warnings.append(testTZ(timezone, locale)); - } - - countryMap = getList(resLoc, true); - - for (String country : countries) { - String[] result = testEntry(country, - countryMapEn, - countryMap, - locale, - "ERROR: {0} country name for country code: {1} not found!\n", - "WARNING: {0} country name for country code: {1} not localized!\n" - ); - if (warnings.indexOf(result[0]) == -1) { - warnings.append(result[0]); - } - if (errors.indexOf(result[1]) == -1) { - errors.append(result[1]); - } - } - - languageMap = getList(resLoc, false); - for (String language : languages) { - String[] result = testEntry(language, - languageMapEn, - languageMap, - locale, - "ERROR: {0} language name for language code: {1} not found!\n", - "WARNING: {0} language name for language code: {1} not localized!\n"); - if (warnings.indexOf(result[0]) == -1) { - warnings.append(result[0]); - } - if (errors.indexOf(result[1]) == -1) { - errors.append(result[1]); + static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US); + static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US); + static Locale locEn = Locale.ENGLISH; + + static SimpleDateFormat sdfLoc; + static SimpleDateFormat sdfLocShort; + static Date date = new Date(); + + // Define supported locales + static Locale[] locales2Test = new Locale[] { + new Locale("de"), + new Locale("es"), + new Locale("fr"), + new Locale("it"), + new Locale("ja"), + new Locale("ko"), + new Locale("sv"), + new Locale("zh", "CN"), + new Locale("zh", "TW") + }; + + public static void main(String[] args) throws Exception { + Locale reservedLocale = Locale.getDefault(); + try { + Locale.setDefault(Locale.ENGLISH); + + StringBuffer errors = new StringBuffer(""); + StringBuffer warnings = new StringBuffer(""); + + String[] timezones = TimeZone.getAvailableIDs(); + String[] countries = locEn.getISOCountries(); + String[] languages = locEn.getISOLanguages(); + + ResourceBundle resEn = ResourceBundle.getBundle( + "sun.util.resources.LocaleNames", locEn); + Map countryMapEn = getList(resEn, true); + Map languageMapEn = getList(resEn, false); + + ResourceBundle resLoc; + Map countryMap; + Map languageMap; + + for (Locale locale : locales2Test) { + resLoc = ResourceBundle.getBundle( + "sun.util.resources.LocaleNames", locale); + + sdfLoc = new SimpleDateFormat("zzzz", locale); + sdfLocShort = new SimpleDateFormat("z", locale); + + for (String timezone : timezones) { + if (isTZIgnored(timezone)) { + continue; + } + warnings.append(testTZ(timezone, locale)); + } + + countryMap = getList(resLoc, true); + + for (String country : countries) { + String[] result = testEntry(country, + countryMapEn, + countryMap, + locale, + "ERROR: {0} country name for country code: {1} not found!\n", + "WARNING: {0} country name for country code: {1} not localized!\n" + ); + if (warnings.indexOf(result[0]) == -1) { + warnings.append(result[0]); + } + if (errors.indexOf(result[1]) == -1) { + errors.append(result[1]); + } + } + + languageMap = getList(resLoc, false); + for (String language : languages) { + String[] result = testEntry(language, + languageMapEn, + languageMap, + locale, + "ERROR: {0} language name for language code: {1} not found!\n", + "WARNING: {0} language name for language code: {1} not localized!\n"); + if (warnings.indexOf(result[0]) == -1) { + warnings.append(result[0]); + } + if (errors.indexOf(result[1]) == -1) { + errors.append(result[1]); + } + } + } + + StringBuffer message = new StringBuffer(""); + if (!"".equals(errors.toString())) { + message.append("Test failed! "); + message.append("ERROR: some keys are missing! "); + } + + if ("".equals(message.toString())) { + System.out.println("\nTest passed"); + System.out.println(warnings.toString()); + } else { + System.out.println("\nTest failed!"); + System.out.println(errors.toString()); + System.out.println(warnings.toString()); + throw new Exception("\n" + message); + } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } - } } - StringBuffer message = new StringBuffer(""); - if (!"".equals(errors.toString())) { - message.append("Test failed! "); - message.append("ERROR: some keys are missing! "); - } + /** + * Compares the english timezone name and timezone name in specified locale + * @param timeZoneName - name of the timezone to compare + * @param locale - locale to test against english + * @return empty string when passed, descriptive error message in other cases + */ + private static String testTZ(String timeZoneName, Locale locale) { + StringBuffer timeZoneResult = new StringBuffer(""); + TimeZone tz = TimeZone.getTimeZone(timeZoneName); + sdfEn.setTimeZone(tz); + sdfEnShort.setTimeZone(tz); + sdfLoc.setTimeZone(tz); + sdfLocShort.setTimeZone(tz); + + String en, enShort, loc, locShort; + en = sdfEn.format(date); + enShort = sdfEnShort.format(date); + loc = sdfLoc.format(date); + locShort = sdfLocShort.format(date); + + String displayLanguage = locale.getDisplayLanguage(); + String displayCountry = locale.getDisplayCountry(); + + if (loc.equals(en)) { + timeZoneResult.append("["); + timeZoneResult.append(displayLanguage); + if (!"".equals(displayCountry)) { + timeZoneResult.append(" "); + timeZoneResult.append(displayCountry); + } + timeZoneResult.append("] timezone \""); + timeZoneResult.append(timeZoneName); + timeZoneResult.append("\" long name \"" + en); + timeZoneResult.append("\" not localized!\n"); + } - if ("".equals(message.toString())) { - System.out.println("\nTest passed"); - System.out.println(warnings.toString()); - } else { - System.out.println("\nTest failed!"); - System.out.println(errors.toString()); - System.out.println(warnings.toString()); - throw new Exception("\n" + message); - } - } - - /** - * Compares the english timezone name and timezone name in specified locale - * @param timeZoneName - name of the timezone to compare - * @param locale - locale to test against english - * @return empty string when passed, descriptive error message in other cases - */ - private static String testTZ(String timeZoneName, Locale locale) { - StringBuffer timeZoneResult = new StringBuffer(""); - TimeZone tz = TimeZone.getTimeZone(timeZoneName); - sdfEn.setTimeZone(tz); - sdfEnShort.setTimeZone(tz); - sdfLoc.setTimeZone(tz); - sdfLocShort.setTimeZone(tz); - - String en, enShort, loc, locShort; - en = sdfEn.format(date); - enShort = sdfEnShort.format(date); - loc = sdfLoc.format(date); - locShort = sdfLocShort.format(date); - - String displayLanguage = locale.getDisplayLanguage(); - String displayCountry = locale.getDisplayCountry(); - - if (loc.equals(en)) { - timeZoneResult.append("["); - timeZoneResult.append(displayLanguage); - if (!"".equals(displayCountry)) { - timeZoneResult.append(" "); - timeZoneResult.append(displayCountry); - } - timeZoneResult.append("] timezone \""); - timeZoneResult.append(timeZoneName); - timeZoneResult.append("\" long name \"" + en); - timeZoneResult.append("\" not localized!\n"); + if (!locShort.equals(enShort)) { + timeZoneResult.append("["); + timeZoneResult.append(displayLanguage); + if (!"".equals(displayCountry)) { + timeZoneResult.append(" "); + timeZoneResult.append(displayCountry); + } + timeZoneResult.append("] timezone \""); + timeZoneResult.append(timeZoneName); + timeZoneResult.append("\" short name \"" + enShort); + timeZoneResult.append("\" is localized \""); + timeZoneResult.append(locShort); + timeZoneResult.append("\"!\n"); + } + return timeZoneResult.toString(); } - if (!locShort.equals(enShort)) { - timeZoneResult.append("["); - timeZoneResult.append(displayLanguage); - if (!"".equals(displayCountry)) { - timeZoneResult.append(" "); - timeZoneResult.append(displayCountry); - } - timeZoneResult.append("] timezone \""); - timeZoneResult.append(timeZoneName); - timeZoneResult.append("\" short name \"" + enShort); - timeZoneResult.append("\" is localized \""); - timeZoneResult.append(locShort); - timeZoneResult.append("\"!\n"); - } - return timeZoneResult.toString(); - } - - /** - * Verifies whether the name for ISOCode is localized. - * @param ISOCode - ISO country/language code for country/language name to test - * @param entriesEn - array of english country/language names - * @param entriesLoc - array of localized country/language names for specified locale - * @param locale - locale to test against english - * @param notFoundMessage - message in form ready for MessageFormat, {0} will be human readable - * language name, {1} will be ISOCode. - * @param notLocalizedMessage - message in for ready for MessageFormat, same formatting like - * for notFountMessage - * @return array of two empty strings when passed, descriptive error message in - * other cases, [0] - warnings for not localized, [1] - errors for missing keys. - */ - private static String[] testEntry(String ISOCode, - Map entriesEn, - Map entriesLoc, - Locale locale, - String notFoundMessage, - String notLocalizedMessage) { - String nameEn = null; - String nameLoc = null; - - for (String key: entriesEn.keySet()) { - if (ISOCode.equalsIgnoreCase(key)) { - nameEn = entriesEn.get(key); - break; - } - } + /** + * Verifies whether the name for ISOCode is localized. + * @param ISOCode - ISO country/language code for country/language name + * to test + * @param entriesEn - array of english country/language names + * @param entriesLoc - array of localized country/language names for + * specified locale + * @param locale - locale to test against english + * @param notFoundMessage - message in form ready for MessageFormat, + * {0} will be human readable language name, {1} will be ISOCode. + * @param notLocalizedMessage - message in for ready for MessageFormat, + * same formatting like for notFountMessage + * @return array of two empty strings when passed, descriptive error message + * in other cases, [0] - warnings for not localized, [1] - errors for + * missing keys. + */ + private static String[] testEntry(String ISOCode, + Map entriesEn, + Map entriesLoc, + Locale locale, + String notFoundMessage, + String notLocalizedMessage) { + String nameEn = null; + String nameLoc = null; + + for (String key: entriesEn.keySet()) { + if (ISOCode.equalsIgnoreCase(key)) { + nameEn = entriesEn.get(key); + break; + } + } - for (String key: entriesLoc.keySet()) { - if (ISOCode.equalsIgnoreCase(key)) { - nameLoc = entriesLoc.get(key); - break; - } - } + for (String key: entriesLoc.keySet()) { + if (ISOCode.equalsIgnoreCase(key)) { + nameLoc = entriesLoc.get(key); + break; + } + } - if (nameEn == null) { - // We should not get here but test is a MUST have - return new String[] {"", MessageFormat.format(notFoundMessage, - new String[] {"English", ISOCode})}; - } + if (nameEn == null) { + // We should not get here but test is a MUST have + return new String[] {"", MessageFormat.format(notFoundMessage, + new String[] {"English", ISOCode})}; + } - if (nameLoc == null) { - return new String[] {"", MessageFormat.format(notFoundMessage, - new String[] {locale.getDisplayName(), ISOCode})}; - } + if (nameLoc == null) { + return new String[] {"", MessageFormat.format(notFoundMessage, + new String[] {locale.getDisplayName(), ISOCode})}; + } - if (nameEn.equals(nameLoc)) { - return new String[] {MessageFormat.format(notLocalizedMessage, - new String[] {locale.getDisplayName(), ISOCode}), ""}; - } + if (nameEn.equals(nameLoc)) { + return new String[] {MessageFormat.format(notLocalizedMessage, + new String[] {locale.getDisplayName(), ISOCode}), ""}; + } - return new String[] {"", ""}; - } + return new String[] {"", ""}; + } - private static boolean isTZIgnored(String TZName) { - if (TZName.startsWith("Etc/GMT") || - TZName.indexOf("Riyadh8") != -1 || - TZName.equals("GMT0") || - TZName.equals("MET") - ) { - return true; + private static boolean isTZIgnored(String TZName) { + if (TZName.startsWith("Etc/GMT") || + TZName.indexOf("Riyadh8") != -1 || + TZName.equals("GMT0") || + TZName.equals("MET") + ) { + return true; + } + return false; } - return false; - } - private static Map getList(ResourceBundle rs, Boolean getCountryList) { + private static Map getList( + ResourceBundle rs, Boolean getCountryList) { char beginChar = 'a'; char endChar = 'z'; if (getCountryList) {