CheckEBCDICLocaleTest.java revision 1636:2e21ecd7a5ad
1122509Sume/* 2122509Sume * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 367957Skris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4122509Sume * 5122509Sume * This code is free software; you can redistribute it and/or modify it 6122509Sume * under the terms of the GNU General Public License version 2 only, as 7122509Sume * published by the Free Software Foundation. 8122509Sume * 9122509Sume * This code is distributed in the hope that it will be useful, but WITHOUT 10122509Sume * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11122509Sume * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12122509Sume * version 2 for more details (a copy is included in the LICENSE file that 13122509Sume * accompanied this code). 14122509Sume * 15122509Sume * You should have received a copy of the GNU General Public License version 16122509Sume * 2 along with this work; if not, write to the Free Software Foundation, 17122509Sume * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18122509Sume * 19122509Sume * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20122509Sume * or visit www.oracle.com if you need additional information or have any 21122509Sume * questions. 22122509Sume */ 23122509Sume 24122509Sume/* 25122509Sume * @test 26122509Sume * @bug 4846262 27122509Sume * @summary check that javac operates correctly in EBCDIC locale 28122509Sume * @library /tools/javac/lib 29122509Sume * @build ToolBox 30122509Sume * @run main CheckEBCDICLocaleTest 31122509Sume */ 32122509Sume 33143420Sumeimport java.io.File; 34143420Sumeimport java.nio.file.Files; 35143420Sumeimport java.nio.file.Paths; 36122509Sumeimport java.util.Arrays; 37122509Sume 38122509Sumepublic class CheckEBCDICLocaleTest { 39122509Sume 40122509Sume private static final String TestSrc = 41122509Sume "public class Test {\n" + 42122509Sume " public void test() {\n" + 43122509Sume " abcdefg\n" + 44122509Sume " }\n" + 45122509Sume "}"; 46122509Sume 47122509Sume private static final String TestOutTemplate = 48143420Sume "output%1$sTest.java:3: error: not a statement\n" + 49143420Sume " abcdefg\n" + 50143420Sume " ^\n" + 51143420Sume "output%1$sTest.java:3: error: ';' expected\n" + 52143420Sume " abcdefg\n" + 53143420Sume " ^\n" + 54143420Sume "2 errors\n"; 55122509Sume 56 public static void main(String[] args) throws Exception { 57 new CheckEBCDICLocaleTest().test(); 58 } 59 60 public void test() throws Exception { 61 String native2asciiBinary = Paths.get( 62 System.getProperty("test.jdk"),"bin", "native2ascii").toString(); 63 64 ToolBox.createJavaFileFromSource(TestSrc); 65 Files.createDirectory(Paths.get("output")); 66 67 ToolBox.AnyToolArgs nativeCmdParams = 68 new ToolBox.AnyToolArgs() 69 .appendArgs(native2asciiBinary) 70 .appendArgs(ToolBox.testToolVMOpts) 71 .appendArgs("-reverse", "-encoding", "IBM1047", "Test.java", 72 "output/Test.java"); 73 ToolBox.executeCommand(nativeCmdParams); 74 75 ToolBox.AnyToolArgs javacParams = 76 new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) 77 .appendArgs(ToolBox.javacBinary) 78 .appendArgs(ToolBox.testToolVMOpts) 79 .appendArgs("-J-Duser.language=en", 80 "-J-Duser.region=US", "-J-Dfile.encoding=IBM1047", 81 "output/Test.java") 82 .setErrOutput(new File("Test.tmp")); 83 ToolBox.executeCommand(javacParams); 84 85 nativeCmdParams = new ToolBox.AnyToolArgs() 86 .appendArgs(native2asciiBinary) 87 .appendArgs(ToolBox.testToolVMOpts) 88 .appendArgs("-encoding", "IBM1047", "Test.tmp", "Test.out"); 89 ToolBox.executeCommand(nativeCmdParams); 90 91 String goldenFile = String.format(TestOutTemplate, File.separator); 92 ToolBox.compareLines(Paths.get("Test.out"), 93 Arrays.asList(goldenFile.split("\n")), null, true); 94 } 95 96} 97