summaryrefslogtreecommitdiff
path: root/tests/Handle_Set_Test.cpp
blob: d8803dfb13710f693e0e76c0dc472e9734219aaa (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
74
75
76
77
78
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
// 
// = FILENAME
//    Handle_Set_Test.cpp
//
// = DESCRIPTION
//      This test illustrates the use of ACE_Handle_Set to maintain a
//      set of handles. No command line arguments are needed to run
//      the test. 
//
// = AUTHOR
//    Prashant Jain
// 
// ============================================================================


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

#define IS_ODD(X) (((X) & 1) != 0)

static void
run_test (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 i = 0; i < count; i++)
    {
      int j = int (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE);

      if (IS_ODD (j))
	{
	  if (handle_set.is_set ((ACE_HANDLE) j))
	    duplicates++;

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

	  handle_set.clr_bit ((ACE_HANDLE) j);
	  clears++;
	}
    }

  ACE_ASSERT (count == sets + clears);
  ACE_ASSERT (handle_set.num_set () + duplicates == sets);

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

int
main (int argc, char *argv[])
{
  ACE_START_TEST ("Handle_Set_Test");

  int count = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_Handle_Set::MAXSIZE;
  run_test (count);

  ACE_END_TEST;
  return 0;
}