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