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
1245N/A @bug 6371437 6371422 6371416 6371619 5058184 6371431 6639450 6569191 6577466
395N/A @summary Check if the problems reported in above bugs have been fixed
395N/A */
395N/A
395N/Aimport java.io.*;
395N/Aimport java.nio.*;
395N/Aimport java.nio.charset.*;
395N/A
395N/Apublic class TestIBMBugs {
395N/A
395N/A private static void bug6371437() throws Exception {
395N/A CharsetEncoder converter = Charset.forName("Cp933").newEncoder();
395N/A converter = converter.onMalformedInput(CodingErrorAction.REPORT);
395N/A converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
395N/A CharBuffer in = CharBuffer.wrap(new char[] { (char)4352 });
395N/A try {
395N/A ByteBuffer out = converter.encode(in);
395N/A } catch (CharacterCodingException e) { }
395N/A }
395N/A
395N/A private static void bug6371422() throws Exception {
395N/A String[] charsets = { "Cp949", "Cp949C" };
395N/A for (int n = 0; n < charsets.length; n++) {
395N/A String charset = charsets[n];
395N/A CharsetEncoder converter = Charset.forName(charset).newEncoder();
395N/A converter = converter.onMalformedInput(CodingErrorAction.REPORT);
395N/A converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
395N/A int errors = 0;
395N/A for (int i = 1; i < 0x1ffff; i++) {
395N/A if (i >= 0x1100 && i <= 0x11f9)
395N/A continue; //Dont try leading consonant, vowel and trailing
395N/A //consonant as a single char
395N/A char[] in = (i < 0x10000
395N/A ? new char[] { (char)i }
395N/A : new char[] { (char)(0xd800 + ((i - 0x10000) >> 10)),
395N/A (char)(0xdc00 + ((i - 0x10000) & 0x3ff)) });
395N/A
395N/A try {
395N/A ByteBuffer out = converter.encode(CharBuffer.wrap(in));
395N/A if (out.remaining() == 0 ||
395N/A (out.remaining() == 1 && out.get(0) == 0x00)) {
395N/A errors++;
395N/A }
395N/A } catch (CharacterCodingException e) { }
395N/A }
395N/A if (errors > 0)
395N/A throw new Exception("Charset "+charset+": "+errors+" errors");
395N/A }
395N/A }
395N/A
395N/A private static void bug6371416() throws Exception {
395N/A String[] charsets = { "Cp933", "Cp949", "Cp949C", "Cp970"};
395N/A for (int n = 0; n < charsets.length; n++) {
395N/A String charset = charsets[n];
395N/A CharsetEncoder converter = Charset.forName(charset).newEncoder();
395N/A converter = converter.onMalformedInput(CodingErrorAction.REPORT);
395N/A converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
395N/A int errors = 0;
395N/A for (int i = 0xd800; i < 0xe000; i++) {
395N/A char[] in = new char[] { (char)i };
395N/A try {
395N/A ByteBuffer out = converter.encode(CharBuffer.wrap(in));
395N/A if (out.remaining() == 0)
395N/A errors++;
395N/A } catch (CharacterCodingException e) { }
395N/A }
395N/A if (errors > 0)
395N/A throw new Exception("Charset "+charset+": "+errors+" errors");
395N/A }
395N/A }
395N/A
395N/A private static void bug6371619() throws Exception {
395N/A String encoding = "Cp964";
395N/A Charset charset = Charset.forName(encoding);
395N/A CharsetDecoder converter = charset.newDecoder();
395N/A converter = converter.onMalformedInput(CodingErrorAction.REPORT);
395N/A converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
395N/A int errors = 0;
395N/A for (int b = 0x80; b < 0x100; b++)
395N/A if (!(b == 0x8e || // 0x8e is a SS2
395N/A (b >= 0x80 && b <= 0x8d) || (b >= 0x90 && b <= 0x9f))) {
395N/A ByteBuffer in = ByteBuffer.wrap(new byte[] { (byte)b });
395N/A try {
395N/A CharBuffer out = converter.decode(in);
395N/A if (out.length() == 0) {
395N/A errors++;
395N/A }
395N/A } catch (CharacterCodingException e) { }
395N/A }
395N/A if (errors > 0)
395N/A throw new Exception("Charset "+charset+": "+errors+" errors");
395N/A }
395N/A
395N/A
395N/A private static void bug6371431() throws Exception {
395N/A String encoding = "Cp33722";
395N/A Charset charset = Charset.forName(encoding);
395N/A CharsetDecoder converter = charset.newDecoder();
395N/A converter = converter.onMalformedInput(CodingErrorAction.REPORT);
395N/A converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
395N/A int errors = 0;
395N/A for (int b = 0xa0; b < 0x100; b++) {
395N/A ByteBuffer in = ByteBuffer.wrap(new byte[] { (byte)b });
395N/A try {
395N/A CharBuffer out = converter.decode(in);
395N/A if (out.length() == 0) {
395N/A errors++;
395N/A }
395N/A } catch (CharacterCodingException e) { }
395N/A }
395N/A if (errors > 0)
395N/A throw new Exception("Charset "+charset+": "+errors+" errors");
395N/A }
395N/A
1245N/A private static void bug6639450 () throws Exception {
1245N/A byte[] bytes1 = "\\".getBytes("IBM949");
1245N/A "\\".getBytes("IBM949C");
1245N/A byte[] bytes2 = "\\".getBytes("IBM949");
1245N/A if (bytes1.length != 1 || bytes2.length != 1 ||
1245N/A bytes1[0] != (byte)0x82 ||
1245N/A bytes2[0] != (byte)0x82)
1245N/A throw new Exception("IBM949/IBM949C failed");
1245N/A }
1245N/A
1245N/A private static void bug6569191 () throws Exception {
1245N/A byte[] bs = new byte[] { (byte)0x81, (byte)0xad,
1245N/A (byte)0x81, (byte)0xae,
1245N/A (byte)0x81, (byte)0xaf,
1245N/A (byte)0x81, (byte)0xb0,
1245N/A (byte)0x85, (byte)0x81,
1245N/A (byte)0x85, (byte)0x87,
1245N/A (byte)0x85, (byte)0xe0,
1245N/A (byte)0x85, (byte)0xf0 };
1245N/A String s = new String(bs, "Cp943");
1245N/A if (!"\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd"
1245N/A .equals(s))
1245N/A throw new Exception("Cp943 failed");
1245N/A }
1245N/A
1245N/A
1245N/A private static void bug6577466 () throws Exception {
1245N/A for (int c = Character.MIN_VALUE; c <= Character.MAX_VALUE; c++){
1245N/A if (!Character.isDefined((char)c)) continue;
1245N/A String s = String.valueOf((char)c);
1245N/A byte[] bb = null;
1245N/A bb = s.getBytes("x-IBM970");
1245N/A }
1245N/A }
1245N/A
395N/A public static void main (String[] args) throws Exception {
1245N/A bug6577466();
1245N/A // need to be tested before any other IBM949C test case
1245N/A bug6639450();
395N/A bug6371437();
395N/A bug6371422();
395N/A bug6371416();
395N/A bug6371619();
395N/A bug6371431();
1245N/A bug6569191();
395N/A }
395N/A}