./test/java/io/IOException/LastErrorString.java

Print this page
rev 4099 : LastErrorString test fixed.

@@ -19,13 +19,17 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-/* @test
-   @bug 4167937
-   @summary Test code paths that use the JVM_LastErrorString procedure
+/*
+ * @test
+ * @bug 4167937
+ * @summary Test code paths that use the JVM_LastErrorString procedure
+ *
+ * @compile LastErrorString.java
+ * @run shell LastErrorString.sh
  */
 
 import java.io.IOException;
 import java.io.File;
 import java.io.FileInputStream;

@@ -35,37 +39,15 @@
 
 public class LastErrorString {
 
     static String UNWRITEABLE_DIR;
     static String UNREADABLE_FILE;
+    static String UNWRITEABLE_FILE;
     static String READABLE_FILE;
     static String WRITEABLE_FILE;
     static String INVALID_PATH;
 
-    static {
-        if (File.separatorChar == '/') {
-            UNWRITEABLE_DIR = "/etc/dfs";
-            UNREADABLE_FILE = "/etc/shadow";
-        } else if (File.separatorChar == '\\') {
-            UNREADABLE_FILE = "c:/pagefile.sys";
-            UNWRITEABLE_DIR = "z:/fooBAR/baz/GORP";
-        } else {
-            throw new RuntimeException("What kind of system is this?");
-        }
-        File d = new File(System.getProperty("test.src", "."));
-        READABLE_FILE = new File(d, "LastErrorString.java").getPath();
-        WRITEABLE_FILE = "x.LastErrorString";
-        String s = "foo/";
-        for (;;) {
-            s = s + s;
-            if (s.length() > 8192) break;
-        }
-        s += "bar";
-        INVALID_PATH = s;
-    }
-
-
     static abstract class Test {
 
         String name;
 
         public Test(String name) {

@@ -195,11 +177,11 @@
                 in.available();
             }}.go();
 
         new Test("FileOutputStream") {
             public void run() throws IOException {
-                new FileOutputStream(UNREADABLE_FILE);
+                new FileOutputStream(UNWRITEABLE_FILE);
             }}.go();
 
         new ClosedFOSTest("write()") {
             public void run() throws IOException {
                 out.write(10);

@@ -255,11 +237,32 @@
                 raf.writeInt(10);
             }}.go();
 
     }
 
+    public static void preparePaths(String workDir) {
+        System.out.println("Work directory: " + workDir);
+
+        // directory prepared by shell script
+        UNWRITEABLE_DIR = workDir + "unwriteable_dir";
+
+        // files prepared by shell script
+        READABLE_FILE = workDir + "readable_file";
+        WRITEABLE_FILE = workDir + "writeable_file";
+        UNREADABLE_FILE = workDir + "unreadable_file";
+        UNWRITEABLE_FILE = workDir + "unwriteable_file";
+
+        String s = "foo/";
+        for (;;) {
+            s = s + s;
+            if (s.length() > 8192) break;
+        }
+        s += "bar";
+        INVALID_PATH = s;
+    }
 
     public static void main(String[] args) throws Exception {
+        preparePaths(args[0]);
         go();
     }
 
 }