< prev index next >

test/jdk/java/io/File/GetXSpace.java

Print this page

        

*** 22,49 **** */ /** * @test * @bug 4057701 6286712 6364377 ! * @requires (os.family == "linux" | os.family == "mac" | os.family == "windows") ! * @run build GetXSpace ! * @run shell GetXSpace.sh * @summary Basic functionality of File.get-X-Space methods. - * @key randomness */ import java.io.BufferedReader; import java.io.File; import java.io.FilePermission; import java.io.InputStreamReader; import java.io.IOException; import java.nio.file.Files; import java.security.Permission; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; import static java.lang.System.out; public class GetXSpace { private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(), --- 22,49 ---- */ /** * @test * @bug 4057701 6286712 6364377 ! * @requires (os.family == "linux" | os.family == "mac" | ! * os.family == "windows") * @summary Basic functionality of File.get-X-Space methods. */ import java.io.BufferedReader; import java.io.File; import java.io.FilePermission; import java.io.InputStreamReader; import java.io.IOException; import java.nio.file.Files; + import java.nio.file.Path; import java.security.Permission; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; + import static java.lang.System.err; import static java.lang.System.out; public class GetXSpace { private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(),
*** 58,67 **** --- 58,73 ---- private static int fail = 0; private static int pass = 0; private static Throwable first; + static void reset() { + fail = 0; + pass = 0; + first = null; + } + static void pass() { pass++; } static void fail(String p) {
*** 329,350 **** public void checkRead(String file) { throw new SecurityException(err); } } ! private static void testFile(String dirName) { out.format("--- Testing %s%n", dirName); ArrayList<Space> l; try { l = space(dirName); } catch (IOException x) { throw new RuntimeException(dirName + " can't get file system information", x); } compare(l.get(0)); } ! private static void testDF() { out.println("--- Testing df"); // Find all of the partitions on the machine and verify that the size // returned by "df" is equivalent to File.getXSpace() values. ArrayList<Space> l; try { --- 335,366 ---- public void checkRead(String file) { throw new SecurityException(err); } } ! private static int testFile(Path dir) { ! String dirName = dir.toString(); out.format("--- Testing %s%n", dirName); ArrayList<Space> l; try { l = space(dirName); } catch (IOException x) { throw new RuntimeException(dirName + " can't get file system information", x); } compare(l.get(0)); + + if (fail != 0) { + err.format("%d tests: %d failure(s); first: %s%n", + fail + pass, fail, first); + } else { + out.format("all %d tests passed%n", fail + pass); } ! return fail != 0 ? 1 : 0; ! } ! ! private static int testDF() { out.println("--- Testing df"); // Find all of the partitions on the machine and verify that the size // returned by "df" is equivalent to File.getXSpace() values. ArrayList<Space> l; try {
*** 372,393 **** compareZeroNonExist(); compareZeroExist(); } } } - } ! public static void main(String [] args) { ! if (args.length > 0) { ! testFile(args[0]); ! } else { ! testDF(); ! } if (fail != 0) { ! throw new RuntimeException((fail + pass) + " tests: " ! + fail + " failure(s), first", first); } else { out.format("all %d tests passed%n", fail + pass); } } } --- 388,440 ---- compareZeroNonExist(); compareZeroExist(); } } } ! System.setSecurityManager(null); if (fail != 0) { ! err.format("%d tests: %d failure(s); first: %s%n", ! fail + pass, fail, first); } else { out.format("all %d tests passed%n", fail + pass); } + + return fail != 0 ? 1 : 0; + } + + private static void perms(File file, boolean allow) throws IOException { + file.setExecutable(allow, false); + file.setReadable(allow, false); + file.setWritable(allow, false); + } + + private static void deny(Path path) throws IOException { + perms(path.toFile(), false); + } + + private static void allow(Path path) throws IOException { + perms(path.toFile(), true); + } + + public static void main(String[] args) throws Exception { + int failedTests = testDF(); + reset(); + + Path tmpDir = Files.createTempDirectory(null); + Path tmpSubdir = Files.createTempDirectory(tmpDir, null); + Path tmpFile = Files.createTempFile(tmpSubdir, "foo", null); + + deny(tmpSubdir); + failedTests += testFile(tmpFile); + + allow(tmpSubdir); + Files.delete(tmpFile); + Files.delete(tmpSubdir); + Files.delete(tmpDir); + + if (failedTests > 0) { + throw new RuntimeException(failedTests + " test(s) failed"); + } } }
< prev index next >