Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/oldTests/ArraysOfArrays.java
38828 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 new version of old test which was under25* /src/share/test/serialization/piotest.java26* Test of serialization/deserialization of27* objects as arrays of arrays28*/2930import java.io.*;3132public class ArraysOfArrays {33public static void main (String argv[]) throws IOException {34System.err.println("\nRegression test for testing of " +35"serialization/deserialization of objects as " +36"arrays of arrays \n");3738FileInputStream istream = null;39FileOutputStream ostream = null;40try {41ostream = new FileOutputStream("piotest5.tmp");42ObjectOutputStream p = new ObjectOutputStream(ostream);4344byte b[][] = {{ 0, 1}, {2,3}};45p.writeObject((Object)b);4647short s[][] = {{ 0, 1, 2}, {3,4,5}};48p.writeObject((Object)s);4950char c[][] = {{ 0, 1, 2, 3}, {4, 5, 6, 7}};51p.writeObject((Object)c);5253int i[][] = {{ 0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}};54p.writeObject((Object)i);5556long l[][] = {{ 0, 1, 2, 3, 4, 5}, {6,7,8,9,10,11}};57p.writeObject((Object)l);5859boolean z[][] = new boolean[2][2];6061z[0][0] = true;62z[0][1] = false;63z[1] = z[0]; // Use first row same as second6465p.writeObject((Object)z);6667float f[][] = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f},68{ 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f}};69p.writeObject((Object)f);7071double d[][] = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d},72{ 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1d}};73p.writeObject((Object)d);7475Integer Int[][] = {{ new Integer(3), new Integer(2)},76{ new Integer(1), new Integer(0)}};77p.writeObject((Object)Int);7879p.flush();8081/* Now read them back and verify82*/83istream = new FileInputStream("piotest5.tmp");84ObjectInputStream q = new ObjectInputStream(istream);8586byte b_u[][] = (byte [][]) (q.readObject());87for (int ix = 0; ix < b_u.length; ix++) {88for(int iy = 0; iy < b_u[ix].length; iy++) {89if (b[ix][iy] != b_u[ix][iy]) {90System.err.println("\nByte array mismatch [" +91ix + "][" + iy + " expected " + b[ix][iy] +92" actual = " + b_u[ix][iy]);93throw new Error();94}95}96}979899short s_u[][] = (short [][])(q.readObject());100for (int ix = 0; ix < b_u.length; ix++) {101for(int iy = 0; iy < b_u[ix].length; iy++) {102if (b[ix][iy] != b_u[ix][iy]) {103System.err.println("\nshort array mismatch [" +104ix + "][" + iy + " expected " + b[ix][iy] +105" actual = " + b_u[ix][iy]);106throw new Error();107}108}109}110111char c_u[][] = (char [][])(q.readObject());112for (int ix = 0; ix < b_u.length; ix++) {113for(int iy = 0; iy < b_u[ix].length; iy++) {114if (b[ix][iy] != b_u[ix][iy]) {115System.err.println("\nchar array mismatch [" +116ix + "][" + iy + " expected " + b[ix][iy] +117" actual = " + b_u[ix][iy]);118throw new Error();119}120}121}122123int i_u[][] = (int [][])(q.readObject());124for (int ix = 0; ix < b_u.length; ix++) {125for(int iy = 0; iy < b_u[ix].length; iy++) {126if (b[ix][iy] != b_u[ix][iy]) {127System.err.println("\nint array mismatch [" +128ix + "][" + iy + " expected " + b[ix][iy] +129" actual = " + b_u[ix][iy]);130throw new Error();131}132}133}134135long l_u[][] = (long [][])(q.readObject());136for (int ix = 0; ix < b_u.length; ix++) {137for(int iy = 0; iy < b_u[ix].length; iy++) {138if (b[ix][iy] != b_u[ix][iy]) {139System.err.println("\nlong array mismatch [" +140ix + "][" + iy + " expected " + b[ix][iy] +141" actual = " + b_u[ix][iy]);142throw new Error();143}144}145}146147boolean z_u[][] = (boolean [][])(q.readObject());148for (int ix = 0; ix < b_u.length; ix++) {149for(int iy = 0; iy < b_u[ix].length; iy++) {150if (b[ix][iy] != b_u[ix][iy]) {151System.err.println("\nboolean array mismatch [" +152ix + "][" + iy + " expected " + b[ix][iy] +153" actual = " + b_u[ix][iy]);154throw new Error();155}156}157}158159float f_u[][] = (float [][])(q.readObject());160for (int ix = 0; ix < b_u.length; ix++) {161for(int iy = 0; iy < b_u[ix].length; iy++) {162if (b[ix][iy] != b_u[ix][iy]) {163System.err.println("\nfloat array mismatch [" +164ix + "][" + iy + " expected " + b[ix][iy] +165" actual = " + b_u[ix][iy]);166throw new Error();167}168}169}170171double d_u[][] = (double [][])(q.readObject());172for (int ix = 0; ix < b_u.length; ix++) {173for(int iy = 0; iy < b_u[ix].length; iy++) {174if (b[ix][iy] != b_u[ix][iy]) {175System.err.println("\ndouble array mismatch [" +176ix + "][" + iy + " expected " + b[ix][iy] +177" actual = " + b_u[ix][iy]);178throw new Error();179}180}181}182183Integer Int_u[][] = (Integer [][])(q.readObject());184for (int ix = 0; ix < b_u.length; ix++) {185for(int iy = 0; iy < b_u[ix].length; iy++) {186if (b[ix][iy] != b_u[ix][iy]) {187System.err.println("\nInteger array mismatch [" +188ix + "][" + iy + " expected " + b[ix][iy] +189" actual = " + b_u[ix][iy]);190throw new Error();191}192}193}194System.err.println("\nTEST PASSED");195} catch (Exception e) {196System.err.print("TEST FAILED: ");197e.printStackTrace();198199System.err.println("\nInput remaining");200int ch;201try {202while ((ch = istream.read()) != -1) {203System.err.print("\n " +Integer.toString(ch, 16) + " ");204}205System.err.println("\n ");206} catch (Exception f) {207throw new Error();208}209throw new Error();210} finally {211if (istream != null) istream.close();212if (ostream != null) ostream.close();213}214}215}216217218