Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Character/UnicodeCasingTest.java
41149 views
1
/*
2
* Copyright (c) 2018, 2019, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
* @test
28
* @bug 4397357 6565620 6959267 8032446 8072600 8221431
29
* @summary Confirm normal case mappings are handled correctly.
30
* @library /lib/testlibrary/java/lang
31
* @run main/timeout=200 UnicodeCasingTest
32
*/
33
34
import java.io.BufferedReader;
35
import java.io.File;
36
import java.io.FileReader;
37
import java.util.ArrayList;
38
import java.util.List;
39
import java.util.Locale;
40
41
public class UnicodeCasingTest {
42
43
private static boolean err = false;
44
45
// Locales which are used for testing
46
private static List<Locale> locales = new ArrayList<>();
47
static {
48
locales.add(new Locale("az", ""));
49
locales.addAll(java.util.Arrays.asList(Locale.getAvailableLocales()));
50
}
51
52
53
public static void main(String[] args) {
54
UnicodeCasingTest specialCasingTest = new UnicodeCasingTest();
55
specialCasingTest.test();
56
}
57
58
private void test() {
59
Locale defaultLocale = Locale.getDefault();
60
61
BufferedReader in = null;
62
63
try {
64
File file = UCDFiles.UNICODE_DATA.toFile();
65
66
int locale_num = locales.size();
67
for (int l = 0; l < locale_num; l++) {
68
Locale locale = locales.get(l);
69
Locale.setDefault(locale);
70
System.out.println("Testing on " + locale + " locale....");
71
72
in = new BufferedReader(new FileReader(file));
73
74
String line;
75
while ((line = in.readLine()) != null) {
76
if (line.length() == 0 || line.charAt(0) == '#') {
77
continue;
78
}
79
80
test(line);
81
}
82
83
in.close();
84
in = null;
85
}
86
}
87
catch (Exception e) {
88
err = true;
89
e.printStackTrace();
90
}
91
finally {
92
if (in != null) {
93
try {
94
in.close();
95
}
96
catch (Exception e) {
97
}
98
}
99
100
Locale.setDefault(defaultLocale);
101
102
if (err) {
103
throw new RuntimeException("UnicodeCasingTest failed.");
104
} else {
105
System.out.println("UnicodeCasingTest passed.");
106
}
107
}
108
}
109
110
private void test(String line) {
111
String[] fields = line.split(";", 15);
112
int orig = convert(fields[0]);
113
114
if (fields[12].length() != 0) {
115
testUpperCase(orig, convert(fields[12]));
116
} else {
117
testUpperCase(orig, orig);
118
}
119
120
if (fields[13].length() != 0) {
121
testLowerCase(orig, convert(fields[13]));
122
} else {
123
testLowerCase(orig, orig);
124
}
125
126
if (fields[14].length() != 0) {
127
testTitleCase(orig, convert(fields[14]));
128
} else {
129
testTitleCase(orig, orig);
130
}
131
}
132
133
private void testUpperCase(int orig, int expected) {
134
int got = Character.toUpperCase(orig);
135
136
if (expected != got) {
137
err = true;
138
System.err.println("toUpperCase(" +
139
") failed.\n\tOriginal: " + toString(orig) +
140
"\n\tGot: " + toString(got) +
141
"\n\tExpected: " + toString(expected));
142
}
143
}
144
145
private void testLowerCase(int orig, int expected) {
146
int got = Character.toLowerCase(orig);
147
148
if (expected != got) {
149
err = true;
150
System.err.println("toLowerCase(" +
151
") failed.\n\tOriginal: " + toString(orig) +
152
"\n\tGot: " + toString(got) +
153
"\n\tExpected: " + toString(expected));
154
}
155
}
156
157
private void testTitleCase(int orig, int expected) {
158
int got = Character.toTitleCase(orig);
159
160
if (expected != got) {
161
err = true;
162
System.err.println("toTitleCase(" +
163
") failed.\n\tOriginal: " + toString(orig) +
164
"\n\tGot: " + toString(got) +
165
"\n\tExpected: " + toString(expected));
166
}
167
}
168
169
private int convert(String str) {
170
return Integer.parseInt(str, 16);
171
}
172
173
private String toString(int i) {
174
return Integer.toHexString(i).toUpperCase();
175
}
176
177
}
178
179