Esempio n. 1
0
    /*!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
Esempio n. 2
0
    /*!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()