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