a8e5e6c69458425873f7ca6a556baab87198fd99
[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 // This recursion is done at the php side (report generation)
118
119 //      private int countSuiteExpectedTests(TestSuite suite) {
120 //              
121 //              int total = 0;
122 //              
123 //              total += suite.getNumTestCasesExpected();
124 //              
125 //              for(int i = 0; i < suite.getTestSuites().size(); i++) 
126 //                      total += countSuiteExpectedTests((TestSuite) suite.getTestSuites().elementAt(i));
127 //              
128 //              System.out.println("total: " + total);
129 //              
130 //              return total;
131 //      
132 //      }
133
134         public int getNumTestsOverall() {
135         
136                 int total = root.getNumTestCasesExpected();
137                 System.out.println("total: " + total);
138                 return total;
139                                 
140         }
141         
142         public int getNumTestsRun() {
143                 
144                 return tests.size();
145                 
146                         
147         }
148         
149         public int getNumFailures() {
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                         
162                         if(element.isFailure())
163                                 total++;
164                         
165                 }
166                         
167                 return total;
168         }
169         
170         public int getNumErrors() {
171
172                 int total = 0;
173                 
174 //              Iterator i = tests.keySet().iterator();
175 //              String key = "";
176 //              while (i.hasNext()) {
177 //                      
178 //                      
179 //                      key = (String) i.next();
180 //                      TestCase element = (TestCase) tests.get(key);
181 //                                              
182 //                      if(element.isError())
183 //                              total++;
184 //                      
185 //              }
186                         
187                 return total;
188         
189         }
190         
191         
192
193 }