Example #1
0
    /*!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) ; 
    }
void doListOperations()
{
   UtlSList testList;

   // fill the list
   appendCountItems(testList, NUM_PERFORMANCE_STRINGS);
   
   // take the first half off the front
   if (!testList.isEmpty())
   {
      getCountItems(testList, NUM_PERFORMANCE_STRINGS / 2);
   }

   // take the rest off the end by reference
   if (!testList.isEmpty())
   {
      UtlContainable* lastItem = testList.last();
      delete dynamic_cast<UtlString*>(testList.removeReference(lastItem));
   }

   // fill the list
   appendCountItems(testList, NUM_PERFORMANCE_STRINGS);

   // search the list for each item by value
   UtlString target;
   int targetIndex;
   for (targetIndex = 0; targetIndex < NUM_PERFORMANCE_STRINGS; targetIndex += 1)
   {
      target = string[targetIndex];
      UtlString* found = dynamic_cast<UtlString*>(testList.find(&target));
      if (found)
      {
         externalForSideEffects = found->length();
      }
   }
   
   // get the object in the middle of the list by index, and remove it by value
   while(!testList.isEmpty())
   {
      int numberLeft = testList.entries();
      UtlString* middle = dynamic_cast<UtlString*>(testList.at((numberLeft / 2)));
      delete dynamic_cast<UtlString*>(testList.remove(middle));
   }

   // fill the list
   appendCountItems(testList, NUM_PERFORMANCE_STRINGS);

   // iterate over each item in the list
   UtlSListIterator iterate(testList);
   UtlString* item;
   while ((item = dynamic_cast<UtlString*>(iterate())))
   {
      externalForSideEffects = item->length();
      delete item;
   }
}
Example #3
0
    /*!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. 
        UtlSList 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