Path: blob/master/test/jdk/tools/launcher/I18NJarTest.java
41144 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 712544226* @summary ensures a jar path as well as a class located in a path containing27* unicode characters are launched.28* @compile -XDignore.symbol.file I18NJarTest.java29* @run main/othervm I18NJarTest30*/31import java.io.File;32import java.util.Locale;3334/*35* Note 1: the system must have the correct Locale, in order for the test to36* work correctly, on those systems that do not comply, the test will succeed.37* Here are some guidelines to set the locale correctly.38* On Windows: ControlPanel->Regional Settings,39* ensure that "Japanese" is selected and checked, and in40* "Code page conversion tables", the following must be checked,41* 932 (ANSI/OEM - Japanese Shift-JIS).42* On Unix: use "locale -a" verify one of these exist ja_JP.UTF-8 or43* ja_JP.utf8 or ja_JP.ujis, and export one of them with LC_ALL.44*45*46* Note 2: since we need to set the locale, it is safest to execute this test47* in its own VM (othervm mode), such that the ensuing tests can run unperturbed,48* regardless of the outcome.49*/50public class I18NJarTest extends TestHelper {51private static final File cwd = new File(".");52private static final File dir = new File("\uFF66\uFF67\uFF68\uFF69");53private static final String encoding = System.getProperty("sun.jnu.encoding", "");54private static final String LANG = System.getenv("LANG");55private static final String LC_ALL = System.getenv("LC_ALL");5657public static void main(String... args) throws Exception {58boolean localeAvailable = false;59for (Locale l : Locale.getAvailableLocales()) {60if (l.toLanguageTag().equals(Locale.JAPAN.toLanguageTag())) {61localeAvailable = true;62break;63}64}65if (!localeAvailable) {66System.out.println("Warning: locale: " + Locale.JAPAN67+ " not found, test passes vacuously");68return;69}70if ("C".equals(LC_ALL) || "C".equals(LANG)) {71System.out.println("Warning: The LANG and/or LC_ALL env vars are " +72"set to \"C\":\n" +73" LANG=" + LANG + "\n" +74" LC_ALL=" + LC_ALL + "\n" +75"This test requires support for multi-byte filenames.\n" +76"Test passes vacuously.");77return;78}79if (encoding.equals("MS932") || encoding.equals("UTF-8")) {80Locale.setDefault(Locale.JAPAN);81System.out.println("using locale " + Locale.JAPAN +82", encoding " + encoding);83} else {84System.out.println("Warning: current encoding is " + encoding +85"this test requires MS932 <Ja> or UTF-8," +86" test passes vacuously");87return;88}89dir.mkdir();90File dirfile = new File(dir, "foo.jar");91createJar(dirfile,92"public static void main(String... args) {",93"System.out.println(\"Hello World\");",94"System.exit(0);",95"}");9697// remove the class files, to ensure that the class is indeed picked up98// from the jar file and not from ambient classpath.99File[] classFiles = cwd.listFiles(createFilter(CLASS_FILE_EXT));100for (File f : classFiles) {101f.delete();102}103104// test with a jar file105TestResult tr = doExec(javaCmd, "-jar", dirfile.getAbsolutePath());106System.out.println(tr);107if (!tr.isOK()) {108throw new RuntimeException("TEST FAILED");109}110111// test the same class but by specifying it as a classpath112tr = doExec(javaCmd, "-cp", dirfile.getAbsolutePath(), "Foo");113System.out.println(tr);114if (!tr.isOK()) {115throw new RuntimeException("TEST FAILED");116}117}118}119120121