/*!a test case for the interaction of remove() and key(). */ void removeKey() { UtlString v1("a"); UtlString v2("b"); UtlString v3("c"); UtlString v4("d"); UtlContainable* e; UtlHashBag h; h.insert(&v1); h.insert(&v2); h.insert(&v3); h.insert(&v4); UtlHashBagIterator iter(h); // Check that key() returns NULL in the initial state. CPPUNIT_ASSERT(iter.key() == NULL); // Step the iterator and check that key() returns non-NULL. e = iter(); CPPUNIT_ASSERT(e != NULL); CPPUNIT_ASSERT(iter.key() != NULL); // Delete the element and check that key() returns NULL. h.remove(e); CPPUNIT_ASSERT(iter.key() == NULL); // Step the iterator and check that key() returns non-NULL. e = iter(); CPPUNIT_ASSERT(e != NULL); CPPUNIT_ASSERT(iter.key() != NULL); // Step the iterator and check that key() returns non-NULL. e = iter(); CPPUNIT_ASSERT(e != NULL); CPPUNIT_ASSERT(iter.key() != NULL); // Delete the element and check that key() returns NULL. h.remove(e); CPPUNIT_ASSERT(iter.key() == NULL); // Step the iterator and check that key() returns non-NULL. e = iter(); CPPUNIT_ASSERT(e != NULL); CPPUNIT_ASSERT(iter.key() != NULL); // Step the iterator after the last element and check that // key() returns NULL. e = iter(); CPPUNIT_ASSERT(e == NULL); CPPUNIT_ASSERT(iter.key() == NULL); } //removeKey()
/*!a Test case for testRemove() * * The Test data for this test case is * a) is an entry's reference * b) is an entry's value(not reference) * c) is the first of multiple matches and is the value match * d) is the second of multiple matches. * e) has no match at all */ void testRemove() { int testCount = 4 ; const char* prefix = "test the remove(UtlContainable* c) method where c " ; const char* Msgs[] = { \ "is an entry's reference ", \ "is an entry's value(not reference) ", \ "is first of multiple value matches ", \ "has no match at all " \ } ; const char* suffix1 = " :- Verify returned value" ; const char* suffix2 = " :- Verify total entries" ; // Insert a new value such that its value matches(isEqual to) // one of the existing items commonList.insert(commonContainables_Clone[4]) ; UtlString notExistContainable("This cannot and willnot exist"); UtlContainable* dataForRemove[] = { \ commonContainables[0], \ commonContainables_Clone[2], \ commonContainables[4], \ ¬ExistContainable \ } ; int totalEnt = commonEntriesCount + 1; UtlBoolean expectedReturnValues[] = { \ true, true, true, false \ } ; int entriesValue[] = { --totalEnt, --totalEnt, --totalEnt, totalEnt } ; totalEnt = commonEntriesCount + 1; for (int i = 0 ; i < testCount ; i++) { string msg ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; UtlContainable* retValue ; retValue = commonList.remove(dataForRemove[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)(retValue!=NULL), \ (UtlBoolean)expectedReturnValues[i]) ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; int expCount = (int)commonList.entries() ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entriesValue[i], expCount) ; } } //testRemove
void testFiltered() { UtlString key1a("key1"); UtlString key1b("key1"); UtlString key2("key2"); UtlString key3("key3"); UtlHashBag theBag; theBag.insert(&key1a); theBag.insert(&key1b); theBag.insert(&key2); theBag.insert(&key3); UtlString* content; { UtlString filter("key2"); UtlHashBagIterator each(theBag,&filter); int foundMask; foundMask = 0; while ((content = (UtlString*)each())) { if ( &key1a == content ) { CHECK_FOUND(foundMask,0x0001); } else if ( &key1b == content ) { CHECK_FOUND(foundMask,0x0002); } else if ( &key2 == content ) { CHECK_FOUND(foundMask,0x0004); } else if ( &key3 == content ) { CHECK_FOUND(foundMask,0x0008); } else { CPPUNIT_FAIL("Unknown element returned"); } } CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0004==foundMask); } { UtlString filter("key1"); UtlHashBagIterator each(theBag,&filter); int foundMask; foundMask = 0; while ((content = (UtlString*)each())) { if ( &key1a == content ) { CHECK_FOUND(foundMask,0x0001); } else if ( &key1b == content ) { CHECK_FOUND(foundMask,0x0002); } else if ( &key2 == content ) { CHECK_FOUND(foundMask,0x0004); } else if ( &key3 == content ) { CHECK_FOUND(foundMask,0x0008); } else { CPPUNIT_FAIL("Unknown element returned"); } } CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0003==foundMask); } { UtlString filter("key1"); UtlHashBagIterator each(theBag,&filter); int foundMask; foundMask = 0; UtlString* removed = (UtlString*)theBag.remove(&filter); if ( &key1a == removed ) { CHECK_FOUND(foundMask,0x0001); } else if ( &key1b == removed ) { CHECK_FOUND(foundMask,0x0002); } else { CPPUNIT_FAIL("Unknown element removed"); } while ((content = (UtlString*)each())) { if ( &key1a == content ) { CHECK_FOUND(foundMask,0x0001); } else if ( &key1b == content ) { CHECK_FOUND(foundMask,0x0002); } else if ( &key2 == content ) { CHECK_FOUND(foundMask,0x0004); } else if ( &key3 == content ) { CHECK_FOUND(foundMask,0x0008); } else { CPPUNIT_FAIL("Unknown element returned"); } } CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0003==foundMask); } { UtlString filter("key3"); UtlHashBagIterator each(theBag,&filter); int foundMask; foundMask = 0; UtlString* removed = (UtlString*)theBag.remove(&filter); CPPUNIT_ASSERT(&key3==removed); while ((content = (UtlString*)each())) { if ( &key1a == content ) { CHECK_FOUND(foundMask,0x0001); } else if ( &key1b == content ) { CHECK_FOUND(foundMask,0x0002); } else if ( &key2 == content ) { CHECK_FOUND(foundMask,0x0004); } else if ( &key3 == content ) { CHECK_FOUND(foundMask,0x0008); } else { CPPUNIT_FAIL("Unknown element returned"); } } CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0000==foundMask); } { UtlString filter("key4"); UtlHashBagIterator each(theBag,&filter); int foundMask; foundMask = 0; UtlString* removed = (UtlString*)theBag.remove(&filter); CPPUNIT_ASSERT(NULL==removed); while ((content = (UtlString*)each())) { if ( &key1a == content ) { CHECK_FOUND(foundMask,0x0001); } else if ( &key1b == content ) { CHECK_FOUND(foundMask,0x0002); } else if ( &key2 == content ) { CHECK_FOUND(foundMask,0x0004); } else if ( &key3 == content ) { CHECK_FOUND(foundMask,0x0008); } else { CPPUNIT_FAIL("Unknown element returned"); } } CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0000==foundMask); } }