author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 48688 | 08b5eb52ccfd |
permissions | -rw-r--r-- |
796 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
10343
diff
changeset
|
2 |
* Copyright (c) 2008, 2011, 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 |
|
48688
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
25 |
* @bug 6379808 8166339 |
44115
bb4e971bf5d4
8176195: Fix misc module dependencies in jdk_core tests
xiaofeya
parents:
14342
diff
changeset
|
26 |
* @summary Check all Cp933 SBCS characters are not supported in Cp834 |
bb4e971bf5d4
8176195: Fix misc module dependencies in jdk_core tests
xiaofeya
parents:
14342
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 TestCp834_SBCS { |
|
35 |
public static void main(String args[]) throws Exception { |
|
36 |
// The correctness of 1:1 mapping is Coverted by CoderTest.java |
|
37 |
// and TestConv.java, we only need to verify that SBCS characters |
|
38 |
// are not supported by this charset. |
|
39 |
CharsetEncoder enc834 = Charset.forName("Cp834") |
|
40 |
.newEncoder() |
|
41 |
.onUnmappableCharacter(CodingErrorAction.REPLACE) |
|
42 |
.onMalformedInput(CodingErrorAction.REPLACE); |
|
43 |
||
44 |
CharsetDecoder dec834 = Charset.forName("Cp834") |
|
45 |
.newDecoder() |
|
46 |
.onUnmappableCharacter(CodingErrorAction.REPLACE) |
|
47 |
.onMalformedInput(CodingErrorAction.REPLACE); |
|
48 |
||
49 |
CharsetDecoder dec933 = Charset.forName("Cp933") |
|
50 |
.newDecoder() |
|
51 |
.onUnmappableCharacter(CodingErrorAction.REPLACE) |
|
52 |
.onMalformedInput(CodingErrorAction.REPLACE); |
|
53 |
byte[] ba = new byte[1]; |
|
54 |
byte[] ba2 = new byte[2]; |
|
55 |
ByteBuffer dbb = ByteBuffer.allocateDirect(10); |
|
56 |
char[] ca = new char[1]; |
|
57 |
char c; |
|
58 |
for (int i = 0; i <= 0xff; i++) { |
|
59 |
if (i != 0xe && i != 0xf) { // no SI/SO |
|
60 |
ba[0] = (byte)i; |
|
61 |
CharBuffer cb = dec933.decode(ByteBuffer.wrap(ba)); |
|
62 |
if ((c = cb.get()) != '\ufffd') { |
|
63 |
// OK, this is a SBCS character in Cp933 |
|
64 |
if (dec834.decode(ByteBuffer.wrap(ba)).get() != '\ufffd') |
|
48688
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
65 |
throw new RuntimeException("SBCS is supported in IBM834 decoder"); |
796 | 66 |
|
67 |
if (enc834.canEncode(c)) |
|
48688
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
68 |
throw new RuntimeException("SBCS can be encoded in IBM834 encoder"); |
796 | 69 |
|
70 |
ca[0] = c; |
|
71 |
ByteBuffer bb = enc834.encode(CharBuffer.wrap(ca)); |
|
72 |
if (bb.get() != (byte)0xfe || bb.get() != (byte)0xfe) |
|
48688
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
73 |
throw new RuntimeException("SBCS is supported in IBM834 encoder"); |
796 | 74 |
} |
75 |
} |
|
76 |
} |
|
48688
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
77 |
|
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
78 |
// 8166339: cp834 should handle unmappable bytes as dobule-byte pair. |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
79 |
if (! new String("\ufffd".getBytes("cp834"), "cp834").equals("\ufffd")) { |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
80 |
throw new RuntimeException("u+fffd roundtrip failed"); |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
81 |
} |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
82 |
|
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
83 |
if (! new String("a".getBytes("cp834"), "cp834").equals("\ufffd") || |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
84 |
! new String(new byte[] { 0x41, 0x40}, "cp834").equals("\ufffd")) { |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
85 |
throw new RuntimeException("decoding unmappable don't return u+fffd"); |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
86 |
} |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
87 |
|
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
88 |
CoderResult cr = Charset.forName("Cp834").newDecoder().decode( |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
89 |
ByteBuffer.wrap(new byte[] { 0x41, 0x40}), CharBuffer.wrap(new char[2]), true); |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
90 |
if (cr.isError() && cr.length() != 2) { |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
91 |
throw new RuntimeException("decoding unmappable don't return unmmappable(2)"); |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
92 |
} |
08b5eb52ccfd
8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents:
47216
diff
changeset
|
93 |
|
796 | 94 |
} |
95 |
} |