Debian Codegraph @

rhino/testsrc/tests/lc3/JavaObject/JavaObjectToString-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 = 'JavaObjectToString-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 string";
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 // Call the unwrapped object's toString() method, and return the result as
41 // a new java.lang.String.
42
43 var newValue = Math.random();
44 var newString = String( newValue );
45
46 a[i++] = new TestObject (
47 "dt.PUB_STRING_REPRESENTATION = \""+newString+"\";" +
48 "dt.setStringObject( dt )",
49 "dt.PUB_STRING +''",
50 "dt.getStringObject() +''",
51 "typeof dt.getStringObject()",
52 newString,
53 "string" );
54
55 a[i++] = new TestObject (
56 "dt.PUB_DOUBLE = java.lang.Double.valueOf(\"" + newString +"\")",
57 "dt.PUB_DOUBLE",
58 "dt.getDouble()",
59 "typeof dt.getDouble()",
60 newValue,
61 "number" );
62
63 for ( i = 0; i < a.length; i++ ) {
64 new TestCase(
65 a[i].description +"; "+ a[i].javaFieldName,
66 a[i].jsValue,
67 a[i].javaFieldValue );
68
69 new TestCase(
70 a[i].description +"; " + a[i].javaMethodName,
71 a[i].jsValue,
72 a[i].javaMethodValue );
73
74 new TestCase(
75 a[i].javaTypeName,
76 a[i].jsType,
77 a[i].javaTypeValue );
78
79 }
80
81 test();
82
83 function TestObject( description, javaField, javaMethod, javaType,
84 jsValue, jsType )
85 {
86 eval (description );
87
88 this.description = description;
89 this.javaFieldName = javaField;
90 this.javaFieldValue = eval( javaField );
91 this.javaMethodName = javaMethod;
92 this.javaMethodValue = eval( javaMethod );
93 this.javaTypeName = javaType,
94 this.javaTypeValue = typeof this.javaFieldValue;
95
96 this.jsValue = jsValue;
97 this.jsType = jsType;
98 }