jdk/test/java/nio/charset/coders/Errors.java
author katleman
Thu, 05 Jan 2012 08:42:37 -0800
changeset 11376 075fe3928b7f
parent 10898 01a232fa2ddb
child 14342 8435a30053c1
permissions -rw-r--r--
Added tag jdk8-b20 for changeset 90e14ec89395
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4817
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4817
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
4817
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     4
 *
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     8
 *
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    13
 * accompanied this code).
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    14
 *
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4817
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4817
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4817
diff changeset
    21
 * questions.
4817
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    22
 */
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    23
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    24
/* @test
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    25
 * @summary Check that error cases are replaced correctly in String/ISR/OSW
10898
01a232fa2ddb 7096080: UTF8 update and new CESU-8 charset
sherman
parents: 5506
diff changeset
    26
 * @bug 4457851 7096080
4817
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    27
 *
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    28
 * @build Errors Util
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    29
 * @run main Errors
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    30
 */
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    31
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    32
import java.io.*;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    33
import java.nio.*;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    34
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    35
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    36
public class Errors {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    37
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    38
    static PrintStream log = System.err;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    39
    static int failures = 0;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    40
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    41
    static final byte Q = (byte)'?';
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    42
    static final byte X = (byte)'x';
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    43
    static final byte Y = (byte)'y';
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    44
    static final byte Z = (byte)'z';
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    45
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    46
    static abstract class Test {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    47
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    48
        protected final String csn;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    49
        protected final String what;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    50
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    51
        Test(String csn, String what) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    52
            this.csn = csn;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    53
            this.what = what;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    54
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    55
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    56
        abstract byte[] enc(String s) throws IOException;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    57
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    58
        Test test(String s, byte[] ref) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    59
            log.print("  " + Util.toString(s.toCharArray()));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    60
            byte[] ba = null;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    61
            try {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    62
                ba = enc(s);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    63
            } catch (IOException x) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    64
                log.println(" -e-> ERROR: " + x.getClass().getName());
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    65
                failures++;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    66
                return this;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    67
            }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    68
            log.println(" -e-> " + Util.toString(ba));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    69
            int i = Util.cmp(ba, ref);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    70
            if (i >= 0) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    71
                log.println("    ERROR: Mismatch at index " + i
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    72
                            + ", expected: " + Util.toString(ref));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    73
                failures++;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    74
            }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    75
            return this;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    76
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    77
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    78
        abstract String dec(byte[] ba) throws IOException;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    79
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    80
        Test test(byte[] ba, String ref) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    81
            log.print("  " + Util.toString(ba));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    82
            String s = null;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    83
            try {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    84
                s = dec(ba);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    85
            } catch (IOException x) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    86
                log.println(" -d-> ERROR: " + x.getClass().getName());
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    87
                failures++;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    88
                return this;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    89
            }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    90
            log.println(" -d-> " + Util.toString(s.toCharArray()));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    91
            char[] ca = s.toCharArray();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    92
            char[] refa = ref.toCharArray();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    93
            int i = Util.cmp(ca, refa);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    94
            if (i >= 0) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    95
                log.println("    ERROR: Mismatch at index " + i
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    96
                            + ", expected: " + Util.toString(refa));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    97
                failures++;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    98
            }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
    99
            return this;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   100
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   101
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   102
        Test run() {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   103
            log.println(csn + ", " + what);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   104
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   105
            test("xyzzy", new byte[] { X, Y, Z, Z, Y });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   106
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   107
            // Malformed surrogates
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   108
            test("\uD800x", new byte[] { Q, X });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   109
            test("\uDC00x", new byte[] { Q, X });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   110
            test("\uD800\uDB00x", new byte[] { Q, Q, X });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   111
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   112
            return this;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   113
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   114
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   115
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   116
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   117
    static class TestStream extends Test {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   118
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   119
        TestStream(String csn) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   120
            super(csn, "I/O streams");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   121
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   122
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   123
        byte[] enc(String s) throws IOException {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   124
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   125
            Writer wr = new OutputStreamWriter(bos, csn);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   126
            wr.write(s);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   127
            wr.close();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   128
            return bos.toByteArray();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   129
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   130
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   131
        String dec(byte[] ba) throws IOException {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   132
            ByteArrayInputStream bis = new ByteArrayInputStream(ba);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   133
            Reader rd = new InputStreamReader(bis, csn);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   134
            char[] ca = new char[1024];
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   135
            int n = rd.read(ca);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   136
            String s = new String(ca, 0, n);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   137
            rd.close();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   138
            return s;
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   139
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   140
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   141
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   142
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   143
    static class TestString extends Test {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   144
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   145
        TestString(String csn) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   146
            super(csn, "strings");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   147
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   148
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   149
        byte[] enc(String s) throws IOException {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   150
            return s.getBytes(csn);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   151
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   152
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   153
        String dec(byte[] ba) throws IOException {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   154
            return new String(ba, 0, ba.length, csn);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   155
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   156
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   157
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   158
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   159
    static void test_US_ASCII(Test t) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   160
        t.run();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   161
        t.test("\u0080", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   162
        t.test("\u0100", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   163
        t.test("\uD800\uDC00", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   164
        t.test("\uF000", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   165
        t.test("\uFFFE", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   166
        t.test("\uFFFF", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   167
        t.test(new byte[] { X, (byte)0x7f, Y }, "x\u007Fy");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   168
        t.test(new byte[] { X, (byte)0x80, Y }, "x\uFFFDy");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   169
        t.test(new byte[] { (byte)0xf0, (byte)0xf0 }, "\uFFFD\uFFFD");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   170
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   171
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   172
    static void test_ISO_8859_1(Test t) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   173
        t.run();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   174
        t.test("\u0080", new byte[] { (byte)0x80 });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   175
        t.test("\u0100", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   176
        t.test("\uD800\uDC00x", new byte[] { Q, X });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   177
        t.test("\uF000", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   178
        t.test("\uFFFE", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   179
        t.test("\uFFFF", new byte[] { Q });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   180
        t.test(new byte[] { X, (byte)0x7f, Y }, "x\u007Fy");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   181
        t.test(new byte[] { X, (byte)0x80, Y }, "x\u0080y");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   182
        t.test(new byte[] { (byte)0xf0, (byte)0xf0 }, "\u00F0\u00F0");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   183
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   184
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   185
    static void test_UTF_8(Test t) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   186
        t.run();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   187
        t.test("\u0080", new byte[] { (byte)0xC2, (byte)0x80 });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   188
        t.test("\u0100", new byte[] { (byte)0xC4, (byte)0x80 });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   189
        t.test("\uD800\uDC00",
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   190
               new byte[] { (byte)0xF0, (byte)0x90, (byte)0x80, (byte)0x80 });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   191
        t.test("\uF000", new byte[] { (byte)0xEF, (byte)0x80, (byte)0x80 });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   192
        t.test("\uFFFE", new byte[] { (byte)0xEF, (byte)0xBF, (byte)0xBE });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   193
        t.test("\uFFFF", new byte[] { (byte)0xEF, (byte)0xBF, (byte)0xBF });
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   194
        t.test(new byte[] { X, (byte)0x7f, Y }, "x\u007Fy");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   195
        t.test(new byte[] { X, (byte)0x80, Y }, "x\uFFFDy");
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   196
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   197
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   198
    public static void main(String[] args) throws Exception {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   199
        test_US_ASCII(new TestString("US-ASCII"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   200
        test_US_ASCII(new TestStream("US-ASCII"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   201
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   202
        test_ISO_8859_1(new TestString("ISO-8859-1"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   203
        test_ISO_8859_1(new TestStream("ISO-8859-1"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   204
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   205
        test_ISO_8859_1(new TestString("ISO-8859-15"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   206
        test_ISO_8859_1(new TestStream("ISO-8859-15"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   207
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   208
        test_UTF_8(new TestString("UTF-8"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   209
        test_UTF_8(new TestStream("UTF-8"));
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   210
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   211
        if (failures > 0) {
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   212
            log.println();
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   213
            throw new Exception("Tests failed: " + failures);
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   214
        }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   215
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   216
    }
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   217
67f425ac409b 6920732: opensource test/java/nio/charset
sherman
parents:
diff changeset
   218
}