Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/nio/charset/Charset/Contains.java
41155 views
1
/*
2
* Copyright (c) 2010, 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
/* @test
25
* @summary Unit test for charset containment
26
* @bug 6798572
27
* @modules jdk.charsets
28
*/
29
30
import java.nio.charset.*;
31
32
33
public class Contains {
34
35
static void ck(Charset cs1, Charset cs2, boolean cont) throws Exception {
36
if ((cs1.contains(cs2)) != cont)
37
throw new Exception("Wrong answer: "
38
+ cs1.name() + " contains " + cs2.name());
39
System.err.println(cs1.name()
40
+ (cont ? " contains " : " does not contain ")
41
+ cs2.name());
42
}
43
44
public static void main(String[] args) throws Exception {
45
46
Charset us_ascii = Charset.forName("US-ASCII");
47
Charset iso_8859_1 = Charset.forName("ISO-8859-1");
48
Charset iso_8859_15 = Charset.forName("ISO-8859-15");
49
Charset utf_8 = Charset.forName("UTF-8");
50
Charset utf_16be = Charset.forName("UTF-16BE");
51
Charset cp1252 = Charset.forName("CP1252");
52
53
ck(us_ascii, us_ascii, true);
54
ck(us_ascii, iso_8859_1, false);
55
ck(us_ascii, iso_8859_15, false);
56
ck(us_ascii, utf_8, false);
57
ck(us_ascii, utf_16be, false);
58
ck(us_ascii, cp1252, false);
59
60
ck(iso_8859_1, us_ascii, true);
61
ck(iso_8859_1, iso_8859_1, true);
62
ck(iso_8859_1, iso_8859_15, false);
63
ck(iso_8859_1, utf_8, false);
64
ck(iso_8859_1, utf_16be, false);
65
ck(iso_8859_1, cp1252, false);
66
67
ck(iso_8859_15, us_ascii, true);
68
ck(iso_8859_15, iso_8859_1, false);
69
ck(iso_8859_15, iso_8859_15, true);
70
ck(iso_8859_15, utf_8, false);
71
ck(iso_8859_15, utf_16be, false);
72
ck(iso_8859_15, cp1252, false);
73
74
ck(utf_8, us_ascii, true);
75
ck(utf_8, iso_8859_1, true);
76
ck(utf_8, iso_8859_15, true);
77
ck(utf_8, utf_8, true);
78
ck(utf_8, utf_16be, true);
79
ck(utf_8, cp1252, true);
80
81
ck(utf_16be, us_ascii, true);
82
ck(utf_16be, iso_8859_1, true);
83
ck(utf_16be, iso_8859_15, true);
84
ck(utf_16be, utf_8, true);
85
ck(utf_16be, utf_16be, true);
86
ck(utf_16be, cp1252, true);
87
88
ck(cp1252, us_ascii, true);
89
ck(cp1252, iso_8859_1, false);
90
ck(cp1252, iso_8859_15, false);
91
ck(cp1252, utf_8, false);
92
ck(cp1252, utf_16be, false);
93
ck(cp1252, cp1252, true);
94
95
checkUTF();
96
}
97
98
static void checkUTF() throws Exception {
99
for (String utfName : utfNames)
100
for (String csName : charsetNames)
101
ck(Charset.forName(utfName),
102
Charset.forName(csName),
103
true);
104
}
105
106
static String[] utfNames = {"utf-16",
107
"utf-8",
108
"utf-16le",
109
"utf-16be",
110
"x-utf-16le-bom"};
111
112
static String[] charsetNames = {
113
"US-ASCII",
114
"UTF-8",
115
"UTF-16",
116
"UTF-16BE",
117
"UTF-16LE",
118
"x-UTF-16LE-BOM",
119
"GBK",
120
"GB18030",
121
"ISO-8859-1",
122
"ISO-8859-15",
123
"ISO-8859-2",
124
"ISO-8859-3",
125
"ISO-8859-4",
126
"ISO-8859-5",
127
"ISO-8859-6",
128
"ISO-8859-7",
129
"ISO-8859-8",
130
"ISO-8859-9",
131
"ISO-8859-13",
132
"JIS_X0201",
133
"x-JIS0208",
134
"JIS_X0212-1990",
135
"GB2312",
136
"EUC-KR",
137
"x-EUC-TW",
138
"EUC-JP",
139
"x-euc-jp-linux",
140
"KOI8-R",
141
"TIS-620",
142
"x-ISCII91",
143
"windows-1251",
144
"windows-1252",
145
"windows-1253",
146
"windows-1254",
147
"windows-1255",
148
"windows-1256",
149
"windows-1257",
150
"windows-1258",
151
"windows-932",
152
"x-mswin-936",
153
"x-windows-949",
154
"x-windows-950",
155
"windows-31j",
156
"Big5",
157
"Big5-HKSCS",
158
"x-MS950-HKSCS",
159
"ISO-2022-JP",
160
"ISO-2022-KR",
161
"x-ISO-2022-CN-CNS",
162
"x-ISO-2022-CN-GB",
163
"Big5-HKSCS",
164
"x-Johab",
165
"Shift_JIS"
166
};
167
}
168
169