Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / WFMO_Reactor_Test.cpp
blobd1058c1d6c5958bd3c24b921f11bc4d4e7ff4ae9
2 //=============================================================================
3 /**
4 * @file WFMO_Reactor_Test.cpp
6 * This is a simple test of the WFMO_Reactor. It makes sure that
7 * removals and suspensions work correctly.
9 * @author Irfan Pyarali <irfan@oomworks.com>
11 //=============================================================================
13 #include "test_config.h"
14 #include "ace/Reactor.h"
15 #include "ace/WFMO_Reactor.h"
16 #include "ace/Pipe.h"
18 #if defined (ACE_WIN32)
20 static int number_of_handlers = 6;
21 static int number_of_closes = 0;
23 class Event_Handler : public ACE_Event_Handler
25 public:
26 Event_Handler (ACE_Reactor &reactor);
28 ~Event_Handler ();
30 ACE_Pipe pipe_;
33 Event_Handler::Event_Handler (ACE_Reactor &reactor)
35 this->reference_counting_policy ().value
36 (ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
38 ACE_DEBUG ((LM_DEBUG,
39 "Reference count in Event_Handler() is %d\n",
40 this->reference_count_.load ()));
42 this->reactor (&reactor);
44 int result =
45 this->pipe_.open ();
47 ACE_TEST_ASSERT (result == 0);
48 ACE_UNUSED_ARG (result);
50 this->reactor ()->register_handler (this->pipe_.read_handle (),
51 this,
52 ACE_Event_Handler::READ_MASK);
53 ACE_TEST_ASSERT (result == 0);
55 this->reactor ()->register_handler (this->pipe_.write_handle (),
56 this,
57 ACE_Event_Handler::READ_MASK);
58 ACE_TEST_ASSERT (result == 0);
61 Event_Handler::~Event_Handler ()
63 ACE_DEBUG ((LM_DEBUG,
64 "Reference count in ~Event_Handler() is %d\n",
65 this->reference_count_.load ()));
67 ++number_of_closes;
70 void
71 test ()
73 int result = 0;
74 int i = 0;
76 ACE_Reactor reactor (new ACE_WFMO_Reactor, true);
78 ACE_Event_Handler_var *safe_event_handlers =
79 new ACE_Event_Handler_var[number_of_handlers];
81 Event_Handler **event_handlers =
82 new Event_Handler*[number_of_handlers];
84 for (i = 0; i < number_of_handlers; ++i)
86 event_handlers[i] =
87 new Event_Handler (reactor);
89 safe_event_handlers[i] =
90 event_handlers[i];
93 ACE_Time_Value timeout (0, 500 * 1000);
95 result = reactor.run_reactor_event_loop (timeout);
96 ACE_TEST_ASSERT (result != -1);
98 for (i = 0; i < number_of_handlers; ++i)
100 if (i % 2 == 0)
101 continue;
103 result = reactor.suspend_handler (event_handlers[i]->pipe_.read_handle ());
104 ACE_TEST_ASSERT (result == 0);
106 result = reactor.suspend_handler (event_handlers[i]->pipe_.write_handle ());
107 ACE_TEST_ASSERT (result == 0);
110 result = reactor.run_reactor_event_loop (timeout);
111 ACE_TEST_ASSERT (result != -1);
113 delete[] safe_event_handlers;
114 delete[] event_handlers;
118 run_main (int, ACE_TCHAR *[])
120 ACE_START_TEST (ACE_TEXT ("WFMO_Reactor_Test"));
122 test ();
124 ACE_TEST_ASSERT (number_of_closes == number_of_handlers);
126 ACE_END_TEST;
128 return 0;
131 #else /* ACE_WIN32 */
134 run_main (int, ACE_TCHAR *[])
136 ACE_START_TEST (ACE_TEXT ("WFMO_Reactor_Test"));
138 ACE_ERROR ((LM_INFO,
139 ACE_TEXT ("WFMO_Reactor not supported on this platform\n")));
141 ACE_END_TEST;
143 return 0;
146 #endif /* ACE_WIN32 */