jdk/test/sun/tools/native2ascii/NativeErrors.java
changeset 4319 47bb128ae7b3
parent 2 90ce3da70b43
child 5506 202f599c92aa
--- a/jdk/test/sun/tools/native2ascii/NativeErrors.java	Mon Nov 16 15:33:05 2009 +0100
+++ b/jdk/test/sun/tools/native2ascii/NativeErrors.java	Wed Nov 18 11:10:18 2009 -0800
@@ -59,15 +59,28 @@
         in = new BufferedReader(new InputStreamReader(p.getInputStream()));
         checkResult(in, "err.bad.arg");
 
-        command = getComString("test123");
+        File f0 = new File(System.getProperty("test.src", "."), "test123");
+        String path0 = f0.getPath();
+        if ( f0.exists() ) {
+            throw new Error("Input file should not exist: " + path0);
+        }
+
+        command = getComString(path0);
         p = Runtime.getRuntime().exec(command);
         in = new BufferedReader(new InputStreamReader(p.getInputStream()));
         checkResult(in, "err.cannot.read");
 
         File f1 = new File(System.getProperty("test.src", "."), "test1");
-        File f2 = new File(System.getProperty("test.src", "."), "test2");
+        File f2 = File.createTempFile("test2", ".tmp");
         String path1 = f1.getPath();
         String path2 = f2.getPath();
+        if ( !f1.exists() ) {
+            throw new Error("Missing input file: " + path1);
+        }
+        if ( !f2.setWritable(false) ) {
+            throw new Error("Output file cannot be made read only: " + path2);
+        }
+        f2.deleteOnExit();
 
         command = getComString(path1, path2);
         p = Runtime.getRuntime().exec(command);
@@ -80,7 +93,9 @@
                                                            throws Exception {
         String errorReceived;
         errorReceived = in.readLine();
+        assert errorReceived != null : "First readline cannot be null";
         errorExpected = rsrc.getString(errorExpected);
+        assert errorExpected != null : "Expected message cannot be null";
         StringBuffer error = new StringBuffer(errorExpected);
         int start = errorExpected.indexOf("{0}");
         if (start >= 0) {
@@ -128,6 +143,7 @@
             f = new File(path);
             if (!f.exists())
                 throw new RuntimeException("Cannot find native2ascii at "+path);
+            System.out.println("Using native2ascii at "+path);
         }
         return path;
     }