Debian Codegraph @

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