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 
31 import java.io.File;
32 import java.io.IOException;
33 import java.nio.file.InvalidPathException;
34 import java.nio.charset.UnmappableCharacterException;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 
38 public class DiacriticTest extends TestHelper {
39 
40     // NFD-normalized form of the class name
41     static String NAME_NFD="ClassA\u0301";
42     // NFC-normalized form of the same class name
43     static String NAME_NFC="Class\u00C1";
44 
main(String[] args)45     public static void main(String[] args) throws IOException {
46         if (!isMacOSX) {
47             System.out.println("This test is for Mac OS X only. Passing.");
48             return;
49         }
50 
51         String lang = System.getenv("LANG");
52         if (lang != null && !lang.contains("UTF-8")) {
53             System.out.println("LANG variable set to the language that " +
54                                "does not support unicode, test passes vacuously");
55             return;
56         }
57 
58         File sourceFile = new File(NAME_NFC + ".java");
59         String source = "public class " + NAME_NFC + " { " +
60                 "    public static void main(String args[]) {\n" +
61                 "        System.out.println(\"Success!\");\n" +
62                 "    }\n" +
63                 "}\n";
64         ArrayList<String> content = new ArrayList<>();
65         content.add(source);
66         try {
67             createFile(sourceFile, content);
68         } catch (UnmappableCharacterException | InvalidPathException ipe) {
69             System.out.println("The locale or file system is configured in a way " +
70                                "that prevents file creation. Real testing impossible.");
71             return;
72         }
73 
74         HashMap<String, String> env = new HashMap<>();
75         env.put("LC_CTYPE", "UTF-8");
76 
77         TestResult tr;
78         tr = doExec(env, javacCmd, NAME_NFD + ".java");
79         System.out.println(tr.testOutput);
80         if (!tr.isOK()) {
81             System.out.println(tr);
82             throw new RuntimeException("Compilation failed");
83         }
84         tr = doExec(env, javaCmd, "-cp", ".", NAME_NFD);
85         System.out.println(tr.testOutput);
86         if (!tr.isOK()) {
87             System.out.println(tr);
88             throw new RuntimeException("Test execution failed");
89         }
90     }
91 }
92