1 // Tags: JDK1.2 |
|
2 |
|
3 /* VectorSerialization.java -- Tests the serialization of Vector. |
|
4 |
|
5 Copyright (c) 1999 by Free Software Foundation, Inc. |
|
6 Written by Guilhem Lavaux <guilhem@kaffe.org>. |
|
7 |
|
8 This program is free software; you can redistribute it and/or modify |
|
9 it under the terms of the GNU General Public License as published |
|
10 by the Free Software Foundation, version 2. (see COPYING) |
|
11 |
|
12 This program is distributed in the hope that it will be useful, but |
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 GNU General Public License for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with this program; if not, write to the Free Software Foundation |
|
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA */ |
|
20 |
|
21 package gnu.testlet.java.util.Vector; |
|
22 |
|
23 import gnu.testlet.TestHarness; |
|
24 import gnu.testlet.Testlet; |
|
25 import java.util.Vector; |
|
26 import java.io.FileOutputStream; |
|
27 import java.io.InputStream; |
|
28 import java.io.ObjectOutputStream; |
|
29 import java.io.ObjectInputStream; |
|
30 import java.io.IOException; |
|
31 |
|
32 public class VectorSerialization implements Testlet |
|
33 { |
|
34 public static void main(String args[]) throws IOException |
|
35 { |
|
36 FileOutputStream os = new FileOutputStream("TestVector.ser"); |
|
37 ObjectOutputStream oo = new ObjectOutputStream(os); |
|
38 Vector v; |
|
39 |
|
40 v = new Vector(); |
|
41 v.add(new Integer(10)); |
|
42 oo.writeObject(v); |
|
43 |
|
44 v = new Vector(); |
|
45 v.add(new Integer(20)); |
|
46 oo.writeObject(v); |
|
47 |
|
48 os.close(); |
|
49 } |
|
50 |
|
51 public void test(TestHarness harness) |
|
52 { |
|
53 try |
|
54 { |
|
55 String packageName = getClass().getPackage().getName().replace('.','#'); |
|
56 InputStream is = harness.getResourceStream(packageName + "#TestVector.ser"); |
|
57 ObjectInputStream oi = new ObjectInputStream(is); |
|
58 Vector v; |
|
59 |
|
60 v = (Vector) oi.readObject(); |
|
61 harness.check(v != null, "returned object null ?"); |
|
62 harness.check(v.size(), 1); |
|
63 harness.check(v.get(0), new Integer(10)); |
|
64 v = (Vector) oi.readObject(); |
|
65 harness.check(v != null, "returned object null ?"); |
|
66 harness.check(v.size(), 1); |
|
67 harness.check(v.get(0), new Integer(20)); |
|
68 } |
|
69 catch (Exception e) |
|
70 { |
|
71 harness.fail("Caught an unexpected exception"); |
|
72 harness.debug(e); |
|
73 } |
|
74 } |
|
75 } |
|