Debian Codegraph @

rhino/testsrc/tests/lc2/Objects/object-002.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'object-002.js';
7
8 /**
9 File Name: object-002.js
10 Description:
11
12 Given a JavaObject, calling the getClass() method of java.lang.Object
13 should return the java.lang.Class of that object.
14
15 This tests the LiveConnect function getClass( <javaobject> ), which
16 should be a defined function that returns the JavaClass object for
17 a JavaObject instance.
18
19 The absense of the getClass function is
20 http://scopus/bugsplat/show_bug.cgi?id=106560
21
22 To test this:
23
24 1. Create a JavaObject by instantiating a new object OR call
25 a java method that returns a JavaObject.
26
27 2. Call the getClass() function with the object as its argument.
28
29 3. Compare the result of 2 to the Class.
30
31 @author [email protected]
32 @version 1.00
33 */
34 var SECTION = "LiveConnect Objects";
35 var VERSION = "1_3";
36 var TITLE = "Getting the Class of JavaObjects";
37
38 startTest();
39 writeHeaderToLog( SECTION + " "+ TITLE);
40
41 // All JavaObjects are of the type "object"
42
43 var E_TYPE = "object";
44
45 // All JavaObjects [[Class]] property is JavaObject
46 var E_JSCLASS = "[object JavaObject]";
47
48 // Create arrays of actual results (java_array) and
49 // expected results (test_array).
50
51 var java_array = new Array();
52 var test_array = new Array();
53
54 var i = 0;
55
56 java_array[i] = new JavaValue( new java.awt.Rectangle(1,2,3,4) );
57 test_array[i] = new TestValue( "new java.awt.Rectangle(1,2,3,4)", "java.awt.Rectangle" );
58 i++;
59
60 java_array[i] = new JavaValue( new java.io.PrintStream( java.lang.System.out ) );
61 test_array[i] = new TestValue( "new java.io.PrintStream(java.lang.System.out)", "java.io.PrintStream" );
62 i++;
63
64 java_array[i] = new JavaValue( new java.lang.String("hello") );
65 test_array[i] = new TestValue( "new java.lang.String('hello')", "java.lang.String" );
66 i++;
67
68 java_array[i] = new JavaValue( new java.net.URL("http://home.netscape.com/") );
69 test_array[i] = new TestValue( "new java.net.URL('http://home.netscape.com')", "java.net.URL" );
70 i++;
71
72 /*
73 java_array[i] = new JavaValue( java.rmi.RMISecurityManager );
74 test_array[i] = new TestValue( "java.rmi.RMISecurityManager" );
75 i++;
76 java_array[i] = new JavaValue( java.text.DateFormat );
77 test_array[i] = new TestValue( "java.text.DateFormat" );
78 i++;
79 */
80 java_array[i] = new JavaValue( new java.util.Vector() );
81 test_array[i] = new TestValue( "new java.util.Vector()", "java.util.Vector" );
82 i++;
83
84 /*
85 java_array[i] = new JavaValue( new Packages.com.netscape.javascript.Context() );
86 test_array[i] = new TestValue( "new Packages.com.netscape.javascript.Context()", "com.netscape.javascript.Context" );
87 i++;
88
89 */
90 for ( i = 0; i < java_array.length; i++ ) {
91 CompareValues( java_array[i], test_array[i] );
92 }
93
94 test();
95
96 function CompareValues( javaval, testval ) {
97 // Check type, which should be E_TYPE
98 new TestCase( SECTION,
99 "typeof (" + testval.description +" )",
100 testval.type,
101 javaval.type );
102 /*
103 // Check JavaScript class, which should be E_JSCLASS
104 new TestCase( SECTION,
105 "(" + testval.description +" ).getJSClass()",
106 testval.jsclass,
107 javaval.jsclass );
108 */
109 // Check the JavaClass, which should be the same as the result as Class.forName(description).
110 new TestCase( SECTION,
111 testval.description +".getClass().equals( " +
112 "java.lang.Class.forName( '" + testval.classname +
113 "' ) )",
114 true,
115 javaval.javaclass.equals( testval.javaclass ) );
116 }
117 function JavaValue( value ) {
118 this.type = typeof value;
119 // LC2 does not support the __proto__ property in Java objects
120 // Object.prototype.toString will show its JavaScript wrapper object.
121 // value.__proto__.getJSClass = Object.prototype.toString;
122 // this.jsclass = value.getJSClass();
123 this.javaclass = value.getClass();
124 return this;
125 }
126 function TestValue( description, classname ) {
127 this.description = description;
128 this.classname = classname;
129 this.type = E_TYPE;
130 this.jsclass = E_JSCLASS;
131 this.javaclass = java.lang.Class.forName( classname );
132 return this;
133 }