1 // Tags: JDK1.2 |
|
2 |
|
3 // Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com> |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but 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 Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. |
|
21 |
|
22 package gnu.testlet.java.lang.Class; |
|
23 |
|
24 import gnu.testlet.TestHarness; |
|
25 import gnu.testlet.Testlet; |
|
26 |
|
27 import java.awt.Graphics2D; |
|
28 import java.awt.LayoutManager; |
|
29 import java.awt.Point; |
|
30 import java.awt.Rectangle; |
|
31 import java.awt.geom.Arc2D; |
|
32 import java.awt.geom.Line2D; |
|
33 import java.awt.geom.Rectangle2D; |
|
34 import java.awt.geom.RoundRectangle2D; |
|
35 import java.io.ByteArrayInputStream; |
|
36 import java.io.ByteArrayOutputStream; |
|
37 import java.io.Externalizable; |
|
38 import java.io.IOException; |
|
39 import java.io.ObjectInput; |
|
40 import java.io.ObjectInputStream; |
|
41 import java.io.ObjectOutput; |
|
42 import java.io.ObjectOutputStream; |
|
43 import java.io.ObjectStreamClass; |
|
44 import java.io.Serializable; |
|
45 import java.lang.reflect.Array; |
|
46 import java.text.DateFormat; |
|
47 import java.util.ArrayList; |
|
48 import java.util.Collection; |
|
49 import java.util.Vector; |
|
50 import java.util.Set; |
|
51 import java.util.SortedSet; |
|
52 |
|
53 import javax.swing.table.DefaultTableModel; |
|
54 |
|
55 /** |
|
56 * Some checks for serialization of a Class instance. |
|
57 */ |
|
58 public class serialization implements Testlet |
|
59 { |
|
60 |
|
61 /** |
|
62 * Runs the test using the specified harness. |
|
63 * |
|
64 * @param harness the test harness (<code>null</code> not permitted). |
|
65 */ |
|
66 public void test(TestHarness harness) |
|
67 { |
|
68 testClass(Cloneable.class, harness); |
|
69 testClass(Comparable.class, harness); |
|
70 testClass(Serializable.class, harness); |
|
71 testClass(Externalizable.class, harness); |
|
72 testClass(String.class, harness); |
|
73 testClass(Number.class, harness); |
|
74 testClass(Boolean.class, harness); |
|
75 testClass(Integer.class, harness); |
|
76 testClass(Float.class, harness); |
|
77 testClass(Double.class, harness); |
|
78 testClass(Vector.class, harness); |
|
79 testClass(ArrayList.class, harness); |
|
80 testClass(DateFormat.class, harness); |
|
81 testClass(Point.class, harness); |
|
82 testClass(Rectangle.class, harness); |
|
83 testClass(Rectangle2D.class, harness); |
|
84 testClass(Rectangle2D.Double.class, harness); |
|
85 testClass(Line2D.class, harness); |
|
86 testClass(Arc2D.class, harness); |
|
87 testClass(RoundRectangle2D.class, harness); |
|
88 testClass(Graphics2D.class, harness); |
|
89 testClass(DefaultTableModel.class, harness); |
|
90 testClass(LayoutManager.class, harness); |
|
91 testClass(Array.class, harness); |
|
92 testClass(Object.class, harness); |
|
93 testClass(Class.class, harness); |
|
94 testClass(Throwable.class, harness); |
|
95 testClass(IOException.class, harness); |
|
96 testClass(Void.class, harness); |
|
97 testClass(ObjectStreamClass.class, harness); |
|
98 testClass(Collection.class, harness); |
|
99 testClass(Set.class, harness); |
|
100 testClass(SortedSet.class, harness); |
|
101 |
|
102 testClass(boolean.class, harness); |
|
103 testClass(byte.class, harness); |
|
104 testClass(short.class, harness); |
|
105 testClass(char.class, harness); |
|
106 testClass(int.class, harness); |
|
107 testClass(long.class, harness); |
|
108 testClass(float.class, harness); |
|
109 testClass(double.class, harness); |
|
110 testClass(void.class, harness); |
|
111 } |
|
112 |
|
113 private void testClass(Class c1, TestHarness harness) |
|
114 { |
|
115 Class c2 = null; |
|
116 try { |
|
117 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
|
118 ObjectOutput out = new ObjectOutputStream(buffer); |
|
119 out.writeObject(c1); |
|
120 out.close(); |
|
121 |
|
122 ObjectInput in = new ObjectInputStream( |
|
123 new ByteArrayInputStream(buffer.toByteArray()) |
|
124 ); |
|
125 c2 = (Class) in.readObject(); |
|
126 in.close(); |
|
127 } |
|
128 catch (Exception e) { |
|
129 harness.debug(e); |
|
130 } |
|
131 harness.check(c1.equals(c2), c1.toString()); |
|
132 } |
|
133 |
|
134 } |
|