Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/oldTests/CheckingEquality.java
38828 views
1
/*
2
* Copyright (c) 2005, 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
26
* /src/share/test/serialization/psiotest.java
27
* Test pickling and unpickling an object with derived classes
28
* and using a read special to serialize the "middle" class.
29
*
30
*/
31
32
import java.io.*;
33
34
public class CheckingEquality {
35
public static void main (String argv[]) {
36
System.err.println("\nRegression test of " +
37
"serialization/deserialization of " +
38
"complex objects\n");
39
40
FileInputStream istream = null;
41
try {
42
43
Thirdpsio objout = new Thirdpsio();
44
objout.init();
45
46
FileOutputStream ostream = new FileOutputStream("psiotest1.tmp");
47
ObjectOutputStream p = new ObjectOutputStream(ostream);
48
49
p.writeObject(objout);
50
51
p.flush();
52
ostream.close();
53
54
istream = new FileInputStream("psiotest1.tmp");
55
ObjectInputStream q = new ObjectInputStream(istream);
56
57
Thirdpsio objin = (Thirdpsio)q.readObject();
58
59
if (!objout.equals(objin)) {
60
System.err.println(
61
"\nTEST FAILED: Original and read objects not equal.");
62
throw new Error();
63
}
64
istream.close();
65
System.err.println("\nTEST PASSED");
66
} catch (Exception e) {
67
System.err.print("TEST FAILED: ");
68
e.printStackTrace();
69
70
System.err.println("\nInput remaining");
71
int ch;
72
try {
73
while ((ch = istream.read()) != -1) {
74
System.out.print(Integer.toString(ch, 16) + " ");
75
}
76
System.err.println("\n");
77
} catch (Exception f) {
78
throw new Error();
79
}
80
throw new Error();
81
}
82
}
83
}
84
85
class Firstpsio implements java.io.Serializable {
86
String one;
87
int two;
88
float three[];
89
90
void init() { /* called only before writing */
91
one = "one";
92
two = 2;
93
three = new float[5];
94
float f = 3.0f;
95
for (int i=0; i<5 ; i++) {
96
f += 0.11;
97
three[i] = f;
98
}
99
}
100
101
/* Compare two first objects */
102
boolean equals(Firstpsio other) {
103
boolean ret = true;
104
105
if (!one.equals(other.one)) {
106
System.err.println("\nfirstpsio: expected " + one +
107
" actual " + other.one);
108
ret = false;
109
}
110
if (two != other.two) {
111
System.err.println("\nfirstpsio: expected " + two +
112
" actual " + other.two);
113
ret = false;
114
}
115
116
for (int i = 0; i < three.length; i++ ) {
117
if (three[i] != other.three[i]) {
118
System.err.println("\nfirstpsio: three[" + i + "] expected " +
119
three[i] + " actual " + other.three[i]);
120
ret = false;
121
}
122
}
123
return ret;
124
}
125
}
126
127
class Secondpsio extends Firstpsio {
128
String quatre;
129
int cinq;
130
131
private void writeObject(ObjectOutputStream pw) throws IOException {
132
pw.writeObject(quatre);
133
pw.writeInt(cinq);
134
}
135
136
private void readObject(ObjectInputStream pr)
137
throws StreamCorruptedException, IOException, ClassNotFoundException
138
{
139
if (one == null) {
140
System.err.println(
141
"\nTEST FAILED: Superclass not serialized when " +
142
"it should have been");
143
throw new StreamCorruptedException("Superclass not serialized " +
144
"when it should have been");
145
}
146
147
quatre = (String)pr.readObject();
148
cinq = pr.readInt();
149
}
150
151
boolean equals(Secondpsio other) {
152
boolean ret = super.equals(other);
153
154
if (!quatre.equals(other.quatre)) {
155
System.err.println("\nsecondpsio: quatre expected " + quatre +
156
" actual " + other.quatre);
157
ret = false;
158
}
159
if (cinq != other.cinq) {
160
System.err.println("\nsecondpsio: cinq expected " + cinq +
161
" actual " + other.cinq);
162
ret = false;
163
}
164
return ret;
165
}
166
167
/* called only before writing */
168
void init() {
169
quatre = "4444";
170
cinq = 5;
171
super.init();
172
}
173
}
174
175
class Thirdpsio extends Secondpsio {
176
177
static String ign = "ignored";
178
transient Object oh;
179
180
int six;
181
182
private static int seven[];
183
protected byte eight = (byte)9;
184
final static byte dcare = (byte) 128;
185
private short nine = 8888;
186
long ten;
187
java.util.Enumeration zero;
188
189
190
boolean equals(Thirdpsio other) {
191
boolean ret = super.equals(other);
192
193
if (six != other.six) {
194
System.err.println("\nthirdpsio six " + six +
195
" actual " + other.six);
196
ret = false;
197
}
198
if (eight != other.eight) {
199
System.err.println("\nthirdpsio eight - expected " + eight +
200
" actual " + other.eight);
201
ret = false;
202
}
203
if (nine != other.nine) {
204
System.err.println("\nthirdpsio nine - expected " + nine +
205
" actual " + other.nine);
206
ret = false;
207
}
208
if (ten != other.ten) {
209
System.err.println("\nthirdpsio ten - expected " + ten +
210
" actual " + other.ten);
211
ret = false;
212
}
213
if (zero != other.zero) {
214
System.err.println("\nthirdpsio zero - expected " + zero +
215
" actual " + other.zero);
216
ret = false;
217
}
218
return ret;
219
}
220
221
/* called only before writing */
222
void init() {
223
six = 666;
224
225
int s7[] = { 7, 7, 7 };
226
seven = s7;
227
eight = (byte)8;
228
nine = (short)9;
229
ten = (long)100000;
230
java.util.Enumeration em = null; /* default */
231
232
super.init();
233
}
234
}
235
236