コード例 #1
0
    /*!a test case for the interaction of remove() and item().
    */
    void removeItem()
    {
       UtlString v1("a");
       UtlString v2("b");
       UtlString v3("c");
       UtlString v4("d");
       UtlContainable* e;

       UtlSList h;
       h.insert(&v1);
       h.insert(&v2);
       h.insert(&v3);
       h.insert(&v4);

       UtlSListIterator iter(h);

       // Check that item() returns NULL in the initial state.
       CPPUNIT_ASSERT(iter.item() == NULL);

       // Step the iterator and check that item() returns v1.
       e = iter();
       CPPUNIT_ASSERT(e == &v1);
       CPPUNIT_ASSERT(iter.item() == &v1);

       // Delete the element and check that item() returns NULL.
       h.remove(e);
       CPPUNIT_ASSERT(iter.item() == NULL);

       // Step the iterator and check that item() returns v2.
       e = iter();
       CPPUNIT_ASSERT(e == &v2);
       CPPUNIT_ASSERT(iter.item() == &v2);

       // Step the iterator and check that item() returns v3.
       e = iter();
       CPPUNIT_ASSERT(e == &v3);
       CPPUNIT_ASSERT(iter.item() == &v3);

       // Delete the element and check that item() returns v2.
       // (Because deleting an element of a list backs the iterator up
       // to the previous element.)
       h.remove(e);
       CPPUNIT_ASSERT(iter.item() == &v2);

       // Step the iterator and check that item() returns v4.
       e = iter();
       CPPUNIT_ASSERT(e == &v4);
       CPPUNIT_ASSERT(iter.item() == &v4);

       // Step the iterator after the last element and check that
       // item() returns NULL.
       e = iter();
       CPPUNIT_ASSERT(e == NULL);
       CPPUNIT_ASSERT(iter.item() == NULL);

    } //removeItem()
コード例 #2
0
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;
   }
}
コード例 #3
0
ファイル: UtlSList.cpp プロジェクト: Konnekt/lib-sipx
    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
コード例 #4
0
ファイル: Plugin.cpp プロジェクト: Jaroslav23/sipxtapi
void PluginHooks::readConfig(OsConfigDb& configDb)
{
   OsSysLog::add(FAC_KERNEL, PRI_DEBUG, "PluginHooks::readConfig" );

   // Move any existing hooks from the current configured list to
   // a temporary holding list.
   UtlSList existingHooks;
   UtlContainable* existingHook;
   
   UtlSortedListIterator nextHook(mConfiguredHooks);
   while (existingHook = nextHook())
   {
      existingHooks.append(mConfiguredHooks.removeReference(existingHook));
   }
   // the mConfiguredHooks list is now empty
   
   // Walk the current configuration,
   //   any existing hook is moved back to the mConfiguredHooks list,
   //   newly configured hooks are added,
   //   each configured hook is called to read its own configuration.
   UtlString  hookPrefix(mPrefix);
   hookPrefix.append(HOOK_LIB_PREFIX);
   
   OsConfigDb allHooks;
   
   OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                 "PluginHooks::readConfig looking up hooks '%s'",
                 hookPrefix.data()
                 );
   if (OS_SUCCESS == configDb.getSubHash(hookPrefix, allHooks)) // any hooks configured for prefix?
   {
      UtlString lastHook;
      UtlString hookName;
      UtlString hookLibrary;

      // walk each hook and attempt to load and configure it 
      for ( lastHook = "";
            OS_SUCCESS == allHooks.getNext(lastHook, hookName, hookLibrary);
            lastHook = hookName
           )
      {
         ConfiguredHook* thisHook;
         
         if (NULL == (thisHook = dynamic_cast<ConfiguredHook*>(existingHooks.remove(&hookName))))
         {
            // not an existing hook, so create a new one
            OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                          "PluginHooks: loading '%s'", hookName.data()
                          );
            thisHook = new ConfiguredHook(hookName, mFactory, hookLibrary);
         }

         // put the hook onto the list of active hooks
         mConfiguredHooks.insert(thisHook);

         // (re)configure the hook
         thisHook->readConfig(mPrefix, configDb);
      }
   }
   else
   {
      OsSysLog::add(FAC_KERNEL, PRI_INFO,
                    "PluginHooks: no '%s' hooks configured", mPrefix.data()
                    );
   }

   // discard any hooks that are no longer in the configuration
   existingHooks.destroyAll();
}