Path: blob/master/test/jdk/java/io/Serializable/oldTests/CircularList.java
41153 views
/*1* Copyright (c) 2005, 2019, 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/piotest.java26* Test of serialization/deserialization of27* objects with CircularListType types28*/2930import java.io.*;3132public class CircularList {33public static void main (String argv[]) throws IOException {34System.err.println("\nRegression test for testing of " +35"serialization/deserialization of " +36"objects with CirculalListType types \n");3738FileInputStream istream = null;39FileOutputStream ostream = null;40try {41ostream = new FileOutputStream("piotest7.tmp");42ObjectOutputStream p = new ObjectOutputStream(ostream);4344CircularListTest.setup();45p.writeObject(CircularListTest.list);46p.flush();4748istream = new FileInputStream("piotest7.tmp");49ObjectInputStream q = new ObjectInputStream(istream);5051CircularListTest cv = (CircularListTest)q.readObject();52if (cv != cv.next) {53System.err.println("\nTEST FAILED: " +54"Circular List Test failed, next != self");55throw new Error();56}57System.err.println("\nTEST PASSED");58} catch (Exception e) {59System.err.print("TEST FAILED: ");60e.printStackTrace();61throw new Error();62} finally {63if (istream != null) istream.close();64if (ostream != null) ostream.close();65}66}67}6869class CircularListTest implements java.io.Serializable {70private static final long serialVersionUID = 1L;7172public CircularListTest next = null;73public static CircularListTest list = null;7475public static void setup() {76list = new CircularListTest();77list.next = list;78}79}808182