Path: blob/master/test/jdk/java/io/File/IsHidden.java
41149 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 4131223 647035425@summary Basic test for isHidden method26*/2728import java.io.*;29import java.nio.file.Files;30import java.nio.file.attribute.DosFileAttributeView;3132public class IsHidden {3334private static String dir = System.getProperty("test.dir", ".");3536private static void ck(String path, boolean ans) throws Exception {37File f = new File(path);38boolean x = f.isHidden();39if (x != ans)40throw new Exception(path + ": expected " + ans + ", got " + x);41System.err.println(path + " ==> " + x);42}4344private static void setHidden(File f, boolean value) throws IOException {45Files.getFileAttributeView(f.toPath(), DosFileAttributeView.class).setHidden(value);46}4748private static void checkHidden(File f) {49if (!f.isHidden())50throw new RuntimeException(f + " should be hidden");51}5253private static void testWin32() throws Exception {54File f = new File(dir, "test");55f.deleteOnExit();56f.createNewFile();57setHidden(f, true);58try {59ck(f.getPath(), true);60} finally {61setHidden(f, false);62}63ck(".foo", false);64ck("foo", false);6566File pagefile = new File("C:\\pagefile.sys");67File hiberfil = new File("C:\\hiberfil.sys");68if (pagefile.exists()) checkHidden(pagefile);69if (hiberfil.exists()) checkHidden(hiberfil);70}7172private static void testUnix() throws Exception {73ck(dir + "/IsHidden.java", false);74ck(dir + "/.", true);75ck(".", true);76ck("..", true);77ck(".foo", true);78ck("foo", false);79ck("", false);80}8182public static void main(String[] args) throws Exception {83if (File.separatorChar == '\\') testWin32();84if (File.separatorChar == '/') testUnix();85}8687}888990