blob: 8323a76041e0f1f3cf2265149787bc1b6a5313b7 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 @bug 4131223 6470354
26 @summary Basic test for isHidden method
27 */
28
29import java.io.*;
30
31
32public class IsHidden {
33
34 private static String dir = System.getProperty("test.dir", ".");
35
36 private static void ck(String path, boolean ans) throws Exception {
37 File f = new File(path);
38 boolean x = f.isHidden();
39 if (x != ans)
40 throw new Exception(path + ": expected " + ans + ", got " + x);
41 System.err.println(path + " ==> " + x);
42 }
43
44 private static void testWin32() throws Exception {
45 File f = new File(dir, "test");
46 f.deleteOnExit();
47 f.createNewFile();
48 String name = f.getCanonicalPath();
49 Process p = Runtime.getRuntime().exec("cmd.exe /c attrib +H " + name);
50 p.waitFor();
51 ck(name, true);
52
53 ck(".foo", false);
54 ck("foo", false);
55 }
56
57 private static void testUnix() throws Exception {
58 ck(dir + "/IsHidden.java", false);
59 ck(dir + "/.", true);
60 ck(".", true);
61 ck("..", true);
62 ck(".foo", true);
63 ck("foo", false);
64 ck("", false);
65 }
66
67 public static void main(String[] args) throws Exception {
68 if (File.separatorChar == '\\') testWin32();
69 if (File.separatorChar == '/') testUnix();
70 }
71
72}