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
= 'ToInt-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
= "number conversion to int";
63 var TITLE
= "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
65 var BUGNUMBER
="335589";
74 // passing a JS number to a method that expects a int:
75 // round JS number to integral value using round-to-negative-infinity mode
76 // numbers with a magnitude too large to be represented in the target integral
77 // type result in a runtime error.
80 // Special cases: 0, -0, Infinity, -Infinity, and NaN
82 a
[i
++] = new TestObject(
86 "typeof dt.getInteger()",
90 // only doubles and floats know about -0
92 a
[i
++] = new TestObject(
93 "dt.setInteger( -0 )",
94 "Infinity / dt.PUB_INT",
95 "Infinity / dt.getInteger()",
96 "typeof dt.getInteger()",
100 a
[i
++] = new TestObject(
101 "dt.setInteger( java.lang.Integer.MAX_VALUE )",
104 "typeof dt.getInteger()",
105 java
.lang
.Integer
.MAX_VALUE
,
108 a
[i
++] = new TestObject(
109 "dt.setInteger( java.lang.Integer.MIN_VALUE )",
112 "typeof dt.getInteger()",
113 java
.lang
.Integer
.MIN_VALUE
,
116 a
[i
++] = new TestObject(
117 "dt.setInteger( -java.lang.Integer.MAX_VALUE )",
120 "typeof dt.getInteger()",
121 -java
.lang
.Integer
.MAX_VALUE
,
124 a
[i
++] = new TestObject(
125 "dt.setInteger(1e-2000)",
128 "typeof dt.getInteger()",
132 a
[i
++] = new TestObject(
133 "dt.setInteger(-1e-2000)",
136 "typeof dt.getInteger()",
140 for ( i
= 0; i
< a
.length
; i
++ ) {
142 a
[i
].description
+"; "+ a
[i
].javaFieldName
,
144 a
[i
].javaFieldValue
);
147 a
[i
].description
+"; " + a
[i
].javaMethodName
,
149 a
[i
].javaMethodValue
);
154 a
[i
].javaTypeValue
);
159 function TestObject( description
, javaField
, javaMethod
, javaType
,
164 this.description
= description
;
165 this.javaFieldName
= javaField
;
166 this.javaFieldValue
= eval( javaField
);
167 this.javaMethodName
= javaMethod
;
168 this.javaMethodValue
= eval( javaMethod
);
169 this.javaTypeName
= javaType
,
170 this.javaTypeValue
= eval( javaType
);
172 this.jsValue
= jsValue
;
173 this.jsType
= jsType
;