Path: blob/master/test/jdk/java/io/Serializable/oldTests/ArrayFields.java
41153 views
/*1* Copyright (c) 2005, 2010, 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 a new version of an old test which was25* /src/share/test/serialization/piotest.java26* Test of serialization/deserialization27* of objects with fields of array type28*29* @build ArrayTest PrimitivesTest ArrayOpsTest30* @run main ArrayFields31*/3233import java.io.*;3435public class ArrayFields {3637public static void main (String argv[]) throws IOException {38System.err.println("\nRegression test for testing of " +39"serialization/deserialization of objects with " +40"fields of array type\n");4142FileOutputStream ostream = null;43FileInputStream istream = null;44try {45ostream = new FileOutputStream("piotest4.tmp");46ObjectOutputStream p = new ObjectOutputStream(ostream);4748ArrayTest array = new ArrayTest();49p.writeObject(array);50p.flush();5152istream = new FileInputStream("piotest4.tmp");53ObjectInputStream q = new ObjectInputStream(istream);5455Object obj = null;56try {57obj = q.readObject();58} catch (ClassCastException ee) {59System.err.println("\nTEST FAILED: An Exception occurred " +60ee.getMessage());61System.err.println("\nBoolean array read as byte array" +62" could not be assigned to field z");63throw new Error();64}6566ArrayTest array_u = (ArrayTest)obj;67if (!array.equals(array_u)) {68System.out.println("\nTEST FAILED: Unpickling of objects " +69"with ArrayTest failed");70throw new Error();71}72System.err.println("\nTEST PASSED");73} catch (Exception e) {74System.err.print("TEST FAILED: ");75e.printStackTrace();76throw new Error();77} finally {78if (istream != null) istream.close();79if (ostream != null) ostream.close();80}81}82}838485