TestJIS0208Decoder.java revision 395
3867N/A/*
3867N/A * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
3867N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3867N/A *
3867N/A * This code is free software; you can redistribute it and/or modify it
3867N/A * under the terms of the GNU General Public License version 2 only, as
3867N/A * published by the Free Software Foundation.
3867N/A *
3867N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3867N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3867N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3867N/A * version 2 for more details (a copy is included in the LICENSE file that
3867N/A * accompanied this code).
3867N/A *
3867N/A * You should have received a copy of the GNU General Public License version
3867N/A * 2 along with this work; if not, write to the Free Software Foundation,
3867N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3867N/A *
3867N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
3867N/A * CA 95054 USA or visit www.sun.com if you need additional information or
3867N/A * have any questions.
3867N/A */
3867N/A
3867N/A/*
3867N/A * @test
3867N/A * @bug 4179800
3867N/A * @summary Make sure JIS0208.Decoder really works
3867N/A */
3867N/A
3867N/Aimport java.nio.*;
3867N/Aimport java.nio.charset.*;
3867N/A
3867N/Apublic class TestJIS0208Decoder {
3867N/A static String outputString = "\u65e5\u672c\u8a9e\u30c6\u30ad\u30b9\u30c8";
3867N/A static byte [] inputBytes = new byte[] {(byte)'F', (byte)'|', (byte)'K', (byte)'\\',
3867N/A (byte)'8', (byte)'l', (byte)'%', (byte)'F',
3867N/A (byte)'%', (byte)'-', (byte)'%', (byte)'9',
3867N/A (byte)'%', (byte)'H'};
3867N/A
3867N/A public static void main(String args[])
3867N/A throws Exception
3867N/A {
3867N/A test();
3867N/A }
3867N/A
3867N/A private static void test()
3867N/A throws Exception
3867N/A {
3867N/A CharsetDecoder dec = Charset.forName("JIS0208").newDecoder();
3867N/A try {
3867N/A String ret = dec.decode(ByteBuffer.wrap(inputBytes)).toString();
3867N/A if (ret.length() != outputString.length()
3867N/A || ! outputString.equals(ret)){
3867N/A throw new Exception("ByteToCharJIS0208 does not work correctly");
3867N/A }
3867N/A }
3867N/A catch (Exception e){
3867N/A throw new Exception("ByteToCharJIS0208 does not work correctly");
3867N/A }
3867N/A }
3867N/A}
3867N/A