jdk/test/tools/launcher/DiacriticTest.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 21847 8d279ff7e53e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20186
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     1
/*
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 20510
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
20186
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     4
 *
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     7
 * published by the Free Software Foundation.
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     8
 *
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    13
 * accompanied this code).
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    14
 *
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    18
 *
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    21
 * questions.
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    22
 */
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    23
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    24
/*
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    25
 * @test
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    26
 * @bug 8017248
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    27
 * @summary Compiler Diacritics Issue
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    28
 * @run main DiacriticTest
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    29
 */
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    30
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    31
import java.io.File;
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    32
import java.io.IOException;
21804
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    33
import java.nio.file.InvalidPathException;
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    34
import java.nio.charset.UnmappableCharacterException;
20186
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    35
import java.util.ArrayList;
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    36
import java.util.HashMap;
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    37
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    38
public class DiacriticTest extends TestHelper {
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    39
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    40
    // NFD-normalized form of the class name
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    41
    static String NAME_NFD="ClassA\u0301";
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    42
    // NFC-normalized form of the same class name
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    43
    static String NAME_NFC="Class\u00C1";
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    44
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    45
    public static void main(String[] args) throws IOException {
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    46
        if (!isMacOSX) {
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    47
            System.out.println("This test is for Mac OS X only. Passing.");
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    48
            return;
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    49
        }
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    50
21804
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    51
        String lang = System.getenv("LANG");
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    52
        if (lang != null && !lang.contains("UTF-8")) {
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    53
            System.out.println("LANG variable set to the language that " +
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    54
                               "does not support unicode, test passes vacuously");
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    55
            return;
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    56
        }
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    57
20186
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    58
        File sourceFile = new File(NAME_NFC + ".java");
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    59
        String source = "public class " + NAME_NFC + " { " +
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    60
                "    public static void main(String args[]) {\n" +
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    61
                "        System.out.println(\"Success!\");\n" +
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    62
                "    }\n" +
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    63
                "}\n";
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    64
        ArrayList<String> content = new ArrayList<>();
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    65
        content.add(source);
20510
46e33ac1d91b 8025738: locale related test fails on langtools mac 10.7 test host
kizune
parents: 20186
diff changeset
    66
        try {
46e33ac1d91b 8025738: locale related test fails on langtools mac 10.7 test host
kizune
parents: 20186
diff changeset
    67
            createFile(sourceFile, content);
21804
07b686da11c4 8028197: tools/launcher/DiacriticTest.java failed on MacOSX: Input length = 1
kizune
parents: 20510
diff changeset
    68
        } catch (UnmappableCharacterException | InvalidPathException ipe) {
20510
46e33ac1d91b 8025738: locale related test fails on langtools mac 10.7 test host
kizune
parents: 20186
diff changeset
    69
            System.out.println("The locale or file system is configured in a way " +
46e33ac1d91b 8025738: locale related test fails on langtools mac 10.7 test host
kizune
parents: 20186
diff changeset
    70
                               "that prevents file creation. Real testing impossible.");
46e33ac1d91b 8025738: locale related test fails on langtools mac 10.7 test host
kizune
parents: 20186
diff changeset
    71
            return;
46e33ac1d91b 8025738: locale related test fails on langtools mac 10.7 test host
kizune
parents: 20186
diff changeset
    72
        }
20186
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    73
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    74
        HashMap<String, String> env = new HashMap<>();
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    75
        env.put("LC_CTYPE", "UTF-8");
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    76
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    77
        TestResult tr;
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    78
        tr = doExec(env, javacCmd, NAME_NFD + ".java");
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    79
        System.out.println(tr.testOutput);
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    80
        if (!tr.isOK()) {
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    81
            System.out.println(tr);
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    82
            throw new RuntimeException("Compilation failed");
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    83
        }
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    84
        tr = doExec(env, javaCmd, "-cp", ".", NAME_NFD);
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    85
        System.out.println(tr.testOutput);
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    86
        if (!tr.isOK()) {
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    87
            System.out.println(tr);
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    88
            throw new RuntimeException("Test execution failed");
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    89
        }
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    90
    }
571cce330408 8025076: Fix for JDK-8017248 breaks jprt submission for non-unicode locales
kizune
parents:
diff changeset
    91
}