Debian Codegraph @

rhino/testsrc/tests/lc3/JSBoolean/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 /* -*- 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 boolean 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 = "boolean conversion";
31 var VERSION = "1_4";
32 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
33 SECTION;
34 var BUGNUMBER = "335907";
35
36 startTest();
37
38 var dt = new DT();
39
40 var a = new Array();
41 var i = 0;
42
43 // passing a boolean to a java method that expects a boolean should map
44 // directly to the Java true / false equivalent
45
46 a[i++] = new TestObject(
47 "dt.setBoolean( true )",
48 "dt.PUB_BOOLEAN",
49 "dt.getBoolean()",
50 "typeof dt.getBoolean()",
51 true,
52 "boolean" );
53
54 a[i++] = new TestObject(
55 "dt.setBoolean( false )",
56 "dt.PUB_BOOLEAN",
57 "dt.getBoolean()",
58 "typeof dt.getBoolean()",
59 false,
60 "boolean" );
61
62 // passing a boolean to a java method that expects a Boolean object
63 // should convert to a new instance of java.lang.Boolean
64
65 a[i++] = new TestObject(
66 "dt.setBooleanObject( true )",
67 "dt.PUB_BOOLEAN_OBJECT +''",
68 "dt.getBooleanObject() +''",
69 "dt.getBooleanObject().getClass()",
70 "true",
71 java.lang.Class.forName( "java.lang.Boolean") );
72
73 a[i++] = new TestObject(
74 "dt.setBooleanObject( false )",
75 "dt.PUB_BOOLEAN_OBJECT +''",
76 "dt.getBooleanObject() +''",
77 "dt.getBooleanObject().getClass()",
78 "false",
79 java.lang.Class.forName( "java.lang.Boolean") );
80
81
82 // passing a boolean to a java method that expects a java.lang.Object
83 // should convert to a new instance of java.lang.Boolean
84
85 a[i++] = new TestObject(
86 "dt.setObject( true )",
87 "dt.PUB_OBJECT +''",
88 "dt.getObject() +''",
89 "dt.getObject().getClass()",
90 "true",
91 java.lang.Class.forName( "java.lang.Boolean") );
92
93 a[i++] = new TestObject(
94 "dt.setObject( false )",
95 "dt.PUB_OBJECT +''",
96 "dt.getObject() +''",
97 "dt.getObject().getClass()",
98 "false",
99 java.lang.Class.forName( "java.lang.Boolean") );
100
101 // passing a boolean to a java method that expects a java.lang.String
102 // should convert true to a java.lang.String whose value is "true" and
103 // false to a java.lang.String whose value is "false"
104
105 a[i++] = new TestObject(
106 "dt.setStringObject( true )",
107 "dt.PUB_STRING +''",
108 "dt.getStringObject() +''",
109 "dt.getStringObject().getClass()",
110 "true",
111 java.lang.Class.forName( "java.lang.String") );
112
113 a[i++] = new TestObject(
114 "dt.setStringObject( false )",
115 "dt.PUB_STRING +''",
116 "dt.getStringObject() +''",
117 "dt.getStringObject().getClass()",
118 "false",
119 java.lang.Class.forName( "java.lang.String") );
120
121 for ( i = 0; i < a.length; i++ ) {
122 new TestCase(
123 a[i].description +"; "+ a[i].javaFieldName,
124 a[i].jsValue,
125 a[i].javaFieldValue );
126
127 new TestCase(
128 a[i].description +"; " + a[i].javaMethodName,
129 a[i].jsValue,
130 a[i].javaMethodValue );
131
132 new TestCase(
133 a[i].javaTypeName,
134 a[i].jsType,
135 a[i].javaTypeValue );
136 }
137
138 test();
139
140 function TestObject( description, javaField, javaMethod, javaType,
141 jsValue, jsType )
142 {
143 eval (description );
144
145 this.description = description;
146 this.javaFieldName = javaField;
147 this.javaFieldValue = eval( javaField );
148 this.javaMethodName = javaMethod;
149 this.javaMethodValue = eval( javaMethod );
150 this.javaTypeName = javaType,
151 this.javaTypeValue = eval( javaType );
152
153 this.jsValue = jsValue;
154 this.jsType = jsType;
155 }