提交 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 reservedLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.ITALY); Locale.setDefault(Locale.ITALY);
try {
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) {
Locale reservedLocale = Locale.getDefault();
try {
test(ENGLISH, DATA.getBytes()); test(ENGLISH, DATA.getBytes());
test(TURKISH, 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,6 +32,8 @@ import java.util.*; ...@@ -32,6 +32,8 @@ import java.util.*;
public class bug6344646 { public class bug6344646 {
public static void main(String[] s) { public static void main(String[] s) {
Locale reservedLocale = Locale.getDefault();
try {
/* This test is only valid on win32 systems */ /* This test is only valid on win32 systems */
if (File.separatorChar != '\\') { if (File.separatorChar != '\\') {
return; return;
...@@ -42,7 +44,12 @@ public class bug6344646 { ...@@ -42,7 +44,12 @@ public class bug6344646 {
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,6 +33,8 @@ import java.util.Locale; ...@@ -33,6 +33,8 @@ 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{
Locale reservedLocale = Locale.getDefault();
try {
// Forces a non US locale // Forces a non US locale
Locale.setDefault(Locale.FRANCE); Locale.setDefault(Locale.FRANCE);
List<HttpCookie> cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT"); List<HttpCookie> cookies = HttpCookie.parse("set-cookie: CUSTOMER=WILE_E_COYOTE; expires=Wednesday, 09-Nov-2019 23:12:40 GMT");
...@@ -41,8 +43,13 @@ public class B6791927 { ...@@ -41,8 +43,13 @@ public class B6791927 {
} }
for (HttpCookie c : cookies) { for (HttpCookie c : cookies) {
if (c.getMaxAge() == 0) { if (c.getMaxAge() == 0) {
throw new RuntimeException("Expiration date shouldn't be 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,13 +29,16 @@ public class LocaleCategory { ...@@ -29,13 +29,16 @@ 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 reservedLocale = Locale.getDefault();
try {
Locale.Builder builder = new Locale.Builder(); 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(
System.getProperty("user.language.display",
Locale.getDefault().getLanguage())) Locale.getDefault().getLanguage()))
.setScript(System.getProperty("user.script.display", .setScript(System.getProperty("user.script.display",
Locale.getDefault().getScript())) Locale.getDefault().getScript()))
...@@ -53,6 +56,10 @@ public class LocaleCategory { ...@@ -53,6 +56,10 @@ public class LocaleCategory {
Locale.getDefault().getVariant())).build(); Locale.getDefault().getVariant())).build();
checkDefault(); checkDefault();
testGetSetDefault(); 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) {
Locale reservedLocale = Locale.getDefault();
try {
new CurrencyNameProviderTest(); 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); Locale.setDefault(defaultLocale);
TimeZone.setDefault(reservedTimeZone);
}
} }
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,6 +32,8 @@ import java.util.*; ...@@ -32,6 +32,8 @@ import java.util.*;
public class Bug6190861 { public class Bug6190861 {
static public void main(String[] args) { static public void main(String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
List localeList = new ArrayList(); List localeList = new ArrayList();
...@@ -47,13 +49,18 @@ public class Bug6190861 { ...@@ -47,13 +49,18 @@ public class Bug6190861 {
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);
}
} }
static void checkMessages(ResourceBundle messages) { static void checkMessages(ResourceBundle messages) {
......
/* /*
* 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) {
Locale reservedLocale = Locale.getDefault();
try {
new Bug6530694(); new Bug6530694();
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
} }
...@@ -69,6 +69,9 @@ public class StressTest { ...@@ -69,6 +69,9 @@ 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 reservedLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
Thread[] tasks = new Thread[locales.length * threadsFactor]; Thread[] tasks = new Thread[locales.length * threadsFactor];
counters = new AtomicIntegerArray(tasks.length); counters = new AtomicIntegerArray(tasks.length);
...@@ -82,7 +85,8 @@ public class StressTest { ...@@ -82,7 +85,8 @@ public class StressTest {
int nProcessors = Runtime.getRuntime().availableProcessors(); int nProcessors = Runtime.getRuntime().availableProcessors();
intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1); intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1);
System.out.printf("%d processors, intervalForCounterCheck = %d [sec]%n", System.out.printf(
"%d processors, intervalForCounterCheck = %d [sec]%n",
nProcessors, intervalForCounterCheck); nProcessors, intervalForCounterCheck);
try { try {
for (int i = 0; runrun && i < duration; i++) { for (int i = 0; runrun && i < duration; i++) {
...@@ -99,6 +103,10 @@ public class StressTest { ...@@ -99,6 +103,10 @@ public class StressTest {
} }
printCounters(); 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) {
Locale reservedLocale = Locale.getDefault();
try {
testCandidateOmission(); testCandidateOmission();
testExample(); 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) {
Locale reservedLocale = Locale.getDefault();
try {
test(Locale.GERMAN); test(Locale.GERMAN);
test(Locale.ENGLISH); 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 reservedLocale = Locale.getDefault();
try {
Locale.setDefault(new Locale("TR", "tr")); Locale.setDefault(new Locale("TR", "tr"));
File f = new File(System.getProperty("test.src","."), "test.jar"); File f = new File(System.getProperty("test.src","."), "test.jar");
JarFile jf = new JarFile(f, true); try (JarFile jf = new JarFile(f, true)) {
JarEntry je = (JarEntry)jf.getEntry("test.class"); JarEntry je = (JarEntry)jf.getEntry("test.class");
InputStream is = jf.getInputStream(je); try (InputStream is = jf.getInputStream(je)) {
byte[] b = new byte[1024]; byte[] b = new byte[1024];
while (is.read(b) != -1) { while (is.read(b) != -1) {
} }
if (je.getCertificates() == null) }
if (je.getCertificates() == null) {
throw new Exception("Null certificate for test.class."); throw new Exception("Null certificate for test.class.");
} }
}
} finally {
// restore the default locale
Locale.setDefault(reservedLocale);
}
}
} }
/* /*
* 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,6 +35,8 @@ import javax.crypto.Cipher; ...@@ -35,6 +35,8 @@ 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 reservedLocale = Locale.getDefault();
try {
Locale.setDefault(new Locale("tr", "TR")); Locale.setDefault(new Locale("tr", "TR"));
System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding")); System.out.println(Cipher.getInstance("RSA/ECB/PKCS1Padding"));
...@@ -45,5 +47,9 @@ public class Turkish { ...@@ -45,5 +47,9 @@ public class Turkish {
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,6 +98,8 @@ public class Test6524757 { ...@@ -98,6 +98,8 @@ 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) {
Locale reservedLocale = Locale.getDefault();
try {
// it affects Swing because it is not initialized // it affects Swing because it is not initialized
Locale.setDefault(Locale.KOREAN); Locale.setDefault(Locale.KOREAN);
validate(KOREAN, create()); validate(KOREAN, create());
...@@ -109,6 +111,10 @@ public class Test6524757 { ...@@ -109,6 +111,10 @@ public class Test6524757 {
// it definitely should affect Swing // it definitely should affect Swing
JComponent.setDefaultLocale(Locale.FRENCH); JComponent.setDefaultLocale(Locale.FRENCH);
validate(FRENCH, create()); 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,6 +1278,8 @@ public class KeyToolTest { ...@@ -1278,6 +1278,8 @@ public class KeyToolTest {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale reservedLocale = Locale.getDefault();
try {
// first test if HumanInputStream really acts like a human being // first test if HumanInputStream really acts like a human being
HumanInputStream.test(); HumanInputStream.test();
KeyToolTest t = new KeyToolTest(); KeyToolTest t = new KeyToolTest();
...@@ -1324,6 +1326,10 @@ public class KeyToolTest { ...@@ -1324,6 +1326,10 @@ public class KeyToolTest {
} }
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,6 +35,8 @@ public class Bug4248694 { ...@@ -35,6 +35,8 @@ public class Bug4248694 {
/******************************************************** /********************************************************
*********************************************************/ *********************************************************/
public static void main (String[] args) { public static void main (String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
int errors=0; int errors=0;
Locale loc = new Locale ("is", "is"); // Icelandic Locale loc = new Locale ("is", "is"); // Icelandic
...@@ -72,6 +74,10 @@ public class Bug4248694 { ...@@ -72,6 +74,10 @@ public class Bug4248694 {
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,6 +35,8 @@ public class Bug4804273 { ...@@ -35,6 +35,8 @@ public class Bug4804273 {
/******************************************************** /********************************************************
*********************************************************/ *********************************************************/
public static void main (String[] args) { public static void main (String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
int errors=0; int errors=0;
Locale loc = new Locale ("sv", "se"); // Swedish Locale loc = new Locale ("sv", "se"); // Swedish
...@@ -110,7 +112,12 @@ public class Bug4804273 { ...@@ -110,7 +112,12 @@ public class Bug4804273 {
}//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,7 +35,8 @@ public class Bug4848897 { ...@@ -35,7 +35,8 @@ public class Bug4848897 {
/******************************************************** /********************************************************
*********************************************************/ *********************************************************/
public static void main (String[] args) { public static void main (String[] args) {
Locale reservedLocale = Locale.getDefault();
try {
int errors=0; int errors=0;
Locale loc = new Locale ("no", "NO"); // Norwegian Locale loc = new Locale ("no", "NO"); // Norwegian
...@@ -68,6 +69,10 @@ public class Bug4848897 { ...@@ -68,6 +69,10 @@ public class Bug4848897 {
if (errors > 0) if (errors > 0)
throw new RuntimeException(); throw new RuntimeException();
}//end main } finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} // 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,6 +34,8 @@ import java.util.Locale; ...@@ -34,6 +34,8 @@ import java.util.Locale;
public class Bug4651568 { public class Bug4651568 {
public static void main (String argv[] ) { public static void main (String argv[] ) {
Locale reservedLocale = Locale.getDefault();
try {
String expectedCurrencyPattern = "\u00A4 #.##0,00"; String expectedCurrencyPattern = "\u00A4 #.##0,00";
Locale locale = new Locale ("pt", "BR"); Locale locale = new Locale ("pt", "BR");
...@@ -42,8 +44,8 @@ public class Bug4651568 { ...@@ -42,8 +44,8 @@ public class Bug4651568 {
DecimalFormat formatter = DecimalFormat formatter =
(DecimalFormat) NumberFormat.getCurrencyInstance(locale); (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
if (formatter.toLocalizedPattern().equals(expectedCurrencyPattern)) if (formatter.toLocalizedPattern().equals(
{ expectedCurrencyPattern)) {
System.out.println ("Passed."); System.out.println ("Passed.");
} else { } else {
System.out.println ("Failed Currency pattern." + System.out.println ("Failed Currency pattern." +
...@@ -52,5 +54,9 @@ public class Bug4651568 { ...@@ -52,5 +54,9 @@ public class Bug4651568 {
throw new RuntimeException(); 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
...@@ -48,6 +48,8 @@ public class Bug4965260 { ...@@ -48,6 +48,8 @@ public class Bug4965260 {
}; };
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale reservedLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
if (locales2Test.length != expectedNames.length) { if (locales2Test.length != expectedNames.length) {
throw new Exception("\nData sizes does not match!\n"); throw new Exception("\nData sizes does not match!\n");
...@@ -74,5 +76,9 @@ public class Bug4965260 { ...@@ -74,5 +76,9 @@ public class Bug4965260 {
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
*/ */
...@@ -73,6 +73,8 @@ public class Bug4640234 { ...@@ -73,6 +73,8 @@ public class Bug4640234 {
}; };
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Locale reservedLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
StringBuffer errors = new StringBuffer(""); StringBuffer errors = new StringBuffer("");
...@@ -82,7 +84,8 @@ public class Bug4640234 { ...@@ -82,7 +84,8 @@ public class Bug4640234 {
String[] countries = locEn.getISOCountries(); String[] countries = locEn.getISOCountries();
String[] languages = locEn.getISOLanguages(); String[] languages = locEn.getISOLanguages();
ResourceBundle resEn = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locEn); ResourceBundle resEn = ResourceBundle.getBundle(
"sun.util.resources.LocaleNames", locEn);
Map<String, String> countryMapEn = getList(resEn, true); Map<String, String> countryMapEn = getList(resEn, true);
Map<String, String> languageMapEn = getList(resEn, false); Map<String, String> languageMapEn = getList(resEn, false);
...@@ -91,7 +94,8 @@ public class Bug4640234 { ...@@ -91,7 +94,8 @@ public class Bug4640234 {
Map<String, String> languageMap; Map<String, String> languageMap;
for (Locale locale : locales2Test) { for (Locale locale : locales2Test) {
resLoc = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locale); resLoc = ResourceBundle.getBundle(
"sun.util.resources.LocaleNames", locale);
sdfLoc = new SimpleDateFormat("zzzz", locale); sdfLoc = new SimpleDateFormat("zzzz", locale);
sdfLocShort = new SimpleDateFormat("z", locale); sdfLocShort = new SimpleDateFormat("z", locale);
...@@ -153,6 +157,10 @@ public class Bug4640234 { ...@@ -153,6 +157,10 @@ public class Bug4640234 {
System.out.println(warnings.toString()); System.out.println(warnings.toString());
throw new Exception("\n" + message); throw new Exception("\n" + message);
} }
} finally {
// restore the reserved locale
Locale.setDefault(reservedLocale);
}
} }
/** /**
...@@ -210,16 +218,19 @@ public class Bug4640234 { ...@@ -210,16 +218,19 @@ public class Bug4640234 {
/** /**
* Verifies whether the name for ISOCode is localized. * Verifies whether the name for ISOCode is localized.
* @param ISOCode - ISO country/language code for country/language name to test * @param ISOCode - ISO country/language code for country/language name
* to test
* @param entriesEn - array of english country/language names * @param entriesEn - array of english country/language names
* @param entriesLoc - array of localized country/language names for specified locale * @param entriesLoc - array of localized country/language names for
* specified locale
* @param locale - locale to test against english * @param locale - locale to test against english
* @param notFoundMessage - message in form ready for MessageFormat, {0} will be human readable * @param notFoundMessage - message in form ready for MessageFormat,
* language name, {1} will be ISOCode. * {0} will be human readable language name, {1} will be ISOCode.
* @param notLocalizedMessage - message in for ready for MessageFormat, same formatting like * @param notLocalizedMessage - message in for ready for MessageFormat,
* for notFountMessage * same formatting like for notFountMessage
* @return array of two empty strings when passed, descriptive error message in * @return array of two empty strings when passed, descriptive error message
* other cases, [0] - warnings for not localized, [1] - errors for missing keys. * in other cases, [0] - warnings for not localized, [1] - errors for
* missing keys.
*/ */
private static String[] testEntry(String ISOCode, private static String[] testEntry(String ISOCode,
Map<String, String> entriesEn, Map<String, String> entriesEn,
...@@ -274,7 +285,8 @@ public class Bug4640234 { ...@@ -274,7 +285,8 @@ public class Bug4640234 {
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.
先完成此消息的编辑!
想要评论请 注册