Print this page
rev 5974 : imported patch 8000997
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/PluggableLocale/CurrencyNameProviderTest.java
+++ new/test/java/util/PluggableLocale/CurrencyNameProviderTest.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 CurrencyNameProviderTest extends ProviderTest {
33 33
34 34 public static void main(String[] s) {
35 35 Locale reservedLocale = Locale.getDefault();
36 36 try {
37 37 new CurrencyNameProviderTest();
38 38 } finally {
39 39 // restore the reserved locale
40 40 Locale.setDefault(reservedLocale);
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
41 41 }
42 42 }
43 43
44 44 CurrencyNameProviderTest() {
45 45 test1();
46 46 test2();
47 47 }
48 48
49 49 void test1() {
50 50 com.bar.CurrencyNameProviderImpl cnp = new com.bar.CurrencyNameProviderImpl();
51 + com.bar.CurrencyNameProviderImpl2 cnp2 = new com.bar.CurrencyNameProviderImpl2();
51 52 Locale[] availloc = Locale.getAvailableLocales();
52 53 Locale[] testloc = availloc.clone();
53 54 List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCurrencyNameProvider().getAvailableLocales());
54 - List<Locale> providerloc = Arrays.asList(cnp.getAvailableLocales());
55 + List<Locale> providerloc = new ArrayList<Locale>();
56 + providerloc.addAll(Arrays.asList(cnp.getAvailableLocales()));
57 + providerloc.addAll(Arrays.asList(cnp2.getAvailableLocales()));
55 58
56 59 for (Locale target: availloc) {
57 60 // pure JRE implementation
58 61 OpenListResourceBundle rb = (OpenListResourceBundle)LocaleProviderAdapter.forJRE().getLocaleData().getCurrencyNames(target);
59 62 boolean jreSupportsTarget = jreimplloc.contains(target);
60 63
61 64 for (Locale test: testloc) {
62 65 // get a Currency instance
63 66 Currency c = null;
64 67 try {
65 68 c = Currency.getInstance(test);
66 69 } catch (IllegalArgumentException iae) {}
67 70
68 71 if (c == null) {
69 72 continue;
70 73 }
71 74
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
72 75 // the localized symbol for the target locale
73 76 String currencyresult = c.getSymbol(target);
74 77
75 78 // the localized name for the target locale
76 79 String nameresult = c.getDisplayName(target);
77 80
78 81 // provider's name (if any)
79 82 String providerscurrency = null;
80 83 String providersname = null;
81 84 if (providerloc.contains(target)) {
82 - providerscurrency = cnp.getSymbol(c.getCurrencyCode(), target);
83 - providersname = cnp.getDisplayName(c.getCurrencyCode(), target);
85 + if (cnp.isSupportedLocale(target)) {
86 + providerscurrency = cnp.getSymbol(c.getCurrencyCode(), target);
87 + providersname = cnp.getDisplayName(c.getCurrencyCode(), target);
88 + } else {
89 + providerscurrency = cnp2.getSymbol(c.getCurrencyCode(), target);
90 + providersname = cnp2.getDisplayName(c.getCurrencyCode(), target);
91 + }
84 92 }
85 93
86 94 // JRE's name
87 95 String jrescurrency = null;
88 96 String jresname = null;
89 97 String key = c.getCurrencyCode();
90 98 String nameKey = key.toLowerCase(Locale.ROOT);
91 99 if (jreSupportsTarget) {
92 100 try {
93 101 jrescurrency = rb.getString(key);
94 102 } catch (MissingResourceException mre) {}
95 103 try {
96 104 jresname = rb.getString(nameKey);
97 105 } catch (MissingResourceException mre) {}
98 106 }
99 107
100 108 checkValidity(target, jrescurrency, providerscurrency, currencyresult,
101 109 jreSupportsTarget && jrescurrency != null);
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
102 110 checkValidity(target, jresname, providersname, nameresult,
103 111 jreSupportsTarget && jresname != null);
104 112 }
105 113 }
106 114 }
107 115
108 116
109 117 final String pattern = "###,###\u00A4";
110 118 final String YEN_IN_OSAKA = "100,000\u5186\u3084\u3002";
111 119 final String YEN_IN_KYOTO = "100,000\u5186\u3069\u3059\u3002";
120 + final String YEN_IN_TOKYO= "100,000JPY-tokyo";
112 121 final Locale OSAKA = new Locale("ja", "JP", "osaka");
113 122 final Locale KYOTO = new Locale("ja", "JP", "kyoto");
123 + final Locale TOKYO = new Locale("ja", "JP", "tokyo");
114 124 Integer i = new Integer(100000);
115 125 String formatted;
116 126 DecimalFormat df;
117 127
118 128 void test2() {
129 + Locale defloc = Locale.getDefault();
130 +
119 131 try {
120 132 df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(OSAKA));
121 133 System.out.println(formatted = df.format(i));
122 134 if(!formatted.equals(YEN_IN_OSAKA)) {
123 - throw new RuntimeException("formatted zone names mismatch. " +
135 + throw new RuntimeException("formatted currency names mismatch. " +
124 136 "Should match with " + YEN_IN_OSAKA);
125 137 }
126 138
127 139 df.parse(YEN_IN_OSAKA);
128 140
129 141 Locale.setDefault(KYOTO);
130 142 df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance());
131 143 System.out.println(formatted = df.format(i));
132 144 if(!formatted.equals(YEN_IN_KYOTO)) {
133 - throw new RuntimeException("formatted zone names mismatch. " +
145 + throw new RuntimeException("formatted currency names mismatch. " +
134 146 "Should match with " + YEN_IN_KYOTO);
135 147 }
136 148
137 149 df.parse(YEN_IN_KYOTO);
150 +
151 + Locale.setDefault(TOKYO);
152 + df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance());
153 + System.out.println(formatted = df.format(i));
154 + if(!formatted.equals(YEN_IN_TOKYO)) {
155 + throw new RuntimeException("formatted currency names mismatch. " +
156 + "Should match with " + YEN_IN_TOKYO);
157 + }
158 +
159 + df.parse(YEN_IN_TOKYO);
138 160 } catch (ParseException pe) {
139 161 throw new RuntimeException("parse error occured" + pe);
162 + } finally {
163 + Locale.setDefault(defloc);
140 164 }
141 165 }
142 166 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX