Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/oldTests/CheckingEquality.java
38828 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @summary it is new version of old test which was25* /src/share/test/serialization/psiotest.java26* Test pickling and unpickling an object with derived classes27* and using a read special to serialize the "middle" class.28*29*/3031import java.io.*;3233public class CheckingEquality {34public static void main (String argv[]) {35System.err.println("\nRegression test of " +36"serialization/deserialization of " +37"complex objects\n");3839FileInputStream istream = null;40try {4142Thirdpsio objout = new Thirdpsio();43objout.init();4445FileOutputStream ostream = new FileOutputStream("psiotest1.tmp");46ObjectOutputStream p = new ObjectOutputStream(ostream);4748p.writeObject(objout);4950p.flush();51ostream.close();5253istream = new FileInputStream("psiotest1.tmp");54ObjectInputStream q = new ObjectInputStream(istream);5556Thirdpsio objin = (Thirdpsio)q.readObject();5758if (!objout.equals(objin)) {59System.err.println(60"\nTEST FAILED: Original and read objects not equal.");61throw new Error();62}63istream.close();64System.err.println("\nTEST PASSED");65} catch (Exception e) {66System.err.print("TEST FAILED: ");67e.printStackTrace();6869System.err.println("\nInput remaining");70int ch;71try {72while ((ch = istream.read()) != -1) {73System.out.print(Integer.toString(ch, 16) + " ");74}75System.err.println("\n");76} catch (Exception f) {77throw new Error();78}79throw new Error();80}81}82}8384class Firstpsio implements java.io.Serializable {85String one;86int two;87float three[];8889void init() { /* called only before writing */90one = "one";91two = 2;92three = new float[5];93float f = 3.0f;94for (int i=0; i<5 ; i++) {95f += 0.11;96three[i] = f;97}98}99100/* Compare two first objects */101boolean equals(Firstpsio other) {102boolean ret = true;103104if (!one.equals(other.one)) {105System.err.println("\nfirstpsio: expected " + one +106" actual " + other.one);107ret = false;108}109if (two != other.two) {110System.err.println("\nfirstpsio: expected " + two +111" actual " + other.two);112ret = false;113}114115for (int i = 0; i < three.length; i++ ) {116if (three[i] != other.three[i]) {117System.err.println("\nfirstpsio: three[" + i + "] expected " +118three[i] + " actual " + other.three[i]);119ret = false;120}121}122return ret;123}124}125126class Secondpsio extends Firstpsio {127String quatre;128int cinq;129130private void writeObject(ObjectOutputStream pw) throws IOException {131pw.writeObject(quatre);132pw.writeInt(cinq);133}134135private void readObject(ObjectInputStream pr)136throws StreamCorruptedException, IOException, ClassNotFoundException137{138if (one == null) {139System.err.println(140"\nTEST FAILED: Superclass not serialized when " +141"it should have been");142throw new StreamCorruptedException("Superclass not serialized " +143"when it should have been");144}145146quatre = (String)pr.readObject();147cinq = pr.readInt();148}149150boolean equals(Secondpsio other) {151boolean ret = super.equals(other);152153if (!quatre.equals(other.quatre)) {154System.err.println("\nsecondpsio: quatre expected " + quatre +155" actual " + other.quatre);156ret = false;157}158if (cinq != other.cinq) {159System.err.println("\nsecondpsio: cinq expected " + cinq +160" actual " + other.cinq);161ret = false;162}163return ret;164}165166/* called only before writing */167void init() {168quatre = "4444";169cinq = 5;170super.init();171}172}173174class Thirdpsio extends Secondpsio {175176static String ign = "ignored";177transient Object oh;178179int six;180181private static int seven[];182protected byte eight = (byte)9;183final static byte dcare = (byte) 128;184private short nine = 8888;185long ten;186java.util.Enumeration zero;187188189boolean equals(Thirdpsio other) {190boolean ret = super.equals(other);191192if (six != other.six) {193System.err.println("\nthirdpsio six " + six +194" actual " + other.six);195ret = false;196}197if (eight != other.eight) {198System.err.println("\nthirdpsio eight - expected " + eight +199" actual " + other.eight);200ret = false;201}202if (nine != other.nine) {203System.err.println("\nthirdpsio nine - expected " + nine +204" actual " + other.nine);205ret = false;206}207if (ten != other.ten) {208System.err.println("\nthirdpsio ten - expected " + ten +209" actual " + other.ten);210ret = false;211}212if (zero != other.zero) {213System.err.println("\nthirdpsio zero - expected " + zero +214" actual " + other.zero);215ret = false;216}217return ret;218}219220/* called only before writing */221void init() {222six = 666;223224int s7[] = { 7, 7, 7 };225seven = s7;226eight = (byte)8;227nine = (short)9;228ten = (long)100000;229java.util.Enumeration em = null; /* default */230231super.init();232}233}234235236