1 #include "ace/OS_NS_sys_time.h"
2 #include "ace/Timer_Heap.h"
3 #include "ace/Timer_List.h"
4 #include "ace/Timer_Queue.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/Recursive_Thread_Mutex.h"
7 #include "ace/Null_Mutex.h"
8 #include "ace/Event_Handler.h"
10 class Example_Handler
: public ACE_Event_Handler
17 virtual int handle_timeout (const ACE_Time_Value
&, const void *arg
)
19 int *times
= (int *) arg
;
22 "yow, the time has come and gone %d times %d, Horatio!\n",
34 test_functionality (ACE_Timer_Queue
*tq
)
38 ACE_TEST_ASSERT (tq
->is_empty ());
39 ACE_TEST_ASSERT (ACE_Time_Value::zero
== ACE_Time_Value (0));
40 const void *timer_act
= 0;
42 ACE_NEW (timer_act
, int (1));
43 long timer_id1
= tq
->schedule (&eh
, timer_act
, ACE_OS::gettimeofday ());
45 // Use timer_id outside of an assert, so that we don't get compile
46 // warnings with ACE_NDEBUG about it being unused.
48 ACE_ERROR ((LM_ERROR
, "%p\n", "schedule () failed"));
49 ACE_TEST_ASSERT (timer_id1
!= -1);
51 ACE_NEW (timer_act
, int (42));
52 long result
= tq
->schedule (&eh
, timer_act
, ACE_OS::gettimeofday ());
53 ACE_TEST_ASSERT (result
!= -1);
54 ACE_NEW (timer_act
, int (42));
55 result
= tq
->schedule (&eh
, timer_act
, ACE_OS::gettimeofday ());
56 ACE_TEST_ASSERT (result
!= -1);
58 result
= tq
->cancel (timer_id1
, &timer_act
);
59 ACE_TEST_ASSERT (result
== 1);
60 delete (int *) timer_act
;
61 result
= tq
->is_empty ();
62 ACE_TEST_ASSERT (!result
);
64 result
= tq
->expire ();
65 ACE_TEST_ASSERT (result
== 2);
67 ACE_NEW (timer_act
, int (4));
68 timer_id1
= tq
->schedule (&eh
, timer_act
, ACE_OS::gettimeofday ());
69 ACE_TEST_ASSERT (timer_id1
!= -1);
70 ACE_NEW (timer_act
, int (5));
71 long timer_id2
= tq
->schedule (&eh
, timer_act
, ACE_OS::gettimeofday ());
72 ACE_TEST_ASSERT (timer_id2
!= -1);
74 result
= tq
->cancel (timer_id1
, &timer_act
);
75 ACE_TEST_ASSERT (result
== 1);
76 delete (int *) timer_act
;
77 result
= tq
->cancel (timer_id2
, &timer_act
);
78 ACE_TEST_ASSERT (result
== 1);
79 delete (int *) timer_act
;
80 result
= tq
->is_empty ();
81 ACE_TEST_ASSERT (result
== 1);
82 result
= tq
->expire ();
83 ACE_TEST_ASSERT (result
== 0);
88 ACE_Timer_Queue
*queue_
;
89 // Pointer to the subclass of <ACE_Timer_Queue> that we're testing.
92 // Name of the Queue that we're testing.
95 static Timer_Queues timer_queues
[] =
97 { new ACE_Timer_List
, "ACE_Timer_List" },
98 { new ACE_Timer_Heap
, "ACE_Timer_Heap" },
103 ACE_TMAIN (int, ACE_TCHAR
*[])
105 for (int i
= 0; timer_queues
[i
].name_
!= 0; i
++)
107 test_functionality (timer_queues
[i
].queue_
);
108 delete timer_queues
[i
].queue_
;