blob: 3af5d593afc29fd27574d1ac50412407e4659ebb [file] [log] [blame]
ksrinif127cd92012-01-28 10:46:46 -08001/*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 4761384
27 * @compile -XDignore.symbol.file I18NTest.java
28 * @run main I18NTest
29 * @summary Test to see if class files with non-ASCII characters can be run
30 * @author Joseph D. Darcy, Kumar Srinivasan
31 */
32
33
34import java.util.ArrayList;
35import java.io.File;
36import java.util.List;
37
38public class I18NTest extends TestHelper {
39 static String fileName = null;
40 public static void main(String... args) throws Exception {
41 String defaultEncoding = System.getProperty("file.encoding");
42 if (defaultEncoding == null) {
43 System.err.println("Default encoding not found; Error.");
44 return;
45 }
46 if (!defaultEncoding.equals("Cp1252")) {
47 System.err.println("Warning: required encoding not found, test skipped.");
48 return;
49 }
50 // for some reason the shell test version insisted on cleaning out the
51 // directory, likely being pedantic.
52 File cwd = new File(".");
53 for (File f : cwd.listFiles(createFilter(CLASS_FILE_EXT))) {
54 f.delete();
55 }
56 for (File f : cwd.listFiles(createFilter(JAVA_FILE_EXT))) {
57 f.delete();
58 }
59 createPlatformFile();
60
61 // compile the generate code using the javac compiler vs. the api, to
62 // as a bonus point to see if the argument is passed correctly
63 TestResult tr = null;
64 tr = doExec(javacCmd, fileName + JAVA_FILE_EXT);
65 if (!tr.isOK()) {
66 System.out.println(tr);
67 throw new Error("compilation failed...");
68 }
69 tr = doExec(javaCmd, "-cp", ".", fileName);
70 if (!tr.isOK()) {
71 System.out.println(tr);
72 throw new RuntimeException("run failed with encoding " + defaultEncoding);
73 }
74 }
75
76 public static void createPlatformFile() throws Exception {
77 List<String> buffer = new ArrayList<>();
78 // "HelloWorld" with an accented e
79 fileName = "i18nH\u00e9lloWorld";
80 buffer.clear();
81 buffer.add("public class i18nH\u00e9lloWorld {");
82 buffer.add(" public static void main(String [] argv) {");
83 buffer.add(" System.out.println(\"Hello Cp1252 World\");");
84 buffer.add(" }");
85 buffer.add("}");
86 File outFile = new File(fileName + JAVA_FILE_EXT);
87 createFile(outFile, buffer);
88 }
89}