summaryrefslogtreecommitdiff
path: root/examples/Reactor/Misc/test_handle_set.cpp
blob: cfd4791f6e86d0eac13a1bf6d3018f99bcdf7bd2 (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
67
68
69
70
71
72
73

// $Id$

#include "ace/Handle_Set.h"

void
test1 (int count)
{
  int duplicates = 0;
  int sets = 0;
  int clears = 0;

  ACE_Handle_Set handle_set;

  ACE_OS::srand (ACE_OS::time (0L));

  for (int j = 0; j < count; j++)
    {
      int i = int (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE);

      if (ACE_ODD (i))
	{
	  if (handle_set.is_set (i))
	    duplicates++;

	  handle_set.set_bit (i);
	  sets++;
	}
      else
	{
	  if (handle_set.is_set (i))
	    duplicates--;

	  handle_set.clr_bit (i);
	  clears++;
	}
    }

  ACE_DEBUG ((LM_DEBUG, "count = %d, set_size = %d, duplicates = %d\n",
	      count, handle_set.num_set (), (sets - clears) == duplicates));
}

void
test2 (void)
{
  ACE_Handle_Set handle_set;
  ACE_HANDLE handle;

  handle_set.set_bit (0);
  handle_set.set_bit (1);
  handle_set.set_bit (32);
  handle_set.set_bit (63);
  handle_set.set_bit (64);
  handle_set.set_bit (65);
  handle_set.set_bit (122);
  handle_set.set_bit (129);
  handle_set.set_bit (245);
  handle_set.set_bit (255);

  for (ACE_Handle_Set_Iterator fi (handle_set); 
       (handle = fi ()) != -1; 
       ++fi)
    ACE_DEBUG ((LM_DEBUG, "handle = %d\n", handle));
}

int
main (int argc, char *argv[])
{
  int count = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_Handle_Set::MAXSIZE;
  test1 (count);
  test2 ();
}