author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 15260 | 7af2d7a87806 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
15260
diff
changeset
|
2 |
* Copyright (c) 2007, 2013, 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 CurrencyNameProviderTest extends ProviderTest { |
|
33 |
||
34 |
public static void main(String[] s) { |
|
10138 | 35 |
Locale reservedLocale = Locale.getDefault(); |
36 |
try { |
|
37 |
new CurrencyNameProviderTest(); |
|
38 |
} finally { |
|
39 |
// restore the reserved locale |
|
40 |
Locale.setDefault(reservedLocale); |
|
41 |
} |
|
2 | 42 |
} |
43 |
||
44 |
CurrencyNameProviderTest() { |
|
45 |
test1(); |
|
46 |
test2(); |
|
47 |
} |
|
48 |
||
49 |
void test1() { |
|
50 |
com.bar.CurrencyNameProviderImpl cnp = new com.bar.CurrencyNameProviderImpl(); |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
51 |
com.bar.CurrencyNameProviderImpl2 cnp2 = new com.bar.CurrencyNameProviderImpl2(); |
2 | 52 |
Locale[] availloc = Locale.getAvailableLocales(); |
53 |
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
|
54 |
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCurrencyNameProvider().getAvailableLocales()); |
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
55 |
List<Locale> providerloc = new ArrayList<Locale>(); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
56 |
providerloc.addAll(Arrays.asList(cnp.getAvailableLocales())); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
57 |
providerloc.addAll(Arrays.asList(cnp2.getAvailableLocales())); |
2 | 58 |
|
59 |
for (Locale target: availloc) { |
|
60 |
// pure JRE implementation |
|
15260 | 61 |
OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getCurrencyNames(target); |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
62 |
boolean jreSupportsTarget = jreimplloc.contains(target); |
2 | 63 |
|
64 |
for (Locale test: testloc) { |
|
65 |
// get a Currency instance |
|
66 |
Currency c = null; |
|
67 |
try { |
|
68 |
c = Currency.getInstance(test); |
|
69 |
} catch (IllegalArgumentException iae) {} |
|
70 |
||
71 |
if (c == null) { |
|
72 |
continue; |
|
73 |
} |
|
74 |
||
75 |
// the localized symbol for the target locale |
|
76 |
String currencyresult = c.getSymbol(target); |
|
77 |
||
78 |
// the localized name for the target locale |
|
79 |
String nameresult = c.getDisplayName(target); |
|
80 |
||
81 |
// provider's name (if any) |
|
82 |
String providerscurrency = null; |
|
83 |
String providersname = null; |
|
84 |
if (providerloc.contains(target)) { |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
85 |
if (cnp.isSupportedLocale(target)) { |
2 | 86 |
providerscurrency = cnp.getSymbol(c.getCurrencyCode(), target); |
87 |
providersname = cnp.getDisplayName(c.getCurrencyCode(), target); |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
88 |
} else { |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
89 |
providerscurrency = cnp2.getSymbol(c.getCurrencyCode(), target); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
90 |
providersname = cnp2.getDisplayName(c.getCurrencyCode(), target); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
91 |
} |
2 | 92 |
} |
93 |
||
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
94 |
// JRE's name |
2 | 95 |
String jrescurrency = null; |
96 |
String jresname = null; |
|
97 |
String key = c.getCurrencyCode(); |
|
98 |
String nameKey = key.toLowerCase(Locale.ROOT); |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
99 |
if (jreSupportsTarget) { |
2 | 100 |
try { |
101 |
jrescurrency = rb.getString(key); |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
102 |
} catch (MissingResourceException mre) {} |
2 | 103 |
try { |
104 |
jresname = rb.getString(nameKey); |
|
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
105 |
} catch (MissingResourceException mre) {} |
2 | 106 |
} |
107 |
||
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
108 |
checkValidity(target, jrescurrency, providerscurrency, currencyresult, |
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
109 |
jreSupportsTarget && jrescurrency != null); |
2 | 110 |
checkValidity(target, jresname, providersname, nameresult, |
14185
916ec0a4d039
8000245: SimpleDateFormat.format(date, StringBuffer, FieldPosition) doesn't work as expected with custom extensions
naoto
parents:
13583
diff
changeset
|
111 |
jreSupportsTarget && jresname != null); |
2 | 112 |
} |
113 |
} |
|
114 |
} |
|
115 |
||
116 |
||
117 |
final String pattern = "###,###\u00A4"; |
|
118 |
final String YEN_IN_OSAKA = "100,000\u5186\u3084\u3002"; |
|
119 |
final String YEN_IN_KYOTO = "100,000\u5186\u3069\u3059\u3002"; |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
120 |
final String YEN_IN_TOKYO= "100,000JPY-tokyo"; |
2 | 121 |
final Locale OSAKA = new Locale("ja", "JP", "osaka"); |
122 |
final Locale KYOTO = new Locale("ja", "JP", "kyoto"); |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
123 |
final Locale TOKYO = new Locale("ja", "JP", "tokyo"); |
2 | 124 |
Integer i = new Integer(100000); |
125 |
String formatted; |
|
126 |
DecimalFormat df; |
|
127 |
||
128 |
void test2() { |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
129 |
Locale defloc = Locale.getDefault(); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
130 |
|
2 | 131 |
try { |
132 |
df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(OSAKA)); |
|
133 |
System.out.println(formatted = df.format(i)); |
|
134 |
if(!formatted.equals(YEN_IN_OSAKA)) { |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
135 |
throw new RuntimeException("formatted currency names mismatch. " + |
2 | 136 |
"Should match with " + YEN_IN_OSAKA); |
137 |
} |
|
138 |
||
139 |
df.parse(YEN_IN_OSAKA); |
|
140 |
||
141 |
Locale.setDefault(KYOTO); |
|
142 |
df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance()); |
|
143 |
System.out.println(formatted = df.format(i)); |
|
144 |
if(!formatted.equals(YEN_IN_KYOTO)) { |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
145 |
throw new RuntimeException("formatted currency names mismatch. " + |
2 | 146 |
"Should match with " + YEN_IN_KYOTO); |
147 |
} |
|
148 |
||
149 |
df.parse(YEN_IN_KYOTO); |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
150 |
|
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
151 |
Locale.setDefault(TOKYO); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
152 |
df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance()); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
153 |
System.out.println(formatted = df.format(i)); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
154 |
if(!formatted.equals(YEN_IN_TOKYO)) { |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
155 |
throw new RuntimeException("formatted currency names mismatch. " + |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
156 |
"Should match with " + YEN_IN_TOKYO); |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
157 |
} |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
158 |
|
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
159 |
df.parse(YEN_IN_TOKYO); |
2 | 160 |
} catch (ParseException pe) { |
161 |
throw new RuntimeException("parse error occured" + pe); |
|
14331
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
162 |
} finally { |
d3411e624053
8000997: Multiple locale sensitive services cannot be loaded
naoto
parents:
14185
diff
changeset
|
163 |
Locale.setDefault(defloc); |
2 | 164 |
} |
165 |
} |
|
166 |
} |