KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
test_suite.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 //
13 
14 #pragma once
15 
16 // System includes
17 #include <vector>
18 
19 // External includes
20 
21 // Project includes
22 #include "testing/test_case.h"
24 
25 namespace Kratos::Testing {
26 namespace Internals {
28  public:
30  std::string const& TestName, std::string const& TestSuiteName) {
31  Tester::AddTestToTestSuite(TestName, TestSuiteName);
32  }
33 };
34 }
35 
38 
41 
43 
47 class KRATOS_API(KRATOS_CORE) TestSuite : public TestCase {
48  public:
51 
52  typedef std::vector<TestCase*> TestCasesContainerType;
53 
57 
59  TestSuite() = delete;
60 
62  TestSuite(TestSuite const& rOther) = delete;
63 
65  explicit TestSuite(std::string const& Name);
66 
68  virtual ~TestSuite();
69 
73 
75  TestSuite& operator=(TestSuite const& rOther) = delete;
76 
80 
81  void AddTestCase(TestCase* pTestCase);
82 
83  void Reset() override;
84 
85  void ResetResult() override;
86 
87  void Run() override;
88 
89  void Profile() override;
90 
91  void Enable() override;
92 
93  void Disable() override;
94 
95  void Select() override;
96 
97  void UnSelect() override;
98 
102 
106 
110 
112  virtual std::string Info() const override;
113 
115  virtual void PrintInfo(std::ostream& rOStream) const override;
116 
118  virtual void PrintData(std::ostream& rOStream) const override;
119 
121  private:
124 
125  TestCasesContainerType mTestCases;
126 
130 
131  void TestFunction() override;
132 
134 
135 }; // Class TestSuite
136 
138 
141 
143 inline std::istream& operator>>(std::istream& rIStream, TestSuite& rThis);
144 
146 inline std::ostream& operator<<(
147  std::ostream& rOStream, const TestSuite& rThis) {
148  rThis.PrintInfo(rOStream);
149  rOStream << std::endl;
150  rThis.PrintData(rOStream);
151 
152  return rOStream;
153 }
157 
158 #define KRATOS_TESTING_CONCATENATE(a, b) a##b
159 
160 #define KRATOS_TESTING_CREATE_DUMMY_VARIABLE_NAME(prefix, UniqueNumber) \
161  KRATOS_TESTING_CONCATENATE(prefix, UniqueNumber)
162 
163 #define KRATOS_TESTING_ADD_TEST_TO_TEST_SUITE(TestName, TestSuiteName) \
164  Kratos::Testing::Internals::AddThisTestToTestSuite \
165  KRATOS_TESTING_CREATE_DUMMY_VARIABLE_NAME(dummy, __LINE__)( \
166  TestName, TestSuiteName)
167 
168 #define KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, ParentName) \
169  class KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName) : public ParentName { \
170  KRATOS_TESTING_TEST_CASE_CLASS_BODY(TestCaseName, ParentName) \
171  static const Kratos::Testing::Internals::AddThisTestToTestSuite \
172  mAnotherDummy; \
173  };
174 
175 // This is the macro to use
176 #define KRATOS_TEST_CASE_IN_SUITE(TestCaseName, TestSuiteName) \
177  KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, TestCase) \
178  const Kratos::Testing::Internals::RegisterThisTest< \
179  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)> \
180  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mDummy; \
181  const Kratos::Testing::Internals::AddThisTestToTestSuite \
182  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mAnotherDummy = \
183  Kratos::Testing::Internals::AddThisTestToTestSuite( \
184  KRATOS_TESTING_CONVERT_TO_STRING(Test##TestCaseName), \
185  KRATOS_TESTING_CONVERT_TO_STRING(TestSuiteName)); \
186  \
187  void KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::TestFunction()
188 
189 // Disabled version of the macro to used
190 #define KRATOS_DISABLED_TEST_CASE_IN_SUITE(TestCaseName, TestSuiteName) \
191  KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, TestCase) \
192  const Kratos::Testing::Internals::RegisterThisTest< \
193  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)> \
194  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mDummy(true); \
195  const Kratos::Testing::Internals::AddThisTestToTestSuite \
196  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mAnotherDummy = \
197  Kratos::Testing::Internals::AddThisTestToTestSuite( \
198  KRATOS_TESTING_CONVERT_TO_STRING(Test##TestCaseName), \
199  KRATOS_TESTING_CONVERT_TO_STRING(TestSuiteName)); \
200  \
201  void KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::TestFunction()
202 
203 // Macro for MPI tests
204 #define KRATOS_DISTRIBUTED_TEST_CASE_IN_SUITE(TestCaseName, TestSuiteName) \
205  KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, DistributedTestCase) \
206  const Kratos::Testing::Internals::RegisterThisTest< \
207  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)> \
208  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mDummy; \
209  const Kratos::Testing::Internals::AddThisTestToTestSuite \
210  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mAnotherDummy = \
211  Kratos::Testing::Internals::AddThisTestToTestSuite( \
212  KRATOS_TESTING_CONVERT_TO_STRING(Test##TestCaseName), \
213  KRATOS_TESTING_CONVERT_TO_STRING(TestSuiteName)); \
214  \
215  void KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::TestFunction()
216 
217 // Disabled version of the MPI macro
218 #define KRATOS_DISABLED_DISTRIBUTED_TEST_CASE_IN_SUITE(TestCaseName, TestSuiteName) \
219  KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, DistributedTestCase) \
220  const Kratos::Testing::Internals::RegisterThisTest< \
221  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)> \
222  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mDummy(true); \
223  const Kratos::Testing::Internals::AddThisTestToTestSuite \
224  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mAnotherDummy = \
225  Kratos::Testing::Internals::AddThisTestToTestSuite( \
226  KRATOS_TESTING_CONVERT_TO_STRING(Test##TestCaseName), \
227  KRATOS_TESTING_CONVERT_TO_STRING(TestSuiteName)); \
228  \
229  void KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::TestFunction()
230 
231 #define KRATOS_TEST_CASE_WITH_FIXTURE_IN_SUITE( \
232  TestCaseName, TestFixtureName, TestSuiteName) \
233  KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, TestFixtureName) \
234  const Kratos::Testing::Internals::RegisterThisTest< \
235  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)> \
236  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mDummy; \
237  const Kratos::Testing::Internals::AddThisTestToTestSuite \
238  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mAnotherDummy = \
239  Kratos::Testing::Internals::AddThisTestToTestSuite( \
240  KRATOS_TESTING_CONVERT_TO_STRING(Test##TestCaseName), \
241  KRATOS_TESTING_CONVERT_TO_STRING(TestSuiteName)); \
242  \
243  void KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::TestFunction()
244 
245 #define KRATOS_DISABLED_TEST_CASE_WITH_FIXTURE_IN_SUITE( \
246  TestCaseName, TestFixtureName, TestSuiteName) \
247  KRATOS_TESTING_TEST_CASE_IN_SUITE_CLASS(TestCaseName, TestFixtureName) \
248  const Kratos::Testing::Internals::RegisterThisTest< \
249  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)> \
250  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mDummy(true); \
251  const Kratos::Testing::Internals::AddThisTestToTestSuite \
252  KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::mAnotherDummy = \
253  Kratos::Testing::Internals::AddThisTestToTestSuite( \
254  KRATOS_TESTING_CONVERT_TO_STRING(Test##TestCaseName), \
255  KRATOS_TESTING_CONVERT_TO_STRING(TestSuiteName)); \
256  \
257  void KRATOS_TESTING_CREATE_CLASS_NAME(TestCaseName)::TestFunction()
258 
260 
262 } // namespace Kratos::Testing
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
AddThisTestToTestSuite(std::string const &TestName, std::string const &TestSuiteName)
Definition: test_suite.h:29
The test case base class.
Definition: test_case.h:53
This class holds an array of test cases and run them one by one in its Run method.
Definition: test_suite.h:47
virtual void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: test_suite.cpp:82
TestSuite(TestSuite const &rOther)=delete
The TestSuite cannot be copied to avoid duplications.
TestSuite & operator=(TestSuite const &rOther)=delete
Preventing the assignment of the test suites.
virtual void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: test_suite.cpp:84
std::vector< TestCase * > TestCasesContainerType
Definition: test_suite.h:52
TestSuite()=delete
Default constructor is deleted becuase the Name should always passed to the constructor.
static void AddTestToTestSuite(std::string const &TestName, std::string const &TestSuiteName)
This method creates the suite if is no exist.
Definition: tester.cpp:180
std::istream & operator>>(std::istream &rIStream, TestSuite &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const TestCase &rThis)
output stream function
Definition: test_case.h:174
Definition: distributed_test_case.cpp:24
def Run()
Definition: convection_diffusion_benchmarks.py:9