Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToLong-001.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 = 'ToLong-001.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 long";
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 JS number to a method that expects a long:
40 // round JS number to integral value using round-to-negative-infinity mode
41 // numbers with a magnitude too large to be represented in the target integral
42 // type result in a runtime error.
43 // Nan converts to 0.
44
45 // Special cases: 0, -0, Infinity, -Infinity, and NaN
46
47 a[i++] = new TestObject(
48 "dt.setLong( 0 )",
49 "dt.PUB_LONG",
50 "dt.getLong()",
51 "typeof dt.getLong()",
52 0,
53 "number" );
54
55 a[i++] = new TestObject(
56 "dt.setLong( -0 )",
57 "Infinity / dt.PUB_LONG",
58 "Infinity / dt.getLong()",
59 "typeof dt.getLong()",
60 Infinity,
61 "number" );
62
63 a[i++] = new TestObject(
64 "dt.setLong(1234567890123)",
65 "dt.PUB_LONG",
66 "dt.getLong()",
67 "typeof dt.getLong()",
68 1234567890123,
69 "number" );
70
71 a[i++] = new TestObject(
72 "dt.setLong(-1234567890123)",
73 "dt.PUB_LONG",
74 "dt.getLong()",
75 "typeof dt.getLong()",
76 -1234567890123,
77 "number" );
78
79 a[i++] = new TestObject(
80 "dt.setLong(0x7ffffffffffffff)",
81 "dt.PUB_LONG",
82 "dt.getLong()",
83 "typeof dt.getLong()",
84 0x7ffffffffffffff,
85 "number" );
86
87 a[i++] = new TestObject(
88 "dt.setLong(0x7ffffffffffffff)",
89 "dt.PUB_LONG",
90 "dt.getLong()",
91 "typeof dt.getLong()",
92 0x7ffffffffffffff,
93 "number" );
94
95 a[i++] = new TestObject(
96 "dt.setLong(0xfffffffffffffff)",
97 "dt.PUB_LONG",
98 "dt.getLong()",
99 "typeof dt.getLong()",
100 0xfffffffffffffff,
101 "number" );
102
103 a[i++] = new TestObject(
104 "dt.setLong(0x6fffffffffffffff)",
105 "dt.PUB_LONG",
106 "dt.getLong()",
107 "typeof dt.getLong()",
108 0x6fffffffffffffff,
109 "number" );
110
111 a[i++] = new TestObject(
112 "dt.setLong(-0x6fffffffffffffff)",
113 "dt.PUB_LONG",
114 "dt.getLong()",
115 "typeof dt.getLong()",
116 -0x6fffffffffffffff,
117 "number" );
118
119 /*
120 a[i++] = new TestObject(
121 "dt.setLong( java.lang.Long.MAX_VALUE )",
122 "dt.PUB_LONG",
123 "dt.getLong()",
124 "typeof dt.getLong()",
125 java.lang.Long.MAX_VALUE,
126 "number" );
127
128 a[i++] = new TestObject(
129 "dt.setLong( java.lang.Long.MIN_VALUE )",
130 "dt.PUB_LONG",
131 "dt.getLong()",
132 "typeof dt.getLong()",
133 java.lang.Long.MIN_VALUE,
134 "number" );
135
136 a[i++] = new TestObject(
137 "dt.setLong( -java.lang.Long.MAX_VALUE )",
138 "dt.PUB_LONG",
139 "dt.getLong()",
140 "typeof dt.getLong()",
141 -java.lang.Long.MAX_VALUE,
142 "number" );
143
144 a[i++] = new TestObject(
145 "dt.setLong( -java.lang.Long.MIN_VALUE )",
146 "dt.PUB_LONG",
147 "dt.getLong()",
148 "typeof dt.getLong()",
149 -java.lang.Long.MIN_VALUE,
150 "number" );
151 */
152 for ( i = 0; i < a.length; i++ ) {
153 new TestCase(
154 a[i].description +"; "+ a[i].javaFieldName,
155 a[i].jsValue,
156 a[i].javaFieldValue );
157
158 new TestCase(
159 a[i].description +"; " + a[i].javaMethodName,
160 a[i].jsValue,
161 a[i].javaMethodValue );
162
163 new TestCase(
164 a[i].javaTypeName,
165 a[i].jsType,
166 a[i].javaTypeValue );
167 }
168
169 test();
170
171 function TestObject( description, javaField, javaMethod, javaType,
172 jsValue, jsType )
173 {
174 eval (description );
175
176 this.description = description;
177 this.javaFieldName = javaField;
178 this.javaFieldValue = eval( javaField );
179 this.javaMethodName = javaMethod;
180 this.javaMethodValue = eval( javaMethod );
181 this.javaTypeName = javaType,
182 this.javaTypeValue = eval( javaType );
183
184 this.jsValue = jsValue;
185 this.jsType = jsType;
186 }