Print this page
rev 5974 : imported patch 8000997
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/PluggableLocale/GenericTest.java
+++ new/test/java/util/PluggableLocale/GenericTest.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
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
31 31 public class GenericTest {
32 32
33 33 // test providers
34 34 com.foo.BreakIteratorProviderImpl breakIP = new com.foo.BreakIteratorProviderImpl();
35 35 com.foo.CollatorProviderImpl collatorP = new com.foo.CollatorProviderImpl();
36 36 com.foo.DateFormatProviderImpl dateFP = new com.foo.DateFormatProviderImpl();
37 37 com.foo.DateFormatSymbolsProviderImpl dateFSP = new com.foo.DateFormatSymbolsProviderImpl();
38 38 com.foo.DecimalFormatSymbolsProviderImpl decimalFSP = new com.foo.DecimalFormatSymbolsProviderImpl();
39 39 com.foo.NumberFormatProviderImpl numberFP = new com.foo.NumberFormatProviderImpl();
40 40 com.bar.CurrencyNameProviderImpl currencyNP = new com.bar.CurrencyNameProviderImpl();
41 + com.bar.CurrencyNameProviderImpl2 currencyNP2 = new com.bar.CurrencyNameProviderImpl2();
41 42 com.bar.LocaleNameProviderImpl localeNP = new com.bar.LocaleNameProviderImpl();
42 43 com.bar.TimeZoneNameProviderImpl tzNP = new com.bar.TimeZoneNameProviderImpl();
43 44 com.bar.CalendarDataProviderImpl calDataP = new com.bar.CalendarDataProviderImpl();
44 45
45 46 public static void main(String[] s) {
46 47 new GenericTest();
47 48 }
48 49
49 50 GenericTest() {
50 51 availableLocalesTest();
51 52 localeFallbackTest();
52 53 }
53 54
54 55 /**
55 56 * Make sure that all the locales are available from the existing providers
56 57 */
57 58 void availableLocalesTest() {
58 59 // Check that Locale.getAvailableLocales() returns the union of the JRE supported
59 60 // locales and providers' locales
60 61 HashSet<Locale> result =
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
61 62 new HashSet<>(Arrays.asList(Locale.getAvailableLocales()));
62 63 HashSet<Locale> expected =
63 64 new HashSet<>(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales()));
64 65 expected.addAll(Arrays.asList(breakIP.getAvailableLocales()));
65 66 expected.addAll(Arrays.asList(collatorP.getAvailableLocales()));
66 67 expected.addAll(Arrays.asList(dateFP.getAvailableLocales()));
67 68 expected.addAll(Arrays.asList(dateFSP.getAvailableLocales()));
68 69 expected.addAll(Arrays.asList(decimalFSP.getAvailableLocales()));
69 70 expected.addAll(Arrays.asList(numberFP.getAvailableLocales()));
70 71 expected.addAll(Arrays.asList(currencyNP.getAvailableLocales()));
72 + expected.addAll(Arrays.asList(currencyNP2.getAvailableLocales()));
71 73 expected.addAll(Arrays.asList(localeNP.getAvailableLocales()));
72 74 expected.addAll(Arrays.asList(tzNP.getAvailableLocales()));
73 75 expected.addAll(Arrays.asList(calDataP.getAvailableLocales()));
74 76 expected.remove(Locale.ROOT);
75 77 if (!result.equals(expected)) {
76 78 throw new RuntimeException("Locale.getAvailableLocales() does not return the union of locales: diff="
77 79 + getDiff(result, expected));
78 80 }
79 81 }
80 82
81 83 /**
82 84 * test with "xx_YY_ZZ", which is an example locale not contained
83 85 * in Locale.getAvailableLocales(). Fallback tests for supported locales
84 86 * are done in each xxxProviderTest test cases.
85 87 */
86 88 void localeFallbackTest() {
87 89 Locale xx = new Locale("xx");
88 90 Locale dispLocale = new Locale ("xx", "YY", "ZZ");
89 91
90 92 String xxname = xx.getDisplayLanguage(xx);
91 93 String expected = localeNP.getDisplayLanguage(xx.getLanguage(), dispLocale);
92 94 if (!xxname.equals(expected)) {
93 95 throw new RuntimeException("Locale fallback did not perform correctly. got: "+xxname+" expected: "+expected);
94 96 }
95 97 }
96 98
97 99 private static String getDiff(Set set1, Set set2) {
98 100 Set s1 = (Set)((HashSet)set1).clone();
99 101 s1.removeAll(set2);
100 102
101 103 Set s2 = (Set)((HashSet)set2).clone();
102 104 s2.removeAll(set1);
103 105 s2.addAll(s1);
104 106 return s2.toString();
105 107 }
106 108 }
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX