• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

signal.test.h

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

Generated on Tue May 10 2011 16:51:50 for wibble by  doxygen 1.7.1