Beispiel #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.
    *        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
Beispiel #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
    *        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()