Debian Codegraph @

rhino/testsrc/tests/lc2/JavaToJS/boolean-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 = 'boolean-001.js';
7
8 /**
9 File Name: boolean-001.js
10 Description:
11
12 If a Java method returns a Java boolean primitive, JavaScript should
13 read the value as a JavaScript boolean primitive.
14
15 To test this:
16
17 1. Call a java method that returns a Java boolean primitive.
18 2. Check the type of the returned type, which should be "boolean"
19 3. Check the value of the returned type, which should be true or false.
20
21 It is an error if the returned value is read as a JavaScript Boolean
22 object.
23
24 @author [email protected]
25 @version 1.00
26 */
27 var SECTION = "LiveConnect";
28 var VERSION = "1_3";
29 var TITLE = "Java Boolean Primitive to JavaScript Object";
30
31 startTest();
32 writeHeaderToLog( SECTION + " "+ TITLE);
33
34 // In all test cases, the expected type is "boolean"
35
36 var E_TYPE = "boolean";
37
38 // Create arrays of actual results (java_array) and expected results
39 // (test_array).
40
41 var java_array = new Array();
42 var test_array = new Array();
43
44 var i = 0;
45
46 // Call a java method that returns true
47 java_array[i] = new JavaValue( (new java.lang.Boolean(true)).booleanValue() );
48 test_array[i] = new TestValue( "(new java.lang.Boolean(true)).booleanValue()",
49 true )
50 i++;
51
52 // Call a java method that returns false
53 java_array[i] = new JavaValue( (new java.lang.Boolean(false)).booleanValue() );
54 test_array[i] = new TestValue( "(new java.lang.Boolean(false)).booleanValue()",
55 false )
56 i++;
57
58 for ( i = 0; i < java_array.length; i++ ) {
59 CompareValues( java_array[i], test_array[i] );
60
61 }
62
63 test();
64
65 function CompareValues( javaval, testval ) {
66 // Check value
67 new TestCase( SECTION,
68 testval.description,
69 testval.value,
70 javaval.value );
71 // Check type.
72
73 new TestCase( SECTION,
74 "typeof (" + testval.description +")",
75 testval.type,
76 javaval.type );
77 }
78 function JavaValue( value ) {
79 this.value = value;
80 this.type = typeof value;
81 return this;
82 }
83 function TestValue( description, value ) {
84 this.description = description;
85 this.value = value;
86 this.type = E_TYPE;
87 return this;
88 }