CircularList.java revision 0:37a05a11f281
1/*
2 * Copyright 2005 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any 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
31import java.io.*;
32
33public class CircularList {
34   public static void main (String argv[]) {
35       System.err.println("\nRegression test for testing of " +
36            "serialization/deserialization of " +
37            "objects with CirculalListType types \n");
38
39       try {
40           FileOutputStream ostream = new FileOutputStream("piotest7.tmp");
41           ObjectOutputStream p = new ObjectOutputStream(ostream);
42
43           CircularListTest.setup();
44           p.writeObject(CircularListTest.list);
45           p.flush();
46
47           FileInputStream istream = new FileInputStream("piotest7.tmp");
48           ObjectInputStream q = new ObjectInputStream(istream);
49
50           CircularListTest cv = (CircularListTest)q.readObject();
51           if (cv != cv.next) {
52               System.err.println("\nTEST FAILED: " +
53                    "Circular List Test failed, next != self");
54               throw new Error();
55           }
56           System.err.println("\nTEST PASSED");
57       } catch (Exception e) {
58           System.err.print("TEST FAILED: ");
59           e.printStackTrace();
60           throw new Error();
61        }
62    }
63}
64
65class CircularListTest implements java.io.Serializable {
66    public CircularListTest next = null;
67    public static CircularListTest list = null;
68
69    public static void setup() {
70        list = new CircularListTest();
71        list.next = list;
72    }
73}
74