Debian Codegraph @

rhino/testsrc/tests/lc2/Packages/package-003.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 = 'package-003.js';
7
8 /**
9 File Name: package-003.js
10 Description:
11
12 Set the package name to a JavaScript variable, and attempt to access
13 classes relative to the package name.
14
15 @author [email protected]
16 @version 1.00
17 */
18 var SECTION = "LiveConnect Packages";
19 var VERSION = "1_3";
20 var TITLE = "LiveConnect Packages";
21
22 startTest();
23 writeHeaderToLog( SECTION + " "+ TITLE);
24
25 // All packages are of the type "object"
26 var E_TYPE = "object";
27
28 // The JavaScript [[Class]] property for all Packages is "[JavaPackage <packagename>]"
29 var E_JSCLASS = "[JavaPackage ";
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 var js = Packages.javax.javascript;
40
41 java_array[i] = new JavaValue( js );
42 test_array[i] = new TestValue( "javax.javascript" );
43 i++;
44
45 var util = java.util;
46
47 java_array[i] = new JavaValue( util );
48 test_array[i] = new TestValue( "java.util" );
49 i++;
50
51 for ( i = 0; i < java_array.length; i++ ) {
52 CompareValues( java_array[i], test_array[i] );
53
54 }
55
56 var v = new util.Vector();
57
58 test();
59
60 function CompareValues( javaval, testval ) {
61 // Check typeof, which should be E_TYPE
62 new TestCase( SECTION,
63 "typeof (" + testval.description +")",
64 testval.type,
65 javaval.type );
66
67 // Check JavaScript class, which should be E_JSCLASS + the package name
68 new TestCase( SECTION,
69 "(" + testval.description +").getJSClass()",
70 testval.jsclass,
71 javaval.jsclass );
72
73 // Number( package ) is NaN
74 new TestCase( SECTION,
75 "Number (" + testval.description +")",
76 NaN,
77 Number( javaval.value ) );
78
79 // String( package ) is string value
80 new TestCase( SECTION,
81 "String (" + testval.description +")",
82 testval.jsclass,
83 String(javaval.value) );
84 /*
85 // ( package ).toString() is string value
86 new TestCase( SECTION,
87 "(" + testval.description +").toString()",
88 testval.jsclass,
89 (javaval.value).toString() );
90 */
91 // Boolean( package ) is true
92 new TestCase( SECTION,
93 "Boolean (" + testval.description +")",
94 true,
95 Boolean( javaval.value ) );
96 // add 0 is name + "0"
97 new TestCase( SECTION,
98 "(" + testval.description +") +0",
99 testval.jsclass +"0",
100 javaval.value + 0);
101 }
102 function JavaValue( value ) {
103 this.value = value;
104 this.type = typeof value;
105 this.jsclass = value +""
106 return this;
107 }
108 function TestValue( description ) {
109 this.packagename = (description.substring(0, "Packages.".length) ==
110 "Packages.") ? description.substring("Packages.".length, description.length ) :
111 description;
112
113 this.description = description;
114 this.type = E_TYPE;
115 this.jsclass = E_JSCLASS + this.packagename +"]";
116 return this;
117 }