1 /* 2 * Copyright (c) 2008, 2012, 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 /* @test 25 * @bug 7130915 26 * @summary Tests file path with nfc/nfd forms on MacOSX 27 * @library ../ 28 * @build MacPathTest 29 * @run shell MacPathTest.sh 30 */ 31 32 import java.nio.file.*; 33 import java.nio.file.attribute.*; 34 import java.text.*; 35 import java.util.*; 36 import java.util.regex.*; 37 38 public class MacPathTest { 39 40 public static void main(String args[]) throws Throwable { 41 String osname = System.getProperty("os.name"); 42 if (!osname.contains("OS X") && !osname.contains("Darwin")) 43 return; 44 System.out.printf("sun.jnu.encoding=%s, file.encoding=%s%n", 45 System.getProperty("file.encoding"), 46 System.getProperty("sun.jnu.encoding")); 47 // English 48 test("TestDir_apple", // test dir 49 "dir_macosx", // dir 50 "file_macosx"); // file 51 52 // Japanese composite character 53 test("TestDir_\u30c8\u30a4\u30e4\u30cb\u30ca\u30eb/", 54 "dir_\u30a4\u30c1\u30b4\u306e\u30b1\u30fc\u30ad", 55 "file_\u30a4\u30c1\u30b4\u306e\u30b1\u30fc\u30ad"); 56 57 // latin-1 supplementory 58 test("TestDir_K\u00f6rperlich\u00e4\u00df/", 59 "dir_Entt\u00e4uschung", 60 "file_Entt\u00e4uschung"); 61 62 test("TestDir_K\u00f6rperlich\u00e4\u00df/", 63 "dir_Entt\u00c4uschung", 64 "file_Entt\u00c4uschung"); 65 66 // Korean syblla 67 test("TestDir_\uac00\uac01\uac02", 68 "dir_\uac20\uac21\uac22", 69 "file_\uacc0\uacc1\uacc2"); 70 } 71 72 private static boolean equal(Object x, Object y) { 73 return x == null ? y == null : x.equals(y); 74 } 75 76 private static boolean match(Path target, Path src) { 77 String fname = target.toString(); 78 System.out.printf(" --> Trying [%s], length=%d...", fname, fname.length()); 79 if (target.equals(src)) { 80 System.out.println(" MATCHED!"); 81 return true; 82 } else { 83 System.out.println(" NOT MATCHED!"); 84 } 85 return false; 86 } 87 88 private static void test(String testdir, String dname, String fname_nfc) 89 throws Throwable | 1 /* 2 * Copyright (c) 2008, 2017, 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 7130915 27 * @summary Tests file path with nfc/nfd forms on MacOSX 28 * @requires (os.family == "mac") 29 * @library /java/nio/file 30 * @run main/othervm -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 MacPathTest 31 */ 32 33 import java.nio.file.DirectoryStream; 34 import java.nio.file.Files; 35 import java.nio.file.Path; 36 import java.nio.file.Paths; 37 import java.nio.file.attribute.PosixFilePermission; 38 import java.text.Normalizer; 39 import java.util.Locale; 40 import java.util.Set; 41 import java.util.regex.Pattern; 42 43 public class MacPathTest { 44 private static final String JNU_ENCODING = System.getProperty("sun.jnu.encoding"); 45 private static final String FILE_ENCODING = System.getProperty("file.encoding"); 46 47 public static void main(String args[]) throws Throwable { 48 if (!(FILE_ENCODING.equals("UTF-8") && JNU_ENCODING.equals("UTF-8"))) { 49 System.out.println("Warning: This test requires UTF-8, current encoding:" 50 + " sun.jnu.encoding = " + JNU_ENCODING + "," 51 + " file.encoding = " + FILE_ENCODING + "\n" 52 + "Test skipped.\n" 53 + "\nRun test with:\n" 54 + "java -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 MacPathTest"); 55 return; 56 } 57 58 Locale defaultLocale = Locale.getDefault(); 59 Locale.setDefault(Locale.US); 60 61 // English 62 test("TestDir_apple", // test dir 63 "dir_macosx", // dir 64 "file_macosx"); // file 65 66 // Japanese composite character 67 test("TestDir_\u30c8\u30a4\u30e4\u30cb\u30ca\u30eb/", 68 "dir_\u30a4\u30c1\u30b4\u306e\u30b1\u30fc\u30ad", 69 "file_\u30a4\u30c1\u30b4\u306e\u30b1\u30fc\u30ad"); 70 71 // latin-1 supplementory 72 test("TestDir_K\u00f6rperlich\u00e4\u00df/", 73 "dir_Entt\u00e4uschung", 74 "file_Entt\u00e4uschung"); 75 76 test("TestDir_K\u00f6rperlich\u00e4\u00df/", 77 "dir_Entt\u00c4uschung", 78 "file_Entt\u00c4uschung"); 79 80 // Korean syblla 81 test("TestDir_\uac00\uac01\uac02", 82 "dir_\uac20\uac21\uac22", 83 "file_\uacc0\uacc1\uacc2"); 84 85 Locale.setDefault(defaultLocale); //restore 86 } 87 88 private static boolean equal(Object x, Object y) { 89 return x == null ? y == null : x.equals(y); 90 } 91 92 private static boolean match(Path target, Path src) { 93 String fname = target.toString(); 94 System.out.printf(" --> Trying [%s], length=%d...", fname, fname.length()); 95 if (target.equals(src)) { 96 System.out.println(" MATCHED!"); 97 return true; 98 } else { 99 System.out.println(" NOT MATCHED!"); 100 } 101 return false; 102 } 103 104 private static void test(String testdir, String dname, String fname_nfc) 105 throws Throwable |