Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / tests / Hash_Map_Bucket_Iterator_Test.cpp
blob2f2f8ac5422d433e8231e4f331a0b7bfcf41ed45
2 //=============================================================================
3 /**
4 * @file Hash_Map_Bucket_Iterator_Test.cpp
6 * This is a simple test of the <Hash_Map_Bucket_Iterator>.
8 * @author Irfan Pyarali <irfan@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "test_config.h"
14 #include "ace/OS_NS_stdlib.h"
15 #include "ace/Hash_Map_Manager.h"
16 #include "ace/Synch_Traits.h"
17 #include "ace/Null_Mutex.h"
18 #include "ace/Get_Opt.h"
19 #include "ace/Functor.h"
21 static ACE_UINT32 iterations = ACE_MAX_ITERATIONS * 10;
22 static ACE_UINT32 table_size = ACE_MAX_ITERATIONS;
24 int
25 parse_args (int argc, ACE_TCHAR *argv[])
27 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("t:i:"));
29 int cc;
31 while ((cc = get_opt ()) != -1)
32 switch (cc)
34 case 't':
35 table_size = ACE_OS::atoi (get_opt.opt_arg ());
36 break;
37 case 'i':
38 iterations = ACE_OS::atoi (get_opt.opt_arg ());
39 break;
40 case '?':
41 case 'h':
42 default:
43 ACE_ERROR ((LM_ERROR,
44 ACE_TEXT ("usage: %s ")
45 ACE_TEXT ("[-i (iterations)] ")
46 ACE_TEXT ("[-t (table size)] "),
47 ACE_TEXT ("Hash_Map_Bucket_Iterator_Test")));
48 return -1;
51 return 0;
54 using HASH_MAP = ACE_Hash_Map_Manager_Ex<ACE_UINT32, ACE_UINT32, ACE_Hash<ACE_UINT32>, ACE_Equal_To<ACE_UINT32>, ACE_MT_SYNCH::NULL_MUTEX>;
56 using HASH_MAP_BUCKET_ITERATOR = ACE_Hash_Map_Bucket_Iterator<ACE_UINT32, ACE_UINT32, ACE_Hash<ACE_UINT32>, ACE_Equal_To<ACE_UINT32>, ACE_MT_SYNCH::NULL_MUTEX>;
58 int
59 run_main (int argc, ACE_TCHAR *argv[])
61 // Validate options.
62 int result = parse_args (argc, argv);
63 if (result != 0)
64 return result;
66 // Start the test only if options are valid.
67 ACE_START_TEST (ACE_TEXT ("Hash_Map_Bucket_Iterator_Test"));
68 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE);
70 ACE_UINT32 i = 0;
71 HASH_MAP map (table_size);
73 for (i = 0; i < iterations; ++i)
75 int result = map.bind (i, i);
76 ACE_TEST_ASSERT (result == 0);
79 for (i = 0; i < table_size; ++i)
81 HASH_MAP_BUCKET_ITERATOR iterator (map,
82 i);
84 HASH_MAP_BUCKET_ITERATOR end (map,
86 1);
88 for (;
89 iterator != end;
90 ++iterator)
92 ACE_DEBUG ((LM_DEBUG, "%d ", (*iterator).int_id_));
93 ACE_UINT32 key = (*iterator).ext_id_;
94 ACE_TEST_ASSERT (((key - i) % table_size) == 0);
97 ACE_DEBUG ((LM_DEBUG, "\n"));
100 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
101 ACE_END_TEST;
103 return 0;