0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @summary it is new version of old test which was
0N/A * /src/share/test/serialization/psiotest.java
0N/A * Test pickling and unpickling an object with derived classes
0N/A * and using a read special to serialize the "middle" class.
0N/A *
0N/A */
0N/A
0N/Aimport java.io.*;
0N/A
0N/Apublic class CheckingEquality {
0N/A public static void main (String argv[]) {
0N/A System.err.println("\nRegression test of " +
0N/A "serialization/deserialization of " +
0N/A "complex objects\n");
0N/A
0N/A FileInputStream istream = null;
0N/A try {
0N/A
0N/A Thirdpsio objout = new Thirdpsio();
0N/A objout.init();
0N/A
0N/A FileOutputStream ostream = new FileOutputStream("psiotest1.tmp");
0N/A ObjectOutputStream p = new ObjectOutputStream(ostream);
0N/A
0N/A p.writeObject(objout);
0N/A
0N/A p.flush();
0N/A ostream.close();
0N/A
0N/A istream = new FileInputStream("psiotest1.tmp");
0N/A ObjectInputStream q = new ObjectInputStream(istream);
0N/A
0N/A Thirdpsio objin = (Thirdpsio)q.readObject();
0N/A
0N/A if (!objout.equals(objin)) {
0N/A System.err.println(
0N/A "\nTEST FAILED: Original and read objects not equal.");
0N/A throw new Error();
0N/A }
0N/A istream.close();
0N/A System.err.println("\nTEST PASSED");
0N/A } catch (Exception e) {
0N/A System.err.print("TEST FAILED: ");
0N/A e.printStackTrace();
0N/A
0N/A System.err.println("\nInput remaining");
0N/A int ch;
0N/A try {
0N/A while ((ch = istream.read()) != -1) {
0N/A System.out.print(Integer.toString(ch, 16) + " ");
0N/A }
0N/A System.err.println("\n");
0N/A } catch (Exception f) {
0N/A throw new Error();
0N/A }
0N/A throw new Error();
0N/A }
0N/A }
0N/A}
0N/A
0N/Aclass Firstpsio implements java.io.Serializable {
0N/A String one;
0N/A int two;
0N/A float three[];
0N/A
0N/A void init() { /* called only before writing */
0N/A one = "one";
0N/A two = 2;
0N/A three = new float[5];
0N/A float f = 3.0f;
0N/A for (int i=0; i<5 ; i++) {
0N/A f += 0.11;
0N/A three[i] = f;
0N/A }
0N/A }
0N/A
0N/A /* Compare two first objects */
0N/A boolean equals(Firstpsio other) {
0N/A boolean ret = true;
0N/A
0N/A if (!one.equals(other.one)) {
0N/A System.err.println("\nfirstpsio: expected " + one +
0N/A " actual " + other.one);
0N/A ret = false;
0N/A }
0N/A if (two != other.two) {
0N/A System.err.println("\nfirstpsio: expected " + two +
0N/A " actual " + other.two);
0N/A ret = false;
0N/A }
0N/A
0N/A for (int i = 0; i < three.length; i++ ) {
0N/A if (three[i] != other.three[i]) {
0N/A System.err.println("\nfirstpsio: three[" + i + "] expected " +
0N/A three[i] + " actual " + other.three[i]);
0N/A ret = false;
0N/A }
0N/A }
0N/A return ret;
0N/A }
0N/A}
0N/A
0N/Aclass Secondpsio extends Firstpsio {
0N/A String quatre;
0N/A int cinq;
0N/A
0N/A private void writeObject(ObjectOutputStream pw) throws IOException {
0N/A pw.writeObject(quatre);
0N/A pw.writeInt(cinq);
0N/A }
0N/A
0N/A private void readObject(ObjectInputStream pr)
0N/A throws StreamCorruptedException, IOException, ClassNotFoundException
0N/A {
0N/A if (one == null) {
0N/A System.err.println(
0N/A "\nTEST FAILED: Superclass not serialized when " +
0N/A "it should have been");
0N/A throw new StreamCorruptedException("Superclass not serialized " +
0N/A "when it should have been");
0N/A }
0N/A
0N/A quatre = (String)pr.readObject();
0N/A cinq = pr.readInt();
0N/A }
0N/A
0N/A boolean equals(Secondpsio other) {
0N/A boolean ret = super.equals(other);
0N/A
0N/A if (!quatre.equals(other.quatre)) {
0N/A System.err.println("\nsecondpsio: quatre expected " + quatre +
0N/A " actual " + other.quatre);
0N/A ret = false;
0N/A }
0N/A if (cinq != other.cinq) {
0N/A System.err.println("\nsecondpsio: cinq expected " + cinq +
0N/A " actual " + other.cinq);
0N/A ret = false;
0N/A }
0N/A return ret;
0N/A }
0N/A
0N/A /* called only before writing */
0N/A void init() {
0N/A quatre = "4444";
0N/A cinq = 5;
0N/A super.init();
0N/A }
0N/A}
0N/A
0N/Aclass Thirdpsio extends Secondpsio {
0N/A
0N/A static String ign = "ignored";
0N/A transient Object oh;
0N/A
0N/A int six;
0N/A
0N/A private static int seven[];
0N/A protected byte eight = (byte)9;
0N/A final static byte dcare = (byte) 128;
0N/A private short nine = 8888;
0N/A long ten;
0N/A java.util.Enumeration zero;
0N/A
0N/A
0N/A boolean equals(Thirdpsio other) {
0N/A boolean ret = super.equals(other);
0N/A
0N/A if (six != other.six) {
0N/A System.err.println("\nthirdpsio six " + six +
0N/A " actual " + other.six);
0N/A ret = false;
0N/A }
0N/A if (eight != other.eight) {
0N/A System.err.println("\nthirdpsio eight - expected " + eight +
0N/A " actual " + other.eight);
0N/A ret = false;
0N/A }
0N/A if (nine != other.nine) {
0N/A System.err.println("\nthirdpsio nine - expected " + nine +
0N/A " actual " + other.nine);
0N/A ret = false;
0N/A }
0N/A if (ten != other.ten) {
0N/A System.err.println("\nthirdpsio ten - expected " + ten +
0N/A " actual " + other.ten);
0N/A ret = false;
0N/A }
0N/A if (zero != other.zero) {
0N/A System.err.println("\nthirdpsio zero - expected " + zero +
0N/A " actual " + other.zero);
0N/A ret = false;
0N/A }
0N/A return ret;
0N/A }
0N/A
0N/A /* called only before writing */
0N/A void init() {
0N/A six = 666;
0N/A
0N/A int s7[] = { 7, 7, 7 };
0N/A seven = s7;
0N/A eight = (byte)8;
0N/A nine = (short)9;
0N/A ten = (long)100000;
0N/A java.util.Enumeration em = null; /* default */
0N/A
0N/A super.init();
0N/A }
0N/A}