Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/oldTests/ArraysOfArrays.java
41153 views
1
/*
2
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. 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 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.
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 {
34
public static void main (String argv[]) throws IOException {
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
FileOutputStream ostream = null;
41
try {
42
ostream = new FileOutputStream("piotest5.tmp");
43
ObjectOutputStream p = new ObjectOutputStream(ostream);
44
45
byte[][] b = {{ 0, 1}, {2,3}};
46
p.writeObject(b);
47
48
short[][] s = {{ 0, 1, 2}, {3,4,5}};
49
p.writeObject(s);
50
51
char[][] c = {{ 0, 1, 2, 3}, {4, 5, 6, 7}};
52
p.writeObject(c);
53
54
int[][] i = {{ 0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}};
55
p.writeObject(i);
56
57
long[][] l = {{ 0, 1, 2, 3, 4, 5}, {6,7,8,9,10,11}};
58
p.writeObject((Object)l);
59
60
boolean[][] z = new boolean[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
66
p.writeObject(z);
67
68
float[][] f = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f},
69
{ 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f}};
70
p.writeObject(f);
71
72
double[][] d = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d},
73
{ 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1d}};
74
p.writeObject(d);
75
76
Integer Int[][] = {{ 3, 2},
77
{ 1, 0}};
78
p.writeObject(Int);
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
87
byte[][] b_u = (byte [][]) (q.readObject());
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 [" +
92
ix + "][" + iy + "] expected " + b[ix][iy] +
93
" actual = " + b_u[ix][iy]);
94
throw new Error();
95
}
96
}
97
}
98
99
100
short[][] s_u = (short [][])(q.readObject());
101
for (int ix = 0; ix < s_u.length; ix++) {
102
for(int iy = 0; iy < s_u[ix].length; iy++) {
103
if (s[ix][iy] != s_u[ix][iy]) {
104
System.err.println("\nshort array mismatch [" +
105
ix + "][" + iy + "] expected " + s[ix][iy] +
106
" actual = " + s_u[ix][iy]);
107
throw new Error();
108
}
109
}
110
}
111
112
char[][] c_u = (char [][])(q.readObject());
113
for (int ix = 0; ix < c_u.length; ix++) {
114
for(int iy = 0; iy < c_u[ix].length; iy++) {
115
if (c[ix][iy] != c_u[ix][iy]) {
116
System.err.println("\nchar array mismatch [" +
117
ix + "][" + iy + "] expected " + c[ix][iy] +
118
" actual = " + c_u[ix][iy]);
119
throw new Error();
120
}
121
}
122
}
123
124
int[][] i_u = (int [][])(q.readObject());
125
for (int ix = 0; ix < i_u.length; ix++) {
126
for(int iy = 0; iy < i_u[ix].length; iy++) {
127
if (i[ix][iy] != i_u[ix][iy]) {
128
System.err.println("\nint array mismatch [" +
129
ix + "][" + iy + "] expected " + i[ix][iy] +
130
" actual = " + i_u[ix][iy]);
131
throw new Error();
132
}
133
}
134
}
135
136
long[][] l_u = (long [][])(q.readObject());
137
for (int ix = 0; ix < l_u.length; ix++) {
138
for(int iy = 0; iy < l_u[ix].length; iy++) {
139
if (l[ix][iy] != l_u[ix][iy]) {
140
System.err.println("\nlong array mismatch [" +
141
ix + "][" + iy + "] expected " + l[ix][iy] +
142
" actual = " + l_u[ix][iy]);
143
throw new Error();
144
}
145
}
146
}
147
148
boolean[][] z_u = (boolean [][])(q.readObject());
149
for (int ix = 0; ix < z_u.length; ix++) {
150
for(int iy = 0; iy < z_u[ix].length; iy++) {
151
if (z[ix][iy] != z_u[ix][iy]) {
152
System.err.println("\nboolean array mismatch [" +
153
ix + "][" + iy + "] expected " + z[ix][iy] +
154
" actual = " + z_u[ix][iy]);
155
throw new Error();
156
}
157
}
158
}
159
160
float[][] f_u = (float [][])(q.readObject());
161
for (int ix = 0; ix < f_u.length; ix++) {
162
for(int iy = 0; iy < f_u[ix].length; iy++) {
163
if (f[ix][iy] != f_u[ix][iy]) {
164
System.err.println("\nfloat array mismatch [" +
165
ix + "][" + iy + "] expected " + f[ix][iy] +
166
" actual = " + f_u[ix][iy]);
167
throw new Error();
168
}
169
}
170
}
171
172
double[][] d_u = (double [][])(q.readObject());
173
for (int ix = 0; ix < d_u.length; ix++) {
174
for(int iy = 0; iy < d_u[ix].length; iy++) {
175
if (d[ix][iy] != d_u[ix][iy]) {
176
System.err.println("\ndouble array mismatch [" +
177
ix + "][" + iy + "] expected " + d[ix][iy] +
178
" actual = " + d_u[ix][iy]);
179
throw new Error();
180
}
181
}
182
}
183
184
Integer[][] Int_u = (Integer [][])(q.readObject());
185
for (int ix = 0; ix < Int_u.length; ix++) {
186
for(int iy = 0; iy < Int_u[ix].length; iy++) {
187
if (!Int[ix][iy].equals(Int_u[ix][iy])) {
188
System.err.println("\nInteger array mismatch [" +
189
ix + "][" + iy + "] expected " + Int[ix][iy] +
190
" actual = " + Int_u[ix][iy]);
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();
211
} finally {
212
if (istream != null) istream.close();
213
if (ostream != null) ostream.close();
214
}
215
}
216
}
217
218