Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKTESTCALLER_H
18 #define MITKTESTCALLER_H
19 
20 #include "cppunit/TestCase.h"
21 
22 #include <string>
23 #include <vector>
24 
25 extern std::vector<std::string> globalCmdLineArgs;
26 
27 namespace mitk
28 {
36  template <class ParameterizedFixture>
37  class TestCaller : public CppUnit::TestCase
38  {
39  typedef void (ParameterizedFixture::*TestMethod)();
40 
41  public:
48  TestCaller(const std::string &name, TestMethod test)
49  : TestCase(name), m_OwnFixture(true), m_Fixture(new ParameterizedFixture()), m_Test(test)
50  {
51  m_Fixture->m_Parameter = globalCmdLineArgs;
52  }
53 
63  TestCaller(const std::string &name, TestMethod test, ParameterizedFixture &fixture)
64  : TestCase(name), m_OwnFixture(false), m_Fixture(&fixture), m_Test(test)
65  {
66  m_Fixture->m_Parameter = globalCmdLineArgs;
67  }
68 
78  TestCaller(const std::string &name, TestMethod test, ParameterizedFixture *fixture)
79  : TestCase(name), m_OwnFixture(true), m_Fixture(fixture), m_Test(test)
80  {
81  m_Fixture->m_Parameter = globalCmdLineArgs;
82  }
83 
94  TestCaller(const std::string &name,
95  TestMethod test,
96  ParameterizedFixture *fixture,
97  const std::vector<std::string> &param)
98  : TestCase(name), m_OwnFixture(true), m_Fixture(fixture), m_Test(test)
99  {
100  m_Fixture->m_Parameter = param;
101  }
102 
104  {
105  if (m_OwnFixture)
106  delete m_Fixture;
107  }
108 
109  void runTest() override { (m_Fixture->*m_Test)(); }
110  void setUp() override { m_Fixture->setUp(); }
111  void tearDown() override { m_Fixture->tearDown(); }
112  std::string toString() const { return "TestCaller " + getName(); }
113  private:
114  TestCaller(const TestCaller &other);
115  TestCaller &operator=(const TestCaller &other);
116 
117  private:
118  bool m_OwnFixture;
119  ParameterizedFixture *m_Fixture;
120  TestMethod m_Test;
121  };
122 }
123 
124 #endif // MITKTESTCALLER_H
TestCaller(const std::string &name, TestMethod test)
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
Definition: testcase.h:32
std::string toString() const
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
A test caller for parameterized tests.
TestCaller(const std::string &name, TestMethod test, ParameterizedFixture &fixture)
std::vector< std::string > globalCmdLineArgs