author | duke |
Wed, 05 Jul 2017 22:06:37 +0200 | |
changeset 40471 | ad45133ff99e |
parent 40455 | db40a6f6f274 |
permissions | -rw-r--r-- |
6490 | 1 |
/* |
40455
db40a6f6f274
7094818: closed/java/text/Format/DateFormat tests failed on Hindi
peytoia
parents:
10339
diff
changeset
|
2 |
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
6490 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
6495
3cec0a02688b
6981759: copyright header fix for test/java/util/Locale/LocaleCategory.java
naoto
parents:
6490
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3cec0a02688b
6981759: copyright header fix for test/java/util/Locale/LocaleCategory.java
naoto
parents:
6490
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3cec0a02688b
6981759: copyright header fix for test/java/util/Locale/LocaleCategory.java
naoto
parents:
6490
diff
changeset
|
21 |
* questions. |
6490 | 22 |
*/ |
23 |
import java.util.Locale; |
|
24 |
||
25 |
public class LocaleCategory { |
|
26 |
private static Locale base = null; |
|
27 |
private static Locale disp = null; |
|
28 |
private static Locale fmt = null; |
|
29 |
private static String enc = null; |
|
30 |
||
31 |
public static void main(String[] args) { |
|
10138 | 32 |
Locale reservedLocale = Locale.getDefault(); |
40455
db40a6f6f274
7094818: closed/java/text/Format/DateFormat tests failed on Hindi
peytoia
parents:
10339
diff
changeset
|
33 |
if (TestUtils.hasSpecialVariant(reservedLocale)) { |
db40a6f6f274
7094818: closed/java/text/Format/DateFormat tests failed on Hindi
peytoia
parents:
10339
diff
changeset
|
34 |
System.out.println("Skipping this test because locale is " + reservedLocale); |
db40a6f6f274
7094818: closed/java/text/Format/DateFormat tests failed on Hindi
peytoia
parents:
10339
diff
changeset
|
35 |
return; |
db40a6f6f274
7094818: closed/java/text/Format/DateFormat tests failed on Hindi
peytoia
parents:
10339
diff
changeset
|
36 |
} |
db40a6f6f274
7094818: closed/java/text/Format/DateFormat tests failed on Hindi
peytoia
parents:
10339
diff
changeset
|
37 |
|
10138 | 38 |
try { |
39 |
Locale.Builder builder = new Locale.Builder(); |
|
7049 | 40 |
|
10138 | 41 |
base = builder.setLanguage(System.getProperty("user.language", "")) |
42 |
.setScript(System.getProperty("user.script", "")) |
|
43 |
.setRegion(System.getProperty("user.country", "")) |
|
44 |
.setVariant(System.getProperty("user.variant", "")).build(); |
|
45 |
disp = builder.setLanguage( |
|
46 |
System.getProperty("user.language.display", |
|
47 |
Locale.getDefault().getLanguage())) |
|
48 |
.setScript(System.getProperty("user.script.display", |
|
49 |
Locale.getDefault().getScript())) |
|
50 |
.setRegion(System.getProperty("user.country.display", |
|
51 |
Locale.getDefault().getCountry())) |
|
52 |
.setVariant(System.getProperty("user.variant.display", |
|
53 |
Locale.getDefault().getVariant())).build(); |
|
54 |
fmt = builder.setLanguage(System.getProperty("user.language.format", |
|
55 |
Locale.getDefault().getLanguage())) |
|
56 |
.setScript(System.getProperty("user.script.format", |
|
57 |
Locale.getDefault().getScript())) |
|
58 |
.setRegion(System.getProperty("user.country.format", |
|
59 |
Locale.getDefault().getCountry())) |
|
60 |
.setVariant(System.getProperty("user.variant.format", |
|
61 |
Locale.getDefault().getVariant())).build(); |
|
62 |
checkDefault(); |
|
63 |
testGetSetDefault(); |
|
10339
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
64 |
testBug7079486(); |
10138 | 65 |
} finally { |
66 |
// restore the reserved locale |
|
67 |
Locale.setDefault(reservedLocale); |
|
68 |
} |
|
6490 | 69 |
} |
70 |
||
71 |
static void checkDefault() { |
|
72 |
if (!base.equals(Locale.getDefault()) || |
|
73 |
!disp.equals(Locale.getDefault(Locale.Category.DISPLAY)) || |
|
74 |
!fmt.equals(Locale.getDefault(Locale.Category.FORMAT))) { |
|
75 |
throw new RuntimeException("Some of the return values from getDefault() do not agree with the locale derived from \"user.xxxx\" system properties"); |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
static void testGetSetDefault() { |
|
80 |
try { |
|
81 |
Locale.setDefault(null, null); |
|
82 |
throw new RuntimeException("setDefault(null, null) should throw a NullPointerException"); |
|
83 |
} catch (NullPointerException npe) {} |
|
84 |
||
85 |
Locale.setDefault(Locale.CHINA); |
|
86 |
if (!Locale.CHINA.equals(Locale.getDefault(Locale.Category.DISPLAY)) || |
|
87 |
!Locale.CHINA.equals(Locale.getDefault(Locale.Category.FORMAT))) { |
|
88 |
throw new RuntimeException("setDefault() should set all default locales for all categories"); |
|
89 |
} |
|
90 |
} |
|
10339
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
91 |
|
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
92 |
static void testBug7079486() { |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
93 |
Locale zh_Hans_CN = Locale.forLanguageTag("zh-Hans-CN"); |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
94 |
|
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
95 |
// make sure JRE has zh_Hans_CN localized string |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
96 |
if (zh_Hans_CN.getDisplayScript(Locale.US).equals(zh_Hans_CN.getDisplayScript(zh_Hans_CN))) { |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
97 |
return; |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
98 |
} |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
99 |
|
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
100 |
Locale.setDefault(Locale.US); |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
101 |
String en_script = zh_Hans_CN.getDisplayScript(); |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
102 |
|
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
103 |
Locale.setDefault(Locale.Category.DISPLAY, zh_Hans_CN); |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
104 |
String zh_script = zh_Hans_CN.getDisplayScript(); |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
105 |
|
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
106 |
if (en_script.equals(zh_script)) { |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
107 |
throw new RuntimeException("Locale.getDisplayScript() (no args) does not honor default DISPLAY locale"); |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
108 |
} |
80d9f4bc094b
7079486: Locale.getDisplayScript() (no args) does not honor default DISPLAY locale
naoto
parents:
10138
diff
changeset
|
109 |
} |
6490 | 110 |
} |
111 |