提交 1d5b1f12 编写于 作者: X xuelei

7068662: Reserve and restore the default locale

Reviewed-by: alanb, weijun
上级 8632cf43
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,15 +36,19 @@ public class LocaleTest { ...@@ -36,15 +36,19 @@ public class LocaleTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.ITALY); Locale reservedLocale = Locale.getDefault();
try { try {
Locale.setDefault(Locale.ITALY);
throw new XMLSecurityException("foo"); throw new XMLSecurityException("foo");
} catch (XMLSecurityException xse) { } catch (XMLSecurityException xse) {
System.out.println("Test PASSED"); System.out.println("Test PASSED");
} catch (Throwable t) { } catch (Throwable t) {
System.out.println("Test FAILED"); System.out.println("Test FAILED");
t.printStackTrace(); t.printStackTrace();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
} }
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -47,8 +47,14 @@ public class Test6341798 { ...@@ -47,8 +47,14 @@ public class Test6341798 {
+ "</java> "; + "</java> ";
public static void main(String[] args) { public static void main(String[] args) {
test(ENGLISH, DATA.getBytes()); Locale reservedLocale = Locale.getDefault();
test(TURKISH, DATA.getBytes()); 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) { private static void test(Locale locale, byte[] data) {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,17 +32,24 @@ import java.util.*; ...@@ -32,17 +32,24 @@ import java.util.*;
public class bug6344646 { public class bug6344646 {
public static void main(String[] s) { public static void main(String[] s) {
/* This test is only valid on win32 systems */ Locale reservedLocale = Locale.getDefault();
if (File.separatorChar != '\\') { try {
return; /* This test is only valid on win32 systems */
} if (File.separatorChar != '\\') {
return;
}
Locale.setDefault(new Locale("lt")); Locale.setDefault(new Locale("lt"));
File f1 = new File("J\u0301"); File f1 = new File("J\u0301");
File f2 = new File("j\u0301"); File f2 = new File("j\u0301");
if (f1.hashCode() != f2.hashCode()) { if (f1.hashCode() != f2.hashCode()) {
throw new RuntimeException("File.hashCode() for \"J\u0301\" and \"j\u0301\" should be the same"); throw new RuntimeException("File.hashCode() for \"J\u0301\" " +
"and \"j\u0301\" should be the same");
}
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
} }
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,16 +33,23 @@ import java.util.Locale; ...@@ -33,16 +33,23 @@ import java.util.Locale;
public class B6791927 { public class B6791927 {
public static final void main( String[] aaParamters ) throws Exception{ public static final void main( String[] aaParamters ) throws Exception{
// Forces a non US locale Locale reservedLocale = Locale.getDefault();
Locale.setDefault(Locale.FRANCE); try {
List<HttpCookie> cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT"); // Forces a non US locale
if (cookies == null || cookies.isEmpty()) { Locale.setDefault(Locale.FRANCE);
throw new RuntimeException("No cookie found"); List<HttpCookie> cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT");
} if (cookies == null || cookies.isEmpty()) {
for (HttpCookie c : cookies) { throw new RuntimeException("No cookie found");
if (c.getMaxAge() == 0) { }
throw new RuntimeException("Expiration date shouldn't be 0"); 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);
} }
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -73,6 +73,7 @@ public class SetIfModifiedSince { ...@@ -73,6 +73,7 @@ public class SetIfModifiedSince {
} }
public static void main (String[] args) { public static void main (String[] args) {
Locale reservedLocale = Locale.getDefault();
try { try {
Locale.setDefault(Locale.JAPAN); Locale.setDefault(Locale.JAPAN);
ServerSocket serversocket = new ServerSocket (0); ServerSocket serversocket = new ServerSocket (0);
...@@ -87,6 +88,10 @@ public class SetIfModifiedSince { ...@@ -87,6 +88,10 @@ public class SetIfModifiedSince {
int i=0, c; int i=0, c;
Thread.sleep (5000); Thread.sleep (5000);
} catch (Exception e) { } catch (Exception e) {
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
} }
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,30 +29,37 @@ public class LocaleCategory { ...@@ -29,30 +29,37 @@ public class LocaleCategory {
private static String enc = null; private static String enc = null;
public static void main(String[] args) { 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", "")) base = builder.setLanguage(System.getProperty("user.language", ""))
.setScript(System.getProperty("user.script", "")) .setScript(System.getProperty("user.script", ""))
.setRegion(System.getProperty("user.country", "")) .setRegion(System.getProperty("user.country", ""))
.setVariant(System.getProperty("user.variant", "")).build(); .setVariant(System.getProperty("user.variant", "")).build();
disp = builder.setLanguage(System.getProperty("user.language.display", disp = builder.setLanguage(
Locale.getDefault().getLanguage())) System.getProperty("user.language.display",
.setScript(System.getProperty("user.script.display", Locale.getDefault().getLanguage()))
Locale.getDefault().getScript())) .setScript(System.getProperty("user.script.display",
.setRegion(System.getProperty("user.country.display", Locale.getDefault().getScript()))
Locale.getDefault().getCountry())) .setRegion(System.getProperty("user.country.display",
.setVariant(System.getProperty("user.variant.display", Locale.getDefault().getCountry()))
Locale.getDefault().getVariant())).build(); .setVariant(System.getProperty("user.variant.display",
fmt = builder.setLanguage(System.getProperty("user.language.format", Locale.getDefault().getVariant())).build();
Locale.getDefault().getLanguage())) fmt = builder.setLanguage(System.getProperty("user.language.format",
.setScript(System.getProperty("user.script.format", Locale.getDefault().getLanguage()))
Locale.getDefault().getScript())) .setScript(System.getProperty("user.script.format",
.setRegion(System.getProperty("user.country.format", Locale.getDefault().getScript()))
Locale.getDefault().getCountry())) .setRegion(System.getProperty("user.country.format",
.setVariant(System.getProperty("user.variant.format", Locale.getDefault().getCountry()))
Locale.getDefault().getVariant())).build(); .setVariant(System.getProperty("user.variant.format",
checkDefault(); Locale.getDefault().getVariant())).build();
testGetSetDefault(); checkDefault();
testGetSetDefault();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
static void checkDefault() { static void checkDefault() {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,7 +32,13 @@ import sun.util.resources.*; ...@@ -32,7 +32,13 @@ import sun.util.resources.*;
public class CurrencyNameProviderTest extends ProviderTest { public class CurrencyNameProviderTest extends ProviderTest {
public static void main(String[] s) { public static void main(String[] s) {
new CurrencyNameProviderTest(); Locale reservedLocale = Locale.getDefault();
try {
new CurrencyNameProviderTest();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
CurrencyNameProviderTest() { CurrencyNameProviderTest() {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -113,6 +113,7 @@ public class TimeZoneNameProviderTest extends ProviderTest { ...@@ -113,6 +113,7 @@ public class TimeZoneNameProviderTest extends ProviderTest {
void test2() { void test2() {
Locale defaultLocale = Locale.getDefault(); Locale defaultLocale = Locale.getDefault();
TimeZone reservedTimeZone = TimeZone.getDefault();
Date d = new Date(2005-1900, Calendar.DECEMBER, 22); Date d = new Date(2005-1900, Calendar.DECEMBER, 22);
String formatted; String formatted;
...@@ -139,7 +140,6 @@ public class TimeZoneNameProviderTest extends ProviderTest { ...@@ -139,7 +140,6 @@ public class TimeZoneNameProviderTest extends ProviderTest {
df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance()); df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
System.out.println(formatted = df.format(d)); System.out.println(formatted = df.format(d));
if(!formatted.equals(DISPLAY_NAMES_KYOTO[i])) { if(!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
Locale.setDefault(defaultLocale);
throw new RuntimeException("Timezone " + TIMEZONES[i] + throw new RuntimeException("Timezone " + TIMEZONES[i] +
": formatted zone names mismatch. " + ": formatted zone names mismatch. " +
formatted + " should match with " + formatted + " should match with " +
...@@ -148,10 +148,12 @@ public class TimeZoneNameProviderTest extends ProviderTest { ...@@ -148,10 +148,12 @@ public class TimeZoneNameProviderTest extends ProviderTest {
df.parse(DISPLAY_NAMES_KYOTO[i]); df.parse(DISPLAY_NAMES_KYOTO[i]);
} }
} catch (ParseException pe) { } catch (ParseException pe) {
Locale.setDefault(defaultLocale);
throw new RuntimeException("parse error occured" + pe); 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"; final String LATIME = "America/Los_Angeles";
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,27 +32,34 @@ import java.util.*; ...@@ -32,27 +32,34 @@ import java.util.*;
public class Bug6190861 { public class Bug6190861 {
static public void main(String[] args) { 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(); List localeList = new ArrayList();
localeList.add(Locale.ENGLISH); localeList.add(Locale.ENGLISH);
localeList.add(Locale.KOREA); localeList.add(Locale.KOREA);
localeList.add(Locale.UK); localeList.add(Locale.UK);
localeList.add(new Locale("en", "CA")); localeList.add(new Locale("en", "CA"));
localeList.add(Locale.ENGLISH); localeList.add(Locale.ENGLISH);
Iterator iter = localeList.iterator(); Iterator iter = localeList.iterator();
while (iter.hasNext()){ while (iter.hasNext()){
Locale currentLocale = (Locale) iter.next(); Locale currentLocale = (Locale) iter.next();
System.out.println("\ncurrentLocale = " System.out.println("\ncurrentLocale = "
+ currentLocale.getDisplayName()); + currentLocale.getDisplayName());
ResourceBundle messages = ResourceBundle.getBundle("Bug6190861Data",currentLocale); ResourceBundle messages =
ResourceBundle.getBundle("Bug6190861Data",currentLocale);
Locale messagesLocale = messages.getLocale(); Locale messagesLocale = messages.getLocale();
System.out.println("messagesLocale = " System.out.println("messagesLocale = "
+ messagesLocale.getDisplayName()); + messagesLocale.getDisplayName());
checkMessages(messages); checkMessages(messages);
}
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -43,6 +43,12 @@ public class Bug6530694 { ...@@ -43,6 +43,12 @@ public class Bug6530694 {
} }
public static void main(String[] args) { public static void main(String[] args) {
new Bug6530694(); Locale reservedLocale = Locale.getDefault();
try {
new Bug6530694();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
} }
...@@ -69,36 +69,44 @@ public class StressTest { ...@@ -69,36 +69,44 @@ public class StressTest {
if (args.length > 1) { if (args.length > 1) {
duration = Math.max(5, Integer.parseInt(args[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++) { Locale reservedLocale = Locale.getDefault();
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);
try { try {
for (int i = 0; runrun && i < duration; i++) { Locale.setDefault(Locale.US);
Thread.sleep(1000); // 1 second Thread[] tasks = new Thread[locales.length * threadsFactor];
if ((i % intervalForCounterCheck) == 0) { counters = new AtomicIntegerArray(tasks.length);
checkCounters();
} 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++) { 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() { static void checkCounters() {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,8 +35,14 @@ import java.util.MissingResourceException; ...@@ -35,8 +35,14 @@ import java.util.MissingResourceException;
public class Test4314141 { public class Test4314141 {
public static void main(String[] args) { public static void main(String[] args) {
testCandidateOmission(); Locale reservedLocale = Locale.getDefault();
testExample(); try {
testCandidateOmission();
testExample();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
/** /**
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,8 +36,14 @@ import java.util.Locale; ...@@ -36,8 +36,14 @@ import java.util.Locale;
public class Test4318520 { public class Test4318520 {
public static void main(String[] args) { public static void main(String[] args) {
test(Locale.GERMAN); Locale reservedLocale = Locale.getDefault();
test(Locale.ENGLISH); try {
test(Locale.GERMAN);
test(Locale.ENGLISH);
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
private static void test(Locale locale) { private static void test(Locale locale) {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
* @bug 4624534 * @bug 4624534
* @summary Make sure jar certificates work for Turkish locale * @summary Make sure jar certificates work for Turkish locale
* @author kladko * @author kladko
* @run main/othervm TurkCert
*/ */
import java.util.*; import java.util.*;
...@@ -36,15 +35,24 @@ import java.io.*; ...@@ -36,15 +35,24 @@ import java.io.*;
public class TurkCert { public class TurkCert {
public static void main(String[] args) throws Exception{ public static void main(String[] args) throws Exception{
Locale.setDefault(new Locale("TR", "tr")); Locale reservedLocale = Locale.getDefault();
File f = new File(System.getProperty("test.src","."), "test.jar"); try {
JarFile jf = new JarFile(f, true); Locale.setDefault(new Locale("TR", "tr"));
JarEntry je = (JarEntry)jf.getEntry("test.class"); File f = new File(System.getProperty("test.src","."), "test.jar");
InputStream is = jf.getInputStream(je); try (JarFile jf = new JarFile(f, true)) {
byte[] b = new byte[1024]; JarEntry je = (JarEntry)jf.getEntry("test.class");
while (is.read(b) != -1) { 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.");
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,15 +35,21 @@ import javax.crypto.Cipher; ...@@ -35,15 +35,21 @@ import javax.crypto.Cipher;
public class Turkish { public class Turkish {
public static void main(String[] args) throws Exception { 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("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("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);
}
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -98,17 +98,23 @@ public class Test6524757 { ...@@ -98,17 +98,23 @@ public class Test6524757 {
private static final Object[] FRENCH = convert(Locale.FRENCH, KEYS); private static final Object[] FRENCH = convert(Locale.FRENCH, KEYS);
public static void main(String[] args) { public static void main(String[] args) {
// it affects Swing because it is not initialized Locale reservedLocale = Locale.getDefault();
Locale.setDefault(Locale.KOREAN); try {
validate(KOREAN, create()); // it affects Swing because it is not initialized
Locale.setDefault(Locale.KOREAN);
// it does not affect Swing because it is initialized validate(KOREAN, create());
Locale.setDefault(Locale.CANADA);
validate(KOREAN, create()); // it does not affect Swing because it is initialized
Locale.setDefault(Locale.CANADA);
// it definitely should affect Swing validate(KOREAN, create());
JComponent.setDefaultLocale(Locale.FRENCH);
validate(FRENCH, 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) { private static void validate(Object[] expected, Object[] actual) {
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1278,52 +1278,58 @@ public class KeyToolTest { ...@@ -1278,52 +1278,58 @@ public class KeyToolTest {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// first test if HumanInputStream really acts like a human being Locale reservedLocale = Locale.getDefault();
HumanInputStream.test(); try {
KeyToolTest t = new KeyToolTest(); // first test if HumanInputStream really acts like a human being
HumanInputStream.test();
if (System.getProperty("file") != null) { KeyToolTest t = new KeyToolTest();
t.sqeTest();
t.testAll(); if (System.getProperty("file") != null) {
t.i18nTest(); t.sqeTest();
t.v3extTest("RSA"); t.testAll();
t.v3extTest("DSA"); t.i18nTest();
boolean testEC = true; t.v3extTest("RSA");
try { t.v3extTest("DSA");
KeyPairGenerator.getInstance("EC"); boolean testEC = true;
} catch (NoSuchAlgorithmException nae) { try {
testEC = false; KeyPairGenerator.getInstance("EC");
} catch (NoSuchAlgorithmException nae) {
testEC = false;
}
if (testEC) t.v3extTest("EC");
} }
if (testEC) t.v3extTest("EC");
}
if (System.getProperty("nss") != null) { if (System.getProperty("nss") != null) {
t.srcP11Arg = NSS_SRC_P11_ARG; t.srcP11Arg = NSS_SRC_P11_ARG;
t.p11Arg = NSS_P11_ARG; t.p11Arg = NSS_P11_ARG;
t.testPKCS11(); t.testPKCS11();
// FAIL: // FAIL:
// 1. we still don't have srcprovidername yet // 1. we still don't have srcprovidername yet
// 2. cannot store privatekey into NSS keystore // 2. cannot store privatekey into NSS keystore
// java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE. // java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE.
//t.testPKCS11ImportKeyStore(); //t.testPKCS11ImportKeyStore();
t.i18nPKCS11Test(); t.i18nPKCS11Test();
//FAIL: currently PKCS11-NSS does not support 2 NSS KeyStores to be loaded at the same time //FAIL: currently PKCS11-NSS does not support 2 NSS KeyStores to be loaded at the same time
//t.sszzTest(); //t.sszzTest();
} }
if (System.getProperty("solaris") != null) { if (System.getProperty("solaris") != null) {
// For Solaris Cryptography Framework // For Solaris Cryptography Framework
t.srcP11Arg = SUN_SRC_P11_ARG; t.srcP11Arg = SUN_SRC_P11_ARG;
t.p11Arg = SUN_P11_ARG; t.p11Arg = SUN_P11_ARG;
t.testPKCS11(); t.testPKCS11();
t.testPKCS11ImportKeyStore(); t.testPKCS11ImportKeyStore();
t.i18nPKCS11Test(); t.i18nPKCS11Test();
} }
System.out.println("Test pass!!!"); System.out.println("Test pass!!!");
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,43 +35,49 @@ public class Bug4248694 { ...@@ -35,43 +35,49 @@ public class Bug4248694 {
/******************************************************** /********************************************************
*********************************************************/ *********************************************************/
public static void main (String[] args) { 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); Locale.setDefault (loc);
Collator col = Collator.getInstance (); Collator col = Collator.getInstance ();
String[] data = {"\u00e6ard", String[] data = {"\u00e6ard",
"Zard", "Zard",
"aard", "aard",
"\u00feard", "\u00feard",
"vird", "vird",
"\u00c6ard", "\u00c6ard",
"Zerd", "Zerd",
"\u00deard"}; "\u00deard"};
String[] sortedData = {"aard", String[] sortedData = {"aard",
"vird", "vird",
"Zard", "Zard",
"Zerd", "Zerd",
"\u00feard", "\u00feard",
"\u00deard", "\u00deard",
"\u00e6ard", "\u00e6ard",
"\u00c6ard"}; "\u00c6ard"};
Arrays.sort (data, col); Arrays.sort (data, col);
System.out.println ("Using " + loc.getDisplayName()); System.out.println ("Using " + loc.getDisplayName());
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
System.out.println(data[i] + " : " + sortedData[i]); System.out.println(data[i] + " : " + sortedData[i]);
if (sortedData[i].compareTo(data[i]) != 0) { if (sortedData[i].compareTo(data[i]) != 0) {
errors++; errors++;
} }
}//end for }//end for
if (errors > 0) if (errors > 0)
throw new RuntimeException(); throw new RuntimeException();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}//end main }//end main
}//end class CollatorTest }//end class CollatorTest
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,82 +35,89 @@ public class Bug4804273 { ...@@ -35,82 +35,89 @@ public class Bug4804273 {
/******************************************************** /********************************************************
*********************************************************/ *********************************************************/
public static void main (String[] args) { 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); Locale.setDefault (loc);
Collator col = Collator.getInstance (); Collator col = Collator.getInstance ();
String[] data = {"A", String[] data = {"A",
"Aa", "Aa",
"Ae", "Ae",
"B", "B",
"Y", "Y",
"U\u0308", // U-umlaut "U\u0308", // U-umlaut
"Z", "Z",
"A\u030a", // A-ring "A\u030a", // A-ring
"A\u0308", // A-umlaut "A\u0308", // A-umlaut
"\u00c6", // AE ligature "\u00c6", // AE ligature
"O\u0308", // O-umlaut "O\u0308", // O-umlaut
"a\u030b", // a-double-acute "a\u030b", // a-double-acute
"\u00d8", // O-stroke "\u00d8", // O-stroke
"a", "a",
"aa", "aa",
"ae", "ae",
"b", "b",
"y", "y",
"u\u0308", // u-umlaut "u\u0308", // u-umlaut
"z", "z",
"A\u030b", // A-double-acute "A\u030b", // A-double-acute
"a\u030a", // a-ring "a\u030a", // a-ring
"a\u0308", // a-umlaut "a\u0308", // a-umlaut
"\u00e6", // ae ligature "\u00e6", // ae ligature
"o\u0308", // o-umlaut "o\u0308", // o-umlaut
"\u00f8", // o-stroke "\u00f8", // o-stroke
}; };
String[] sortedData = {"a", String[] sortedData = {"a",
"A", "A",
"aa", "aa",
"Aa", "Aa",
"ae", "ae",
"Ae", "Ae",
"b", "b",
"B", "B",
"y", "y",
"Y", "Y",
"u\u0308", // o-umlaut "u\u0308", // o-umlaut
"U\u0308", // o-umlaut "U\u0308", // o-umlaut
"z", "z",
"Z", "Z",
"a\u030a", // a-ring "a\u030a", // a-ring
"A\u030a", // A-ring "A\u030a", // A-ring
"a\u0308", // a-umlaut "a\u0308", // a-umlaut
"A\u0308", // A-umlaut "A\u0308", // A-umlaut
"a\u030b", // a-double-acute "a\u030b", // a-double-acute
"A\u030b", // A-double-acute "A\u030b", // A-double-acute
"\u00e6", // ae ligature "\u00e6", // ae ligature
"\u00c6", // AE ligature "\u00c6", // AE ligature
"o\u0308", // o-umlaut "o\u0308", // o-umlaut
"O\u0308", // O-umlaut "O\u0308", // O-umlaut
"\u00f8", // o-stroke "\u00f8", // o-stroke
"\u00d8", // O-stroke "\u00d8", // O-stroke
}; };
Arrays.sort (data, col); Arrays.sort (data, col);
System.out.println ("Using " + loc.getDisplayName()); System.out.println ("Using " + loc.getDisplayName());
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
System.out.println(data[i] + " : " + sortedData[i]); System.out.println(data[i] + " : " + sortedData[i]);
if (sortedData[i].compareTo(data[i]) != 0) { if (sortedData[i].compareTo(data[i]) != 0) {
errors++; errors++;
} }
}//end for }//end for
if (errors > 0) if (errors > 0)
throw new RuntimeException("There are " + errors + " words sorted incorrectly!"); throw new RuntimeException("There are " + errors +
" words sorted incorrectly!");
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
}//end main }//end main
}//end class CollatorTest }//end class CollatorTest
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,39 +35,44 @@ public class Bug4848897 { ...@@ -35,39 +35,44 @@ public class Bug4848897 {
/******************************************************** /********************************************************
*********************************************************/ *********************************************************/
public static void main (String[] args) { 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.setDefault (loc);
Locale loc = new Locale ("no", "NO"); // Norwegian Collator col = Collator.getInstance ();
Locale.setDefault (loc); String[] data = {"wird",
Collator col = Collator.getInstance (); "vird",
"verd",
"werd",
"vard",
"ward"};
String[] data = {"wird", String[] sortedData = {"vard",
"vird", "verd",
"verd", "vird",
"werd", "ward",
"vard", "werd",
"ward"}; "wird"};
String[] sortedData = {"vard", Arrays.sort (data, col);
"verd",
"vird",
"ward",
"werd",
"wird"};
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()); if (errors > 0)
for (int i = 0; i < data.length; i++) { throw new RuntimeException();
System.out.println(data[i] + " : " + sortedData[i]); } finally {
if (sortedData[i].compareTo(data[i]) != 0) { // restore the reserved locale
errors++; Locale.setDefault(reservedLocale);
} }
}//end for } // end main
if (errors > 0)
throw new RuntimeException();
}//end main
}//end class CollatorTest }//end class CollatorTest
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -34,23 +34,29 @@ import java.util.Locale; ...@@ -34,23 +34,29 @@ import java.util.Locale;
public class Bug4651568 { public class Bug4651568 {
public static void main (String argv[] ) { public static void main (String argv[] ) {
String expectedCurrencyPattern = "\u00A4 #.##0,00"; Locale reservedLocale = Locale.getDefault();
try {
Locale locale = new Locale ("pt", "BR"); String expectedCurrencyPattern = "\u00A4 #.##0,00";
Locale.setDefault(locale);
Locale locale = new Locale ("pt", "BR");
DecimalFormat formatter = Locale.setDefault(locale);
(DecimalFormat) NumberFormat.getCurrencyInstance(locale);
DecimalFormat formatter =
if (formatter.toLocalizedPattern().equals(expectedCurrencyPattern)) (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
{
System.out.println ("Passed."); if (formatter.toLocalizedPattern().equals(
} else { expectedCurrencyPattern)) {
System.out.println ("Failed Currency pattern." + System.out.println ("Passed.");
" Expected: " + expectedCurrencyPattern + } else {
" Received: " + formatter.toLocalizedPattern() ); System.out.println ("Failed Currency pattern." +
throw new RuntimeException(); " Expected: " + expectedCurrencyPattern +
" Received: " + formatter.toLocalizedPattern() );
} throw new RuntimeException();
}
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,49 +30,55 @@ import java.util.Locale; ...@@ -30,49 +30,55 @@ import java.util.Locale;
public class Bug4965260 { public class Bug4965260 {
// Define supported locales // Define supported locales
static Locale[] locales2Test = new Locale[] { static Locale[] locales2Test = new Locale[] {
new Locale("de"), new Locale("de"),
new Locale("es"), new Locale("es"),
new Locale("fr"), new Locale("fr"),
new Locale("it"), new Locale("it"),
new Locale("sv") new Locale("sv")
}; };
static String[] expectedNames = new String[] { static String[] expectedNames = new String[] {
"Niederl\u00e4ndisch", "Niederl\u00e4ndisch",
"neerland\u00e9s", "neerland\u00e9s",
"n\u00e9erlandais", "n\u00e9erlandais",
"neerlandese", "neerlandese",
"nederl\u00e4ndska" "nederl\u00e4ndska"
}; };
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.ENGLISH); Locale reservedLocale = Locale.getDefault();
if (locales2Test.length != expectedNames.length) { try {
throw new Exception("\nData sizes does not match!\n"); Locale.setDefault(Locale.ENGLISH);
} if (locales2Test.length != expectedNames.length) {
throw new Exception("\nData sizes does not match!\n");
}
StringBuffer message = new StringBuffer(""); StringBuffer message = new StringBuffer("");
Locale dutch = new Locale("nl", "BE"); Locale dutch = new Locale("nl", "BE");
String current; String current;
for (int i = 0; i < locales2Test.length; i++) { for (int i = 0; i < locales2Test.length; i++) {
Locale locale = locales2Test[i]; Locale locale = locales2Test[i];
current = dutch.getDisplayLanguage(locale); current = dutch.getDisplayLanguage(locale);
if (!current.equals(expectedNames[i])) { if (!current.equals(expectedNames[i])) {
message.append("["); message.append("[");
message.append(locale.getDisplayLanguage()); message.append(locale.getDisplayLanguage());
message.append("] "); message.append("] ");
message.append("Language name is "); message.append("Language name is ");
message.append(current); message.append(current);
message.append(" should be "); message.append(" should be ");
message.append(expectedNames[i]); message.append(expectedNames[i]);
message.append("\n"); message.append("\n");
} }
} }
if (message.length() >0) { if (message.length() >0) {
throw new Exception("\n" + message.toString()); throw new Exception("\n" + message.toString());
}
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
}
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
/** /**
* @test * @test
* @bug 4640234 4946057 4938151 4873691 5023181 * @bug 4640234 4946057 4938151 4873691 5023181
* @summary Verifies the translation of time zone names, this test will catch presence * @summary Verifies the translation of time zone names, this test will catch
* of country name for english and selected locales for all ISO country * presence of country name for english and selected locales for all
* codes. * ISO country codes.
* The test program also displays which timezone, country and language names * The test program also displays which timezone, country and
* are not translated * language names are not translated
*/ */
...@@ -51,230 +51,242 @@ import java.util.TimeZone; ...@@ -51,230 +51,242 @@ import java.util.TimeZone;
public class Bug4640234 { public class Bug4640234 {
static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US); static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US);
static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US); static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US);
static Locale locEn = Locale.ENGLISH; static Locale locEn = Locale.ENGLISH;
static SimpleDateFormat sdfLoc; static SimpleDateFormat sdfLoc;
static SimpleDateFormat sdfLocShort; static SimpleDateFormat sdfLocShort;
static Date date = new Date(); static Date date = new Date();
// Define supported locales // Define supported locales
static Locale[] locales2Test = new Locale[] { static Locale[] locales2Test = new Locale[] {
new Locale("de"), new Locale("de"),
new Locale("es"), new Locale("es"),
new Locale("fr"), new Locale("fr"),
new Locale("it"), new Locale("it"),
new Locale("ja"), new Locale("ja"),
new Locale("ko"), new Locale("ko"),
new Locale("sv"), new Locale("sv"),
new Locale("zh", "CN"), new Locale("zh", "CN"),
new Locale("zh", "TW") new Locale("zh", "TW")
}; };
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.ENGLISH); Locale reservedLocale = Locale.getDefault();
try {
StringBuffer errors = new StringBuffer(""); Locale.setDefault(Locale.ENGLISH);
StringBuffer warnings = new StringBuffer("");
StringBuffer errors = new StringBuffer("");
String[] timezones = TimeZone.getAvailableIDs(); StringBuffer warnings = new StringBuffer("");
String[] countries = locEn.getISOCountries();
String[] languages = locEn.getISOLanguages(); String[] timezones = TimeZone.getAvailableIDs();
String[] countries = locEn.getISOCountries();
ResourceBundle resEn = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locEn); String[] languages = locEn.getISOLanguages();
Map<String, String> countryMapEn = getList(resEn, true);
Map<String, String> languageMapEn = getList(resEn, false); ResourceBundle resEn = ResourceBundle.getBundle(
"sun.util.resources.LocaleNames", locEn);
ResourceBundle resLoc; Map<String, String> countryMapEn = getList(resEn, true);
Map<String, String> countryMap; Map<String, String> languageMapEn = getList(resEn, false);
Map<String, String> languageMap;
ResourceBundle resLoc;
for (Locale locale : locales2Test) { Map<String, String> countryMap;
resLoc = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locale); Map<String, String> languageMap;
sdfLoc = new SimpleDateFormat("zzzz", locale); for (Locale locale : locales2Test) {
sdfLocShort = new SimpleDateFormat("z", locale); resLoc = ResourceBundle.getBundle(
"sun.util.resources.LocaleNames", locale);
for (String timezone : timezones) {
if (isTZIgnored(timezone)) { sdfLoc = new SimpleDateFormat("zzzz", locale);
continue; sdfLocShort = new SimpleDateFormat("z", locale);
}
warnings.append(testTZ(timezone, locale)); for (String timezone : timezones) {
} if (isTZIgnored(timezone)) {
continue;
countryMap = getList(resLoc, true); }
warnings.append(testTZ(timezone, locale));
for (String country : countries) { }
String[] result = testEntry(country,
countryMapEn, countryMap = getList(resLoc, true);
countryMap,
locale, for (String country : countries) {
"ERROR: {0} country name for country code: {1} not found!\n", String[] result = testEntry(country,
"WARNING: {0} country name for country code: {1} not localized!\n" countryMapEn,
); countryMap,
if (warnings.indexOf(result[0]) == -1) { locale,
warnings.append(result[0]); "ERROR: {0} country name for country code: {1} not found!\n",
} "WARNING: {0} country name for country code: {1} not localized!\n"
if (errors.indexOf(result[1]) == -1) { );
errors.append(result[1]); if (warnings.indexOf(result[0]) == -1) {
} warnings.append(result[0]);
} }
if (errors.indexOf(result[1]) == -1) {
languageMap = getList(resLoc, false); errors.append(result[1]);
for (String language : languages) { }
String[] result = testEntry(language, }
languageMapEn,
languageMap, languageMap = getList(resLoc, false);
locale, for (String language : languages) {
"ERROR: {0} language name for language code: {1} not found!\n", String[] result = testEntry(language,
"WARNING: {0} language name for language code: {1} not localized!\n"); languageMapEn,
if (warnings.indexOf(result[0]) == -1) { languageMap,
warnings.append(result[0]); locale,
} "ERROR: {0} language name for language code: {1} not found!\n",
if (errors.indexOf(result[1]) == -1) { "WARNING: {0} language name for language code: {1} not localized!\n");
errors.append(result[1]); 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())) { * Compares the english timezone name and timezone name in specified locale
message.append("Test failed! "); * @param timeZoneName - name of the timezone to compare
message.append("ERROR: some keys are missing! "); * @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())) { if (!locShort.equals(enShort)) {
System.out.println("\nTest passed"); timeZoneResult.append("[");
System.out.println(warnings.toString()); timeZoneResult.append(displayLanguage);
} else { if (!"".equals(displayCountry)) {
System.out.println("\nTest failed!"); timeZoneResult.append(" ");
System.out.println(errors.toString()); timeZoneResult.append(displayCountry);
System.out.println(warnings.toString()); }
throw new Exception("\n" + message); timeZoneResult.append("] timezone \"");
} timeZoneResult.append(timeZoneName);
} timeZoneResult.append("\" short name \"" + enShort);
timeZoneResult.append("\" is localized \"");
/** timeZoneResult.append(locShort);
* Compares the english timezone name and timezone name in specified locale timeZoneResult.append("\"!\n");
* @param timeZoneName - name of the timezone to compare }
* @param locale - locale to test against english return timeZoneResult.toString();
* @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("["); * Verifies whether the name for ISOCode is localized.
timeZoneResult.append(displayLanguage); * @param ISOCode - ISO country/language code for country/language name
if (!"".equals(displayCountry)) { * to test
timeZoneResult.append(" "); * @param entriesEn - array of english country/language names
timeZoneResult.append(displayCountry); * @param entriesLoc - array of localized country/language names for
} * specified locale
timeZoneResult.append("] timezone \""); * @param locale - locale to test against english
timeZoneResult.append(timeZoneName); * @param notFoundMessage - message in form ready for MessageFormat,
timeZoneResult.append("\" short name \"" + enShort); * {0} will be human readable language name, {1} will be ISOCode.
timeZoneResult.append("\" is localized \""); * @param notLocalizedMessage - message in for ready for MessageFormat,
timeZoneResult.append(locShort); * same formatting like for notFountMessage
timeZoneResult.append("\"!\n"); * @return array of two empty strings when passed, descriptive error message
} * in other cases, [0] - warnings for not localized, [1] - errors for
return timeZoneResult.toString(); * missing keys.
} */
private static String[] testEntry(String ISOCode,
/** Map<String, String> entriesEn,
* Verifies whether the name for ISOCode is localized. Map<String, String> entriesLoc,
* @param ISOCode - ISO country/language code for country/language name to test Locale locale,
* @param entriesEn - array of english country/language names String notFoundMessage,
* @param entriesLoc - array of localized country/language names for specified locale String notLocalizedMessage) {
* @param locale - locale to test against english String nameEn = null;
* @param notFoundMessage - message in form ready for MessageFormat, {0} will be human readable String nameLoc = null;
* language name, {1} will be ISOCode.
* @param notLocalizedMessage - message in for ready for MessageFormat, same formatting like for (String key: entriesEn.keySet()) {
* for notFountMessage if (ISOCode.equalsIgnoreCase(key)) {
* @return array of two empty strings when passed, descriptive error message in nameEn = entriesEn.get(key);
* other cases, [0] - warnings for not localized, [1] - errors for missing keys. break;
*/ }
private static String[] testEntry(String ISOCode, }
Map<String, String> entriesEn,
Map<String, String> 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()) { for (String key: entriesLoc.keySet()) {
if (ISOCode.equalsIgnoreCase(key)) { if (ISOCode.equalsIgnoreCase(key)) {
nameLoc = entriesLoc.get(key); nameLoc = entriesLoc.get(key);
break; break;
} }
} }
if (nameEn == null) { if (nameEn == null) {
// We should not get here but test is a MUST have // We should not get here but test is a MUST have
return new String[] {"", MessageFormat.format(notFoundMessage, return new String[] {"", MessageFormat.format(notFoundMessage,
new String[] {"English", ISOCode})}; new String[] {"English", ISOCode})};
} }
if (nameLoc == null) { if (nameLoc == null) {
return new String[] {"", MessageFormat.format(notFoundMessage, return new String[] {"", MessageFormat.format(notFoundMessage,
new String[] {locale.getDisplayName(), ISOCode})}; new String[] {locale.getDisplayName(), ISOCode})};
} }
if (nameEn.equals(nameLoc)) { if (nameEn.equals(nameLoc)) {
return new String[] {MessageFormat.format(notLocalizedMessage, return new String[] {MessageFormat.format(notLocalizedMessage,
new String[] {locale.getDisplayName(), ISOCode}), ""}; new String[] {locale.getDisplayName(), ISOCode}), ""};
} }
return new String[] {"", ""}; return new String[] {"", ""};
} }
private static boolean isTZIgnored(String TZName) { private static boolean isTZIgnored(String TZName) {
if (TZName.startsWith("Etc/GMT") || if (TZName.startsWith("Etc/GMT") ||
TZName.indexOf("Riyadh8") != -1 || TZName.indexOf("Riyadh8") != -1 ||
TZName.equals("GMT0") || TZName.equals("GMT0") ||
TZName.equals("MET") TZName.equals("MET")
) { ) {
return true; return true;
}
return false;
} }
return false;
}
private static Map<String, String> getList(ResourceBundle rs, Boolean getCountryList) { private static Map<String, String> getList(
ResourceBundle rs, Boolean getCountryList) {
char beginChar = 'a'; char beginChar = 'a';
char endChar = 'z'; char endChar = 'z';
if (getCountryList) { if (getCountryList) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册