1/*
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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 *
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.
22 */
23
24/* @test
25   @bug 6176819
26   @summary Check if COMPUND_TEXT charset works as expected
27   @run main/timeout=1200 TestCOMP
28 */
29
30import java.util.HashMap;
31import java.util.Set;
32import java.io.UnsupportedEncodingException;
33import java.nio.charset.*;
34import java.nio.*;
35
36public class TestCOMP {
37    public static void main(String[] argv) throws CharacterCodingException {
38        String osName = System.getProperty("os.name");
39        if (osName.startsWith("Windows"))
40            return;
41        try {
42            String src =
43                "JIS0208\u4eb0" +
44                "ASCII" +
45                "JIS0212\u4e74\u4e79" +
46                "GB2312\u7279\u5b9a" +
47                "JIS0201\uff67\uff68" +
48                "Johab\uac00\uac01";
49
50            byte[] ba = src.getBytes("COMPOUND_TEXT");
51            /*
52            System.out.print("ba=");
53            for (int i = 0; i < ba.length; i++) {
54                System.out.printf("<%x> ", ba[i] & 0xff);
55            }
56            System.out.println();
57            */
58            String dst = new String(ba, "COMPOUND_TEXT");
59            char[] ca = dst.toCharArray();
60            /*
61            System.out.print("ca=");
62            for (int i = 0; i < ca.length; i++) {
63                System.out.printf("<%x> ", ca[i] & 0xffff);
64            }
65            System.out.println();
66            */
67            if (!src.equals(dst)) {
68                System.out.printf("src=<%s>\n", src);
69                System.out.printf("dst=<%s>\n", dst);
70                throw new CharacterCodingException();
71            }
72        } catch (Exception e){
73            e.printStackTrace();
74        }
75    }
76}
77