Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToShort-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 = 'ToShort-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 startTest();
33
34 var dt = new DT();
35
36 var a = new Array();
37 var i = 0;
38
39 // passing a JS number to a method that expects a int:
40 // round JS number to integral value using round-to-negative-infinity mode
41 // numbers with a magnitude too large to be represented in the target integral
42 // type result in a runtime error.
43 // Nan converts to 0.
44
45 // Special cases: 0, -0, Infinity, -Infinity, and NaN
46
47 a[i++] = new TestObject(
48 "dt.setShort(java.lang.Short.MIN_VALUE - 0.5)",
49 "dt.PUB_SHORT",
50 "dt.getShort()",
51 "typeof dt.getShort()",
52 java.lang.Short.MIN_VALUE,
53 "number" );
54
55 a[i++] = new TestObject(
56 "dt.setShort(java.lang.Short.MIN_VALUE - 0.4)",
57 "dt.PUB_SHORT",
58 "dt.getShort()",
59 "typeof dt.getShort()",
60 java.lang.Short.MIN_VALUE,
61 "number" );
62
63 a[i++] = new TestObject(
64 "dt.setShort(java.lang.Short.MIN_VALUE + 0.6)",
65 "dt.PUB_SHORT",
66 "dt.getShort()",
67 "typeof dt.getShort()",
68 java.lang.Short.MIN_VALUE + 1,
69 "number" );
70
71 for ( i = 0; i < a.length; i++ ) {
72 new TestCase(
73 a[i].description +"; "+ a[i].javaFieldName,
74 a[i].jsValue,
75 a[i].javaFieldValue );
76
77 new TestCase(
78 a[i].description +"; " + a[i].javaMethodName,
79 a[i].jsValue,
80 a[i].javaMethodValue );
81
82 new TestCase(
83 a[i].javaTypeName,
84 a[i].jsType,
85 a[i].javaTypeValue );
86 }
87
88 test();
89
90 function TestObject( description, javaField, javaMethod, javaType,
91 jsValue, jsType )
92 {
93 eval (description );
94
95 this.description = description;
96 this.javaFieldName = javaField;
97 this.javaFieldValue = eval( javaField );
98 this.javaMethodName = javaMethod;
99 this.javaMethodValue = eval( javaMethod );
100 this.javaTypeName = javaType,
101 this.javaTypeValue = eval( javaType );
102
103 this.jsValue = jsValue;
104 this.jsType = jsType;
105 }