jdk/test/sun/nio/cs/TestSJIS0213.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 44115 bb4e971bf5d4
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
     2
 * Copyright (c) 2008, 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 6529796 6710199
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    26
   @summary Test SJIS/MS932_0213 charsets
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
import java.util.Arrays;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    30
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    31
public class TestSJIS0213 {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    32
    private static String sjisStr = "\u2014\u301C\u2016\u2212\u00A2\u00A3\u00AC";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    33
    private static String winStr = "\u2015\uFF5E\u2225\uFF0D\uFFE0\uFFE1\uFFE2\u2252\u2261\u222B\u2211\u221A\u22A5\u2220\u2235\u2229\u222A";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    34
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    35
    private static String compStr = "\u304B\u309A\u304D\u309A\u304F\u309A\u3051\u309A\u3053\u309A\u30AB\u309A\u30AD\u309A\u30AF\u309A\u30B1\u309A\u30B3\u309A\u30BB\u309A\u30C4\u309A\u30C8\u309A\u31F7\u309A\u00E6\u0300\u0254\u0300\u0254\u0301\u028C\u0300\u028C\u0301\u0259\u0300\u0259\u0301\u025A\u0300\u025A\u0301\u02E9\u02E5\u02E5\u02E9";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    36
    private static byte[] compBytes = new byte[] {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    37
        (byte)0x82, (byte)0xf5,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    38
        (byte)0x82, (byte)0xf6,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    39
        (byte)0x82, (byte)0xf7,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    40
        (byte)0x82, (byte)0xf8,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    41
        (byte)0x82, (byte)0xf9,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    42
        (byte)0x83, (byte)0x97,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    43
        (byte)0x83, (byte)0x98,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    44
        (byte)0x83, (byte)0x99,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    45
        (byte)0x83, (byte)0x9a,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    46
        (byte)0x83, (byte)0x9b,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    47
        (byte)0x83, (byte)0x9c,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    48
        (byte)0x83, (byte)0x9d,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    49
        (byte)0x83, (byte)0x9e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    50
        (byte)0x83, (byte)0xf6,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    51
        (byte)0x86, (byte)0x63,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    52
        (byte)0x86, (byte)0x67,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    53
        (byte)0x86, (byte)0x68,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    54
        (byte)0x86, (byte)0x69,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    55
        (byte)0x86, (byte)0x6a,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    56
        (byte)0x86, (byte)0x6b,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    57
        (byte)0x86, (byte)0x6c,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    58
        (byte)0x86, (byte)0x6d,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    59
        (byte)0x86, (byte)0x6e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    60
        (byte)0x86, (byte)0x85,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    61
        (byte)0x86, (byte)0x86 };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    62
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    63
    private static String mixedStr = "\u002B\u0041\u007a\uff61\uff9f\u3000\u30a1\u4e00\u304B\u309A\u304b";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    64
    private static byte[] mixedBytes = new byte[] {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    65
         (byte)0x2b,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    66
         (byte)0x41, (byte)0x7a,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    67
         (byte)0xa1, (byte)0xdf,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    68
         (byte)0x81, (byte)0x40,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    69
         (byte)0x83, (byte)0x40,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    70
         (byte)0x88, (byte)0xea,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    71
         (byte)0x82, (byte)0xf5,   // composite
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    72
         (byte)0x82, (byte)0xa9 }; // base without cc
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    73
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    74
    //base + base + cc
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    75
    private static String mixedCompStr = "\u304D\u304B\u309A";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    76
    private static byte[] mixedCompBytes = new byte[] {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    77
        (byte)0x82, (byte)0xab, (byte)0x82, (byte)0xf5};
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    78
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    79
    private static char[] unmappableChars = new char[] {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    80
        0x80, 0xfffc, 0xfffd};
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    81
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    82
    private static byte[] unmappableBytes = new byte[] {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    83
        0x3f, 0x3f, 0x3f};
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    84
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    85
    public static void main(String[] args) throws Exception {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    86
        if (!winStr.equals(new String(winStr.getBytes("MS932"), "MS932_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    87
            throw new RuntimeException("MS932_0213 failed on special codepoints!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    88
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    89
        if (!(Arrays.equals(compStr.getBytes("MS932_0213"), compBytes)) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    90
            !compStr.equals(new String(compBytes, "MS932_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    91
            throw new RuntimeException("MS932_0213 failed on composites!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    92
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    93
        if (!(Arrays.equals(mixedStr.getBytes("MS932_0213"), mixedBytes)) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    94
            !mixedStr.equals(new String(mixedBytes, "MS932_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    95
            throw new RuntimeException("MS932_0213 failed on mixed!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    96
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    97
        if (!sjisStr.equals(new String(sjisStr.getBytes("SJIS"), "SJIS_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    98
            throw new RuntimeException("SJIS_0213 failed on special codepoints!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    99
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   100
        if (!(Arrays.equals(compStr.getBytes("SJIS_0213"), compBytes)) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   101
            !compStr.equals(new String(compBytes, "SJIS_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   102
            throw new RuntimeException("SJIS_0213 failed on composites!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   103
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   104
        if (!(Arrays.equals(mixedStr.getBytes("SJIS_0213"), mixedBytes)) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   105
            !mixedStr.equals(new String(mixedBytes, "SJIS_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   106
            throw new RuntimeException("SJIS_0213 failed on mixed!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   107
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   108
        if (!(Arrays.equals(mixedCompStr.getBytes("SJIS_0213"), mixedCompBytes)) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   109
            !mixedCompStr.equals(new String(mixedCompBytes, "SJIS_0213")))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   110
            throw new RuntimeException("SJIS_0213 failed on mixedComp!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   111
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   112
        if (!Arrays.equals(new String(unmappableChars).getBytes("SJIS_0213"), unmappableBytes) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   113
            !Arrays.equals(new String(unmappableChars).getBytes("MS932_0213"), unmappableBytes))
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   114
            throw new RuntimeException("SJIS/MS932_0213 failed on unmappable encoding!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   115
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   116
}