TestRunner.h 1.1 KB

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