author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5809 | 6e38efd0293f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @summary it is new version of old test which was |
|
26 |
* /src/share/test/serialization/piotest.java |
|
27 |
* Test of serialization/deserialization of |
|
28 |
* objects with BinaryTree types |
|
29 |
*/ |
|
30 |
||
31 |
import java.io.*; |
|
32 |
||
33 |
public class BinaryTree { |
|
34 |
public static void main (String argv[]) { |
|
35 |
System.err.println("\nRegression test for testing of " + |
|
36 |
"serialization/deserialization of objects " + |
|
37 |
"with BinaryTree types \n"); |
|
38 |
||
39 |
try { |
|
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
40 |
BinaryTreeTest base = new BinaryTreeTest(2); |
2 | 41 |
FileOutputStream ostream = new FileOutputStream("piotest3.tmp"); |
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
42 |
try { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
43 |
ObjectOutputStream p = new ObjectOutputStream(ostream); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
44 |
p.writeObject(null); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
45 |
p.writeObject(base); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
46 |
p.flush(); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
47 |
} finally { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
48 |
ostream.close(); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
49 |
} |
2 | 50 |
|
51 |
FileInputStream istream = new FileInputStream("piotest3.tmp"); |
|
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
52 |
try { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
53 |
ObjectInputStream q = new ObjectInputStream(istream); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
54 |
Object n = q.readObject(); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
55 |
if (n != null) { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
56 |
System.err.println("\nnull read as " + n); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
57 |
} |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
58 |
BinaryTreeTest nbase = (BinaryTreeTest)q.readObject(); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
59 |
if (!base.equals(nbase)) { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
60 |
System.err.println("\nTEST FAILED: BinaryTree read " + |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
61 |
"incorrectly."); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
62 |
throw new Error(); |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
63 |
} |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
64 |
} finally { |
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
65 |
istream.close(); |
2 | 66 |
} |
5809
6e38efd0293f
6962045: TEST_BUG: Tests in test/java/io/Serializable leave files open
alanb
parents:
5506
diff
changeset
|
67 |
|
2 | 68 |
System.err.println("\nTEST PASSED"); |
69 |
} catch (Exception e) { |
|
70 |
System.err.print("TEST FAILED: "); |
|
71 |
e.printStackTrace(); |
|
72 |
throw new Error(); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
class BinaryTreeTest implements java.io.Serializable { |
|
78 |
public BinaryTreeTest left; |
|
79 |
public BinaryTreeTest right; |
|
80 |
public int id; |
|
81 |
public int level; |
|
82 |
||
83 |
private static int count = 0; |
|
84 |
||
85 |
public BinaryTreeTest(int l) { |
|
86 |
id = count++; |
|
87 |
level = l; |
|
88 |
if (l > 0) { |
|
89 |
left = new BinaryTreeTest(l-1); |
|
90 |
right = new BinaryTreeTest(l-1); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
public void print(int levels) { |
|
95 |
for (int i = 0; i < level; i++) { |
|
96 |
System.out.print(" "); |
|
97 |
} |
|
98 |
System.err.println("node " + id); |
|
99 |
||
100 |
if (level <= levels && left != null) { |
|
101 |
left.print(levels); |
|
102 |
} |
|
103 |
||
104 |
if (level <= levels && right != null) { |
|
105 |
right.print(levels); |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
public boolean equals(BinaryTreeTest other) { |
|
110 |
if (other == null) { |
|
111 |
return false; |
|
112 |
} |
|
113 |
||
114 |
if (id != other.id) { |
|
115 |
return false; |
|
116 |
} |
|
117 |
||
118 |
if (left != null && !left.equals(other.left)) { |
|
119 |
return false; |
|
120 |
} |
|
121 |
||
122 |
if (right != null && !right.equals(other.right)) { |
|
123 |
return false; |
|
124 |
} |
|
125 |
||
126 |
return true; |
|
127 |
} |
|
128 |
} |