wibble  0.1.28
signal.test.h
Go to the documentation of this file.
1 /* -*- C++ -*- (c) 2009 Enrico Zini <enrico@enricozini.org> */
2 #include <wibble/sys/signal.h>
3 #include <set>
4 #include <cstdlib>
5 #include <unistd.h>
6 
7 #include <wibble/test.h>
8 
9 using namespace std;
10 using namespace wibble::sys;
11 
12 static int counter;
13 static void test_signal_action(int signum)
14 {
15  ++counter;
16 }
17 
18 struct TestSignal {
20  struct sigaction a;
21  a.sa_handler = test_signal_action;
22  sigemptyset(&a.sa_mask);
23  a.sa_flags = 0;
24 
25  counter = 0;
26 
27  sig::Action act(SIGUSR1, a);
28  kill(getpid(), SIGUSR1);
29  assert_eq(counter, 1);
30  }
31 
33  sigset_t blocked;
34  struct sigaction a;
35  a.sa_handler = test_signal_action;
36  sigemptyset(&a.sa_mask);
37  a.sa_flags = 0;
38 
39  sigemptyset(&blocked);
40  sigaddset(&blocked, SIGUSR1);
41 
42  counter = 0;
43 
44  sig::Action act(SIGUSR1, a);
45  {
46  sig::ProcMask mask(blocked);
47  kill(getpid(), SIGUSR1);
48  assert_eq(counter, 0);
49  }
50  assert_eq(counter, 1);
51  }
52 };
53 
54 // vim:set ts=4 sw=4: