1 /*
   2  * Copyright (c) 2005, 2010, 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/piotest.java
  27  *          Test of serialization/deserialization of
  28  *          objects with CircularListType types
  29  */
  30 
  31 import java.io.*;
  32 
  33 public class CircularList {
  34    public static void main (String argv[]) throws IOException {
  35        System.err.println("\nRegression test for testing of " +
  36             "serialization/deserialization of " +
  37             "objects with CirculalListType types \n");
  38 
  39        FileInputStream istream = null;
  40        FileOutputStream ostream = null;
  41        try {
  42            ostream = new FileOutputStream("piotest7.tmp");
  43            ObjectOutputStream p = new ObjectOutputStream(ostream);
  44 
  45            CircularListTest.setup();
  46            p.writeObject(CircularListTest.list);
  47            p.flush();
  48 
  49            istream = new FileInputStream("piotest7.tmp");
  50            ObjectInputStream q = new ObjectInputStream(istream);
  51 
  52            CircularListTest cv = (CircularListTest)q.readObject();
  53            if (cv != cv.next) {
  54                System.err.println("\nTEST FAILED: " +
  55                     "Circular List Test failed, next != self");
  56                throw new Error();
  57            }
  58            System.err.println("\nTEST PASSED");
  59        } catch (Exception e) {
  60            System.err.print("TEST FAILED: ");
  61            e.printStackTrace();
  62            throw new Error();
  63         } finally {
  64            if (istream != null) istream.close();
  65            if (ostream != null) ostream.close();
  66         }
  67     }
  68 }
  69 
  70 class CircularListTest implements java.io.Serializable {
  71     public CircularListTest next = null;
  72     public static CircularListTest list = null;
  73 
  74     public static void setup() {
  75         list = new CircularListTest();
  76         list.next = list;
  77     }
  78 }