本文整理汇总了C++中UtlHashBag::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ UtlHashBag::insert方法的具体用法?C++ UtlHashBag::insert怎么用?C++ UtlHashBag::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UtlHashBag
的用法示例。
在下文中一共展示了UtlHashBag::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testClearAndDestroy
/*!a Test case to test the DestroyAll()
* method.
*/
void testClearAndDestroy()
{
const int testCount = 3 ;
int cCountBefore = UtlContainableTestStub :: getCount() ;
const char* prefix = "test the destroyAll() method " ;
const char* suffix1 = " :- sanity check to double check that the counter was incremented for every new() call" ;
const char* suffix2 = " :- Verify that all entries are removed and the objects are deleted" ;
UtlContainableTestStub* uStub ;
UtlContainableTestStub* uStubPtr ;
UtlContainableTestStub* uStubPtr2 ;
uStub = new UtlContainableTestStub(0) ;
uStubPtr = new UtlContainableTestStub(201) ;
uStubPtr2 = new UtlContainableTestStub(201) ;
emptyList.insert(uStub) ;
emptyList.insert(uStubPtr) ;
emptyList.insert(uStubPtr2) ;
cCountBefore = UtlContainableTestStub :: getCount() - cCountBefore ;
emptyList.destroyAll() ;
int cCountAfter = UtlContainableTestStub :: getCount() ;
string msg ;
// Make sure that static count was incremented for every instance
// of the TestStub that was created.
TestUtilities::createMessage(2, &msg, prefix, suffix1) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), testCount, cCountBefore) ;
// Verify that the list has no entries left after destroyAll()
// and also ensure that all the TestStub instances were deleted.
TestUtilities::createMessage(2, &msg, prefix, suffix2) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ;
} //testClearAndDestroy
示例2: testCollision
/* Check for a problem that turned up in insert(): If an object
* was inserted that should have been put at the end of a chain,
* it was instead inserted at the beginning.
*
* This test detects the problem by inserting two objects which we arrange
* to fall into the same bucket. The object with the largest hash is
* inserted second, so it should go at the end of the list, but instead
* is inserted at the beginning. The result is that the small-hash
* object can't be seen by a selective HashBagIterator.
*
* The objects we use to exercise this case have to be tuned to the hash
* algorithm of the objects and the algorithm
* (UtlHashBag::bucketNumber) for turning hashes into bucket numbers.
*/
void testCollision()
{
UtlHashBag bag;
// For UtlInt's, the hash is the value.
UtlInt small_hash_object(1);
bag.insert(&small_hash_object);
// put in some other objects
UtlInt other_hash_object3(3);
bag.insert(&other_hash_object3);
UtlInt other_hash_object4(4);
bag.insert(&other_hash_object4);
UtlInt other_hash_object5(5);
bag.insert(&other_hash_object5);
UtlContainable* found;
{
// check that a keyed iterator sees the small_hash_object
UtlHashBagIterator itor(bag, new UtlInt(1));
found = itor();
CPPUNIT_ASSERT(found == &small_hash_object);
// and nothing else
found = itor();
CPPUNIT_ASSERT(found == NULL);
}
// We depend on the fact that a HashBag initially has 16 buckets and
// folds hashes with XOR. Under these conditions, 1 & 16 collide and
// land in the same bucket.
UtlInt large_hash_object(16);
bag.insert(&large_hash_object);
{
// check that a keyed iterator sees the small_hash_object
UtlHashBagIterator itor(bag, new UtlInt(1));
found = itor();
CPPUNIT_ASSERT(found == &small_hash_object);
// and nothing else
found = itor();
CPPUNIT_ASSERT(found == NULL);
}
{
// check that a keyed iterator sees the large_hash_object
UtlHashBagIterator itor(bag, new UtlInt(16));
found = itor();
CPPUNIT_ASSERT(found == &large_hash_object);
// and nothing else
found = itor();
CPPUNIT_ASSERT(found == NULL);
}
} // testCollision
示例3: removeKey
/*!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()
示例4: and
// Get all bindings expiring before newerThanTime.
void
RegistrationDB::getAllOldBindings(int newerThanTime,
UtlHashBag& rAors) const
{
// Empty the return value.
rAors.destroyAll();
if ( m_pFastDB != NULL )
{
SMART_DB_ACCESS;
// Note: callid set to null indicates provisioned entries and
// these should not be removed
dbQuery query;
query = "expires <", static_cast<const int&>(newerThanTime), " and (callid != '#')";
dbCursor< RegistrationRow > cursor;
int rows = cursor.select( query );
if (rows > 0)
{
// Create UtlString containing the AOR from the "uri" column.
UtlString* uri = new UtlString(cursor->uri);
// Add it to the result set.
rAors.insert(uri);
} while ( cursor.next() );
}
else
{
OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getAllOldBindings failed - no DB");
}
return;
}
示例5: testOneThousandInserts
void testOneThousandInserts()
{
// Test case used to validate fix to issue XPL-169
const int COUNT = 1000;
const char stringPrefix[] = "Apofur81Kb";
UtlHashBag bag;
char tmpString[20];
for( int i = 0; i < COUNT; i++)
{
sprintf(tmpString, "%s%d", stringPrefix, i);
UtlString *stringToInsert = new UtlString();
*stringToInsert = tmpString;
CPPUNIT_ASSERT( ! bag.contains( stringToInsert ) );
bag.insert( stringToInsert );
CPPUNIT_ASSERT_EQUAL( i+1, (int)bag.entries() );
for( unsigned int j = 0; j < bag.entries(); j++ )
{
// verify that all entries are indeed in the bag
sprintf( tmpString, "%s%d", stringPrefix, j );
UtlString stringTolookUp( tmpString );
CPPUNIT_ASSERT_MESSAGE( tmpString, bag.contains( &stringTolookUp ) );
}
}
}
示例6: setUp
void setUp()
{
UtlContainableTestStub::clearCount() ;
commonString1 = UtlString(regularString) ;
commonString1_clone = UtlString(regularString) ;
commonString2 = UtlString("") ;
commonString2_clone = UtlString("") ;
commonString3 = UtlString(longAlphaNumString) ;
commonString3_clone = UtlString(longAlphaNumString) ;
commonInt1 = UtlInt(0) ;
commonInt1_clone = UtlInt(0) ;
commonInt2 = UtlInt(INT_MAX) ;
commonInt2_clone = UtlInt(INT_MAX) ;
commonInt3 = UtlInt(INT_MIN) ;
commonInt3_clone = UtlInt(INT_MIN) ;
commonList.insert(&commonString1) ;
commonContainables[0] = &commonString1 ;
commonContainables_Clone[0] = &commonString1_clone ;
commonList.insert(&commonInt1) ;
commonContainables[1] = &commonInt1 ;
commonContainables_Clone[1] = &commonInt1_clone ;
commonList.insert(&commonInt2) ;
commonContainables[2] = &commonInt2 ;
commonContainables_Clone[2] = &commonInt2_clone;
commonList.insert(&commonString2) ;
commonContainables[3] = &commonString2 ;
commonContainables_Clone[3] = &commonString2_clone ;
commonList.insert(&commonInt3) ;
commonContainables[4] = &commonInt3 ;
commonContainables_Clone[4] = &commonInt3_clone ;
commonList.insert(&commonString3) ;
commonContainables[5] = &commonString3 ;
commonContainables_Clone[5] = &commonString3_clone ;
}
示例7: testIsEmpty
/*!a Test case for the isEmpty() method.
* The test data for this test are :-
* a) When the list has just been created.
* b) When the list has one entry in it
* c) When the list has multiple entries in it.
* e) When all the entries in a list have been removed using removeAll()
*/
void testIsEmpty()
{
const int testCount = 4 ;
const char* prefix = "Test the isEmpty() method when " ;
const char* Msgs[] = { \
"the list has just been created" , \
"the list has just one entry in it", \
"the list has multiple entries in it", \
"all the list entries have been retreived using removeAll()" \
} ;
UtlHashBag newList ;
UtlHashBag secondNewList ;
UtlHashBag commonList_Clone ;
// Add a single entry to the list.
newList.insert(commonContainables[0]) ;
UtlString uS1("Tester string") ;
// populate the second list and then removeAll entries.
secondNewList.insert(&uS1) ;
UtlInt uI1 = UtlInt(232) ;
secondNewList.insert(&uI1) ;
secondNewList.insert(commonContainables[3]) ;
secondNewList.removeAll() ;
UtlHashBag* testLists[] = { \
&emptyList, &newList, &commonList, &secondNewList \
} ;
bool exp[] = { true, false, false, true } ;
for (int i = 0 ; i < testCount; i++)
{
string msg ;
TestUtilities::createMessage(2, &msg, prefix, Msgs[i]) ;
UtlBoolean act = testLists[i] -> isEmpty() ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)exp[i], act) ;
}
} // testIsEmpty
示例8: testRemove
/*!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
示例9: testInsert
/*a! Test the insert method for a list that is not empty. Add both unique and non-unique entries.
*
* The test data for this test is :-
* a) Add a new UtlInt
* b) Add a new UtlString
* c) Add a new UtlVoidPtr
* d) Add a new Containable such that a similar one (value match) exists already
* e) Add a new Containable such that the same one (reference match) exists already
*/
void testInsert()
{
struct testInsertStructure
{
const char* testDescription ;
UtlContainable* itemToAdd ;
UtlContainable* expectedReturnValue ;
// In case of the hashtable, searching for a key can return *ANY* of the values
// that matches and we dont care about which one. so we need two set of expected values
UtlContainable* expectedFoundValue ;
UtlContainable* altExpectedFoundValue ;
} ;
const char* prefix = "Test the insert(UtlContainable*) method for a non empty HashTable " ;
const char* suffix1 = " :- Verify return value" ;
const char* suffix2 = " :- Verify that the value is inserted" ;
const char* suffix3 = " :- Verify that the number of entries is incremented by one" ;
UtlInt uInt = UtlInt(1234) ;
UtlString uString = UtlString("Test String") ;
UtlVoidPtr uVoidPtr((char*)"Hello world") ;
testInsertStructure testData[] = { \
{ "Add a new UtlInt ", &uInt, &uInt, &uInt, &uInt}, \
{ "Add a new UtlString ", &uString, &uString, &uString, &uString}, \
{ "Add a new UtlVoidPtr ", &uVoidPtr, &uVoidPtr, &uVoidPtr, &uVoidPtr}, \
{ "Add a Containable such that an identical one(value match) " \
"exists in the table ", commonContainables_Clone[3], commonContainables_Clone[3], \
commonContainables[3], commonContainables_Clone[3] }, \
{ "Add a Containable such that an exact duplicate " \
"(including reference match) exists in the table ", commonContainables[4],
commonContainables[4], commonContainables[4] } \
} ;
int expCount = commonEntriesCount;
string msg ;
UtlContainable* uAct ;
UtlContainable* uReturn ;
/* :TODO: this part of the test is in error.
* when there is more than one of the same value in the bage,
* the find() method may return any of the objects with that value.
*/
int testCount = sizeof(testData)/sizeof(testData[0]) ;
for (int i = 0 ; i < testCount ; i++)
{
uReturn = commonList.insert(testData[i].itemToAdd) ;
expCount++ ;
uAct = commonList.find(testData[i].itemToAdd) ;
TestUtilities::createMessage(3, &msg, prefix, \
testData[i].testDescription, suffix1) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), \
testData[i].expectedReturnValue, uReturn) ;
// when there is more than one of the same value in the bag,
// the find() method may return any of the objects with that value.
bool isFound = (uAct == testData[i].expectedFoundValue) || \
(uAct == testData[i].altExpectedFoundValue) ;
TestUtilities::createMessage(3, &msg, prefix, \
testData[i].testDescription, suffix2) ;
CPPUNIT_ASSERT_MESSAGE(msg.data(), isFound) ;
TestUtilities::createMessage(3, &msg, prefix, \
testData[i].testDescription, suffix3) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expCount, (int)commonList.entries()) ;
}
} //testInsert
示例10: publish
void SipPublishContentMgr::publish(const char* resourceId,
const char* eventTypeKey,
const char* eventType,
int numContentTypes,
HttpBody* eventContent[],
UtlBoolean fullState,
UtlBoolean noNotify)
{
Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
"SipPublishContentMgr::publish resourceId '%s', eventTypeKey '%s', eventType '%s', numContentTypes %d, noNotify %d, fullState %d",
resourceId ? resourceId : "(null)",
eventTypeKey, eventType, numContentTypes, noNotify, fullState);
if (numContentTypes < 1)
{
Os::Logger::instance().log(FAC_SIP, PRI_ERR,
"SipPublishContentMgr::publish "
"No content bodies supplied for resourceId '%s', "
"eventTypeKey '%s', fullState %d",
resourceId? resourceId : "(null)",
eventTypeKey, fullState);
}
// Construct the key to look up.
UtlString key;
key.append(resourceId);
key.append(CONTENT_KEY_SEPARATOR);
key.append(eventTypeKey);
lock();
// Determine the storage we will be using.
UtlHashBag* pContent;
// resourceId can be NULL if we are called from ::publishDefault()
if (resourceId)
{
if (fullState)
{
// Full dialog events
pContent = &mContentEntries;
}
else
{
// Partial dialog events
pContent = &mPartialContentEntries;
}
}
else
{
// Default dialog events
if (fullState)
{
pContent = &mDefaultContentEntries;
}
else
{
pContent = &mDefaultPartialContentEntries;
}
}
// Look up the key in the specific or default entries, as appropriate.
PublishContentContainer* container =
dynamic_cast <PublishContentContainer*> (pContent->find(&key));
// If not found, create a container.
if (container == NULL)
{
container = new PublishContentContainer(key);
// Save the container in the appropriate hash.
pContent->insert(container);
}
// The content for this event type already existed
else
{
// Remove the old content
container->mEventContent.destroyAll();
}
// Add the new content
for (int index = 0; index < numContentTypes; index++)
{
Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
"SipPublishContentMgr::publish eventContent[%d] = %p, key = '%s', content type = '%s', getBytes() = %p '%s'",
index,
eventContent[index],
key.data(),
eventContent[index]->data(),
eventContent[index]->getBytes(),
eventContent[index]->getBytes());
container->mEventContent.append(eventContent[index]);
}
// Don't call the observers if noNotify is set or if this is default content.
if (!noNotify && resourceId)
{
// Call the observer for the content change, if any.
UtlString eventTypeString(eventType);
PublishCallbackContainer* callbackContainer =
dynamic_cast <PublishCallbackContainer*>
//.........这里部分代码省略.........
示例11: testRemoveReference
void testRemoveReference()
{
// the following two entries collide if the initial bucket size is 16
UtlInt int1(1);
UtlInt int16(16);
UtlInt int2a(2);
UtlInt int2b(2);
UtlInt int3(3);
UtlHashBag bag;
CPPUNIT_ASSERT( bag.numberOfBuckets() == 16 ); // check assumption of collision
// Load all the test objects
CPPUNIT_ASSERT( bag.insert(&int1) == &int1 );
CPPUNIT_ASSERT( bag.insert(&int16) == &int16 );
CPPUNIT_ASSERT( bag.insert(&int2a) == &int2a );
CPPUNIT_ASSERT( bag.insert(&int2b) == &int2b );
CPPUNIT_ASSERT( bag.insert(&int3) == &int3 );
// Check that everything is there
CPPUNIT_ASSERT( bag.entries() == 5 );
CPPUNIT_ASSERT( bag.contains(&int1) );
CPPUNIT_ASSERT( bag.contains(&int16) );
CPPUNIT_ASSERT( bag.contains(&int2a) ); // cannot test for 2a and 2b independently
CPPUNIT_ASSERT( bag.contains(&int3) );
// Take entry 1 out (might collide w/ 16)
CPPUNIT_ASSERT( bag.removeReference(&int1) == &int1 );
// Check that everything except entry 1 is still there, and that 1 is gone
CPPUNIT_ASSERT( bag.entries() == 4 );
CPPUNIT_ASSERT( ! bag.contains(&int1) );
CPPUNIT_ASSERT( bag.contains(&int16) );
CPPUNIT_ASSERT( bag.contains(&int2a) );// cannot test for 2a and 2b independently
CPPUNIT_ASSERT( bag.contains(&int3) );
// Put entry 1 back in (so that 16 will collide w/ it again)
CPPUNIT_ASSERT( bag.insert(&int1) == &int1 );
// Check that everything is there
CPPUNIT_ASSERT( bag.entries() == 5 );
CPPUNIT_ASSERT( bag.contains(&int1) );
CPPUNIT_ASSERT( bag.contains(&int16) );
CPPUNIT_ASSERT( bag.contains(&int2a) );
CPPUNIT_ASSERT( bag.contains(&int3) );
// Take entry 16 out (might collide w/ 1)
CPPUNIT_ASSERT( bag.removeReference(&int16) == &int16 );
// Check that everything except entry 16 is still there, and that 16 is gone
CPPUNIT_ASSERT( bag.entries() == 4 );
CPPUNIT_ASSERT( bag.contains(&int1) );
CPPUNIT_ASSERT( ! bag.contains(&int16) );
CPPUNIT_ASSERT( bag.contains(&int2a) );// cannot test for 2a and 2b independently
CPPUNIT_ASSERT( bag.contains(&int3) );
// remove 2a (and ensure that you don't get back 2b)
CPPUNIT_ASSERT( bag.removeReference(&int2a) == &int2a );
// Check that everything that should be is still there
CPPUNIT_ASSERT( bag.entries() == 3 );
CPPUNIT_ASSERT( bag.contains(&int1) );
CPPUNIT_ASSERT( ! bag.contains(&int16) );
CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
CPPUNIT_ASSERT( bag.contains(&int3) );
// remove 3 (no collision for this one)
CPPUNIT_ASSERT( bag.removeReference(&int3) == &int3 );
// Check that everything that should be is still there
CPPUNIT_ASSERT( bag.entries() == 2 );
CPPUNIT_ASSERT( bag.contains(&int1) );
CPPUNIT_ASSERT( ! bag.contains(&int16) );
CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
CPPUNIT_ASSERT( ! bag.contains(&int3) );
// remove 3 again - should fail this time
CPPUNIT_ASSERT( bag.removeReference(&int3) == NULL );
// Check that everything that should be is still there
CPPUNIT_ASSERT( bag.entries() == 2 );
CPPUNIT_ASSERT( bag.contains(&int1) );
CPPUNIT_ASSERT( ! bag.contains(&int16) );
CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
CPPUNIT_ASSERT( ! bag.contains(&int3) );
}
示例12: addTopologyResources
int MpTopologyGraph::addTopologyResources(MpResourceTopology& resourceTopology,
MpResourceFactory& resourceFactory,
UtlHashBag& newResources,
UtlBoolean replaceNumInName,
int resourceNum)
{
// Add the resources
int resourceIndex = 0;
MpResource* resourcePtr = NULL;
MpResource* resourceArray[MAX_CONSTRUCTED_RESOURCES];
UtlString resourceType;
UtlString resourceName;
MpConnectionID resourceConnId;
int resourceStreamId;
OsStatus result;
while(resourceTopology.getResource(resourceIndex, resourceType, resourceName,
resourceConnId, resourceStreamId) == OS_SUCCESS)
{
if(replaceNumInName)
{
MpResourceTopology::replaceNumInName(resourceName, resourceNum);
}
int numConstructorResources;
OsStatus status;
status = resourceFactory.newResource(resourceType, resourceName, MAX_CONSTRUCTED_RESOURCES,
numConstructorResources, resourceArray);
if(status == OS_SUCCESS)
{
assert(numConstructorResources > 0);
int arrayIndex;
// We now can potentially get more than one resource back from the
// constructor
for(arrayIndex = 0; arrayIndex < numConstructorResources; arrayIndex++)
{
resourcePtr = resourceArray[arrayIndex];
assert(resourcePtr);
if(resourcePtr)
{
#ifdef TEST_PRINT
printf("constructed and adding resource name: %s type: %s\n",
resourcePtr->getName().data(),
resourceType.data());
#endif
if(replaceNumInName && resourceConnId == MP_INVALID_CONNECTION_ID)
{
resourcePtr->setConnectionId(resourceNum);
}
else
{
resourcePtr->setConnectionId(resourceConnId);
}
resourcePtr->setStreamId(resourceStreamId);
newResources.insert(resourcePtr);
result = addResource(*resourcePtr, FALSE);
assert(result == OS_SUCCESS);
}
}
}
else
{
OsSysLog::add(FAC_MP, PRI_ERR,
"Failed to create resource type: %s name: %s status: %d",
resourceType.data(), resourceName.data(), status);
}
resourceIndex++;
}
return(resourceIndex);
}
示例13: testClear
/*!a test the removeAll() method.
*
* The test data for this method is
* a) When the list is empty
* b) When the list has one entry.
* c) When the list multiple entries
* d) When removeAll has been called and entries are added again
* e) When the removeAll is called twice on the list.
* f) When the removeAll is call on a list that has muliple entries
* for the same key.
*/
void testClear()
{
const int testCount = 6 ;
const char* prefix = "Test the removeAll() method when :- " ;
const char* Msgs[] = { \
"the list is empty", \
"the list has one entry", \
"the list has multiple entries", \
" has been called and entries are added again", \
"removeAll() has already been called", \
"removeAll() is called on list that has multiple matches" \
} ;
const char* suffix = " :- Verify number of entries after removeAll()" ;
UtlHashBag uSingleList ;
UtlHashBag uAddAfterClear ;
UtlHashBag uDoubleClear ;
// populate the hashtable with the 'common' values
UtlHashBag commonList_Clone ;
for (int i = 0 ; i < commonEntriesCount ; i++)
{
commonList_Clone.insert(commonContainables_Clone[i]) ;
}
// Add two values such that one of them has a 'value'
// match already in the table and the other one has
// a ref match.
commonList_Clone.insert(commonContainables_Clone[3]) ;
commonList_Clone.insert(commonContainables[5]) ;
// Add a single entry to the list that is to be made up
// of just one element
uSingleList.insert(&commonString1) ;
// call removeAll() on a list and then add entries again.
uAddAfterClear.insert(&commonInt1) ;
uAddAfterClear.insert(&commonString1) ;
uAddAfterClear.removeAll() ;
uAddAfterClear.insert(&commonInt2) ;
// call removeAll on a list twice.
uDoubleClear.insert(&commonString3) ;
uDoubleClear.insert(&commonInt3) ;
uDoubleClear.removeAll() ;
UtlHashBag* testLists[] = { \
&emptyList, &uSingleList, &commonList, &uAddAfterClear, &uDoubleClear, &commonList_Clone
} ;
int expEntries[] = { 0 , 0, 0, 1, 0, 0} ;
// since we are not calling removeAll for all the lists, do it outside the for loop for those
// that require to be cleared.
emptyList.removeAll() ;
uSingleList.removeAll() ;
commonList.removeAll() ;
commonList_Clone.removeAll() ;
// no removeAll() for uAddAfterClear
uDoubleClear.removeAll() ;
for ( int j = 0 ; j < testCount ; j++)
{
string msg ;
TestUtilities::createMessage(3, &msg, prefix, Msgs[j], suffix) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data() , expEntries[j], (int)testLists[j] -> entries()) ;
}
} //testClear()
示例14: 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()) ;
}
示例15: updateFile
OsStatus OsConfigDb::updateFile(const char* filename) const
{
UtlString originalFileContents;
long fileLength = OsFile::openAndRead(filename, originalFileContents);
const char* unparsedBits = originalFileContents;
int unparsedLength = originalFileContents.length();
// Loop through and try to preserve comments, space and order
int lineStart = 0;
int lineEnd = 0;
UtlHashBag writtenNames;
UtlString newFileContents;
UtlString name;
UtlString value;
UtlString newValue;
while(lineStart < unparsedLength)
{
lineEnd = UtlTokenizer::nextDelim(unparsedBits, lineStart, unparsedLength, "\n\r");
//printf("start: %d end: %d length: %d\n", lineStart, lineEnd, unparsedLength);
UtlString oneLine(&unparsedBits[lineStart], lineEnd - lineStart);
//printf("Line: <%s>\n", oneLine.data());
// If line contains a parameter
if(parseLine(oneLine, mCapitalizeName, filename, name, value))
{
//printf("name<%s> value<%s>\n", name.data(), value.data());
if(get(name, newValue) == OS_SUCCESS &&
!writtenNames.contains(&name))
{
//printf("Wrote name<%s>\n", name.data());
// The parameter still exists in the configDb and we have not yet
// written it out, write the potentially changed value
newFileContents.appendFormat("%s : %s\n", name.data(), newValue.data());
// Save names/parameters written so that we can figure out what has not
// been written out
writtenNames.insert(new UtlString(name));
}
// else the parameter was removed, do nothing
}
// The line was a comment or blank line, write it back out the same
else
{
newFileContents.appendFormat("%s\n", oneLine.data());
}
lineStart = lineEnd + 1;
}
int paramIndex;
int paramCount = numEntries();
DbEntry* paramEntry;
for (paramIndex = 0; paramIndex < paramCount; paramIndex++)
{
paramEntry = (DbEntry*) mDb.at(paramIndex);
removeNewlineReturns(paramEntry->key);
removeNewlineReturns(paramEntry->value);
// We have not written the value yet
if(!writtenNames.contains(&(paramEntry->key)))
{
newFileContents.appendFormat("%s : %s\n", paramEntry->key.data(), paramEntry->value.data());
writtenNames.insert(new UtlString(paramEntry->key));
}
}
fileLength = OsFile::openAndWrite(filename, newFileContents);
writtenNames.destroyAll();
return(fileLength > 0 ? OS_SUCCESS : OS_INVALID_ARGUMENT);
}