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
|
|
25 |
@bug 6379808
|
|
26 |
@summary Check all Cp933 SBCS characters are not supported in Cp834
|
|
27 |
*/
|
|
28 |
|
|
29 |
import sun.io.*;
|
|
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 |
CharToByteConverter cb834 = CharToByteConverter.getConverter("Cp834");
|
|
40 |
ByteToCharConverter bc834 = ByteToCharConverter.getConverter("Cp834");
|
|
41 |
CharsetEncoder enc834 = Charset.forName("Cp834")
|
|
42 |
.newEncoder()
|
|
43 |
.onUnmappableCharacter(CodingErrorAction.REPLACE)
|
|
44 |
.onMalformedInput(CodingErrorAction.REPLACE);
|
|
45 |
|
|
46 |
CharsetDecoder dec834 = Charset.forName("Cp834")
|
|
47 |
.newDecoder()
|
|
48 |
.onUnmappableCharacter(CodingErrorAction.REPLACE)
|
|
49 |
.onMalformedInput(CodingErrorAction.REPLACE);
|
|
50 |
|
|
51 |
CharsetDecoder dec933 = Charset.forName("Cp933")
|
|
52 |
.newDecoder()
|
|
53 |
.onUnmappableCharacter(CodingErrorAction.REPLACE)
|
|
54 |
.onMalformedInput(CodingErrorAction.REPLACE);
|
|
55 |
byte[] ba = new byte[1];
|
|
56 |
byte[] ba2 = new byte[2];
|
|
57 |
ByteBuffer dbb = ByteBuffer.allocateDirect(10);
|
|
58 |
char[] ca = new char[1];
|
|
59 |
char c;
|
|
60 |
for (int i = 0; i <= 0xff; i++) {
|
|
61 |
if (i != 0xe && i != 0xf) { // no SI/SO
|
|
62 |
ba[0] = (byte)i;
|
|
63 |
CharBuffer cb = dec933.decode(ByteBuffer.wrap(ba));
|
|
64 |
if ((c = cb.get()) != '\ufffd') {
|
|
65 |
// OK, this is a SBCS character in Cp933
|
|
66 |
if (dec834.decode(ByteBuffer.wrap(ba)).get() != '\ufffd')
|
|
67 |
throw new Exception("SBCS is supported in IBM834 decoder");
|
|
68 |
|
|
69 |
if (enc834.canEncode(c))
|
|
70 |
throw new Exception("SBCS can be encoded in IBM834 encoder");
|
|
71 |
|
|
72 |
ca[0] = c;
|
|
73 |
ByteBuffer bb = enc834.encode(CharBuffer.wrap(ca));
|
|
74 |
if (bb.get() != (byte)0xfe || bb.get() != (byte)0xfe)
|
|
75 |
throw new Exception("SBCS is supported in IBM834 encoder");
|
|
76 |
|
|
77 |
boolean isMalformed = false;
|
|
78 |
int ret = 0;
|
|
79 |
bc834.reset();
|
|
80 |
try {
|
|
81 |
ret = bc834.convert(ba, 0, 1, ca, 0, 1);
|
|
82 |
} catch (sun.io.MalformedInputException x) { isMalformed = true; }
|
|
83 |
if (!isMalformed && ret != 0 && ca[0] != '\ufffd') {
|
|
84 |
// three scenarios (1)malformed (2)held as an incomplete
|
|
85 |
// input or (3)return replacement all mean "no sbcs"
|
|
86 |
throw new Exception("SBCS is supported in Cp834 b2c");
|
|
87 |
}
|
|
88 |
|
|
89 |
if (cb834.canConvert(c))
|
|
90 |
throw new Exception("SBCS can be converted in Cp834 c2b ");
|
|
91 |
|
|
92 |
ca[0] = c;
|
|
93 |
if (cb834.convert(ca, 0, 1, ba2, 0, 2) != 2 ||
|
|
94 |
ba2[0] != (byte)0xfe || ba2[1] != (byte)0xfe) {
|
|
95 |
throw new Exception("SBCS is supported in Cp834 c2b");
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
}
|
|
101 |
}
|