| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package com.netscape.javascript.qa.drivers; |
| 7 |
|
| 8 |
import com.netscape.javascript.qa.liveconnect.LiveConnectTest; |
| 9 |
import java.lang.*; |
| 10 |
import java.io.*; |
| 11 |
import java.util.Vector; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class LiveConnectEnv implements TestEnvironment { |
| 42 |
TestFile file; |
| 43 |
TestSuite suite; |
| 44 |
LiveConnectDrv driver; |
| 45 |
ObservedTask task; |
| 46 |
String TEMP_LOG_NAME; |
| 47 |
File helper; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public LiveConnectEnv( TestFile f, TestSuite s, LiveConnectDrv d) { |
| 53 |
this.file = f; |
| 54 |
this.suite = s; |
| 55 |
this.driver = d; |
| 56 |
this.TEMP_LOG_NAME = "js" + getRandomFileName() +".tmp"; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public synchronized void runTest() { |
| 63 |
try { |
| 64 |
createContext(); |
| 65 |
file.startTime = driver.getCurrentTime(); |
| 66 |
executeTestFile(); |
| 67 |
file.endTime = driver.getCurrentTime(); |
| 68 |
|
| 69 |
if (task.getExitValue() != 0) { |
| 70 |
System.out.println( "Abmormal program termination. "+ |
| 71 |
"Exit value: " + task.getExitValue() ); |
| 72 |
if ( file.name.endsWith( "-n.js" )) { |
| 73 |
file.passed = true; |
| 74 |
} else { |
| 75 |
file.exception = "Process exit value: " + task.getExitValue(); |
| 76 |
suite.passed = false; |
| 77 |
file.passed = false; |
| 78 |
} |
| 79 |
} |
| 80 |
parseResult(); |
| 81 |
|
| 82 |
} catch ( Exception e ) { |
| 83 |
suite.passed = false; |
| 84 |
file.passed = false; |
| 85 |
e.printStackTrace(); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public Object createContext() { |
| 94 |
task = new ObservedTask( driver.EXECUTABLE + " " + |
| 95 |
driver.HELPER_FUNCTIONS.getAbsolutePath() + " " + |
| 96 |
file.filePath +" "+ |
| 97 |
TEMP_LOG_NAME, |
| 98 |
this ); |
| 99 |
return (Object) task; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public Object executeTestFile() { |
| 106 |
try { |
| 107 |
task.exec(); |
| 108 |
} catch ( IOException e ) { |
| 109 |
System.err.println( e ); |
| 110 |
file.exception = e.toString(); |
| 111 |
} |
| 112 |
return null; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public synchronized boolean parseResult() { |
| 129 |
String line; |
| 130 |
BufferedReader buf = new BufferedReader(new StringReader( |
| 131 |
new String(task.getInput()))); |
| 132 |
try { |
| 133 |
do { |
| 134 |
line = buf.readLine(); |
| 135 |
System.out.println( line ); |
| 136 |
} while( line != null ) ; |
| 137 |
} catch ( IOException e ) { |
| 138 |
System.err.println( "Exception reading process output:" + |
| 139 |
e.toString() ); |
| 140 |
file.exception = e.toString(); |
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
Vector label = null; |
| 145 |
Vector value = null; |
| 146 |
|
| 147 |
String t = null; |
| 148 |
|
| 149 |
try { |
| 150 |
FileReader fr = new FileReader( |
| 151 |
driver.OUTPUT_DIRECTORY.getAbsolutePath()+ |
| 152 |
TEMP_LOG_NAME ); |
| 153 |
|
| 154 |
BufferedReader br = new BufferedReader( fr ); |
| 155 |
String classname = br.readLine(); |
| 156 |
boolean passed = (new Boolean(br.readLine())).booleanValue(); |
| 157 |
int length = (new Double(br.readLine())).intValue(); |
| 158 |
int no_passed = (new Double(br.readLine())).intValue(); |
| 159 |
int no_failed = (new Double(br.readLine())).intValue(); |
| 160 |
String bugnumber = br.readLine(); |
| 161 |
|
| 162 |
if ( ! passed ) { |
| 163 |
this.file.passed = false; |
| 164 |
this.suite.passed = false; |
| 165 |
} |
| 166 |
this.file.totalCases += length; |
| 167 |
this.suite.totalCases += length; |
| 168 |
this.file.casesPassed += no_passed; |
| 169 |
this.suite.casesPassed += no_passed; |
| 170 |
this.file.casesFailed += no_failed; |
| 171 |
this.suite.casesFailed += no_failed; |
| 172 |
this.file.bugnumber = bugnumber; |
| 173 |
|
| 174 |
} catch ( IOException e ) { |
| 175 |
System.err.println( e ); |
| 176 |
e.printStackTrace(); |
| 177 |
} |
| 178 |
return true; |
| 179 |
} |
| 180 |
|
| 181 |
public String getRandomFileName() { |
| 182 |
return (Integer.toString((new Double(Math.random()*100000)).intValue())); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public void close(){ |
| 190 |
String templog = driver.OUTPUT_DIRECTORY + TEMP_LOG_NAME; |
| 191 |
try { |
| 192 |
File f = new File ( templog ); |
| 193 |
if ( f.exists() ) { |
| 194 |
f.delete(); |
| 195 |
} |
| 196 |
} catch ( Exception e ) { |
| 197 |
e.printStackTrace(); |
| 198 |
} |
| 199 |
return; |
| 200 |
} |
| 201 |
|
| 202 |
void p( String s ) { |
| 203 |
System.out.println( s ); |
| 204 |
} |
| 205 |
|
| 206 |
} |