00001 #ifndef UNITTEST_SIGNALTRANSLATOR_H 00002 #define UNITTEST_SIGNALTRANSLATOR_H 00003 00004 #include <setjmp.h> 00005 #include <signal.h> 00006 00007 namespace UnitTest { 00008 00009 class SignalTranslator { 00010 public: 00011 SignalTranslator(); 00012 ~SignalTranslator(); 00013 00014 static sigjmp_buf* s_jumpTarget; 00015 00016 private: 00017 sigjmp_buf m_currentJumpTarget; 00018 sigjmp_buf* m_oldJumpTarget; 00019 00020 struct sigaction m_old_SIGFPE_action; 00021 struct sigaction m_old_SIGTRAP_action; 00022 struct sigaction m_old_SIGSEGV_action; 00023 struct sigaction m_old_SIGBUS_action; 00024 struct sigaction m_old_SIGABRT_action; 00025 struct sigaction m_old_SIGALRM_action; 00026 }; 00027 00028 #if !defined (__GNUC__) 00029 #define UNITTEST_EXTENSION 00030 #else 00031 #define UNITTEST_EXTENSION __extension__ 00032 #endif 00033 00034 #define UNITTEST_THROW_SIGNALS \ 00035 UnitTest::SignalTranslator sig; \ 00036 if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ 00037 throw ("Unhandled system exception"); 00038 00039 } 00040 00041 #endif