| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package com.netscape.javascript.qa.drivers; |
| 7 |
|
| 8 |
import java.io.*; |
| 9 |
import java.util.StringTokenizer; |
| 10 |
|
| 11 |
|
| 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 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public class RefEnv implements TestEnvironment { |
| 66 |
TestFile file; |
| 67 |
TestSuite suite; |
| 68 |
RefDrv driver; |
| 69 |
ObservedTask task; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public RefEnv( TestFile f, TestSuite s, RefDrv d) { |
| 75 |
this.file = f; |
| 76 |
this.suite = s; |
| 77 |
this.driver = d; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public void runTest() { |
| 84 |
driver.p( file.name ); |
| 85 |
try { |
| 86 |
file.startTime = driver.getCurrentTime(); |
| 87 |
createContext(); |
| 88 |
executeTestFile(); |
| 89 |
file.endTime = driver.getCurrentTime(); |
| 90 |
|
| 91 |
if (task.getExitValue() != 0) { |
| 92 |
if ( file.name.endsWith( "-n.js" )) { |
| 93 |
file.passed = true; |
| 94 |
} else { |
| 95 |
suite.passed = false; |
| 96 |
file.passed = false; |
| 97 |
} |
| 98 |
} |
| 99 |
if ( ! parseResult() ) { |
| 100 |
if ( file.name.endsWith( "-n.js" ) ) { |
| 101 |
file.passed = true; |
| 102 |
} else { |
| 103 |
suite.passed = false; |
| 104 |
file.passed = false; |
| 105 |
} |
| 106 |
file.exception = new String(task.getError()); |
| 107 |
} |
| 108 |
|
| 109 |
} catch ( Exception e ) { |
| 110 |
suite.passed = false; |
| 111 |
file.passed = false; |
| 112 |
file.exception = "Unknown process exception."; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public Object createContext() { |
| 127 |
if ( driver.CODE_COVERAGE ) { |
| 128 |
String command = "coverage " + |
| 129 |
"/SaveMergeData /SaveMergeTextData "+ |
| 130 |
driver.EXECUTABLE + " -f " + |
| 131 |
driver.HELPER_FUNCTIONS.getAbsolutePath() + " -f " + |
| 132 |
file.filePath; |
| 133 |
|
| 134 |
System.out.println( "command is " + command ); |
| 135 |
|
| 136 |
task = new ObservedTask( command, this ); |
| 137 |
} else { |
| 138 |
task = new ObservedTask( driver.EXECUTABLE + " -f " + |
| 139 |
driver.HELPER_FUNCTIONS.getAbsolutePath() + " -f " + |
| 140 |
file.filePath, this); |
| 141 |
} |
| 142 |
return (Object) task; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public Object executeTestFile() { |
| 149 |
try { |
| 150 |
task.exec(); |
| 151 |
} catch ( IOException e ) { |
| 152 |
driver.p( e.toString() ); |
| 153 |
file.exception = e.toString(); |
| 154 |
e.printStackTrace(); |
| 155 |
} |
| 156 |
return null; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public boolean parseResult() { |
| 164 |
String line; |
| 165 |
int i,j; |
| 166 |
|
| 167 |
BufferedReader br = new BufferedReader(new StringReader( |
| 168 |
new String(task.getInput()))); |
| 169 |
try { |
| 170 |
do { |
| 171 |
line = br.readLine(); |
| 172 |
driver.p( line ); |
| 173 |
|
| 174 |
if (line == null) { |
| 175 |
driver.p("\tERROR: No lines to read"); |
| 176 |
return false; |
| 177 |
} |
| 178 |
} while (!line.equals(sizeTag)); |
| 179 |
|
| 180 |
if ((line = br.readLine()) == null) |
| 181 |
return false; |
| 182 |
|
| 183 |
file.totalCases = Integer.valueOf(line).intValue(); |
| 184 |
|
| 185 |
if ((line = br.readLine()) == null) { |
| 186 |
driver.p("\tERROR: No lines after " + sizeTag); |
| 187 |
return false; |
| 188 |
} |
| 189 |
|
| 190 |
} catch (NumberFormatException nfe) { |
| 191 |
driver.p("\tERROR: No integer after " + sizeTag); |
| 192 |
return false; |
| 193 |
} catch ( IOException e ) { |
| 194 |
driver.p( "Exception reading process output:" + e.toString() ); |
| 195 |
file.exception = e.toString(); |
| 196 |
return false; |
| 197 |
} |
| 198 |
|
| 199 |
for ( i = 0; i < file.totalCases; i++) { |
| 200 |
String values[] = new String[tags.length]; |
| 201 |
try { |
| 202 |
for ( j = 0; j < tags.length; j++) { |
| 203 |
values[j] = null; |
| 204 |
|
| 205 |
if (!line.startsWith(tags[j])) { |
| 206 |
driver.p("line didn't start with " + tags[j] +":"+line); |
| 207 |
return false; |
| 208 |
} |
| 209 |
while (((line = br.readLine()) != null) && |
| 210 |
(!(line.startsWith(startTag)))) |
| 211 |
{ |
| 212 |
values[j] = (values[j] == null) ? line : (values[j] + |
| 213 |
"\n" + line); |
| 214 |
} |
| 215 |
if (values[j] == null) values[j] = ""; |
| 216 |
} |
| 217 |
if ((line == null) && (i < file.totalCases - 1)) { |
| 218 |
driver.p("line == null and " + i + "<" + |
| 219 |
(file.totalCases - 1)); |
| 220 |
return false; |
| 221 |
} |
| 222 |
} catch ( IOException e ) { |
| 223 |
driver.p( "Exception reading process output: " + e ); |
| 224 |
file.exception = e.toString(); |
| 225 |
return false; |
| 226 |
} |
| 227 |
|
| 228 |
TestCase rt = new TestCase(values[0],values[1],values[4],values[2], |
| 229 |
values[3],values[5]); |
| 230 |
|
| 231 |
file.bugnumber = values[6]; |
| 232 |
file.caseVector.addElement( rt ); |
| 233 |
|
| 234 |
if ( rt.passed.equals("false") ) { |
| 235 |
if ( file.name.endsWith( "-n.js" ) ) { |
| 236 |
this.file.passed = true; |
| 237 |
} else { |
| 238 |
this.file.passed = false; |
| 239 |
this.suite.passed = false; |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
if ( file.totalCases == 0 ) { |
| 246 |
if ( file.name.endsWith( "-n.js" ) ) { |
| 247 |
this.file.passed = true; |
| 248 |
} else { |
| 249 |
this.file.reason = "File contains no testcases. " + this.file.reason; |
| 250 |
this.file.passed = false; |
| 251 |
this.suite.passed = false; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
return true; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public void close(){ |
| 262 |
return; |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public static final String tags[]; |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public static final String sizeTag = "<#TEST CASES SIZE>"; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
public static final String startTag = "<#TEST CASE"; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
public static final String endTag = ">"; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
static { |
| 286 |
String fields[] = { "PASSED", "NAME", "EXPECTED", "ACTUAL", "DESCRIPTION", "REASON", |
| 287 |
"BUGNUMBER" }; |
| 288 |
|
| 289 |
tags = new String[fields.length]; |
| 290 |
|
| 291 |
for (int i = 0; i < fields.length; ++i) { |
| 292 |
tags[i] = startTag + " " + fields[i] + endTag; |
| 293 |
} |
| 294 |
} |
| 295 |
} |