--- /dev/null
+/*
+ * Created on Jul 31, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit.testpool;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TestPool {
+
+ //private TestSuite currentParentTestSuite;
+ private HashMap tests;
+ private TestSuite root;
+ private TestSuite currentTestSuite;
+
+
+ /**
+ *
+ */
+ public TestPool(String rootTitle) {
+
+ tests = new HashMap();
+ root = new TestSuite(rootTitle, "-1", 0);
+
+ currentTestSuite = root;
+
+ }
+
+ /**
+ * @param test
+ */
+ public void addTest(TestCase test) {
+
+ tests.put(test.getTestID(), test);
+
+ currentTestSuite.addTestCase(test);
+
+
+ //if we run all tests. then this is the end of this test suite.
+ if( currentTestSuite != root && currentTestSuite.isFinished()) {
+
+ currentTestSuite = currentTestSuite.getParent();
+
+ }
+
+ }
+
+ /**
+ * @param suite
+ * @param numTestsRunSinceStartOfTestSuite
+ */
+ public void addTestSuite(TestSuite suite) {
+
+ //add as sibling
+ currentTestSuite.addTestSuite(suite);
+ suite.setParent(currentTestSuite);
+
+ currentTestSuite = suite;
+ }
+
+ /**
+ * @return
+ */
+ public TestSuite getRoot() {
+
+ return root;
+ }
+
+ /**
+ * @param r
+ */
+ public void setRoot(TestSuite r) {
+ this.root = r;
+ }
+
+
+
+ /**
+ * @param testID
+ * @return
+ */
+ public TestCase getTest(String testID) {
+
+ return (TestCase) tests.get(testID);
+ }
+
+ public String toString() {
+
+ String string = "";
+
+ TestSuite node = root;
+
+ string = root.toString();
+
+ return string;
+
+ }
+
+ private int countSuiteExpectedTests(TestSuite suite) {
+
+ int total = 0;
+
+ total += suite.getNumTestCasesExpected();
+
+ for(int i = 0; i < suite.getTestSuites().size(); i++)
+ total += countSuiteExpectedTests((TestSuite) suite.getTestSuites().elementAt(i));
+
+ return total;
+
+ }
+
+ public int getNumTestsOverall() {
+
+ return countSuiteExpectedTests(root);
+
+ }
+
+ public int getNumTestsRun() {
+
+ return tests.size();
+
+
+ }
+
+ public int getNumFailures() {
+
+ int total = 0;
+
+ Iterator i = tests.keySet().iterator();
+ String key = "";
+ while (i.hasNext()) {
+
+
+ key = (String) i.next();
+ TestCase element = (TestCase) tests.get(key);
+
+
+ if(element.isFailure())
+ total++;
+
+ }
+
+ return total;
+ }
+
+ public int getNumErrors() {
+
+ int total = 0;
+
+// Iterator i = tests.keySet().iterator();
+// String key = "";
+// while (i.hasNext()) {
+//
+//
+// key = (String) i.next();
+// TestCase element = (TestCase) tests.get(key);
+//
+// if(element.isError())
+// total++;
+//
+// }
+
+ return total;
+
+ }
+
+
+
+}