Skip to content

Instantly share code, notes, and snippets.

@astoeckel
Last active October 12, 2016 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astoeckel/8ad4268004dafa67083049fc08f0ee92 to your computer and use it in GitHub Desktop.
Save astoeckel/8ad4268004dafa67083049fc08f0ee92 to your computer and use it in GitHub Desktop.
Google Test EXPECT_SIGNAL macro
#include <setjmp.h>
#include <signal.h>
#include <gtest/gtest.h>
static sigjmp_buf jmp_expect_signal;
static void handler(int) { siglongjmp(jmp_expect_signal, 1); }
#define EXPECT_SIGNAL(CODE, SIGNO) \
{ \
sighandler_t old_handler = signal(SIGNO, handler); \
bool triggered = sigsetjmp(jmp_expect_signal, true); \
if (!triggered) { \
CODE; \
} \
EXPECT_TRUE(triggered); \
signal(SIGNO, old_handler); \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment