author | duke |
Wed, 05 Jul 2017 21:44:52 +0200 | |
changeset 38481 | c81b0662f43a |
parent 35768 | 7066da300a08 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
35768
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
31263
diff
changeset
|
2 |
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
/* |
|
24 |
* @test |
|
31263 | 25 |
* @bug 4449637 8008577 |
2 | 26 |
* @summary Basic acceptance test for international J2RE. Verifies that the |
27 |
* most important locale data and character converters exist and are |
|
28 |
* minimally functional. |
|
35768
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
31263
diff
changeset
|
29 |
* @modules jdk.localedata |
7066da300a08
8149391: Fix module dependences in java/util tests
shurailine
parents:
31263
diff
changeset
|
30 |
* jdk.charsets |
31263 | 31 |
* @run main/othervm -Djava.locale.providers=JRE,SPI InternationalBAT |
2 | 32 |
*/ |
33 |
||
34 |
import java.io.UnsupportedEncodingException; |
|
35 |
import java.text.DateFormat; |
|
36 |
import java.util.Calendar; |
|
37 |
import java.util.Date; |
|
38 |
import java.util.Locale; |
|
39 |
import java.util.TimeZone; |
|
40 |
||
41 |
public class InternationalBAT { |
|
42 |
||
43 |
public static void main(String[] args) { |
|
44 |
boolean pass = true; |
|
21830
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
45 |
|
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
46 |
TimeZone tz = TimeZone.getDefault(); |
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
47 |
try { |
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
48 |
pass &= testRequiredLocales(); |
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
49 |
pass &= testRequiredEncodings(); |
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
50 |
} finally { |
668b2337f339
8028734: test/java/util/Locale/InternationalBAT.java changes does not restore the default TimeZone
alanb
parents:
5506
diff
changeset
|
51 |
TimeZone.setDefault(tz); |
2 | 52 |
} |
53 |
||
54 |
if (!pass) { |
|
55 |
System.out.println("\nSome tests failed.\n" |
|
56 |
+ "If you installed the US-only J2RE for Windows, " |
|
57 |
+ "failures are expected and OK.\n" |
|
58 |
+ "If you installed the international J2RE, or any J2SDK, " |
|
59 |
+ "or if this occurs on any platform other than Windows, " |
|
60 |
+ "please file a bug report.\n" |
|
61 |
+ "Unfortunately, this test cannot determine whether you " |
|
62 |
+ "installed a US-only J2RE, an international J2RE, or " |
|
63 |
+ "a J2SDK.\n"); |
|
64 |
throw new RuntimeException(); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
// We require the "fully supported locales" for java.util and java.text: |
|
69 |
// http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#util-text |
|
70 |
||
71 |
private static Locale[] requiredLocales = { |
|
72 |
new Locale("ar", "SA"), |
|
73 |
new Locale("zh", "CN"), |
|
74 |
new Locale("zh", "TW"), |
|
75 |
new Locale("nl", "NL"), |
|
76 |
new Locale("en", "AU"), |
|
77 |
new Locale("en", "CA"), |
|
78 |
new Locale("en", "GB"), |
|
79 |
new Locale("en", "US"), |
|
80 |
new Locale("fr", "CA"), |
|
81 |
new Locale("fr", "FR"), |
|
82 |
new Locale("de", "DE"), |
|
83 |
new Locale("iw", "IL"), |
|
84 |
new Locale("hi", "IN"), |
|
85 |
new Locale("it", "IT"), |
|
86 |
new Locale("ja", "JP"), |
|
87 |
new Locale("ko", "KR"), |
|
88 |
new Locale("pt", "BR"), |
|
89 |
new Locale("es", "ES"), |
|
90 |
new Locale("sv", "SE"), |
|
91 |
new Locale("th", "TH"), |
|
92 |
}; |
|
93 |
||
94 |
// Date strings for May 10, 2001, for the required locales |
|
95 |
private static String[] requiredLocaleDates = { |
|
96 |
"10 \u0645\u0627\u064A\u0648, 2001", |
|
97 |
"2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB", |
|
98 |
"2001\u5E745\u670810\u65E5 \u661F\u671F\u56DB", |
|
99 |
"donderdag 10 mei 2001", |
|
100 |
"Thursday, 10 May 2001", |
|
101 |
"Thursday, May 10, 2001", |
|
102 |
"Thursday, 10 May 2001", |
|
103 |
"Thursday, May 10, 2001", |
|
104 |
"jeudi 10 mai 2001", |
|
105 |
"jeudi 10 mai 2001", |
|
106 |
"Donnerstag, 10. Mai 2001", |
|
107 |
"\u05D9\u05D5\u05DD \u05D7\u05DE\u05D9\u05E9\u05D9 10 \u05DE\u05D0\u05D9 2001", |
|
108 |
"\u0917\u0941\u0930\u0941\u0935\u093E\u0930, \u0967\u0966 \u092E\u0908, \u0968\u0966\u0966\u0967", |
|
109 |
"gioved\u00EC 10 maggio 2001", |
|
110 |
"2001\u5E745\u670810\u65E5", // ja_JP |
|
111 |
"2001\uB144 5\uC6D4 10\uC77C \uBAA9\uC694\uC77C", |
|
112 |
"Quinta-feira, 10 de Maio de 2001", |
|
113 |
"jueves 10 de mayo de 2001", |
|
114 |
"den 10 maj 2001", |
|
115 |
"\u0E27\u0E31\u0E19\u0E1E\u0E24\u0E2B\u0E31\u0E2A\u0E1A\u0E14\u0E35\u0E17\u0E35\u0E48 10 \u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21 \u0E1E.\u0E28. 2544", |
|
116 |
}; |
|
117 |
||
118 |
private static boolean testRequiredLocales() { |
|
119 |
boolean pass = true; |
|
120 |
||
121 |
TimeZone.setDefault(TimeZone.getTimeZone("GMT")); |
|
122 |
Calendar calendar = Calendar.getInstance(Locale.US); |
|
123 |
calendar.clear(); |
|
124 |
calendar.set(2001, 4, 10, 12, 0, 0); |
|
125 |
Date date = calendar.getTime(); |
|
126 |
||
127 |
Locale[] available = Locale.getAvailableLocales(); |
|
128 |
for (int i = 0; i < requiredLocales.length; i++) { |
|
129 |
Locale locale = requiredLocales[i]; |
|
130 |
boolean found = false; |
|
131 |
for (int j = 0; j < available.length; j++) { |
|
132 |
if (available[j].equals(locale)) { |
|
133 |
found = true; |
|
134 |
break; |
|
135 |
} |
|
136 |
} |
|
137 |
if (!found) { |
|
138 |
System.out.println("Locale not available: " + locale); |
|
139 |
pass = false; |
|
140 |
} else { |
|
141 |
DateFormat format = |
|
142 |
DateFormat.getDateInstance(DateFormat.FULL, locale); |
|
143 |
String dateString = format.format(date); |
|
144 |
if (!dateString.equals(requiredLocaleDates[i])) { |
|
145 |
System.out.println("Incorrect date string for locale " |
|
146 |
+ locale + ". Expected: " + requiredLocaleDates[i] |
|
147 |
+ ", got: " + dateString); |
|
148 |
pass = false; |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
return pass; |
|
153 |
} |
|
154 |
||
155 |
// We require the encodings of the fully supported writing systems: |
|
156 |
// http://webwork.eng/j2se/1.4/docs/guide/intl/locale.doc.html#jfc |
|
157 |
||
158 |
private static String[] requiredEncodings = { |
|
159 |
"Cp1256", |
|
160 |
"MS936", |
|
161 |
"MS950", |
|
162 |
"Cp1255", |
|
163 |
"MS932", |
|
164 |
"MS949", |
|
165 |
"Cp1252", |
|
166 |
"MS874", |
|
167 |
"ISO8859_6", |
|
168 |
"EUC_CN", |
|
169 |
"UTF8", |
|
170 |
"GBK", |
|
171 |
"EUC_TW", |
|
172 |
"ISO8859_8", |
|
173 |
"EUC_JP", |
|
174 |
"PCK", |
|
175 |
"EUC_KR", |
|
176 |
"ISO8859_1", |
|
177 |
"ISO8859_15", |
|
178 |
"TIS620", |
|
179 |
}; |
|
180 |
||
181 |
// one sample locale each for the required encodings |
|
182 |
||
183 |
private static Locale[] sampleLocales = { |
|
184 |
new Locale("ar", "SA"), |
|
185 |
new Locale("zh", "CN"), |
|
186 |
new Locale("zh", "TW"), |
|
187 |
new Locale("iw", "IL"), |
|
188 |
new Locale("ja", "JP"), |
|
189 |
new Locale("ko", "KR"), |
|
190 |
new Locale("it", "IT"), |
|
191 |
new Locale("th", "TH"), |
|
192 |
new Locale("ar", "SA"), |
|
193 |
new Locale("zh", "CN"), |
|
194 |
new Locale("zh", "CN"), |
|
195 |
new Locale("zh", "CN"), |
|
196 |
new Locale("zh", "TW"), |
|
197 |
new Locale("iw", "IL"), |
|
198 |
new Locale("ja", "JP"), |
|
199 |
new Locale("ja", "JP"), |
|
200 |
new Locale("ko", "KR"), |
|
201 |
new Locale("it", "IT"), |
|
202 |
new Locale("it", "IT"), |
|
203 |
new Locale("th", "TH"), |
|
204 |
}; |
|
205 |
||
206 |
// expected conversion results for the date strings of the sample locales |
|
207 |
||
208 |
private static byte[][] expectedBytes = { |
|
209 |
{ 0x31, 0x30, 0x20, (byte) 0xE3, (byte) 0xC7, (byte) 0xED, (byte) 0xE6, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
210 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4}, |
|
211 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xA6, 0x7E, 0x35, (byte) 0xA4, (byte) 0xEB, 0x31, 0x30, (byte) 0xA4, (byte) 0xE9, 0x20, (byte) 0xAC, (byte)0x50, (byte) 0xB4, (byte) 0xC1, (byte) 0xA5, (byte) 0x7C}, |
|
212 |
{ (byte) 0xE9, (byte) 0xE5, (byte) 0xED, 0x20, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xF9, (byte) 0xE9, 0x20, 0x31, 0x30, 0x20, (byte) 0xEE, (byte) 0xE0, (byte) 0xE9, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
213 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0x94, 0x4E, 0x35, (byte) 0x8C, (byte) 0x8E, 0x31, 0x30, (byte) 0x93, (byte) 0xFA, }, |
|
214 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xB3, (byte) 0xE2, 0x20, 0x35, (byte) 0xBF, (byte) 0xF9, 0x20, 0x31, 0x30, (byte) 0xC0, (byte) 0xCF, 0x20, (byte) 0xB8, (byte) 0xF1, (byte) 0xBF, (byte) 0xE4, (byte) 0xC0, (byte) 0xCF, }, |
|
215 |
{ 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
216 |
{ (byte) 0xC7, (byte) 0xD1, (byte) 0xB9, (byte) 0xBE, (byte) 0xC4, (byte) 0xCB, (byte) 0xD1, (byte) 0xCA, (byte) 0xBA, (byte) 0xB4, (byte) 0xD5, (byte) 0xB7, (byte) 0xD5, (byte) 0xE8, 0x20, 0x31, 0x30, 0x20, (byte) 0xBE, (byte) 0xC4, (byte) 0xC9, (byte) 0xC0, (byte) 0xD2, (byte) 0xA4, (byte) 0xC1, 0x20, (byte) 0xBE, 0x2E, (byte) 0xC8, 0x2E, 0x20, 0x32, 0x35, 0x34, 0x34, }, |
|
217 |
{ 0x31, 0x30, 0x20, (byte) 0xE5, (byte) 0xC7, (byte) 0xEA, (byte) 0xE8, 0x2C, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
218 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4}, |
|
219 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xE5, (byte) 0xB9, (byte) 0xB4, 0x35, (byte) 0xE6, (byte) 0x9C, (byte) 0x88, 0x31, 0x30, (byte) 0xE6, (byte) 0x97, (byte) 0xA5, 0x20, (byte) 0xE6, (byte)0x98, (byte) 0x9F, (byte) 0xE6, (byte) 0x9C, (byte) 0x9F, (byte) 0xE5, (byte) 0x9B, (byte) 0x9B}, |
|
220 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xC4, (byte) 0xEA, 0x35, (byte) 0xD4, (byte) 0xC2, 0x31, 0x30, (byte) 0xC8, (byte) 0xD5, 0x20, (byte) 0xD0, (byte) 0xC7, (byte) 0xC6, (byte) 0xDA, (byte) 0xCB, (byte) 0xC4}, |
|
221 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xC8, (byte) 0xA1, 0x35, (byte) 0xC5, (byte) 0xCC, 0x31, 0x30, (byte) 0xC5, (byte) 0xCA, 0x20, (byte) 0xD1, (byte) 0xD3, (byte) 0xDF, (byte) 0xE6, (byte) 0xC6, (byte) 0xBE}, |
|
222 |
{ (byte) 0xE9, (byte) 0xE5, (byte) 0xED, 0x20, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xF9, (byte) 0xE9, 0x20, 0x31, 0x30, 0x20, (byte) 0xEE, (byte) 0xE0, (byte) 0xE9, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
223 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xC7, (byte) 0xAF, 0x35, (byte) 0xB7, (byte) 0xEE, 0x31, 0x30, (byte) 0xC6, (byte) 0xFC, }, |
|
224 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0x94, 0x4E, 0x35, (byte) 0x8C, (byte) 0x8E, 0x31, 0x30, (byte) 0x93, (byte) 0xFA, }, |
|
225 |
{ 0x32, 0x30, 0x30, 0x31, (byte) 0xB3, (byte) 0xE2, 0x20, 0x35, (byte) 0xBF, (byte) 0xF9, 0x20, 0x31, 0x30, (byte) 0xC0, (byte) 0xCF, 0x20, (byte) 0xB8, (byte) 0xF1, (byte) 0xBF, (byte) 0xE4, (byte) 0xC0, (byte) 0xCF, }, |
|
226 |
{ 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
227 |
{ 0x67, 0x69, 0x6F, 0x76, 0x65, 0x64, (byte) 0xEC, 0x20, 0x31, 0x30, 0x20, 0x6D, 0x61, 0x67, 0x67, 0x69, 0x6F, 0x20, 0x32, 0x30, 0x30, 0x31, }, |
|
228 |
{ (byte) 0xC7, (byte) 0xD1, (byte) 0xB9, (byte) 0xBE, (byte) 0xC4, (byte) 0xCB, (byte) 0xD1, (byte) 0xCA, (byte) 0xBA, (byte) 0xB4, (byte) 0xD5, (byte) 0xB7, (byte) 0xD5, (byte) 0xE8, 0x20, 0x31, 0x30, 0x20, (byte) 0xBE, (byte) 0xC4, (byte) 0xC9, (byte) 0xC0, (byte) 0xD2, (byte) 0xA4, (byte) 0xC1, 0x20, (byte) 0xBE, 0x2E, (byte) 0xC8, 0x2E, 0x20, 0x32, 0x35, 0x34, 0x34, }, |
|
229 |
}; |
|
230 |
||
231 |
||
232 |
private static boolean testRequiredEncodings() { |
|
233 |
boolean pass = true; |
|
234 |
||
235 |
for (int i = 0; i < requiredEncodings.length; i++) { |
|
236 |
String encoding = requiredEncodings[i]; |
|
237 |
Locale sampleLocale = sampleLocales[i]; |
|
238 |
try { |
|
239 |
int index = 0; |
|
240 |
while (!sampleLocale.equals(requiredLocales[index])) { |
|
241 |
index++; |
|
242 |
} |
|
243 |
byte[] out = requiredLocaleDates[index].getBytes(encoding); |
|
244 |
byte[] expected = expectedBytes[i]; |
|
245 |
if (out.length != expected.length) { |
|
246 |
reportConversionError(encoding, expected, out); |
|
247 |
pass = false; |
|
248 |
} else { |
|
249 |
for (int j = 0; j < out.length; j++) { |
|
250 |
if (out[j] != expected[j]) { |
|
251 |
reportConversionError(encoding, expected, out); |
|
252 |
pass = false; |
|
253 |
break; |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
} catch (UnsupportedEncodingException e) { |
|
258 |
System.out.println("Encoding not available: " + encoding); |
|
259 |
pass = false; |
|
260 |
} |
|
261 |
} |
|
262 |
return pass; |
|
263 |
} |
|
264 |
||
265 |
private static void reportConversionError(String encoding, |
|
266 |
byte[] expected, byte[] actual) { |
|
267 |
||
268 |
System.out.println("Incorrect conversion for encoding: " + encoding); |
|
269 |
System.out.println("Expected output:"); |
|
270 |
dumpBytes(expected); |
|
271 |
System.out.println("Actual output:"); |
|
272 |
dumpBytes(actual); |
|
273 |
} |
|
274 |
||
275 |
private static void dumpBytes(byte[] bytes) { |
|
276 |
System.out.print(" { "); |
|
277 |
for (int i = 0; i < bytes.length; i++) { |
|
278 |
byte b = bytes[i]; |
|
279 |
if (b < 0) { |
|
280 |
System.out.print("(byte) "); |
|
281 |
} |
|
282 |
System.out.print("0x" + toHex((b & 0x00F0) >> 4) |
|
283 |
+ toHex((b & 0x000F)) + ", "); |
|
284 |
} |
|
285 |
System.out.println("},"); |
|
286 |
} |
|
287 |
||
288 |
private static char toHex(int i) { |
|
289 |
if (i <= 9) { |
|
290 |
return (char) ('0' + i); |
|
291 |
} else { |
|
292 |
return (char) ('A' + i - 10); |
|
293 |
} |
|
294 |
} |
|
295 |
} |