Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToInt-001.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'JavaObjectToInt-001.js';
7
8 /* -*- Mode: java; tab-width: 8 -*-
9 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
10 * All Rights Reserved.
11 */
12 /**
13 * JavaScript to Java type conversion.
14 *
15 * This test passes JavaScript number values to several Java methods
16 * that expect arguments of various types, and verifies that the value is
17 * converted to the correct value and type.
18 *
19 * This tests instance methods, and not static methods.
20 *
21 * Running these tests successfully requires you to have
22 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
23 *
24 * Specification: Method Overloading Proposal for Liveconnect 3.0
25 *
26 * @author: [email protected]
27 *
28 */
29 var SECTION = "JavaObject to int";
30 var VERSION = "1_4";
31 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
32 SECTION;
33 var BUGNUMBER="335589";
34
35 startTest();
36
37 var dt = new DT();
38
39 var a = new Array();
40 var i = 0;
41
42 // 1. If the object does not have a doubleValue() method, a runtime error
43 // occurs.
44 // 2. Call the object's doubleValue() method
45 // 3. If result(2) is NaN, a runtime error occurs
46 // 3. Convert Result(2) to Java numeric type. Round JS number to integral
47 // value using round-to-negative-infinity mode.
48 // Numbers with a magnitude too large to be represented in the target
49 // integral type should result in a runtime error.
50
51 a[i++] = new TestObject (
52 "dt.PUB_DOUBLE_REPRESENTATION = 0.5 ;"+
53 "dt.setInteger( dt )",
54 "dt.PUB_INT",
55 "dt.getInteger()",
56 "typeof dt.getInteger()",
57 0,
58 "number" );
59
60 a[i++] = new TestObject (
61 "dt.PUB_DOUBLE_REPRESENTATION = -0.5;"+
62 "dt.setInteger( dt )",
63 "dt.PUB_INT",
64 "dt.getInteger()",
65 "typeof dt.getInteger()",
66 0,
67 "number" );
68
69 a[i++] = new TestObject (
70 "dt.PUB_DOUBLE_REPRESENTATION = 0.5;"+
71 "dt.setInteger( dt )",
72 "dt.PUB_INT",
73 "dt.getInteger()",
74 "typeof dt.getInteger()",
75 0,
76 "number" );
77
78 a[i++] = new TestObject (
79 "dt.PUB_DOUBLE_REPRESENTATION = -0.4;"+
80 "dt.setInteger( dt )",
81 "dt.PUB_INT",
82 "dt.getInteger()",
83 "typeof dt.getInteger()",
84 0,
85 "number" );
86
87 a[i++] = new TestObject (
88 "dt.PUB_DOUBLE_REPRESENTATION = 0.6;"+
89 "dt.setInteger( dt )",
90 "dt.PUB_INT",
91 "dt.getInteger()",
92 "typeof dt.getInteger()",
93 0,
94 "number" );
95
96 a[i++] = new TestObject (
97 "dt.PUB_DOUBLE_REPRESENTATION = -0.6;"+
98 "dt.setInteger( dt )",
99 "dt.PUB_INT",
100 "dt.getInteger()",
101 "typeof dt.getInteger()",
102 0,
103 "number" );
104
105 a[i++] = new TestObject (
106 "dt.PUB_DOUBLE_REPRESENTATION = "+Math.PI+";"+
107 "dt.setInteger( dt )",
108 "dt.PUB_INT",
109 "dt.getInteger()",
110 "typeof dt.getInteger()",
111 3,
112 "number" );
113
114 a[i++] = new TestObject (
115 "dt.PUB_DOUBLE_REPRESENTATION = -" +Math.PI+";"+
116 "dt.setInteger( dt )",
117 "dt.PUB_INT",
118 "dt.getInteger()",
119 "typeof dt.getInteger()",
120 -3,
121 "number" );
122
123 a[i++] = new TestObject (
124 "dt.PUB_DOUBLE_REPRESENTATION = 2147483647;"+
125 "dt.setInteger( dt )",
126 "dt.PUB_INT",
127 "dt.getInteger()",
128 "typeof dt.getInteger()",
129 2147483647,
130 "number" );
131
132 a[i++] = new TestObject (
133 "dt.PUB_DOUBLE_REPRESENTATION = -2147483648;"+
134 "dt.setInteger( dt )",
135 "dt.PUB_INT",
136 "dt.getInteger()",
137 "typeof dt.getInteger()",
138 -2147483648,
139 "number" );
140
141 a[i++] = new TestObject (
142 "dt.PUB_DOUBLE_REPRESENTATION = -2147483648.5;"+
143 "dt.setInteger( dt )",
144 "dt.PUB_INT",
145 "dt.getInteger()",
146 "typeof dt.getInteger()",
147 -2147483648,
148 "number" );
149
150 a[i++] = new TestObject (
151 "dt.PUB_DOUBLE_REPRESENTATION = 2147483647.5;"+
152 "dt.setInteger( dt )",
153 "dt.PUB_INT",
154 "dt.getInteger()",
155 "typeof dt.getInteger()",
156 2147483647,
157 "number" );
158
159 for ( i = 0; i < a.length; i++ ) {
160 new TestCase(
161 a[i].description +"; "+ a[i].javaFieldName,
162 a[i].jsValue,
163 a[i].javaFieldValue );
164
165 new TestCase(
166 a[i].description +"; " + a[i].javaMethodName,
167 a[i].jsValue,
168 a[i].javaMethodValue );
169
170 new TestCase(
171 a[i].javaTypeName,
172 a[i].jsType,
173 a[i].javaTypeValue );
174
175 }
176
177 test();
178
179 function TestObject( description, javaField, javaMethod, javaType,
180 jsValue, jsType )
181 {
182 eval (description );
183
184 this.description = description;
185 this.javaFieldName = javaField;
186 this.javaFieldValue = eval( javaField );
187 this.javaMethodName = javaMethod;
188 this.javaMethodValue = eval( javaMethod );
189 this.javaTypeName = javaType,
190 this.javaTypeValue = typeof this.javaFieldValue;
191
192 this.jsValue = jsValue;
193 this.jsType = jsType;
194 }