| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package com.netscape.javascript.qa.liveconnect.slot; |
| 6 |
|
| 7 |
import netscape.javascript.*; |
| 8 |
import com.netscape.javascript.qa.liveconnect.*; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class Slot_002 extends LiveConnectTest { |
| 33 |
public Slot_002() { |
| 34 |
super(); |
| 35 |
} |
| 36 |
public static void main( String[] args ) { |
| 37 |
Slot_002 test = new Slot_002(); |
| 38 |
test.start(); |
| 39 |
} |
| 40 |
|
| 41 |
public void executeTest() { |
| 42 |
getBaseObjects(); |
| 43 |
Object testMatrix[] = getDataArray(); |
| 44 |
String args = getArrayArguments( testMatrix ); |
| 45 |
|
| 46 |
JSObject jsArray = createJSArray( args ); |
| 47 |
getLength( jsArray, testMatrix.length ); |
| 48 |
|
| 49 |
for ( int i = 0; i < testMatrix.length; i++ ) { |
| 50 |
getSlot( jsArray, i, (Object[]) testMatrix[i] ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public String getArrayArguments( Object[] matrix ) { |
| 55 |
StringBuffer buffer = new StringBuffer(); |
| 56 |
for ( int i = 0; i < matrix.length; i++ ) { |
| 57 |
buffer.append( ((Object[]) matrix[i]) [0] ); |
| 58 |
if ( i < matrix.length -1 ) { |
| 59 |
buffer.append( ", " ); |
| 60 |
} |
| 61 |
} |
| 62 |
return buffer.toString(); |
| 63 |
} |
| 64 |
|
| 65 |
public JSObject jsNumber; |
| 66 |
public JSObject jsFunction; |
| 67 |
public JSObject jsBoolean; |
| 68 |
public JSObject jsObject; |
| 69 |
public JSObject jsString; |
| 70 |
public JSObject jsMath; |
| 71 |
public JSObject jsDate; |
| 72 |
public JSObject jsArray; |
| 73 |
public JSObject jsRegExp; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public boolean getBaseObjects() { |
| 82 |
try { |
| 83 |
jsNumber = (JSObject) global.eval( "Number.prototype.constructor" ); |
| 84 |
jsString = (JSObject) global.eval( "String.prototype.constructor" ); |
| 85 |
jsFunction = (JSObject) global.eval( "Function.prototype.constructor" ); |
| 86 |
jsBoolean = (JSObject) global.eval( "Boolean.prototype.constructor" ); |
| 87 |
jsObject = (JSObject) global.eval( "Object.prototype.constructor" ); |
| 88 |
jsMath = (JSObject) global.eval("Math"); |
| 89 |
jsDate = (JSObject) global.eval( "Date.prototype.constructor" ); |
| 90 |
jsArray = (JSObject) global.eval( "Array.prototype.constructor" ); |
| 91 |
jsRegExp = (JSObject) global.eval("RegExp.prototype.constructor"); |
| 92 |
|
| 93 |
} catch ( Exception e ) { |
| 94 |
System.err.println( "Failed in getBaseObjects: " + e.toString() ); |
| 95 |
e.printStackTrace(); |
| 96 |
return false; |
| 97 |
} |
| 98 |
|
| 99 |
return true; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public Object[] getDataArray() { |
| 114 |
Object item0[] = { |
| 115 |
new String("new String(\"JavaScript String\")"), |
| 116 |
new String ("JavaScript String"), |
| 117 |
jsString }; |
| 118 |
|
| 119 |
Object item1[] = { |
| 120 |
new String( "new Number(12345)" ), |
| 121 |
new String( "12345" ), |
| 122 |
jsNumber }; |
| 123 |
|
| 124 |
Object item2[] = { |
| 125 |
new String( "new Boolean(false)" ), |
| 126 |
new String( "false" ), |
| 127 |
jsBoolean }; |
| 128 |
|
| 129 |
Object item3[] = { |
| 130 |
new String( "new Array(0,1,2,3,4)" ), |
| 131 |
new String( "0,1,2,3,4" ), |
| 132 |
jsArray }; |
| 133 |
|
| 134 |
Object item4[] = { |
| 135 |
new String( "new Object()" ), |
| 136 |
new String( "[object Object]" ), |
| 137 |
jsObject }; |
| 138 |
|
| 139 |
Object dataArray[] = { item0, item1, item2, item3, item4 }; |
| 140 |
return dataArray; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public JSObject createJSArray( String newArrayArguments ) { |
| 152 |
JSObject jsArray = null; |
| 153 |
String args = "var jsArray = new Array( " + newArrayArguments +" )"; |
| 154 |
String result = "passed!"; |
| 155 |
try { |
| 156 |
System.out.println( args ); |
| 157 |
global.eval( args ); |
| 158 |
jsArray = (JSObject) global.getMember("jsArray"); |
| 159 |
|
| 160 |
} catch ( Exception e ) { |
| 161 |
result = "failed!"; |
| 162 |
exception = "global.getMember(\"jsArray\")"+ |
| 163 |
"threw " + e.toString(); |
| 164 |
file.exception += exception; |
| 165 |
e.printStackTrace(); |
| 166 |
} finally { |
| 167 |
addTestCase( |
| 168 |
"global.eval(\"var jsArray = "+ |
| 169 |
"new Array(\""+newArrayArguments+"\"); " + |
| 170 |
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")", |
| 171 |
"passed!", |
| 172 |
result, |
| 173 |
exception ); |
| 174 |
} |
| 175 |
return jsArray; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public void getLength( JSObject jsArray, int javaLength ) { |
| 185 |
String exception = ""; |
| 186 |
int jsLength = 0; |
| 187 |
|
| 188 |
try { |
| 189 |
jsLength = ((Double) jsArray.getMember("length")).intValue(); |
| 190 |
} catch ( Exception e ) { |
| 191 |
exception = "jsArray.getMember(\"length\") threw "+ |
| 192 |
e.toString(); |
| 193 |
file.exception += exception; |
| 194 |
e.printStackTrace(); |
| 195 |
} finally { |
| 196 |
addTestCase( |
| 197 |
"[length is " + jsLength +"] "+ |
| 198 |
"( jsArray.getMember(\"length\")).intValue() == " + |
| 199 |
javaLength +" )", |
| 200 |
"true", |
| 201 |
(jsLength == javaLength) + "", |
| 202 |
exception ); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
public void getSlot( JSObject jsArray, int slot, Object[] data ) { |
| 218 |
String exception = ""; |
| 219 |
JSObject constructor = null; |
| 220 |
JSObject result = null; |
| 221 |
Class eClass = null; |
| 222 |
Class aClass = null; |
| 223 |
|
| 224 |
try { |
| 225 |
result = (JSObject) jsArray.getSlot( slot ); |
| 226 |
if ( result != null ) { |
| 227 |
eClass = Class.forName( "netscape.javascript.JSObject" ); |
| 228 |
aClass = result.getClass(); |
| 229 |
constructor = (JSObject) result.getMember( "constructor" ); |
| 230 |
} |
| 231 |
} catch ( Exception e ) { |
| 232 |
exception = "jsArray.getSlot( " + slot + " ) "+ |
| 233 |
"threw " + e.toString(); |
| 234 |
file.exception += exception; |
| 235 |
e.printStackTrace(); |
| 236 |
} finally { |
| 237 |
if ( result == null ) { |
| 238 |
addTestCase( |
| 239 |
"[jsArray.getSlot(" + slot +").toString().trim() returned " + result +"] "+ |
| 240 |
"( " + data[1] +".equals( " + result +" )", |
| 241 |
"true", |
| 242 |
data[1].toString().trim().equals( result.toString() ) +"", |
| 243 |
exception ); |
| 244 |
|
| 245 |
} else { |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
addTestCase( |
| 258 |
"( " + eClass +".equals( " + aClass +" ) )", |
| 259 |
"true", |
| 260 |
eClass.equals( aClass ) +"", |
| 261 |
exception ); |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
addTestCase( |
| 266 |
"( " + constructor +".equals( " + data[2] +" ) )", |
| 267 |
"true", |
| 268 |
constructor.equals( data[2] ) +"", |
| 269 |
exception ); |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
|