1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// $Id$
#include "ace/Timer_Heap.h"
#include "ace/Timer_List.h"
#include "ace/Timer_Queue.h"
class Example_Handler : public ACE_Event_Handler
{
public:
Example_Handler (void)
: count_ (0)
{}
virtual int handle_timeout (const ACE_Time_Value &, const void *arg)
{
// Cast the arg to a long, first, because a pointer is the same
// size as a long on all current ACE platforms.
int times = (int) (long) arg;
ACE_DEBUG ((LM_DEBUG,
"yow, the time has come and gone %d times %d, Horatio!\n",
this->count_++,
times));
return 0;
}
private:
int count_;
};
static void
test_functionality (ACE_Timer_Queue *tq)
{
Example_Handler eh;
ACE_ASSERT (tq->is_empty ());
ACE_ASSERT (ACE_Time_Value::zero == ACE_Time_Value (0));
int timer_id;
timer_id = tq->schedule (&eh, (const void *) 1, ACE_OS::gettimeofday ());
ACE_ASSERT (timer_id != -1);
ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
ACE_OS::gettimeofday ()) != -1);
ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
ACE_OS::gettimeofday ()) != -1);
ACE_ASSERT (tq->cancel (timer_id) == 1);
ACE_ASSERT (!tq->is_empty ());
ACE_ASSERT (tq->expire () == 2);
ACE_ASSERT (tq->schedule (&eh, (const void *) 4, ACE_OS::gettimeofday
()) != -1);
ACE_ASSERT (tq->schedule (&eh, (const void *) 5, ACE_OS::gettimeofday
()) != -1);
ACE_ASSERT (tq->cancel (&eh) == 2);
ACE_ASSERT (tq->is_empty ());
ACE_ASSERT (tq->expire () == 0);
}
struct Timer_Queues
{
ACE_Timer_Queue *queue_;
// Pointer to the subclass of <ACE_Timer_Queue> that we're testing.
const char *name_;
// Name of the Queue that we're testing.
};
static Timer_Queues timer_queues[] =
{
{ new ACE_Timer_List, "ACE_Timer_List" },
{ new ACE_Timer_Heap, "ACE_Timer_Heap" },
{ 0, 0 },
};
int
main (int, char *[])
{
for (int i = 0; timer_queues[i].name_ != 0; i++)
{
test_functionality (timer_queues[i].queue_);
delete timer_queues[i].queue_;
}
return 0;
}
|