Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/PluggableLocale/DecimalFormatSymbolsProviderTest.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 8062588 8210406
27
* @summary DecimalFormatSymbolsProvider tests
28
* @library providersrc/foobarutils
29
* providersrc/fooprovider
30
* @modules java.base/sun.util.locale.provider
31
* @build com.foobar.Utils
32
* com.foo.*
33
* @run main/othervm -Djava.locale.providers=JRE,SPI DecimalFormatSymbolsProviderTest
34
*/
35
36
import java.text.DecimalFormatSymbols;
37
import java.util.Arrays;
38
import java.util.HashSet;
39
import java.util.List;
40
import java.util.Locale;
41
import java.util.Set;
42
43
import com.foo.DecimalFormatSymbolsProviderImpl;
44
45
import sun.util.locale.provider.LocaleProviderAdapter;
46
47
public class DecimalFormatSymbolsProviderTest extends ProviderTest {
48
49
DecimalFormatSymbolsProviderImpl dfsp = new DecimalFormatSymbolsProviderImpl();
50
List<Locale> availloc = Arrays.asList(DecimalFormatSymbols.getAvailableLocales());
51
List<Locale> providerloc = Arrays.asList(dfsp.getAvailableLocales());
52
List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
53
List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider().getAvailableLocales());
54
55
public static void main(String[] s) {
56
new DecimalFormatSymbolsProviderTest();
57
}
58
59
DecimalFormatSymbolsProviderTest() {
60
availableLocalesTest();
61
objectValidityTest();
62
}
63
64
void availableLocalesTest() {
65
Set<Locale> localesFromAPI = new HashSet<>(availloc);
66
Set<Locale> localesExpected = new HashSet<>(jreloc);
67
localesExpected.addAll(providerloc);
68
if (localesFromAPI.equals(localesExpected)) {
69
System.out.println("availableLocalesTest passed.");
70
} else {
71
throw new RuntimeException("availableLocalesTest failed");
72
}
73
}
74
75
void objectValidityTest() {
76
77
for (Locale target: availloc) {
78
// pure JRE implementation
79
Object[] data = LocaleProviderAdapter.forJRE().getLocaleResources(target).getDecimalFormatSymbolsData();
80
boolean jreSupportsLocale = jreimplloc.contains(target);
81
82
// JRE string arrays
83
String[] jres = new String[2];
84
if (jreSupportsLocale) {
85
String[] tmp = (String[]) data[0];
86
jres[0] = tmp[9]; // infinity
87
jres[1] = tmp[10]; // NaN
88
}
89
90
// result object
91
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(target);
92
String[] result = new String[2];
93
result[0] = dfs.getInfinity();
94
result[1] = dfs.getNaN();
95
96
// provider's object (if any)
97
DecimalFormatSymbols providersDfs= null;
98
String[] providers = new String[2];
99
if (providerloc.contains(target)) {
100
providersDfs = dfsp.getInstance(target);
101
providers[0] = providersDfs.getInfinity();
102
providers[1] = providersDfs.getNaN();
103
}
104
105
for (int i = 0; i < result.length; i ++) {
106
checkValidity(target, jres[i], providers[i], result[i], jreSupportsLocale);
107
}
108
}
109
}
110
}
111