Debian Codegraph @

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