Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToChar-002.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 = 'JavaObjectToChar-002.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 char";
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. If result(2) is NaN, a runtime error occurs
44 // 3. Convert Result(2) to Java numeric type. Round JS number to integral
45 // value using round-to-negative-infinity mode.
46 // Numbers with a magnitude too large to be represented in the target
47 // integral type should result in a runtime error.
48
49 a[i++] = new TestObject (
50 "dt.PUB_DOUBLE_REPRESENTATION = -0.6;"+
51 "dt.setChar( dt )",
52 "dt.PUB_CHAR",
53 "dt.getChar()",
54 "typeof dt.getChar()",
55 0,
56 "number" );
57
58 for ( i = 0; i < a.length; i++ ) {
59 new TestCase(
60 a[i].description +"; "+ a[i].javaFieldName,
61 a[i].jsValue,
62 a[i].javaFieldValue );
63
64 new TestCase(
65 a[i].description +"; " + a[i].javaMethodName,
66 a[i].jsValue,
67 a[i].javaMethodValue );
68
69 new TestCase(
70 a[i].javaTypeName,
71 a[i].jsType,
72 a[i].javaTypeValue );
73
74 }
75
76 test();
77
78 function TestObject( description, javaField, javaMethod, javaType,
79 jsValue, jsType )
80 {
81 eval (description );
82
83 this.description = description;
84 this.javaFieldName = javaField;
85 this.javaFieldValue = eval( javaField );
86 this.javaMethodName = javaMethod;
87 this.javaMethodValue = eval( javaMethod );
88 this.javaTypeName = javaType,
89 this.javaTypeValue = typeof this.javaFieldValue;
90
91 this.jsValue = jsValue;
92 this.jsType = jsType;
93 }