Debian Codegraph @

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