Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/nio/cs/EuroConverter.java
38838 views
1
/*
2
* Copyright (c) 2008, 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 4114080
27
* @summary Make sure the euro converters, which are derived from
28
* existing converters, only differ from their parents at the expected
29
* code point.
30
*/
31
32
import java.text.*;
33
import java.util.*;
34
import java.io.*;
35
36
/* Author: Alan Liu
37
* 7/14/98
38
*/
39
public class EuroConverter {
40
public static void main(String args[]) throws Exception {
41
boolean pass = true;
42
char[] map = new char[256]; // map for the encoding
43
byte[] bytes = new byte[1]; // scratch
44
char[] chars = new char[1]; // scratch
45
for (int i=0; i<DATA.length; ) {
46
String euroEnc = DATA[i++];
47
String parentEnc = DATA[i++];
48
System.out.println("Checking encoder " + euroEnc + " against " + parentEnc);
49
String currentEnc = parentEnc;
50
51
try {
52
// Fill map with parent values
53
for (int j=-128; j<128; ++j) {
54
bytes[0] = (byte)j;
55
char parentValue = new String(bytes, parentEnc).charAt(0);
56
// NOTE: 0x25 doesn't round trip on the EBCDIC code pages,
57
// so we don't check that code point in the sanity check.
58
if (j != 0x0025) {
59
chars[0] = parentValue;
60
int parentRoundTrip = new String(chars).getBytes(parentEnc)[0];
61
// This is a sanity check -- we aren't really testing the parent
62
// encoder here.
63
if (parentRoundTrip != j) {
64
pass = false;
65
System.out.println("Error: Encoder " + parentEnc +
66
" fails round-trip: " + j +
67
" -> \\u" + Integer.toHexString(parentValue) +
68
" -> " + parentRoundTrip);
69
}
70
}
71
map[(j+0x100)&0xFF] = parentValue;
72
}
73
74
// Modify map with new expected values. Each pair has code point, parent value, euro value.
75
// Terminated by null.
76
while (DATA[i] != null) {
77
int codePoint = Integer.valueOf(DATA[i++], 16).intValue();
78
char expectedParentValue = DATA[i++].charAt(0);
79
char expectedEuroValue = DATA[i++].charAt(0);
80
// This is a sanity check -- we aren't really testing the parent
81
// encoder here.
82
if (map[codePoint] != expectedParentValue) {
83
pass = false;
84
System.out.println("Error: Encoder " + parentEnc +
85
" " + Integer.toHexString(codePoint) + " -> \\u" +
86
Integer.toHexString(map[codePoint]) + ", expected \\u" +
87
Integer.toHexString(expectedParentValue));
88
}
89
// Fill in new expected value
90
map[codePoint] = expectedEuroValue;
91
}
92
++i; // Skip over null at end of set
93
94
// Now verify the euro encoder
95
currentEnc = euroEnc;
96
for (int j=-128; j<128; ++j) {
97
bytes[0] = (byte)j;
98
char euroValue = new String(bytes, euroEnc).charAt(0);
99
chars[0] = euroValue;
100
// NOTE: 0x15 doesn't round trip on the EBCDIC code pages,
101
// so we don't check that code point in the sanity check.
102
if (j != 0x0015) {
103
int euroRoundTrip = new String(chars).getBytes(euroEnc)[0];
104
if (euroRoundTrip != j) {
105
pass = false;
106
System.out.println("Error: Encoder " + euroEnc +
107
" fails round-trip at " + j);
108
}
109
}
110
// Compare against the map
111
if (euroValue != map[(j+0x100)&0xFF]) {
112
pass = false;
113
System.out.println("Error: Encoder " + euroEnc +
114
" " + Integer.toHexString((j+0x100)&0xFF) + " -> \\u" +
115
Integer.toHexString(euroValue) + ", expected \\u" +
116
Integer.toHexString(map[(j+0x100)&0xFF]));
117
}
118
}
119
} catch (UnsupportedEncodingException e) {
120
System.out.println("Unsupported encoding " + currentEnc);
121
pass = false;
122
while (i < DATA.length && DATA[i] != null) ++i;
123
++i; // Skip over null
124
}
125
}
126
if (!pass) {
127
throw new RuntimeException("Bug 4114080 - Euro encoder test failed");
128
}
129
}
130
static String[] DATA = {
131
// New converter, parent converter, [ code point that changed, parent code point value,
132
// euro code point value ], null
133
// Any number of changed code points may be specified, including zero.
134
"ISO8859_15_FDIS", "ISO8859_1",
135
"A4", "\u00A4", "\u20AC",
136
"A6", "\u00A6", "\u0160",
137
"A8", "\u00A8", "\u0161",
138
"B4", "\u00B4", "\u017D",
139
"B8", "\u00B8", "\u017E",
140
"BC", "\u00BC", "\u0152",
141
"BD", "\u00BD", "\u0153",
142
"BE", "\u00BE", "\u0178",
143
null,
144
// 923 is IBM's name for ISO 8859-15; make sure they're identical
145
"Cp923", "ISO8859_15_FDIS", null,
146
"Cp858", "Cp850", "D5", "\u0131", "\u20AC", null,
147
"Cp1140", "Cp037", "9F", "\u00A4", "\u20AC", null,
148
"Cp1141", "Cp273", "9F", "\u00A4", "\u20AC", null,
149
"Cp1142", "Cp277", "5A", "\u00A4", "\u20AC", null,
150
"Cp1143", "Cp278", "5A", "\u00A4", "\u20AC", null,
151
"Cp1144", "Cp280", "9F", "\u00A4", "\u20AC", null,
152
"Cp1145", "Cp284", "9F", "\u00A4", "\u20AC", null,
153
"Cp1146", "Cp285", "9F", "\u00A4", "\u20AC", null,
154
"Cp1147", "Cp297", "9F", "\u00A4", "\u20AC", null,
155
"Cp1148", "Cp500", "9F", "\u00A4", "\u20AC", null,
156
"Cp1149", "Cp871", "9F", "\u00A4", "\u20AC", null,
157
};
158
}
159
160