Medical Imaging Interaction Toolkit  2021.02.99-00f000b3
Medical Imaging Interaction Toolkit
mitkTestCaller.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef MITKTESTCALLER_H
14 #define MITKTESTCALLER_H
15 
16 #include "cppunit/TestCase.h"
17 
18 #include <string>
19 #include <vector>
20 
21 extern std::vector<std::string> globalCmdLineArgs;
22 
23 namespace mitk
24 {
32  template <class ParameterizedFixture>
33  class TestCaller : public CppUnit::TestCase
34  {
35  typedef void (ParameterizedFixture::*TestMethod)();
36 
37  public:
44  TestCaller(const std::string &name, TestMethod test)
45  : TestCase(name), m_OwnFixture(true), m_Fixture(new ParameterizedFixture()), m_Test(test)
46  {
47  m_Fixture->m_Parameter = globalCmdLineArgs;
48  }
49 
59  TestCaller(const std::string &name, TestMethod test, ParameterizedFixture &fixture)
60  : TestCase(name), m_OwnFixture(false), m_Fixture(&fixture), m_Test(test)
61  {
62  m_Fixture->m_Parameter = globalCmdLineArgs;
63  }
64 
74  TestCaller(const std::string &name, TestMethod test, ParameterizedFixture *fixture)
75  : TestCase(name), m_OwnFixture(true), m_Fixture(fixture), m_Test(test)
76  {
77  m_Fixture->m_Parameter = globalCmdLineArgs;
78  }
79 
90  TestCaller(const std::string &name,
91  TestMethod test,
92  ParameterizedFixture *fixture,
93  const std::vector<std::string> &param)
94  : TestCase(name), m_OwnFixture(true), m_Fixture(fixture), m_Test(test)
95  {
96  m_Fixture->m_Parameter = param;
97  }
98 
99  ~TestCaller() override
100  {
101  if (m_OwnFixture)
102  delete m_Fixture;
103  }
104 
105  void runTest() override { (m_Fixture->*m_Test)(); }
106  void setUp() override { m_Fixture->setUp(); }
107  void tearDown() override { m_Fixture->tearDown(); }
108  std::string toString() const { return "TestCaller " + getName(); }
109  private:
110  TestCaller(const TestCaller &other);
111  TestCaller &operator=(const TestCaller &other);
112 
113  private:
114  bool m_OwnFixture;
115  ParameterizedFixture *m_Fixture;
116  TestMethod m_Test;
117  };
118 }
119 
120 #endif // MITKTESTCALLER_H
TestCaller(const std::string &name, TestMethod test)
std::string toString() const
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
Definition: testcase.h:28
DataCollection - Class to facilitate loading/accessing structured data.
void tearDown() override
void runTest() override
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture *fixture, const std::vector< std::string > &param)
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture *fixture)
void setUp() override
~TestCaller() override
A test caller for parameterized tests.
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture &fixture)
std::vector< std::string > globalCmdLineArgs