1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile
= 'array-001.js';
42 * Verify that for-in loops can be used with java objects.
44 * Java array members should be enumerated in for... in loops.
48 var SECTION
= "array-001";
50 var TITLE
= "LiveConnect 3.0: for ... in java objects";
54 // we just need to know the names of all the expected enumerated
55 // properties. we will get the values to the original objects.
57 // for arrays, we just need to know the length, since java arrays
58 // don't have any extra properties
61 var dt
= new Packages
.com
.netscape
.javascript
.qa
.liveconnect
.DataTypeClass
;
65 a
[a
.length
] = new TestObject(
66 new java
.lang
.String("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").getBytes(),
67 "new java.lang.String(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\").getBytes()",
70 a
[a
.length
] = new TestObject(
73 dt
.PUB_ARRAY_SHORT
.length
);
75 a
[a
.length
] = new TestObject(
78 dt
.PUB_ARRAY_LONG
.length
);
80 a
[a
.length
] = new TestObject(
82 "dt.PUB_ARRAY_DOUBLE",
83 dt
.PUB_ARRAY_DOUBLE
.length
);
85 a
[a
.length
] = new TestObject(
88 dt
.PUB_ARRAY_BYTE
.length
);
90 a
[a
.length
] = new TestObject(
93 dt
.PUB_ARRAY_CHAR
.length
);
95 a
[a
.length
] = new TestObject(
97 "dt.PUB_ARRAY_OBJECT",
98 dt
.PUB_ARRAY_OBJECT
.length
);
100 for ( var i
= 0; i
< a
.length
; i
++ ) {
101 // check the number of properties of the enumerated object
103 a
[i
].description
+"; length",
105 a
[i
].enumedArray
.pCount
);
107 for ( var arrayItem
= 0; arrayItem
< a
[i
].items
; arrayItem
++ ) {
110 a
[i
].javaArray
[arrayItem
],
111 a
[i
].enumedArray
[arrayItem
] );
117 function TestObject( arr
, descr
, len
) {
118 this.javaArray
= arr
;
119 this.description
= descr
;
121 this.enumedArray
= new enumObject(arr
);
124 function enumObject( o
) {
129 eval( "this["+p
+"] = o["+p
+"]" );
131 eval( "this." + p
+ " = o["+ p
+"]" );