G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExecuteTest.h
1 #ifndef UNITTEST_EXECUTE_TEST_H
2 #define UNITTEST_EXECUTE_TEST_H
3 
4 #include "Config.h"
5 #include "ExceptionMacros.h"
6 #include "TestDetails.h"
7 #include "TestResults.h"
8 #include "MemoryOutStream.h"
9 #include "AssertException.h"
10 #include "CurrentTest.h"
11 
12 #ifdef UNITTEST_NO_EXCEPTIONS
13  #include "ReportAssertImpl.h"
14 #endif
15 
16 #ifdef UNITTEST_POSIX
17  #include "Posix/SignalTranslator.h"
18 #endif
19 
20 namespace UnitTest {
21 
22 template< typename T >
23 void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest)
24 {
25  if (isMockTest == false)
26  CurrentTest::Details() = &details;
27 
28 #ifdef UNITTEST_NO_EXCEPTIONS
29  if (UNITTEST_SET_ASSERT_JUMP_TARGET() == 0)
30  {
31 #endif
32 #ifndef UNITTEST_POSIX
33  UT_TRY({ testObject.RunImpl(); })
34 #else
35  UT_TRY
36  ({
37  UNITTEST_THROW_SIGNALS_POSIX_ONLY
38  testObject.RunImpl();
39  })
40 #endif
41  UT_CATCH(AssertException, e, { (void)e; })
42  UT_CATCH(std::exception, e,
43  {
44  MemoryOutStream stream;
45  stream << "Unhandled exception: " << e.what();
46  CurrentTest::Results()->OnTestFailure(details, stream.GetText());
47  })
48  UT_CATCH_ALL
49  ({
50  CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed");
51  })
52 #ifdef UNITTEST_NO_EXCEPTIONS
53  }
54 #endif
55 }
56 
57 }
58 
59 #endif