4e631ee865b00efbe17408ea17f3b0fb92719b60
[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 = null;            
35                 currentTestSuite = root;
36                 
37         }
38
39         /**
40          * @param test
41          */
42         public void addTest(TestCase test) {
43                 
44                 tests.put(test.getTestID(), test);
45                 
46                 currentTestSuite.addTestCase(test);
47                 
48                 
49                 //if we run all tests. then this is the end of this test suite.
50                 if( currentTestSuite != root && currentTestSuite.isFinished()) {
51                         
52                         currentTestSuite = currentTestSuite.getParent();
53
54                 }                               
55                 
56         } 
57
58         /**
59          * @param suite
60          * @param numTestsRunSinceStartOfTestSuite
61          */
62         public void addTestSuite(TestSuite suite) {
63         
64         
65         if(root == null) {
66                 root = suite;
67         } 
68         else {
69         
70                 //add as sibling        
71                         currentTestSuite.addTestSuite(suite);
72                         suite.setParent(currentTestSuite);
73
74         }       
75         
76                 currentTestSuite = suite;       
77         }
78
79         /**
80          * @return
81          */
82         public TestSuite getRoot() {
83                 
84                 return root;
85         }
86         
87         /**
88          * @param r
89          */
90         public void setRoot(TestSuite r) {
91                 this.root = r;
92         }
93
94
95         
96         /**
97          * @param testID
98          * @return
99          */
100         public TestCase getTest(String testID) {
101                                 
102                 return (TestCase) tests.get(testID);
103         }
104
105         public String toString() {
106                 
107                 String string = "";
108                 
109                 TestSuite node = root;
110                 
111                 string = root.toString();
112
113                 return string;                  
114         
115         }
116
117
118         public int getNumTestsOverall() {
119         
120                 int total = root.getNumTestCasesExpected();
121                 System.out.println("total: " + total);
122                 return total;
123                                 
124         }
125         
126         public int getNumTestsRun() {
127                 
128                 return tests.size();
129                 
130                         
131         }
132         
133         public int getNumFailures() {
134                 
135                 int total = 0;
136                 
137 //              Iterator i = tests.keySet().iterator();
138 //              String key = "";
139 //              while (i.hasNext()) {
140 //                      
141 //                      
142 //                      key = (String) i.next();
143 //                      TestCase element = (TestCase) tests.get(key);
144 //                      
145 //                      
146 //                      if(element.isFailure())
147 //                              total++;
148 //                      
149 //              }
150                         
151                 return total;
152         }
153         
154         public int getNumErrors() {
155
156                 int total = 0;
157                 
158 //              Iterator i = tests.keySet().iterator();
159 //              String key = "";
160 //              while (i.hasNext()) {
161 //                      
162 //                      
163 //                      key = (String) i.next();
164 //                      TestCase element = (TestCase) tests.get(key);
165 //                                              
166 //                      if(element.isError())
167 //                              total++;
168 //                      
169 //              }
170                         
171                 return total;
172         
173         }
174         
175         
176
177 }