本文整理汇总了C++中UtlHashBag::destroy方法的典型用法代码示例。如果您正苦于以下问题:C++ UtlHashBag::destroy方法的具体用法?C++ UtlHashBag::destroy怎么用?C++ UtlHashBag::destroy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UtlHashBag
的用法示例。
在下文中一共展示了UtlHashBag::destroy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRemoveAndDestroy
/*!a Test case to test the destroy()
* method.
*/
void testRemoveAndDestroy()
{
const char* prefix = "test the destroy() method " ;
// The ContainableTestStub has been implemented such that a static
// counter is incremented everytime an instance is created and
// the counter is decremented everytime an instance is destroyed.
UtlContainableTestStub* uStub = new UtlContainableTestStub(0) ;
UtlContainableTestStub* uStubPtr = new UtlContainableTestStub(101) ;
commonList.insert(uStub) ;
commonList.insert(uStubPtr) ;
string msg ;
int cCountBefore = UtlContainableTestStub :: getCount() ;
UtlBoolean retValue = commonList.destroy(uStubPtr) ;
int cCountAfter ;
uStubPtr = NULL ;
TestUtilities::createMessage(2, &msg, prefix, ":- Verify the return value") ;
CPPUNIT_ASSERT_MESSAGE(msg.data(), retValue) ;
// To verify that the object was destroyed, check to see if the static count has been
// decremented. If yes, it means that the destructor was called.
cCountAfter = UtlContainableTestStub :: getCount() ;
TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the object was deleted") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;
// THe way to verify if the object has been removed is to
// create a new stub such that it has the same value as
// the removed stub. Try to find the new stub
UtlContainableTestStub uStubNew(101) ;
UtlContainable* uSearch = commonList.find(&uStubNew) ;
TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the entry is removed") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)NULL, (void*)uSearch) ;
// Now test the case when you have added multiple deletable keys
// and the first key inserted is deleted first.
UtlContainableTestStub* uStubPtr2 = new UtlContainableTestStub(201) ;
UtlContainableTestStub* uStubPtr3 = new UtlContainableTestStub(201) ;
commonList.insert(uStubPtr2) ;
commonList.insert(uStubPtr3) ;
UtlInt uTestInt(2031) ;
commonList.insert(&uTestInt) ;
// after destroying, either uStubPtr or uStubPtr3 might have gotten deleted and
// we have no way to find out which one. So create a new ContainableTestStub
// and use that for search
UtlContainableTestStub uStubTemp(201) ;
cCountBefore = UtlContainableTestStub :: getCount() ;
commonList.destroy(&uStubTemp) ;
cCountAfter = UtlContainableTestStub :: getCount() ;
uSearch = commonList.find(&uStubTemp) ;
const char* msgTemp = "Verify that doing a removeAndDestroy on " \
"an item that has multiple matches removes only one entry " ;
TestUtilities::createMessage(2, &msg, msgTemp, " :- Verify value is still found") ;
CPPUNIT_ASSERT_MESSAGE("Verify that doing a removeAndDestroy on " \
"an item that has multiple matches removes only one entry", \
uSearch == uStubPtr2 || uSearch == uStubPtr3) ;
TestUtilities::createMessage(2, &msg, msgTemp, " :- Verify value *was* destroyed") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;
msgTemp = "Verify that the remaining entry can also be deleted" ;
cCountBefore = UtlContainableTestStub :: getCount() ;
commonList.destroy(&uStubTemp) ;
cCountAfter = UtlContainableTestStub :: getCount() ;
TestUtilities::createMessage(2, &msg, msgTemp, " :- Verify value *was* destroyed") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;
// In all the above tests, a total of 5 entries were added
// and 3 were removed.
int finalCount = commonEntriesCount + 2 ;
msgTemp = "Verify that the HashTable stil has the other entries" ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msgTemp, finalCount, (int)commonList.entries()) ;
}