Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/oldTests/CheckingEquality.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
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
private static final long serialVersionUID = 1L;
87
88
String one;
89
int two;
90
float three[];
91
92
void init() { /* called only before writing */
93
one = "one";
94
two = 2;
95
three = new float[5];
96
float f = 3.0f;
97
for (int i=0; i<5 ; i++) {
98
f += 0.11;
99
three[i] = f;
100
}
101
}
102
103
/* Compare two first objects */
104
boolean equals(Firstpsio other) {
105
boolean ret = true;
106
107
if (!one.equals(other.one)) {
108
System.err.println("\nfirstpsio: expected " + one +
109
" actual " + other.one);
110
ret = false;
111
}
112
if (two != other.two) {
113
System.err.println("\nfirstpsio: expected " + two +
114
" actual " + other.two);
115
ret = false;
116
}
117
118
for (int i = 0; i < three.length; i++ ) {
119
if (three[i] != other.three[i]) {
120
System.err.println("\nfirstpsio: three[" + i + "] expected " +
121
three[i] + " actual " + other.three[i]);
122
ret = false;
123
}
124
}
125
return ret;
126
}
127
}
128
129
class Secondpsio extends Firstpsio {
130
private static final long serialVersionUID = 1L;
131
132
String quatre;
133
int cinq;
134
135
private void writeObject(ObjectOutputStream pw) throws IOException {
136
pw.writeObject(quatre);
137
pw.writeInt(cinq);
138
}
139
140
private void readObject(ObjectInputStream pr)
141
throws StreamCorruptedException, IOException, ClassNotFoundException
142
{
143
if (one == null) {
144
System.err.println(
145
"\nTEST FAILED: Superclass not serialized when " +
146
"it should have been");
147
throw new StreamCorruptedException("Superclass not serialized " +
148
"when it should have been");
149
}
150
151
quatre = (String)pr.readObject();
152
cinq = pr.readInt();
153
}
154
155
boolean equals(Secondpsio other) {
156
boolean ret = super.equals(other);
157
158
if (!quatre.equals(other.quatre)) {
159
System.err.println("\nsecondpsio: quatre expected " + quatre +
160
" actual " + other.quatre);
161
ret = false;
162
}
163
if (cinq != other.cinq) {
164
System.err.println("\nsecondpsio: cinq expected " + cinq +
165
" actual " + other.cinq);
166
ret = false;
167
}
168
return ret;
169
}
170
171
/* called only before writing */
172
void init() {
173
quatre = "4444";
174
cinq = 5;
175
super.init();
176
}
177
}
178
179
class Thirdpsio extends Secondpsio {
180
private static final long serialVersionUID = 1L;
181
182
static String ign = "ignored";
183
transient Object oh;
184
185
int six;
186
187
private static int seven[];
188
protected byte eight = (byte)9;
189
static final byte dcare = (byte) 128;
190
private short nine = 8888;
191
long ten;
192
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
193
java.util.Enumeration<?> zero;
194
195
196
boolean equals(Thirdpsio other) {
197
boolean ret = super.equals(other);
198
199
if (six != other.six) {
200
System.err.println("\nthirdpsio six " + six +
201
" actual " + other.six);
202
ret = false;
203
}
204
if (eight != other.eight) {
205
System.err.println("\nthirdpsio eight - expected " + eight +
206
" actual " + other.eight);
207
ret = false;
208
}
209
if (nine != other.nine) {
210
System.err.println("\nthirdpsio nine - expected " + nine +
211
" actual " + other.nine);
212
ret = false;
213
}
214
if (ten != other.ten) {
215
System.err.println("\nthirdpsio ten - expected " + ten +
216
" actual " + other.ten);
217
ret = false;
218
}
219
if (zero != other.zero) {
220
System.err.println("\nthirdpsio zero - expected " + zero +
221
" actual " + other.zero);
222
ret = false;
223
}
224
return ret;
225
}
226
227
/* called only before writing */
228
void init() {
229
six = 666;
230
231
int s7[] = { 7, 7, 7 };
232
seven = s7;
233
eight = (byte)8;
234
nine = (short)9;
235
ten = (long)100000;
236
java.util.Enumeration<?> em = null; /* default */
237
238
super.init();
239
}
240
}
241
242