コード例 #1
0
ファイル: UtlDList.cpp プロジェクト: Jaroslav23/sipxtapi
    /*!a  Test the occurancesOf() method .
    * 
    *     The test data for this test are :-
    *        a) When the search data is the first entry
    *        b) When the search data is the last entry
    *        c) When the search data is the mid(unique) entry
    *        d) When the search data has a matching value but not ref. 
    *        e) When the search data has multiple matches - mixture of ref / values
    *        f) When the search data has no match at all. 
    */
    void testOccurancesOf()
    {
        const int testCount = 6 ; 
        const char* prefix = "Test the occurancesOf(UtlContainable* cl); where cl " ; 
        const char* Msgs[] = { \
               "is the first entry ", \
               "is the last entry and ref matches ", \
               "is the mid entry and is unique ", \
               "has a matching value but not reference ", \
               "has multiple matches ", \
               "has no match at all " \
        } ; 

        commonList.insertAt(3, commonContainables_Clone[4]) ; 
        commonList.insertAt(5, commonContainables[4]) ; 
        UtlString notExistCollectable("This cannot and willnot exist"); 
       
        UtlContainable* searchValues[] = { \
                   commonContainables[0], commonContainables[commonEntriesCount -1], \
                   commonContainables[2], commonContainables_Clone[3], \
                   commonContainables[4], &notExistCollectable \
        } ;        
        size_t matchCount[] = { 1, 1, 1, 1, 3, 0 } ; 
        for (int i = 0 ; i < testCount ; i++)
        {
            string msg ; 
            TestUtilities::createMessage(2, &msg, prefix, Msgs[i]) ; 
            size_t actual = commonList.occurrencesOf(searchValues[i]) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), matchCount[i], actual) ; 
        }
    } //testOccurancesOf
コード例 #2
0
ファイル: UtlDListIterator.cpp プロジェクト: Konnekt/lib-sipx
    /*!a Test case for the findNext() method
    *
    *    The test data for this test case are :-
    *      a) When the match is the first element.
    *      b) When the match is the last element.
    *      c) When the match is a mid element(unique).
    *      d) When the match has two value matches (but a single ref match)
    *      e) When the match has two ref matches.
    *      f) When there is no match at all!
    *      g) When the match is after the current find.
    */
    void testFindNext()
    {
        const int testCount = 7 ;
        const char* prefixFind = "Test the find() method when the match " ;
        const char* Msgs[] = { \
                               "is the first element ", \
                               "is the last element ", \
                               "is a mid element (unique match) ", \
                               "has two value matches but a single ref match ", \
                               "has two ref matches", \
                               "has a value match but no ref match", \
                               "has no match at all" \
                             } ;
        // insert a clone of the 4th element to the 1st position
        commonList.insertAt(1, (UtlContainable*)commonContainables_Clone[4]) ;
        // The new index for a value match of commonContainables[4] must be 1.

        // insert another copy of the 3rd element to the 2nd position.
        commonList.insertAt(2, (UtlContainable*)commonContainables[3]) ;
        // The new index for commonContainables[3] must be 2) ;
        // what used to be the second element has now moved to 4.

        UtlString noExist("This cannot and should not exist!!!") ;
        const UtlContainable* searchValuesForFind[] = { \
                                                        commonContainables[0], commonContainables[5], commonContainables[2], \
                                                        commonContainables[4], commonContainables[3], \
                                                        commonContainables_Clone[1], &noExist \
                                                      } ;
        const UtlContainable* expValuesForFind[] = { \
                                                     commonContainables[0], commonContainables[5], commonContainables[2], \
                                                     commonContainables_Clone[4], commonContainables[3], \
                                                     commonContainables[1], NULL \
                                                   } ;

        UtlDListIterator iter(commonList) ;
        for (int i = 0 ; i < testCount ; i++)
        {
            string msg ;

            const UtlContainable* act = iter.findNext(searchValuesForFind[i]) ;
            const UtlContainable* exp = expValuesForFind[i] ;
            TestUtilities::createMessage(2, &msg, prefixFind, Msgs[i]) ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), exp, act) ;
            iter.reset() ;
        }

        // Now test the case where the iterator is 'past' the index
        iter.reset() ;
        iter() ;
        iter() ;
        iter() ;
        iter() ;
        iter() ;
        UtlContainable* act = iter.findNext(commonContainables[1]) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE("test findNext() when the iterator has moved past the search index", (void*)NULL, (void*)act) ;
    }//testFindNext
