301b9fdb2ddbcd4b8e5bcf0e9e9750f1c2bad6d3
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / testpool / TestSuite.java
1 /*************************************************************************
2  * @author Ali Echihabi (ali_echihabi@ieee.org, ali.echihabi@souss.ca)
3  *
4  * Plugin for PHP unit Testing.
5  * www.phpeclipse.de
6  * 
7  *************************************************************************/
8
9 package net.sourceforge.phpeclipse.phpunit.testpool;
10
11 import java.util.Vector;
12
13 public class TestSuite {
14
15         private boolean hasFailure;
16
17         private boolean isAllPass;
18
19         private boolean hasError;
20
21         private Vector testCases; // current or actual.
22
23         private Vector testSuites; // current or actual.
24
25         private String name;
26
27         private String id;
28
29         private int numTestCasesExpected; // expected
30
31         private int numTestCasesRunSoFar;
32
33         TestSuite parent;
34
35         /**
36          * @param name
37          * @param testID
38          * @param testCount
39          */
40         public TestSuite(TestSuite parent, String name, String testID, int testCount) {
41
42                 this.parent = parent;
43                 this.id = testID;
44                 this.name = name;
45                 this.numTestCasesExpected = testCount;
46
47                 testCases = new Vector();
48                 testSuites = new Vector();
49
50                 hasError = false;
51                 isAllPass = true;
52                 hasFailure = false;
53         }
54
55         public void addTestCase(TestCase test) {
56                 testCases.addElement(test);
57                 test.setParentSuite(this);
58                 numTestCasesRunSoFar++;
59         }
60
61         public void removeTestCase(TestCase test) {
62         }
63
64         public boolean contains(TestCase test) {
65
66                 return false;
67
68         }
69
70         public String toString() {
71
72                 String string = "";
73
74                 // print test cases.
75                 TestCase tc = null;
76                 for (int i = 0; i < testCases.size(); i++) {
77
78                         tc = (TestCase) testCases.elementAt(i);
79                         string += "  - " + tc.getTestID() + ", " + tc.getTestName() + "\n";
80
81                 }
82
83                 for (int i = 0; i < testSuites.size(); i++)
84                         string += ((TestSuite) testSuites.elementAt(i)).toString();
85
86                 // print its own test suites.
87                 return string;
88         }
89
90         /**
91          * @return
92          */
93         public String getId() {
94                 return id;
95         }
96
97         /**
98          * @return
99          */
100         public String getName() {
101                 return name;
102         }
103
104         /**
105          * @return
106          */
107         public int getNumTestCasesExpected() {
108                 return numTestCasesExpected;
109         }
110
111         /**
112          * @param string
113          */
114         public void setId(String string) {
115                 id = string;
116         }
117
118         /**
119          * @param string
120          */
121         public void setName(String string) {
122                 name = string;
123         }
124
125         /**
126          * @param i
127          */
128         public void setNumTestCasesExpected(int i) {
129                 numTestCasesExpected = i;
130         }
131
132         /**
133          * @param suite
134          */
135         public void addTestSuite(TestSuite suite) {
136                 testSuites.addElement(suite);
137
138         }
139
140         /**
141          * @return
142          */
143         public boolean isFinished() {
144
145                 return numTestCasesRunSoFar >= numTestCasesExpected;
146
147         }
148
149         /**
150          * @return
151          */
152         public TestSuite getParent() {
153                 return parent;
154         }
155
156         /**
157          * @param suite
158          */
159         public void setParent(TestSuite suite) {
160                 parent = suite;
161         }
162
163         /**
164          * @return
165          */
166         public int getNumTestCases() {
167
168                 return testCases.size();
169         }
170
171         /**
172          * @return
173          */
174         public Vector getTestCases() {
175                 return testCases;
176         }
177
178         /**
179          * @return
180          */
181         public Vector getTestSuites() {
182                 return testSuites;
183         }
184
185         /**
186          * @param vector
187          */
188         public void setTestCases(Vector vector) {
189                 testCases = vector;
190         }
191
192         /**
193          * @param vector
194          */
195         public void setTestSuites(Vector vector) {
196                 testSuites = vector;
197         }
198
199         /**
200          * @return
201          */
202         public boolean hasError() {
203
204                 return hasError;
205
206         }
207
208         public void setHasError() {
209
210                 if (hasError)
211                         return;
212
213                 hasError = true;
214
215                 if (parent != null)
216                         parent.setHasError();
217         }
218
219         /**
220          * @return
221          */
222         public boolean hasFailure() {
223
224                 return hasFailure;
225
226         }
227
228         public void setHasFailure() {
229
230                 if (hasFailure)
231                         return;
232
233                 hasFailure = true;
234
235                 if (parent != null)
236                         parent.setHasFailure();
237         }
238
239         public boolean isAllPass() {
240
241                 return !hasError() && !hasFailure();
242
243         }
244 }