Debian Codegraph @

rhino/testsrc/tests/lc2/JavaToJS/boolean-005.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 = 'boolean-005.js';
7
8 /**
9 File Name: boolean-005.js
10 Description:
11
12 A java.lang.Boolean object should be read as a JavaScript JavaObject.
13
14 @author [email protected]
15 @version 1.00
16 */
17 var SECTION = "LiveConnect";
18 var VERSION = "1_3";
19 var TITLE = "Java Boolean Object to JavaScript Object";
20
21 startTest();
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24 // In all test cases, the expected type is "object"
25
26 var E_TYPE = "object";
27
28 // The JavaScrpt [[Class]] of a JavaObject should be JavaObject"
29
30 var E_JSCLASS = "[object JavaObject]";
31
32 // The Java class of this object is java.lang.Boolean.
33
34 var E_JAVACLASS = java.lang.Class.forName( "java.lang.Boolean" );
35
36 // Create arrays of actual results (java_array) and expected results
37 // (test_array).
38
39 var java_array = new Array();
40 var test_array = new Array();
41
42 var i = 0;
43
44 // Test for java.lang.Boolean.FALSE, which is a Boolean object.
45 java_array[i] = new JavaValue( java.lang.Boolean.FALSE );
46 test_array[i] = new TestValue( "java.lang.Boolean.FALSE",
47 false );
48
49 i++;
50
51 // Test for java.lang.Boolean.TRUE, which is a Boolean object.
52 java_array[i] = new JavaValue( java.lang.Boolean.TRUE );
53 test_array[i] = new TestValue( "java.lang.Boolean.TRUE",
54 true );
55
56 i++;
57
58 for ( i = 0; i < java_array.length; i++ ) {
59 CompareValues( java_array[i], test_array[i] );
60
61 }
62
63 test();
64
65 function CompareValues( javaval, testval ) {
66 // Check booleanValue()
67 new TestCase( SECTION,
68 "("+testval.description+").booleanValue()",
69 testval.value,
70 javaval.value );
71 // Check typeof, which should be E_TYPE
72 new TestCase( SECTION,
73 "typeof (" + testval.description +")",
74 testval.type,
75 javaval.type );
76 /*
77 // Check JavaScript class, which should be E_JSCLASS
78 new TestCase( SECTION,
79 "(" + testval.description +").getJSClass()",
80 testval.jsclass,
81 javaval.jsclass );
82 */
83 // Check Java class, which should equal() E_JAVACLASS
84 new TestCase( SECTION,
85 "(" + testval.description +").getClass().equals( " + E_JAVACLASS +" )",
86 true,
87 javaval.javaclass.equals( testval.javaclass ) );
88
89 // Check string representation
90 new TestCase( SECTION,
91 "("+ testval.description+") + ''",
92 testval.string,
93 javaval.string );
94 }
95 function JavaValue( value ) {
96 // java.lang.Object.getClass() returns the Java Object's class.
97 this.javaclass = value.getClass();
98
99
100 // __proto__ of Java objects is not supported in LC2.
101 // Object.prototype.toString will show its JavaScript wrapper object.
102 // value.__proto__.getJSClass = Object.prototype.toString;
103 // this.jsclass = value.getJSClass();
104
105 this.string = value + "";
106 print( this.string );
107 this.value = value.booleanValue();
108 this.type = typeof value;
109
110 return this;
111 }
112 function TestValue( description, value ) {
113 this.description = description;
114 this.string = String( value );
115 this.value = value;
116 this.type = E_TYPE;
117 this.javaclass = E_JAVACLASS;
118 this.jsclass = E_JSCLASS;
119 return this;
120 }