SignalTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log$
00014  *
00015  */
00016 
00017 #ifndef Signal_cpp
00018 #define Signal_cpp
00019 
00020 #include <cppunit/ui/text/TestRunner.h>
00021 #include <cppunit/TextOutputter.h>
00022 #include <cppunit/extensions/TestFactoryRegistry.h>
00023 #include <cppunit/extensions/HelperMacros.h>
00024 #include <cppunit/TestAssert.h>
00025 
00026 #include <coil/Signal.h>
00027 
00032 namespace Signal
00033 {
00034 static int Signum;
00035 
00036   class SignalTests
00037    : public CppUnit::TestFixture
00038   {
00039     CPPUNIT_TEST_SUITE(SignalTests);
00040     CPPUNIT_TEST(test_SignalAction_constructor_1);
00041     CPPUNIT_TEST(test_SignalAction_constructor_2);
00042     CPPUNIT_TEST(test_SignalAction_test);
00043     CPPUNIT_TEST_SUITE_END();
00044   
00045   private:
00046 
00047   public:
00048   
00052     SignalTests()
00053     {
00054     }
00055     
00059     ~SignalTests()
00060     {
00061     }
00062   
00066     virtual void setUp()
00067     {
00068     }
00069     
00073     virtual void tearDown()
00074     { 
00075     }
00076   
00077     /* test case */
00081     void test_SignalAction_constructor_1()
00082     {
00083       coil::SignalAction * sa = new coil::SignalAction();
00084       delete sa;
00085     }
00086 
00090     void test_SignalAction_constructor_2()
00091     {
00092       coil::SignalHandler handle(signalHandler);
00093       int signum(SIGINT);
00094       coil::SignalAction * sa = new coil::SignalAction(handle, signum);
00095 
00096       delete sa;
00097     }
00098 
00103 //    void test_SignalAction_constructor_3()
00104 //    {
00105 //      coil::SignalHandler handle(0);
00106 //      int signum(0);
00107 //      sigset_t *mask(0);
00108 //      coil::SignalAction * sa = new coil::SignalAction(handle, signum, mask);
00109 
00110 //      delete sa;
00111 //    }
00112 
00116     void test_SignalAction_test()
00117     {
00118       checkSignalAction();
00119     }
00120 
00124     void checkSignalAction()
00125     {
00126       coil::SignalAction * signalAction;
00127       coil::SignalHandler handle(signalHandler);
00128 //      int sn[] = {
00129 //        SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGPIPE, SIGALRM,
00130 //        SIGTERM,SIGUSR1, SIGUSR2, SIGCHLD, SIGCONT, SIGTSTP, SIGTTIN, SIGTTOU,
00131 //        0
00132 //      };
00133       int sn[] = {    // posix, win common.
00134         SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, 
00135         0
00136       };
00137       int index;
00138       
00139       for (index = 0; sn[index]; index++) {
00140         Signum = sn[index];
00141 //        signalAction = new coil::SignalAction(handle, Signum, mask);
00142         signalAction = new coil::SignalAction(handle, Signum);
00143         raise(Signum);
00144         delete signalAction;
00145       }
00146     }
00147 
00148     /* Signal Handler */
00152     static void signalHandler(int aSignum)
00153     {
00154 //   std::cout << "Signum : " << Signum << std::endl << std::flush ;
00155       CPPUNIT_ASSERT_EQUAL(Signum, aSignum);
00156     }
00157   };
00158 }; // namespace Signal
00159 
00160 /*
00161  * Register test suite
00162  */
00163 CPPUNIT_TEST_SUITE_REGISTRATION(Signal::SignalTests);
00164 
00165 #ifdef LOCAL_MAIN
00166 int main(int argc, char* argv[])
00167 {
00168     CppUnit::TextUi::TestRunner runner;
00169     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00170     CppUnit::Outputter* outputter = 
00171       new CppUnit::TextOutputter(&runner.result(), std::cout);
00172     runner.setOutputter(outputter);
00173     bool retcode = runner.run();
00174     return !retcode;
00175 }
00176 #endif // MAIN
00177 
00178 #if 0
00179 __sighandler_t signal(int __sig, __sighandler_t __handler)
00180 {
00181   __sighandler_t st;
00182   std::cout << "Hello, Signal" << std::endl;
00183   return st;
00184 }
00185 #endif
00186 
00187 #endif // Signal_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07