test/jdk/java/io/Serializable/oldTests/ArraysOfArrays.java
changeset 58565 baa5969ecf34
parent 47216 71c04702a3d5
equal deleted inserted replaced
58564:218a1a642c6f 58565:baa5969ecf34
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    40         FileOutputStream ostream = null;
    40         FileOutputStream ostream = null;
    41         try {
    41         try {
    42             ostream = new FileOutputStream("piotest5.tmp");
    42             ostream = new FileOutputStream("piotest5.tmp");
    43             ObjectOutputStream p = new ObjectOutputStream(ostream);
    43             ObjectOutputStream p = new ObjectOutputStream(ostream);
    44 
    44 
    45             byte b[][] = {{ 0, 1}, {2,3}};
    45             byte[][] b = {{ 0, 1}, {2,3}};
    46             p.writeObject((Object)b);
    46             p.writeObject(b);
    47 
    47 
    48             short s[][] = {{ 0, 1, 2}, {3,4,5}};
    48             short[][] s = {{ 0, 1, 2}, {3,4,5}};
    49             p.writeObject((Object)s);
    49             p.writeObject(s);
    50 
    50 
    51             char c[][] = {{ 0, 1, 2, 3}, {4, 5, 6, 7}};
    51             char[][] c = {{ 0, 1, 2, 3}, {4, 5, 6, 7}};
    52             p.writeObject((Object)c);
    52             p.writeObject(c);
    53 
    53 
    54             int i[][] = {{ 0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}};
    54             int[][] i = {{ 0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}};
    55             p.writeObject((Object)i);
    55             p.writeObject(i);
    56 
    56 
    57             long l[][] = {{ 0, 1, 2, 3, 4, 5}, {6,7,8,9,10,11}};
    57             long[][] l = {{ 0, 1, 2, 3, 4, 5}, {6,7,8,9,10,11}};
    58             p.writeObject((Object)l);
    58             p.writeObject((Object)l);
    59 
    59 
    60             boolean z[][] = new boolean[2][2];
    60             boolean[][] z = new boolean[2][2];
    61 
    61 
    62             z[0][0] = true;
    62             z[0][0] = true;
    63             z[0][1] = false;
    63             z[0][1] = false;
    64             z[1] = z[0];        // Use first row same as second
    64             z[1] = z[0];        // Use first row same as second
    65 
    65 
    66             p.writeObject((Object)z);
    66             p.writeObject(z);
    67 
    67 
    68             float f[][] = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f},
    68             float[][] f = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f},
    69                 { 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f}};
    69                 { 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f}};
    70             p.writeObject((Object)f);
    70             p.writeObject(f);
    71 
    71 
    72             double d[][] = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d},
    72             double[][] d = {{ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0d},
    73                 { 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1d}};
    73                 { 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1d}};
    74             p.writeObject((Object)d);
    74             p.writeObject(d);
    75 
    75 
    76             Integer Int[][] = {{ new Integer(3), new Integer(2)},
    76             Integer Int[][] = {{ 3, 2},
    77                 { new Integer(1), new Integer(0)}};
    77                                { 1, 0}};
    78             p.writeObject((Object)Int);
    78             p.writeObject(Int);
    79 
    79 
    80             p.flush();
    80             p.flush();
    81 
    81 
    82             /* Now read them back and verify
    82             /* Now read them back and verify
    83              */
    83              */
    84             istream = new FileInputStream("piotest5.tmp");
    84             istream = new FileInputStream("piotest5.tmp");
    85             ObjectInputStream q = new ObjectInputStream(istream);
    85             ObjectInputStream q = new ObjectInputStream(istream);
    86 
    86 
    87             byte b_u[][] = (byte [][]) (q.readObject());
    87             byte[][] b_u = (byte [][]) (q.readObject());
    88             for (int ix = 0; ix < b_u.length; ix++) {
    88             for (int ix = 0; ix < b_u.length; ix++) {
    89                 for(int iy = 0; iy < b_u[ix].length; iy++) {
    89                 for(int iy = 0; iy < b_u[ix].length; iy++) {
    90                     if (b[ix][iy] != b_u[ix][iy]) {
    90                     if (b[ix][iy] != b_u[ix][iy]) {
    91                         System.err.println("\nByte array mismatch [" +
    91                         System.err.println("\nByte array mismatch [" +
    92                             ix + "][" + iy + " expected " + b[ix][iy] +
    92                             ix + "][" + iy + "] expected " + b[ix][iy] +
    93                             " actual = " + b_u[ix][iy]);
    93                             " actual = " + b_u[ix][iy]);
    94                         throw new Error();
    94                         throw new Error();
    95                     }
    95                     }
    96                 }
    96                 }
    97             }
    97             }
    98 
    98 
    99 
    99 
   100             short s_u[][] = (short [][])(q.readObject());
   100             short[][] s_u = (short [][])(q.readObject());
   101             for (int ix = 0; ix < b_u.length; ix++) {
   101             for (int ix = 0; ix < s_u.length; ix++) {
   102                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   102                 for(int iy = 0; iy < s_u[ix].length; iy++) {
   103                     if (b[ix][iy] != b_u[ix][iy]) {
   103                     if (s[ix][iy] != s_u[ix][iy]) {
   104                         System.err.println("\nshort array mismatch [" +
   104                         System.err.println("\nshort array mismatch [" +
   105                             ix + "][" + iy + " expected " + b[ix][iy] +
   105                             ix + "][" + iy + "] expected " + s[ix][iy] +
   106                             " actual = " + b_u[ix][iy]);
   106                             " actual = " + s_u[ix][iy]);
   107                         throw new Error();
   107                         throw new Error();
   108                     }
   108                     }
   109                 }
   109                 }
   110             }
   110             }
   111 
   111 
   112             char c_u[][] = (char [][])(q.readObject());
   112             char[][] c_u = (char [][])(q.readObject());
   113             for (int ix = 0; ix < b_u.length; ix++) {
   113             for (int ix = 0; ix < c_u.length; ix++) {
   114                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   114                 for(int iy = 0; iy < c_u[ix].length; iy++) {
   115                     if (b[ix][iy] != b_u[ix][iy]) {
   115                     if (c[ix][iy] != c_u[ix][iy]) {
   116                         System.err.println("\nchar array mismatch [" +
   116                         System.err.println("\nchar array mismatch [" +
   117                             ix + "][" + iy + " expected " + b[ix][iy] +
   117                             ix + "][" + iy + "] expected " + c[ix][iy] +
   118                             " actual = " + b_u[ix][iy]);
   118                             " actual = " + c_u[ix][iy]);
   119                         throw new Error();
   119                         throw new Error();
   120                     }
   120                     }
   121                 }
   121                 }
   122             }
   122             }
   123 
   123 
   124             int i_u[][] = (int [][])(q.readObject());
   124             int[][] i_u = (int [][])(q.readObject());
   125             for (int ix = 0; ix < b_u.length; ix++) {
   125             for (int ix = 0; ix < i_u.length; ix++) {
   126                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   126                 for(int iy = 0; iy < i_u[ix].length; iy++) {
   127                     if (b[ix][iy] != b_u[ix][iy]) {
   127                     if (i[ix][iy] != i_u[ix][iy]) {
   128                         System.err.println("\nint array mismatch [" +
   128                         System.err.println("\nint array mismatch [" +
   129                             ix + "][" + iy + " expected " + b[ix][iy] +
   129                             ix + "][" + iy + "] expected " + i[ix][iy] +
   130                             " actual = " + b_u[ix][iy]);
   130                             " actual = " + i_u[ix][iy]);
   131                         throw new Error();
   131                         throw new Error();
   132                     }
   132                     }
   133                 }
   133                 }
   134             }
   134             }
   135 
   135 
   136             long l_u[][] = (long [][])(q.readObject());
   136             long[][] l_u = (long [][])(q.readObject());
   137             for (int ix = 0; ix < b_u.length; ix++) {
   137             for (int ix = 0; ix < l_u.length; ix++) {
   138                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   138                 for(int iy = 0; iy < l_u[ix].length; iy++) {
   139                     if (b[ix][iy] != b_u[ix][iy]) {
   139                     if (l[ix][iy] != l_u[ix][iy]) {
   140                         System.err.println("\nlong array mismatch [" +
   140                         System.err.println("\nlong array mismatch [" +
   141                             ix + "][" + iy + " expected " + b[ix][iy] +
   141                             ix + "][" + iy + "] expected " + l[ix][iy] +
   142                             " actual = " + b_u[ix][iy]);
   142                             " actual = " + l_u[ix][iy]);
   143                         throw new Error();
   143                         throw new Error();
   144                     }
   144                     }
   145                 }
   145                 }
   146             }
   146             }
   147 
   147 
   148             boolean z_u[][] = (boolean [][])(q.readObject());
   148             boolean[][] z_u = (boolean [][])(q.readObject());
   149             for (int ix = 0; ix < b_u.length; ix++) {
   149             for (int ix = 0; ix < z_u.length; ix++) {
   150                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   150                 for(int iy = 0; iy < z_u[ix].length; iy++) {
   151                     if (b[ix][iy] != b_u[ix][iy]) {
   151                     if (z[ix][iy] != z_u[ix][iy]) {
   152                         System.err.println("\nboolean array mismatch [" +
   152                         System.err.println("\nboolean array mismatch [" +
   153                             ix + "][" + iy + " expected " + b[ix][iy] +
   153                             ix + "][" + iy + "] expected " + z[ix][iy] +
   154                             " actual = " + b_u[ix][iy]);
   154                             " actual = " + z_u[ix][iy]);
   155                         throw new Error();
   155                         throw new Error();
   156                     }
   156                     }
   157                 }
   157                 }
   158             }
   158             }
   159 
   159 
   160             float f_u[][] = (float [][])(q.readObject());
   160             float[][] f_u = (float [][])(q.readObject());
   161             for (int ix = 0; ix < b_u.length; ix++) {
   161             for (int ix = 0; ix < f_u.length; ix++) {
   162                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   162                 for(int iy = 0; iy < f_u[ix].length; iy++) {
   163                     if (b[ix][iy] != b_u[ix][iy]) {
   163                     if (f[ix][iy] != f_u[ix][iy]) {
   164                         System.err.println("\nfloat array mismatch [" +
   164                         System.err.println("\nfloat array mismatch [" +
   165                             ix + "][" + iy + " expected " + b[ix][iy] +
   165                             ix + "][" + iy + "] expected " + f[ix][iy] +
   166                             " actual = " + b_u[ix][iy]);
   166                             " actual = " + f_u[ix][iy]);
   167                         throw new Error();
   167                         throw new Error();
   168                     }
   168                     }
   169                 }
   169                 }
   170             }
   170             }
   171 
   171 
   172             double d_u[][] = (double [][])(q.readObject());
   172             double[][] d_u = (double [][])(q.readObject());
   173             for (int ix = 0; ix < b_u.length; ix++) {
   173             for (int ix = 0; ix < d_u.length; ix++) {
   174                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   174                 for(int iy = 0; iy < d_u[ix].length; iy++) {
   175                     if (b[ix][iy] != b_u[ix][iy]) {
   175                     if (d[ix][iy] != d_u[ix][iy]) {
   176                         System.err.println("\ndouble array mismatch [" +
   176                         System.err.println("\ndouble array mismatch [" +
   177                             ix + "][" + iy + " expected " + b[ix][iy] +
   177                             ix + "][" + iy + "] expected " + d[ix][iy] +
   178                             " actual = " + b_u[ix][iy]);
   178                             " actual = " + d_u[ix][iy]);
   179                         throw new Error();
   179                         throw new Error();
   180                     }
   180                     }
   181                 }
   181                 }
   182             }
   182             }
   183 
   183 
   184             Integer Int_u[][] = (Integer [][])(q.readObject());
   184             Integer[][] Int_u = (Integer [][])(q.readObject());
   185             for (int ix = 0; ix < b_u.length; ix++) {
   185             for (int ix = 0; ix < Int_u.length; ix++) {
   186                 for(int iy = 0; iy < b_u[ix].length; iy++) {
   186                 for(int iy = 0; iy < Int_u[ix].length; iy++) {
   187                     if (b[ix][iy] != b_u[ix][iy]) {
   187                     if (!Int[ix][iy].equals(Int_u[ix][iy])) {
   188                         System.err.println("\nInteger array mismatch [" +
   188                         System.err.println("\nInteger array mismatch [" +
   189                             ix + "][" + iy + " expected " + b[ix][iy] +
   189                             ix + "][" + iy + "] expected " + Int[ix][iy] +
   190                             " actual = " + b_u[ix][iy]);
   190                             " actual = " + Int_u[ix][iy]);
   191                         throw new Error();
   191                         throw new Error();
   192                     }
   192                     }
   193                 }
   193                 }
   194             }
   194             }
   195             System.err.println("\nTEST PASSED");
   195             System.err.println("\nTEST PASSED");