Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToDouble-003.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
3 * All Rights Reserved.
4 */
5 /* This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
9 gTestfile = 'ToDouble-003.js';
10
11 /**
12 * JavaScript to Java type conversion.
13 *
14 * This test passes JavaScript number values to several Java methods
15 * that expect arguments of various types, and verifies that the value is
16 * converted to the correct value and type.
17 *
18 * This tests instance methods, and not static methods.
19 *
20 * Running these tests successfully requires you to have
21 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
22 *
23 * Specification: Method Overloading Proposal for Liveconnect 3.0
24 *
25 * @author: [email protected]
26 *
27 */
28 var SECTION = "number conversion to float";
29 var VERSION = "1_4";
30 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
31 SECTION;
32 startTest();
33
34 var dt = new DT();
35
36 var a = new Array();
37 var i = 0;
38
39 // passing a number value to a method that expects a float should round JS
40 // number to float precision. unrepresentably large values are converted
41 // to +/- Infinity.
42
43 // Special cases: 0, -0, Infinity, -Infinity, and NaN
44
45 a[i++] = new TestObject(
46 "dt.setFloat( 0 )",
47 "dt.PUB_FLOAT",
48 "dt.getFloat()",
49 "typeof dt.getFloat()",
50 0,
51 "number" );
52
53 a[i++] = new TestObject(
54 "dt.setFloat( -0 )",
55 "Infinity / dt.PUB_FLOAT",
56 "Infinity / dt.getFloat()",
57 "typeof dt.getFloat()",
58 -Infinity,
59 "number" );
60
61 a[i++] = new TestObject(
62 "dt.setFloat( Infinity )",
63 "dt.PUB_FLOAT ",
64 "dt.getFloat() ",
65 "typeof dt.getFloat()",
66 Infinity,
67 "number" );
68
69 a[i++] = new TestObject(
70 "dt.setFloat( -Infinity )",
71 "dt.PUB_FLOAT",
72 "dt.getFloat() ",
73 "typeof dt.getFloat()",
74 -Infinity,
75 "number" );
76
77 a[i++] = new TestObject(
78 "dt.setFloat( NaN )",
79 "dt.PUB_FLOAT",
80 "dt.getFloat()",
81 "typeof dt.getFloat()",
82 NaN,
83 "number" );
84
85 a[i++] = new TestObject(
86 "dt.setFloat( java.lang.Float.MAX_VALUE )",
87 "dt.PUB_FLOAT",
88 "dt.getFloat()",
89 "typeof dt.getFloat()",
90 java.lang.Float.MAX_VALUE,
91 "number" );
92
93 a[i++] = new TestObject(
94 "dt.setFloat( java.lang.Float.MIN_VALUE )",
95 "dt.PUB_FLOAT",
96 "dt.getFloat()",
97 "typeof dt.getFloat()",
98 java.lang.Float.MIN_VALUE,
99 "number" );
100
101 a[i++] = new TestObject(
102 "dt.setFloat( -java.lang.Float.MAX_VALUE )",
103 "dt.PUB_FLOAT",
104 "dt.getFloat()",
105 "typeof dt.getFloat()",
106 -java.lang.Float.MAX_VALUE,
107 "number" );
108
109 a[i++] = new TestObject(
110 "dt.setFloat( -java.lang.Float.MIN_VALUE )",
111 "dt.PUB_FLOAT",
112 "dt.getFloat()",
113 "typeof dt.getFloat()",
114 -java.lang.Float.MIN_VALUE,
115 "number" );
116
117 a[i++] = new TestObject(
118 "dt.setFloat(1.7976931348623157E+308)",
119 "dt.PUB_FLOAT",
120 "dt.getFloat()",
121 "typeof dt.getFloat()",
122 Infinity,
123 "number" );
124
125 a[i++] = new TestObject(
126 "dt.setFloat(1.7976931348623158e+308)",
127 "dt.PUB_FLOAT",
128 "dt.getFloat()",
129 "typeof dt.getFloat()",
130 Infinity,
131 "number" );
132
133 a[i++] = new TestObject(
134 "dt.setFloat(1.7976931348623159e+308)",
135 "dt.PUB_FLOAT",
136 "dt.getFloat()",
137 "typeof dt.getFloat()",
138 Infinity,
139 "number" );
140
141 a[i++] = new TestObject(
142 "dt.setFloat(-1.7976931348623157E+308)",
143 "dt.PUB_FLOAT",
144 "dt.getFloat()",
145 "typeof dt.getFloat()",
146 -Infinity,
147 "number" );
148
149 a[i++] = new TestObject(
150 "dt.setFloat(-1.7976931348623158e+308)",
151 "dt.PUB_FLOAT",
152 "dt.getFloat()",
153 "typeof dt.getFloat()",
154 -Infinity,
155 "number" );
156
157 a[i++] = new TestObject(
158 "dt.setFloat(-1.7976931348623159e+308)",
159 "dt.PUB_FLOAT",
160 "dt.getFloat()",
161 "typeof dt.getFloat()",
162 -Infinity,
163 "number" );
164
165 a[i++] = new TestObject(
166 "dt.setFloat(1e-2000)",
167 "dt.PUB_FLOAT",
168 "dt.getFloat()",
169 "typeof dt.getFloat()",
170 0,
171 "number" );
172
173 a[i++] = new TestObject(
174 "dt.setFloat(1e2000)",
175 "dt.PUB_FLOAT",
176 "dt.getFloat()",
177 "typeof dt.getFloat()",
178 Infinity,
179 "number" );
180
181 a[i++] = new TestObject(
182 "dt.setFloat(-1e2000)",
183 "dt.PUB_FLOAT",
184 "dt.getFloat()",
185 "typeof dt.getFloat()",
186 -Infinity,
187 "number" );
188
189
190 for ( i = 0; i < a.length; i++ ) {
191 new TestCase(
192 a[i].description +"; "+ a[i].javaFieldName,
193 a[i].jsValue,
194 a[i].javaFieldValue );
195
196 new TestCase(
197 a[i].description +"; " + a[i].javaMethodName,
198 a[i].jsValue,
199 a[i].javaMethodValue );
200
201 new TestCase(
202 a[i].javaTypeName,
203 a[i].jsType,
204 a[i].javaTypeValue );
205 }
206
207 test();
208
209 function TestObject( description, javaField, javaMethod, javaType,
210 jsValue, jsType )
211 {
212 eval (description );
213
214 this.description = description;
215 this.javaFieldName = javaField;
216 this.javaFieldValue = eval( javaField );
217 this.javaMethodName = javaMethod;
218 this.javaMethodValue = eval( javaMethod );
219 this.javaTypeName = javaType,
220 this.javaTypeValue = eval( javaType );
221
222 this.jsValue = jsValue;
223 this.jsType = jsType;
224 }