0N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 5016938
0N/A * @summary Test file operations with Unicode filenames
0N/A * @author Martin Buchholz
0N/A */
0N/A
0N/Aimport java.io.*;
0N/A
0N/Apublic class Unicode
0N/A{
0N/A static int fail = 0;
0N/A static void fail(String msg) {
0N/A fail++;
0N/A System.err.println(msg);
0N/A }
0N/A
0N/A static boolean creat(File f) throws Exception {
0N/A try {
0N/A FileOutputStream out = new FileOutputStream(f);
0N/A out.write(new byte[]{'a', 'b', 'c'});
0N/A out.close();
0N/A // Check that the file we tried to create has the expected name
0N/A return find(f);
0N/A } catch (Exception e) {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A static boolean find(File f) throws Exception {
0N/A String fn = f.getPath();
0N/A String[] fns = new File(".").list();
0N/A for (int i = 0; i < fns.length; i++)
0N/A if (fns[i].equals(fn))
0N/A return true;
0N/A return false;
0N/A }
0N/A
0N/A static void sanityCheck(File f) throws Exception {
0N/A if (! f.exists()) fail("! f.exists()");
0N/A if ( f.length() != 3) fail(" f.length() != 3");
0N/A if ( f.isAbsolute()) fail(" f.isAbsolute()");
0N/A if (! f.canRead()) fail("! f.canRead()");
0N/A if (! f.canWrite()) fail("! f.canWrite()");
0N/A if ( f.isHidden()) fail(" f.isHidden()");
0N/A if (! f.isFile()) fail("! f.isFile()");
0N/A if ( f.isDirectory()) fail(" f.isDirectory()");
0N/A }
0N/A
0N/A public static void main(String [] args) throws Exception {
0N/A final File f1 = new File("\u0411.tst");
0N/A final File f2 = new File("\u0412.tst");
0N/A
0N/A try {
0N/A if (! creat(f1))
0N/A // Couldn't create file with Unicode filename?
0N/A return;
0N/A
0N/A System.out.println("This system supports Unicode filenames!");
0N/A sanityCheck(f1);
0N/A
0N/A f1.renameTo(f2);
0N/A sanityCheck(f2);
0N/A if (! f2.delete()) fail("! f2.delete()");
0N/A if ( f2.exists()) fail(" f2.exists()");
0N/A if ( f1.exists()) fail(" f1.exists()");
0N/A if ( f1.delete()) fail(" f1.delete()");
0N/A
0N/A if (fail != 0) throw new Exception(fail + " failures");
0N/A } finally {
0N/A f1.delete();
0N/A f2.delete();
0N/A }
0N/A }
0N/A}