Path: blob/master/test/jdk/java/nio/charset/RemovingSunIO/TestCOMP.java
41153 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 617681925@summary Check if COMPUND_TEXT charset works as expected26@run main/timeout=1200 TestCOMP27*/2829import java.util.HashMap;30import java.util.Set;31import java.io.UnsupportedEncodingException;32import java.nio.charset.*;33import java.nio.*;3435public class TestCOMP {36public static void main(String[] argv) throws CharacterCodingException {37String osName = System.getProperty("os.name");38if (osName.startsWith("Windows"))39return;40try {41String src =42"JIS0208\u4eb0" +43"ASCII" +44"JIS0212\u4e74\u4e79" +45"GB2312\u7279\u5b9a" +46"JIS0201\uff67\uff68" +47"Johab\uac00\uac01";4849byte[] ba = src.getBytes("COMPOUND_TEXT");50/*51System.out.print("ba=");52for (int i = 0; i < ba.length; i++) {53System.out.printf("<%x> ", ba[i] & 0xff);54}55System.out.println();56*/57String dst = new String(ba, "COMPOUND_TEXT");58char[] ca = dst.toCharArray();59/*60System.out.print("ca=");61for (int i = 0; i < ca.length; i++) {62System.out.printf("<%x> ", ca[i] & 0xffff);63}64System.out.println();65*/66if (!src.equals(dst)) {67System.out.printf("src=<%s>\n", src);68System.out.printf("dst=<%s>\n", dst);69throw new CharacterCodingException();70}71} catch (Exception e){72e.printStackTrace();73}74}75}767778