Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/liveconnect/slot/Slot_006.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package com.netscape.javascript.qa.liveconnect.slot;
6
7 import netscape.javascript.*;
8 import com.netscape.javascript.qa.liveconnect.*;
9
10 /**
11 * Create a JS String. Get the values of characters in that string using
12 * getSlot.
13 *
14 * This covers the following JavaScript -> Java cases through getSlot:
15 * <table border = 1>
16 * <tr>
17 * <th> Java type
18 * <th> JavaScript type
19 * </tr>
20 * <tr>
21 * <td> string
22 * <td> java.lang.String
23 * </tr>
24 * </table>
25 *
26 * @see netscape.javascript.JSObject#getSlot
27 * @see netscape.javascript.JSObject#setSlot
28 *
29 * @author christine m begle
30 */
31 public class Slot_006 extends LiveConnectTest {
32 public Slot_006() {
33 super();
34 }
35 public static void main( String[] args ) {
36 Slot_006 test = new Slot_006();
37 test.start();
38 }
39
40 public void executeTest() {
41 Object testMatrix[] = getDataArray();
42
43 for ( int i = 0; i < testMatrix.length; i++ ) {
44 JSObject jsObject = getJSString( (Object[]) testMatrix[i] );
45
46 for ( int j = 0;
47 j < ((String) ((Object[]) testMatrix[i])[1]).length();
48 j++ )
49 {
50 getSlot( jsObject, j, (Object[]) testMatrix[i] );
51 }
52 }
53 }
54
55 public JSObject getJSString ( Object[] data ) {
56 return (JSObject) data[0];
57 }
58
59 /**
60 * Data in this test contains of :
61 * JavaScript String object
62 * Java object with the same string value
63 *
64 * @return the data array.
65 */
66 public Object[] getDataArray() {
67 Object item0[] = {
68 global.eval("new String(\"passed!\")"),
69 new String("passed!")
70 };
71
72 Object dataArray[] = { item0 };
73 return dataArray;
74 }
75
76 /**
77 * Use JSObject.getSlot to get an indexed member of a JSObject. In this
78 * test, the expected class of all objects is JSObject.
79 *
80 * XXX propbably need to add a bunch of unicode characters here.
81 *
82 * @param jsSTring the JSObject with indexed members
83 * @param slot the index property to retrieve
84 * @param data object array containing the string representation of the
85 * expected result of jsArray.getSlot(slot) and the JSObjectconstructor
86 * of the expected result, which allows us to verify the value and type
87 * of the result object.
88 */
89 public void getSlot( JSObject jsString, int slot, Object[] data ) {
90 String exception = "";
91 JSObject constructor = null;
92 Class eClass = null;
93 Class aClass = null;
94 String result = null;
95 String eResult = null;
96
97 try {
98 eResult = new Character( ((String)data[1]).charAt(slot) ).toString();
99 result = (String) jsString.getSlot( slot );
100 if ( result != null ) {
101 eClass = Class.forName( "java.lang.String" );
102 aClass = result.getClass();
103 }
104 } catch ( Exception e ) {
105 exception = "jsString.getSlot( " + slot + " ) "+
106 "threw " + e.toString();
107 file.exception += exception;
108 e.printStackTrace();
109 } finally {
110 if ( result == null ) {
111 addTestCase(
112 "[jsString.getSlot(" + slot +").toString(). returned " + result +"] "+
113 "( " + eResult +".equals( " + result +" )",
114 "true",
115 eResult.equals( result +"") +"",
116 exception );
117
118 } else {
119 // check the string value of the result
120 addTestCase(
121 "[jsString.getSlot(" + slot +") returned " + result +"] "+
122 eResult +".toString().equals( " + result +" ) ",
123 "true",
124 eResult.equals( result.toString() ) +"",
125 exception );
126
127 // check the class of the result. all should be java.lang.Strings.
128 addTestCase(
129 "( " + eClass +".equals( " + aClass +" ) )",
130 "true",
131 eClass.equals( aClass ) +"",
132 exception );
133 }
134 }
135 }
136 }