1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
5 /* ***** BEGIN LICENSE BLOCK *****
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the
18 * The Original Code is Mozilla Communicator client code, released
21 * The Initial Developer of the Original Code is
22 * Netscape Communications Corporation.
23 * Portions created by the Initial Developer are Copyright (C) 1998
24 * the Initial Developer. All Rights Reserved.
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 gTestfile = 'ToObject-001.js';
45 * JavaScript to Java type conversion.
47 * This test passes JavaScript number values to several Java methods
48 * that expect arguments of various types, and verifies that the value is
49 * converted to the correct value and type.
51 * This tests instance methods, and not static methods.
53 * Running these tests successfully requires you to have
54 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
56 * Specification: Method Overloading Proposal for Liveconnect 3.0
58 * @author: christine@netscape.com
61 var SECTION = "JavaScript Object to java.lang.String";
63 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
65 var BUGNUMBER="335882";
74 // 3.3.6.4 Other JavaScript Objects
75 // Passing a JavaScript object to a java method that that expects a JSObject
76 // should wrap the JS object in a new instance of netscape.javascript.JSObject.
77 // HOwever, since we are running the test from JavaScript, getting the value
78 // back should return the unwrapped object.
80 var string = new String("JavaScript String Value");
82 a[i++] = new TestObject(
83 "dt.setObject(string)",
86 "dt.getObject().constructor",
90 var myobject = new MyObject( string );
92 a[i++] = new TestObject(
93 "dt.setObject( myobject )",
96 "dt.getObject().constructor",
100 var bool = new Boolean(true);
102 a[i++] = new TestObject(
103 "dt.setObject( bool )",
106 "dt.getObject().constructor",
110 bool = new Boolean(false);
112 a[i++] = new TestObject(
113 "dt.setObject( bool )",
116 "dt.getObject().constructor",
120 var object = new Object();
122 a[i++] = new TestObject(
123 "dt.setObject( object)",
126 "dt.getObject().constructor",
130 var number = new Number(0);
132 a[i++] = new TestObject(
133 "dt.setObject( number )",
136 "dt.getObject().constructor",
140 nan = new Number(NaN);
142 a[i++] = new TestObject(
143 "dt.setObject( nan )",
146 "dt.getObject().constructor",
150 infinity = new Number(Infinity);
152 a[i++] = new TestObject(
153 "dt.setObject( infinity )",
156 "dt.getObject().constructor",
160 var neg_infinity = new Number(-Infinity);
162 a[i++] = new TestObject(
163 "dt.setObject( neg_infinity )",
166 "dt.getObject().constructor",
170 var array = new Array(1,2,3)
172 a[i++] = new TestObject(
173 "dt.setObject(array)",
176 "dt.getObject().constructor",
181 a[i++] = new TestObject(
182 "dt.setObject( MyObject )",
185 "dt.getObject().constructor",
191 a[i++] = new TestObject(
192 "dt.setObject( THIS )",
195 "dt.getObject().constructor",
199 a[i++] = new TestObject(
200 "dt.setObject( Math )",
203 "dt.getObject().constructor",
207 a[i++] = new TestObject(
208 "dt.setObject( Function )",
211 "dt.getObject().constructor",
215 for ( i = 0; i < a.length; i++ ) {
217 a[i].description +"; "+ a[i].javaFieldName,
219 a[i].javaFieldValue );
222 a[i].description +"; " + a[i].javaMethodName,
224 a[i].javaMethodValue );
229 a[i].javaTypeValue );
234 function MyObject( stringValue ) {
235 this.stringValue = String(stringValue);
236 this.toString = new Function( "return this.stringValue" );
240 function TestObject( description, javaField, javaMethod, javaType,
245 this.description = description;
246 this.javaFieldName = javaField;
247 this.javaFieldValue = eval( javaField );
248 this.javaMethodName = javaMethod;
249 this.javaMethodValue = eval( javaMethod );
250 this.javaTypeName = javaType,
251 this.javaTypeValue = eval( javaType );
253 this.jsValue = jsValue;
254 this.jsType = jsType;