diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-05-22 18:53:42 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-05-22 18:53:42 +0000 |
commit | d5c89c0858f351389dabe7b3ee55f1a1c36ef14b (patch) | |
tree | 71017a3db937722354222eb80ff5f06a962f731a /tests/WFMO_Reactor_Test.cpp | |
parent | 85a5337fdd6ad331b82536f934edc5c091444f28 (diff) | |
download | ATCD-d5c89c0858f351389dabe7b3ee55f1a1c36ef14b.tar.gz |
ChangeLogTag: Thu May 22 14:13:37 2003 Irfan Pyarali <irfan@oomworks.com>Reactor_RefCount_1
Diffstat (limited to 'tests/WFMO_Reactor_Test.cpp')
-rw-r--r-- | tests/WFMO_Reactor_Test.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/tests/WFMO_Reactor_Test.cpp b/tests/WFMO_Reactor_Test.cpp new file mode 100644 index 00000000000..6bea596a615 --- /dev/null +++ b/tests/WFMO_Reactor_Test.cpp @@ -0,0 +1,157 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// tests +// +// = FILENAME +// WFMO_Reactor_Test.cpp +// +// = DESCRIPTION +// This is a simple test of the WFMO_Reactor. It makes sure that +// removals and suspensions work correctly. +// +// = AUTHOR +// Irfan Pyarali <irfan@oomworks.com> +// +// ============================================================================ + +#include "tests/test_config.h" +#include "ace/Reactor.h" +#include "ace/WFMO_Reactor.h" +#include "ace/Pipe.h" + +ACE_RCSID(tests, WFMO_Reactor_Test, "$Id$") + +#if defined (ACE_WIN32) + +static int number_of_handlers = 6; +static int number_of_closes = 0; + +class Event_Handler : public ACE_Event_Handler +{ +public: + + Event_Handler (ACE_Reactor &reactor); + + ~Event_Handler (void); + + ACE_Pipe pipe_; + +}; + +Event_Handler::Event_Handler (ACE_Reactor &reactor) +{ + this->reference_counting_policy ().value + (ACE_Event_Handler::Reference_Counting_Policy::ENABLED); + + ACE_DEBUG ((LM_DEBUG, + "Reference count in Event_Handler() is %d\n", + this->reference_count_.value ())); + + this->reactor (&reactor); + + int result = + this->pipe_.open (); + + ACE_ASSERT (result == 0); + ACE_UNUSED_ARG (result); + + this->reactor ()->register_handler (this->pipe_.read_handle (), + this, + ACE_Event_Handler::READ_MASK); + ACE_ASSERT (result == 0); + + this->reactor ()->register_handler (this->pipe_.write_handle (), + this, + ACE_Event_Handler::READ_MASK); + ACE_ASSERT (result == 0); +} + +Event_Handler::~Event_Handler (void) +{ + ACE_DEBUG ((LM_DEBUG, + "Reference count in ~Event_Handler() is %d\n", + this->reference_count_.value ())); + + ++number_of_closes; +} + +void +test (void) +{ + int result = 0; + int i = 0; + + ACE_Reactor reactor (new ACE_WFMO_Reactor, 1); + + ACE_Event_Handler_var *safe_event_handlers = + new ACE_Event_Handler_var[number_of_handlers]; + + Event_Handler **event_handlers = + new Event_Handler*[number_of_handlers]; + + for (i = 0; i < number_of_handlers; ++i) + { + event_handlers[i] = + new Event_Handler (reactor); + + safe_event_handlers[i] = + event_handlers[i]; + } + + ACE_Time_Value timeout (0, 500 * 1000); + + result = reactor.run_reactor_event_loop (timeout); + ACE_ASSERT (result != -1); + + for (i = 0; i < number_of_handlers; ++i) + { + if (i % 2 == 0) + continue; + + result = reactor.suspend_handler (event_handlers[i]->pipe_.read_handle ()); + ACE_ASSERT (result == 0); + + result = reactor.suspend_handler (event_handlers[i]->pipe_.write_handle ()); + ACE_ASSERT (result == 0); + } + + result = reactor.run_reactor_event_loop (timeout); + ACE_ASSERT (result != -1); + + delete[] safe_event_handlers; + delete[] event_handlers; +} + +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("WFMO_Reactor_Test")); + + test (); + + ACE_ASSERT (number_of_closes == number_of_handlers); + + ACE_END_TEST; + + return 0; +} + +#else /* ACE_WIN32 */ + +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("WFMO_Reactor_Test")); + + ACE_ERROR ((LM_INFO, + ACE_TEXT ("WFMO_Reactor not supported on this platform\n"))); + + ACE_END_TEST; + + return 0; +} + +#endif /* ACE_WIN32 */ |