Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/liveconnect/jsobject/JSObject_001.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.jsobject;
6
7 import netscape.javascript.*;
8
9 import com.netscape.javascript.qa.liveconnect.LiveConnectTest;
10
11 /**
12 * Try to get properties of the global object. This test verifies that
13 * getMember can access default properties of the global object, and that
14 * the Object returned is an instance of netscape.javascript.JSObject
15 * for objects, and java.lang.Double for numbers (NaN, Infinity).
16 *
17 * @see com.netscape.javascript.qa.liveconnect.LiveConnectTest
18 *
19 * @author [email protected]
20 *
21 */
22 public class JSObject_001 extends LiveConnectTest {
23 public JSObject_001() {
24 super();
25 }
26
27 public static void main( String[] args ) {
28 JSObject_001 test = new JSObject_001();
29 test.start();
30 }
31
32 public void executeTest() {
33 getDouble( "NaN" );
34 getDouble( "Infinity" );
35 getJSObject( "parseInt" );
36 getJSObject( "parseFloat" );
37 getJSObject( "eval" );
38 getJSObject( "escape" );
39 getJSObject( "unescape" );
40 getJSObject( "isNaN" );
41 getJSObject( "isFinite" );
42 getJSObject( "Object" );
43 getJSObject( "Function" );
44 getJSObject( "Array" );
45 getJSObject( "String" );
46 getJSObject( "Boolean" );
47 getJSObject( "Number" );
48 getJSObject( "Date" );
49 getJSObject( "Math" );
50 }
51
52 /**
53 * Try to get a property of the JavaScript Global object. The
54 * type of this property should be a java.lang.Double. If it
55 * is not, the test will fail with a java.lang.ClassCastException.
56 *
57 * @param property name of the JavaScript property to get.
58 */
59 public void getDouble( String property ) {
60 Object jsobject = null;
61 String exception = null;
62
63 String identifier = this.getClass().toString();
64 String description = "Object jsobject = global.getMember(\""+
65 property +"\"); jsobject instanceof java.lang.Double ";
66
67 try {
68 jsobject = global.getMember( property );
69 } catch ( Exception e ) {
70 exception = ("Exception getting " + property +": "+ e.toString());
71 System.err.println( exception );
72 }
73
74 String expect = "true";
75 String actual = (jsobject instanceof java.lang.Double) +"";
76
77 addTestCase( description, expect, actual, exception );
78 }
79
80 /**
81 * Try to get a property of the JavaScript Global object. The type of
82 * this property should be a netscape.javascript.JSObject. If it is not,
83 * the test will fail with a java.lang.ClassCastException.
84 *
85 * @param property name of the JavaScript property to get.
86 */
87 public void getJSObject( String property ) {
88 Object jsobject = null;
89 String exception = null;
90
91 String identifier = this.getClass().toString();
92 String description = "Object jsobject = global.getMember(\""+
93 property +"\"); jsobject instanceof JSObject ";
94
95 try {
96 jsobject = global.getMember( property );
97 } catch ( Exception e ) {
98 exception = ("Exception getting " + property +": "+ e.toString());
99 System.err.println( exception );
100 }
101
102 String expect = "true";
103 String actual = (jsobject instanceof JSObject) +"";
104
105 addTestCase( description, expect, actual, exception );
106 }
107 }