Medical Imaging Interaction Toolkit  2024.06.00
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
mitk::TestCaller::TestCaller
TestCaller(const std::string &name, TestMethod test)
Definition: mitkTestCaller.h:44
mitk::TestCaller::TestCaller
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture *fixture, const std::vector< std::string > &param)
Definition: mitkTestCaller.h:90
mitk::TestCaller::runTest
void runTest() override
Definition: mitkTestCaller.h:105
mitk::TestCaller::TestCaller
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture *fixture)
Definition: mitkTestCaller.h:74
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::TestCaller::TestCaller
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture &fixture)
Definition: mitkTestCaller.h:59
mitk::TestCaller::setUp
void setUp() override
Definition: mitkTestCaller.h:106
mitk::TestCaller::tearDown
void tearDown() override
Definition: mitkTestCaller.h:107
mitk::TestCaller
A test caller for parameterized tests.
Definition: mitkTestCaller.h:33
mitk::TestCaller::~TestCaller
~TestCaller() override
Definition: mitkTestCaller.h:99
mitk::TestCaller::toString
std::string toString() const
Definition: mitkTestCaller.h:108
globalCmdLineArgs
std::vector< std::string > globalCmdLineArgs