jdk/test/sun/nio/cs/TestISO2022CNDecoder.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: 2913
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: 2913
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2913
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2913
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
2913
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
    25
   @bug 4779029 4924625 6392664 6730652
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    26
   @summary Test decoding of various permutations of valid ISO-2022-CN byte sequences
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
 * Regression test for NIO ISO-2022-CN decoder. Passes various valid
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    31
 * ISO-2022-CN byte sequences to the decoder using the java.io
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    32
 * InputStreamReader API
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    33
 */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    34
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    35
import java.io.*;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    36
import java.nio.*;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    37
import java.nio.charset.*;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    38
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    39
public class TestISO2022CNDecoder
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    40
{
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    41
    private static String encodingName = "ISO2022CN";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    42
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    43
    //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    44
    // Positive tests -- test both output and input processing against
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    45
    // various "known good" data
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    46
    //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    47
    private static boolean decodeTest (
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    48
        byte encoded[],
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    49
        char decoded[],
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    50
        String label)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    51
    {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    52
        boolean retval = true;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    53
        int i = 0;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    54
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    55
        try {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    56
            //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    57
            // Ensure that reading decodes correctly
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    58
            //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    59
            ByteArrayInputStream in;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    60
            InputStreamReader reader;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    61
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    62
            in = new ByteArrayInputStream(encoded);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    63
            reader = new InputStreamReader(in, encodingName);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    64
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    65
            for (i = 0; i < decoded.length; i++) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    66
                int c = reader.read();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    67
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    68
                if (c != decoded[i]) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    69
                    System.err.print(label + ": read failed, char " + i);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    70
                    System.err.print(" ... expected 0x"
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    71
                            + Integer.toHexString(decoded[i]));
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    72
                    if (c == -1)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    73
                        System.err.println(", got EOF");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    74
                    else
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    75
                        System.err.println(", got 0x"
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    76
                            + Integer.toHexString(c));
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    77
                    retval = false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    78
                    if (c == -1)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    79
                        return retval;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    80
                }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    81
            }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    82
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    83
            int testChar;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    84
            if ((testChar = reader.read()) != -1) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    85
                System.err.println(label + ": read failed, no EOF");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    86
                System.err.println("testChar is " +
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    87
                        Integer.toHexString((int)testChar));
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    88
                return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    89
            }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    90
            String decodedString = new String(encoded, "ISO2022CN");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    91
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    92
            for (i = 0; i < decodedString.length(); i++) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    93
                if (decodedString.charAt(i) != decoded[i])
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    94
                    System.err.println(label + ": read failed, char " + i);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    95
            }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    96
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    97
            CharsetDecoder dec = Charset.forName("ISO2022CN")
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    98
                .newDecoder()
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    99
                .onUnmappableCharacter(CodingErrorAction.REPLACE)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   100
                .onMalformedInput(CodingErrorAction.REPLACE);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   101
            ByteBuffer bb = ByteBuffer.allocateDirect(encoded.length).put(encoded);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   102
            bb.flip();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   103
            CharBuffer cb = ByteBuffer.allocateDirect(2*encoded.length*(int)dec.maxCharsPerByte())
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   104
                                      .asCharBuffer();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   105
            if (bb.hasArray() || cb.hasArray()) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   106
                System.err.println(label + ": directBuffer failed, ");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   107
                return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   108
            }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   109
            if (!dec.decode(bb, cb, true).isUnderflow()) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   110
                System.err.println(label + ": decoder's decode() failed!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   111
                return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   112
            }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   113
            cb.flip();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   114
            for (i = 0; i < cb.limit(); i++) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   115
                if (cb.get() != decoded[i])
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   116
                    System.err.println(label + ": decoder failed, char " + i);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   117
            }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   118
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   119
        } catch (Exception e) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   120
            System.err.println(label + ": failed "
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   121
                + "(i = " + i + "), "
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   122
                + e.getClass().getName()
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   123
                + ", " + e.getMessage());
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   124
            e.printStackTrace();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   125
            return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   126
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   127
        return retval;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   128
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   129
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   130
    private static boolean equal(CoderResult a, CoderResult b) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   131
        return (a == CoderResult.OVERFLOW && b == CoderResult.OVERFLOW) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   132
            (a == CoderResult.UNDERFLOW && b == CoderResult.UNDERFLOW) ||
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   133
            ((a.isError() == b.isError()) &&
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   134
             (a.isMalformed() == b.isMalformed()) &&
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   135
             (a.isUnmappable() == b.isUnmappable()) &&
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   136
             (a.length() == b.length()));
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   137
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   138
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   139
    private static boolean decodeResultTest (byte encoded[],
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   140
                                             CoderResult expected,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   141
                                             String label) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   142
        CharsetDecoder dec = Charset.forName("ISO2022CN").newDecoder();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   143
        ByteBuffer bb = ByteBuffer.wrap(encoded);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   144
        CharBuffer cb = CharBuffer.allocate(encoded.length*(int)dec.maxCharsPerByte());
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   145
        CoderResult result = dec.decode(bb, cb, true);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   146
        if (!equal(result, expected)) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   147
            System.err.println(label + ": decoder's decode() failed!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   148
            return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   149
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   150
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   151
        bb = ByteBuffer.allocateDirect(encoded.length).put(encoded);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   152
        bb.flip();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   153
        cb = ByteBuffer.allocateDirect(2*encoded.length*(int)dec.maxCharsPerByte())
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   154
            .asCharBuffer();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   155
        if (bb.hasArray() || cb.hasArray()) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   156
            System.err.println(label + ": directBuffer failed, ");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   157
            return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   158
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   159
        result = dec.reset().decode(bb, cb, true);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   160
        if (!equal(result, expected)) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   161
            System.err.println(label + ": decoder's decode() - direct failed!");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   162
            return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   163
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   164
        return true;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   165
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   166
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   167
    //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   168
    // Negative tests -- only for input processing, make sure that
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   169
    // invalid or corrupt characters are rejected.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   170
    //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   171
    private static boolean negative (byte encoded [], String label)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   172
    {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   173
        try {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   174
            ByteArrayInputStream in;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   175
            InputStreamReader reader;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   176
            int c;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   177
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   178
            in = new ByteArrayInputStream(encoded);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   179
            reader = new InputStreamReader(in, encodingName);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   180
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   181
            c = reader.read();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   182
            System.err.print (label + ": read failed, ");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   183
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   184
            if (c == -1)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   185
                System.err.println("reported EOF");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   186
            else
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   187
                System.err.println("returned char 0x"
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   188
                    + Integer.toHexString(c)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   189
                    + ", expected exception");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   190
            return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   191
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   192
        } catch (CharConversionException e) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   193
            return true;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   194
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   195
        } catch (Throwable t) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   196
            System.err.println(label + ": failed, threw "
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   197
                + t.getClass().getName()
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   198
                + ", " + t.getMessage());
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   199
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   200
        return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   201
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   202
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   203
    private static boolean decodeTest6392664 () {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   204
        try {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   205
            CharsetDecoder dec = Charset.forName("ISO-2022-CN-GB").newDecoder();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   206
            dec.decode(ByteBuffer.wrap(new byte[] {(byte)0x0e, (byte)0x42, (byte)0x43 }));
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   207
        } catch (Exception e) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   208
            e.printStackTrace();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   209
            return false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   210
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   211
        return true;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   212
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   213
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   214
    //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   215
    // TEST #0: 7-bit unshifted values,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   216
    // shift-in of a valid decodable GB2312-80
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   217
    // character and an unmappable GB2312-80 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   218
    // This is a positive test.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   219
    //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   220
    private static byte test0_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   221
        (byte)0x00,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   222
        (byte)0x01, (byte)0x02, (byte)0x03,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   223
        (byte)0x0E, (byte)0x21, (byte)0x2f,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   224
        (byte)0x0E, (byte)0xDD, (byte)0x9f
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   225
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   226
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   227
    private static char test0_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   228
        0x0000,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   229
        0x0001, 0x0002, 0x0003,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   230
        0x2019,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   231
        0xFFFD
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   232
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   233
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   234
    private static byte test1_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   235
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41, (byte)0x21,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   236
        (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   237
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   238
    private static char test1_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   239
        0x21, 0x2f
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   240
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   241
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   242
    private static byte test2_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   243
        (byte)0x0e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   244
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   245
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   246
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   247
    private static char test2_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   248
        0x2019
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   249
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   250
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   251
    private static byte test3_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   252
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   253
        (byte)0x0e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   254
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   255
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   256
    private static byte test3a_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   257
        (byte)0x1b, (byte)0x24, (byte)0x41,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   258
        (byte)0x0e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   259
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   260
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   261
    private static char test3_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   262
        0x2019
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   263
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   264
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   265
    private static byte test4_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   266
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   267
        (byte)0x0f,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   268
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   269
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   270
    private static char test4_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   271
        0x21, 0x2f
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   272
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   273
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   274
    private static byte test5_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   275
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   276
        (byte)0x0e, (byte)0x21, (byte)0x2e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   277
        (byte)0x0f, (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   278
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   279
    private static char test5_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   280
        0x2018, 0x21, 0x2f
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   281
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   282
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   283
    private static byte test6_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   284
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   285
        (byte)0x0e, (byte)0x21, (byte)0x2e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   286
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   287
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   288
    private static char test6_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   289
        0x2018, 0x2019
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   290
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   291
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   292
    private static byte test7_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   293
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)'G',
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   294
        (byte)0x0e, (byte)0x21, (byte)0x2e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   295
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   296
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   297
    private static char test7_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   298
        0xFE50, 0xFE51
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   299
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   300
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   301
    private static byte test8_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   302
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)'G',
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   303
        (byte)0x0e, (byte)0x21, (byte)0x2e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   304
        (byte)0x0f, (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   305
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   306
    private static char test8_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   307
        0xFE50, 0x21, 0x2f
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   308
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   309
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   310
    private static byte test9_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   311
        (byte)0x1b, (byte)0x24, (byte)0x2a, (byte)'H',
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   312
        (byte)0x1b, (byte)0x4e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   313
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   314
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   315
    private static char test9_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   316
        0x4e0e
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   317
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   318
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   319
    /*
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   320
     * Plane 3 support provided for compatibility with
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   321
     * sun.io ISO2022_CN decoder. Officially ISO-2022-CN
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   322
     * just handles planes 1/2 of CNS-11643 (1986)
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   323
     * Test case data below verifies this compatibility
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   324
     *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   325
     */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   326
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   327
    private static byte test10_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   328
        (byte)0x1b, (byte)0x24, (byte)'+', (byte)'I',
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   329
        (byte)0x1b, (byte)0x4f,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   330
        (byte)0x21, (byte)0x2f };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   331
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   332
    private static char test10_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   333
        0x51e2
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   334
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   335
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   336
    private static byte test11_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   337
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41, //SO Designator
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   338
        (byte)0x0e,                                     //SO
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   339
        (byte)0x21, (byte)0x2e,                         //GB2312 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   340
        (byte)0x1b, (byte)0x24, (byte)0x2a, (byte)'H',  //SS2 Designator
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   341
        (byte)0x1b, (byte)0x4e,                         //SS2
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   342
        (byte)0x21, (byte)0x2f,                         //CNS-P2 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   343
        (byte)0x21, (byte)0x2f                          //GB2312 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   344
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   345
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   346
    private static char test11_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   347
        0x2018,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   348
        0x4e0e,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   349
        0x2019
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   350
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   351
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   352
    private static byte test12_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   353
        (byte)0x1b, (byte)0x24, (byte)0x29, (byte)0x41, //SO Designator
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   354
        (byte)0x0e,                                     //SO
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   355
        (byte)0x21, (byte)0x2e,                         //GB2312 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   356
        (byte)0x1b, (byte)0x24, (byte)'+', (byte)'I',  //SS3 Designator
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   357
        (byte)0x1b, (byte)0x4f,                         //SS3
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   358
        (byte)0x21, (byte)0x2f,                         //CNS-P2 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   359
        (byte)0x21, (byte)0x2f                          //GB2312 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   360
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   361
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   362
    private static char test12_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   363
        0x2018,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   364
        0x51e2,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   365
        0x2019
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   366
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   367
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   368
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   369
    private static byte test13_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   370
        (byte)0x0f0,   // byte with MSB
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   371
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   372
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   373
    private static char test13_chars[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   374
        0x00f0,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   375
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   376
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   377
    private static byte test14_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   378
        (byte)0x0E, (byte)0x21, (byte)0x2f,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   379
        (byte)0x0E, (byte)0xDD, (byte)0x9f
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   380
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   381
    private static CoderResult test14_result = CoderResult.unmappableForLength(2);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   382
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   383
    // Current ISO2022CN treats the "out of range" code points as "unmappable"
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   384
    private static byte test15_bytes[] = {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   385
        (byte)0x1b, (byte)0x4f,      // SS3
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   386
        (byte)0x20, (byte)0x2f,      // "out of range" CNS-P2 char
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   387
    };
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   388
    private static  CoderResult test15_result = CoderResult.unmappableForLength(4);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   389
2913
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   390
    private static boolean encodeTest6730652 () throws Exception {
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   391
        //sample p3 codepoints
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   392
        String strCNSP3 = "\u4e28\u4e36\u4e3f\u4e85\u4e05\u4e04\u5369\u53b6\u4e2a\u4e87\u4e49\u51e2\u56b8\u56b9\u56c4\u8053\u92b0";
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   393
        return strCNSP3.equals(new String(strCNSP3.getBytes("x-ISO-2022-CN-CNS"), "x-ISO-2022-CN-CNS"));
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   394
    }
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   395
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   396
    /**
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   397
     * Main program to test ISO2022CN conformance
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   398
     *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   399
     */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   400
    public static void main (String argv []) throws Exception
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   401
    {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   402
        boolean pass = true;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   403
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   404
        System.out.println ("");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   405
        System.out.println ("------ checking ISO2022CN decoder -----");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   406
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   407
        // This regtest must be the first one.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   408
        pass &= decodeTest6392664();
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   409
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   410
        try {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   411
            new InputStreamReader (System.in, "ISO2022CN");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   412
        } catch (Exception e) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   413
            encodingName = "ISO2022CN";
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   414
            System.out.println ("... requires nonstandard encoding name "
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   415
                    + encodingName);
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   416
            pass &= false;
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   417
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   418
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   419
        //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   420
        // Positive tests -- good data is dealt with correctly
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   421
        //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   422
        pass &= decodeTest(test0_bytes, test0_chars, "first batch");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   423
        pass &= decodeTest(test1_bytes, test1_chars, "escapes1");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   424
        pass &= decodeTest(test2_bytes, test2_chars, "escapes2");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   425
        pass &= decodeTest(test3_bytes, test3_chars, "escapes3");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   426
        pass &= decodeTest(test3a_bytes, test3_chars, "escapes3a");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   427
        pass &= decodeTest(test4_bytes, test4_chars, "escapes4");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   428
        pass &= decodeTest(test5_bytes, test5_chars, "escapes5");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   429
        pass &= decodeTest(test6_bytes, test6_chars, "escapes6");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   430
        pass &= decodeTest(test7_bytes, test7_chars, "escapes7");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   431
        pass &= decodeTest(test8_bytes, test8_chars, "escapes8");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   432
        pass &= decodeTest(test9_bytes, test9_chars, "escapes9");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   433
        pass &= decodeTest(test10_bytes, test10_chars, "escapes10");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   434
        pass &= decodeTest(test11_bytes, test11_chars, "escapes11");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   435
        pass &= decodeTest(test12_bytes, test12_chars, "escapes12");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   436
        pass &= decodeTest(test13_bytes, test13_chars, "escapes13");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   437
        pass &= decodeResultTest(test14_bytes, test14_result, "escapes14");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   438
        pass &= decodeResultTest(test15_bytes, test15_result, "escapes15");
2913
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   439
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   440
        pass &= encodeTest6730652 ();
39a9cc073b84 6831794: charset EUC_TW is 12.6% of the total size of charsets.jar
sherman
parents: 796
diff changeset
   441
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   442
        // PASS/FAIL status is what the whole thing is about.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   443
        //
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   444
        if (! pass) {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   445
            throw new Exception("FAIL -- incorrect ISO-2022-CN");
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   446
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   447
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   448
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   449
}