Example #1
0
    /*!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
Example #2
0
    /*!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()
Example #3
0
 /*a! This test is more of a sanity check to verify that
 *    the basic append(), entries() and at() methods work as expected.
 *    All future tests will depend heavily on the at() method
 *    and the most common way of having something in the list is
 *    by means of the append() method. 
 *
 */
 void checkSanity_Append_Entries_And_At()
 {
     for (int i = 0 ; i < commonEntriesCount; i++)
     {
         UtlContainable* ucExpected = commonContainables[i] ; 
         UtlContainable* ucActual = commonList.at(i) ; 
         string msg ; 
         char strItr[33] ; 
         sprintf(strItr, "%d", i);
         TestUtilities::createMessage(3, &msg, "Verify that the at(n) method, where n = ", \
             strItr, " ;") ; 
         CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), ucExpected, ucActual) ; 
     }
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Verify that the entries() for an empty list returns 0", \
             (int)emptyList.entries(), 0) ; 
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Verify the entries() method for a list", \
             (int)commonList.entries(), commonEntriesCount) ; 
 }// checkSanity_Append_And_At()
Example #4
0
    /*!a Test case to verify insertAt(size_t, UtlContainable*) for a
    *     list that is not empty.
    *     The test data for this test are
    *     a) Insert any UtlContainable to the 0th location,
    *     b) Insert a UtlInt to a 'mid' location,
    *     c) Insert any UtlString object to a 'mid' location
    *     d) Insert any UtlContainable object to the last location
    */
    void testInsertAt_NonEmptyList()
    {
        const int testCount = 4 ;
        const char* prefix = "Test insert(n, Collectable*) for a list that is not empty; "\
              "where Collectable is "  ;
        const char* Msgs[] = { \
               "a UtlContainableXXX and n = 0", \
               "a UtlString and n > 0 && n < size", \
               "a UtlInt and n > 0 && n < size", \
               "a UtlContainableXXX where n = size-1" \
        };
        const char* suffix1 = " :- Verify return value" ; 
        const char* suffix2 = " :- Verify value is appended"  ; 
        const char* suffix3 = " :- Verify new list size" ;  

        UtlString testFirst("First Entry") ; 
        UtlInt testInt(102) ;
        UtlString testString("Test String") ;
        UtlInt testLast(99999) ; 
        UtlContainable* itemToAdd[] = { &testFirst, &testInt, &testString, &testLast } ;
        UtlContainable* expectedValue[] = { &testFirst, &testInt, &testString, &testLast} ;
        int insertLocation[] = { 0, 2, 3, commonEntriesCount+3} ;
        int tmpCount = commonEntriesCount ; 
        int expectedEntries[] = {++tmpCount, ++tmpCount, ++tmpCount, ++tmpCount} ; 

        for (int i = 0 ; i < testCount ; i++)
        {
            UtlContainable* uActual ; 
            string msg ; 
              
            // comment out for now. Uncomment if implementation returns Collectable
            uActual = commonList.insertAt(insertLocation[i], itemToAdd[i]);
            //verify that the right value is returned.
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], uActual) ;
            //`commonList.insertAt(insertLocation[i], itemToAdd[i]);

            // verify that the value is inserted
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; 
            uActual = commonList.at(insertLocation[i]) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], uActual) ;
 
            //verify that the total number of entries has incremented by one. 
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix3) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedEntries[i], \
                (int)commonList.entries()) ; 
            
        }
    }//testInsertAt_NonEmptyList()
