test/jdk/sun/nio/cs/EncodingNothing.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:
7542
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     1
/*
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     4
 *
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     8
 *
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    13
 * accompanied this code).
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    14
 *
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    18
 *
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    21
 * questions.
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    22
 */
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    23
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    24
/*
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    25
 * @test
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    26
 * @bug 6415373
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    27
 * @summary Encoding nothing should output nothing
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    28
 */
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    29
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    30
import java.io.*;
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    31
import java.nio.charset.*;
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    32
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    33
public class EncodingNothing {
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    34
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    35
    public static void main(String[] args) throws Throwable {
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    36
        int failed = 0;
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    37
        for (Charset cs : Charset.availableCharsets().values()) {
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    38
            if (! cs.canEncode())
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    39
                continue;
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    40
            System.out.printf("%s: ", cs.name());
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    41
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    42
            OutputStreamWriter osw = new OutputStreamWriter(baos, cs);
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    43
            osw.close();
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    44
            if (baos.size() != 0) {
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    45
                System.out.printf(" Failed:  output bytes=%d", baos.size());
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    46
                failed++;
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    47
            }
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    48
            System.out.println();
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    49
        }
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    50
        if (failed != 0)
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    51
            throw new AssertionError("Some tests failed");
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    52
    }
514d58003c20 6415373: (cs) UnicodeEncoder emits BOM when there are no bytes to encode
sherman
parents:
diff changeset
    53
}