Debian Codegraph @

rhino/testsrc/tests/lc2/Objects/object-005.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 = 'object-005.js';
7
8 /**
9 File Name: object-005.js
10 Description:
11
12 Call ToNumber, ToString, and use the addition operator to
13 access the DefaultValue with hints Number, String, and no
14 hint (respectively).
15
16 @author [email protected]
17 @version 1.00
18 */
19 var SECTION = "LiveConnect Objects";
20 var VERSION = "1_3";
21 var TITLE = "Getting the Class of JavaObjects";
22
23 startTest();
24 writeHeaderToLog( SECTION + " "+ TITLE);
25
26 var a = new Array();
27 var i = 0;
28
29 // here's an object that should be converted to a number
30 a[i++] = new TestObject( "new java.lang.Integer(999)",
31 new java.lang.Integer(999), "Number", 999, "number" );
32
33 a[i++] = new TestObject(
34 "new java.lang.Float(999.0)",
35 new java.lang.Float(999.0),
36 "Number",
37 999,
38 "number" );
39
40 a[i++] = new TestObject(
41 "new java.lang.String(\"hi\")",
42 new java.lang.String("hi"),
43 "String",
44 "hi",
45 "string" );
46
47 a[i++] = new TestObject(
48 "new java.lang.Integer(2134)",
49 new java.lang.Integer(2134),
50 "0 + ",
51 "21340",
52 "string" );
53
54 a[i++] = new TestObject(
55 "new java.lang.Integer(666)",
56 new java.lang.Integer(666),
57 "Boolean",
58 true,
59 "boolean" );
60
61 for ( i = 0; i < a.length; i++ ) {
62 CompareValues( a[i] );
63 }
64
65 test();
66
67 function CompareValues( t ) {
68 new TestCase(
69 SECTION,
70 t.converter +"("+ t.description +")",
71 t.expect,
72 t.actual );
73
74 new TestCase(
75 SECTION,
76 "typeof (" + t.converter +"( "+ t.description +" ) )",
77 t.type,
78 typeof t.actual );
79 }
80 function TestObject( description, javaobject, converter, expect, type ) {
81 this.description = description;
82 this.javavalue = javaobject
83 this.converter = converter;
84 this.expect = expect;
85 this.type = type;
86
87 switch ( converter ) {
88 case( "Number" ) : this.actual = Number( javaobject ); break;
89 case( "String" ) : this.actual = String( javaobject ); break;
90 case( "Boolean") : this.actual = Boolean(javaobject ); break;
91 default: this.actual = javaobject + 0;
92 }
93 return this;
94 }