diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Map_Manager_Test.cpp | 11 | ||||
-rw-r--r-- | tests/Process_Mutex_Test.cpp | 22 | ||||
-rw-r--r-- | tests/RB_Tree_Test.cpp | 156 | ||||
-rw-r--r-- | tests/Thread_Pool_Reactor_Test.cpp | 35 |
4 files changed, 137 insertions, 87 deletions
diff --git a/tests/Map_Manager_Test.cpp b/tests/Map_Manager_Test.cpp index 70dcf6cb412..5d534f52cac 100644 --- a/tests/Map_Manager_Test.cpp +++ b/tests/Map_Manager_Test.cpp @@ -58,10 +58,14 @@ test_active_map_manager (size_t table_size, TYPE j; ssize_t k; - ACTIVE_MAP_MANAGER::key_type *active_keys - = new ACTIVE_MAP_MANAGER::key_type[iterations]; + ACTIVE_MAP_MANAGER::key_type *active_keys; - for (i = 0; i < iterations; i++) + ACE_NEW (active_keys, + ACTIVE_MAP_MANAGER::key_type[iterations]); + + for (i = 0; + i < iterations; + i++) ACE_ASSERT (map.bind (i, active_keys[i]) != -1); if (test_iterators) @@ -70,6 +74,7 @@ test_active_map_manager (size_t table_size, i = 0; ACTIVE_MAP_MANAGER::iterator end = map.end (); + for (ACTIVE_MAP_MANAGER::iterator iter = map.begin (); iter != end; ++iter) diff --git a/tests/Process_Mutex_Test.cpp b/tests/Process_Mutex_Test.cpp index 3bec5f84551..065c9f20ada 100644 --- a/tests/Process_Mutex_Test.cpp +++ b/tests/Process_Mutex_Test.cpp @@ -31,7 +31,7 @@ USELIB("..\ace\aced.lib"); #if !defined (ACE_LACKS_FORK) static int release_mutex = 1; static int child_process = 0; -static char *mutex_name = ACE_DEFAULT_MUTEX_A; +static const char *mutex_name = ACE_DEFAULT_MUTEX_A; // Explain usage and exit. static void @@ -72,18 +72,26 @@ static void acquire_release (void) { ACE_Process_Mutex mutex (ACE_WIDE_STRING (mutex_name)); + // Make sure the constructor succeeded ACE_ASSERT (ACE_LOG_MSG->op_status () == 0); + // Grab the lock ACE_ASSERT (mutex.acquire () == 0); - ACE_DEBUG ((LM_DEBUG, "(%P) Mutex acquired %s\n", mutex_name)); - ACE_DEBUG ((LM_DEBUG, "(%P) Working....\n")); + + ACE_DEBUG ((LM_DEBUG, + "(%P) Mutex acquired %s\n", + mutex_name)); + ACE_DEBUG ((LM_DEBUG, + "(%P) Working....\n")); // work ACE_OS::sleep (2); // Check if we need to release the mutex if (release_mutex == 1) { - ACE_DEBUG ((LM_DEBUG, "(%P) Releasing the mutex %s\n", mutex_name)); + ACE_DEBUG ((LM_DEBUG, + "(%P) Releasing the mutex %s\n", + mutex_name)); ACE_ASSERT (mutex.release () == 0); } } @@ -119,11 +127,13 @@ main (int argc, char *argv[]) if (release_mutex == 0) options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT ("Process_Mutex_Test") ACE_PLATFORM_EXE_SUFFIX - ACE_TEXT (" -c -n %s -d"), ACE_WIDE_STRING (mutex_name)); + ACE_TEXT (" -c -n %s -d"), + ACE_WIDE_STRING (mutex_name)); else options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT ("Process_Mutex_Test") ACE_PLATFORM_EXE_SUFFIX - ACE_TEXT (" -c -n %s"), ACE_WIDE_STRING (mutex_name)); + ACE_TEXT (" -c -n %s"), + ACE_WIDE_STRING (mutex_name)); // Spawn ACE_MAX_PROCESSES processes that will contend for the // lock. diff --git a/tests/RB_Tree_Test.cpp b/tests/RB_Tree_Test.cpp index edb47bfbfbd..a5edd805bd2 100644 --- a/tests/RB_Tree_Test.cpp +++ b/tests/RB_Tree_Test.cpp @@ -34,11 +34,11 @@ USELIB("..\ace\aced.lib"); //--------------------------------------------------------------------------- #endif /* defined(__BORLANDC__) && __BORLANDC__ >= 0x0530 */ - - // These arrays of numbers as ints and character strings // are used to instantiate key and item nodes in the tree. -static const char *number_strings [] = + +// @@ Chris, the following should be a "const char *" not a "char *". +static char *number_strings [] = { "10", "20", "30", "40", "50", "60", "70", "80" }; @@ -63,93 +63,118 @@ main (int, ASYS_TCHAR *[]) { ACE_START_TEST (ASYS_TEXT ("RB_Tree_Test")); + // @@ Chris, this function is WAY, WAY, WAY too long, which makes it + // impossible to tell what's going on... Please break it up into a + // number of smaller functions. + // Local variables used to index arrays. - int i, k; + int i; + int k; + + // Construct eight RB_Trees. Specialization of the ACE_Less_Than + // template for character strings performs strcmp style string + // comparisons rather than < operator comparison of the pointers + // themselves. + + // @@ Chris, the following definitions are (1) not const-correct, + // (2) should be factored out into typedefs so that the code is + // readable, and (3) each variable should be defined 1 per line. - // Construct eight RB_Trees. Specialization of the ACE_Less_Than template - // for character strings performs strcmp style string comparisons rather - // than < operator comparison of the pointers themselves. ACE_RB_Tree<int, int, ACE_Less_Than<int>, ACE_Null_Mutex> int_int_tree1, int_int_tree2; ACE_RB_Tree<int, char *, ACE_Less_Than<int>, ACE_Null_Mutex> int_str_tree1, int_str_tree2; ACE_RB_Tree<char *, int, ACE_Less_Than<char *>, ACE_Null_Mutex> str_int_tree1, str_int_tree2; ACE_RB_Tree<char *, char *, ACE_Less_Than<char *>, ACE_Null_Mutex> str_str_tree1, str_str_tree2; // First, test the new ACE_Hash_Map_Manager_Ex compliant interface. - // Fill in each tree with the key and item from the appropriate arrays, - // using the shuffle indexes to create different insertion orders. - for (i = 0; i < RB_TREE_TEST_ENTRIES; ++i) + // Fill in each tree with the key and item from the appropriate + // arrays, using the shuffle indexes to create different insertion + // orders. + + for (i = 0; + i < RB_TREE_TEST_ENTRIES; + ++i) { char *str_item; int int_item; k = int_int_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); int_item = -1; - int_int_tree1.insert (number_integers [k], number_integers [k]); - ACE_ASSERT ((int_int_tree1.find (number_integers [k], int_item) == 0) && - (int_item == number_integers [k])); + // @@ Chris, shouldn't you be checking return values here to + // make sure this call worked (same for all calls below)? + int_int_tree1.insert (number_integers [k], + number_integers [k]); + ACE_ASSERT (int_int_tree1.find (number_integers [k], int_item) == 0 + && int_item == number_integers [k]); k = int_str_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); str_item = 0; - int_str_tree1.insert (number_integers [k], number_strings [k]); - ACE_ASSERT ((int_str_tree1.find (number_integers [k], str_item) == 0) && - (str_item == number_strings [k])); + int_str_tree1.insert (number_integers [k], + number_strings [k]); + ACE_ASSERT (int_str_tree1.find (number_integers [k], str_item) == 0 + && str_item == number_strings [k]); k = str_int_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); int_item = -1; str_int_tree1.insert (number_strings [k], number_integers [k]); - ACE_ASSERT ((str_int_tree1.find (number_strings [k], int_item) == 0) && - (int_item == number_integers [k])); + ACE_ASSERT (str_int_tree1.find (number_strings [k], int_item) == 0 + && int_item == number_integers [k]); k = str_str_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); str_item = 0; - str_str_tree1.insert (number_strings [k], number_strings [k]); - ACE_ASSERT ((str_str_tree1.find (number_strings [k], str_item) == 0) && - (str_item == number_strings [k])); + str_str_tree1.insert (number_strings [k], + number_strings [k]); + ACE_ASSERT (str_str_tree1.find (number_strings [k], str_item) == 0 + && str_item == number_strings [k]); } - // Second, test the deprecated interface. This portion of the test will - // go away when the deprecated interface is removed - // Fill in each tree with the key and item from the appropriate arrays, + // Second, test the deprecated interface. This portion of the test + // will go away when the deprecated interface is removed Fill in + // each tree with the key and item from the appropriate arrays, // using the shuffle indexes to create different insertion orders. - for (i = 0; i < RB_TREE_TEST_ENTRIES; ++i) + for (i = 0; + i < RB_TREE_TEST_ENTRIES; + ++i) { k = int_int_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); - int_int_tree2.insert (number_integers [k], number_integers [k]); - ACE_ASSERT ((int_int_tree2.find (number_integers [k]) != 0) && - (*int_int_tree2.find (number_integers [k]) == - number_integers [k])); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); + int_int_tree2.insert (number_integers [k], + number_integers [k]); + ACE_ASSERT (int_int_tree2.find (number_integers [k]) != 0 + && *int_int_tree2.find (number_integers [k]) == number_integers [k]); k = int_str_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); - int_str_tree2.insert (number_integers [k], number_strings [k]); - ACE_ASSERT ((int_str_tree2.find (number_integers [k]) != 0) && - (*int_str_tree2.find (number_integers [k]) == - number_strings [k])); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); + int_str_tree2.insert (number_integers [k], + number_strings [k]); + ACE_ASSERT (int_str_tree2.find (number_integers [k]) != 0 + && *int_str_tree2.find (number_integers [k]) == number_strings [k]); k = str_int_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); - str_int_tree2.insert (number_strings [k], number_integers [k]); - ACE_ASSERT ((str_int_tree2.find (number_strings [k]) != 0) && - (*str_int_tree2.find (number_strings [k]) == - number_integers [k])); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); + str_int_tree2.insert (number_strings [k], + number_integers [k]); + ACE_ASSERT (str_int_tree2.find (number_strings [k]) != 0 + && *str_int_tree2.find (number_strings [k]) == number_integers [k]); k = str_str_index [i]; - ACE_ASSERT ((k >= 0) && (k < RB_TREE_TEST_ENTRIES)); - str_str_tree2.insert (number_strings [k], number_strings [k]); - ACE_ASSERT ((str_str_tree2.find (number_strings [k]) != 0) && - (*str_str_tree2.find (number_strings [k]) == - number_strings [k])); + ACE_ASSERT (k >= 0 && k < RB_TREE_TEST_ENTRIES); + str_str_tree2.insert (number_strings [k], + number_strings [k]); + ACE_ASSERT (str_str_tree2.find (number_strings [k]) != 0 + && *str_str_tree2.find (number_strings [k]) == number_strings [k]); } // Construct a forward and reverse iterator for each of the trees. + // @@ Chris, these should also be typedef'd at the beginning of the + // file and cleaned up to be const-correct. + ACE_RB_Tree_Iterator<int, int, ACE_Less_Than<int>, ACE_Null_Mutex> int_int_iter1 (int_int_tree1); ACE_RB_Tree_Iterator<int, char *, ACE_Less_Than<int>, ACE_Null_Mutex> int_str_iter1 (int_str_tree1); ACE_RB_Tree_Iterator<char *, int, ACE_Less_Than<char *>, ACE_Null_Mutex> str_int_iter1 (str_int_tree1); @@ -170,10 +195,12 @@ main (int, ASYS_TCHAR *[]) ACE_RB_Tree_Reverse_Iterator<char *, int, ACE_Less_Than<char *>, ACE_Null_Mutex> str_int_rev_iter2 (str_int_tree2); ACE_RB_Tree_Reverse_Iterator<char *, char *, ACE_Less_Than<char *>, ACE_Null_Mutex> str_str_rev_iter2 (str_str_tree2); - // Iterate over each of the trees, making sure their entries - // are in the same relative order (i.e., the integers and strings - // represent the same values at each respective position in the tree). - for (i = 0; i < RB_TREE_TEST_ENTRIES; ++i) + // Iterate over each of the trees, making sure their entries are in + // the same relative order (i.e., the integers and strings represent + // the same values at each respective position in the tree). + for (i = 0; + i < RB_TREE_TEST_ENTRIES; + ++i) { char *str_item; int int_item; @@ -226,7 +253,6 @@ main (int, ASYS_TCHAR *[]) str_item = (*str_str_rev_iter2).item (); ACE_ASSERT (str_item == number_strings [RB_TREE_TEST_ENTRIES - i - 1]); - // Advance each iterator. ++int_int_iter1; ++int_str_iter1; @@ -264,8 +290,11 @@ main (int, ASYS_TCHAR *[]) ACE_ASSERT (str_int_rev_iter2.done () == 1); ACE_ASSERT (str_str_rev_iter2.done () == 1); - // Remove the even numbered entries from each of the trees. New interface. - for (i = 0; i < RB_TREE_TEST_ENTRIES; i += 2) + // Remove the even numbered entries from each of the trees. New + // interface. + for (i = 0; + i < RB_TREE_TEST_ENTRIES; + i += 2) { ACE_ASSERT (int_int_tree1.unbind (number_integers [i]) == 0); ACE_ASSERT (int_str_tree1.unbind (number_integers [i]) == 0); @@ -273,8 +302,11 @@ main (int, ASYS_TCHAR *[]) ACE_ASSERT (str_str_tree1.unbind (number_strings [i]) == 0); } - // Remove the even numbered entries from each of the trees. Deprecated interface. - for (i = 0; i < RB_TREE_TEST_ENTRIES; i += 2) + // Remove the even numbered entries from each of the trees. + // Deprecated interface. + for (i = 0; + i < RB_TREE_TEST_ENTRIES; + i += 2) { ACE_ASSERT (int_int_tree2.remove (number_integers [i]) == 1); ACE_ASSERT (int_str_tree2.remove (number_integers [i]) == 1); @@ -301,11 +333,13 @@ main (int, ASYS_TCHAR *[]) str_int_rev_iter2 = str_int_tree2.rbegin (); str_str_rev_iter2 = str_str_tree2.rbegin (); - // Iterate over each of the trees, making sure their entries are // still in the same relative order (i.e., the integers and strings - // represent the same values at each respective position in the tree). - for (i = 1; i < RB_TREE_TEST_ENTRIES; i += 2) + // represent the same values at each respective position in the + // tree). + for (i = 1; + i < RB_TREE_TEST_ENTRIES; + i += 2) { char *str_item; int int_item; diff --git a/tests/Thread_Pool_Reactor_Test.cpp b/tests/Thread_Pool_Reactor_Test.cpp index 4d8770bcc96..9d5489e2777 100644 --- a/tests/Thread_Pool_Reactor_Test.cpp +++ b/tests/Thread_Pool_Reactor_Test.cpp @@ -33,7 +33,7 @@ // <delay>: 50 usec // // = AUTHOR -// Irfan Pyarali <irfan@cs.wustl.edu> +// Irfan Pyarali <irfan@cs.wustl.edu> and // Nanbor Wang <nanbor@cs.wustl.edu> // // ============================================================================ @@ -58,13 +58,13 @@ USELIB("..\ace\aced.lib"); #include "tests/Thread_Pool_Reactor_Test.h" typedef ACE_Strategy_Acceptor <Request_Handler, ACE_SOCK_ACCEPTOR> ACCEPTOR; -static ASYS_TCHAR *rendezvous = ASYS_TEXT ("127.0.0.1:10010"); -// Accepting end point. This is actually "localhost:10010", -// but some platform couldn't resolve the name so we use the -// IP address directly here. +// Accepting end point. This is actually "localhost:10010", but some +// platform couldn't resolve the name so we use the IP address +// directly here. +static LPCTSTR rendezvous = ASYS_TEXT ("127.0.0.1:10010"); -static size_t svr_thrno = ACE_MAX_THREADS; // Total number of server threads. +static size_t svr_thrno = ACE_MAX_THREADS; #if defined (CHORUS) // Add platforms that can't handle too many // connection simultaneously here. @@ -73,19 +73,19 @@ static size_t svr_thrno = ACE_MAX_THREADS; #define ACE_LOAD_FACTOR #endif -static size_t cli_thrno = ACE_MAX_THREADS ACE_LOAD_FACTOR; // Total number of client threads. +static size_t cli_thrno = ACE_MAX_THREADS ACE_LOAD_FACTOR; -static size_t cli_conn_no = ACE_MAX_ITERATIONS ACE_LOAD_FACTOR; // Total connection attemps of a client thread. +static size_t cli_conn_no = ACE_MAX_ITERATIONS ACE_LOAD_FACTOR; -static size_t cli_req_no = ACE_MAX_THREADS ACE_LOAD_FACTOR; // Total requests a client thread sends. +static size_t cli_req_no = ACE_MAX_THREADS ACE_LOAD_FACTOR; -static int req_delay = 50; // Delay before a thread sending the next request (in msec.) +static int req_delay = 50; -void +static void parse_arg (int argc, ASYS_TCHAR *argv[]) { ACE_Get_Opt getopt (argc, argv, ASYS_TEXT ("r:s:c:d:i:n:")); @@ -179,7 +179,7 @@ Request_Handler::handle_close (ACE_HANDLE fd, ACE_Reactor_Mask) return 0; } -void * +static void * svr_worker (void *) { // Server thread function. @@ -200,7 +200,7 @@ svr_worker (void *) return 0; } -void * +static void * cli_worker (void *arg) { // Client thread function. @@ -226,7 +226,8 @@ cli_worker (void *arg) ASYS_TEXT ("(%t) conn_worker handle 0x%x, req %d\n"), stream.get_handle (), j+1)); - if (stream.send_n (arg, len + sizeof (ASYS_TCHAR)) == -1) + if (stream.send_n (arg, + len + sizeof (ASYS_TCHAR)) == -1) { ACE_ERROR ((LM_ERROR, ASYS_TEXT ("(%t) %p\n"), @@ -242,11 +243,11 @@ cli_worker (void *arg) return 0; } -void * +static void * worker (void *) { ACE_OS::sleep (3); - ASYS_TCHAR *msg = ASYS_TEXT ("Message from Connection worker"); + LPCTSTR msg = ASYS_TEXT ("Message from Connection worker"); ASYS_TCHAR buf [BUFSIZ]; buf[0] = (ACE_OS::strlen (msg) + 1) * sizeof (ASYS_TCHAR); ACE_OS::strcpy (&buf[1], msg); @@ -273,7 +274,7 @@ worker (void *) ASYS_TEXT ("(%t) %p Error while connecting\n"), ASYS_TEXT ("connect"))); - char *sbuf = "\011shutdown"; + const char *sbuf = "\011shutdown"; ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("shutdown stream handle = %x\n"), |