Debian Codegraph @

rhino/testsrc/tests/lc2/JavaToJS/number-002.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 = 'number-002.js';
7
8 /**
9 File Name: number-001.js
10 Description:
11
12 Accessing a Java field whose value is one of the primitive Java types
13 below, JavaScript should read this as a JavaScript Number object.
14 byte
15 short
16 int
17 long
18 float
19 double
20 char
21
22 To test this:
23 1. Instantiate a new Java object that has a field whose type one of
24 the above primitive Java types, OR get the value of a class's static
25 field.
26 2. Check the value of the returned object
27 3. Check the type of the returned object, which should be "object"
28 4. Check the class of the returned object using Object.prototype.toString,
29 which should return "[object Number]"
30
31 It is an error if the type of the JavaScript variable is "number" or if
32 its class is JavaObject.
33
34 @author [email protected]
35 @version 1.00
36 */
37 var SECTION = "LiveConnect";
38 var VERSION = "1_3";
39 var TITLE = "Java Number Primitive to JavaScript Object";
40
41 startTest();
42 writeHeaderToLog( SECTION + " "+ TITLE);
43
44 // In all test cases, the expected type is "object, and the expected
45 // class is "Number"
46
47 var E_TYPE = "number";
48
49 // Create arrays of actual results (java_array) and expected results
50 // (test_array).
51
52 var java_array = new Array();
53 var test_array = new Array();
54
55 var i = 0;
56
57 // Get a static java field whose type is byte.
58
59 java_array[i] = new JavaValue( java.lang.Byte.MIN_VALUE );
60 test_array[i] = new TestValue( "java.lang.Byte.MIN_VALUE",
61 -128 )
62 i++;
63
64 // Get a static java field whose type is short.
65 java_array[i] = new JavaValue( java.lang.Short.MIN_VALUE );
66 test_array[i] = new TestValue( "java.lang.Short.MIN_VALUE",
67 -32768 )
68 i++;
69
70 // Get a static java field whose type is int.
71
72 java_array[i] = new JavaValue( java.lang.Integer.MIN_VALUE );
73 test_array[i] = new TestValue( "java.lang.Integer.MIN_VALUE",
74 -2147483648 )
75 i++;
76
77
78 // Instantiate a class, and get a field in that class whose type is int.
79
80 var java_rect = new java.awt.Rectangle( 1,2,3,4 );
81
82 java_array[i] = new JavaValue( java_rect.width );
83 test_array[i] = new TestValue( "java_object = new java.awt.Rectangle( 1,2,3,4 ); java_object.width",
84 3 );
85 i++;
86
87 // Get a static java field whose type is long.
88 java_array[i] = new JavaValue( java.lang.Long.MIN_VALUE );
89 test_array[i] = new TestValue( "java.lang.Long.MIN_VALUE",
90 -9223372036854776000 );
91 i++;
92
93 // Get a static java field whose type is float.
94 java_array[i] = new JavaValue( java.lang.Float.MAX_VALUE );
95 test_array[i] = new TestValue( "java.lang.Float.MAX_VALUE",
96 3.4028234663852886e+38 )
97 i++;
98
99 // Get a static java field whose type is double.
100 java_array[i] = new JavaValue( java.lang.Double.MAX_VALUE );
101 test_array[i] = new TestValue( "java.lang.Double.MAX_VALUE",
102 1.7976931348623157e+308 )
103 i++;
104
105 // Get a static java field whose type is char.
106 java_array[i] = new JavaValue( java.lang.Character.MAX_VALUE );
107 test_array[i] = new TestValue( "java.lang.Character.MAX_VALUE",
108 65535 );
109 i++;
110
111 for ( i = 0; i < java_array.length; i++ ) {
112 CompareValues( java_array[i], test_array[i] );
113
114 }
115
116 test();
117 function CompareValues( javaval, testval ) {
118 // Check value
119 new TestCase( SECTION,
120 testval.description,
121 testval.value,
122 javaval.value );
123 // Check type.
124
125 new TestCase( SECTION,
126 "typeof (" + testval.description +")",
127 testval.type,
128 javaval.type );
129 }
130 function JavaValue( value ) {
131 this.value = value.valueOf();
132 this.type = typeof value;
133 return this;
134 }
135 function TestValue( description, value, type ) {
136 this.description = description;
137 this.value = value;
138 this.type = E_TYPE;
139 // this.classname = classname;
140 return this;
141 }