Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToInt-004.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 = 'ToInt-004.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 int";
29 var VERSION = "1_4";
30 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
31 SECTION;
32 var BUGNUMBER="335589";
33
34 startTest();
35
36 var dt = new DT();
37
38 var a = new Array();
39 var i = 0;
40
41 // passing a JS number to a method that expects a int:
42 // round JS number to integral value using round-to-negative-infinity mode
43 // numbers with a magnitude too large to be represented in the target integral
44 // type result in a runtime error.
45 // Nan converts to 0.
46
47 // Special cases: 0, -0, Infinity, -Infinity, and NaN
48
49 a[i++] = new TestObject(
50 "dt.setInteger(java.lang.Integer.MIN_VALUE - 0.5)",
51 "dt.PUB_INT",
52 "dt.getInteger()",
53 "typeof dt.getInteger()",
54 java.lang.Integer.MIN_VALUE,
55 "number" );
56
57 a[i++] = new TestObject(
58 "dt.setInteger(java.lang.Integer.MIN_VALUE - 0.4)",
59 "dt.PUB_INT",
60 "dt.getInteger()",
61 "typeof dt.getInteger()",
62 java.lang.Integer.MIN_VALUE,
63 "number" );
64
65 a[i++] = new TestObject(
66 "dt.setInteger(java.lang.Integer.MIN_VALUE + 0.6)",
67 "dt.PUB_INT",
68 "dt.getInteger()",
69 "typeof dt.getInteger()",
70 java.lang.Integer.MIN_VALUE+1,
71 "number" );
72
73 a[i++] = new TestObject(
74 "dt.setInteger(java.lang.Integer.MIN_VALUE + 0.5)",
75 "dt.PUB_INT",
76 "dt.getInteger()",
77 "typeof dt.getInteger()",
78 java.lang.Integer.MIN_VALUE +1,
79 "number" );
80
81 a[i++] = new TestObject(
82 "dt.setInteger(java.lang.Integer.MIN_VALUE + 0.4)",
83 "dt.PUB_INT",
84 "dt.getInteger()",
85 "typeof dt.getInteger()",
86 java.lang.Integer.MIN_VALUE +1,
87 "number" );
88
89 a[i++] = new TestObject(
90 "dt.setInteger(java.lang.Integer.MIN_VALUE - 0.999)",
91 "dt.PUB_INT",
92 "dt.getInteger()",
93 "typeof dt.getInteger()",
94 java.lang.Integer.MIN_VALUE,
95 "number" );
96
97 for ( i = 0; i < a.length; i++ ) {
98 new TestCase(
99 a[i].description +"; "+ a[i].javaFieldName,
100 a[i].jsValue,
101 a[i].javaFieldValue );
102
103 new TestCase(
104 a[i].description +"; " + a[i].javaMethodName,
105 a[i].jsValue,
106 a[i].javaMethodValue );
107
108 new TestCase(
109 a[i].javaTypeName,
110 a[i].jsType,
111 a[i].javaTypeValue );
112 }
113
114 test();
115
116 function TestObject( description, javaField, javaMethod, javaType,
117 jsValue, jsType )
118 {
119 eval (description );
120
121 this.description = description;
122 this.javaFieldName = javaField;
123 this.javaFieldValue = eval( javaField );
124 this.javaMethodName = javaMethod;
125 this.javaMethodValue = eval( javaMethod );
126 this.javaTypeName = javaType,
127 this.javaTypeValue = eval( javaType );
128
129 this.jsValue = jsValue;
130 this.jsType = jsType;
131 }