Print this page
rev 6057 : imported patch 8001205.8001562
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/PluggableLocale/DateFormatSymbolsProviderTest.java
+++ new/test/java/util/PluggableLocale/DateFormatSymbolsProviderTest.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 DateFormatSymbolsProviderTest extends ProviderTest {
33 33
34 34 com.foo.DateFormatSymbolsProviderImpl dfsp = new com.foo.DateFormatSymbolsProviderImpl();
35 35 List<Locale> availloc = Arrays.asList(DateFormatSymbols.getAvailableLocales());
36 36 List<Locale> providerloc = Arrays.asList(dfsp.getAvailableLocales());
37 37 List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
38 38 List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider().getAvailableLocales());
39 39
40 40 public static void main(String[] s) {
41 41 new DateFormatSymbolsProviderTest();
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
42 42 }
43 43
44 44 DateFormatSymbolsProviderTest() {
45 45 availableLocalesTest();
46 46 objectValidityTest();
47 47 hashCodeTest();
48 48 }
49 49
50 50 void availableLocalesTest() {
51 51 Set<Locale> localesFromAPI = new HashSet<Locale>(availloc);
52 - Set<Locale> localesExpected = new HashSet<Locale>(jreimplloc);
53 - localesExpected.remove(Locale.ROOT);
52 + Set<Locale> localesExpected = new HashSet<Locale>(jreloc);
54 53 localesExpected.addAll(providerloc);
55 54 if (localesFromAPI.equals(localesExpected)) {
56 55 System.out.println("availableLocalesTest passed.");
57 56 } else {
58 57 throw new RuntimeException("availableLocalesTest failed");
59 58 }
60 59 }
61 60
62 61 void objectValidityTest() {
63 62
64 63 for (Locale target: availloc) {
65 64 // pure JRE implementation
66 65 ResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getDateFormatData(target);
67 66 boolean jreSupportsLocale = jreimplloc.contains(target);
68 67
69 68 // JRE string arrays
70 69 String[][] jres = new String[6][];
71 70 if (jreSupportsLocale) {
72 71 try {
73 72 jres[0] = (String[])rb.getObject("MonthNames");
74 73 jres[1] = (String[])rb.getObject("MonthAbbreviations");
75 74 jres[2] = (String[])rb.getObject("DayNames");
76 75 jres[3] = (String[])rb.getObject("DayAbbreviations");
77 76 jres[4] = (String[])rb.getObject("AmPmMarkers");
78 77 jres[5] = (String[])rb.getObject("Eras");
79 78 } catch (MissingResourceException mre) {}
80 79 }
81 80
82 81 // result object
83 82 DateFormatSymbols dfs = DateFormatSymbols.getInstance(target);
84 83 String[][] result = new String[6][];
85 84 result[0] = dfs.getMonths();
86 85 result[1] = dfs.getShortMonths();
87 86 // note that weekdays are 1-based
88 87 String[] tmp = dfs.getWeekdays();
89 88 result[2] = new String[7];
90 89 System.arraycopy(tmp, 1, result[2], 0, result[2].length);
91 90 tmp = dfs.getShortWeekdays();
92 91 result[3] = new String[7];
93 92 System.arraycopy(tmp, 1, result[3], 0, result[3].length);
94 93 result[4] = dfs.getAmPmStrings();
95 94 result[5] = dfs.getEras();
96 95
97 96 // provider's object (if any)
98 97 DateFormatSymbols providersDfs= null;
99 98 String[][] providers = new String[6][];
100 99 if (providerloc.contains(target)) {
101 100 providersDfs = dfsp.getInstance(target);
102 101 providers[0] = providersDfs.getMonths();
103 102 providers[1] = providersDfs.getShortMonths();
104 103 // note that weekdays are 1-based
105 104 tmp = dfs.getWeekdays();
106 105 providers[2] = new String[7];
107 106 System.arraycopy(tmp, 1, providers[2], 0, providers[2].length);
108 107 tmp = dfs.getShortWeekdays();
109 108 providers[3] = new String[7];
110 109 System.arraycopy(tmp, 1, providers[3], 0, providers[3].length);
111 110 providers[4] = providersDfs.getAmPmStrings();
112 111 providers[5] = providersDfs.getEras();
113 112 }
114 113
115 114 for (int i = 0; i < result.length; i ++) {
116 115 for (int j = 0; j < result[i].length; j++) {
117 116 String jresStr =
118 117 (jres[i] != null ? jres[i][j] : null);
119 118 String providersStr =
120 119 (providers[i] != null ? providers[i][j] : null);
121 120 String resultStr =
122 121 (result[i] != null ? result[i][j] : null);
123 122 checkValidity(target, jresStr, providersStr, resultStr, jreSupportsLocale);
124 123 }
125 124 }
126 125 }
127 126 }
128 127
129 128 // Bug 7200341.
130 129 void hashCodeTest() {
131 130 for (Locale target: availloc) {
132 131 // look for provider's object
133 132 DateFormatSymbols dfs = DateFormatSymbols.getInstance(target);
134 133 if (dfs.getClass().getSimpleName().equals("FooDateFormatSymbols")) {
135 134 // call its hashCode(). success if no ArrayIndexOutOfBoundsException is thrown.
136 135 dfs.hashCode();
137 136 break;
138 137 }
139 138 }
140 139 }
141 140 }
↓ open down ↓ |
78 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX