Debian Codegraph @

rhino/testsrc/tests/lc3/JavaClass/ToClass-001.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
3 * All Rights Reserved.
4 */
5 /* This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
9 gTestfile = 'ToClass-001.js';
10
11 /**
12 * JavaScript to Java type conversion.
13 *
14 * This test passes JavaScript number values to several Java methods
15 * that expect arguments of various types, and verifies that the value is
16 * converted to the correct value and type.
17 *
18 * This tests instance methods, and not static methods.
19 *
20 * Running these tests successfully requires you to have
21 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
22 *
23 * Specification: Method Overloading Proposal for Liveconnect 3.0
24 *
25 * @author: [email protected]
26 *
27 */
28 var SECTION = "JavaClass to java.lang.Class";
29 var VERSION = "1_4";
30 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
31 SECTION;
32 startTest();
33
34 var dt = new DT();
35
36 var a = new Array();
37 var i = 0;
38
39 // Extract the corresponding Java class object
40
41 a[i++] = new TestObject (
42 "var newClass = java.lang.Class.forName(\"java.lang.Byte\"); "+
43 "dt.setClass( newClass )",
44 "dt.PUB_CLASS",
45 "dt.instanceGetClass()",
46 "dt.instanceGetClass()",
47 java.lang.Class.forName("java.lang.Byte"),
48 "object" );
49
50 // pass a java class to a method that expects a java.lang.Object
51
52 a[i++] = new TestObject (
53 "var newClass = java.lang.Class.forName(\"java.lang.Byte\"); "+
54 "var javaVector = new java.util.Vector() ;"+
55 "javaVector.addElement( newClass ); " +
56 "javaVector.elementAt(0)",
57 "dt.PUB_CLASS",
58 "dt.instanceGetClass()",
59 "dt.instanceGetClass()",
60 java.lang.Class.forName("java.lang.Byte"),
61 "object" );
62
63
64 for ( i = 0; i < a.length; i++ ) {
65 new TestCase(
66 a[i].description +"; "+ a[i].javaFieldName,
67 a[i].jsValue,
68 a[i].javaFieldValue );
69
70 new TestCase(
71 a[i].description +"; " + a[i].javaMethodName,
72 a[i].jsValue,
73 a[i].javaMethodValue );
74
75 new TestCase(
76 a[i].javaTypeName,
77 a[i].jsType,
78 a[i].javaTypeValue );
79
80 }
81
82 test();
83
84 function TestObject( description, javaField, javaMethod, javaType,
85 jsValue, jsType )
86 {
87 eval (description );
88
89 this.description = description;
90 this.javaFieldName = javaField;
91 this.javaFieldValue = eval( javaField );
92 this.javaMethodName = javaMethod;
93 this.javaMethodValue = eval( javaMethod );
94 this.javaTypeName = javaType,
95 this.javaTypeValue = typeof this.javaFieldValue;
96
97 this.jsValue = jsValue;
98 this.jsType = jsType;
99 }