jdk/test/tools/launcher/I18NJarTest.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 16028 1204994c426f
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     1
/*
16028
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     4
 *
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     8
 *
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    13
 * accompanied this code).
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    14
 *
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    18
 *
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    21
 * questions.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    22
 */
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    23
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    24
/*
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    25
 * @test
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    26
 * @bug 7125442
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    27
 * @summary ensures a jar path as well as a class located in a path containing
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    28
 *          unicode characters are launched.
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11520
diff changeset
    29
 * @compile -XDignore.symbol.file I18NJarTest.java
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    30
 * @run main/othervm I18NJarTest
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    31
 */
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    32
import java.io.File;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    33
import java.util.Locale;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    34
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    35
/*
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    36
 * Note 1: the system must have the correct Locale, in order for the test to
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    37
 * work correctly, on those systems that do not comply, the test will succeed.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    38
 * Here are some guidelines to set the locale correctly.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    39
 * On Windows: ControlPanel->Regional Settings,
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    40
 *             ensure that "Japanese" is selected and checked, and in
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    41
 *             "Code page conversion tables", the following must be checked,
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    42
 *             932 (ANSI/OEM - Japanese Shift-JIS).
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    43
 * On Unix: use "locale -a" verify one of these exist ja_JP.UTF-8 or
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    44
 *          ja_JP.utf8 or ja_JP.ujis, and export one of them with LC_ALL.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    45
 *
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    46
 *
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    47
 * Note 2: since we need to set the locale, it is safest to execute this test
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    48
 * in its own VM (othervm mode), such that the ensuing tests can run unperturbed,
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    49
 * regardless of the outcome.
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    50
 */
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11520
diff changeset
    51
public class I18NJarTest extends TestHelper {
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    52
    private static final File cwd = new File(".");
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    53
    private static final File dir = new File("\uFF66\uFF67\uFF68\uFF69");
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    54
    private static final String encoding = System.getProperty("sun.jnu.encoding", "");
16028
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    55
    private static final String LANG = System.getenv("LANG");
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    56
    private static final String LC_ALL = System.getenv("LC_ALL");
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    57
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    58
    public static void main(String... args) throws Exception {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    59
        boolean localeAvailable = false;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    60
        for (Locale l : Locale.getAvailableLocales()) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    61
            if (l.toLanguageTag().equals(Locale.JAPAN.toLanguageTag())) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    62
                localeAvailable = true;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    63
                break;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    64
            }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    65
        }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    66
        if (!localeAvailable) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    67
            System.out.println("Warning: locale: " + Locale.JAPAN
16028
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    68
                    + " not found, test passes vacuously");
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    69
            return;
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    70
        }
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    71
        if ("C".equals(LC_ALL) || "C".equals(LANG)) {
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    72
            System.out.println("Warning: The LANG and/or LC_ALL env vars are " +
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    73
              "set to \"C\":\n" +
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    74
              "  LANG=" + LANG + "\n" +
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    75
              "  LC_ALL=" + LC_ALL + "\n" +
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    76
              "This test requires support for multi-byte filenames.\n" +
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    77
              "Test passes vacuously.");
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    78
            return;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    79
        }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    80
        if (encoding.equals("MS932") || encoding.equals("UTF-8")) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    81
            Locale.setDefault(Locale.JAPAN);
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    82
            System.out.println("using locale " + Locale.JAPAN +
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    83
                    ", encoding " + encoding);
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    84
        } else {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    85
            System.out.println("Warning: current encoding is " + encoding +
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    86
                    "this test requires MS932 <Ja> or UTF-8," +
16028
1204994c426f 8006039: test/tools/launcher/I18NJarTest.java fails on Mac w/ LANG=C, LC_ALL=C
bchristi
parents: 11687
diff changeset
    87
                    " test passes vacuously");
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    88
            return;
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    89
        }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    90
        dir.mkdir();
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    91
        File dirfile = new File(dir, "foo.jar");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11520
diff changeset
    92
        createJar(dirfile,
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    93
                "public static void main(String... args) {",
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    94
                "System.out.println(\"Hello World\");",
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    95
                "System.exit(0);",
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    96
                "}");
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    97
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    98
        // remove the class files, to ensure that the class is indeed picked up
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
    99
        // from the jar file and not from ambient classpath.
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11520
diff changeset
   100
        File[] classFiles = cwd.listFiles(createFilter(CLASS_FILE_EXT));
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   101
        for (File f : classFiles) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   102
            f.delete();
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   103
        }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   104
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   105
        // test with a jar file
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11520
diff changeset
   106
        TestResult tr = doExec(javaCmd, "-jar", dirfile.getAbsolutePath());
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   107
        System.out.println(tr);
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   108
        if (!tr.isOK()) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   109
            throw new RuntimeException("TEST FAILED");
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   110
        }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   111
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   112
        // test the same class but by specifying it as a classpath
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 11520
diff changeset
   113
        tr = doExec(javaCmd, "-cp", dirfile.getAbsolutePath(), "Foo");
11520
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   114
        System.out.println(tr);
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   115
        if (!tr.isOK()) {
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   116
            throw new RuntimeException("TEST FAILED");
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   117
        }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   118
    }
1c485b79de81 7125442: jar application located in two bytes character named folder cannot be run with JRE 7 u1/u2
ksrini
parents:
diff changeset
   119
}