static void unbind_test (MAP &map, size_t iterations, KEY *keys) { // Remove system generated keys. size_t counter = iterations; for (VALUE i = 0; i < iterations; ++i) { ACE_ASSERT (map.unbind (keys[i]) != -1); --counter; ACE_ASSERT (map.current_size () == counter); } }
static void functionality_test (MAP &map, size_t iterations) { size_t counter; VALUE i; KEY *original_keys = new KEY[iterations]; KEY *modified_keys = new KEY[iterations]; // Setup the keys to have some initial data. for (i = 0; i < iterations; ++i) { original_keys[i].size (sizeof i / sizeof (KEY::TYPE)); ACE_OS::memcpy (&original_keys[i][0], &i, sizeof i); } // Make a copy of the keys so that we can compare with the original // keys later. for (i = 0; i < iterations; ++i) { modified_keys[i] = original_keys[i]; } // Add to the map, allowing keys to be modified. counter = 0; for (i = 0; i < iterations; ++i) { ACE_ASSERT (map.bind_modify_key (i, modified_keys[i]) == 0); ++counter; ACE_ASSERT (map.current_size () == counter); } // Forward iteration... { counter = 0; MAP::iterator end = map.end (); for (MAP::iterator iter = map.begin (); iter != end; ++iter, ++counter) { MAP::value_type entry = *iter; // Recover original key. KEY original_key; ACE_ASSERT (map.recover_key (entry.first (), original_key) == 0); // Make sure recovering keys work. ACE_ASSERT (original_keys[entry.second ()] == original_key); // Obtain value from key. VALUE original_value; ACE_OS::memcpy (&original_value, &original_key[0], sizeof original_value); // Debugging info. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%d|%d|%d)"), counter, original_value, entry.second ())); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); ACE_ASSERT (counter == iterations); } // Reverse iteration... { counter = iterations; MAP::reverse_iterator end = map.rend (); for (MAP::reverse_iterator iter = map.rbegin (); iter != end; ++iter) { --counter; MAP::value_type entry = *iter; // Recover original key. KEY original_key; ACE_ASSERT (map.recover_key (entry.first (), original_key) == 0); // Make sure recovering keys work. ACE_ASSERT (original_keys[entry.second ()] == original_key); // Obtain value from key. VALUE original_value; ACE_OS::memcpy (&original_value, &original_key[0], sizeof original_value); // Debugging info. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%d|%d|%d)"), counter, original_value, entry.second ())); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); ACE_ASSERT (counter == 0); } // Search using the modified keys. for (i = 0; i < iterations; ++i) { VALUE j; ACE_ASSERT (map.find (modified_keys[i], j) != -1); ACE_ASSERT (i == j); } // Rmoved keys from map. counter = iterations; for (i = 0; i < iterations; ++i) { ACE_ASSERT (map.unbind (modified_keys[i]) != -1); --counter; ACE_ASSERT (map.current_size () == counter); } // Cleanup. delete[] modified_keys; delete[] original_keys; }