Debian Codegraph @

rhino/testsrc/tests/lc2/Classes/class-001.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 = 'class-001.js';
7
8 /**
9 File Name: class-001.js
10 Description:
11
12 @author [email protected]
13 @version 1.00
14 */
15 var SECTION = "LiveConnect Classes";
16 var VERSION = "1_3";
17 var TITLE = "JavaClass objects";
18
19 startTest();
20 writeHeaderToLog( SECTION + " "+ TITLE);
21
22 // All packages are of the type "function", since they implement [[Construct]]
23 // and [[Call]]
24
25 var E_TYPE = "function";
26
27 // The JavaScript [[Class]] property for all Classes is "[object JavaClass]"
28 var E_JSCLASS = "[object JavaClass]";
29
30 // Create arrays of actual results (java_array) and
31 // expected results (test_array).
32
33 var java_array = new Array();
34 var test_array = new Array();
35
36 var i = 0;
37
38 java_array[i] = new JavaValue( java.awt.Image );
39 test_array[i] = new TestValue( "java.awt.Image" );
40 i++;
41
42 java_array[i] = new JavaValue( java.beans.Beans );
43 test_array[i] = new TestValue( "java.beans.Beans" );
44 i++;
45
46 java_array[i] = new JavaValue( java.io.File );
47 test_array[i] = new TestValue( "java.io.File" );
48 i++;
49
50 java_array[i] = new JavaValue( java.lang.String );
51 test_array[i] = new TestValue( "java.lang.String" );
52 i++;
53
54 java_array[i] = new JavaValue( java.math.BigDecimal );
55 test_array[i] = new TestValue( "java.math.BigDecimal" );
56 i++;
57
58 java_array[i] = new JavaValue( java.net.URL );
59 test_array[i] = new TestValue( "java.net.URL" );
60 i++;
61
62 java_array[i] = new JavaValue( java.text.DateFormat );
63 test_array[i] = new TestValue( "java.text.DateFormat" );
64 i++;
65
66 java_array[i] = new JavaValue( java.util.Vector );
67 test_array[i] = new TestValue( "java.util.Vector" );
68 i++;
69 /*
70 java_array[i] = new JavaValue( Packages.com.netscape.javascript.Context );
71 test_array[i] = new TestValue( "Packages.com.netscape.javascript.Context" );
72 i++;
73 */
74 for ( i = 0; i < java_array.length; i++ ) {
75 CompareValues( java_array[i], test_array[i] );
76 }
77
78 test();
79 function CompareValues( javaval, testval ) {
80 // Check type, which should be E_TYPE
81 new TestCase( SECTION,
82 "typeof (" + testval.description +")",
83 testval.type,
84 javaval.type );
85 /*
86 // Check JavaScript class, which should be E_JSCLASS
87 new TestCase( SECTION,
88 "(" + testval.description +".)getJSClass()",
89 testval.jsclass,
90 javaval.jsclass );
91 */
92 // Check the class's name, which should be the description, minus the "Package." part.
93 new TestCase( SECTION,
94 "(" + testval.description +") +''",
95 testval.classname,
96 javaval.classname );
97 }
98 function JavaValue( value ) {
99 // Object.prototype.toString will show its JavaScript wrapper object.
100 // value.__proto__.getJSClass = Object.prototype.toString;
101 // this.jsclass = value.getJSClass();
102
103 this.classname = value +"";
104 this.type = typeof value;
105 return this;
106 }
107 function TestValue( description, value ) {
108 this.description = description;
109 this.type = E_TYPE;
110 this.jclass = E_JSCLASS;
111 this.lcclass = java.lang.Class.forName( description );
112
113 this.classname = "[JavaClass " +
114 ( ( description.substring(0,9) == "Packages." )
115 ? description.substring(9,description.length)
116 : description
117 ) + "]"
118
119
120 return this;
121 }