J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2006 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 a new version of an old test which was |
| 26 | * /src/share/test/serialization/piotest.java |
| 27 | * Test of serialization/deserialization |
| 28 | * of objects with fields of array type |
| 29 | * |
| 30 | * @build ArrayTest PrimitivesTest ArrayOpsTest |
| 31 | * @run main ArrayFields |
| 32 | */ |
| 33 | |
| 34 | import java.io.*; |
| 35 | |
| 36 | public class ArrayFields { |
| 37 | |
| 38 | public static void main (String argv[]) { |
| 39 | System.err.println("\nRegression test for testing of " + |
| 40 | "serialization/deserialization of objects with " + |
| 41 | "fields of array type\n"); |
| 42 | |
| 43 | try { |
| 44 | FileOutputStream ostream = new FileOutputStream("piotest4.tmp"); |
| 45 | ObjectOutputStream p = new ObjectOutputStream(ostream); |
| 46 | |
| 47 | ArrayTest array = new ArrayTest(); |
| 48 | p.writeObject(array); |
| 49 | p.flush(); |
| 50 | |
| 51 | FileInputStream istream = new FileInputStream("piotest4.tmp"); |
| 52 | ObjectInputStream q = new ObjectInputStream(istream); |
| 53 | |
| 54 | Object obj = null; |
| 55 | try { |
| 56 | obj = q.readObject(); |
| 57 | } catch (ClassCastException ee) { |
| 58 | System.err.println("\nTEST FAILED: An Exception occurred " + |
| 59 | ee.getMessage()); |
| 60 | System.err.println("\nBoolean array read as byte array" + |
| 61 | " could not be assigned to field z"); |
| 62 | throw new Error(); |
| 63 | } |
| 64 | |
| 65 | ArrayTest array_u = (ArrayTest)obj; |
| 66 | if (!array.equals(array_u)) { |
| 67 | System.out.println("\nTEST FAILED: Unpickling of objects " + |
| 68 | "with ArrayTest failed"); |
| 69 | throw new Error(); |
| 70 | } |
| 71 | System.err.println("\nTEST PASSED"); |
| 72 | } catch (Exception e) { |
| 73 | System.err.print("TEST FAILED: "); |
| 74 | e.printStackTrace(); |
| 75 | throw new Error(); |
| 76 | } |
| 77 | } |
| 78 | } |