blob: 796e6fe568e9c9dd340e525af80b664694bf0c96 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @summary it is new version of old test which was under
26 * /src/share/test/serialization/piotest.java
27 * Test of serialization/deserialization of
28 * objects as arrays of arrays
29 */
30
31import java.io.*;
32
33public class ArraysOfArrays {
34 public static void main (String argv[]) {
35 System.err.println("\nRegression test for testing of " +
36 "serialization/deserialization of objects as " +
37 "arrays of arrays \n");
38
39 FileInputStream istream = null;
40 try {
41 FileOutputStream ostream = new FileOutputStream("piotest5.tmp");
42 ObjectOutputStream p = new ObjectOutputStream(ostream);
43
44 byte b[][] = {{ 0, 1}, {2,3}};
45 p.writeObject((Object)b);
46
47 short s[][] = {{ 0, 1, 2}, {3,4,5}};
48 p.writeObject((Object)s);
49
50 char c[][] = {{ 0, 1, 2, 3}, {4, 5, 6, 7}};
51 p.writeObject((Object)c);
52
53 int i[][] = {{ 0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}};
54 p.writeObject((Object)i);
55
56 long l[][] = {{ 0, 1, 2, 3, 4, 5}, {6,7,8,9,10,11}};
57 p.writeObject((Object)l);
58
59 boolean z[][] = new boolean[2][2];
60
61 z[0][0] = true;
62 z[0][1] = false;
63 z[1] = z[0]; // Use first row same as second
64
65 p.writeObject((Object)z);
66
67 float f[][] = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f},
68 { 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f}};
69 p.writeObject((Object)f);
70
71 double d[][] = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d},
72 { 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1d}};
73 p.writeObject((Object)d);
74
75 Integer Int[][] = {{ new Integer(3), new Integer(2)},
76 { new Integer(1), new Integer(0)}};
77 p.writeObject((Object)Int);
78
79 p.flush();
80
81 /* Now read them back and verify
82 */
83 istream = new FileInputStream("piotest5.tmp");
84 ObjectInputStream q = new ObjectInputStream(istream);
85
86 byte b_u[][] = (byte [][]) (q.readObject());
87 for (int ix = 0; ix < b_u.length; ix++) {
88 for(int iy = 0; iy < b_u[ix].length; iy++) {
89 if (b[ix][iy] != b_u[ix][iy]) {
90 System.err.println("\nByte array mismatch [" +
91 ix + "][" + iy + " expected " + b[ix][iy] +
92 " actual = " + b_u[ix][iy]);
93 throw new Error();
94 }
95 }
96 }
97
98
99 short s_u[][] = (short [][])(q.readObject());
100 for (int ix = 0; ix < b_u.length; ix++) {
101 for(int iy = 0; iy < b_u[ix].length; iy++) {
102 if (b[ix][iy] != b_u[ix][iy]) {
103 System.err.println("\nshort array mismatch [" +
104 ix + "][" + iy + " expected " + b[ix][iy] +
105 " actual = " + b_u[ix][iy]);
106 throw new Error();
107 }
108 }
109 }
110
111 char c_u[][] = (char [][])(q.readObject());
112 for (int ix = 0; ix < b_u.length; ix++) {
113 for(int iy = 0; iy < b_u[ix].length; iy++) {
114 if (b[ix][iy] != b_u[ix][iy]) {
115 System.err.println("\nchar array mismatch [" +
116 ix + "][" + iy + " expected " + b[ix][iy] +
117 " actual = " + b_u[ix][iy]);
118 throw new Error();
119 }
120 }
121 }
122
123 int i_u[][] = (int [][])(q.readObject());
124 for (int ix = 0; ix < b_u.length; ix++) {
125 for(int iy = 0; iy < b_u[ix].length; iy++) {
126 if (b[ix][iy] != b_u[ix][iy]) {
127 System.err.println("\nint array mismatch [" +
128 ix + "][" + iy + " expected " + b[ix][iy] +
129 " actual = " + b_u[ix][iy]);
130 throw new Error();
131 }
132 }
133 }
134
135 long l_u[][] = (long [][])(q.readObject());
136 for (int ix = 0; ix < b_u.length; ix++) {
137 for(int iy = 0; iy < b_u[ix].length; iy++) {
138 if (b[ix][iy] != b_u[ix][iy]) {
139 System.err.println("\nlong array mismatch [" +
140 ix + "][" + iy + " expected " + b[ix][iy] +
141 " actual = " + b_u[ix][iy]);
142 throw new Error();
143 }
144 }
145 }
146
147 boolean z_u[][] = (boolean [][])(q.readObject());
148 for (int ix = 0; ix < b_u.length; ix++) {
149 for(int iy = 0; iy < b_u[ix].length; iy++) {
150 if (b[ix][iy] != b_u[ix][iy]) {
151 System.err.println("\nboolean array mismatch [" +
152 ix + "][" + iy + " expected " + b[ix][iy] +
153 " actual = " + b_u[ix][iy]);
154 throw new Error();
155 }
156 }
157 }
158
159 float f_u[][] = (float [][])(q.readObject());
160 for (int ix = 0; ix < b_u.length; ix++) {
161 for(int iy = 0; iy < b_u[ix].length; iy++) {
162 if (b[ix][iy] != b_u[ix][iy]) {
163 System.err.println("\nfloat array mismatch [" +
164 ix + "][" + iy + " expected " + b[ix][iy] +
165 " actual = " + b_u[ix][iy]);
166 throw new Error();
167 }
168 }
169 }
170
171 double d_u[][] = (double [][])(q.readObject());
172 for (int ix = 0; ix < b_u.length; ix++) {
173 for(int iy = 0; iy < b_u[ix].length; iy++) {
174 if (b[ix][iy] != b_u[ix][iy]) {
175 System.err.println("\ndouble array mismatch [" +
176 ix + "][" + iy + " expected " + b[ix][iy] +
177 " actual = " + b_u[ix][iy]);
178 throw new Error();
179 }
180 }
181 }
182
183 Integer Int_u[][] = (Integer [][])(q.readObject());
184 for (int ix = 0; ix < b_u.length; ix++) {
185 for(int iy = 0; iy < b_u[ix].length; iy++) {
186 if (b[ix][iy] != b_u[ix][iy]) {
187 System.err.println("\nInteger array mismatch [" +
188 ix + "][" + iy + " expected " + b[ix][iy] +
189 " actual = " + b_u[ix][iy]);
190 throw new Error();
191 }
192 }
193 }
194 System.err.println("\nTEST PASSED");
195 } catch (Exception e) {
196 System.err.print("TEST FAILED: ");
197 e.printStackTrace();
198
199 System.err.println("\nInput remaining");
200 int ch;
201 try {
202 while ((ch = istream.read()) != -1) {
203 System.err.print("\n " +Integer.toString(ch, 16) + " ");
204 }
205 System.err.println("\n ");
206 } catch (Exception f) {
207 throw new Error();
208 }
209 throw new Error();
210 }
211 }
212}