Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToDouble-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 = 'JavaObjectToDouble-001.js';
7
8 /* -*- Mode: java; tab-width: 8 -*-
9 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
10 * All Rights Reserved.
11 */
12 /**
13 * JavaScript to Java type conversion.
14 *
15 * This test passes JavaScript number values to several Java methods
16 * that expect arguments of various types, and verifies that the value is
17 * converted to the correct value and type.
18 *
19 * This tests instance methods, and not static methods.
20 *
21 * Running these tests successfully requires you to have
22 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
23 *
24 * Specification: Method Overloading Proposal for Liveconnect 3.0
25 *
26 * @author: [email protected]
27 *
28 */
29 var SECTION = "JavaObject to double";
30 var VERSION = "1_4";
31 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
32 SECTION;
33 startTest();
34
35 var dt = new DT();
36
37 var a = new Array();
38 var i = 0;
39
40 // 1. If the object does not have a doubleValue() method, a runtime error
41 // occurs.
42 // 2. Call the object's doubleValue() method
43 // 3. Convert Result(2) to Java numeric type. with no loss of magnitude or
44 // sign.
45
46 var newValue = Math.random();
47
48 a[i++] = new TestObject(
49 "dt.setDouble( " +newValue +" )",
50 "dt.PUB_DOUBLE",
51 "dt.getDouble()",
52 "typeof dt.getDouble()",
53 newValue,
54 "number" );
55
56 a[i++] = new TestObject(
57 "dt.setDouble( dt )",
58 "dt.PUB_DOUBLE",
59 "dt.getDouble()",
60 "typeof dt.getDouble()",
61 dt.PUB_DOUBLE_REPRESENTATION,
62 "number" );
63
64 a[i++] = new TestObject(
65 "dt.doubleValue()",
66 "dt.PUB_DOUBLE",
67 "dt.getDouble()",
68 "typeof dt.getDouble()",
69 dt.PUB_DOUBLE_REPRESENTATION,
70 "number" );
71
72 for ( i = 0; i < a.length; i++ ) {
73 new TestCase(
74 a[i].description +"; "+ a[i].javaFieldName,
75 a[i].jsValue,
76 a[i].javaFieldValue );
77
78 new TestCase(
79 a[i].description +"; " + a[i].javaMethodName,
80 a[i].jsValue,
81 a[i].javaMethodValue );
82
83 new TestCase(
84 a[i].javaTypeName,
85 a[i].jsType,
86 a[i].javaTypeValue );
87
88 }
89
90 test();
91
92 function TestObject( description, javaField, javaMethod, javaType,
93 jsValue, jsType )
94 {
95 eval (description );
96
97 this.description = description;
98 this.javaFieldName = javaField;
99 this.javaFieldValue = eval( javaField );
100 this.javaMethodName = javaMethod;
101 this.javaMethodValue = eval( javaMethod );
102 this.javaTypeName = javaType,
103 this.javaTypeValue = typeof this.javaFieldValue;
104
105 this.jsValue = jsValue;
106 this.jsType = jsType;
107 }