395N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
395N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
395N/A *
395N/A * This code is free software; you can redistribute it and/or modify it
395N/A * under the terms of the GNU General Public License version 2 only, as
395N/A * published by the Free Software Foundation.
395N/A *
395N/A * This code is distributed in the hope that it will be useful, but WITHOUT
395N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
395N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
395N/A * version 2 for more details (a copy is included in the LICENSE file that
395N/A * accompanied this code).
395N/A *
395N/A * You should have received a copy of the GNU General Public License version
395N/A * 2 along with this work; if not, write to the Free Software Foundation,
395N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
395N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
395N/A */
395N/A
395N/A/* @test
395N/A @bug 6379808
395N/A @summary Check all Cp933 SBCS characters are not supported in Cp834
395N/A */
395N/A
395N/Aimport sun.io.*;
395N/Aimport java.io.*;
395N/Aimport java.nio.*;
395N/Aimport java.nio.charset.*;
395N/A
395N/Apublic class TestCp834_SBCS {
395N/A public static void main(String args[]) throws Exception {
395N/A // The correctness of 1:1 mapping is Coverted by CoderTest.java
395N/A // and TestConv.java, we only need to verify that SBCS characters
395N/A // are not supported by this charset.
395N/A CharToByteConverter cb834 = CharToByteConverter.getConverter("Cp834");
395N/A ByteToCharConverter bc834 = ByteToCharConverter.getConverter("Cp834");
395N/A CharsetEncoder enc834 = Charset.forName("Cp834")
395N/A .newEncoder()
395N/A .onUnmappableCharacter(CodingErrorAction.REPLACE)
395N/A .onMalformedInput(CodingErrorAction.REPLACE);
395N/A
395N/A CharsetDecoder dec834 = Charset.forName("Cp834")
395N/A .newDecoder()
395N/A .onUnmappableCharacter(CodingErrorAction.REPLACE)
395N/A .onMalformedInput(CodingErrorAction.REPLACE);
395N/A
395N/A CharsetDecoder dec933 = Charset.forName("Cp933")
395N/A .newDecoder()
395N/A .onUnmappableCharacter(CodingErrorAction.REPLACE)
395N/A .onMalformedInput(CodingErrorAction.REPLACE);
395N/A byte[] ba = new byte[1];
395N/A byte[] ba2 = new byte[2];
395N/A ByteBuffer dbb = ByteBuffer.allocateDirect(10);
395N/A char[] ca = new char[1];
395N/A char c;
395N/A for (int i = 0; i <= 0xff; i++) {
395N/A if (i != 0xe && i != 0xf) { // no SI/SO
395N/A ba[0] = (byte)i;
395N/A CharBuffer cb = dec933.decode(ByteBuffer.wrap(ba));
395N/A if ((c = cb.get()) != '\ufffd') {
395N/A // OK, this is a SBCS character in Cp933
395N/A if (dec834.decode(ByteBuffer.wrap(ba)).get() != '\ufffd')
395N/A throw new Exception("SBCS is supported in IBM834 decoder");
395N/A
395N/A if (enc834.canEncode(c))
395N/A throw new Exception("SBCS can be encoded in IBM834 encoder");
395N/A
395N/A ca[0] = c;
395N/A ByteBuffer bb = enc834.encode(CharBuffer.wrap(ca));
395N/A if (bb.get() != (byte)0xfe || bb.get() != (byte)0xfe)
395N/A throw new Exception("SBCS is supported in IBM834 encoder");
395N/A
395N/A boolean isMalformed = false;
395N/A int ret = 0;
395N/A bc834.reset();
395N/A try {
395N/A ret = bc834.convert(ba, 0, 1, ca, 0, 1);
395N/A } catch (sun.io.MalformedInputException x) { isMalformed = true; }
395N/A if (!isMalformed && ret != 0 && ca[0] != '\ufffd') {
395N/A // three scenarios (1)malformed (2)held as an incomplete
395N/A // input or (3)return replacement all mean "no sbcs"
395N/A throw new Exception("SBCS is supported in Cp834 b2c");
395N/A }
395N/A
395N/A if (cb834.canConvert(c))
395N/A throw new Exception("SBCS can be converted in Cp834 c2b ");
395N/A
395N/A ca[0] = c;
395N/A if (cb834.convert(ca, 0, 1, ba2, 0, 2) != 2 ||
395N/A ba2[0] != (byte)0xfe || ba2[1] != (byte)0xfe) {
395N/A throw new Exception("SBCS is supported in Cp834 c2b");
395N/A }
395N/A }
395N/A }
395N/A }
395N/A }
395N/A}