4609N/A/*
5861N/A * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
4609N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4609N/A *
4609N/A * This code is free software; you can redistribute it and/or modify it
4609N/A * under the terms of the GNU General Public License version 2 only, as
4609N/A * published by the Free Software Foundation.
4609N/A *
4609N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4609N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4609N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4609N/A * version 2 for more details (a copy is included in the LICENSE file that
4609N/A * accompanied this code).
4609N/A *
4609N/A * You should have received a copy of the GNU General Public License version
4609N/A * 2 along with this work; if not, write to the Free Software Foundation,
4609N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4609N/A *
4609N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4609N/A * or visit www.oracle.com if you need additional information or have any
4609N/A * questions.
4609N/A */
4609N/A
4609N/A/*
4609N/A * @test
4609N/A * @bug 7125442
4609N/A * @summary ensures a jar path as well as a class located in a path containing
4609N/A * unicode characters are launched.
4609N/A * @compile -XDignore.symbol.file I18NJarTest.java TestHelper.java
4609N/A * @run main/othervm I18NJarTest
4609N/A */
4609N/Aimport java.io.File;
4609N/Aimport java.util.Locale;
4609N/A
4609N/A/*
4609N/A * Note 1: the system must have the correct Locale, in order for the test to
4609N/A * work correctly, on those systems that do not comply, the test will succeed.
4609N/A * Here are some guidelines to set the locale correctly.
4609N/A * On Windows: ControlPanel->Regional Settings,
4609N/A * ensure that "Japanese" is selected and checked, and in
4609N/A * "Code page conversion tables", the following must be checked,
4609N/A * 932 (ANSI/OEM - Japanese Shift-JIS).
4609N/A * On Unix: use "locale -a" verify one of these exist ja_JP.UTF-8 or
4609N/A * ja_JP.utf8 or ja_JP.ujis, and export one of them with LC_ALL.
4609N/A *
4609N/A *
4609N/A * Note 2: since we need to set the locale, it is safest to execute this test
4609N/A * in its own VM (othervm mode), such that the ensuing tests can run unperturbed,
4609N/A * regardless of the outcome.
4609N/A */
4609N/Apublic class I18NJarTest {
4609N/A private static final File cwd = new File(".");
4609N/A private static final File dir = new File("\uFF66\uFF67\uFF68\uFF69");
4609N/A private static final String encoding = System.getProperty("sun.jnu.encoding", "");
5861N/A private static final String LANG = System.getenv("LANG");
5861N/A private static final String LC_ALL = System.getenv("LC_ALL");
4609N/A
4609N/A public static void main(String... args) throws Exception {
4609N/A boolean localeAvailable = false;
4609N/A for (Locale l : Locale.getAvailableLocales()) {
4609N/A if (l.toLanguageTag().equals(Locale.JAPAN.toLanguageTag())) {
4609N/A localeAvailable = true;
4609N/A break;
4609N/A }
4609N/A }
4609N/A if (!localeAvailable) {
4609N/A System.out.println("Warning: locale: " + Locale.JAPAN
5861N/A + " not found, test passes vacuously");
5861N/A return;
5861N/A }
5861N/A if ("C".equals(LC_ALL) || "C".equals(LANG)) {
5861N/A System.out.println("Warning: The LANG and/or LC_ALL env vars are " +
5861N/A "set to \"C\":\n" +
5861N/A " LANG=" + LANG + "\n" +
5861N/A " LC_ALL=" + LC_ALL + "\n" +
5861N/A "This test requires support for multi-byte filenames.\n" +
5861N/A "Test passes vacuously.");
4609N/A return;
4609N/A }
4609N/A if (encoding.equals("MS932") || encoding.equals("UTF-8")) {
4609N/A Locale.setDefault(Locale.JAPAN);
4609N/A System.out.println("using locale " + Locale.JAPAN +
4609N/A ", encoding " + encoding);
4609N/A } else {
4609N/A System.out.println("Warning: current encoding is " + encoding +
4609N/A "this test requires MS932 <Ja> or UTF-8," +
5861N/A " test passes vacuously");
4609N/A return;
4609N/A }
4609N/A dir.mkdir();
4609N/A File dirfile = new File(dir, "foo.jar");
4609N/A TestHelper.createJar(dirfile,
4609N/A "public static void main(String... args) {",
4609N/A "System.out.println(\"Hello World\");",
4609N/A "System.exit(0);",
4609N/A "}");
4609N/A
4609N/A // remove the class files, to ensure that the class is indeed picked up
4609N/A // from the jar file and not from ambient classpath.
4609N/A File[] classFiles = cwd.listFiles(TestHelper.createFilter(TestHelper.CLASS_FILE_EXT));
4609N/A for (File f : classFiles) {
4609N/A f.delete();
4609N/A }
4609N/A
4609N/A // test with a jar file
4609N/A TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd,
4609N/A "-jar", dirfile.getAbsolutePath());
4609N/A System.out.println(tr);
4609N/A if (!tr.isOK()) {
4609N/A throw new RuntimeException("TEST FAILED");
4609N/A }
4609N/A
4609N/A // test the same class but by specifying it as a classpath
4609N/A tr = TestHelper.doExec(TestHelper.javaCmd, "-cp",
4609N/A dirfile.getAbsolutePath(), "Foo");
4609N/A System.out.println(tr);
4609N/A if (!tr.isOK()) {
4609N/A throw new RuntimeException("TEST FAILED");
4609N/A }
4609N/A }
4609N/A}