1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile = 'boolean-005.js';
42 File Name: boolean-005.js
45 A java.lang.Boolean object should be read as a JavaScript JavaObject.
47 @author christine@netscape.com
50 var SECTION = "LiveConnect";
52 var TITLE = "Java Boolean Object to JavaScript Object";
55 writeHeaderToLog( SECTION + " "+ TITLE);
57 // In all test cases, the expected type is "object"
59 var E_TYPE = "object";
61 // The JavaScrpt [[Class]] of a JavaObject should be JavaObject"
63 var E_JSCLASS = "[object JavaObject]";
65 // The Java class of this object is java.lang.Boolean.
67 var E_JAVACLASS = java.lang.Class.forName( "java.lang.Boolean" );
69 // Create arrays of actual results (java_array) and expected results
72 var java_array = new Array();
73 var test_array = new Array();
77 // Test for java.lang.Boolean.FALSE, which is a Boolean object.
78 java_array[i] = new JavaValue( java.lang.Boolean.FALSE );
79 test_array[i] = new TestValue( "java.lang.Boolean.FALSE",
84 // Test for java.lang.Boolean.TRUE, which is a Boolean object.
85 java_array[i] = new JavaValue( java.lang.Boolean.TRUE );
86 test_array[i] = new TestValue( "java.lang.Boolean.TRUE",
91 for ( i = 0; i < java_array.length; i++ ) {
92 CompareValues( java_array[i], test_array[i] );
98 function CompareValues( javaval, testval ) {
99 // Check booleanValue()
100 new TestCase( SECTION,
101 "("+testval.description+").booleanValue()",
104 // Check typeof, which should be E_TYPE
105 new TestCase( SECTION,
106 "typeof (" + testval.description +")",
110 // Check JavaScript class, which should be E_JSCLASS
111 new TestCase( SECTION,
112 "(" + testval.description +").getJSClass()",
116 // Check Java class, which should equal() E_JAVACLASS
117 new TestCase( SECTION,
118 "(" + testval.description +").getClass().equals( " + E_JAVACLASS +" )",
120 javaval.javaclass.equals( testval.javaclass ) );
122 // Check string representation
123 new TestCase( SECTION,
124 "("+ testval.description+") + ''",
128 function JavaValue( value ) {
129 // java.lang.Object.getClass() returns the Java Object's class.
130 this.javaclass = value.getClass();
133 // __proto__ of Java objects is not supported in LC2.
134 // Object.prototype.toString will show its JavaScript wrapper object.
135 // value.__proto__.getJSClass = Object.prototype.toString;
136 // this.jsclass = value.getJSClass();
138 this.string = value + "";
139 print( this.string );
140 this.value = value.booleanValue();
141 this.type = typeof value;
145 function TestValue( description, value ) {
146 this.description = description;
147 this.string = String( value );
150 this.javaclass = E_JAVACLASS;
151 this.jsclass = E_JSCLASS;