1 // Tags: not-a-test |
|
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.io.ObjectInputStream; |
|
23 |
|
24 import gnu.testlet.TestHarness; |
|
25 import gnu.testlet.Testlet; |
|
26 |
|
27 import java.io.ByteArrayInputStream; |
|
28 import java.io.ByteArrayOutputStream; |
|
29 import java.io.IOException; |
|
30 import java.io.ObjectInput; |
|
31 import java.io.ObjectInputStream; |
|
32 import java.io.ObjectInputValidation; |
|
33 import java.io.ObjectOutput; |
|
34 import java.io.ObjectOutputStream; |
|
35 import java.io.Serializable; |
|
36 import java.util.ArrayList; |
|
37 |
|
38 class TestObjectInputValidation implements ObjectInputValidation, Serializable { |
|
39 ArrayList validated; |
|
40 private String name; |
|
41 private int priority; |
|
42 TestObjectInputValidation object; |
|
43 |
|
44 public TestObjectInputValidation(String name) |
|
45 { |
|
46 this.name = name; |
|
47 this.priority = 10; |
|
48 this.object = this; |
|
49 } |
|
50 |
|
51 // Registers with priority for given object. |
|
52 public TestObjectInputValidation(int priority, |
|
53 TestObjectInputValidation object) |
|
54 { |
|
55 this.priority = priority; |
|
56 this.object = object; |
|
57 } |
|
58 |
|
59 public void validateObject() |
|
60 { |
|
61 if (object.validated == null) |
|
62 object.validated = new ArrayList(); |
|
63 object.validated.add(new Integer(priority)); |
|
64 } |
|
65 |
|
66 private void writeObject(ObjectOutputStream stream) throws IOException |
|
67 { |
|
68 stream.defaultWriteObject(); |
|
69 } |
|
70 |
|
71 private void readObject(ObjectInputStream stream) |
|
72 throws IOException, ClassNotFoundException |
|
73 { |
|
74 stream.registerValidation(this, 10); |
|
75 stream.registerValidation(new TestObjectInputValidation(-10, this), -10); |
|
76 stream.defaultReadObject(); |
|
77 stream.registerValidation(this, 12); // Again with other priority |
|
78 stream.registerValidation(new TestObjectInputValidation(-12, this), -12); |
|
79 stream.registerValidation(new TestObjectInputValidation(11, this), 11); |
|
80 } |
|
81 |
|
82 // Ignores validated list and object. |
|
83 public boolean equals(Object o) |
|
84 { |
|
85 if (o instanceof TestObjectInputValidation) |
|
86 { |
|
87 TestObjectInputValidation other = (TestObjectInputValidation) o; |
|
88 return this.name.equals(other.name) |
|
89 && this.priority == other.priority; |
|
90 } |
|
91 return false; |
|
92 } |
|
93 } |
|