Debian Codegraph @

rhino/testsrc/tests/lc2/Packages/package-004.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-004.js';
7
8 /**
9 File Name: package-004.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 var util = java.util;
26 var v = new util.Vector();
27
28 new TestCase( SECTION,
29 "var v = new util.Vector(); v.size()",
30 0,
31 v.size() );
32
33 var h = util.Hashcode;
34 var hString = String(h);
35 util.Hashcode = null;
36
37 new TestCase( SECTION,
38 "util.Hashcode = null; String( util.Hashcode )",
39 hString,
40 String( util.Hashcode ) );
41
42 test();
43
44 function CompareValues( javaval, testval ) {
45 // Check typeof, which should be E_TYPE
46 new TestCase( SECTION,
47 "typeof (" + testval.description +")",
48 testval.type,
49 javaval.type );
50
51 // Check JavaScript class, which should be E_JSCLASS + the package name
52 new TestCase( SECTION,
53 "(" + testval.description +").getJSClass()",
54 testval.jsclass,
55 javaval.getJSClass() );
56
57 // Number( package ) is NaN
58 new TestCase( SECTION,
59 "Number (" + testval.description +")",
60 NaN,
61 Number( javaval ) );
62
63 // String( package ) is string value
64 new TestCase( SECTION,
65 "String (" + testval.description +")",
66 testval.jsclass,
67 String(javaval) );
68 // ( package ).toString() is string value
69 new TestCase( SECTION,
70 "(" + testval.description +").toString()",
71 testval.jsclass,
72 (javaval).toString() );
73
74 // Boolean( package ) is true
75 new TestCase( SECTION,
76 "Boolean (" + testval.description +")",
77 true,
78 Boolean( javaval ) );
79 // add 0 is name + "0"
80 new TestCase( SECTION,
81 "(" + testval.description +") +0",
82 testval.jsclass +"0",
83 javaval + 0);
84 }
85 function JavaValue( value ) {
86 this.value = value;
87 this.type = typeof value;
88 this.getJSClass = Object.prototype.toString;
89 this.jsclass = value +""
90 return this;
91 }
92 function TestValue( description ) {
93 this.packagename = (description.substring(0, "Packages.".length) ==
94 "Packages.") ? description.substring("Packages.".length, description.length ) :
95 description;
96
97 this.description = description;
98 this.type = E_TYPE;
99 this.jsclass = E_JSCLASS + this.packagename +"]";
100 return this;
101 }