| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package com.netscape.javascript.qa.liveconnect; |
| 6 |
|
| 7 |
import java.applet.Applet; |
| 8 |
import java.io.File; |
| 9 |
import java.util.Vector; |
| 10 |
import netscape.javascript.*; |
| 11 |
|
| 12 |
|
| 13 |
import com.netscape.javascript.qa.drivers.*; |
| 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 |
public class LiveConnectTest extends Applet implements Runnable { |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public LiveConnectTest() { |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public static void main( String[] args ) { |
| 74 |
LiveConnectTest test = new LiveConnectTest(); |
| 75 |
} |
| 76 |
|
| 77 |
public void start() { |
| 78 |
run(); |
| 79 |
} |
| 80 |
|
| 81 |
public void stop() { |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public void run() { |
| 90 |
System.out.println("Running the test." ); |
| 91 |
setupTestEnvironment(); |
| 92 |
file.startTime = TestDriver.getCurrentTime(); |
| 93 |
executeTest(); |
| 94 |
file.endTime= TestDriver.getCurrentTime(); |
| 95 |
getResults(); |
| 96 |
cleanupTestEnvironment(); |
| 97 |
stop(); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public void setupTestEnvironment() { |
| 104 |
global = JSObject.getWindow( this ); |
| 105 |
|
| 106 |
getEnvironment(); |
| 107 |
|
| 108 |
if ( ENVIRONMENT == BROWSER ) { |
| 109 |
|
| 110 |
|
| 111 |
} |
| 112 |
output = getOutputDirectory(); |
| 113 |
if (LOGGING) { |
| 114 |
TestDriver.openLogFiles( output ); |
| 115 |
templog = getTempLog( output ); |
| 116 |
} |
| 117 |
testdir = getTestDirectory(); |
| 118 |
file = new TestFile( this.getClass().getName(), testdir.toString() + |
| 119 |
this.getClass().toString() ); |
| 120 |
|
| 121 |
file.bugnumber = this.BUGNUMBER; |
| 122 |
file.description = ( this.getClass().toString() ); |
| 123 |
} |
| 124 |
|
| 125 |
public void getEnvironment() { |
| 126 |
this.ENVIRONMENT = ( global.getMember("version").equals( "undefined")) |
| 127 |
? BROWSER |
| 128 |
: SHELL; |
| 129 |
return; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public TestLog getTempLog( File output ) { |
| 138 |
String templog = ""; |
| 139 |
|
| 140 |
try { |
| 141 |
TEMP_LOG_NAME = ((String) global.getMember( "OUTPUT_FILE" )).equals |
| 142 |
("undefined") |
| 143 |
? TEMP_LOG_NAME |
| 144 |
: (String) global.getMember("OUTPUT_FILE"); |
| 145 |
|
| 146 |
templog = output.getAbsolutePath() + TEMP_LOG_NAME; |
| 147 |
} catch ( Exception e ) { |
| 148 |
this.exception = e.toString(); |
| 149 |
p("Exception deleting existing templog: " + e.toString() ); |
| 150 |
} |
| 151 |
|
| 152 |
return new TestLog( templog, "" ); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public File getOutputDirectory() { |
| 165 |
String o = ""; |
| 166 |
|
| 167 |
if ( this.ENVIRONMENT == BROWSER ) { |
| 168 |
String outputParam = this.getParameter( "output" ); |
| 169 |
|
| 170 |
return new File( getParameter( "output" ) ); |
| 171 |
} else { |
| 172 |
try { |
| 173 |
o = (String) global.getMember( "OUTPUT_DIRECTORY" ); |
| 174 |
|
| 175 |
if ( ! o.equals( "undefined") ) { |
| 176 |
LOGGING = true; |
| 177 |
} |
| 178 |
} catch ( Exception e ) { |
| 179 |
System.err.println( "OUTPUT_DIRECTORY threw: " + e ); |
| 180 |
e.printStackTrace(); |
| 181 |
System.exit(1); |
| 182 |
} |
| 183 |
|
| 184 |
System.out.println( "Output file is " + o.toString() ); |
| 185 |
|
| 186 |
return new File( o.toString() ); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public File getTestDirectory() { |
| 197 |
try { |
| 198 |
String o = (String) global.getMember( "TEST_DIRECTORY" ); |
| 199 |
o = o.endsWith( File.separator ) ? o : o + File.separator; |
| 200 |
return new File( o.toString() ); |
| 201 |
} catch ( Exception e ) { |
| 202 |
System.err.println( "TEST_DIRECTORY is not defined: " + e ); |
| 203 |
return new File( "." ); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public void executeTest() { |
| 214 |
return; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
public void addTestCase( String description, String expect, String actual, |
| 229 |
String exception ) |
| 230 |
{ |
| 231 |
String result = ( expect == actual ) ? "true" : "false"; |
| 232 |
TestCase tc = new TestCase( result, this.getClass().getName().toString(), |
| 233 |
description, expect, actual, exception ); |
| 234 |
file.caseVector.addElement( tc ); |
| 235 |
file.totalCases++; |
| 236 |
if ( result == "false" ) { |
| 237 |
file.passed = false; |
| 238 |
file.casesFailed++; |
| 239 |
} else { |
| 240 |
file.casesPassed++; |
| 241 |
} |
| 242 |
return; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
public void closeLogs() { |
| 250 |
TestDriver.getLog( output, TestDriver.SUMMARY_LOG_NAME ).closeLog(); |
| 251 |
TestDriver.getLog( output, TestDriver.SUITE_LOG_NAME ).closeLog(); |
| 252 |
TestDriver.getLog( output, TestDriver.FILE_LOG_NAME ).closeLog(); |
| 253 |
TestDriver.getLog( output, TestDriver.CASE_LOG_NAME ).closeLog(); |
| 254 |
templog.closeLog(); |
| 255 |
templog = null; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
public void getResults() { |
| 263 |
displayResults(); |
| 264 |
if (LOGGING) { |
| 265 |
writeResultsToCaseLog(); |
| 266 |
writeResultsToFileLog(); |
| 267 |
writeResultsToTempLog(); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public void displayResults() { |
| 276 |
for ( int i = 0; i < file.caseVector.size(); i++ ) { |
| 277 |
TestCase tc = (TestCase) file.caseVector.elementAt(i); |
| 278 |
p( tc.description +" = "+ tc.actual+ |
| 279 |
( tc.expect != tc.actual |
| 280 |
? " FAILED! expected: " + tc.expect |
| 281 |
: " PASSED!" ) ); |
| 282 |
} |
| 283 |
getFailedCases(); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public void writeResultsToCaseLog() { |
| 293 |
if ( !file.passed ) { |
| 294 |
TestDriver.writeCaseResults( file, file.description, output ); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
public void writeResultsToFileLog() { |
| 305 |
if ( !file.passed ) { |
| 306 |
TestDriver.writeFileResult(file, null, output); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public void writeResultsToTempLog(){ |
| 337 |
System.out.println( "Writing results to " + templog.toString() ); |
| 338 |
|
| 339 |
templog.writeLine( file.description ); |
| 340 |
templog.writeLine( file.passed + "" ); |
| 341 |
templog.writeLine( file.caseVector.size() +"" ); |
| 342 |
templog.writeLine( file.casesPassed + ""); |
| 343 |
templog.writeLine( file.casesFailed + ""); |
| 344 |
templog.writeLine( file.bugnumber ); |
| 345 |
|
| 346 |
p( file.name ); |
| 347 |
p( "passed: " + passed ); |
| 348 |
p( "total cases: " + file.caseVector.size() ); |
| 349 |
p( "cases passed: " + file.casesPassed ); |
| 350 |
p( "cases failed: " + file.casesFailed ); |
| 351 |
p( "bugnumber: " + file.bugnumber ); |
| 352 |
return; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
public void cleanupTestEnvironment() { |
| 361 |
try { |
| 362 |
if ( LOGGING ) { |
| 363 |
|
| 364 |
} |
| 365 |
|
| 366 |
} catch ( Exception e ) { |
| 367 |
p( "exception in cleanupTestEnvironment: " + e.toString() ); |
| 368 |
e.printStackTrace(); |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
public void p (String s ) { |
| 373 |
System.out.println( s ); |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
public static String catchException(JSObject self, String method, |
| 384 |
Object args[]) { |
| 385 |
Object rval; |
| 386 |
String msg; |
| 387 |
try { |
| 388 |
rval = self.call(method, args); |
| 389 |
msg = NO_EXCEPTION; |
| 390 |
} catch (Throwable e) { |
| 391 |
msg = e.getMessage(); |
| 392 |
} |
| 393 |
return msg; |
| 394 |
} |
| 395 |
|
| 396 |
public void getFailedCases() { |
| 397 |
if ( file.passed ) { |
| 398 |
return; |
| 399 |
} |
| 400 |
|
| 401 |
p( "********** Failed Test Cases **********" ); |
| 402 |
|
| 403 |
for ( int i = 0; i < file.caseVector.size(); i++ ) { |
| 404 |
TestCase tc = (TestCase) file.caseVector.elementAt(i); |
| 405 |
|
| 406 |
if ( tc.passed != "true" ) { |
| 407 |
|
| 408 |
p( tc.description +" = "+ tc.actual+ |
| 409 |
( tc.expect != tc.actual |
| 410 |
? " FAILED! expected: " + tc.expect |
| 411 |
: " PASSED!" |
| 412 |
) + |
| 413 |
( tc.reason.length() > 0 |
| 414 |
? ": " + tc.reason |
| 415 |
: "" |
| 416 |
) |
| 417 |
); |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
public File output; |
| 423 |
public File testdir; |
| 424 |
|
| 425 |
public TestFile file; |
| 426 |
|
| 427 |
public Vector testcase; |
| 428 |
public JSObject global; |
| 429 |
|
| 430 |
public boolean passed = true; |
| 431 |
public Vector failedVector = new Vector(); |
| 432 |
public TestLog templog; |
| 433 |
public String exception = ""; |
| 434 |
|
| 435 |
public String BUGNUMBER = ""; |
| 436 |
|
| 437 |
boolean LOGGING = false; |
| 438 |
public static String TEMP_LOG_NAME = "result.tmp"; |
| 439 |
|
| 440 |
public static final int BROWSER = 1; |
| 441 |
public static final int SHELL = 0; |
| 442 |
|
| 443 |
public int ENVIRONMENT; |
| 444 |
|
| 445 |
public static final String NO_EXCEPTION = "Expected exception not thrown."; |
| 446 |
|
| 447 |
public static final String DATA_CLASS = "com.netscape.javascript.qa.liveconnect.DataTypeClass"; |
| 448 |
} |