1 33 34 package edu.rice.cs.util.newjvm; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 import edu.rice.cs.drjava.config.FileOption; 38 import edu.rice.cs.util.StringOps; 39 40 import java.io.File ; 41 import java.io.IOException ; 42 43 48 public class ExecJVMTest extends DrJavaTestCase { 49 52 public void setUp() throws Exception { 53 super.setUp(); 54 } 56 57 public void testExecFileCreator() throws IOException , InterruptedException { 58 File tempFile = File.createTempFile("drjava-test", ".tmp").getCanonicalFile(); 59 assertTrue("temp file exists", tempFile.exists()); 60 boolean ret = tempFile.delete(); 61 assertTrue("temp file delete succeeded", ret); 62 63 String className = getClass().getName() + "$FileCreator"; 65 String tempName = tempFile.getAbsolutePath(); 66 Process jvm = ExecJVM.runJVMPropagateClassPath(className, new String [] { tempName }, FileOption.NULL_FILE); 67 68 int result = jvm.waitFor(); 69 70 try { 72 assertEquals("jvm exit code", 0, result); 73 assertTrue("jvm did not create file", tempFile.exists()); 74 assertTrue("jvm System.out not empty", jvm.getInputStream().read() == -1); 75 assertTrue("jvm System.err not empty", jvm.getErrorStream().read() == -1); 76 } 77 finally { } 78 79 ret = tempFile.delete(); 81 assertTrue("temp file delete succeeded", ret); 82 } 83 84 public static final class FileCreator { 85 public static void main(String [] args) { 86 File file = new File (args[0]); 87 boolean ret; 88 try { ret = file.createNewFile(); } 89 catch (IOException ioe) { ret = false; } 90 if (!ret) throw new RuntimeException ("file creation failed"); 91 System.exit(0); 92 } 93 } 94 95 public void testExecWorkingDirNotFound() throws IOException , InterruptedException { 96 File tempFile = File.createTempFile("drjava-test", ".tmp").getCanonicalFile(); 98 assertTrue("temp file exists", tempFile.exists()); 99 boolean ret = tempFile.delete(); 100 assertTrue("temp file delete succeeded", ret); 101 102 File tempDir = new File (tempFile.toString() + File.separatorChar); 104 ret = tempDir.mkdirs(); 105 assertTrue("temp dir exists", tempDir.exists()); 106 assertTrue("temp dir is dir", tempDir.isDirectory()); 107 ret = tempDir.delete(); 108 assertTrue("temp dir delete succeeded", ret); 109 110 String className = getClass().getName() + "$" + StringOps.getSimpleName(NoOp.class); 112 String tempName = tempFile.getAbsolutePath(); 113 Process jvm = ExecJVM.runJVMPropagateClassPath(className, new String [] { tempName }, tempDir); 114 115 int result = jvm.waitFor(); 116 117 try { 119 assertEquals("jvm exit code", 0, result); 120 assertTrue("jvm System.out not empty", jvm.getInputStream().read() == -1); 121 assertTrue("jvm System.err not empty", jvm.getErrorStream().read() == -1); 122 } 123 finally { 124 } 125 } 126 127 public static final class NoOp { 128 public static void main(String [] args) { 129 } 130 } 131 } 132 | Popular Tags |