Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/PluggableLocale/DateFormatSymbolsProviderTest.java
41149 views
1
/*
2
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
24
/*
25
* @test
26
* @bug 4052440 7200341 8062588 8210406
27
* @summary DateFormatSymbolsProvider tests
28
* @library providersrc/foobarutils
29
* providersrc/fooprovider
30
* @modules java.base/sun.util.locale.provider
31
* java.base/sun.util.resources
32
* @build com.foobar.Utils
33
* com.foo.*
34
* @run main/othervm -Djava.locale.providers=JRE,SPI DateFormatSymbolsProviderTest
35
*/
36
37
import java.text.DateFormatSymbols;
38
import java.util.Arrays;
39
import java.util.HashSet;
40
import java.util.List;
41
import java.util.Locale;
42
import java.util.MissingResourceException;
43
import java.util.ResourceBundle;
44
import java.util.Set;
45
46
import com.foo.DateFormatSymbolsProviderImpl;
47
48
import sun.util.locale.provider.LocaleProviderAdapter;
49
import sun.util.locale.provider.ResourceBundleBasedAdapter;
50
51
public class DateFormatSymbolsProviderTest extends ProviderTest {
52
53
DateFormatSymbolsProviderImpl dfsp = new DateFormatSymbolsProviderImpl();
54
List<Locale> availloc = Arrays.asList(DateFormatSymbols.getAvailableLocales());
55
List<Locale> providerloc = Arrays.asList(dfsp.getAvailableLocales());
56
List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
57
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider().getAvailableLocales());
58
59
public static void main(String[] s) {
60
new DateFormatSymbolsProviderTest();
61
}
62
63
DateFormatSymbolsProviderTest() {
64
availableLocalesTest();
65
objectValidityTest();
66
hashCodeTest();
67
}
68
69
void availableLocalesTest() {
70
Set<Locale> localesFromAPI = new HashSet<>(availloc);
71
Set<Locale> localesExpected = new HashSet<>(jreloc);
72
localesExpected.addAll(providerloc);
73
if (localesFromAPI.equals(localesExpected)) {
74
System.out.println("availableLocalesTest passed.");
75
} else {
76
throw new RuntimeException("availableLocalesTest failed");
77
}
78
}
79
80
void objectValidityTest() {
81
82
for (Locale target: availloc) {
83
// pure JRE implementation
84
ResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getDateFormatData(target);
85
boolean jreSupportsLocale = jreimplloc.contains(target);
86
87
// JRE string arrays
88
String[][] jres = new String[6][];
89
if (jreSupportsLocale) {
90
try {
91
jres[0] = (String[])rb.getObject("MonthNames");
92
jres[1] = (String[])rb.getObject("MonthAbbreviations");
93
jres[2] = (String[])rb.getObject("DayNames");
94
jres[3] = (String[])rb.getObject("DayAbbreviations");
95
jres[4] = (String[])rb.getObject("AmPmMarkers");
96
jres[5] = (String[])rb.getObject("Eras");
97
} catch (MissingResourceException mre) {}
98
}
99
100
// result object
101
DateFormatSymbols dfs = DateFormatSymbols.getInstance(target);
102
String[][] result = new String[6][];
103
result[0] = dfs.getMonths();
104
result[1] = dfs.getShortMonths();
105
// note that weekdays are 1-based
106
String[] tmp = dfs.getWeekdays();
107
result[2] = new String[7];
108
System.arraycopy(tmp, 1, result[2], 0, result[2].length);
109
tmp = dfs.getShortWeekdays();
110
result[3] = new String[7];
111
System.arraycopy(tmp, 1, result[3], 0, result[3].length);
112
result[4] = dfs.getAmPmStrings();
113
result[5] = dfs.getEras();
114
115
// provider's object (if any)
116
DateFormatSymbols providersDfs= null;
117
String[][] providers = new String[6][];
118
if (providerloc.contains(target)) {
119
providersDfs = dfsp.getInstance(target);
120
providers[0] = providersDfs.getMonths();
121
providers[1] = providersDfs.getShortMonths();
122
// note that weekdays are 1-based
123
tmp = dfs.getWeekdays();
124
providers[2] = new String[7];
125
System.arraycopy(tmp, 1, providers[2], 0, providers[2].length);
126
tmp = dfs.getShortWeekdays();
127
providers[3] = new String[7];
128
System.arraycopy(tmp, 1, providers[3], 0, providers[3].length);
129
providers[4] = providersDfs.getAmPmStrings();
130
providers[5] = providersDfs.getEras();
131
}
132
133
for (int i = 0; i < result.length; i ++) {
134
for (int j = 0; j < result[i].length; j++) {
135
String jresStr =
136
(jres[i] != null ? jres[i][j] : null);
137
String providersStr =
138
(providers[i] != null ? providers[i][j] : null);
139
String resultStr =
140
(result[i] != null ? result[i][j] : null);
141
checkValidity(target, jresStr, providersStr, resultStr, jreSupportsLocale);
142
}
143
}
144
}
145
}
146
147
// Bug 7200341.
148
void hashCodeTest() {
149
for (Locale target: availloc) {
150
// look for provider's object
151
DateFormatSymbols dfs = DateFormatSymbols.getInstance(target);
152
if (dfs.getClass().getSimpleName().equals("FooDateFormatSymbols")) {
153
// call its hashCode(). success if no ArrayIndexOutOfBoundsException is thrown.
154
dfs.hashCode();
155
break;
156
}
157
}
158
}
159
}
160