1 #ifndef UNITTEST_TESTRUNNER_H
2 #define UNITTEST_TESTRUNNER_H
3 
4 #include "Test.h"
5 #include "TestList.h"
6 #include "CurrentTest.h"
7 
8 namespace UnitTest {
9 
10 class TestReporter;
11 class TestResults;
12 class Timer;
13 
14 UNITTEST_LINKAGE int RunAllTests();
15 
16 struct True
17 {
operatorTrue18 	bool operator()(const Test* const) const
19 	{
20 		return true;
21 	}
22 };
23 
24 class UNITTEST_LINKAGE TestRunner
25 {
26 public:
27 	explicit TestRunner(TestReporter& reporter);
28 	~TestRunner();
29 
30 	template< class Predicate >
RunTestsIf(TestList const & list,char const * suiteName,const Predicate & predicate,int maxTestTimeInMs)31 	int RunTestsIf(TestList const& list, char const* suiteName,
32 				   const Predicate& predicate, int maxTestTimeInMs) const
33 	{
34 	    Test* curTest = list.GetHead();
35 
36 	    while (curTest != 0)
37 	    {
38 		    if (IsTestInSuite(curTest, suiteName) && predicate(curTest))
39 				RunTest(m_result, curTest, maxTestTimeInMs);
40 
41 			curTest = curTest->m_nextTest;
42 	    }
43 
44 	    return Finish();
45 	}
46 
47 	TestResults* GetTestResults();
48 
49 private:
50 	TestReporter* m_reporter;
51 	TestResults* m_result;
52 	Timer* m_timer;
53 
54 	int Finish() const;
55 	bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
56 	void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
57 };
58 
59 }
60 
61 #endif
62