DiacriticTest.java revision 8729:0242fce0f717
1/* 2 * Copyright (c) 2013, 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 8017248 27 * @summary Compiler Diacritics Issue 28 * @run main DiacriticTest 29 */ 30 31import java.io.File; 32import java.io.IOException; 33import java.util.ArrayList; 34import java.util.HashMap; 35 36public class DiacriticTest extends TestHelper { 37 38 // NFD-normalized form of the class name 39 static String NAME_NFD="ClassA\u0301"; 40 // NFC-normalized form of the same class name 41 static String NAME_NFC="Class\u00C1"; 42 43 public static void main(String[] args) throws IOException { 44 if (!isMacOSX) { 45 System.out.println("This test is for Mac OS X only. Passing."); 46 return; 47 } 48 49 File sourceFile = new File(NAME_NFC + ".java"); 50 String source = "public class " + NAME_NFC + " { " + 51 " public static void main(String args[]) {\n" + 52 " System.out.println(\"Success!\");\n" + 53 " }\n" + 54 "}\n"; 55 ArrayList<String> content = new ArrayList<>(); 56 content.add(source); 57 try { 58 createFile(sourceFile, content); 59 } catch (java.nio.file.InvalidPathException ipe) { 60 System.out.println("The locale or file system is configured in a way " + 61 "that prevents file creation. Real testing impossible."); 62 return; 63 } 64 65 HashMap<String, String> env = new HashMap<>(); 66 env.put("LC_CTYPE", "UTF-8"); 67 68 TestResult tr; 69 tr = doExec(env, javacCmd, NAME_NFD + ".java"); 70 System.out.println(tr.testOutput); 71 if (!tr.isOK()) { 72 System.out.println(tr); 73 throw new RuntimeException("Compilation failed"); 74 } 75 tr = doExec(env, javaCmd, "-cp", ".", NAME_NFD); 76 System.out.println(tr.testOutput); 77 if (!tr.isOK()) { 78 System.out.println(tr); 79 throw new RuntimeException("Test execution failed"); 80 } 81 } 82} 83