1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile
= 'double-002.js';
42 Template for LiveConnect Tests
44 File Name: number-001.js
47 When setting the value of a Java field with a JavaScript number or
48 when passing a JavaScript number to a Java method as an argument,
49 LiveConnect should be able to convert the number to any one of the
61 Note that the value of the Java field may not be as precise as the
62 JavaScript value's number, if for example, you pass a large number to
63 a short or byte, or a float to integer.
65 JavaScript numbers cannot be converted to instances of java.lang.Float
68 This test does not cover the cases in which a Java method returns one
69 of the above primitive Java types.
71 Currently split up into numerous tests, since rhino live connect fails
72 to translate numbers into the correct types.
74 Test for passing JavasScript numbers to static java.lang.Integer methods.
77 @author christine@netscape.com
80 var SECTION
= "double-001";
82 var TITLE
= "LiveConnect JavaScript to Java Data Type Conversion";
85 writeHeaderToLog( SECTION
+ " "+ TITLE
);
87 // typeof all resulting objects is "object";
88 var E_TYPE
= "object";
90 // JS class of all resulting objects is "JavaObject";
91 var E_JSCLASS
= "[object JavaObject]";
96 a
[i
++] = new TestObject( "java.lang.Double.toString(0)",
97 java
.lang
.Double
.toString(0), "0.0" );
99 a
[i
++] = new TestObject( "java.lang.Double.toString(NaN)",
100 java
.lang
.Double
.toString(NaN
), "NaN" );
102 a
[i
++] = new TestObject( "java.lang.Double.toString(5)",
103 java
.lang
.Double
.toString(5), "5.0" );
105 a
[i
++] = new TestObject( "java.lang.Double.toString(9.9)",
106 java
.lang
.Double
.toString(9.9), "9.9" );
108 a
[i
++] = new TestObject( "java.lang.Double.toString(-9.9)",
109 java
.lang
.Double
.toString(-9.9), "-9.9" );
111 for ( var i
= 0; i
< a
.length
; i
++ ) {
116 "typeof (" + a
[i
].description
+")",
118 typeof a
[i
].javavalue
);
120 // check the js class
123 "("+ a[i].description +").getJSClass()",
127 // check the number value of the object
130 "String(" + a
[i
].description
+")",
132 String( a
[i
].javavalue
) );
137 function TestObject( description
, javavalue
, jsvalue
) {
138 this.description
= description
;
139 this.javavalue
= javavalue
;
140 this.jsvalue
= jsvalue
;
142 // LC2 does not support the proto property in Java objects
143 // this.javavalue.__proto__.getJSClass = Object.prototype.toString;
144 // this.jsclass = this.javavalue.getJSClass();