Debian Codegraph @

rhino/testsrc/tests/lc2/Arrays/array-002.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 = 'array-002.js';
7
8 /**
9 File Name: array-002.js
10 Description:
11
12 JavaArrays should have a length property that specifies the number of
13 elements in the array.
14
15 JavaArray elements can be referenced with the [] array index operator.
16
17 @author [email protected]
18 @version 1.00
19 */
20 var SECTION = "LiveConnect";
21 var VERSION = "1_3";
22 var TITLE = "Java Array to JavaScript JavaArray object";
23
24 startTest();
25 writeHeaderToLog( SECTION + " "+ TITLE);
26
27 // In all test cases, the expected type is "object, and the expected
28 // class is "JavaArray"
29
30 var E_TYPE = "object";
31 var E_CLASS = "[object JavaArray]";
32
33 // Create arrays of actual results (java_array) and expected results
34 // (test_array).
35
36 var java_array = new Array();
37 var test_array = new Array();
38
39 var i = 0;
40
41 // byte[]
42
43 var byte_array = ( new java.lang.String("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ).getBytes();
44
45 java_array[i] = new JavaValue( byte_array );
46 test_array[i] = new TestValue( "( new java.lang.String('ABCDEFGHIJKLMNOPQRSTUVWXYZ') ).getBytes()",
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ".length
48 );
49 i++;
50
51
52 // char[]
53 var char_array = ( new java.lang.String("rhino") ).toCharArray();
54
55 java_array[i] = new JavaValue( char_array );
56 test_array[i] = new TestValue( "( new java.lang.String('rhino') ).toCharArray()",
57 "rhino".length );
58 i++;
59
60
61 for ( i = 0; i < java_array.length; i++ ) {
62 CompareValues( java_array[i], test_array[i] );
63 }
64
65 test();
66
67 function CompareValues( javaval, testval ) {
68 // Check length
69 new TestCase( SECTION,
70 "("+ testval.description +").length",
71 testval.value,
72 javaval.length );
73 }
74 function JavaValue( value ) {
75 this.value = value;
76 this.length = value.length;
77 this.type = typeof value;
78 this.classname = this.value.toString();
79
80 return this;
81 }
82 function TestValue( description, value ) {
83 this.description = description;
84 this.length = value
85 this.value = value;
86 this.type = E_TYPE;
87 this.classname = E_CLASS;
88 return this;
89 }