wibble  1.1
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 #ifdef POSIX
21  struct sigaction a;
22  a.sa_handler = test_signal_action;
23  sigemptyset(&a.sa_mask);
24  a.sa_flags = 0;
25 
26  counter = 0;
27 
28  sig::Action act(SIGUSR1, a);
29  kill(getpid(), SIGUSR1);
30  assert_eq(counter, 1);
31 #endif
32  }
33 
35 #ifdef POSIX
36  sigset_t blocked;
37  struct sigaction a;
38  a.sa_handler = test_signal_action;
39  sigemptyset(&a.sa_mask);
40  a.sa_flags = 0;
41 
42  sigemptyset(&blocked);
43  sigaddset(&blocked, SIGUSR1);
44 
45  counter = 0;
46 
47  sig::Action act(SIGUSR1, a);
48  {
49  sig::ProcMask mask(blocked);
50  kill(getpid(), SIGUSR1);
51  assert_eq(counter, 0);
52  }
53  assert_eq(counter, 1);
54 #endif
55  }
56 };
57 
58 // vim:set ts=4 sw=4: