Print this page
rev 5957 : imported patch 8000245.8000273.8000615
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java
+++ new/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java
1 1 /*
2 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 *
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 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();
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
38 38 }
39 39
40 40 TimeZoneNameProviderTest() {
41 41 test1();
42 42 test2();
43 43 aliasTest();
44 44 }
45 45
46 46 void test1() {
47 47 Locale[] available = Locale.getAvailableLocales();
48 + List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getTimeZoneNameProvider().getAvailableLocales());
48 49 List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
49 50 String[] ids = TimeZone.getAvailableIDs();
50 51
51 52 for (Locale target: available) {
52 53 // pure JRE implementation
53 54 OpenListResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getTimeZoneNames(target);
54 - boolean jreHasBundle = rb.getLocale().equals(target);
55 + boolean jreSupportsTarget = jreimplloc.contains(target);
55 56
56 57 for (String id: ids) {
57 58 // the time zone
58 59 TimeZone tz = TimeZone.getTimeZone(id);
59 60
60 61 // JRE string array for the id
61 62 String[] jrearray = null;
62 - if (jreHasBundle) {
63 + if (jreSupportsTarget) {
63 64 try {
64 65 jrearray = rb.getStringArray(id);
65 66 } catch (MissingResourceException mre) {}
66 67 }
67 68
68 69 for (int i = 1; i <=(tz.useDaylightTime()?4:2); i++) {
69 70 // the localized name
70 71 String name = tz.getDisplayName(i>=3, i%2, target);
71 72
72 73 // provider's name (if any)
73 74 String providersname = null;
74 75 if (providerLocales.contains(target)) {
75 76 providersname = tznp.getDisplayName(id, i>=3, i%2, target);
76 77 }
77 78
78 - // JRE's name (if any)
79 + // JRE's name
79 80 String jresname = null;
80 81 if (jrearray != null) {
81 82 jresname = jrearray[i];
82 83 }
83 84
84 85 checkValidity(target, jresname, providersname, name,
85 - jreHasBundle && rb.handleGetKeys().contains(id));
86 + jreSupportsTarget && jresname != null);
86 87 }
87 88 }
88 89 }
89 90 }
90 91
91 92 final String pattern = "z";
92 93 final Locale OSAKA = new Locale("ja", "JP", "osaka");
93 94 final Locale KYOTO = new Locale("ja", "JP", "kyoto");
94 95
95 96 final String[] TIMEZONES = {
96 97 "GMT", "America/Los_Angeles", "SystemV/PST8",
97 98 "SystemV/PST8PDT", "PST8PDT",
98 99 };
99 100 final String[] DISPLAY_NAMES_OSAKA = {
100 101 tznp.getDisplayName(TIMEZONES[0], false, TimeZone.SHORT, OSAKA),
101 102 tznp.getDisplayName(TIMEZONES[1], false, TimeZone.SHORT, OSAKA),
102 103 tznp.getDisplayName(TIMEZONES[2], false, TimeZone.SHORT, OSAKA),
103 104 tznp.getDisplayName(TIMEZONES[3], false, TimeZone.SHORT, OSAKA),
104 105 tznp.getDisplayName(TIMEZONES[4], false, TimeZone.SHORT, OSAKA)
105 106 };
106 107 final String[] DISPLAY_NAMES_KYOTO = {
107 108 tznp.getDisplayName(TIMEZONES[0], false, TimeZone.SHORT, KYOTO),
108 109 tznp.getDisplayName(TIMEZONES[1], false, TimeZone.SHORT, KYOTO),
109 110 tznp.getDisplayName(TIMEZONES[2], false, TimeZone.SHORT, KYOTO),
110 111 tznp.getDisplayName(TIMEZONES[3], false, TimeZone.SHORT, KYOTO),
111 112 tznp.getDisplayName(TIMEZONES[4], false, TimeZone.SHORT, KYOTO)
112 113 };
113 114
114 115 void test2() {
115 116 Locale defaultLocale = Locale.getDefault();
116 117 TimeZone reservedTimeZone = TimeZone.getDefault();
117 118 Date d = new Date(2005-1900, Calendar.DECEMBER, 22);
118 119 String formatted;
119 120
120 121 TimeZone tz;
121 122 SimpleDateFormat df;
122 123
123 124 try {
124 125 for (int i = 0; i < TIMEZONES.length; i++) {
125 126 tz = TimeZone.getTimeZone(TIMEZONES[i]);
126 127 TimeZone.setDefault(tz);
127 128 df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance(OSAKA));
128 129 Locale.setDefault(defaultLocale);
129 130 System.out.println(formatted = df.format(d));
130 131 if(!formatted.equals(DISPLAY_NAMES_OSAKA[i])) {
131 132 throw new RuntimeException("TimeZone " + TIMEZONES[i] +
132 133 ": formatted zone names mismatch. " +
133 134 formatted + " should match with " +
134 135 DISPLAY_NAMES_OSAKA[i]);
135 136 }
136 137
137 138 df.parse(DISPLAY_NAMES_OSAKA[i]);
138 139
139 140 Locale.setDefault(KYOTO);
140 141 df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
141 142 System.out.println(formatted = df.format(d));
142 143 if(!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
143 144 throw new RuntimeException("Timezone " + TIMEZONES[i] +
144 145 ": formatted zone names mismatch. " +
145 146 formatted + " should match with " +
146 147 DISPLAY_NAMES_KYOTO[i]);
147 148 }
148 149 df.parse(DISPLAY_NAMES_KYOTO[i]);
149 150 }
150 151 } catch (ParseException pe) {
151 152 throw new RuntimeException("parse error occured" + pe);
152 153 } finally {
153 154 // restore the reserved locale and time zone
154 155 Locale.setDefault(defaultLocale);
155 156 TimeZone.setDefault(reservedTimeZone);
156 157 }
157 158 }
158 159
159 160 final String LATIME = "America/Los_Angeles";
160 161 final String PST = "PST";
161 162 final String PST8PDT = "PST8PDT";
162 163 final String US_PACIFIC = "US/Pacific";
163 164 final String LATIME_IN_OSAKA =
164 165 tznp.getDisplayName(LATIME, false, TimeZone.LONG, OSAKA);
165 166
166 167 final String TOKYOTIME = "Asia/Tokyo";
167 168 final String JST = "JST";
168 169 final String JAPAN = "Japan";
169 170 final String JST_IN_OSAKA =
170 171 tznp.getDisplayName(JST, false, TimeZone.LONG, OSAKA);
171 172
172 173 void aliasTest() {
173 174 // Check that provider's name for a standard id (America/Los_Angeles) is
174 175 // propagated to its aliases
175 176 String latime = TimeZone.getTimeZone(LATIME).getDisplayName(OSAKA);
176 177 if (!LATIME_IN_OSAKA.equals(latime)) {
177 178 throw new RuntimeException("Could not get provider's localized name. result: "+latime+" expected: "+LATIME_IN_OSAKA);
178 179 }
179 180
180 181 String pst = TimeZone.getTimeZone(PST).getDisplayName(OSAKA);
181 182 if (!LATIME_IN_OSAKA.equals(pst)) {
182 183 throw new RuntimeException("Provider's localized name is not available for an alias ID: "+PST+". result: "+pst+" expected: "+LATIME_IN_OSAKA);
183 184 }
184 185
185 186 String us_pacific = TimeZone.getTimeZone(US_PACIFIC).getDisplayName(OSAKA);
186 187 if (!LATIME_IN_OSAKA.equals(us_pacific)) {
187 188 throw new RuntimeException("Provider's localized name is not available for an alias ID: "+US_PACIFIC+". result: "+us_pacific+" expected: "+LATIME_IN_OSAKA);
188 189 }
189 190
190 191 // Check that provider's name for an alias id (JST) is
191 192 // propagated to its standard id and alias ids.
192 193 String jstime = TimeZone.getTimeZone(JST).getDisplayName(OSAKA);
193 194 if (!JST_IN_OSAKA.equals(jstime)) {
194 195 throw new RuntimeException("Could not get provider's localized name. result: "+jstime+" expected: "+JST_IN_OSAKA);
195 196 }
196 197
197 198 String tokyotime = TimeZone.getTimeZone(TOKYOTIME).getDisplayName(OSAKA);
198 199 if (!JST_IN_OSAKA.equals(tokyotime)) {
199 200 throw new RuntimeException("Provider's localized name is not available for a standard ID: "+TOKYOTIME+". result: "+tokyotime+" expected: "+JST_IN_OSAKA);
200 201 }
201 202
202 203 String japan = TimeZone.getTimeZone(JAPAN).getDisplayName(OSAKA);
203 204 if (!JST_IN_OSAKA.equals(japan)) {
204 205 throw new RuntimeException("Provider's localized name is not available for an alias ID: "+JAPAN+". result: "+japan+" expected: "+JST_IN_OSAKA);
205 206 }
206 207 }
207 208 }
↓ open down ↓ |
112 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX