Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToFloat-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 = 'JavaObjectToFloat-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 float";
30 var VERSION = "1_4";
31 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
32 SECTION;
33 var BUGNUMBER = "335899";
34
35 startTest();
36
37 var dt = new DT();
38
39 var a = new Array();
40 var i = 0;
41
42 // 1. If the object does not have a doubleValue() method, a runtime error
43 // occurs.
44 // 2. Call the object's doubleValue() method
45 // 3. Convert Result(2) to Java numeric type. Round to float precision.
46 // Unrepresentably large numbers are converted to +/-Infinity.
47
48 var newValue = Math.random();
49
50 a[i++] = new TestObject (
51 "dt.PUB_DOUBLE_REPRESENTATION = java.lang.Double.MAX_VALUE;" +
52 "dt.setFloat( dt )",
53 "dt.PUB_FLOAT",
54 "dt.getFloat()",
55 "typeof dt.getFloat()",
56 Infinity,
57 "number" );
58
59 a[i++] = new TestObject (
60 "dt.PUB_DOUBLE_REPRESENTATION = -java.lang.Double.MAX_VALUE;" +
61 "dt.setFloat( dt )",
62 "dt.PUB_FLOAT",
63 "dt.getFloat()",
64 "typeof dt.getFloat()",
65 -Infinity,
66 "number" );
67
68 a[i++] = new TestObject (
69 "dt.PUB_DOUBLE_REPRESENTATION = java.lang.Float.MAX_VALUE * 2;" +
70 "dt.setFloat( dt )",
71 "dt.PUB_FLOAT",
72 "dt.getFloat()",
73 "typeof dt.getFloat()",
74 Infinity,
75 "number" );
76
77 for ( i = 0; i < a.length; i++ ) {
78 new TestCase(
79 a[i].description +"; "+ a[i].javaFieldName,
80 a[i].jsValue,
81 a[i].javaFieldValue );
82
83 new TestCase(
84 a[i].description +"; " + a[i].javaMethodName,
85 a[i].jsValue,
86 a[i].javaMethodValue );
87
88 new TestCase(
89 a[i].javaTypeName,
90 a[i].jsType,
91 a[i].javaTypeValue );
92
93 }
94
95 test();
96
97 function TestObject( description, javaField, javaMethod, javaType,
98 jsValue, jsType )
99 {
100 eval (description );
101
102 this.description = description;
103 this.javaFieldName = javaField;
104 this.javaFieldValue = eval( javaField );
105 this.javaMethodName = javaMethod;
106 this.javaMethodValue = eval( javaMethod );
107 this.javaTypeName = javaType,
108 this.javaTypeValue = typeof this.javaFieldValue;
109
110 this.jsValue = jsValue;
111 this.jsType = jsType;
112 }