008cb3d599bf3e4471a301aa250f59854af60fb3
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / testpool / TestPool.java
1 /*
2  * Created on Jul 31, 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */
7 package net.sourceforge.phpeclipse.phpunit.testpool;
8
9 import java.util.HashMap;
10 import java.util.Iterator;
11 import java.util.Vector;
12
13
14 /**
15  * @author Ali Echihabi
16  *
17  * To change the template for this generated type comment go to
18  * Window>Preferences>Java>Code Generation>Code and Comments
19  */
20 public class TestPool {
21
22         //private TestSuite currentParentTestSuite;
23         private HashMap tests;
24         private TestSuite root;
25         private TestSuite currentTestSuite;
26         
27         
28         /**
29          * 
30          */
31         public TestPool(String rootTitle) {
32                 
33                 tests = new HashMap();
34                 root = new TestSuite(rootTitle, "-1", 0);
35                 
36                 currentTestSuite = root;
37                 
38         }
39
40         /**
41          * @param test
42          */
43         public void addTest(TestCase test) {
44                 
45                 tests.put(test.getTestID(), test);
46                 
47                 currentTestSuite.addTestCase(test);
48                 
49                 
50                 //if we run all tests. then this is the end of this test suite.
51                 if( currentTestSuite != root && currentTestSuite.isFinished()) {
52                         
53                         currentTestSuite = currentTestSuite.getParent();
54
55                 }                               
56                 
57         } 
58
59         /**
60          * @param suite
61          * @param numTestsRunSinceStartOfTestSuite
62          */
63         public void addTestSuite(TestSuite suite) {
64         
65         //add as sibling
66                 currentTestSuite.addTestSuite(suite);
67                 suite.setParent(currentTestSuite);
68
69                 currentTestSuite = suite;
70         }
71
72         /**
73          * @return
74          */
75         public TestSuite getRoot() {
76                 
77                 return root;
78         }
79         
80         /**
81          * @param r
82          */
83         public void setRoot(TestSuite r) {
84                 this.root = r;
85         }
86
87
88         
89         /**
90          * @param testID
91          * @return
92          */
93         public TestCase getTest(String testID) {
94                                 
95                 return (TestCase) tests.get(testID);
96         }
97
98         public String toString() {
99                 
100                 String string = "";
101                 
102                 TestSuite node = root;
103                 
104                 string = root.toString();
105
106                 return string;                  
107         
108         }
109
110         private int countSuiteExpectedTests(TestSuite suite) {
111                 
112                 int total = 0;
113                 
114                 total += suite.getNumTestCasesExpected();
115                 
116                 for(int i = 0; i < suite.getTestSuites().size(); i++) 
117                         total += countSuiteExpectedTests((TestSuite) suite.getTestSuites().elementAt(i));
118                 
119                 return total;
120         
121         }
122
123         public int getNumTestsOverall() {
124         
125                 return countSuiteExpectedTests(root);
126                                 
127         }
128         
129         public int getNumTestsRun() {
130                 
131                 return tests.size();
132                 
133                         
134         }
135         
136         public int getNumFailures() {
137                 
138                 int total = 0;
139                 
140                 Iterator i = tests.keySet().iterator();
141                 String key = "";
142                 while (i.hasNext()) {
143                         
144                         
145                         key = (String) i.next();
146                         TestCase element = (TestCase) tests.get(key);
147                         
148                         
149                         if(element.isFailure())
150                                 total++;
151                         
152                 }
153                         
154                 return total;
155         }
156         
157         public int getNumErrors() {
158
159                 int total = 0;
160                 
161 //              Iterator i = tests.keySet().iterator();
162 //              String key = "";
163 //              while (i.hasNext()) {
164 //                      
165 //                      
166 //                      key = (String) i.next();
167 //                      TestCase element = (TestCase) tests.get(key);
168 //                                              
169 //                      if(element.isError())
170 //                              total++;
171 //                      
172 //              }
173                         
174                 return total;
175         
176         }
177         
178         
179
180 }