1 /* 2 * Copyright (c) 2011, 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 * @summary <rdar://problem/4978208> Filename containing extended char problem using java io 27 * @summary com.apple.junit.java.io.File 28 * @run junit R4978208MultipleUmlautsTest 29 */ 30 31 import java.io.File; 32 import java.io.FileWriter; 33 import java.text.Collator; 34 import junit.framework.Test; 35 import junit.framework.TestCase; 36 import junit.framework.TestSuite; 37 38 public class R4978208MultipleUmlautsTest extends TestCase { 39 public static Test suite() { 40 return new TestSuite(R4978208MultipleUmlautsTest.class); 41 } 42 43 public static void main(String argv[]) { 44 junit.textui.TestRunner.run(suite()); 45 } 46 47 public void testFileWithMultipleUmlauts() throws Exception { 48 String fileName = "Test-&üäöߧ&.txt"; 49 String tmpDir = System.getProperty("java.io.tmpdir"); 50 createFile(tmpDir + File.separator + fileName); 51 52 File f = new File(tmpDir); 53 boolean found = false; 54 String[] files = f.list(); 55 for (String file : files) { 56 if (Collator.getInstance().equals(file, fileName)) 57 found = true; 58 } 59 assertTrue("File should exist but it doesn't", found); 60 } 61 62 /** Create the file with dummy content, will remove existing file first if exists */ 63 private void createFile(String fileName) throws Exception { 64 String data = "This is a test file"; 65 66 File file = new File(fileName); 67 if (file.exists()) { 68 file.delete(); 69 } 70 file.createNewFile(); 71 file.deleteOnExit(); 72 73 FileWriter fw = new FileWriter(file); 74 fw.write(data); 75 fw.close(); 76 } 77 }