Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/drivers/TestDriver.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
3 * All Rights Reserved.
4 */
5
6 package com.netscape.javascript.qa.drivers;
7
8 import java.util.Vector;
9 import java.util.Date;
10 import java.io.*;
11 import java.applet.Applet;
12
13 /**
14 * Parent class for JavaScript test drivers. Subclasses run tests against
15 * the JavaScript engine in C, Java, and its embedding in Navigator.
16 *
17 * <p>
18 *
19 * The default implementation does nothing, but contains methods that are
20 * used by all subclasses.
21
22 <p>
23
24 The JavaScript test suite is extendable. To write a new JavaScript test,
25 your test program must call a function that returns array of TestCase objects.
26 The TestCase object is defined in <b>shell.js</b>:
27 <pre>
28 function TestCase( n, d, e, a ) {
29 this.name = n;
30 this.description = d;
31 this.expect = e;
32 this.actual = a;
33 this.passed = true;
34 this.reason = "";
35 this.passed = getTestCaseResult( this.expect, this.actual );
36 }
37 </pre>
38
39 In your test program you should:
40
41 <ul>
42 <li> Create an array of TestCase objects.
43 <li> The last function call in your test must return the array of TestCase
44 objects.
45 </ul>
46
47 To add new test to the suite:
48 <ul >
49 <li > Create a subdirectory of the JavaScript test suite directory.
50 <li > Add tests, which must have the file extension ".js" to this
51 directory.
52 </ul>
53
54 */
55
56 public class TestDriver extends Applet implements Runnable {
57 Thread THREAD = null;
58
59 String[] SYSTEM;
60
61 File TEST_DIRECTORY;
62 File HELPER_FUNCTIONS;
63 File OUTPUT_DIRECTORY;
64
65 String HTTP_PATH;
66 String SUFFIX;
67
68 int OPT_LEVEL;
69 int DEBUG_LEVEL;
70
71 String[] ARGS;
72
73 String EXECUTABLE = null;
74
75 Vector SUITES;
76 String[] FILES;
77
78 public static boolean TINDERBOX = false;
79
80 public static final boolean DEBUG = true;
81 public static final boolean TCMS = false;
82
83 Runtime RUNTIME;
84
85 long FREE_MEMORY;
86 long TOTAL_MEMORY;
87
88 public TestDriver( String[] args ) {
89 this.ARGS = args;
90 if ( THREAD == null ) {
91 THREAD = new Thread(this);
92 THREAD.start();
93 }
94 }
95 public void run() {
96 }
97
98 public void start() {
99 this.FILES = null;
100 this.OUTPUT_DIRECTORY = null;
101 this.OPT_LEVEL = 0;
102 this.DEBUG_LEVEL=0;
103 this.RUNTIME = Runtime.getRuntime();
104 this.FREE_MEMORY = RUNTIME.freeMemory();
105 this.TOTAL_MEMORY = RUNTIME.totalMemory();
106
107 if ( processOptions() ) {
108
109 openLogFiles( OUTPUT_DIRECTORY == null ? TEST_DIRECTORY :
110 OUTPUT_DIRECTORY);
111
112 writeDateToLogs("<hr>", OUTPUT_DIRECTORY );
113 writeLogHeaders( OUTPUT_DIRECTORY );
114
115 if (FILES == null) {
116 FILES = TEST_DIRECTORY.list();
117 }
118
119 if ( TestDriver.TINDERBOX ) {
120 writeTinderboxHeader(EXECUTABLE);
121 }
122
123 SUITES = getSuites( FILES );
124
125 for ( int i = 0; i < SUITES.size(); i++ ) {
126 getCases((TestSuite) SUITES.elementAt(i));
127 }
128 for ( int i = 0; i < SUITES.size(); i++ ) {
129 if (TestDriver.TINDERBOX) {
130 writeTinderboxSuiteName((TestSuite) SUITES.elementAt(i));
131 }
132 executeSuite((TestSuite) SUITES.elementAt(i));
133 if (TestDriver.TINDERBOX) {
134 writeTinderboxSuiteResult((TestSuite) SUITES.elementAt(i));
135 }
136 RUNTIME.gc();
137 }
138 }
139 stop();
140 }
141 /**
142 * Close all logs.
143 */
144
145 public void stop() {
146 closeLogs();
147 RUNTIME.gc();
148 long NEW_FREE_MEMORY = RUNTIME.freeMemory();
149 long NEW_TOTAL_MEMORY = RUNTIME.totalMemory();
150
151 String string = "<tt>"+
152 "Free Memory " + NEW_FREE_MEMORY + "\n<br>"+
153 "Total Memory " + NEW_TOTAL_MEMORY +"\n<br>"+
154 "Free Leaked " + (FREE_MEMORY - NEW_FREE_MEMORY) +"\n<br>"+
155 "Total Leaked " + (TOTAL_MEMORY- NEW_TOTAL_MEMORY) +"\n<br>"+
156 "</tt>";
157
158 p( string );
159 p("done!");
160
161 if ( THREAD != null ) {
162 THREAD.stop();
163 THREAD = null;
164 }
165 }
166
167 public void closeLogs() {
168 writeDateToLogs( "", OUTPUT_DIRECTORY );
169 getLog( OUTPUT_DIRECTORY, SUMMARY_LOG_NAME ).closeLog();
170 getLog( OUTPUT_DIRECTORY, SUITE_LOG_NAME ).closeLog();
171 getLog( OUTPUT_DIRECTORY, FILE_LOG_NAME).closeLog();
172 getLog( OUTPUT_DIRECTORY, CASE_LOG_NAME).closeLog();
173
174 if ( DEBUG ) {
175 getLog( OUTPUT_DIRECTORY, DEBUG_LOG_NAME ).closeLog();
176 }
177 }
178
179 /**
180 * Get information about the operating system.
181 */
182 public static String[] getSystemInformation() {
183 String [] SYSTEM = { System.getProperty( "os.name" ),
184 System.getProperty( "os.arch" ),
185 System.getProperty( "os.version" ) };
186 return SYSTEM;
187 }
188
189 /**
190 *
191 *
192 * @return a file object with the specified in the output directory.
193 */
194
195 public static TestLog getLog(File output, String filename ) {
196 enablePrivileges();
197 TestLog log = null;
198 String[] SYSTEM = getSystemInformation();
199
200 // String platform = ( SYSTEM[0].length() < 4 ) ? SYSTEM[0] : SYSTEM[0].substring(0,4);
201
202 String platform = SYSTEM[0];
203
204 try {
205 File logdir = new File(
206 output.getAbsolutePath() +
207 (output.getAbsolutePath().endsWith(File.separator) ? "" : File.separator) +
208 platform +
209 SYSTEM[1] +"-"+ SYSTEM[2],
210 getCurrentDate("_") );
211 logdir.mkdirs();
212 log = new TestLog( logdir.getAbsolutePath() + File.separator +
213 filename, TERMINATOR );
214 } catch ( Exception e ) {
215 p( "TestDriver.getLog threw " + e.toString() );
216 p( "platform " + platform );
217 p( "output" + output.toString() );
218 p( "filename " + filename.toString() );
219 p( "File.separator " + File.separator.toString() );
220 p( "SYSTEM[0] " + SYSTEM[0] );
221 p( "SYSTEM[1] " + SYSTEM[1] );
222 p( "SYSTEM[2] " + SYSTEM[2] );
223 p( "date " +getCurrentDate("_") );
224
225 e.printStackTrace();
226 }
227
228 return log;
229
230 }
231
232 /**
233 * Create and write headers to log files.
234 *
235 * @param output directory in which output files are written.
236 */
237
238 public static void openLogFiles( File output ) {
239 enablePrivileges();
240
241 TestLog SUMMARY_LOG = getLog( output, SUMMARY_LOG_NAME );
242 TestLog FILE_LOG = getLog( output, FILE_LOG_NAME );
243 TestLog SUITE_LOG = getLog( output, SUITE_LOG_NAME );
244 TestLog CASE_LOG = getLog( output, CASE_LOG_NAME );
245
246 if ( DEBUG ) {
247 TestLog DEBUG_LOG = getLog( output, DEBUG_LOG_NAME );
248 }
249
250 return;
251 }
252
253 public void writeLogHeaders( File output ) {
254 String header = "<table>"+
255 "<tr><th>Test Driver <td>" + this.getClass().toString() +"</tr>" +
256 "<tr><th>Output Directory <td>" + OUTPUT_DIRECTORY +"</tr>" +
257 ( EXECUTABLE == null
258 ? "<tr><th>OptLevel <td>" + OPT_LEVEL +"</tr>" +
259 "<tr><th>DebugLevel <td>" + DEBUG_LEVEL+"</tr>"
260 : "<tr><th>Executable <td>" + EXECUTABLE +"</tr>"
261 ) +
262 "<tr><th>Java Version <td>" + System.getProperty("java.vendor")+
263 " "+ System.getProperty( "java.version" ) +"</tr>"+
264 "<tr><th>Test File Directory <td>" + TEST_DIRECTORY +"</tr>"+
265 "<tr><th>Helper Functions <td>" + HELPER_FUNCTIONS +"</tr>"+
266 "<tr><th>Free Memory <td>" + FREE_MEMORY +"</tr>"+
267 "<tr><th>Total JVM Memory <td>" + TOTAL_MEMORY +"</tr>"+
268 "</table>";
269
270 getLog( OUTPUT_DIRECTORY, SUITE_LOG_NAME ).writeLine( header );
271 getLog( OUTPUT_DIRECTORY, CASE_LOG_NAME ).writeLine( header );
272 getLog( OUTPUT_DIRECTORY, FILE_LOG_NAME ).writeLine( header );
273 getLog( OUTPUT_DIRECTORY, SUMMARY_LOG_NAME ).writeLine( header );
274
275 getLog( OUTPUT_DIRECTORY, SUMMARY_LOG_NAME ).writeLine(
276 "<table width=100%>" +
277 "<tr bgColor=#ffffcc >" +
278 "<th rowspan=2 width=15%> Suite" +
279 "<th rowspan=2 width=20%> Files" +
280 "<th rowspan=2 width=10%> Cases" +
281 "<th colspan=2 width=20% > Passed" +
282 "<th colspan=2 width=20%> Failed" +
283 "<th rowspan=2 width=15%> Result" +
284 "</tr>" +
285 "<tr>" +
286 "<th width=10%> #" +
287 "<th width=10%> %" +
288 "<th width=10%> #" +
289 "<th width=10%> %" +
290 "</tr></table>" );
291 return;
292 }
293
294 /**
295 * For each subdirectory of the main test directory, create a new
296 * TestSuite object.
297 */
298
299 public Vector getSuites( String[] files ) {
300 Vector suites = new Vector();
301
302 for ( int i = 0; i < files.length; i++ ) {
303 String filename = stripDoubleSlashes( TEST_DIRECTORY +
304 File.separator + files[i] );
305 File fileobject = new File( filename );
306
307 if ( fileobject.isDirectory() ) {
308 TestSuite s = new TestSuite( fileobject.getName(),
309 filename );
310 suites.addElement( s );
311 }
312 }
313
314 return suites;
315 }
316 /**
317 * If two slashes in a row are found, one slash is stripped out.
318 * Mac client has trouble if we don't do this.
319 * xxx this doesn't work and needs to be fixed.
320 */
321 public static String stripDoubleSlashes( String string ) {
322 StringBuffer buffer = new StringBuffer();
323 for ( int letter = 0; letter < string.length(); letter++ ) {
324 char current_char = string.charAt(letter);
325
326 if ( current_char != File.separatorChar ) {
327 buffer.append(current_char);
328 } else {
329 while ( string.charAt(++letter) ==
330 File.separatorChar )
331 {
332 ;
333 }
334 // only add one slash
335 buffer.append( File.separatorChar );
336 --letter;
337 }
338
339 }
340 /*
341 if ((new Character(string.charAt(letter))).toString().equals("/")){
342 if (!(new Character(
343 string.charAt(letter+1))).toString().equals("/"))
344 {
345 // only got one, leave it alone
346 buffer.append( string.charAt( letter ) );
347 }
348 } else {
349 buffer.append( string.charAt( letter ) );
350 }
351 */
352
353
354 return buffer.toString();
355 }
356
357 /**
358 * For each test file in the suite directory, create a TestFile object.
359 *
360 */
361
362 public void getCases( TestSuite suite ) {
363 enablePrivileges();
364
365 File dir = new File ( suite.filePath );
366 String[] files = dir.list();
367
368 for ( int i = 0; i < files.length; i++ ) {
369 TestFile item = new TestFile( files[i],
370 suite.filePath + File.separator+ files[i] );
371
372 if ( item.isFile()
373 && (item.getName().toLowerCase()).endsWith(getSuffix())
374 && (!item.isDirectory()) ) {
375 suite.addElement(item);
376 p( item +"" );
377 }
378 }
379 }
380 /**
381 * Subclasses should override this method to iterate through all TestFiles
382 * in the TestSuite, create a new TestEnvironment, run the test, and close
383 * the TestEnvironment.
384 *
385 * For examples,
386 * @see com.netscape.javascript.qa.drivers.RhinoDrv and
387 * @see com.netscape.javascript.qa.drivers.RefDrv
388 */
389 public synchronized void executeSuite( TestSuite suite ) {
390 }
391
392 /**
393 * If the environment uses a Security Manager and requires privileges to
394 * access system properties, override this method to enable privileges.
395 * The default method does nothing.
396 *
397 */
398
399 public static void enablePrivileges() {
400 }
401
402 /*
403 * Begin functions that write to logs
404 *
405 * These methods are static so that LiveConnectTest objects can call them
406 * directly.
407 *
408 */
409
410 /**
411 * Write the suite result to the Tinderbox log.
412 *
413 *
414 * XXX need machine, branch, startTime, endTime
415 */
416 public void writeTinderboxHeader( String executable ) {
417 String dottedLine =
418 "--------------------------------------------------------------";
419
420 String product = ( executable == null ) ? "ns/js/rhino" : "ns/js/ref";
421 String osInfo = System.getProperty( "os.name" ) +" " +
422 System.getProperty( "os.arch" ) +" " +
423 System.getProperty( "os.version" );
424 String javaInfo=System.getProperty( "java.vendor" ) +" "+
425 System.getProperty( "java.version" );
426
427 // Create the log string;
428
429 System.out.println( dottedLine );
430 System.out.println( "Product " + product );
431 // System.out.println( "Machine " + machine );
432 System.out.println( "Operating System " + osInfo );
433 System.out.println( "Java Version " + javaInfo);
434 System.out.println( "Free Memory " + FREE_MEMORY );
435 System.out.println( "Total JVM Memory " + TOTAL_MEMORY );
436
437 System.out.println( "Test Driver " + this.getClass().getName());
438 System.out.println( "Output Directory " + OUTPUT_DIRECTORY );
439 System.out.println( "Path to Executable " + EXECUTABLE );
440
441 if ( product.equals( "ns/js/rhino" ) ){
442 System.out.println( "Optimization Level " + OPT_LEVEL );
443 System.out.println( "Debug level " + DEBUG_LEVEL );
444 }
445
446
447 System.out.println( "Test Directory " + TEST_DIRECTORY );
448 System.out.println( dottedLine );
449 }
450
451
452 public void writeTinderboxSuiteName( TestSuite suite ) {
453 System.out.println( "Suite " + suite.name );
454 }
455
456 public void writeTinderboxSuiteResult( TestSuite suite ) {
457 String dottedLine =
458 "--------------------------------------------------------------";
459
460 System.out.println( "Result " + ( suite.passed
461 ? "PASSED" : "FAILED"));
462
463 if ( ! suite.passed ) {
464 System.out.println( "Failed Files " );
465 for ( int i = 0; i < suite.size(); i++ ) {
466 TestFile file = (TestFile) suite.elementAt(i);
467 if ( ! file.passed ) {
468 System.out.println( file.name +
469 (file.bugnumber.equals("") ? "" :
470 " http://scopus.mcom.com/bugsplat/show_bug.cgi?id="+
471 file.bugnumber +" "));
472 }
473 }
474 }
475
476 System.out.println( dottedLine );
477 }
478
479 /**
480 * Write an HTML-formatted string to SUITE_LOG.
481 */
482 public static void writeSuiteResult( TestSuite suite, File output ) {
483 if ( ! (suite.size() > 0) ) {
484 return;
485 }
486
487 String buffer = "";
488 buffer += ( "<tt>" +
489 ( suite.passed
490 ? "<font color=#00dd00>passed</font>"
491 : "<font color=#dd0000>FAILED</font>"
492 ) +
493 "&nbsp;" +
494 "<a href='./../../" + suite.name +"'>"+
495 suite.name +"</a></b>" );
496
497 if ( ! suite.passed ) {
498 for ( int i = 0; i < suite.size(); i++ ) {
499 TestFile file = (TestFile) suite.elementAt(i);
500 if ( ! file.passed ) {
501 buffer += ( "&nbsp;" +
502 "<a href='case.html#"+ suite.name +"-"+ file.name + "'>" +
503 file.name + "</a>" );
504
505 if ( ! file.bugnumber.equals("") ) {
506 buffer += ( "&nbsp;"+
507 "(<a href='http://scopus.mcom.com/bugsplat/show_bug.cgi?id="+
508 file.bugnumber+"'>"+file.bugnumber+"</a>)" );
509 }
510 }
511 }
512 }
513
514 buffer += ( "</tt><br >" );
515
516 getLog( output, SUITE_LOG_NAME).writeLine( buffer.toString() );
517 }
518
519 /**
520 * Write an HTML-formatted string to the SUMMARY_LOG that looks like
521 * this:
522 * <pre >
523 * Suite Number of Number of Passed Failed Result
524 * Name Files Cases # % # %
525 *
526 * </pre>
527 */
528 public static void writeSuiteSummary( TestSuite suite, File output ) {
529 if ( ! (suite.size() > 0) ) {
530 return;
531 }
532
533 String buffer = "";
534 p( "total :"+ suite.totalCases );
535 p("passed :"+ suite.casesPassed );
536 p("failed :"+ suite.casesFailed );
537
538
539 double percentPassed = Math.round((double) suite.casesPassed /
540 (double) suite.totalCases * 10000)/100 ;
541 double percentFailed = Math.round((double) suite.casesFailed /
542 (double) suite.totalCases * 10000)/100 ;
543
544 buffer += ( "<table width=100%>" );
545 buffer += ( "<th bgcolor=#ffffcc width=15%>" +
546 suite.name );
547
548 buffer += ( "<th width=15% bgcolor=#ffffcc >" + suite.size() +
549 "<th width=10% bgcolor=#ffffcc >" + suite.totalCases +
550 "<th width=10% bgcolor=#ffffcc >" + suite.casesPassed +
551 "<th width=10% bgcolor=#ffffcc >" + percentPassed +
552 "<th width=10% bgcolor=#ffffcc >" + suite.casesFailed +
553 "<th width=10% bgcolor=#ffffcc >" + percentFailed +
554 "<th width=15% bgcolor=#ffffcc >" +
555 ( ( suite.passed == true )
556 ? "<font color=#006600 >PASSED</font >"
557 : "<font color=#990000 >FAILED</font >"
558 ) + "</tr></table>" );
559
560 for ( int i = 0; i < suite.size(); i++ ) {
561 TestFile file= ((TestFile) suite.elementAt(i));
562
563 double pPassed = 0;
564 double pFailed = 0;
565
566 if ( file.totalCases > 0 ) {
567 pPassed = (Math.round((double) file.casesPassed /
568 (double) file.totalCases * 10000))/100 ;
569 pFailed = (Math.round((double) file.casesFailed /
570 (double) file.totalCases * 10000))/100 ;
571 }
572
573 buffer += ( "<table width=100%>" +
574 "<tr>" +
575 "<td width=15%>" +
576 "<td width=15% ><a href='case.html#"+ suite.name +
577 "-"+ file.name + "'>" + file.name + "</a>" +
578 "<td width=10%>" + file.totalCases +
579 "<td width=10% bgColor=#ccffcc >" + file.casesPassed +
580 "<td width=10% bgColor=#ccffcc >" + pPassed +
581 "<td width=10% bgColor=#ffcccc >" + file.casesFailed +
582 "<td width=10% bgColor=#ffcccc >" + pFailed +
583 "<td width=15%>" +
584 ( ( file.passed == true )
585 ? "<font color=#006600 >PASSED</font >"
586 : "<font color=#990000 >FAILED</font >"
587 ) +
588 ( ( file.reason.equals("") )
589 ? ""
590 : ": "+ file.reason
591 ) +
592 ( ( file.exception.equals("") )
593 ? ""
594 : ":<br>"+ file.exception
595 ) +
596 "<tr ></table>" );
597 }
598
599 getLog( output, SUMMARY_LOG_NAME ).writeLine( buffer.toString() );
600 }
601
602 /**
603 * Write the result of the current file to the FILE_LOG.
604 * If the file threw an exception, print the exception.
605 *
606 */
607 public static void writeFileResult( TestFile file, TestSuite suite, File output ) {
608 String suitename = ( suite == null ) ? "" : suite.name;
609
610 if ( !file.passed ) {
611 String buffer = "";
612
613 buffer += ( "<tt ><font color=" +
614 ( (file.passed )
615 ? "#00dd00>PASSED</font>&nbsp;"
616 : "#dd0000>FAILED</font>&nbsp;" ) +
617 "<a href='case.html#" + suitename +"-"+ file.name + "'>" +
618 suitename+" "+file.name + "</a > " +
619 file.exception + "\n" );
620
621 if ( ! file.bugnumber.equals("") ) {
622 buffer += ( "&nbsp;"+
623 "(<a href='http://scopus.mcom.com/bugsplat/show_bug.cgi?id="+
624 file.bugnumber+"'>"+file.bugnumber+"</a>)" );
625 }
626 getLog( output, FILE_LOG_NAME ).writeLine( buffer.toString() );
627
628 }
629 }
630
631 /**
632 * Read the contents of a file into a string.
633 */
634 public static String readFile( String filePath ) {
635 File jsFile = new File( filePath );
636
637 int length = new Long( jsFile.length()).intValue();
638 byte[] b = new byte[length];
639 StringBuffer contents = new StringBuffer();
640
641 try {
642 FileInputStream fis = new FileInputStream( jsFile );
643 int read = fis.read( b );
644 contents.append( new String( b ) );
645 } catch ( Exception e ) {
646 p( e.toString() );
647 }
648 return ( contents.toString() );
649 }
650 /**
651 Test Case Management System (TCMS) requires the following
652 information:
653 (MachineID), -pass- or *FAIL*, TestFileName/Beaker,
654 TestFileName,Date Run in MM/DD/YY, Start Time HH:MM:SS,
655 End Time HH:MM:SS, ExpectedResults String
656 (quite often null), Actual Result String, Reason For Failure
657
658 Tests can provide this information. we expected it to be
659 in an object called "TestCase" with the following structure:
660
661 <pre >
662 function TestCase( passed, name, expect, actual, reason ) {
663 this.passed = passed;
664 this.name = "Description of the Test Case";
665 this.expect = ( theExpectedResult );
666 this.actual = ( theActualResult );
667 this.reason = ( reasonForFailure );
668 }
669 </pre >
670
671 we will generate machineID, pass/fail, date run, start time,
672 end time.
673
674 If TCMS == false, omit unnecessary log id.
675
676 */
677 public static void writeCaseResults( TestFile file, TestSuite suite,
678 File output )
679 {
680 suite.totalCases += file.totalCases;
681
682 String[] SYSTEM = getSystemInformation();
683
684 String buffer = "";
685
686 for ( int i = 0; i < file.caseVector.size(); i++ ) {
687 TestCase tcase = (TestCase) (file.caseVector.elementAt(i));
688
689 // format and write test case results to CASE_LOG
690 if ( !tcase.passed.equals("true")) {
691 if ( !file.passed ) {
692 buffer += ("<a name=" + suite.name +"-"+ file.name +">");
693 buffer += ("<tt>");
694 buffer += ( "(" + SYSTEM[0] + "), " );
695 }
696 }
697
698 if ( tcase.passed.equals("true")) {
699 if (!file.passed)
700 buffer += ( "-pass-, " );
701 suite.casesPassed += 1;
702 file.casesPassed += 1;
703 } else {
704 if (!file.passed)
705 buffer += ( "*FAIL*, ");
706 suite.casesFailed += 1;
707 file.casesFailed += 1;
708 }
709
710 if ( TCMS ) {
711 buffer += ( tcase.name + "-" + tcase.description + "/Beaker, " +
712 tcase.name + "-" + tcase.description + ", " +
713 getCurrentDate("/") + ", " +
714 file.startTime + ", " +
715 file.endTime + ", " +
716 tcase.expect +", " +
717 tcase.actual +", " +
718 tcase.reason + "\n" );
719 } else {
720 buffer += ( tcase.name +","+
721 tcase.description +","+
722 tcase.expect +","+
723 tcase.actual +","+
724 tcase.reason +"\n" );
725 }
726
727 if (!tcase.passed.equals("true")) {
728 buffer += ("</tt><br>\n");
729 getLog( output, CASE_LOG_NAME ).writeLine( buffer.toString() );
730 } else {
731 buffer = "";
732 }
733 }
734 }
735
736 /**
737 * Short version of writing test case results to the CASE_LOG, used by
738 * LiveConnecTest subclasses.
739 *
740 * @param cases vector of testcases whose results should be written
741 * to the CASE_LOG. LiveConnectTest sends a vector of failed TestCase
742 * objects.
743 * @param classname name of the LiveConnectTest class
744 * @param output directory in which output is written.
745 *
746 * @see
747 * com.netscape.javascript.qa.liveconnect.LiveConnectTest#writeResultsToCaseLog
748 *
749 */
750
751 public static void writeCaseResults( TestFile file, String classname,
752 File output )
753 {
754 String[] system = getSystemInformation();
755 String buffer = "";
756
757 for ( int i = 0; i < file.caseVector.size(); i++ ) {
758 TestCase tcase = (TestCase) (file.caseVector.elementAt(i));
759 if ( tcase.passed.equals("true")) {
760 // buffer += ( "-pass-, " );
761 } else {
762 buffer += ("<tt>");
763 buffer += ( "(" + system[0] + "), " );
764
765 buffer += ( "*FAIL*, ");
766 buffer += ( tcase.name +","+
767 tcase.description +","+
768 tcase.expect +","+
769 tcase.actual +","+
770 tcase.reason +"\n" );
771 buffer += ("</tt><br>\n");
772 getLog( output, CASE_LOG_NAME ).writeLine( buffer.toString() );
773 }
774 }
775 }
776 /**
777 Write system information and current date to the SUMMARY_LOG,
778 FILE_LOG, and SUITE_LOG.
779
780 XXX need to fix this to output all test information.
781 */
782 public static void writeDateToLogs( String separator, File output ) {
783 Date today = new Date();
784 String[] SYSTEM = getSystemInformation();
785
786 // long NEW_FREE_MEMORY = RUNTIME.freeMemory();
787 // long NEW_TOTAL_MEMORY = RUNTIME.totalMemory();
788
789 String string = "<tt>"+
790 // "Free Memory " + NEW_FREE_MEMORY + "\n<br>"+
791 // "Total Memory " + NEW_TOTAL_MEMORY +"\n<br>"+
792 // "Free Leaked " + FREE_MEMORY - NEW_FREE_MEMORY +"\n<br>"+
793 // "Total Leaked " + TOTAL_MEMORY-NEW_TOTAL_MEMORY +"\n<br>"+
794 "</tt>"+
795 separator + SYSTEM[0] +" "+ SYSTEM[1] +" "+ SYSTEM[2] +" "+
796 today.toString();
797
798 getLog( output, SUMMARY_LOG_NAME ).writeLine( string );
799 getLog( output, FILE_LOG_NAME).writeLine( string );
800 getLog( output, SUITE_LOG_NAME).writeLine( string );
801 if ( !TCMS ) {
802 getLog( output, CASE_LOG_NAME ).writeLine( string );
803 }
804 }
805
806 /**
807 * Convenience methods.
808 */
809
810 public static void p( String s ) {
811 if ( !TestDriver.TINDERBOX ) {
812 System.out.println( s );
813 }
814 }
815 public static void debug (String s ) {
816 if ( DEBUG && !TestDriver.TINDERBOX )
817 System.err.println( s );
818 }
819 /**
820 From the current Date, return a string in the format "DD?MM?YY",
821 where "/" is specified by the separator argument.
822 */
823 public static String getCurrentDate( String separator ) {
824 Date today = new Date();
825 String date = (today.getDate() < 10)
826 ? "0" + String.valueOf( today.getDate() )
827 : String.valueOf( today.getDate() );
828 String month = (today.getMonth() + 1 < 10 )
829 ? "0" + String.valueOf( (today.getMonth() +1) )
830 : String.valueOf( today.getMonth() + 1 );
831 String year = String.valueOf( today.getYear() );
832
833 return ( month + separator + date + separator + year );
834 }
835 /**
836 From the current time, return a string in the format "HH:MM:SS"
837 */
838
839 public static String getCurrentTime() {
840 Date now = new Date();
841 String hours = ( now.getHours() < 10 )
842 ? "0" + String.valueOf( now.getHours() )
843 : String.valueOf( now.getHours() );
844
845 String minutes = ( now.getMinutes() < 10 )
846 ? "0" + String.valueOf( now.getMinutes() )
847 : String.valueOf( now.getMinutes() );
848
849 String seconds = ( now.getSeconds() < 10 )
850 ? "0" + String.valueOf( now.getSeconds() )
851 : String.valueOf( now.getSeconds() );
852
853 String time = hours + ":" + minutes + ":" + seconds;
854
855 return ( time );
856 }
857 public String getSuffix() {
858 return SUFFIX;
859 }
860 public void setSuffix(String s) {
861 SUFFIX = s;
862 }
863 /**
864 * Temporary stop this thread for 5 seconds.
865 *
866 */
867 public boolean sleep(int ms) {
868 try {
869 THREAD.sleep( 5000 );
870 } catch ( Exception e ) {
871 p( "sleep failed: " + e );
872 return false;
873 }
874 return true;
875 }
876
877 /**
878 * Implementations need to override this method, which should call
879 * its own constructor, passing the args object as an argument.
880 */
881
882
883 /**
884 * Process options should parse the ARGS object.
885 *
886 * return true if the driver should continue. return false if the driver
887 * should not continue.
888 *
889 */
890
891 public boolean processOptions() {
892 return false;
893 }
894 public static void main ( String[] args ) {
895 TestDriver d = new TestDriver( args );
896 d.start();
897 }
898
899 public static final String SUMMARY_LOG_NAME = "summ.html";
900 public static final String CASE_LOG_NAME = "case.html";
901 public static final String FILE_LOG_NAME = "file.html";
902 public static final String SUITE_LOG_NAME = "suite.html";
903 public static final String DEBUG_LOG_NAME = "debug.html";
904 public static final String TERMINATOR = "<BR>\n";
905
906 }
907