test/jdk/sun/nio/cs/TestUnmappable.java
author dholmes
Wed, 06 Nov 2019 21:18:42 -0500
changeset 58956 9a0a5e70eeb2
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516 Reviewed-by: jiefu, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21309
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     1
/*
41127
186dce575463 8166553: undeclared dependencies for two IO tests
skovalev
parents: 21309
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
21309
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     4
 *
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    10
 *
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    15
 * accompanied this code).
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    16
 *
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    20
 *
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    23
 * questions.
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    24
 */
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    25
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    26
/*
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    27
 * @test
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    28
 * @bug 8008386
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    29
 * @summary (cs) Unmappable leading should be decoded to replacement.
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    30
 *          Tests for Shift_JIS and MS932 decoding
41127
186dce575463 8166553: undeclared dependencies for two IO tests
skovalev
parents: 21309
diff changeset
    31
 * @modules jdk.charsets
21309
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    32
 * @run main TestUnmappable
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    33
 */
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    34
41127
186dce575463 8166553: undeclared dependencies for two IO tests
skovalev
parents: 21309
diff changeset
    35
import java.nio.charset.Charset;
21309
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    36
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    37
public class TestUnmappable {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    38
    public static void main(String args[]) throws Exception {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    39
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    40
        // illegal leading character test
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    41
        byte[][] inputBytes = {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    42
                               // Shift_JIS
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    43
                               {(byte)0xce, (byte)0xa0, (byte)0xce, (byte)0x7a},
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    44
                               // MS932
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    45
                               {(byte)0x3c, (byte)0x21, (byte)0x2d, (byte)0x2d,
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    46
                                (byte)0xe5, (byte)0xaf, (byte)0xbe, (byte)0xe5,
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    47
                                (byte)0xbf, (byte)0x9c, (byte)0x2d, (byte)0x2d,
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    48
                                (byte)0x3e, (byte)0xd,  (byte)0xa },
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    49
                               {(byte)0x81, (byte)0xad},
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    50
                               // PCK
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    51
                               {(byte)0xef, (byte)0x90},
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    52
                               {(byte)0x91, (byte)0xfd}
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    53
                              };
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    54
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    55
        String[] charsets = { "Shift_JIS", "MS932", "PCK" };
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    56
        String[] expectedStrings = {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    57
                                    // Shift_JIS
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    58
                                    "0xce 0x3f 0xce 0x7a ",
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    59
                                    // MS932
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    60
                                    "0x3c 0x21 0x2d 0x2d 0xe5 0xaf 0xbe 0xe5 0xbf " +
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    61
                                    "0x3f 0x2d 0x2d 0x3e 0xd 0xa ",
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    62
                                    "0x3f 0xad ",
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    63
                                    // PCK
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    64
                                    "0x3f 0x3f ",
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    65
                                    "0x3f "};
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    66
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    67
        for (int i = 0; i < charsets.length; i++) {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    68
            String ret = new String(inputBytes[i], charsets[i]);
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    69
            String bString = getByteString(ret.getBytes(Charset.forName(charsets[i])));
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    70
            if (expectedStrings[i].length() != bString.length()
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    71
               || ! expectedStrings[i].equals(bString)){
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    72
                throw new Exception("ByteToChar for " + charsets[i]
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    73
                    + " does not work correctly.\n" +
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    74
                    "Expected: " + expectedStrings[i] + "\n" +
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    75
                    "Received: " + bString);
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    76
            }
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    77
        }
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    78
    }
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    79
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    80
    private static String getByteString(byte[] bytes) {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    81
        StringBuffer sb = new StringBuffer();
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    82
        for (int i = 0; i < bytes.length; i++) {
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    83
            sb.append("0x" + Integer.toHexString((int)(bytes[i] & 0xFF)) + " ");
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    84
        }
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    85
        return sb.toString();
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    86
    }
5adf83468a1d 8008386: (cs) Unmappable leading should be decoded to replacement.
sherman
parents:
diff changeset
    87
}