Debian Codegraph @

rhino/testsrc/tests/lc2/Methods/method-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 = 'method-001.js';
7
8 /**
9 File Name: method-001.js
10 Description:
11
12 Call a static method of an object and verify return value.
13 This is covered more thoroughly in the type conversion test cases.
14 This only covers cases in which JavaObjects are returned.
15
16 @author [email protected]
17 @version 1.00
18 */
19 var SECTION = "LiveConnect Objects";
20 var VERSION = "1_3";
21 var TITLE = "Calling Static Methods";
22
23 startTest();
24 writeHeaderToLog( SECTION + " "+ TITLE);
25
26 // All JavaObjects are of the type "object"
27
28 var E_TYPE = "object";
29
30 // All JavaObjects [[Class]] property is JavaObject
31 var E_JSCLASS = "[object JavaObject]";
32
33 // Create arrays of actual results (java_array) and
34 // expected results (test_array).
35
36 var java_array = new Array();
37 var test_array = new Array();
38
39 var i = 0;
40
41 java_array[i] = new JavaValue( java.lang.String.valueOf(true) );
42 test_array[i] = new TestValue( "java.lang.String.valueOf(true)",
43 "object", "java.lang.String", "true" );
44
45 i++;
46
47 java_array[i] = new JavaValue( java.awt.Color.getHSBColor(0.0, 0.0, 0.0) );
48 test_array[i] = new TestValue( "java.awt.Color.getHSBColor(0.0, 0.0, 0.0)",
49 "object", "java.awt.Color", "java.awt.Color[r=0,g=0,b=0]" );
50
51 i++;
52
53
54 for ( i = 0; i < java_array.length; i++ ) {
55 CompareValues( java_array[i], test_array[i] );
56 }
57
58 test();
59
60 function CompareValues( javaval, testval ) {
61 // Check type, which should be E_TYPE
62 new TestCase( SECTION,
63 "typeof (" + testval.description +" )",
64 testval.type,
65 javaval.type );
66 /*
67 // Check JavaScript class, which should be E_JSCLASS
68 new TestCase( SECTION,
69 "(" + testval.description +" ).getJSClass()",
70 E_JSCLASS,
71 javaval.jsclass );
72 */
73 // Check the JavaClass, which should be the same as the result as Class.forName(description).
74 new TestCase( SECTION,
75 "("+testval.description +").getClass().equals( " +
76 "java.lang.Class.forName( '" + testval.classname +
77 "' ) )",
78 true,
79 (javaval.javaclass).equals( testval.javaclass ) );
80 // check the string value
81 new TestCase(
82 SECTION,
83 "("+testval.description+") +''",
84 testval.stringval,
85 javaval.value +"" );
86 }
87 function JavaValue( value ) {
88 this.type = typeof value;
89 this.value = value;
90 // LC2 does not support the __proto__ property in Java objects
91 // Object.prototype.toString will show its JavaScript wrapper object.
92 // value.__proto__.getJSClass = Object.prototype.toString;
93 // this.jsclass = value.getJSClass();
94 this.javaclass = value.getClass();
95
96 return this;
97 }
98 function TestValue( description, type, classname, stringval ) {
99 this.description = description;
100 this.type = type;
101 this.classname = classname;
102 this.javaclass = java.lang.Class.forName( classname );
103 this.stringval = stringval;
104
105 return this;
106 }