author | rriggs |
Fri, 11 Oct 2019 13:11:56 -0400 | |
changeset 58565 | baa5969ecf34 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 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 |
||
31 |
import java.io.*; |
|
32 |
||
33 |
public class ArraysOfArrays { |
|
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
34 |
public static void main (String argv[]) throws IOException { |
2 | 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; |
|
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
40 |
FileOutputStream ostream = null; |
2 | 41 |
try { |
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
42 |
ostream = new FileOutputStream("piotest5.tmp"); |
2 | 43 |
ObjectOutputStream p = new ObjectOutputStream(ostream); |
44 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
45 |
byte[][] b = {{ 0, 1}, {2,3}}; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
46 |
p.writeObject(b); |
2 | 47 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
48 |
short[][] s = {{ 0, 1, 2}, {3,4,5}}; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
49 |
p.writeObject(s); |
2 | 50 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
51 |
char[][] c = {{ 0, 1, 2, 3}, {4, 5, 6, 7}}; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
52 |
p.writeObject(c); |
2 | 53 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
54 |
int[][] i = {{ 0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}}; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
55 |
p.writeObject(i); |
2 | 56 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
57 |
long[][] l = {{ 0, 1, 2, 3, 4, 5}, {6,7,8,9,10,11}}; |
2 | 58 |
p.writeObject((Object)l); |
59 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
60 |
boolean[][] z = new boolean[2][2]; |
2 | 61 |
|
62 |
z[0][0] = true; |
|
63 |
z[0][1] = false; |
|
64 |
z[1] = z[0]; // Use first row same as second |
|
65 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
66 |
p.writeObject(z); |
2 | 67 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
68 |
float[][] f = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}, |
2 | 69 |
{ 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f}}; |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
70 |
p.writeObject(f); |
2 | 71 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
72 |
double[][] d = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d}, |
2 | 73 |
{ 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1d}}; |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
74 |
p.writeObject(d); |
2 | 75 |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
76 |
Integer Int[][] = {{ 3, 2}, |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
77 |
{ 1, 0}}; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
78 |
p.writeObject(Int); |
2 | 79 |
|
80 |
p.flush(); |
|
81 |
||
82 |
/* Now read them back and verify |
|
83 |
*/ |
|
84 |
istream = new FileInputStream("piotest5.tmp"); |
|
85 |
ObjectInputStream q = new ObjectInputStream(istream); |
|
86 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
87 |
byte[][] b_u = (byte [][]) (q.readObject()); |
2 | 88 |
for (int ix = 0; ix < b_u.length; ix++) { |
89 |
for(int iy = 0; iy < b_u[ix].length; iy++) { |
|
90 |
if (b[ix][iy] != b_u[ix][iy]) { |
|
91 |
System.err.println("\nByte array mismatch [" + |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
92 |
ix + "][" + iy + "] expected " + b[ix][iy] + |
2 | 93 |
" actual = " + b_u[ix][iy]); |
94 |
throw new Error(); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
100 |
short[][] s_u = (short [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
101 |
for (int ix = 0; ix < s_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
102 |
for(int iy = 0; iy < s_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
103 |
if (s[ix][iy] != s_u[ix][iy]) { |
2 | 104 |
System.err.println("\nshort array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
105 |
ix + "][" + iy + "] expected " + s[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
106 |
" actual = " + s_u[ix][iy]); |
2 | 107 |
throw new Error(); |
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
112 |
char[][] c_u = (char [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
113 |
for (int ix = 0; ix < c_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
114 |
for(int iy = 0; iy < c_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
115 |
if (c[ix][iy] != c_u[ix][iy]) { |
2 | 116 |
System.err.println("\nchar array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
117 |
ix + "][" + iy + "] expected " + c[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
118 |
" actual = " + c_u[ix][iy]); |
2 | 119 |
throw new Error(); |
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
124 |
int[][] i_u = (int [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
125 |
for (int ix = 0; ix < i_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
126 |
for(int iy = 0; iy < i_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
127 |
if (i[ix][iy] != i_u[ix][iy]) { |
2 | 128 |
System.err.println("\nint array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
129 |
ix + "][" + iy + "] expected " + i[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
130 |
" actual = " + i_u[ix][iy]); |
2 | 131 |
throw new Error(); |
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
136 |
long[][] l_u = (long [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
137 |
for (int ix = 0; ix < l_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
138 |
for(int iy = 0; iy < l_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
139 |
if (l[ix][iy] != l_u[ix][iy]) { |
2 | 140 |
System.err.println("\nlong array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
141 |
ix + "][" + iy + "] expected " + l[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
142 |
" actual = " + l_u[ix][iy]); |
2 | 143 |
throw new Error(); |
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
148 |
boolean[][] z_u = (boolean [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
149 |
for (int ix = 0; ix < z_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
150 |
for(int iy = 0; iy < z_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
151 |
if (z[ix][iy] != z_u[ix][iy]) { |
2 | 152 |
System.err.println("\nboolean array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
153 |
ix + "][" + iy + "] expected " + z[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
154 |
" actual = " + z_u[ix][iy]); |
2 | 155 |
throw new Error(); |
156 |
} |
|
157 |
} |
|
158 |
} |
|
159 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
160 |
float[][] f_u = (float [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
161 |
for (int ix = 0; ix < f_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
162 |
for(int iy = 0; iy < f_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
163 |
if (f[ix][iy] != f_u[ix][iy]) { |
2 | 164 |
System.err.println("\nfloat array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
165 |
ix + "][" + iy + "] expected " + f[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
166 |
" actual = " + f_u[ix][iy]); |
2 | 167 |
throw new Error(); |
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
172 |
double[][] d_u = (double [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
173 |
for (int ix = 0; ix < d_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
174 |
for(int iy = 0; iy < d_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
175 |
if (d[ix][iy] != d_u[ix][iy]) { |
2 | 176 |
System.err.println("\ndouble array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
177 |
ix + "][" + iy + "] expected " + d[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
178 |
" actual = " + d_u[ix][iy]); |
2 | 179 |
throw new Error(); |
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
184 |
Integer[][] Int_u = (Integer [][])(q.readObject()); |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
185 |
for (int ix = 0; ix < Int_u.length; ix++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
186 |
for(int iy = 0; iy < Int_u[ix].length; iy++) { |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
187 |
if (!Int[ix][iy].equals(Int_u[ix][iy])) { |
2 | 188 |
System.err.println("\nInteger array mismatch [" + |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
189 |
ix + "][" + iy + "] expected " + Int[ix][iy] + |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
190 |
" actual = " + Int_u[ix][iy]); |
2 | 191 |
throw new Error(); |
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
System.err.println("\nTEST PASSED"); |
|
196 |
} catch (Exception e) { |
|
197 |
System.err.print("TEST FAILED: "); |
|
198 |
e.printStackTrace(); |
|
199 |
||
200 |
System.err.println("\nInput remaining"); |
|
201 |
int ch; |
|
202 |
try { |
|
203 |
while ((ch = istream.read()) != -1) { |
|
204 |
System.err.print("\n " +Integer.toString(ch, 16) + " "); |
|
205 |
} |
|
206 |
System.err.println("\n "); |
|
207 |
} catch (Exception f) { |
|
208 |
throw new Error(); |
|
209 |
} |
|
210 |
throw new Error(); |
|
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
211 |
} finally { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
212 |
if (istream != null) istream.close(); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
213 |
if (ostream != null) ostream.close(); |
2 | 214 |
} |
215 |
} |
|
216 |
} |