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