G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SignalTranslator.h
1 #ifndef UNITTEST_SIGNALTRANSLATOR_H
2 #define UNITTEST_SIGNALTRANSLATOR_H
3 
4 #include <setjmp.h>
5 #include <signal.h>
6 
7 namespace UnitTest {
8 
9 class SignalTranslator
10 {
11 public:
12  SignalTranslator();
13  ~SignalTranslator();
14 
15  static sigjmp_buf* s_jumpTarget;
16 
17 private:
18  sigjmp_buf m_currentJumpTarget;
19  sigjmp_buf* m_oldJumpTarget;
20 
21  struct sigaction m_old_SIGFPE_action;
22  struct sigaction m_old_SIGTRAP_action;
23  struct sigaction m_old_SIGSEGV_action;
24  struct sigaction m_old_SIGBUS_action;
25  //struct sigaction m_old_SIGABRT_action; //G+Smo: not used
26  //struct sigaction m_old_SIGALRM_action; //G+Smo: not used
27 };
28 
29 #if !defined (__GNUC__)
30  #define UNITTEST_EXTENSION
31 #else
32  #define UNITTEST_EXTENSION __extension__
33 #endif
34 
35 #define UNITTEST_THROW_SIGNALS_POSIX_ONLY \
36  UnitTest::SignalTranslator sig; \
37  if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \
38  { throw ("Unhandled system exception"); }
39 
40 }
41 
42 #endif