Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java
+++ new/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java
1 1 /*
2 - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 */
23 23 /*
24 24 *
25 25 */
26 26
27 27 import java.text.*;
28 28 import java.util.*;
29 -import sun.util.*;
29 +import sun.util.locale.provider.*;
30 30 import sun.util.resources.*;
31 31
32 32 public class TimeZoneNameProviderTest extends ProviderTest {
33 33
34 34 com.bar.TimeZoneNameProviderImpl tznp = new com.bar.TimeZoneNameProviderImpl();
35 35
36 36 public static void main(String[] s) {
37 37 new TimeZoneNameProviderTest();
38 38 }
39 39
40 40 TimeZoneNameProviderTest() {
41 41 test1();
42 42 test2();
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
43 43 aliasTest();
44 44 }
45 45
46 46 void test1() {
47 47 Locale[] available = Locale.getAvailableLocales();
48 48 List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
49 49 String[] ids = TimeZone.getAvailableIDs();
50 50
51 51 for (Locale target: available) {
52 52 // pure JRE implementation
53 - OpenListResourceBundle rb = LocaleData.getTimeZoneNames(target);
53 + OpenListResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getTimeZoneNames(target);
54 54 boolean jreHasBundle = rb.getLocale().equals(target);
55 55
56 56 for (String id: ids) {
57 57 // the time zone
58 58 TimeZone tz = TimeZone.getTimeZone(id);
59 59
60 60 // JRE string array for the id
61 61 String[] jrearray = null;
62 62 if (jreHasBundle) {
63 63 try {
64 64 jrearray = rb.getStringArray(id);
65 65 } catch (MissingResourceException mre) {}
66 66 }
67 67
68 68 for (int i = 1; i <=(tz.useDaylightTime()?4:2); i++) {
69 69 // the localized name
70 70 String name = tz.getDisplayName(i>=3, i%2, target);
71 71
72 72 // provider's name (if any)
73 73 String providersname = null;
74 74 if (providerLocales.contains(target)) {
75 75 providersname = tznp.getDisplayName(id, i>=3, i%2, target);
76 76 }
77 77
78 78 // JRE's name (if any)
79 79 String jresname = null;
80 80 if (jrearray != null) {
81 81 jresname = jrearray[i];
82 82 }
83 83
84 84 checkValidity(target, jresname, providersname, name,
85 85 jreHasBundle && rb.handleGetKeys().contains(id));
86 86 }
87 87 }
88 88 }
89 89 }
90 90
91 91 final String pattern = "z";
92 92 final Locale OSAKA = new Locale("ja", "JP", "osaka");
93 93 final Locale KYOTO = new Locale("ja", "JP", "kyoto");
94 94
95 95 final String[] TIMEZONES = {
96 96 "GMT", "America/Los_Angeles", "SystemV/PST8",
97 97 "SystemV/PST8PDT", "PST8PDT",
98 98 };
99 99 final String[] DISPLAY_NAMES_OSAKA = {
100 100 tznp.getDisplayName(TIMEZONES[0], false, TimeZone.SHORT, OSAKA),
101 101 tznp.getDisplayName(TIMEZONES[1], false, TimeZone.SHORT, OSAKA),
102 102 tznp.getDisplayName(TIMEZONES[2], false, TimeZone.SHORT, OSAKA),
103 103 tznp.getDisplayName(TIMEZONES[3], false, TimeZone.SHORT, OSAKA),
104 104 tznp.getDisplayName(TIMEZONES[4], false, TimeZone.SHORT, OSAKA)
105 105 };
106 106 final String[] DISPLAY_NAMES_KYOTO = {
107 107 tznp.getDisplayName(TIMEZONES[0], false, TimeZone.SHORT, KYOTO),
108 108 tznp.getDisplayName(TIMEZONES[1], false, TimeZone.SHORT, KYOTO),
109 109 tznp.getDisplayName(TIMEZONES[2], false, TimeZone.SHORT, KYOTO),
110 110 tznp.getDisplayName(TIMEZONES[3], false, TimeZone.SHORT, KYOTO),
111 111 tznp.getDisplayName(TIMEZONES[4], false, TimeZone.SHORT, KYOTO)
112 112 };
113 113
114 114 void test2() {
115 115 Locale defaultLocale = Locale.getDefault();
116 116 TimeZone reservedTimeZone = TimeZone.getDefault();
117 117 Date d = new Date(2005-1900, Calendar.DECEMBER, 22);
118 118 String formatted;
119 119
120 120 TimeZone tz;
121 121 SimpleDateFormat df;
122 122
123 123 try {
124 124 for (int i = 0; i < TIMEZONES.length; i++) {
125 125 tz = TimeZone.getTimeZone(TIMEZONES[i]);
126 126 TimeZone.setDefault(tz);
127 127 df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance(OSAKA));
128 128 Locale.setDefault(defaultLocale);
129 129 System.out.println(formatted = df.format(d));
130 130 if(!formatted.equals(DISPLAY_NAMES_OSAKA[i])) {
131 131 throw new RuntimeException("TimeZone " + TIMEZONES[i] +
132 132 ": formatted zone names mismatch. " +
133 133 formatted + " should match with " +
134 134 DISPLAY_NAMES_OSAKA[i]);
135 135 }
136 136
137 137 df.parse(DISPLAY_NAMES_OSAKA[i]);
138 138
139 139 Locale.setDefault(KYOTO);
140 140 df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
141 141 System.out.println(formatted = df.format(d));
142 142 if(!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
143 143 throw new RuntimeException("Timezone " + TIMEZONES[i] +
144 144 ": formatted zone names mismatch. " +
145 145 formatted + " should match with " +
146 146 DISPLAY_NAMES_KYOTO[i]);
147 147 }
148 148 df.parse(DISPLAY_NAMES_KYOTO[i]);
149 149 }
150 150 } catch (ParseException pe) {
151 151 throw new RuntimeException("parse error occured" + pe);
152 152 } finally {
153 153 // restore the reserved locale and time zone
154 154 Locale.setDefault(defaultLocale);
155 155 TimeZone.setDefault(reservedTimeZone);
156 156 }
157 157 }
158 158
159 159 final String LATIME = "America/Los_Angeles";
160 160 final String PST = "PST";
161 161 final String PST8PDT = "PST8PDT";
162 162 final String US_PACIFIC = "US/Pacific";
163 163 final String LATIME_IN_OSAKA =
164 164 tznp.getDisplayName(LATIME, false, TimeZone.LONG, OSAKA);
165 165
166 166 final String TOKYOTIME = "Asia/Tokyo";
167 167 final String JST = "JST";
168 168 final String JAPAN = "Japan";
169 169 final String JST_IN_OSAKA =
170 170 tznp.getDisplayName(JST, false, TimeZone.LONG, OSAKA);
171 171
172 172 void aliasTest() {
173 173 // Check that provider's name for a standard id (America/Los_Angeles) is
174 174 // propagated to its aliases
175 175 String latime = TimeZone.getTimeZone(LATIME).getDisplayName(OSAKA);
176 176 if (!LATIME_IN_OSAKA.equals(latime)) {
177 177 throw new RuntimeException("Could not get provider's localized name. result: "+latime+" expected: "+LATIME_IN_OSAKA);
178 178 }
179 179
180 180 String pst = TimeZone.getTimeZone(PST).getDisplayName(OSAKA);
181 181 if (!LATIME_IN_OSAKA.equals(pst)) {
182 182 throw new RuntimeException("Provider's localized name is not available for an alias ID: "+PST+". result: "+pst+" expected: "+LATIME_IN_OSAKA);
183 183 }
184 184
185 185 String us_pacific = TimeZone.getTimeZone(US_PACIFIC).getDisplayName(OSAKA);
186 186 if (!LATIME_IN_OSAKA.equals(us_pacific)) {
187 187 throw new RuntimeException("Provider's localized name is not available for an alias ID: "+US_PACIFIC+". result: "+us_pacific+" expected: "+LATIME_IN_OSAKA);
188 188 }
189 189
190 190 // Check that provider's name for an alias id (JST) is
191 191 // propagated to its standard id and alias ids.
192 192 String jstime = TimeZone.getTimeZone(JST).getDisplayName(OSAKA);
193 193 if (!JST_IN_OSAKA.equals(jstime)) {
194 194 throw new RuntimeException("Could not get provider's localized name. result: "+jstime+" expected: "+JST_IN_OSAKA);
195 195 }
196 196
197 197 String tokyotime = TimeZone.getTimeZone(TOKYOTIME).getDisplayName(OSAKA);
198 198 if (!JST_IN_OSAKA.equals(tokyotime)) {
199 199 throw new RuntimeException("Provider's localized name is not available for a standard ID: "+TOKYOTIME+". result: "+tokyotime+" expected: "+JST_IN_OSAKA);
200 200 }
201 201
202 202 String japan = TimeZone.getTimeZone(JAPAN).getDisplayName(OSAKA);
203 203 if (!JST_IN_OSAKA.equals(japan)) {
204 204 throw new RuntimeException("Provider's localized name is not available for an alias ID: "+JAPAN+". result: "+japan+" expected: "+JST_IN_OSAKA);
205 205 }
206 206 }
207 207 }
↓ open down ↓ |
144 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX