Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToByte-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 = 'JavaObjectToByte-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 boolean";
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
52 a[i++] = new TestObject (
53 "dt.PUB_DOUBLE_REPRESENTATION = 0.5 ;"+
54 "dt.setByte( dt )",
55 "dt.PUB_BYTE",
56 "dt.getByte()",
57 "typeof dt.getByte()",
58 0,
59 "number" );
60
61 a[i++] = new TestObject (
62 "dt.PUB_DOUBLE_REPRESENTATION = -0.5;"+
63 "dt.setByte( dt )",
64 "dt.PUB_BYTE",
65 "dt.getByte()",
66 "typeof dt.getByte()",
67 0,
68 "number" );
69
70 a[i++] = new TestObject (
71 "dt.PUB_DOUBLE_REPRESENTATION = 0.5;"+
72 "dt.setByte( dt )",
73 "dt.PUB_BYTE",
74 "dt.getByte()",
75 "typeof dt.getByte()",
76 0,
77 "number" );
78
79 a[i++] = new TestObject (
80 "dt.PUB_DOUBLE_REPRESENTATION = -0.4;"+
81 "dt.setByte( dt )",
82 "dt.PUB_BYTE",
83 "dt.getByte()",
84 "typeof dt.getByte()",
85 0,
86 "number" );
87
88 a[i++] = new TestObject (
89 "dt.PUB_DOUBLE_REPRESENTATION = 0.6;"+
90 "dt.setByte( dt )",
91 "dt.PUB_BYTE",
92 "dt.getByte()",
93 "typeof dt.getByte()",
94 0,
95 "number" );
96
97 a[i++] = new TestObject (
98 "dt.PUB_DOUBLE_REPRESENTATION = -0.6;"+
99 "dt.setByte( dt )",
100 "dt.PUB_BYTE",
101 "dt.getByte()",
102 "typeof dt.getByte()",
103 0,
104 "number" );
105
106 a[i++] = new TestObject (
107 "dt.PUB_DOUBLE_REPRESENTATION = "+Math.PI+";"+
108 "dt.setByte( dt )",
109 "dt.PUB_BYTE",
110 "dt.getByte()",
111 "typeof dt.getByte()",
112 3,
113 "number" );
114
115 a[i++] = new TestObject (
116 "dt.PUB_DOUBLE_REPRESENTATION = -" +Math.PI+";"+
117 "dt.setByte( dt )",
118 "dt.PUB_BYTE",
119 "dt.getByte()",
120 "typeof dt.getByte()",
121 -3,
122 "number" );
123
124 a[i++] = new TestObject (
125 "dt.PUB_DOUBLE_REPRESENTATION = 127;"+
126 "dt.setByte( dt )",
127 "dt.PUB_BYTE",
128 "dt.getByte()",
129 "typeof dt.getByte()",
130 127,
131 "number" );
132
133 a[i++] = new TestObject (
134 "dt.PUB_DOUBLE_REPRESENTATION = -128;"+
135 "dt.setByte( dt )",
136 "dt.PUB_BYTE",
137 "dt.getByte()",
138 "typeof dt.getByte()",
139 -128,
140 "number" );
141
142 a[i++] = new TestObject (
143 "dt.PUB_DOUBLE_REPRESENTATION = -128.5;"+
144 "dt.setByte( dt )",
145 "dt.PUB_BYTE",
146 "dt.getByte()",
147 "typeof dt.getByte()",
148 -128,
149 "number" );
150
151 a[i++] = new TestObject (
152 "dt.PUB_DOUBLE_REPRESENTATION = 127.5;"+
153 "dt.setByte( dt )",
154 "dt.PUB_BYTE",
155 "dt.getByte()",
156 "typeof dt.getByte()",
157 127,
158 "number" );
159
160 for ( i = 0; i < a.length; i++ ) {
161 new TestCase(
162 a[i].description +"; "+ a[i].javaFieldName,
163 a[i].jsValue,
164 a[i].javaFieldValue );
165
166 new TestCase(
167 a[i].description +"; " + a[i].javaMethodName,
168 a[i].jsValue,
169 a[i].javaMethodValue );
170
171 new TestCase(
172 a[i].javaTypeName,
173 a[i].jsType,
174 a[i].javaTypeValue );
175
176 }
177
178 test();
179
180 function TestObject( description, javaField, javaMethod, javaType,
181 jsValue, jsType )
182 {
183 eval (description );
184
185 this.description = description;
186 this.javaFieldName = javaField;
187 this.javaFieldValue = eval( javaField );
188 this.javaMethodName = javaMethod;
189 this.javaMethodValue = eval( javaMethod );
190 this.javaTypeName = javaType,
191 this.javaTypeValue = typeof this.javaFieldValue;
192
193 this.jsValue = jsValue;
194 this.jsType = jsType;
195 }