796
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
796
|
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 |
*
|
5506
|
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.
|
796
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
2921
|
25 |
@bug 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466
|
796
|
26 |
@summary Check if the problems reported in above bugs have been fixed
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.io.*;
|
|
30 |
import java.nio.*;
|
|
31 |
import java.nio.charset.*;
|
|
32 |
|
|
33 |
public class TestIBMBugs {
|
|
34 |
|
|
35 |
private static void bug6371437() throws Exception {
|
|
36 |
CharsetEncoder converter = Charset.forName("Cp933").newEncoder();
|
|
37 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT);
|
|
38 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
|
|
39 |
CharBuffer in = CharBuffer.wrap(new char[] { (char)4352 });
|
|
40 |
try {
|
|
41 |
ByteBuffer out = converter.encode(in);
|
|
42 |
} catch (CharacterCodingException e) { }
|
|
43 |
}
|
|
44 |
|
|
45 |
private static void bug6371422() throws Exception {
|
|
46 |
String[] charsets = { "Cp949", "Cp949C" };
|
|
47 |
for (int n = 0; n < charsets.length; n++) {
|
|
48 |
String charset = charsets[n];
|
|
49 |
CharsetEncoder converter = Charset.forName(charset).newEncoder();
|
|
50 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT);
|
|
51 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
|
|
52 |
int errors = 0;
|
|
53 |
for (int i = 1; i < 0x1ffff; i++) {
|
|
54 |
if (i >= 0x1100 && i <= 0x11f9)
|
|
55 |
continue; //Dont try leading consonant, vowel and trailing
|
|
56 |
//consonant as a single char
|
|
57 |
char[] in = (i < 0x10000
|
|
58 |
? new char[] { (char)i }
|
|
59 |
: new char[] { (char)(0xd800 + ((i - 0x10000) >> 10)),
|
|
60 |
(char)(0xdc00 + ((i - 0x10000) & 0x3ff)) });
|
|
61 |
|
|
62 |
try {
|
|
63 |
ByteBuffer out = converter.encode(CharBuffer.wrap(in));
|
|
64 |
if (out.remaining() == 0 ||
|
|
65 |
(out.remaining() == 1 && out.get(0) == 0x00)) {
|
|
66 |
errors++;
|
|
67 |
}
|
|
68 |
} catch (CharacterCodingException e) { }
|
|
69 |
}
|
|
70 |
if (errors > 0)
|
|
71 |
throw new Exception("Charset "+charset+": "+errors+" errors");
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
private static void bug6371416() throws Exception {
|
|
76 |
String[] charsets = { "Cp933", "Cp949", "Cp949C", "Cp970"};
|
|
77 |
for (int n = 0; n < charsets.length; n++) {
|
|
78 |
String charset = charsets[n];
|
|
79 |
CharsetEncoder converter = Charset.forName(charset).newEncoder();
|
|
80 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT);
|
|
81 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
|
|
82 |
int errors = 0;
|
|
83 |
for (int i = 0xd800; i < 0xe000; i++) {
|
|
84 |
char[] in = new char[] { (char)i };
|
|
85 |
try {
|
|
86 |
ByteBuffer out = converter.encode(CharBuffer.wrap(in));
|
|
87 |
if (out.remaining() == 0)
|
|
88 |
errors++;
|
|
89 |
} catch (CharacterCodingException e) { }
|
|
90 |
}
|
|
91 |
if (errors > 0)
|
|
92 |
throw new Exception("Charset "+charset+": "+errors+" errors");
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
private static void bug6371619() throws Exception {
|
|
97 |
String encoding = "Cp964";
|
|
98 |
Charset charset = Charset.forName(encoding);
|
|
99 |
CharsetDecoder converter = charset.newDecoder();
|
|
100 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT);
|
|
101 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
|
|
102 |
int errors = 0;
|
|
103 |
for (int b = 0x80; b < 0x100; b++)
|
|
104 |
if (!(b == 0x8e || // 0x8e is a SS2
|
|
105 |
(b >= 0x80 && b <= 0x8d) || (b >= 0x90 && b <= 0x9f))) {
|
|
106 |
ByteBuffer in = ByteBuffer.wrap(new byte[] { (byte)b });
|
|
107 |
try {
|
|
108 |
CharBuffer out = converter.decode(in);
|
|
109 |
if (out.length() == 0) {
|
|
110 |
errors++;
|
|
111 |
}
|
|
112 |
} catch (CharacterCodingException e) { }
|
|
113 |
}
|
|
114 |
if (errors > 0)
|
|
115 |
throw new Exception("Charset "+charset+": "+errors+" errors");
|
|
116 |
}
|
|
117 |
|
|
118 |
|
|
119 |
private static void bug6371431() throws Exception {
|
|
120 |
String encoding = "Cp33722";
|
|
121 |
Charset charset = Charset.forName(encoding);
|
|
122 |
CharsetDecoder converter = charset.newDecoder();
|
|
123 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT);
|
|
124 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
|
|
125 |
int errors = 0;
|
|
126 |
for (int b = 0xa0; b < 0x100; b++) {
|
|
127 |
ByteBuffer in = ByteBuffer.wrap(new byte[] { (byte)b });
|
|
128 |
try {
|
|
129 |
CharBuffer out = converter.decode(in);
|
|
130 |
if (out.length() == 0) {
|
|
131 |
errors++;
|
|
132 |
}
|
|
133 |
} catch (CharacterCodingException e) { }
|
|
134 |
}
|
|
135 |
if (errors > 0)
|
|
136 |
throw new Exception("Charset "+charset+": "+errors+" errors");
|
|
137 |
}
|
|
138 |
|
2921
|
139 |
private static void bug6639450 () throws Exception {
|
|
140 |
byte[] bytes1 = "\\".getBytes("IBM949");
|
|
141 |
"\\".getBytes("IBM949C");
|
|
142 |
byte[] bytes2 = "\\".getBytes("IBM949");
|
|
143 |
if (bytes1.length != 1 || bytes2.length != 1 ||
|
|
144 |
bytes1[0] != (byte)0x82 ||
|
|
145 |
bytes2[0] != (byte)0x82)
|
|
146 |
throw new Exception("IBM949/IBM949C failed");
|
|
147 |
}
|
|
148 |
|
|
149 |
private static void bug6569191 () throws Exception {
|
|
150 |
byte[] bs = new byte[] { (byte)0x81, (byte)0xad,
|
|
151 |
(byte)0x81, (byte)0xae,
|
|
152 |
(byte)0x81, (byte)0xaf,
|
|
153 |
(byte)0x81, (byte)0xb0,
|
|
154 |
(byte)0x85, (byte)0x81,
|
|
155 |
(byte)0x85, (byte)0x87,
|
|
156 |
(byte)0x85, (byte)0xe0,
|
|
157 |
(byte)0x85, (byte)0xf0 };
|
|
158 |
String s = new String(bs, "Cp943");
|
|
159 |
if (!"\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
|
|
160 |
.equals(s))
|
|
161 |
throw new Exception("Cp943 failed");
|
|
162 |
}
|
|
163 |
|
|
164 |
|
|
165 |
private static void bug6577466 () throws Exception {
|
|
166 |
for (int c = Character.MIN_VALUE; c <= Character.MAX_VALUE; c++){
|
|
167 |
if (!Character.isDefined((char)c)) continue;
|
|
168 |
String s = String.valueOf((char)c);
|
|
169 |
byte[] bb = null;
|
|
170 |
bb = s.getBytes("x-IBM970");
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
796
|
174 |
public static void main (String[] args) throws Exception {
|
2921
|
175 |
bug6577466();
|
|
176 |
// need to be tested before any other IBM949C test case
|
|
177 |
bug6639450();
|
796
|
178 |
bug6371437();
|
|
179 |
bug6371422();
|
|
180 |
bug6371416();
|
|
181 |
bug6371619();
|
|
182 |
bug6371431();
|
2921
|
183 |
bug6569191();
|
796
|
184 |
}
|
|
185 |
}
|