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