1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
5 /* ***** BEGIN LICENSE BLOCK *****
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
18 * The Original Code is Mozilla Communicator client code, released
21 * The Initial Developer of the Original Code is
22 * Netscape Communications Corporation.
23 * Portions created by the Initial Developer are Copyright (C) 1998
24 * the Initial Developer. All Rights Reserved.
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 gTestfile = 'ToDouble-003.js';
45 * JavaScript to Java type conversion.
47 * This test passes JavaScript number values to several Java methods
48 * that expect arguments of various types, and verifies that the value is
49 * converted to the correct value and type.
51 * This tests instance methods, and not static methods.
53 * Running these tests successfully requires you to have
54 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
56 * Specification: Method Overloading Proposal for Liveconnect 3.0
58 * @author: christine@netscape.com
61 var SECTION = "number conversion to float";
63 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
72 // passing a number value to a method that expects a float should round JS
73 // number to float precision. unrepresentably large values are converted
76 // Special cases: 0, -0, Infinity, -Infinity, and NaN
78 a[i++] = new TestObject(
82 "typeof dt.getFloat()",
86 a[i++] = new TestObject(
88 "Infinity / dt.PUB_FLOAT",
89 "Infinity / dt.getFloat()",
90 "typeof dt.getFloat()",
94 a[i++] = new TestObject(
95 "dt.setFloat( Infinity )",
98 "typeof dt.getFloat()",
102 a[i++] = new TestObject(
103 "dt.setFloat( -Infinity )",
106 "typeof dt.getFloat()",
110 a[i++] = new TestObject(
111 "dt.setFloat( NaN )",
114 "typeof dt.getFloat()",
118 a[i++] = new TestObject(
119 "dt.setFloat( java.lang.Float.MAX_VALUE )",
122 "typeof dt.getFloat()",
123 java.lang.Float.MAX_VALUE,
126 a[i++] = new TestObject(
127 "dt.setFloat( java.lang.Float.MIN_VALUE )",
130 "typeof dt.getFloat()",
131 java.lang.Float.MIN_VALUE,
134 a[i++] = new TestObject(
135 "dt.setFloat( -java.lang.Float.MAX_VALUE )",
138 "typeof dt.getFloat()",
139 -java.lang.Float.MAX_VALUE,
142 a[i++] = new TestObject(
143 "dt.setFloat( -java.lang.Float.MIN_VALUE )",
146 "typeof dt.getFloat()",
147 -java.lang.Float.MIN_VALUE,
150 a[i++] = new TestObject(
151 "dt.setFloat(1.7976931348623157E+308)",
154 "typeof dt.getFloat()",
158 a[i++] = new TestObject(
159 "dt.setFloat(1.7976931348623158e+308)",
162 "typeof dt.getFloat()",
166 a[i++] = new TestObject(
167 "dt.setFloat(1.7976931348623159e+308)",
170 "typeof dt.getFloat()",
174 a[i++] = new TestObject(
175 "dt.setFloat(-1.7976931348623157E+308)",
178 "typeof dt.getFloat()",
182 a[i++] = new TestObject(
183 "dt.setFloat(-1.7976931348623158e+308)",
186 "typeof dt.getFloat()",
190 a[i++] = new TestObject(
191 "dt.setFloat(-1.7976931348623159e+308)",
194 "typeof dt.getFloat()",
198 a[i++] = new TestObject(
199 "dt.setFloat(1e-2000)",
202 "typeof dt.getFloat()",
206 a[i++] = new TestObject(
207 "dt.setFloat(1e2000)",
210 "typeof dt.getFloat()",
214 a[i++] = new TestObject(
215 "dt.setFloat(-1e2000)",
218 "typeof dt.getFloat()",
223 for ( i = 0; i < a.length; i++ ) {
225 a[i].description +"; "+ a[i].javaFieldName,
227 a[i].javaFieldValue );
230 a[i].description +"; " + a[i].javaMethodName,
232 a[i].javaMethodValue );
237 a[i].javaTypeValue );
242 function TestObject( description, javaField, javaMethod, javaType,
247 this.description = description;
248 this.javaFieldName = javaField;
249 this.javaFieldValue = eval( javaField );
250 this.javaMethodName = javaMethod;
251 this.javaMethodValue = eval( javaMethod );
252 this.javaTypeName = javaType,
253 this.javaTypeValue = eval( javaType );
255 this.jsValue = jsValue;
256 this.jsType = jsType;