Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Sig_Handlers_Test.cpp
blob9378667c33c8b7da14004c39096b7a3a09cc2b46
2 //=============================================================================
3 /**
4 * @file Sig_Handlers_Test.cpp
6 * This is a simple program that tests whether the ACE_Sig_Handlers
7 * class works properly. To run this test, start the application
8 * and then type ^C. If everything is working properly the test
9 * will shutdown gracefully.
11 * @author Douglas C. Schmidt <schmidt@dre.vanderbilt.edu> and Andreas Drescher <ace at anticat dot ch>
13 //=============================================================================
16 #include "test_config.h"
17 #include "ace/Reactor.h"
18 #include "ace/WFMO_Reactor.h"
19 #include "ace/Select_Reactor.h"
20 #include "ace/Log_Msg.h"
21 #include "ace/Signal.h"
22 #include "ace/Assert.h"
23 #include "ace/SString.h"
26 class Test_SIGINT_Handler : public ACE_Event_Handler
28 public:
29 Test_SIGINT_Handler (ACE_Reactor *reactor, const char *message)
30 : message_ (message)
32 int result = reactor->register_handler (SIGINT, this);
33 ACE_DEBUG ((LM_DEBUG,
34 ACE_TEXT("Main::Test_SIGINT_Handler (%u) - Result %i\n"),
35 this,
36 result));
37 Test_SIGINT_Handler::registration_count_++;
40 ~Test_SIGINT_Handler() override
42 ACE_TEST_ASSERT (Test_SIGINT_Handler::handle_signal_count_ == Test_SIGINT_Handler::registration_count_);
45 int handle_signal (int signal, siginfo_t *, ucontext_t *) override
47 ACE_TEST_ASSERT (signal == SIGINT);
48 ACE_DEBUG ((LM_DEBUG,
49 ACE_TEXT("Main::Test_SIGINT_Handler (%u) - %s\n"),
50 this,
51 this->message_.c_str()));
52 Test_SIGINT_Handler::handle_signal_count_++;
53 return 0;
56 private:
57 ACE_CString message_;
59 static int handle_signal_count_;
61 static int registration_count_;
64 int Test_SIGINT_Handler::handle_signal_count_ = 0;
65 int Test_SIGINT_Handler::registration_count_ = 0;
67 class Test_SIGINT_Shutdown_Handler : public ACE_Event_Handler
69 public:
70 Test_SIGINT_Shutdown_Handler (ACE_Reactor *reactor)
72 int result = reactor->register_handler (SIGINT, this);
73 ACE_DEBUG ((LM_DEBUG,
74 ACE_TEXT("Main::Test_SIGINT_Shutdown_Handler (%u) - Result %i\n"),
75 this,
76 result));
79 int handle_signal (int signal, siginfo_t *, ucontext_t *) override
81 ACE_TEST_ASSERT (signal == SIGINT);
82 ACE_DEBUG ((LM_DEBUG,
83 ACE_TEXT("Main::Test_SIGINT_Shutdown_Handler (%u)\n"),
84 this));
85 ACE_Reactor::instance ()->end_reactor_event_loop ();
86 return 0;
90 int
91 run_main (int, ACE_TCHAR *[])
93 ACE_START_TEST (ACE_TEXT ("Sig_Handlers_Test"));
95 ACE_Sig_Handlers multi_handlers;
96 ACE_Select_Reactor reactor_impl (&multi_handlers);
97 ACE_Reactor reactor (&reactor_impl);
98 ACE_Reactor::instance (&reactor);
100 // Create a bevy of handlers.
102 Test_SIGINT_Handler h1 (ACE_Reactor::instance (), "h1");
103 Test_SIGINT_Handler h2 (ACE_Reactor::instance (), "h2");
104 Test_SIGINT_Handler h3 (ACE_Reactor::instance (), "h3");
105 Test_SIGINT_Handler h4 (ACE_Reactor::instance (), "h4");
106 Test_SIGINT_Handler h5 (ACE_Reactor::instance (), "h5");
107 Test_SIGINT_Handler h6 (ACE_Reactor::instance (), "h6");
108 Test_SIGINT_Handler h7 (ACE_Reactor::instance (), "h7");
109 Test_SIGINT_Handler h8 (ACE_Reactor::instance (), "h8");
111 Test_SIGINT_Shutdown_Handler h0 (ACE_Reactor::instance ());
113 // Wait for user to type SIGINT.
114 while (!ACE_Reactor::instance ()->reactor_event_loop_done ())
116 ACE_DEBUG ((LM_DEBUG,"\nwaiting for SIGINT\n"));
117 if (ACE_Reactor::instance ()->handle_events () == -1)
118 ACE_ERROR ((LM_ERROR,"%p\n","handle_events"));
121 ACE_END_TEST;
122 return 0;