Last active
October 12, 2016 14:53
-
-
Save astoeckel/8ad4268004dafa67083049fc08f0ee92 to your computer and use it in GitHub Desktop.
Google Test EXPECT_SIGNAL macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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