author | jiangli |
Wed, 27 Sep 2017 17:55:20 -0400 | |
changeset 47548 | 664b9d44db74 |
parent 47216 | 71c04702a3d5 |
child 50992 | faf1cd52a5b7 |
permissions | -rw-r--r-- |
796 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21309
diff
changeset
|
2 |
* Copyright (c) 2008, 2013, 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 |
|
44115
bb4e971bf5d4
8176195: Fix misc module dependencies in jdk_core tests
xiaofeya
parents:
23010
diff
changeset
|
25 |
* @bug 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466 |
bb4e971bf5d4
8176195: Fix misc module dependencies in jdk_core tests
xiaofeya
parents:
23010
diff
changeset
|
26 |
* @summary Check if the problems reported in above bugs have been fixed |
bb4e971bf5d4
8176195: Fix misc module dependencies in jdk_core tests
xiaofeya
parents:
23010
diff
changeset
|
27 |
* @modules jdk.charsets |
796 | 28 |
*/ |
29 |
||
30 |
import java.io.*; |
|
31 |
import java.nio.*; |
|
32 |
import java.nio.charset.*; |
|
33 |
||
34 |
public class TestIBMBugs { |
|
35 |
||
36 |
private static void bug6371437() throws Exception { |
|
37 |
CharsetEncoder converter = Charset.forName("Cp933").newEncoder(); |
|
38 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT); |
|
39 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); |
|
40 |
CharBuffer in = CharBuffer.wrap(new char[] { (char)4352 }); |
|
41 |
try { |
|
42 |
ByteBuffer out = converter.encode(in); |
|
43 |
} catch (CharacterCodingException e) { } |
|
44 |
} |
|
45 |
||
46 |
private static void bug6371422() throws Exception { |
|
47 |
String[] charsets = { "Cp949", "Cp949C" }; |
|
48 |
for (int n = 0; n < charsets.length; n++) { |
|
49 |
String charset = charsets[n]; |
|
50 |
CharsetEncoder converter = Charset.forName(charset).newEncoder(); |
|
51 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT); |
|
52 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); |
|
53 |
int errors = 0; |
|
54 |
for (int i = 1; i < 0x1ffff; i++) { |
|
55 |
if (i >= 0x1100 && i <= 0x11f9) |
|
56 |
continue; //Dont try leading consonant, vowel and trailing |
|
57 |
//consonant as a single char |
|
58 |
char[] in = (i < 0x10000 |
|
59 |
? new char[] { (char)i } |
|
60 |
: new char[] { (char)(0xd800 + ((i - 0x10000) >> 10)), |
|
61 |
(char)(0xdc00 + ((i - 0x10000) & 0x3ff)) }); |
|
62 |
||
63 |
try { |
|
64 |
ByteBuffer out = converter.encode(CharBuffer.wrap(in)); |
|
65 |
if (out.remaining() == 0 || |
|
66 |
(out.remaining() == 1 && out.get(0) == 0x00)) { |
|
67 |
errors++; |
|
68 |
} |
|
69 |
} catch (CharacterCodingException e) { } |
|
70 |
} |
|
71 |
if (errors > 0) |
|
72 |
throw new Exception("Charset "+charset+": "+errors+" errors"); |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
private static void bug6371416() throws Exception { |
|
77 |
String[] charsets = { "Cp933", "Cp949", "Cp949C", "Cp970"}; |
|
78 |
for (int n = 0; n < charsets.length; n++) { |
|
79 |
String charset = charsets[n]; |
|
80 |
CharsetEncoder converter = Charset.forName(charset).newEncoder(); |
|
81 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT); |
|
82 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); |
|
83 |
int errors = 0; |
|
84 |
for (int i = 0xd800; i < 0xe000; i++) { |
|
85 |
char[] in = new char[] { (char)i }; |
|
86 |
try { |
|
87 |
ByteBuffer out = converter.encode(CharBuffer.wrap(in)); |
|
88 |
if (out.remaining() == 0) |
|
89 |
errors++; |
|
90 |
} catch (CharacterCodingException e) { } |
|
91 |
} |
|
92 |
if (errors > 0) |
|
93 |
throw new Exception("Charset "+charset+": "+errors+" errors"); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
private static void bug6371619() throws Exception { |
|
98 |
String encoding = "Cp964"; |
|
99 |
Charset charset = Charset.forName(encoding); |
|
100 |
CharsetDecoder converter = charset.newDecoder(); |
|
101 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT); |
|
102 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); |
|
103 |
int errors = 0; |
|
104 |
for (int b = 0x80; b < 0x100; b++) |
|
105 |
if (!(b == 0x8e || // 0x8e is a SS2 |
|
106 |
(b >= 0x80 && b <= 0x8d) || (b >= 0x90 && b <= 0x9f))) { |
|
107 |
ByteBuffer in = ByteBuffer.wrap(new byte[] { (byte)b }); |
|
108 |
try { |
|
109 |
CharBuffer out = converter.decode(in); |
|
110 |
if (out.length() == 0) { |
|
111 |
errors++; |
|
112 |
} |
|
113 |
} catch (CharacterCodingException e) { } |
|
114 |
} |
|
115 |
if (errors > 0) |
|
116 |
throw new Exception("Charset "+charset+": "+errors+" errors"); |
|
117 |
} |
|
118 |
||
119 |
||
120 |
private static void bug6371431() throws Exception { |
|
121 |
String encoding = "Cp33722"; |
|
122 |
Charset charset = Charset.forName(encoding); |
|
123 |
CharsetDecoder converter = charset.newDecoder(); |
|
124 |
converter = converter.onMalformedInput(CodingErrorAction.REPORT); |
|
125 |
converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT); |
|
126 |
int errors = 0; |
|
127 |
for (int b = 0xa0; b < 0x100; b++) { |
|
128 |
ByteBuffer in = ByteBuffer.wrap(new byte[] { (byte)b }); |
|
129 |
try { |
|
130 |
CharBuffer out = converter.decode(in); |
|
131 |
if (out.length() == 0) { |
|
132 |
errors++; |
|
133 |
} |
|
134 |
} catch (CharacterCodingException e) { } |
|
135 |
} |
|
136 |
if (errors > 0) |
|
137 |
throw new Exception("Charset "+charset+": "+errors+" errors"); |
|
138 |
} |
|
139 |
||
2921 | 140 |
private static void bug6639450 () throws Exception { |
141 |
byte[] bytes1 = "\\".getBytes("IBM949"); |
|
142 |
"\\".getBytes("IBM949C"); |
|
143 |
byte[] bytes2 = "\\".getBytes("IBM949"); |
|
144 |
if (bytes1.length != 1 || bytes2.length != 1 || |
|
145 |
bytes1[0] != (byte)0x82 || |
|
146 |
bytes2[0] != (byte)0x82) |
|
147 |
throw new Exception("IBM949/IBM949C failed"); |
|
148 |
} |
|
149 |
||
150 |
private static void bug6569191 () throws Exception { |
|
21309
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
151 |
byte[] bs = new byte[] { (byte)0x81, (byte)0xad, // fffd ff6d |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
152 |
(byte)0x81, (byte)0xae, // fffd ff6e |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
153 |
(byte)0x81, (byte)0xaf, // fffd ff6f |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
154 |
(byte)0x81, (byte)0xb0, // fffd ff70 |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
155 |
(byte)0x85, (byte)0x81, // fffd -> |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
156 |
(byte)0x85, (byte)0x87, // 2266 -> |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
157 |
(byte)0x85, (byte)0xe0, // 32a4 -> |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
158 |
(byte)0x85, (byte)0xf0 };// 7165 fffd |
2921 | 159 |
String s = new String(bs, "Cp943"); |
21309
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
160 |
// see DoubleByte for how the unmappables are handled |
5adf83468a1d
8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
5506
diff
changeset
|
161 |
if (!"\ufffd\uff6d\ufffd\uff6e\ufffd\uff6f\ufffd\uff70\ufffd\u2266\u32a4\u7165\ufffd" |
2921 | 162 |
.equals(s)) |
163 |
throw new Exception("Cp943 failed"); |
|
164 |
} |
|
165 |
||
166 |
||
167 |
private static void bug6577466 () throws Exception { |
|
168 |
for (int c = Character.MIN_VALUE; c <= Character.MAX_VALUE; c++){ |
|
169 |
if (!Character.isDefined((char)c)) continue; |
|
170 |
String s = String.valueOf((char)c); |
|
171 |
byte[] bb = null; |
|
172 |
bb = s.getBytes("x-IBM970"); |
|
173 |
} |
|
174 |
} |
|
175 |
||
796 | 176 |
public static void main (String[] args) throws Exception { |
2921 | 177 |
bug6577466(); |
178 |
// need to be tested before any other IBM949C test case |
|
179 |
bug6639450(); |
|
796 | 180 |
bug6371437(); |
181 |
bug6371422(); |
|
182 |
bug6371416(); |
|
183 |
bug6371619(); |
|
184 |
bug6371431(); |
|
2921 | 185 |
bug6569191(); |
796 | 186 |
} |
187 |
} |