Path: blob/master/test/jdk/tools/launcher/I18NTest.java
41144 views
/*1* Copyright (c) 2012, 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 476138426* @compile -XDignore.symbol.file I18NTest.java27* @run main I18NTest28* @summary Test to see if class files with non-ASCII characters can be run29* @author Joseph D. Darcy, Kumar Srinivasan30*/313233import java.util.ArrayList;34import java.io.File;35import java.util.List;3637public class I18NTest extends TestHelper {38static String fileName = null;39public static void main(String... args) throws Exception {40String defaultEncoding = System.getProperty("file.encoding");41if (defaultEncoding == null) {42System.err.println("Default encoding not found; Error.");43return;44}45if (!defaultEncoding.equals("Cp1252")) {46System.err.println("Warning: required encoding not found, test skipped.");47return;48}49// for some reason the shell test version insisted on cleaning out the50// directory, likely being pedantic.51File cwd = new File(".");52for (File f : cwd.listFiles(createFilter(CLASS_FILE_EXT))) {53f.delete();54}55for (File f : cwd.listFiles(createFilter(JAVA_FILE_EXT))) {56f.delete();57}58createPlatformFile();5960// compile the generate code using the javac compiler vs. the api, to61// as a bonus point to see if the argument is passed correctly62TestResult tr;63tr = doExec(javacCmd, fileName + JAVA_FILE_EXT);64if (!tr.isOK()) {65System.out.println(tr);66throw new Error("compilation failed...");67}68tr = doExec(javaCmd, "-cp", ".", fileName);69if (!tr.isOK()) {70System.out.println(tr);71throw new RuntimeException("run failed with encoding " + defaultEncoding);72}73}7475public static void createPlatformFile() throws Exception {76List<String> buffer = new ArrayList<>();77// "HelloWorld" with an accented e78fileName = "i18nH\u00e9lloWorld";79buffer.clear();80buffer.add("public class i18nH\u00e9lloWorld {");81buffer.add(" public static void main(String [] argv) {");82buffer.add(" System.out.println(\"Hello Cp1252 World\");");83buffer.add(" }");84buffer.add("}");85File outFile = new File(fileName + JAVA_FILE_EXT);86createFile(outFile, buffer);87}88}899091