summaryrefslogtreecommitdiff
path: root/tests/Timer_Queue_Test.cpp
blob: f0ec1c908156dd577f70992bea085c42d0c244b7 (plain)
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
// ============================================================================
// $Id$

//
// = LIBRARY
//    tests
// 
// = FILENAME
//    Timer_Queue_Test.cpp
//
// = DESCRIPTION
//      This is a simple test of ACE_Timer_Queue. The test sets up a
//      bunch of timers and then adds them to a timer queue. The
//      functionality of the timer queue is then tested. No command line
//      arguments are needed to run the test.
//
// = AUTHOR
//    Prashant Jain
// 
// ============================================================================


#include "ace/Timer_Queue.h"
#include "test_config.h"

class Example_Handler : public ACE_Event_Handler
{
public:
  virtual int handle_timeout (const ACE_Time_Value &,
			      const void *arg)
  {
    ACE_ASSERT ((int) arg == 42);
    return 0;
  }
};

int
main (int, char *[])
{
  ACE_START_TEST ("Timer_Queue_Test");

  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 ());
  tq.schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ());
  tq.schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ());
  tq.cancel (timer_id);
  ACE_ASSERT (!tq.is_empty ());

  tq.expire (ACE_OS::gettimeofday ());

  tq.schedule (&eh, (const void *) 4, ACE_OS::gettimeofday ());
  tq.schedule (&eh, (const void *) 5, ACE_OS::gettimeofday ());
  tq.cancel (&eh);
  ACE_ASSERT (tq.is_empty ());
  tq.expire (ACE_OS::gettimeofday ());

  ACE_END_TEST;
  return 0;
}