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 {
00018         bool operator()(const Test* const) const
00019         {
00020                 return true;    
00021         }
00022 };
00023 
00024 class TestRunner
00025 {
00026 public:
00027         explicit TestRunner(TestReporter& reporter);
00028         ~TestRunner();
00029 
00030         template <class Predicate>
00031         int RunTestsIf(TestList const& list, char const* suiteName, 
00032                                    const Predicate& predicate, int maxTestTimeInMs) const
00033         {
00034             Test* curTest = list.GetHead();
00035 
00036             while (curTest != 0)
00037             {
00038                     if (IsTestInSuite(curTest, suiteName) && predicate(curTest))
00039                                 RunTest(m_result, curTest, maxTestTimeInMs);
00040 
00041                         curTest = curTest->next;
00042             }
00043 
00044             return Finish();
00045         }       
00046 
00047 private:
00048         TestReporter* m_reporter;
00049         TestResults* m_result;
00050         Timer* m_timer;
00051 
00052         int Finish() const;
00053         bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
00054         void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
00055 };
00056 
00057 }
00058 
00059 #endif