Debian Codegraph @

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