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