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
= 'ToDouble-001.js';
41 /* -*- Mode: java; tab-width: 8 -*-
42 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
43 * All Rights Reserved.
47 * JavaScript to Java type conversion.
49 * This test passes JavaScript number values to several Java methods
50 * that expect arguments of various types, and verifies that the value is
51 * converted to the correct value and type.
53 * This tests instance methods, and not static methods.
55 * Running these tests successfully requires you to have
56 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
58 * Specification: Method Overloading Proposal for Liveconnect 3.0
60 * @author: christine@netscape.com
63 var SECTION
= "number conversion";
65 var TITLE
= "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
74 // passing a number to a java method that expects a double should
75 // transfer the exact value to java with no rounding or loss of magnitude
78 // Special cases: 0, -0, Infinity, -Infinity, and NaN
80 a
[i
++] = new TestObject(
84 "typeof dt.getDouble()",
88 a
[i
++] = new TestObject(
90 "Infinity / dt.PUB_DOUBLE",
91 "Infinity / dt.getDouble()",
92 "typeof dt.getDouble()",
96 a
[i
++] = new TestObject(
97 "dt.setDouble( Infinity )",
100 "typeof dt.getDouble()",
104 a
[i
++] = new TestObject(
105 "dt.setDouble( -Infinity )",
108 "typeof dt.getDouble()",
112 a
[i
++] = new TestObject(
113 "dt.setDouble( NaN )",
116 "typeof dt.getDouble()",
120 // test cases from waldemar
122 a
[i
++] = new TestObject(
123 "dt.setDouble(077777777777777777)",
126 "typeof dt.getDouble()",
131 a
[i
++] = new TestObject(
132 "dt.setDouble(077777777777777776)",
135 "typeof dt.getDouble()",
140 a
[i
++] = new TestObject(
141 "dt.setDouble(0x1fffffffffffff)",
144 "typeof dt.getDouble()",
148 a
[i
++] = new TestObject(
149 "dt.setDouble(0x20000000000000)",
152 "typeof dt.getDouble()",
156 a
[i
++] = new TestObject(
157 "dt.setDouble(0x20123456789abc)",
160 "typeof dt.getDouble()",
164 a
[i
++] = new TestObject(
165 "dt.setDouble(0x20123456789abd)",
168 "typeof dt.getDouble()",
172 a
[i
++] = new TestObject(
173 "dt.setDouble(0x20123456789abe)",
176 "typeof dt.getDouble()",
180 a
[i
++] = new TestObject(
181 "dt.setDouble(0x20123456789abf)",
184 "typeof dt.getDouble()",
188 a
[i
++] = new TestObject(
189 "dt.setDouble(0x1000000000000080)",
192 "typeof dt.getDouble()",
196 a
[i
++] = new TestObject(
197 "dt.setDouble(0x1000000000000081)",
200 "typeof dt.getDouble()",
204 a
[i
++] = new TestObject(
205 "dt.setDouble(0x1000000000000100)",
208 "typeof dt.getDouble()",
212 a
[i
++] = new TestObject(
213 "dt.setDouble(0x100000000000017f)",
216 "typeof dt.getDouble()",
220 a
[i
++] = new TestObject(
221 "dt.setDouble(0x1000000000000180)",
224 "typeof dt.getDouble()",
228 a
[i
++] = new TestObject(
229 "dt.setDouble(0x1000000000000181)",
232 "typeof dt.getDouble()",
236 a
[i
++] = new TestObject(
237 "dt.setDouble(1.7976931348623157E+308)",
240 "typeof dt.getDouble()",
241 1.7976931348623157e+308,
244 a
[i
++] = new TestObject(
245 "dt.setDouble(1.7976931348623158e+308)",
248 "typeof dt.getDouble()",
249 1.7976931348623157e+308,
252 a
[i
++] = new TestObject(
253 "dt.setDouble(1.7976931348623159e+308)",
256 "typeof dt.getDouble()",
260 a
[i
++] = new TestObject(
261 "dt.setDouble(-1.7976931348623157E+308)",
264 "typeof dt.getDouble()",
265 -1.7976931348623157e+308,
268 a
[i
++] = new TestObject(
269 "dt.setDouble(-1.7976931348623158e+308)",
272 "typeof dt.getDouble()",
273 -1.7976931348623157e+308,
276 a
[i
++] = new TestObject(
277 "dt.setDouble(-1.7976931348623159e+308)",
280 "typeof dt.getDouble()",
284 a
[i
++] = new TestObject(
285 "dt.setDouble(1e-2000)",
288 "typeof dt.getDouble()",
292 a
[i
++] = new TestObject(
293 "dt.setDouble(1e2000)",
296 "typeof dt.getDouble()",
300 a
[i
++] = new TestObject(
301 "dt.setDouble(-1e2000)",
304 "typeof dt.getDouble()",
308 for ( i
= 0; i
< a
.length
; i
++ ) {
310 a
[i
].description
+"; "+ a
[i
].javaFieldName
,
312 a
[i
].javaFieldValue
);
315 a
[i
].description
+"; " + a
[i
].javaMethodName
,
317 a
[i
].javaMethodValue
);
322 a
[i
].javaTypeValue
);
327 function TestObject( description
, javaField
, javaMethod
, javaType
,
332 this.description
= description
;
333 this.javaFieldName
= javaField
;
334 this.javaFieldValue
= eval( javaField
);
335 this.javaMethodName
= javaMethod
;
336 this.javaMethodValue
= eval( javaMethod
);
337 this.javaTypeName
= javaType
,
338 this.javaTypeValue
= eval( javaType
);
340 this.jsValue
= jsValue
;
341 this.jsType
= jsType
;