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 = 'number-002.js';
42 File Name: number-001.js
45 Accessing a Java field whose value is one of the primitive Java types
46 below, JavaScript should read this as a JavaScript Number object.
56 1. Instantiate a new Java object that has a field whose type one of
57 the above primitive Java types, OR get the value of a class's static
59 2. Check the value of the returned object
60 3. Check the type of the returned object, which should be "object"
61 4. Check the class of the returned object using Object.prototype.toString,
62 which should return "[object Number]"
64 It is an error if the type of the JavaScript variable is "number" or if
65 its class is JavaObject.
67 @author christine@netscape.com
70 var SECTION = "LiveConnect";
72 var TITLE = "Java Number Primitive to JavaScript Object";
75 writeHeaderToLog( SECTION + " "+ TITLE);
77 // In all test cases, the expected type is "object, and the expected
80 var E_TYPE = "number";
82 // Create arrays of actual results (java_array) and expected results
85 var java_array = new Array();
86 var test_array = new Array();
90 // Get a static java field whose type is byte.
92 java_array[i] = new JavaValue( java.lang.Byte.MIN_VALUE );
93 test_array[i] = new TestValue( "java.lang.Byte.MIN_VALUE",
97 // Get a static java field whose type is short.
98 java_array[i] = new JavaValue( java.lang.Short.MIN_VALUE );
99 test_array[i] = new TestValue( "java.lang.Short.MIN_VALUE",
103 // Get a static java field whose type is int.
105 java_array[i] = new JavaValue( java.lang.Integer.MIN_VALUE );
106 test_array[i] = new TestValue( "java.lang.Integer.MIN_VALUE",
111 // Instantiate a class, and get a field in that class whose type is int.
113 var java_rect = new java.awt.Rectangle( 1,2,3,4 );
115 java_array[i] = new JavaValue( java_rect.width );
116 test_array[i] = new TestValue( "java_object = new java.awt.Rectangle( 1,2,3,4 ); java_object.width",
120 // Get a static java field whose type is long.
121 java_array[i] = new JavaValue( java.lang.Long.MIN_VALUE );
122 test_array[i] = new TestValue( "java.lang.Long.MIN_VALUE",
123 -9223372036854776000 );
126 // Get a static java field whose type is float.
127 java_array[i] = new JavaValue( java.lang.Float.MAX_VALUE );
128 test_array[i] = new TestValue( "java.lang.Float.MAX_VALUE",
129 3.4028234663852886e+38 )
132 // Get a static java field whose type is double.
133 java_array[i] = new JavaValue( java.lang.Double.MAX_VALUE );
134 test_array[i] = new TestValue( "java.lang.Double.MAX_VALUE",
135 1.7976931348623157e+308 )
138 // Get a static java field whose type is char.
139 java_array[i] = new JavaValue( java.lang.Character.MAX_VALUE );
140 test_array[i] = new TestValue( "java.lang.Character.MAX_VALUE",
144 for ( i = 0; i < java_array.length; i++ ) {
145 CompareValues( java_array[i], test_array[i] );
150 function CompareValues( javaval, testval ) {
152 new TestCase( SECTION,
158 new TestCase( SECTION,
159 "typeof (" + testval.description +")",
163 function JavaValue( value ) {
164 this.value = value.valueOf();
165 this.type = typeof value;
168 function TestValue( description, value, type ) {
169 this.description = description;
172 // this.classname = classname;