Path: blob/master/test/langtools/tools/javac/4846262/CheckEBCDICLocaleTest.java
41149 views
/*1* Copyright (c) 2013, 2016, 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 484626226* @summary check that javac operates correctly in EBCDIC locale27* @library /tools/lib28* @modules jdk.compiler/com.sun.tools.javac.api29* jdk.compiler/com.sun.tools.javac.main30* jdk.jdeps/com.sun.tools.javap31* @build toolbox.ToolBox32* @run main CheckEBCDICLocaleTest33*/3435import java.io.File;36import java.io.FileOutputStream;37import java.io.OutputStreamWriter;38import java.io.PrintStream;39import java.io.PrintWriter;40import java.nio.charset.Charset;41import java.nio.file.Files;42import java.nio.file.Paths;43import java.util.Arrays;44import java.util.List;4546import toolbox.ToolBox;4748public class CheckEBCDICLocaleTest {4950private static final String TestSrc =51"public class Test {\n" +52" public void test() {\n" +53" abcdefg\n" +54" }\n" +55"}";5657private static final String TestOutTemplate =58"output%1$sTest.java:3: error: not a statement\n" +59" abcdefg\n" +60" ^\n" +61"output%1$sTest.java:3: error: ';' expected\n" +62" abcdefg\n" +63" ^\n" +64"2 errors\n";6566public static void main(String[] args) throws Exception {67new CheckEBCDICLocaleTest().test();68}6970public void test() throws Exception {71ToolBox tb = new ToolBox();72tb.writeFile("Test.java", TestSrc);73tb.createDirectories("output");7475Charset ebcdic = Charset.forName("IBM1047");76Native2Ascii n2a = new Native2Ascii(ebcdic);77n2a.asciiToNative(Paths.get("Test.java"), Paths.get("output", "Test.java"));7879// Use -encoding to specify the encoding with which to read source files80// Use a suitable configured output stream for javac diagnostics81int rc;82try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Test.tmp"), ebcdic))) {83String[] args = { "-encoding", ebcdic.name(), "output/Test.java" };84rc = com.sun.tools.javac.Main.compile(args, out);85if (rc != 1)86throw new Exception("unexpected exit from javac: " + rc);87}8889n2a.nativeToAscii(Paths.get("Test.tmp"), Paths.get("Test.out"));9091List<String> expectLines = Arrays.asList(92String.format(TestOutTemplate, File.separator).split("\n"));93List<String> actualLines = Files.readAllLines(Paths.get("Test.out"));94try {95tb.checkEqual(expectLines, actualLines);96} catch (Throwable tt) {97PrintStream out = tb.out;98out.println("Output mismatch:");99100out.println("Expected output:");101for (String s: expectLines) {102out.println(s);103}104out.println();105106out.println("Actual output:");107for (String s : actualLines) {108out.println(s);109}110out.println();111112throw tt;113}114}115}116117118