コード例 #3
0
ファイル: UtlDList.cpp プロジェクト: Jaroslav23/sipxtapi
    /*!a! Test case to verify insertAt(size_t, UtlContainable*) for an 
    *     empty list. 
    *     The test data for this test are 
    *     a) Insert a UtlString to the 0th location, 
    *     b) Insert a UtlInt to the 0th location, 
    *     c) Insert any UtlContainable object to a 'non-zero' location
    */
    void testInsertAt_EmptyList()
    {
        const int testCount = 3 ; 
        const char* prefix = "Test insert(n, Collectable*) for an empty list; "\
             "where Collectable is "  ; 
        const char* Msgs[] = { \
               "a UtlString and n = 0", \
               "a UtlInt and n = 0", \
               "a UtlContainableXXX and n > 0" \
        }; 
        const char* suffix1 = " :- Verify return value" ; 
        const char* suffix2 = " :- Verify value is appended"  ; 

        UtlInt testInt(102) ; 
        UtlString testString("Test String") ; 
        UtlString testNegative("This should not get added") ; 
        UtlContainable* itemToAdd[] = { &testString, &testInt, &testNegative } ; 
        UtlContainable* expectedValue[] = { &testString, &testInt, NULL} ; 
        int insertLocation[] = { 0, 0, 1} ; 
        for (int i = 0 ; i < testCount ; i++)
        {
            UtlDList testList ; 
    
            string msg ; 
            // insertAt now returns void. Retain this block of comment in case 
            // we (I think we should return a Collectable / bool) decide to return
            // a collectable. 

            UtlContainable* result = testList.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], result) ;

            testList.insertAt(insertLocation[i], itemToAdd[i]) ; 
            // verify that the value is inserted 
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], testList.at(0)) ; 
        }
    }//testInsertAt_EmptyList
コード例 #4
0
ファイル: UtlDList.cpp プロジェクト: Jaroslav23/sipxtapi
    /*!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()
コード例 #5
0
ファイル: UtlDList.cpp プロジェクト: Jaroslav23/sipxtapi
    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
コード例 #6
0
ファイル: UtlDList.cpp プロジェクト: Jaroslav23/sipxtapi
    // Since the test setup / preconditions for the index, find, 
    // contains and containsReference are all the same, these
    // tests have been combined into one utility function. Based
    // on the type argument, the method to be tested is varied. 
    void utlTestIndex_Find_And_Contains(IndexOrContains type)
    {
        const int testCount = 7 ; 
        const char* prefixIndex = "Test the index() method when the match " ; 
        const char* prefixFind = "Test the find() method when the match " ; 
        const char* prefixContains = "Test the contains() method when the match " ; 
        const char* prefixContainsRef = "Test the containsReference() method when the match " ; 
        const char* Msgs[] = { \
               "is the first element ", \
               "is the last element ", \
               "is a mid element (unique match) ", \
               "has two value matches but a single ref match ", \
               "has two ref matches", \
               "has a value match but no ref match", \
               "has no match at all" \
        } ; 
        // insert a clone of the 4th element to the 1st position
        commonList.insertAt(1, commonContainables_Clone[4]) ; 
       // The new index for a value match of commonContainables[4] must be 1. 

       // insert another copy of the 3rd element to the 2nd position. 
       commonList.insertAt(2, commonContainables[3]) ; 
       // The new index for commonContainables[3] must be 2) ; 
       // what used to be the second element has now moved to 4. 

       UtlString noExist("This cannot and should not exist!!!") ; 

       UtlContainable* searchValues[] = { \
                 commonContainables[0], commonContainables[5], commonContainables[2], \
                 commonContainables[4], commonContainables[3], \
                 commonContainables_Clone[2], &noExist \
       } ; 

       size_t expectedValues_Index[] = { 0, 7, 4, 1, 2, 4, UTL_NOT_FOUND } ; 
 
       bool expectedValues_Contains[]    = {true, true, true, true, true, true, false } ;
       bool expectedValues_ContainsRef[] = {true, true, true, true, true, false, false} ; 

       UtlContainable* searchValuesForFind[] = { \
                 commonContainables[0], commonContainables[5], commonContainables[2], \
                 commonContainables[4], commonContainables[3], \
                 commonContainables_Clone[1], &noExist \
       } ;
       UtlContainable* expectedValuesForFind[] = { \
                 commonContainables[0], commonContainables[5], commonContainables[2], \
                 commonContainables_Clone[4], commonContainables[3], \
                 commonContainables[1], NULL \
       } ;

       for (int i = 0 ; i < testCount ; i++)
       {
           string msg ; 
           if (type == TEST_INDEX) 
           {
               size_t actual = commonList.index(searchValues[i]) ; 
               TestUtilities::createMessage(2, &msg, prefixIndex, Msgs[i]) ; 
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_Index[i], actual) ; 
           } 
           else if (type == TEST_FIND) 
           {
               UtlContainable* actual = commonList.find(searchValuesForFind[i]) ; 
               TestUtilities::createMessage(2, &msg, prefixFind, Msgs[i]) ; 
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValuesForFind[i], actual) ;
           }
           else if (type == TEST_CONTAINS) 
           {
               UtlBoolean actual = commonList.contains(searchValues[i]) ; 
               TestUtilities::createMessage(2, &msg, prefixContains, Msgs[i]) ; 
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_Contains[i], \
                  (TRUE == actual)) ; 
           }
           else if (type == TEST_CONTAINS_REF)
           {
               UtlBoolean actual = commonList.containsReference(searchValues[i]) ;
               TestUtilities::createMessage(2, &msg, prefixContainsRef, Msgs[i]) ;
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_ContainsRef[i], \
                   (TRUE == actual)) ;
           }
       }
    }//utlTestIndex
コード例 #7
0
ファイル: UtlDList.cpp プロジェクト: Jaroslav23/sipxtapi
    /*!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