author | ctornqvi |
Thu, 16 May 2013 15:31:00 +0200 | |
changeset 17598 | f78d22d3c6c2 |
parent 15260 | 7af2d7a87806 |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
13583 | 2 |
* Copyright (c) 2007, 2012, 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 |
* |
|
25 |
*/ |
|
26 |
||
27 |
import java.text.*; |
|
28 |
import java.util.*; |
|
13583 | 29 |
import sun.util.locale.provider.*; |
2 | 30 |
import sun.util.resources.*; |
31 |
||
32 |
public class LocaleNameProviderTest extends ProviderTest { |
|
33 |
||
34 |
public static void main(String[] s) { |
|
35 |
new LocaleNameProviderTest(); |
|
36 |
} |
|
37 |
||
38 |
LocaleNameProviderTest() { |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
39 |
checkAvailLocValidityTest(); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
40 |
variantFallbackTest(); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
41 |
} |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
42 |
|
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
43 |
void checkAvailLocValidityTest() { |
2 | 44 |
com.bar.LocaleNameProviderImpl lnp = new com.bar.LocaleNameProviderImpl(); |
45 |
Locale[] availloc = Locale.getAvailableLocales(); |
|
46 |
Locale[] testloc = availloc.clone(); |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
47 |
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getLocaleNameProvider().getAvailableLocales()); |
2 | 48 |
List<Locale> providerloc = Arrays.asList(lnp.getAvailableLocales()); |
49 |
||
50 |
for (Locale target: availloc) { |
|
51 |
// pure JRE implementation |
|
15260 | 52 |
OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getLocaleNames(target); |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
53 |
boolean jreSupportsTarget = jreimplloc.contains(target); |
2 | 54 |
|
55 |
for (Locale test: testloc) { |
|
56 |
// codes |
|
57 |
String lang = test.getLanguage(); |
|
58 |
String ctry = test.getCountry(); |
|
59 |
String vrnt = test.getVariant(); |
|
60 |
||
61 |
// the localized name |
|
62 |
String langresult = test.getDisplayLanguage(target); |
|
63 |
String ctryresult = test.getDisplayCountry(target); |
|
64 |
String vrntresult = test.getDisplayVariant(target); |
|
65 |
||
66 |
// provider's name (if any) |
|
67 |
String providerslang = null; |
|
68 |
String providersctry = null; |
|
69 |
String providersvrnt = null; |
|
70 |
if (providerloc.contains(target)) { |
|
71 |
providerslang = lnp.getDisplayLanguage(lang, target); |
|
72 |
providersctry = lnp.getDisplayCountry(ctry, target); |
|
73 |
providersvrnt = lnp.getDisplayVariant(vrnt, target); |
|
74 |
} |
|
75 |
||
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
76 |
// JRE's name |
2 | 77 |
String jreslang = null; |
78 |
String jresctry = null; |
|
79 |
String jresvrnt = null; |
|
80 |
if (!lang.equals("")) { |
|
81 |
try { |
|
82 |
jreslang = rb.getString(lang); |
|
83 |
} catch (MissingResourceException mre) {} |
|
84 |
} |
|
85 |
if (!ctry.equals("")) { |
|
86 |
try { |
|
87 |
jresctry = rb.getString(ctry); |
|
88 |
} catch (MissingResourceException mre) {} |
|
89 |
} |
|
90 |
if (!vrnt.equals("")) { |
|
91 |
try { |
|
92 |
jresvrnt = rb.getString("%%"+vrnt); |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
93 |
} catch (MissingResourceException mre) {} |
2 | 94 |
} |
95 |
||
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
96 |
System.out.print("For key: "+lang+" "); |
2 | 97 |
checkValidity(target, jreslang, providerslang, langresult, |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
98 |
jreSupportsTarget && jreslang != null); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
99 |
System.out.print("For key: "+ctry+" "); |
2 | 100 |
checkValidity(target, jresctry, providersctry, ctryresult, |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
101 |
jreSupportsTarget && jresctry != null); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
102 |
System.out.print("For key: "+vrnt+" "); |
2 | 103 |
checkValidity(target, jresvrnt, providersvrnt, vrntresult, |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
104 |
jreSupportsTarget && jresvrnt != null); |
2 | 105 |
} |
106 |
} |
|
107 |
} |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
108 |
|
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
109 |
void variantFallbackTest() { |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
110 |
Locale YY = new Locale("yy", "YY", "YYYY"); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
111 |
Locale YY_suffix = new Locale("yy", "YY", "YYYY_suffix"); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
112 |
String retVrnt = null; |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
113 |
String message = "variantFallbackTest() succeeded."; |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
114 |
|
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
115 |
|
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
116 |
try { |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
117 |
YY.getDisplayVariant(YY_suffix); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
118 |
message = "variantFallbackTest() failed. Either provider wasn't invoked, or invoked without suffix."; |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
119 |
} catch (RuntimeException re) { |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
120 |
retVrnt = re.getMessage(); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
121 |
if (YY_suffix.getVariant().equals(retVrnt)) { |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
122 |
System.out.println(message); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
123 |
return; |
2 | 124 |
} |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
125 |
message = "variantFallbackTest() failed. Returned variant: "+retVrnt; |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
126 |
} |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
127 |
|
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
128 |
throw new RuntimeException(message); |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
129 |
} |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
130 |
} |