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 {
00011 public:
00012     SignalTranslator();
00013     ~SignalTranslator();
00014 
00015     static sigjmp_buf* s_jumpTarget;
00016 
00017 private:
00018     sigjmp_buf m_currentJumpTarget;
00019     sigjmp_buf* m_oldJumpTarget;
00020 
00021     struct sigaction m_old_SIGFPE_action;
00022     struct sigaction m_old_SIGTRAP_action;
00023     struct sigaction m_old_SIGSEGV_action;
00024     struct sigaction m_old_SIGBUS_action;
00025     struct sigaction m_old_SIGABRT_action;
00026     struct sigaction m_old_SIGALRM_action;
00027 };
00028 
00029 #if !defined (__GNUC__)
00030     #define UNITTEST_EXTENSION
00031 #else
00032     #define UNITTEST_EXTENSION __extension__
00033 #endif
00034 
00035 #define UNITTEST_THROW_SIGNALS \
00036         UnitTest::SignalTranslator sig; \
00037         if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \
00038         throw ("Unhandled system exception"); 
00039 
00040 }
00041 
00042 #endif