Debian Codegraph @

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