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-002.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";
63 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
72 // passing a number to a java method that expects a Double object should
73 // transfer the exact value to java with no rounding or loss of magnitude
76 // Special cases: 0, -0, Infinity, -Infinity, and NaN
78 a[i++] = new TestObject(
79 "dt.setDoubleObject( 0 )",
80 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
81 "dt.getDoubleObject().doubleValue()",
82 "dt.getDoubleObject().getClass()",
84 java.lang.Class.forName("java.lang.Double") );
86 a[i++] = new TestObject(
87 "dt.setDoubleObject( -0 )",
88 "Infinity / dt.PUB_DOUBLE_OBJECT",
89 "Infinity / dt.getDoubleObject().doubleValue()",
90 "dt.getDoubleObject().getClass()",
92 java.lang.Class.forName("java.lang.Double") );
94 a[i++] = new TestObject(
95 "dt.setDoubleObject( Infinity )",
96 "dt.PUB_DOUBLE_OBJECT.doubleValue() ",
97 "dt.getDoubleObject().doubleValue()",
98 "dt.getDoubleObject().getClass()",
100 java.lang.Class.forName("java.lang.Double") );
102 a[i++] = new TestObject(
103 "dt.setDoubleObject( -Infinity )",
104 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
105 "dt.getDoubleObject().doubleValue()",
106 "dt.getDoubleObject().getClass()",
108 java.lang.Class.forName("java.lang.Double") );
110 a[i++] = new TestObject(
111 "dt.setDoubleObject( NaN )",
112 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
113 "dt.getDoubleObject().doubleValue()",
114 "dt.getDoubleObject().getClass()",
116 java.lang.Class.forName("java.lang.Double") );
118 // test cases from waldemar
120 a[i++] = new TestObject(
121 "dt.setDoubleObject(077777777777777777)",
122 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
123 "dt.getDoubleObject().doubleValue()",
124 "dt.getDoubleObject().getClass()",
126 java.lang.Class.forName("java.lang.Double") );
129 a[i++] = new TestObject(
130 "dt.setDoubleObject(077777777777777776)",
131 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
132 "dt.getDoubleObject().doubleValue()",
133 "dt.getDoubleObject().getClass()",
135 java.lang.Class.forName("java.lang.Double") );
138 a[i++] = new TestObject(
139 "dt.setDoubleObject(0x1fffffffffffff)",
140 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
141 "dt.getDoubleObject().doubleValue()",
142 "dt.getDoubleObject().getClass()",
144 java.lang.Class.forName("java.lang.Double") );
146 a[i++] = new TestObject(
147 "dt.setDoubleObject(0x20000000000000)",
148 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
149 "dt.getDoubleObject().doubleValue()",
150 "dt.getDoubleObject().getClass()",
152 java.lang.Class.forName("java.lang.Double") );
154 a[i++] = new TestObject(
155 "dt.setDoubleObject(0x20123456789abc)",
156 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
157 "dt.getDoubleObject().doubleValue()",
158 "dt.getDoubleObject().getClass()",
160 java.lang.Class.forName("java.lang.Double") );
162 a[i++] = new TestObject(
163 "dt.setDoubleObject(0x20123456789abd)",
164 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
165 "dt.getDoubleObject().doubleValue()",
166 "dt.getDoubleObject().getClass()",
168 java.lang.Class.forName("java.lang.Double") );
170 a[i++] = new TestObject(
171 "dt.setDoubleObject(0x20123456789abe)",
172 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
173 "dt.getDoubleObject().doubleValue()",
174 "dt.getDoubleObject().getClass()",
176 java.lang.Class.forName("java.lang.Double") );
178 a[i++] = new TestObject(
179 "dt.setDoubleObject(0x20123456789abf)",
180 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
181 "dt.getDoubleObject().doubleValue()",
182 "dt.getDoubleObject().getClass()",
184 java.lang.Class.forName("java.lang.Double") );
186 a[i++] = new TestObject(
187 "dt.setDoubleObject(0x1000000000000080)",
188 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
189 "dt.getDoubleObject().doubleValue()",
190 "dt.getDoubleObject().getClass()",
192 java.lang.Class.forName("java.lang.Double") );
194 a[i++] = new TestObject(
195 "dt.setDoubleObject(0x1000000000000081)",
196 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
197 "dt.getDoubleObject().doubleValue()",
198 "dt.getDoubleObject().getClass()",
200 java.lang.Class.forName("java.lang.Double") );
202 a[i++] = new TestObject(
203 "dt.setDoubleObject(0x1000000000000100)",
204 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
205 "dt.getDoubleObject().doubleValue()",
206 "dt.getDoubleObject().getClass()",
208 java.lang.Class.forName("java.lang.Double") );
210 a[i++] = new TestObject(
211 "dt.setDoubleObject(0x100000000000017f)",
212 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
213 "dt.getDoubleObject().doubleValue()",
214 "dt.getDoubleObject().getClass()",
216 java.lang.Class.forName("java.lang.Double") );
218 a[i++] = new TestObject(
219 "dt.setDoubleObject(0x1000000000000180)",
220 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
221 "dt.getDoubleObject().doubleValue()",
222 "dt.getDoubleObject().getClass()",
224 java.lang.Class.forName("java.lang.Double") );
226 a[i++] = new TestObject(
227 "dt.setDoubleObject(0x1000000000000181)",
228 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
229 "dt.getDoubleObject().doubleValue()",
230 "dt.getDoubleObject().getClass()",
232 java.lang.Class.forName("java.lang.Double") );
234 a[i++] = new TestObject(
235 "dt.setDoubleObject(1.7976931348623157E+308)",
236 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
237 "dt.getDoubleObject().doubleValue()",
238 "dt.getDoubleObject().getClass()",
239 1.7976931348623157e+308,
240 java.lang.Class.forName("java.lang.Double") );
242 a[i++] = new TestObject(
243 "dt.setDoubleObject(1.7976931348623158e+308)",
244 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
245 "dt.getDoubleObject().doubleValue()",
246 "dt.getDoubleObject().getClass()",
247 1.7976931348623157e+308,
248 java.lang.Class.forName("java.lang.Double") );
250 a[i++] = new TestObject(
251 "dt.setDoubleObject(1.7976931348623159e+308)",
252 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
253 "dt.getDoubleObject().doubleValue()",
254 "dt.getDoubleObject().getClass()",
256 java.lang.Class.forName("java.lang.Double") );
258 a[i++] = new TestObject(
259 "dt.setDoubleObject(-1.7976931348623157E+308)",
260 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
261 "dt.getDoubleObject().doubleValue()",
262 "dt.getDoubleObject().getClass()",
263 -1.7976931348623157e+308,
264 java.lang.Class.forName("java.lang.Double") );
266 a[i++] = new TestObject(
267 "dt.setDoubleObject(-1.7976931348623158e+308)",
268 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
269 "dt.getDoubleObject().doubleValue()",
270 "dt.getDoubleObject().getClass()",
271 -1.7976931348623157e+308,
272 java.lang.Class.forName("java.lang.Double") );
274 a[i++] = new TestObject(
275 "dt.setDoubleObject(-1.7976931348623159e+308)",
276 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
277 "dt.getDoubleObject().doubleValue()",
278 "dt.getDoubleObject().getClass()",
280 java.lang.Class.forName("java.lang.Double") );
282 a[i++] = new TestObject(
283 "dt.setDoubleObject(1e-2000)",
284 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
285 "dt.getDoubleObject().doubleValue()",
286 "dt.getDoubleObject().getClass()",
288 java.lang.Class.forName("java.lang.Double") );
290 a[i++] = new TestObject(
291 "dt.setDoubleObject(1e2000)",
292 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
293 "dt.getDoubleObject().doubleValue()",
294 "dt.getDoubleObject().getClass()",
296 java.lang.Class.forName("java.lang.Double") );
298 a[i++] = new TestObject(
299 "dt.setDoubleObject(-1e2000)",
300 "dt.PUB_DOUBLE_OBJECT.doubleValue()",
301 "dt.getDoubleObject().doubleValue()",
302 "dt.getDoubleObject().getClass()",
304 java.lang.Class.forName("java.lang.Double") );
306 for ( i = 0; i < a.length; i++ ) {
308 a[i].description +"; "+ a[i].javaFieldName,
310 a[i].javaFieldValue );
313 a[i].description +"; " + a[i].javaMethodName,
315 a[i].javaMethodValue );
320 a[i].javaTypeValue );
325 function TestObject( description, javaField, javaMethod, javaType,
330 this.description = description;
331 this.javaFieldName = javaField;
332 this.javaFieldValue = eval( javaField );
333 this.javaMethodName = javaMethod;
334 this.javaMethodValue = eval( javaMethod );
335 this.javaTypeName = javaType,
336 this.javaTypeValue = eval( javaType );
338 this.jsValue = jsValue;
339 this.jsType = jsType;