wibble
0.1.28
|
00001 /* -*- C++ -*- (c) 2009 Enrico Zini <enrico@enricozini.org> */ 00002 #include <wibble/sys/signal.h> 00003 #include <set> 00004 #include <cstdlib> 00005 #include <unistd.h> 00006 00007 #include <wibble/test.h> 00008 00009 using namespace std; 00010 using namespace wibble::sys; 00011 00012 static int counter; 00013 static void test_signal_action(int signum) 00014 { 00015 ++counter; 00016 } 00017 00018 struct TestSignal { 00019 Test sigAction() { 00020 struct sigaction a; 00021 a.sa_handler = test_signal_action; 00022 sigemptyset(&a.sa_mask); 00023 a.sa_flags = 0; 00024 00025 counter = 0; 00026 00027 sig::Action act(SIGUSR1, a); 00028 kill(getpid(), SIGUSR1); 00029 assert_eq(counter, 1); 00030 } 00031 00032 Test sigProcMask() { 00033 sigset_t blocked; 00034 struct sigaction a; 00035 a.sa_handler = test_signal_action; 00036 sigemptyset(&a.sa_mask); 00037 a.sa_flags = 0; 00038 00039 sigemptyset(&blocked); 00040 sigaddset(&blocked, SIGUSR1); 00041 00042 counter = 0; 00043 00044 sig::Action act(SIGUSR1, a); 00045 { 00046 sig::ProcMask mask(blocked); 00047 kill(getpid(), SIGUSR1); 00048 assert_eq(counter, 0); 00049 } 00050 assert_eq(counter, 1); 00051 } 00052 }; 00053 00054 // vim:set ts=4 sw=4: