| 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 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public class Slot_001 extends LiveConnectTest { |
| 56 |
public Slot_001() { |
| 57 |
super(); |
| 58 |
} |
| 59 |
public static void main( String[] args ) { |
| 60 |
Slot_001 test = new Slot_001(); |
| 61 |
test.start(); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
Object test1[] = { new String("null"), null }; |
| 69 |
Object test2[] = { new String( "" ) }; |
| 70 |
Object test3[] = { new String("true,\"hi\",3.14159"), |
| 71 |
new Boolean(true), new String("hi"), new Double("3.14159") }; |
| 72 |
|
| 73 |
Object test4[] = { new String( "new java.lang.Boolean(true), " + |
| 74 |
"new java.lang.String(\"hello\"), java.lang.System.out, "+ |
| 75 |
"new java.lang.Integer(5)"), |
| 76 |
new Boolean(true), |
| 77 |
new String("hello"), |
| 78 |
System.out, |
| 79 |
new Integer(5) }; |
| 80 |
|
| 81 |
Object testMatrix[] = { test1, test2, test3, test4 }; |
| 82 |
|
| 83 |
public void executeTest() { |
| 84 |
for ( int i = 0; i < testMatrix.length; i++ ) { |
| 85 |
String args = (String) ((Object[]) testMatrix[i])[0]; |
| 86 |
|
| 87 |
JSObject jsArray = createJSArray( args ); |
| 88 |
|
| 89 |
|
| 90 |
int javaLength = ((Object[]) testMatrix[i]).length -1; |
| 91 |
|
| 92 |
getLength( jsArray, javaLength ); |
| 93 |
|
| 94 |
for ( int j = 0; j < javaLength ; j++ ) { |
| 95 |
getSlot( jsArray, j, ((Object[]) testMatrix[i])[j+1] ); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public JSObject createJSArray( String newArrayArguments ) { |
| 109 |
JSObject jsArray = null; |
| 110 |
String args = "var jsArray = new Array( " + newArrayArguments +" )"; |
| 111 |
String result = "passed!"; |
| 112 |
try { |
| 113 |
System.out.println( args ); |
| 114 |
global.eval( args ); |
| 115 |
jsArray = (JSObject) global.getMember("jsArray"); |
| 116 |
|
| 117 |
} catch ( Exception e ) { |
| 118 |
result = "failed!"; |
| 119 |
exception = "global.getMember(\"jsArray\")"+ |
| 120 |
"threw " + e.toString(); |
| 121 |
file.exception += exception; |
| 122 |
e.printStackTrace(); |
| 123 |
} finally { |
| 124 |
addTestCase( |
| 125 |
"global.eval(\"var jsArray = "+ |
| 126 |
"new Array(\""+newArrayArguments+"\"); " + |
| 127 |
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")", |
| 128 |
"passed!", |
| 129 |
result, |
| 130 |
exception ); |
| 131 |
} |
| 132 |
return jsArray; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public void getLength( JSObject jsArray, int javaLength ) { |
| 142 |
String exception = ""; |
| 143 |
int jsLength = 0; |
| 144 |
|
| 145 |
try { |
| 146 |
jsLength = ((Double) jsArray.getMember("length")).intValue(); |
| 147 |
} catch ( Exception e ) { |
| 148 |
exception = "jsArray.getMember(\"length\") threw "+ |
| 149 |
e.toString(); |
| 150 |
file.exception += exception; |
| 151 |
e.printStackTrace(); |
| 152 |
} finally { |
| 153 |
addTestCase( |
| 154 |
"[length is " + jsLength +"] "+ |
| 155 |
"( jsArray.getMember(\"length\")).intValue() == " + |
| 156 |
javaLength +" )", |
| 157 |
"true", |
| 158 |
(jsLength == javaLength) + "", |
| 159 |
exception ); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public void getSlot( JSObject jsArray, int slot, Object javaValue ) { |
| 172 |
String exception = ""; |
| 173 |
Object result = null; |
| 174 |
Class eClass = null; |
| 175 |
Class aClass = null; |
| 176 |
|
| 177 |
try { |
| 178 |
result = jsArray.getSlot( slot ); |
| 179 |
if ( javaValue != null ) { |
| 180 |
eClass = javaValue.getClass(); |
| 181 |
aClass = result.getClass(); |
| 182 |
} |
| 183 |
} catch ( Exception e ) { |
| 184 |
exception = "jsArray.getSlot( " + slot + " ) "+ |
| 185 |
"threw " + e.toString(); |
| 186 |
file.exception += exception; |
| 187 |
e.printStackTrace(); |
| 188 |
} finally { |
| 189 |
if ( javaValue == null ) { |
| 190 |
addTestCase( |
| 191 |
"[jsArray.getSlot(" + slot +") returned " + result +"] "+ |
| 192 |
"( " +javaValue +" == " + result +" )", |
| 193 |
"true", |
| 194 |
(javaValue == result ) +"", |
| 195 |
exception ); |
| 196 |
|
| 197 |
} else { |
| 198 |
addTestCase( |
| 199 |
"[jsArray.getSlot(" + slot +") returned " + result +"] "+ |
| 200 |
javaValue +".equals( " + result +" ) ", |
| 201 |
"true", |
| 202 |
javaValue.equals( result ) +"", |
| 203 |
exception ); |
| 204 |
|
| 205 |
addTestCase( |
| 206 |
"( " + eClass +".equals( " + aClass +" ) )", |
| 207 |
"true", |
| 208 |
eClass.equals( aClass ) +"", |
| 209 |
exception ); |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
public void setSlot( JSObject jsArray, int slot, Object javaValue ) { |
| 223 |
String exception = null; |
| 224 |
String result = "passed!"; |
| 225 |
|
| 226 |
try { |
| 227 |
jsArray.setSlot( slot, javaValue ); |
| 228 |
} catch ( Exception e ) { |
| 229 |
result = "failed!"; |
| 230 |
exception = "jsArray.setSlot( " + slot +","+ javaValue +") "+ |
| 231 |
"threw " + e.toString(); |
| 232 |
file.exception += exception; |
| 233 |
e.printStackTrace(); |
| 234 |
} finally { |
| 235 |
addTestCase( |
| 236 |
"jsArray.setSlot( " + slot +", "+ javaValue +")", |
| 237 |
"passed!", |
| 238 |
result, |
| 239 |
exception ); |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|