test/jdk/sun/nio/cs/StreamEncoderOut.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:
28850
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     1
/*
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     4
 *
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     8
 *
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    13
 * accompanied this code).
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    14
 *
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    18
 *
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    21
 * questions.
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    22
 */
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    23
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    24
/* @test
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    25
   @bug 8030179
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    26
   @summary test if the charset encoder deails with surrogate correctly
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    27
 * @run testng/othervm -esa StreamEncoderOut
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    28
 */
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    29
import org.testng.annotations.DataProvider;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    30
import org.testng.annotations.Test;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    31
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    32
import java.io.IOException;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    33
import java.io.OutputStream;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    34
import java.io.OutputStreamWriter;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    35
import java.nio.charset.Charset;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    36
import java.util.stream.Stream;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    37
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    38
import static java.util.stream.Collectors.joining;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    39
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    40
@Test
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    41
public class StreamEncoderOut {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    42
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    43
    enum Input {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    44
        HIGH("\ud834"),
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    45
        LOW("\udd1e"),
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    46
        HIGH_LOW("\ud834\udd1e");
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    47
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    48
        final String value;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    49
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    50
        Input(String value) {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    51
            this.value = value;
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    52
        }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    53
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    54
        @Override
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    55
        public String toString() {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    56
            return name() + " : \'" + value + "\"";
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    57
        }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    58
    }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    59
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    60
    @DataProvider(name = "CharsetAndString")
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    61
    // [Charset, Input]
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    62
    public static Object[][] makeStreamTestData() {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    63
        // Cross product of supported charsets and inputs
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    64
        return Charset.availableCharsets().values().stream().
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    65
                filter(Charset::canEncode).
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    66
                flatMap(cs -> Stream.of(Input.values()).map(i -> new Object[]{cs, i})).
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    67
                toArray(Object[][]::new);
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    68
    }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    69
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    70
    private static String generate(String s, int n) {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    71
        return Stream.generate(() -> s).limit(n).collect(joining());
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    72
    }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    73
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    74
    static final OutputStream DEV_NULL = new OutputStream() {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    75
        @Override
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    76
        public void write(byte b[], int off, int len) throws IOException {}
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    77
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    78
        @Override
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    79
        public void write(int b) throws IOException {}
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    80
    };
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    81
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    82
    @Test(dataProvider = "CharsetAndString")
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    83
    public void test(Charset cs, Input input) throws IOException {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    84
        OutputStreamWriter w = new OutputStreamWriter(DEV_NULL, cs);
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    85
        String t = generate(input.value, 8193);
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    86
        for (int i = 0; i < 10; i++) {
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    87
            w.append(t);
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    88
        }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    89
    }
4996a75e8bfb 8030179: java/nio/Buffer/Chars.java, testcases seems all pass but jtreg/testng failed with java.lang.AssertionError
sherman
parents:
diff changeset
    90
}