| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package com.netscape.javascript.qa.drivers; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import java.io.*; |
| 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 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public class LiveConnectDrv extends TestDriver { |
| 76 |
public LiveConnectDrv( String[] args ) { |
| 77 |
super( args ); |
| 78 |
setSuffix( ".class"); |
| 79 |
} |
| 80 |
public static void main ( String[] args ) { |
| 81 |
LiveConnectDrv d = new LiveConnectDrv( args ); |
| 82 |
d.start(); |
| 83 |
} |
| 84 |
public boolean processOptions() { |
| 85 |
int length = ARGS.length; |
| 86 |
|
| 87 |
if (ARGS[0].startsWith("-")) { |
| 88 |
|
| 89 |
|
| 90 |
for (int i=0; i < ARGS.length; i++ ) { |
| 91 |
if ( ARGS[i].equals("-d") ) { |
| 92 |
this.TEST_DIRECTORY = |
| 93 |
ARGS[i].endsWith(File.separator) |
| 94 |
? new File( ARGS[++i] ) |
| 95 |
: new File( ARGS[++i] + File.separator ); |
| 96 |
|
| 97 |
if ( ! ( this.TEST_DIRECTORY ).isDirectory() ) { |
| 98 |
p( "error: " + |
| 99 |
this.TEST_DIRECTORY.getAbsolutePath() + |
| 100 |
" is not a directory." ); |
| 101 |
return false; |
| 102 |
} else { |
| 103 |
continue; |
| 104 |
} |
| 105 |
} |
| 106 |
if ( ARGS[i].equals("-s") ) { |
| 107 |
FILES = new String[20] ; |
| 108 |
for ( int j = ++i, k=0; j < ARGS.length; j++ ) { |
| 109 |
if ( ARGS[j].startsWith("-") ){ |
| 110 |
break; |
| 111 |
} |
| 112 |
FILES[k++] = ARGS[j]; |
| 113 |
} |
| 114 |
} |
| 115 |
if ( ARGS[i].equals("-h") ) { |
| 116 |
this.HELPER_FUNCTIONS = new File( ARGS[++i] ); |
| 117 |
if ( ! (this.HELPER_FUNCTIONS ).isFile() ) { |
| 118 |
p( "error: "+ |
| 119 |
this.HELPER_FUNCTIONS.getAbsolutePath()+ |
| 120 |
" file not found." ); |
| 121 |
return false; |
| 122 |
} |
| 123 |
} |
| 124 |
if ( ARGS[i].equals("-o") ) { |
| 125 |
String odir = ARGS[++i]; |
| 126 |
|
| 127 |
OUTPUT_DIRECTORY = new File( |
| 128 |
(odir.endsWith(File.separator) ? odir : |
| 129 |
odir+File.separator)); |
| 130 |
|
| 131 |
OUTPUT_DIRECTORY.mkdirs(); |
| 132 |
|
| 133 |
if ( !OUTPUT_DIRECTORY.exists() || |
| 134 |
!OUTPUT_DIRECTORY.isDirectory() ) |
| 135 |
{ |
| 136 |
p( "error: "+ |
| 137 |
OUTPUT_DIRECTORY.getAbsolutePath()+ |
| 138 |
" could not create directory."); |
| 139 |
return false; |
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
if ( ARGS[i].equals("-p") ) { |
| 145 |
OPT_LEVEL = Integer.parseInt( ARGS[++i] ); |
| 146 |
} |
| 147 |
|
| 148 |
if ( ARGS[i].equals("-db" )) { |
| 149 |
DEBUG_LEVEL = Integer.parseInt( ARGS[++i] ); |
| 150 |
OPT_LEVEL = 0; |
| 151 |
} |
| 152 |
|
| 153 |
if ( ARGS[i].equals("-e")) { |
| 154 |
EXECUTABLE = ARGS[++i]; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return true; |
| 159 |
|
| 160 |
} else { |
| 161 |
switch ( ARGS.length ) { |
| 162 |
case 0: |
| 163 |
p( "error: specify location of JavaScript "+ |
| 164 |
"tests" ); |
| 165 |
return false; |
| 166 |
case 1: |
| 167 |
p( "error: specify location of JavaScript "+ |
| 168 |
"HELPER_FUNCTIONS file" ); |
| 169 |
return false; |
| 170 |
case 2: |
| 171 |
this.TEST_DIRECTORY = ARGS[0].endsWith(File.separator) |
| 172 |
? new File( ARGS[0] ) |
| 173 |
: new File( ARGS[0] + File.separator ); |
| 174 |
this.HELPER_FUNCTIONS = new File( ARGS[1] ); |
| 175 |
if ( ! ( this.TEST_DIRECTORY ).isDirectory() ) { |
| 176 |
p( "error: " + |
| 177 |
this.TEST_DIRECTORY.getAbsolutePath() + |
| 178 |
" is not a directory." ); |
| 179 |
return false; |
| 180 |
} |
| 181 |
if ( ! (this.HELPER_FUNCTIONS ).isFile() ) { |
| 182 |
p( "error: "+ |
| 183 |
this.HELPER_FUNCTIONS.getAbsolutePath()+ |
| 184 |
" file not found." ); |
| 185 |
return false; |
| 186 |
} |
| 187 |
return true; |
| 188 |
default: |
| 189 |
p( "could not understand arguments." ); |
| 190 |
return false; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
} |
| 195 |
|
| 196 |
public synchronized void executeSuite( TestSuite suite ) { |
| 197 |
p( "LiveConnectDrv.executeSuite " + suite.name ); |
| 198 |
TestEnvironment context; |
| 199 |
TestFile file; |
| 200 |
|
| 201 |
if ( EXECUTABLE != null ) { |
| 202 |
generateHelperFile(); |
| 203 |
} |
| 204 |
|
| 205 |
for ( int i = 0; i < suite.size(); i++ ) { |
| 206 |
synchronized ( suite ) { |
| 207 |
file = (TestFile) suite.elementAt( i ); |
| 208 |
|
| 209 |
p( file.name ); |
| 210 |
|
| 211 |
|
| 212 |
context = new LiveConnectEnv( file, suite, this ); |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
synchronized( context ) { |
| 218 |
context.runTest(); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
context.close(); |
| 230 |
context = null; |
| 231 |
|
| 232 |
if ( ! file.passed ) { |
| 233 |
suite.passed = false; |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
writeSuiteResult( suite, OUTPUT_DIRECTORY ); |
| 239 |
writeSuiteSummary( suite, OUTPUT_DIRECTORY ); |
| 240 |
} |
| 241 |
|
| 242 |
public void generateHelperFile() { |
| 243 |
try { |
| 244 |
this.HELPER_FUNCTIONS = new File( OUTPUT_DIRECTORY, "helper.js" ); |
| 245 |
|
| 246 |
p( "HELPER FUNCTIONS FILE IS " + HELPER_FUNCTIONS ); |
| 247 |
FileOutputStream fos = new FileOutputStream( HELPER_FUNCTIONS ); |
| 248 |
|
| 249 |
fos.write( ("var OUTPUT_DIRECTORY = \"" + OUTPUT_DIRECTORY + "\";").getBytes()); |
| 250 |
fos.write( ("var OUTPUT_FILE = arguments[1];").getBytes() ); |
| 251 |
fos.write( ("var TestClassName = arguments[0];" ).getBytes()); |
| 252 |
fos.write( ("var TestClass = eval( TestClassName );" ).getBytes()); |
| 253 |
fos.write( ("var testclass = new TestClass();" ).getBytes()); |
| 254 |
fos.write( ("testclass.run();").getBytes() ); |
| 255 |
fos.write( ("quit();" ).getBytes()); |
| 256 |
fos.close(); |
| 257 |
|
| 258 |
} catch ( Exception e ) { |
| 259 |
p( "generateHelperFile threw " + e.toString() ); |
| 260 |
e.printStackTrace(); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public void getCases( TestSuite suite ) { |
| 272 |
enablePrivileges(); |
| 273 |
|
| 274 |
File dir = new File ( suite.filePath ); |
| 275 |
String[] files = dir.list(); |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
String filename = "Packages.com.netscape.javascript.qa.liveconnect." + |
| 280 |
suite.name +"."; |
| 281 |
|
| 282 |
for ( int i = 0; i < files.length; i++ ) { |
| 283 |
if ( files[i].endsWith( getSuffix() )) { |
| 284 |
TestFile item = new TestFile( files[i], |
| 285 |
filename + (files[i].substring(0,files[i].length() - |
| 286 |
getSuffix().length()))); |
| 287 |
|
| 288 |
p( item.filePath ); |
| 289 |
suite.addElement(item); |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
} |