Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToByte-004.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 = 'ToByte-004.js';
7
8 /* -*- Mode: java; tab-width: 8 -*-
9 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
10 * All Rights Reserved.
11 */
12
13 /**
14 * JavaScript to Java type conversion.
15 *
16 * This test passes JavaScript number values to several Java methods
17 * that expect arguments of various types, and verifies that the value is
18 * converted to the correct value and type.
19 *
20 * This tests instance methods, and not static methods.
21 *
22 * Running these tests successfully requires you to have
23 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
24 *
25 * Specification: Method Overloading Proposal for Liveconnect 3.0
26 *
27 * @author: [email protected]
28 *
29 */
30 var SECTION = "number conversion to byte";
31 var VERSION = "1_4";
32 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
33 SECTION;
34 var BUGNUMBER="335589";
35
36 startTest();
37
38 var dt = new DT();
39
40 var a = new Array();
41 var i = 0;
42
43 // passing a JS number to a method that expects a byte:
44 // round JS number to integral value using round-to-negative-infinity mode
45 // numbers with a magnitude too large to be represented in the target integral
46 // type result in a runtime error.
47 // Nan converts to 0.
48
49 // Special cases: 0, -0, Infinity, -Infinity, and NaN
50
51 a[i++] = new TestObject(
52 "dt.setByte(java.lang.Byte.MIN_VALUE + 0.6)",
53 "dt.PUB_BYTE",
54 "dt.getByte()",
55 "typeof dt.getByte()",
56 java.lang.Byte.MIN_VALUE +1,
57 "number" );
58
59 a[i++] = new TestObject(
60 "dt.setByte(java.lang.Byte.MIN_VALUE + 0.5)",
61 "dt.PUB_BYTE",
62 "dt.getByte()",
63 "typeof dt.getByte()",
64 java.lang.Byte.MIN_VALUE +1,
65 "number" );
66
67 a[i++] = new TestObject(
68 "dt.setByte(java.lang.Byte.MIN_VALUE + 0.4)",
69 "dt.PUB_BYTE",
70 "dt.getByte()",
71 "typeof dt.getByte()",
72 java.lang.Byte.MIN_VALUE +1,
73 "number" );
74
75 a[i++] = new TestObject(
76 "dt.setByte(java.lang.Byte.MIN_VALUE - 0.5)",
77 "dt.PUB_BYTE",
78 "dt.getByte()",
79 "typeof dt.getByte()",
80 java.lang.Byte.MIN_VALUE,
81 "number" );
82
83 a[i++] = new TestObject(
84 "dt.setByte(java.lang.Byte.MIN_VALUE - 0.4)",
85 "dt.PUB_BYTE",
86 "dt.getByte()",
87 "typeof dt.getByte()",
88 java.lang.Byte.MIN_VALUE,
89 "number" );
90 a[i++] = new TestObject(
91 "dt.setByte(java.lang.Byte.MIN_VALUE - 0.6)",
92 "dt.PUB_BYTE",
93 "dt.getByte()",
94 "typeof dt.getByte()",
95 java.lang.Byte.MIN_VALUE,
96 "number" );
97
98 for ( i = 0; i < a.length; i++ ) {
99 new TestCase(
100 a[i].description +"; "+ a[i].javaFieldName,
101 a[i].jsValue,
102 a[i].javaFieldValue );
103
104 new TestCase(
105 a[i].description +"; " + a[i].javaMethodName,
106 a[i].jsValue,
107 a[i].javaMethodValue );
108
109 new TestCase(
110 a[i].javaTypeName,
111 a[i].jsType,
112 a[i].javaTypeValue );
113 }
114
115 test();
116
117 function TestObject( description, javaField, javaMethod, javaType,
118 jsValue, jsType )
119 {
120 eval (description );
121
122 this.description = description;
123 this.javaFieldName = javaField;
124 this.javaFieldValue = eval( javaField );
125 this.javaMethodName = javaMethod;
126 this.javaMethodValue = eval( javaMethod );
127 this.javaTypeName = javaType,
128 this.javaTypeValue = eval( javaType );
129
130 this.jsValue = jsValue;
131 this.jsType = jsType;
132 }