jdk/test/java/io/Serializable/oldTests/CheckingEquality.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 5506 202f599c92aa
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @summary it is new version of old test which was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *          /src/share/test/serialization/psiotest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *          Test pickling and unpickling an object with derived classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          and using a read special to serialize the "middle" class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class CheckingEquality {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    public static void main (String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        System.err.println("\nRegression test of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                           "serialization/deserialization of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
                           "complex objects\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        FileInputStream istream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            Thirdpsio objout = new Thirdpsio();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            objout.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            FileOutputStream ostream = new FileOutputStream("psiotest1.tmp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            ObjectOutputStream p = new ObjectOutputStream(ostream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            p.writeObject(objout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            p.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            ostream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            istream = new FileInputStream("psiotest1.tmp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            ObjectInputStream q = new ObjectInputStream(istream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            Thirdpsio objin = (Thirdpsio)q.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            if (!objout.equals(objin)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                    "\nTEST FAILED: Original and read objects not equal.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                throw new Error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            istream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            System.err.println("\nTEST PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            System.err.print("TEST FAILED: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            System.err.println("\nInput remaining");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            int ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                while ((ch = istream.read()) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    System.out.print(Integer.toString(ch, 16) + " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                System.err.println("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            } catch (Exception f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                throw new Error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            throw new Error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
class Firstpsio implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    String one;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    int two;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    float three[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    void init() { /* called only before writing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        one = "one";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        two = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        three = new float[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        float f = 3.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        for (int i=0; i<5 ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            f += 0.11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            three[i] = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /* Compare two first objects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    boolean equals(Firstpsio other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        boolean ret = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (!one.equals(other.one)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            System.err.println("\nfirstpsio: expected " + one +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                " actual " + other.one);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (two != other.two) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            System.err.println("\nfirstpsio: expected " + two +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                " actual " + other.two);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        for (int i = 0; i < three.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (three[i] != other.three[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                System.err.println("\nfirstpsio: three[" + i + "] expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    three[i] + " actual " + other.three[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
class Secondpsio extends Firstpsio  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    String quatre;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    int cinq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private void writeObject(ObjectOutputStream pw) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        pw.writeObject(quatre);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        pw.writeInt(cinq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private void readObject(ObjectInputStream pr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        throws StreamCorruptedException, IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (one == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.err.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                "\nTEST FAILED: Superclass not serialized when " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                "it should have been");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new StreamCorruptedException("Superclass not serialized " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                               "when it should have been");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        quatre = (String)pr.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        cinq = pr.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    boolean equals(Secondpsio other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        boolean ret = super.equals(other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (!quatre.equals(other.quatre)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            System.err.println("\nsecondpsio: quatre expected " + quatre +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                " actual " + other.quatre);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (cinq != other.cinq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            System.err.println("\nsecondpsio: cinq expected " + cinq +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                " actual " + other.cinq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /* called only before writing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        quatre = "4444";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        cinq = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        super.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
class Thirdpsio extends Secondpsio {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    static String ign = "ignored";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    transient Object oh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    int six;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private static int seven[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected byte eight = (byte)9;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 5506
diff changeset
   184
    static final byte dcare = (byte) 128;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private short nine = 8888;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    long ten;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    java.util.Enumeration zero;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    boolean equals(Thirdpsio other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        boolean ret = super.equals(other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (six != other.six) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            System.err.println("\nthirdpsio six " + six +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                " actual " + other.six);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (eight != other.eight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            System.err.println("\nthirdpsio eight - expected " + eight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                " actual " + other.eight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (nine != other.nine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            System.err.println("\nthirdpsio nine - expected " + nine +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
               " actual " + other.nine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (ten != other.ten) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            System.err.println("\nthirdpsio ten - expected " + ten +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                " actual " + other.ten);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (zero != other.zero) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.err.println("\nthirdpsio zero - expected " + zero +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                " actual " + other.zero);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            ret = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /* called only before writing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        six = 666;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        int s7[] = { 7, 7, 7 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        seven = s7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        eight = (byte)8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        nine = (short)9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        ten = (long)100000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        java.util.Enumeration em = null; /* default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        super.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}