Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToLong-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 = 'JavaObjectToLong-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 long";
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.setLong( dt )",
54 "dt.PUB_LONG",
55 "dt.getLong()",
56 "typeof dt.getLong()",
57 0,
58 "number" );
59
60 a[i++] = new TestObject (
61 "dt.PUB_DOUBLE_REPRESENTATION = -0.5;"+
62 "dt.setLong( dt )",
63 "dt.PUB_LONG",
64 "dt.getLong()",
65 "typeof dt.getLong()",
66 0,
67 "number" );
68
69 a[i++] = new TestObject (
70 "dt.PUB_DOUBLE_REPRESENTATION = 0.5;"+
71 "dt.setLong( dt )",
72 "dt.PUB_LONG",
73 "dt.getLong()",
74 "typeof dt.getLong()",
75 0,
76 "number" );
77
78 a[i++] = new TestObject (
79 "dt.PUB_DOUBLE_REPRESENTATION = -0.4;"+
80 "dt.setLong( dt )",
81 "dt.PUB_LONG",
82 "dt.getLong()",
83 "typeof dt.getLong()",
84 0,
85 "number" );
86
87 a[i++] = new TestObject (
88 "dt.PUB_DOUBLE_REPRESENTATION = 0.6;"+
89 "dt.setLong( dt )",
90 "dt.PUB_LONG",
91 "dt.getLong()",
92 "typeof dt.getLong()",
93 0,
94 "number" );
95
96 a[i++] = new TestObject (
97 "dt.PUB_DOUBLE_REPRESENTATION = -0.6;"+
98 "dt.setLong( dt )",
99 "dt.PUB_LONG",
100 "dt.getLong()",
101 "typeof dt.getLong()",
102 0,
103 "number" );
104
105 a[i++] = new TestObject (
106 "dt.PUB_DOUBLE_REPRESENTATION = "+Math.PI+";"+
107 "dt.setLong( dt )",
108 "dt.PUB_LONG",
109 "dt.getLong()",
110 "typeof dt.getLong()",
111 3,
112 "number" );
113
114 a[i++] = new TestObject (
115 "dt.PUB_DOUBLE_REPRESENTATION = -" +Math.PI+";"+
116 "dt.setLong( dt )",
117 "dt.PUB_LONG",
118 "dt.getLong()",
119 "typeof dt.getLong()",
120 -3,
121 "number" );
122
123
124 for ( i = 0; i < a.length; i++ ) {
125 new TestCase(
126 a[i].description +"; "+ a[i].javaFieldName,
127 a[i].jsValue,
128 a[i].javaFieldValue );
129
130 new TestCase(
131 a[i].description +"; " + a[i].javaMethodName,
132 a[i].jsValue,
133 a[i].javaMethodValue );
134
135 new TestCase(
136 a[i].javaTypeName,
137 a[i].jsType,
138 a[i].javaTypeValue );
139
140 }
141
142 test();
143
144 function TestObject( description, javaField, javaMethod, javaType,
145 jsValue, jsType )
146 {
147 eval (description );
148
149 this.description = description;
150 this.javaFieldName = javaField;
151 this.javaFieldValue = eval( javaField );
152 this.javaMethodName = javaMethod;
153 this.javaMethodValue = eval( javaMethod );
154 this.javaTypeName = javaType,
155 this.javaTypeValue = typeof this.javaFieldValue;
156
157 this.jsValue = jsValue;
158 this.jsType = jsType;
159 }