author | naoto |
Tue, 16 Oct 2012 10:59:21 -0700 | |
changeset 14185 | 916ec0a4d039 |
parent 14028 | 5f3d5ae5f1ea |
child 14336 | 4a3418a2c07f |
permissions | -rw-r--r-- |
13583 | 1 |
/* |
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* |
|
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. |
|
22 |
*/ |
|
14028
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
23 |
import java.text.*; |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
24 |
import java.text.spi.*; |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
25 |
import java.util.*; |
13583 | 26 |
import sun.util.locale.provider.LocaleProviderAdapter; |
27 |
||
28 |
public class LocaleProviders { |
|
29 |
||
30 |
public static void main(String[] args) { |
|
14028
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
31 |
String methodName = args[0]; |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
32 |
|
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
33 |
switch (methodName) { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
34 |
case "getPlatformLocale": |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
35 |
if (args[1].equals("format")) { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
36 |
getPlatformLocale(Locale.Category.FORMAT); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
37 |
} else { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
38 |
getPlatformLocale(Locale.Category.DISPLAY); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
39 |
} |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
40 |
break; |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
41 |
|
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
42 |
case "adapterTest": |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
43 |
adapterTest(args[1], args[2], (args.length >= 4 ? args[3] : "")); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
44 |
break; |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
45 |
|
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
46 |
case "bug7198834Test": |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
47 |
bug7198834Test(); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
48 |
break; |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
49 |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
50 |
case "tzNameTest": |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
51 |
tzNameTest(args[1]); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
52 |
break; |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
53 |
|
14028
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
54 |
default: |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
55 |
throw new RuntimeException("Test method '"+methodName+"' not found."); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
56 |
} |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
57 |
} |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
58 |
|
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
59 |
static void getPlatformLocale(Locale.Category cat) { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
60 |
Locale defloc = Locale.getDefault(cat); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
61 |
System.out.printf("%s,%s\n", defloc.getLanguage(), defloc.getCountry()); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
62 |
} |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
63 |
|
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
64 |
static void adapterTest(String expected, String lang, String ctry) { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
65 |
Locale testLocale = new Locale(lang, ctry); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
66 |
String preference = System.getProperty("java.locale.providers", ""); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
67 |
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
68 |
LocaleProviderAdapter.Type type = lda.getAdapterType(); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
69 |
System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
70 |
if (!type.toString().equals(expected)) { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
71 |
throw new RuntimeException("Returned locale data adapter is not correct."); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
72 |
} |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
73 |
} |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
74 |
|
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
75 |
static void bug7198834Test() { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
76 |
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
77 |
LocaleProviderAdapter.Type type = lda.getAdapterType(); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
78 |
if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
79 |
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
80 |
String date = df.format(new Date()); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
81 |
if (date.charAt(date.length()-1) == ' ') { |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
82 |
throw new RuntimeException("Windows Host Locale Provider returns a trailing space."); |
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
83 |
} |
14024
694c379c2958
7196799: CLDR adapter can not be invoked when region code is specified in Locale
naoto
parents:
13583
diff
changeset
|
84 |
} else { |
14028
5f3d5ae5f1ea
7198834: HOST Adapter: one extra empty space in the end of the pattern string
naoto
parents:
14024
diff
changeset
|
85 |
System.out.println("Windows HOST locale adapter not found. Ignoring this test."); |
13583 | 86 |
} |
87 |
} |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
88 |
|
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
89 |
static void tzNameTest(String id) { |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
90 |
TimeZone tz = TimeZone.getTimeZone(id); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
91 |
String tzName = tz.getDisplayName(false, TimeZone.SHORT, Locale.US); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
92 |
if (tzName.startsWith("GMT")) { |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
93 |
throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
94 |
} |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
14028
diff
changeset
|
95 |
} |
13583 | 96 |
} |