本文整理汇总了C++中UtlDList::append方法的典型用法代码示例。如果您正苦于以下问题:C++ UtlDList::append方法的具体用法?C++ UtlDList::append怎么用?C++ UtlDList::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UtlDList
的用法示例。
在下文中一共展示了UtlDList::append方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testGet
/*!a Test case for the get() method.
*
* The test data for this test is :-
* 1) The first entry is a CollectableString
* 2) The first entry is a CollectableInt
* 3) The List has only one entry
* 4) The List has no entries
*/
void testGet()
{
const int testCount = 4 ;
const char* prefix = "Verify the get() method for a list when " ;
const char* Msgs[] = { \
"the first entry is a CollectableString", \
"the first entry is a CollectableInt", \
"when the list has only one entry", \
"when the list is empty" \
} ;
const char* suffix1 = ":- verify return value" ;
const char* suffix2 = ":- verify the number of entries in the list" ;
UtlDList testList ;
testList.append(&commonString1) ;
testList.append(&commonInt1) ;
testList.append(&commonString2) ;
UtlContainable* expectedValue[] = { \
&commonString1 , &commonInt1, &commonString2, NULL \
} ;
int entryCount[] = { 2, 1, 0, 0 } ;
for (int i = 0 ; i < testCount ; i++)
{
UtlContainable* actual = testList.get() ;
string msg ;
TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], actual) ;
TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entryCount[i], (int)testList.entries()) ;
}
} //testGet()
示例2: testClearAndDestroy
/*!a Test case to test the destroyAll()
* method.
*/
void testClearAndDestroy()
{
const char* prefix = "test the destroyAll() method " ;
const char* suffix1 = ":- Verify that all entries are removed" ;
const char* suffix2 = ":- The objects are deleted" ;
UtlContainableTestStub* uStub ;
UtlContainableTestStub* uStubPtr ;
uStub = new UtlContainableTestStub(0) ;
uStubPtr = new UtlContainableTestStub(1) ;
emptyList.append(uStub) ;
emptyList.append(uStubPtr) ;
emptyList.destroyAll() ;
int cCountAfter = UtlContainableTestStub::getCount() ;
string msg ;
TestUtilities::createMessage(2, &msg, prefix, suffix1) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ;
// Since the TestStub has been implemented such that destructor
// decrements the static counter, to verify that the objects have
// been deleted, verify that the static counter has been decremented.
TestUtilities::createMessage(2, &msg, prefix, suffix2) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;
} //testClearAndDestroy
示例3: testRemoveAndDestroy
/*!a Test case to test the destroy()
* method.
*/
void testRemoveAndDestroy()
{
const char* prefix = "test the destroy() method " ;
UtlContainableTestStub uStub(0) ;
UtlContainableTestStub* uStubPtr ;
uStubPtr = new UtlContainableTestStub(1) ;
commonList.append(&uStub) ;
commonList.append(uStubPtr) ;
int cCountBefore = UtlContainableTestStub :: getCount() ;
UtlBoolean returnValue = commonList.destroy(uStubPtr) ;
UtlContainable* uLast = commonList.last() ;
string msg ;
TestUtilities::createMessage(2, &msg, prefix, ":- Verify the return value") ;
CPPUNIT_ASSERT_MESSAGE(msg.data(), returnValue) ;
TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the entry is removed") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)&uStub, (void*)uLast) ;
// The CollectableTestStub has been implemented such that a static counter gets decremented
// for every descruction of an object instance. To verify that the object was destroyed,
// verify that the static count went down.
int cCountAfter = UtlContainableTestStub :: getCount() ;
TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the object was deleted") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;
}
示例4: 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.
* d) When all the entries in a list have been removed using get.
* e) When all the entries in a list have been removed using removeAll()
*/
void testIsEmpty()
{
const int testCount = 5 ;
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 retreieved using get()", \
"all the list entries have been retreived using removeAll()" \
} ;
UtlDList newList ;
UtlDList secondNewList ;
UtlDList commonList_Clone ;
// first populate a list and then retreive all elements using get
for (int i = 0 ; i < commonEntriesCount ; i++)
{
commonList_Clone.append(commonContainables_Clone[i]) ;
}
for (int j = 0 ; j < commonEntriesCount; j++)
{
commonList_Clone.get();
}
UtlString uS1 = UtlString("Lone Entry") ;
newList.append(&uS1) ;
// populate the second list and then clear all entries.
secondNewList.append(&uS1) ;
UtlInt uI1 = UtlInt(232) ;
secondNewList.append(&uI1) ;
secondNewList.removeAll() ;
UtlDList* testLists[] = { \
&emptyList, &newList, &commonList, &commonList_Clone, &secondNewList \
} ;
bool expectedValue[] = { true, false, false, true, true } ;
for (int k = 0 ; k < testCount; k++)
{
string msg ;
TestUtilities::createMessage(2, &msg, prefix, Msgs[k]) ;
UtlBoolean actual = testLists[k] -> isEmpty() ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)expectedValue[k], \
actual) ;
}
} // testIsEmpty
示例5: testAdvancingOperator
/*!a Test case for the () operator.
*
* The test data for this test is :-
* 1) The next entry is a UtlString
* 2) The next entry is a UtlInt
* 3) The next entry is the last entry
* 4) All entries have been read
*/
void testAdvancingOperator()
{
const int testCount = 4 ;
const char* prefix = "Verify the () operator for an iterator when " ;
const char* Msgs[] = { \
"the first entry is a UtlString", \
"the first entry is a UtlInt", \
"when the list has only one entry", \
"when the list is empty" \
} ;
const char* suffix1 = " :- verify return value" ;
const char* suffix2 = " :- verify number of entries in the list" ;
UtlDList testList ;
testList.append(&commonString1) ;
testList.append(&commonInt1) ;
testList.append(&commonString2) ;
UtlDListIterator iter(testList) ;
UtlContainable* exp[] = { \
&commonString1 , &commonInt1, &commonString2, NULL \
} ;
int expEntries = 3 ;
for (int i = 0 ; i < testCount ; i++)
{
UtlContainable* act = iter() ;
string msg ;
TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), exp[i], act) ;
TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2);
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expEntries, (int)testList.entries()) ;
}
// Test the () operator for an empty list
UtlDListIterator emptyIter(emptyList) ;
UtlContainable* act = emptyIter() ;
CPPUNIT_ASSERT_EQUAL_MESSAGE("Test the () operator for an empty list iterator" , (void*)NULL, (void*)act) ;
} //testAdvancingOperator()
示例6: setUp
void setUp()
{
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.append(&commonString1) ;
commonContainables[0] = &commonString1 ;
commonContainables_Clone[0] = &commonString1_clone ;
commonList.append(&commonInt1) ;
commonContainables[1] = &commonInt1 ;
commonContainables_Clone[1] = &commonInt1_clone ;
commonList.append(&commonInt2) ;
commonContainables[2] = &commonInt2 ;
commonContainables_Clone[2] = &commonInt2_clone;
commonList.append(&commonString2) ;
commonContainables[3] = &commonString2 ;
commonContainables_Clone[3] = &commonString2_clone ;
commonList.append(&commonInt3) ;
commonContainables[4] = &commonInt3 ;
commonContainables_Clone[4] = &commonInt3_clone ;
commonList.append(&commonString3) ;
commonContainables[5] = &commonString3 ;
commonContainables_Clone[5] = &commonString3_clone ;
}
示例7: 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
* d) When the removeAll is called twice on the list.
*/
void testClear()
{
const int testCount = 5 ;
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", \
"removeAll() has been called and entries are added again", \
"removeAll() has already been called", \
} ;
const char* suffix = " :- Verify number of entries after removeAll()" ;
UtlDList uSingleList ;
UtlDList uAddAfterClear ;
UtlDList uDoubleClear ;
uSingleList.append(&commonString1) ;
// call removeAll() on a list and then add entries again.
uAddAfterClear.append(&commonInt1) ;
uAddAfterClear.append(&commonString1) ;
uAddAfterClear.removeAll() ;
uAddAfterClear.append(&commonInt2) ;
// call removeAll on a list twice.
uDoubleClear.append(&commonString3) ;
uDoubleClear.append(&commonInt3) ;
uDoubleClear.removeAll() ;
UtlDList* testLists[] = { \
&emptyList, &uSingleList, &commonList, &uAddAfterClear, &uDoubleClear
} ;
int expectedEntries[] = { 0 , 0, 0, 1, 0 } ;
// since we are not calling removeAll for all the data, do it outside the for loop.
emptyList.removeAll() ;
uSingleList.removeAll() ;
commonList.removeAll() ;
// no removeAll() for uAddAfterClear
uDoubleClear.removeAll() ;
for ( int i = 0 ; i < testCount ; i++)
{
string msg ;
TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data() , expectedEntries[i], \
(int)testLists[i]->entries()) ;
}
} //testClear()
示例8: testFirst_And_Last
/*!a Test case to test the first() and last() method.
*
* The test data for this test case is :-
* a) Test the first and last element after appending
* b) Test the first and last element after insertAt(midlevel)
* c) Test the first and last element after insertAt(0)
* d) Test the first and last element after insertAt(last)
*/
void testFirst_And_Last()
{
const char* prefix1 = "Test the first() method ";
const char* prefix2 = "Test the last() method " ;
string msg ;
UtlContainable* uActual ;
UtlContainable* uData ;
UtlContainable* uExpected ;
const char* Msgs[] = { \
"after appending ", \
"after insertAt(0) ", \
"after insertAt(last) ", \
"after insertAt(mid-level) " \
} ;
// Since this testcase requires a different test data
// for each of its test data, the regula test-matrix
// technique is not being used here.
// create a new list and append one element to it.
UtlDList testList ;
uData = commonContainables[0] ;
testList.append(uData);
// Test the first() and last() element immeidately after
// appending to an empty list.
TestUtilities::createMessage(2, &msg, prefix1, Msgs[0]);
uActual = testList.first() ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uData, uActual) ;
uActual = testList.last() ;
TestUtilities::createMessage(2, &msg, prefix2, Msgs[0]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uData, uActual) ;
// insert more values to populate the List
testList.append(commonContainables[1]) ;
testList.append(commonContainables[2]) ;
// test the first() / last() methods
// after insertAt(0..)
uData = commonContainables[3] ;
testList.insertAt(0, uData) ;
uExpected = commonContainables[3] ;
uActual = testList.first() ;
TestUtilities::createMessage(2, &msg, prefix1, Msgs[1]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
uExpected = commonContainables[2] ;
uActual = testList.last() ;
TestUtilities::createMessage(2, &msg, prefix2, Msgs[1]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
// test after inserting at the last location
uData = commonContainables[4] ;
testList.insertAt(4, uData) ;
uExpected = commonContainables[3] ;
uActual = testList.first() ;
TestUtilities::createMessage(2, &msg, prefix1, Msgs[2]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
uExpected = commonContainables[4] ;
uActual = testList.last() ;
TestUtilities::createMessage(2, &msg, prefix2, Msgs[2]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
//test after inserting at the midLocation
uData = commonContainables[5] ;
testList.insertAt(2, uData) ;
uExpected = commonContainables[3] ;
uActual = testList.first() ;
TestUtilities::createMessage(2, &msg, prefix1, Msgs[3]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
uExpected = commonContainables[4] ;
uActual = testList.last() ;
TestUtilities::createMessage(2, &msg, prefix2, Msgs[3]) ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
} //testFirst_And_Last
示例9: utlTestAppend_Insert
void utlTestAppend_Insert(TestInsertOrAppend type)
{
int testCount = 2 ;
const char* prefix = "";
UtlInt testInt(1234) ;
UtlString testString("Test String") ;
if (type == TEST_APPEND)
{
commonList.append(&testInt) ;
commonList.append(&testString) ;
prefix = "Test the append(UtlContainable*) method for a non empty list" ;
}
else if (type == TEST_INSERT)
{
commonList.insert(&testInt) ;
commonList.insert(&testString) ;
prefix = "Test the insert(UtlContainable*) method for a non empty list" ;
}
int expectedCount = commonEntriesCount + testCount ;
UtlContainable* uActual ;
UtlContainable* uExpected ;
string msg ;
// Verify that the number of entries has increased accordingly
TestUtilities::createMessage(2, &msg, prefix, " :- Verify the number of entries") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedCount, \
(int)commonList.entries()) ;
// Verify that the first entry has still not changed.
uActual = commonList.at(0) ;
uExpected = commonContainables[0] ;
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify that the first entry is not changed") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ;
// Verify the entry at the previous last position
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify that the previous last entry is intact") ;
// Verify that the number of entries has increased accordingly
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify the number of entries") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedCount, \
(int)commonList.entries()) ;
// Verify that the first entry has still not changed.
uActual = commonList.at(0) ;
uExpected = commonContainables[0] ;
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify that the first entry is not changed") ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ;
// Verify the entry at the previous last position
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify that the previous last entry is intact") ;
uActual = commonList.at(commonEntriesCount-1) ;
uExpected = commonContainables[commonEntriesCount-1] ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ;
// Verify that the two new entries are added.
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify that the Collectable Integer has been added") ;
uActual = commonList.at(commonEntriesCount) ;
uExpected = &testInt ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ;
TestUtilities::createMessage(2, &msg, prefix, \
" :- Verify that the Collectable String has been added") ;
uActual = commonList.at(commonEntriesCount + 1) ;
uExpected = &testString ;
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ;
} //testAppend