File: TestRunner.h

package info (click to toggle)
etlcpp 20.40.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 18,548 kB
  • sloc: cpp: 257,359; ansic: 10,566; sh: 1,730; asm: 301; python: 281; makefile: 24
file content (61 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef UNITTEST_TESTRUNNER_H
#define UNITTEST_TESTRUNNER_H

#include "Test.h"
#include "TestList.h"
#include "CurrentTest.h"

namespace UnitTest {

   class TestReporter;
   class TestResults;
   class Timer;

   UNITTEST_LINKAGE int RunAllTests();

   struct True
   {
      bool operator()(const Test* const) const
      {
         return true;
      }
   };

   class UNITTEST_LINKAGE TestRunner
   {
   public:
      explicit TestRunner(TestReporter& reporter);
      ~TestRunner();

      template< class Predicate >
      int RunTestsIf(TestList const& list, char const* suiteName,
                     const Predicate& predicate, int maxTestTimeInMs) const
      {
         Test* curTest = list.GetHead();

         while (curTest != 0)
         {
            if (IsTestInSuite(curTest, suiteName) && predicate(curTest))
               RunTest(m_result, curTest, maxTestTimeInMs);

            curTest = curTest->m_nextTest;
         }

         return Finish();
      }

      TestResults* GetTestResults();

   private:
      TestReporter* m_reporter;
      TestResults* m_result;
      Timer* m_timer;

      int Finish() const;
      bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
      void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
   };

}

#endif