00001 #ifndef UNITTEST_TESTRUNNER_H
00002 #define UNITTEST_TESTRUNNER_H
00003
00004 #include "Test.h"
00005 #include "TestList.h"
00006 #include "CurrentTest.h"
00007
00008 namespace UnitTest {
00009
00010 class TestReporter;
00011 class TestResults;
00012 class Timer;
00013
00014 int RunAllTests();
00015
00016 struct True {
00017 bool operator() ( const Test* const ) const {
00018 return true;
00019 }
00020 };
00021
00022 class TestRunner {
00023 public:
00024 explicit TestRunner ( TestReporter& reporter );
00025 ~TestRunner();
00026
00027 template <class Predicate>
00028 int RunTestsIf ( TestList const& list, char const* suiteName,
00029 const Predicate& predicate, int maxTestTimeInMs ) const {
00030 Test* curTest = list.GetHead();
00031
00032 while ( curTest != 0 ) {
00033 if ( IsTestInSuite ( curTest, suiteName ) && predicate ( curTest ) )
00034 RunTest ( m_result, curTest, maxTestTimeInMs );
00035
00036 curTest = curTest->next;
00037 }
00038
00039 return Finish();
00040 }
00041
00042 private:
00043 TestReporter* m_reporter;
00044 TestResults* m_result;
00045 Timer* m_timer;
00046
00047 int Finish() const;
00048 bool IsTestInSuite ( const Test* const curTest, char const* suiteName ) const;
00049 void RunTest ( TestResults* const result, Test* const curTest, int const maxTestTimeInMs ) const;
00050 };
00051
00052 }
00053
00054 #endif