Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8181919: Refactor test/java/io/File/GetXSpace.sh to java test
Reviewed-by: naoto
  • Loading branch information
Brian Burkhalter committed Aug 14, 2020
1 parent 4741abb commit d0b46ecf4f1ebc38c4f3d8778538eaf090d0a9bd
Showing with 63 additions and 98 deletions.
  1. +63 −16 test/jdk/java/io/File/GetXSpace.java
  2. +0 −82 test/jdk/java/io/File/GetXSpace.sh
@@ -23,12 +23,10 @@

/**
* @test
* @bug 4057701 6286712 6364377
* @requires (os.family == "linux" | os.family == "mac" | os.family == "windows")
* @run build GetXSpace
* @run shell GetXSpace.sh
* @bug 4057701 6286712 6364377 8181919
* @requires (os.family == "linux" | os.family == "mac" |
* os.family == "windows")
* @summary Basic functionality of File.get-X-Space methods.
* @key randomness
*/

import java.io.BufferedReader;
@@ -38,11 +36,13 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.FileStore;
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 {
@@ -61,6 +61,12 @@ public class GetXSpace {
private static int pass = 0;
private static Throwable first;

static void reset() {
fail = 0;
pass = 0;
first = null;
}

static void pass() {
pass++;
}
@@ -338,7 +344,8 @@ public void checkRead(String file) {
}
}

private static void testFile(String dirName) {
private static int testFile(Path dir) {
String dirName = dir.toString();
out.format("--- Testing %s%n", dirName);
ArrayList<Space> l;
try {
@@ -347,9 +354,18 @@ private static void testFile(String dirName) {
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 void testDF() {
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.
@@ -381,20 +397,51 @@ private static void testDF() {
}
}
}
}

public static void main(String [] args) {
if (args.length > 0) {
testFile(args[0]);
} else {
testDF();
}
System.setSecurityManager(null);

if (fail != 0) {
throw new RuntimeException((fail + pass) + " tests: "
+ fail + " failure(s), first", first);
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");
}
}
}

This file was deleted.

0 comments on commit d0b46ec

Please sign in to comment.