test/jdk/sun/nio/cs/MalformedSurrogates.java
author jiangli
Wed, 27 Sep 2017 17:55:20 -0400
changeset 47548 664b9d44db74
parent 47216 71c04702a3d5
permissions -rw-r--r--
8068314: "Java fields that are currently set during shared space dumping" comment is incorrect Summary: CDS dump time should also initialize preallocated out_of_memory error messages. Reviewed-by: iklam, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     1
/*
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     4
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     8
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    13
 * accompanied this code).
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    14
 *
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 796
diff changeset
    21
 * questions.
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    22
 */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    23
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    24
/* @test
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    25
 * @bug 4153987
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    26
 * @summary Malformed surrogates should be handled by the converter in
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    27
 * substitution mode.
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    28
 */
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    29
import java.io.*;
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    30
import java.nio.charset.Charset;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    31
import java.nio.charset.CharsetDecoder;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    32
import java.nio.charset.CharsetEncoder;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    33
import java.nio.CharBuffer;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    34
import java.nio.ByteBuffer;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    35
import java.nio.charset.CodingErrorAction;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    36
import java.nio.charset.MalformedInputException;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    37
import java.nio.charset.UnmappableCharacterException;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    38
import java.util.SortedMap;
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    39
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    40
public class MalformedSurrogates {
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    41
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    42
    private static final String PREFIX = "abc";
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    43
    private static final String SUFFIX = "efgh";
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    44
    private static final String MALFORMED_SURROGATE = PREFIX + "\uD800\uDB00" + SUFFIX;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    45
    private static final String NORMAL_SURROGATE = PREFIX + "\uD800\uDC00" + SUFFIX;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    46
    private static final String REVERSED_SURROGATE = PREFIX + "\uDC00\uD800" + SUFFIX;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    47
    private static final String SOLITARY_HIGH_SURROGATE = PREFIX + "\uD800" + SUFFIX;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    48
    private static final String SOLITARY_LOW_SURROGATE = PREFIX + "\uDC00" + SUFFIX;
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    49
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    50
    public static void main(String[] args) throws IOException {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    51
        SortedMap<String, Charset> map = Charset.availableCharsets();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    52
        for (String name : map.keySet()) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    53
            Charset charset = map.get(name);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    54
            if (charset.canEncode() && !charset.name().equals("x-COMPOUND_TEXT")) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    55
                testNormalSurrogate(charset, NORMAL_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    56
                testMalformedSurrogate(charset, MALFORMED_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    57
                testMalformedSurrogate(charset, REVERSED_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    58
                testMalformedSurrogate(charset, SOLITARY_HIGH_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    59
                testMalformedSurrogate(charset, SOLITARY_LOW_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    60
                testSurrogateWithReplacement(charset, NORMAL_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    61
                testSurrogateWithReplacement(charset, MALFORMED_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    62
                testSurrogateWithReplacement(charset, REVERSED_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    63
                testSurrogateWithReplacement(charset, SOLITARY_HIGH_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    64
                testSurrogateWithReplacement(charset, SOLITARY_LOW_SURROGATE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    65
            }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    66
        }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    67
    }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    68
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    69
    public static void testMalformedSurrogate(Charset cs, String surrogate) throws IOException {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    70
        CharsetEncoder en = cs.newEncoder();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    71
        if (en.canEncode(surrogate)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    72
            throw new RuntimeException("testMalformedSurrogate failed with charset " + cs.name());
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    73
        }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    74
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    75
        try {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    76
            en.encode(CharBuffer.wrap(surrogate));
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    77
            throw new RuntimeException("Should throw MalformedInputException or UnmappableCharacterException");
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    78
        } catch (MalformedInputException | UnmappableCharacterException ex) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    79
        } finally {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    80
            en.reset();
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    81
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    82
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    83
        try (OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream(), en)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    84
            osw.write(surrogate);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    85
            throw new RuntimeException("Should throw MalformedInputException or UnmappableCharacterException");
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    86
        } catch (MalformedInputException | UnmappableCharacterException ex) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    87
        }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    88
    }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    89
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    90
    public static void testNormalSurrogate(Charset cs, String surrogate) throws IOException {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    91
        CharsetEncoder en = cs.newEncoder();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    92
        try {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    93
            en.encode(CharBuffer.wrap(surrogate));
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    94
        } catch (UnmappableCharacterException ex) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    95
        } finally {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    96
            en.reset();
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    97
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
    98
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
    99
        try (OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream(), en)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   100
            osw.write(surrogate);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   101
        } catch (UnmappableCharacterException ex) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   102
        }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   103
    }
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   104
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   105
    public static void testSurrogateWithReplacement(Charset cs, String surrogate) throws IOException {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   106
        CharsetEncoder en = cs.newEncoder();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   107
        CharsetDecoder de = cs.newDecoder();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   108
        if (!en.canEncode(NORMAL_SURROGATE)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   109
            return;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   110
        }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   111
        String expected = null;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   112
        String replace = new String(en.replacement(), cs);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   113
        switch (surrogate) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   114
            case MALFORMED_SURROGATE:
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   115
            case REVERSED_SURROGATE:
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   116
                expected = PREFIX + replace + replace + SUFFIX;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   117
                break;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   118
            case SOLITARY_HIGH_SURROGATE:
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   119
            case SOLITARY_LOW_SURROGATE:
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   120
                expected = PREFIX + replace + SUFFIX;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   121
                break;
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   122
            default:
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   123
                expected = NORMAL_SURROGATE;
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   124
        }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   125
22074
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   126
        try {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   127
            en.onMalformedInput(CodingErrorAction.REPLACE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   128
            en.onUnmappableCharacter(CodingErrorAction.REPLACE);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   129
            ByteBuffer bbuf = en.encode(CharBuffer.wrap(surrogate));
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   130
            CharBuffer cbuf = de.decode(bbuf);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   131
            if (!cbuf.toString().equals(expected)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   132
                throw new RuntimeException("charset " + cs.name() + " (en)decoded the surrogate " + surrogate + " to " + cbuf.toString() + " which is not same as the expected " + expected);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   133
            }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   134
        } finally {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   135
            en.reset();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   136
            de.reset();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   137
        }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   138
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   139
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   140
                OutputStreamWriter osw = new OutputStreamWriter(bos, en);) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   141
            osw.write(surrogate);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   142
            osw.flush();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   143
            try (InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bos.toByteArray()), de)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   144
                CharBuffer cbuf = CharBuffer.allocate(expected.length());
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   145
                isr.read(cbuf);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   146
                cbuf.rewind();
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   147
                if (!cbuf.toString().equals(expected)) {
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   148
                    throw new RuntimeException("charset " + cs.name() + " (en)decoded the surrogate " + surrogate + " to " + cbuf.toString() + " which is not same as the expected " + expected);
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   149
                }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   150
            }
e25a2837787e 8022879: TEST_BUG: sun/nio/cs/MalformedSurrogates.java fails intermittently
alanb
parents: 5506
diff changeset
   151
        }
796
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   152
    }
2c3db720c065 6675856: Open charset tests
sherman
parents:
diff changeset
   153
}