Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToLong-002-n.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-002-n.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: Infinity, -Infinity should cause a runtime error
46
47 DESCRIPTION = "dt.setLong( Infinity )";
48 EXPECTED = "error";
49
50 a[i++] = new TestObject(
51 "dt.setLong( Infinity )",
52 "dt.PUB_LONG ",
53 "dt.getLong() ",
54 "typeof dt.getLong()",
55 "error",
56 "number" );
57 /*
58 a[i++] = new TestObject(
59 "dt.setLong( -Infinity )",
60 "dt.PUB_LONG",
61 "dt.getLong() ",
62 "typeof dt.getLong()",
63 -Infinity,
64 "number" );
65
66 a[i++] = new TestObject(
67 "dt.setLong(1.7976931348623157E+308)",
68 "dt.PUB_LONG",
69 "dt.getLong()",
70 "typeof dt.getLong()",
71 Infinity,
72 "number" );
73
74 a[i++] = new TestObject(
75 "dt.setLong(1.7976931348623158e+308)",
76 "dt.PUB_LONG",
77 "dt.getLong()",
78 "typeof dt.getLong()",
79 Infinity,
80 "number" );
81
82 a[i++] = new TestObject(
83 "dt.setLong(1.7976931348623159e+308)",
84 "dt.PUB_LONG",
85 "dt.getLong()",
86 "typeof dt.getLong()",
87 Infinity,
88 "number" );
89
90 a[i++] = new TestObject(
91 "dt.setLong(-1.7976931348623157E+308)",
92 "dt.PUB_LONG",
93 "dt.getLong()",
94 "typeof dt.getLong()",
95 -Infinity,
96 "number" );
97
98 a[i++] = new TestObject(
99 "dt.setLong(-1.7976931348623158e+308)",
100 "dt.PUB_LONG",
101 "dt.getLong()",
102 "typeof dt.getLong()",
103 -Infinity,
104 "number" );
105
106 a[i++] = new TestObject(
107 "dt.setLong(-1.7976931348623159e+308)",
108 "dt.PUB_LONG",
109 "dt.getLong()",
110 "typeof dt.getLong()",
111 -Infinity,
112 "number" );
113
114 a[i++] = new TestObject(
115 "dt.setLong(1e-2000)",
116 "dt.PUB_LONG",
117 "dt.getLong()",
118 "typeof dt.getLong()",
119 0,
120 "number" );
121
122 a[i++] = new TestObject(
123 "dt.setLong(1e2000)",
124 "dt.PUB_LONG",
125 "dt.getLong()",
126 "typeof dt.getLong()",
127 Infinity,
128 "number" );
129
130 a[i++] = new TestObject(
131 "dt.setLong(-1e2000)",
132 "dt.PUB_LONG",
133 "dt.getLong()",
134 "typeof dt.getLong()",
135 -Infinity,
136 "number" );
137 */
138 for ( i = 0; i < a.length; i++ ) {
139 new TestCase(
140 a[i].description +"; "+ a[i].javaFieldName,
141 a[i].jsValue,
142 a[i].javaFieldValue );
143
144 new TestCase(
145 a[i].description +"; " + a[i].javaMethodName,
146 a[i].jsValue,
147 a[i].javaMethodValue );
148
149 new TestCase(
150 a[i].javaTypeName,
151 a[i].jsType,
152 a[i].javaTypeValue );
153 }
154
155 test();
156
157 function TestObject( description, javaField, javaMethod, javaType,
158 jsValue, jsType )
159 {
160 eval (description );
161
162 this.description = description;
163 this.javaFieldName = javaField;
164 this.javaFieldValue = eval( javaField );
165 this.javaMethodName = javaMethod;
166 this.javaMethodValue = eval( javaMethod );
167 this.javaTypeName = javaType,
168 this.javaTypeValue = eval( javaType );
169
170 this.jsValue = jsValue;
171 this.jsType = jsType;
172 }