Debian Codegraph @

rhino/testsrc/tests/lc3/JavaArray/ToArray-002-n.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 = 'ToArray-002-n.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 = "JavaArray to Object[]";
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 // if the array is not an instance of the correct type, create a runtime
40 // error.
41
42 // Vector.copyInto expects an object array
43
44 DESCRIPTION = "var vector = new java.util.Vector(); "+
45 "vector.addElement( \"a\" ); vector.addElement( \"b\" ); "+
46 "vector.copyInto( DT.PUB_STATIC_ARRAY_CHAR )";
47 EXPECTED = "error";
48
49 a[i++] = new TestObject(
50 "var vector = new java.util.Vector(); "+
51 "vector.addElement( \"a\" ); vector.addElement( \"b\" ); "+
52 "vector.copyInto( DT.PUB_STATIC_ARRAY_CHAR )",
53 "DT.PUB_STATIC_ARRAY_OBJECT[0] +''",
54 "DT.staticGetObjectArray()[0] +''",
55 "typeof DT.staticGetObjectArray()[0]",
56 "error",
57 "error" );
58
59 for ( i = 0; i < a.length; i++ ) {
60 new TestCase(
61 a[i].description +"; "+ a[i].javaFieldName,
62 a[i].jsValue,
63 a[i].javaFieldValue );
64
65 new TestCase(
66 a[i].description +"; " + a[i].javaMethodName,
67 a[i].jsValue,
68 a[i].javaMethodValue );
69
70 new TestCase(
71 a[i].javaTypeName,
72 a[i].jsType,
73 a[i].javaTypeValue );
74
75 }
76
77 test();
78
79 function TestObject( description, javaField, javaMethod, javaType,
80 jsValue, jsType )
81 {
82 eval (description );
83
84 this.description = description;
85 this.javaFieldName = javaField;
86 this.javaFieldValue = eval( javaField );
87 this.javaMethodName = javaMethod;
88 this.javaMethodValue = eval( javaMethod );
89 this.javaTypeName = javaType,
90 this.javaTypeValue = eval(javaType);
91
92 this.jsValue = jsValue;
93 this.jsType = jsType;
94 }