2 //=============================================================================
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"
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
26 Event_Handler (ACE_Reactor
&reactor
);
33 Event_Handler::Event_Handler (ACE_Reactor
&reactor
)
35 this->reference_counting_policy ().value
36 (ACE_Event_Handler::Reference_Counting_Policy::ENABLED
);
39 "Reference count in Event_Handler() is %d\n",
40 this->reference_count_
.load ()));
42 this->reactor (&reactor
);
47 ACE_TEST_ASSERT (result
== 0);
48 ACE_UNUSED_ARG (result
);
50 this->reactor ()->register_handler (this->pipe_
.read_handle (),
52 ACE_Event_Handler::READ_MASK
);
53 ACE_TEST_ASSERT (result
== 0);
55 this->reactor ()->register_handler (this->pipe_
.write_handle (),
57 ACE_Event_Handler::READ_MASK
);
58 ACE_TEST_ASSERT (result
== 0);
61 Event_Handler::~Event_Handler ()
64 "Reference count in ~Event_Handler() is %d\n",
65 this->reference_count_
.load ()));
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
)
87 new Event_Handler (reactor
);
89 safe_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
)
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"));
124 ACE_TEST_ASSERT (number_of_closes
== number_of_handlers
);
131 #else /* ACE_WIN32 */
134 run_main (int, ACE_TCHAR
*[])
136 ACE_START_TEST (ACE_TEXT ("WFMO_Reactor_Test"));
139 ACE_TEXT ("WFMO_Reactor not supported on this platform\n")));
146 #endif /* ACE_WIN32 */