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 of |
| 28 | * objects with Arrays types |
| 29 | * |
| 30 | * @build ArrayOpsTest PrimitivesTest |
| 31 | * @run main SimpleArrays |
| 32 | */ |
| 33 | |
| 34 | import java.io.*; |
| 35 | |
| 36 | |
| 37 | public class SimpleArrays { |
| 38 | public static void main (String argv[]) { |
| 39 | System.err.println("\nRegression test for testing of " + |
| 40 | "serialization/deserialization of objects with Arrays types\n"); |
| 41 | |
| 42 | FileInputStream istream = null; |
| 43 | try { |
| 44 | FileOutputStream ostream = new FileOutputStream("piotest2.tmp"); |
| 45 | ObjectOutputStream p = new ObjectOutputStream(ostream); |
| 46 | |
| 47 | byte b[] = { 0, 1}; |
| 48 | p.writeObject((Object)b); |
| 49 | |
| 50 | short s[] = { 0, 1, 2}; |
| 51 | p.writeObject((Object)s); |
| 52 | |
| 53 | char c[] = { 'A', 'B', 'C', 'D'}; |
| 54 | p.writeObject((Object)c); |
| 55 | |
| 56 | int i[] = { 0, 1, 2, 3, 4}; |
| 57 | p.writeObject((Object)i); |
| 58 | |
| 59 | long l[] = { 0, 1, 2, 3, 4, 5}; |
| 60 | p.writeObject((Object)l); |
| 61 | |
| 62 | boolean z[] = new boolean[4]; |
| 63 | z[0] = true; |
| 64 | z[1] = false; |
| 65 | z[2] = true; |
| 66 | z[3] = false; |
| 67 | p.writeObject(z); |
| 68 | |
| 69 | float f[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; |
| 70 | p.writeObject((Object)f); |
| 71 | |
| 72 | double d[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d}; |
| 73 | p.writeObject((Object)d); |
| 74 | |
| 75 | String string[] = { "A", "B", "C", "D"}; |
| 76 | p.writeObject((Object) string); |
| 77 | |
| 78 | PrimitivesTest prim[] = new PrimitivesTest[5]; |
| 79 | prim[0] = new PrimitivesTest(); |
| 80 | prim[1] = prim[0]; |
| 81 | prim[2] = new PrimitivesTest(); |
| 82 | prim[3] = prim[2]; |
| 83 | prim[4] = null; |
| 84 | p.writeObject((Object)prim); |
| 85 | |
| 86 | p.flush(); |
| 87 | |
| 88 | /* now read them back */ |
| 89 | istream = new FileInputStream("piotest2.tmp"); |
| 90 | ObjectInputStream q = new ObjectInputStream(istream); |
| 91 | |
| 92 | Object obj; |
| 93 | |
| 94 | byte b_u[] = (byte[])q.readObject(); |
| 95 | short s_u[] = (short[])q.readObject(); |
| 96 | char c_u[] = (char[])q.readObject(); |
| 97 | int i_u[] = (int[])q.readObject(); |
| 98 | long l_u[] = (long[])q.readObject(); |
| 99 | |
| 100 | /* This should be boolean, but they were serialized as bytes |
| 101 | */ |
| 102 | boolean z_u[] = null; |
| 103 | Object z_obj = null; |
| 104 | try { |
| 105 | z_obj = q.readObject(); |
| 106 | z_u = (boolean[])z_obj; |
| 107 | } catch (ClassCastException e) { |
| 108 | System.err.println("\nClassCastException " + e.getMessage()); |
| 109 | System.err.println("\nBoolean array read as " + |
| 110 | z_obj.getClass().getName()); |
| 111 | System.err.println("\nAn Exception occurred. " + |
| 112 | e.getMessage()); |
| 113 | z_u = z; |
| 114 | throw new Error(); |
| 115 | } |
| 116 | |
| 117 | float f_u[] = (float[])q.readObject(); |
| 118 | double d_u[] = (double[])q.readObject(); |
| 119 | String string_u[] = (String[])q.readObject(); |
| 120 | |
| 121 | PrimitivesTest prim_u[] = (PrimitivesTest[])q.readObject(); |
| 122 | |
| 123 | if (!ArrayOpsTest.verify(i, i_u)) { |
| 124 | System.err.println("\nUnpickling of int array failed"); |
| 125 | throw new Error(); |
| 126 | } |
| 127 | if (!ArrayOpsTest.verify(b, b_u)) { |
| 128 | System.err.println("\nUnpickling of byte array failed"); |
| 129 | throw new Error(); |
| 130 | } |
| 131 | if (!ArrayOpsTest.verify(s, s_u)) { |
| 132 | System.err.println("\nUnpickling of short array failed"); |
| 133 | throw new Error(); |
| 134 | } |
| 135 | if (!ArrayOpsTest.verify(c, c_u)) { |
| 136 | System.err.println("\nUnpickling of char array failed"); |
| 137 | throw new Error(); |
| 138 | } |
| 139 | if (!ArrayOpsTest.verify(l, l_u)) { |
| 140 | System.err.println("\nUnpickling of long array failed"); |
| 141 | throw new Error(); |
| 142 | } |
| 143 | if (!ArrayOpsTest.verify(f, f_u)) { |
| 144 | System.err.println("\nUnpickling of float array failed"); |
| 145 | throw new Error(); |
| 146 | } |
| 147 | if (!ArrayOpsTest.verify(d, d_u)) { |
| 148 | System.err.println("\nUnpickling of double array failed"); |
| 149 | throw new Error(); |
| 150 | } |
| 151 | if (!ArrayOpsTest.verify(z, z_u)) { |
| 152 | System.err.println("\nUnpickling of boolean array failed"); |
| 153 | throw new Error(); |
| 154 | } |
| 155 | if (!ArrayOpsTest.verify(string, string_u)) { |
| 156 | System.err.println("\nUnpickling of String array failed"); |
| 157 | throw new Error(); |
| 158 | } |
| 159 | if (!ArrayOpsTest.verify(prim, prim_u)) { |
| 160 | System.err.println("\nUnpickling of PrimitivesTest array " + |
| 161 | "failed"); |
| 162 | throw new Error(); |
| 163 | } |
| 164 | System.err.println("\nTEST PASSED"); |
| 165 | } catch (Exception e) { |
| 166 | System.err.print("TEST FAILED: "); |
| 167 | e.printStackTrace(); |
| 168 | |
| 169 | System.err.println("\nInput remaining"); |
| 170 | int ch; |
| 171 | try { |
| 172 | while ((ch = istream.read()) != -1) { |
| 173 | System.err.print("\n " + Integer.toString(ch, 16) + " "); |
| 174 | } |
| 175 | System.err.println("\n "); |
| 176 | } catch (Exception f) { |
| 177 | throw new Error(); |
| 178 | } |
| 179 | throw new Error(); |
| 180 | } |
| 181 | } |
| 182 | } |