jdk/test/sun/nio/cs/TestX11JIS0201.java
author cl
Thu, 25 Jul 2013 03:18:14 -0700
changeset 18968 de18c7eb70e2
parent 14342 8435a30053c1
permissions -rw-r--r--
Added tag jdk8-b100 for changeset e7387def0ed3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13366
diff changeset
     2
 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     4
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     8
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    13
 * accompanied this code).
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    14
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
    21
 * questions.
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    22
 */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    23
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    24
/* @test
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    25
 * @bug 4195325
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    26
 * @summary name() should return "X11JIS0201"
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    27
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    28
 */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    29
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    30
import java.nio.charset.*;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    31
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    32
public class TestX11JIS0201 {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    33
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    34
    public static void main(String args[])
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    35
        throws Exception
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    36
    {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    37
        test();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    38
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    39
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    40
    private static void test()
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    41
        throws Exception
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    42
    {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    43
        Class cl = null;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    44
        try {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    45
            cl = Class.forName("sun.awt.motif.X11JIS0201");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    46
        } catch (Exception e){
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    47
            return;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    48
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    49
        Charset cs = (Charset)cl.newInstance();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    50
        if (! cs.name().equals("X11JIS0201")){
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    51
            throw new Exception("X11JIS0201 does not work correctly");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    52
        }
13366
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    53
        CharsetEncoder enc = cs.newEncoder();
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    54
        char[] cc = new char[0xffff];
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    55
        for (char c = 0; c < 0xffff; c++) {
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    56
            cc[c] = c;
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    57
            if (enc.canEncode(c) !=
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    58
                ((c >= 0xff61 && c <= 0xff9f) || c == 0x203e || c == 0xa5)) {
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    59
                throw new RuntimeException("x11jis0201 canEncod() failed!");
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    60
            }
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    61
        }
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    62
        String s = new String(cc);
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    63
        byte[] bb_x11 = s.getBytes(cs);
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    64
        byte[] bb = s.getBytes("jis0201");
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    65
        if (!java.util.Arrays.equals(bb, bb_x11)) {
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    66
            throw new RuntimeException("x11jis0201 encoding failed");
2f5fdf6d8c22 6653797: Reimplement JDK charset repository charsets.jar
sherman
parents: 5506
diff changeset
    67
        }
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    68
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    69
}