Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/drivers/LiveConnectEnv.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 com.netscape.javascript.qa.liveconnect.LiveConnectTest;
9 import java.lang.*;
10 import java.io.*;
11 import java.util.Vector;
12
13 /**
14 * The LiveConnect test environment. Creates a new LiveConnect enabled
15 * JavaScript shell, and passes it three arguments
16 *
17 * <pre>
18 * jsshell helper.js Packages.com.netscape.javascript.qa.liveconnect.LiveConnectTestClass js00000.tmp
19 * </pre>
20
21 * where helper.js contains some statements that allow the shell to run
22 * the test, and js00000.tmp is the temporary file whose name is generated
23 * by this class, and specifies where test results should be written.
24 *
25 * Unlike the other TestEnvironments, LiveConnectEnv does not parse the test
26 * result. The LiveConnectEnv uses LiveConnect to get and parse the test
27 * result, using LiveConnect to get the JSObject that contains the testcases.
28 *
29 * The LiveConnectEnv gets File and Suite result information from a
30 * temporary file that the test applet writes to the output directory
31 * the test
32 *
33 * @see com.netscape.javascript.qa.drivers.TestEnvironment
34 * @see com.netscape.javascript.qa.drivers.ObservedTask
35 * @see com.netscape.javascript.qa.drivers.LiveConnectDrv
36 * @see com.netscape.javascript.qa.liveconnect.LiveConnectTest
37 *
38 * @author [email protected]
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 * Create a new LiveConnectEnv.
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 * Called by the driver to execute the test program.
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 * Instantiate a new JavaScript shell, passing the helper file and the
91 * name of the test class as arguments.
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 * Start the shell process.
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 * Parse the results file for this test. The which contains data in the
117 * following format:
118 * <pre>
119 * CLASSNAME LiveConnectTest
120 * PASSED [true, false]
121 * LENGTH [number of testcases in this test]
122 * NO_PASSED [number of testcases that passed]
123 * NO_FAILED [number of testcases that failed]
124 * </pre>
125 *
126 * @see com.netscape.javascript.qa.liveconnect.LiveConnectTest#writeResultsToTempFile
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 * Delete the temp log associated with this context.
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 }