1 18 package com.Ostermiller.util; 19 20 import java.io.*; 21 import java.util.*; 22 23 33 class ExecHelperTests { 34 35 public static void main(String args[]){ 36 try { 37 File temp = File.createTempFile("ExecHelperTests", "tmp"); 38 temp.deleteOnExit(); 39 String s = createLargeString(); 40 Writer out = new FileWriter(temp); 41 out.write(s); 42 out.close(); 43 ExecHelper eh = ExecHelper.exec(new String []{"cat", temp.toString()}); 44 if (!eh.getOutput().equals(s)){ 45 throw new Exception ("Couldn't read file via cat"); 46 } 47 File sh = new File("/bin/sh"); 49 if (sh.exists()){ 50 eh = ExecHelper.execUsingShell("sleep 3; echo -n stdin && echo -n stderr 1>&2; exit 11"); 51 if (!eh.getOutput().equals("stdin")){ 52 throw new Exception ("Couldn't echo to stdin through a shell."); 53 } 54 if (!eh.getError().equals("stderr")){ 55 throw new Exception ("Couldn't echo to stderr through a shell."); 56 } 57 if (eh.getStatus() != 11){ 58 throw new Exception ("Expected exit status of 11."); 59 } 60 } 61 } catch (Exception x){ 62 x.printStackTrace(); 63 System.exit(1); 64 } 65 System.exit(0); 66 } 67 68 private static String createLargeString(){ 69 StringBuffer sb = new StringBuffer (40000*26); 70 for (int i=0; i<40000; i++){ 71 sb.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 72 } 73 return sb.toString(); 74 75 } 76 } 77 | Popular Tags |