Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToByte-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 = 'ToByte-001.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 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.setByte( 0 )",
51 "dt.PUB_BYTE",
52 "dt.getByte()",
53 "typeof dt.getByte()",
54 0,
55 "number" );
56
57 // 0 can only have a negative sign for floats and doubles
58
59 a[i++] = new TestObject(
60 "dt.setByte( -0 )",
61 "Infinity / dt.PUB_BYTE",
62 "Infinity / dt.getByte()",
63 "typeof dt.getByte()",
64 Infinity,
65 "number" );
66
67 a[i++] = new TestObject(
68 "dt.setByte( java.lang.Byte.MAX_VALUE )",
69 "dt.PUB_BYTE",
70 "dt.getByte()",
71 "typeof dt.getByte()",
72 java.lang.Byte.MAX_VALUE,
73 "number" );
74
75 a[i++] = new TestObject(
76 "dt.setByte( java.lang.Byte.MIN_VALUE )",
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.MAX_VALUE )",
85 "dt.PUB_BYTE",
86 "dt.getByte()",
87 "typeof dt.getByte()",
88 -java.lang.Byte.MAX_VALUE,
89 "number" );
90
91 a[i++] = new TestObject(
92 "dt.setByte(1e-2000)",
93 "dt.PUB_BYTE",
94 "dt.getByte()",
95 "typeof dt.getByte()",
96 0,
97 "number" );
98
99 a[i++] = new TestObject(
100 "dt.setByte(-1e-2000)",
101 "dt.PUB_BYTE",
102 "dt.getByte()",
103 "typeof dt.getByte()",
104 0,
105 "number" );
106
107 for ( i = 0; i < a.length; i++ ) {
108 new TestCase(
109 a[i].description +"; "+ a[i].javaFieldName,
110 a[i].jsValue,
111 a[i].javaFieldValue );
112
113 new TestCase(
114 a[i].description +"; " + a[i].javaMethodName,
115 a[i].jsValue,
116 a[i].javaMethodValue );
117
118 new TestCase(
119 a[i].javaTypeName,
120 a[i].jsType,
121 a[i].javaTypeValue );
122 }
123
124 test();
125
126 function TestObject( description, javaField, javaMethod, javaType,
127 jsValue, jsType )
128 {
129 eval (description );
130
131 this.description = description;
132 this.javaFieldName = javaField;
133 this.javaFieldValue = eval( javaField );
134 this.javaMethodName = javaMethod;
135 this.javaMethodValue = eval( javaMethod );
136 this.javaTypeName = javaType,
137 this.javaTypeValue = eval( javaType );
138
139 this.jsValue = jsValue;
140 this.jsType = jsType;
141 }