Example #5
0
    /*!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()
Example #6
0
    /*!a Test case for the insertAfterPoint() method.
    *
    *    The test data is :-
    *      a) Insert when the iterator is the starting position
    *      b) Insert when the iterator is at mid position
    *      c) Insert when the iterator is at the last position
    *      d) Insert to an empty Iterator.
    */
    void testInsertAfterPoint()
    {
        const char* prefix = "Test the insertAfterPoint() method when " ;
        const char* Msgs[] = {\
                              "the iterator is the starting position " , \
                              "the iterator is at mid-position ", \
                              "the iterator is at the last position " \
                             } ;
        const char* suffix1 = ":- Verify return value" ;
        const char* suffix2 = ":- Verify value is inserted" ;
        const char* suffix3 = ":- Verify that previous value is not lost" ;
        UtlDListIterator iter(commonList) ;
        const UtlContainable* uReturn ;
        UtlContainable* uAppended ;
        UtlContainable* uOrig ;
        string msg ;

        UtlString newColString1("Insert at starting position") ;
        UtlInt newColInt2(101) ;
        UtlString newColString3 ("Insert at last position") ;

        UtlContainable* insertValues[] = { \
                                           &newColString1, &newColInt2, &newColString3 \
                                         };
        const UtlContainable* oldValues[] = { \
                                              commonContainables[0], commonContainables[1], commonContainables[5] \
                                            } ;

        // Since this test requires different steps for the different test data,
        // steps are executed individually rather than the regular technique of
        // iterating through the test-array loop

        //Test#1 - Verify the case when the iterator has been reset
        int ti = 0 ;
        iter.reset() ;
        uReturn = iter.insertAfterPoint(insertValues[ti]) ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE (msg.data(), (void*)insertValues[ti], (void*)uReturn) ;
        // The item is inserted at first position
        // old[0] is now @ pos1. old[1] is now @ pos2
        iter.reset() ;
        uAppended = iter() ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)insertValues[ti], (void*)uAppended) ;
        // Verify that the original item is still retained.
        uOrig = iter() ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)oldValues[ti], (void*)uOrig) ;

        //Test#2 - inserting at mid position
        ti = 1;
        iter.reset() ;
        iter() ; //moves cursor to 0
        iter() ; //moves cursor to 1
        iter() ; //moves cursor to 2
        // old[1] stays at pos2
        // Value is now inserted at pos3
        uReturn = iter.insertAfterPoint(insertValues[ti]) ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE (msg.data(), (void*)insertValues[ti], (void*)uReturn) ;
        iter.reset() ;
        iter() ;  // moves cursor to 0
        iter() ; // moves cursor to 1
        // Verify that the original item is still retained.
        uOrig = iter() ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix3) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)oldValues[ti], (void*)uOrig) ;
        // The item is inserted just after the position.
        uAppended = iter() ; //moves cursor to pos3 and returns item at pos2
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)insertValues[ti], (void*)uAppended) ;

        // Test#3 - Now verify when the cursor is at the last position.
        ti = 2 ;
        iter.reset() ;
        iter.toLast() ;
        uReturn = iter.insertAfterPoint(insertValues[ti]) ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)insertValues[ti], (void*)uReturn) ;
        iter.reset() ;
        // now move the cursor all the way to the penultimate position
        for (size_t i = 0 ; i < commonList.entries() - 1; i++)
        {
            uOrig = iter() ;
        }
        // verify original is still retained.
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix3) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)oldValues[ti], (void*)uOrig) ;
        uAppended = iter() ;
        TestUtilities::createMessage(3, &msg, prefix, Msgs[ti], suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE( msg.data(), (void*)insertValues[ti], (void*)uAppended) ;

    } //testInsertAfterPoint
Example #7
0
    void utlTestRemove(RemoveType type)
    {

        int testCount = 5 ; 
        const char* prefix = "";
        if (type == TEST_REMOVE)
        {
            prefix = "test the remove(UtlContainable* c) method where c" ;

        }
        else if (type == TEST_REMOVE_REF)
        {
            prefix = "test the removeReference(UtlContainable* c) where c" ;
        }
        const char* Msgs[] = { \
               "is the first entry's reference ", \
               "is the last entry' reference ", \
               "is the mid entry's value(not reference) ", \
               "is the first of multiple matches and is the value match ", \
               "has no match at all " \
        } ;
        const char* suffix1 = " :- Verify returned value" ; 
        const char* suffix2 = " :- Verify total entries" ; 

        commonList.insertAt(2, commonContainables_Clone[4]) ; 

        UtlString notExistCollectable("This cannot and willnot exist");
    
        UtlContainable* itemToRemove[] = { \
                           commonContainables[0], commonContainables[commonEntriesCount -1 ], \
                           commonContainables_Clone[2], commonContainables[4], \
                           &notExistCollectable \
        } ; 
        
        int totalEnt = commonEntriesCount + 1; 

        UtlContainable* expectedValue[] = { \
                           commonContainables[0], commonContainables[commonEntriesCount -1 ], \
                           commonContainables[2], commonContainables_Clone[4], \
                           NULL \
        }; 
        
 
        int entriesValue[] = { --totalEnt, --totalEnt, --totalEnt, --totalEnt, totalEnt } ; 

        totalEnt = commonEntriesCount + 1;

        UtlContainable* expectedRef[] = { \
                           commonContainables[0], commonContainables[commonEntriesCount -1 ], \
                           NULL, commonContainables[4], \
                           NULL \
        };
        int entriesRef[] = { --totalEnt, --totalEnt, totalEnt, --totalEnt, totalEnt } ;
        
        for (int i = 0 ; i < testCount ; i++)
        {
            
            string msg ; 
            if (type == TEST_REMOVE)
            {
                TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ;
                
                UtlContainable* retValue = commonList.remove(itemToRemove[i]) ;
                CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(),  expectedValue[i], retValue) ; 
                TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; 
                CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entriesValue[i], (int)commonList.entries()) ; 
            }
            else if (type == TEST_REMOVE_REF)
            {
 
                UtlContainable* uRemoved = commonList.removeReference(itemToRemove[i]) ; 
                TestUtilities::createMessage(3, &msg, prefix, Msgs[i],  suffix2) ; 
                CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedRef[i], uRemoved) ; 
                TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ;
                CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entriesRef[i], (int)commonList.entries()) ;
            }
        }
    } //utlRemove
Example #8
0
    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