예제 #1
0
    /*!a Test case to test the DestroyAll()
    *    method.
    */
    void testClearAndDestroy()
    {
        const int testCount = 3 ;
        int cCountBefore = UtlContainableTestStub :: getCount() ;
        const char* prefix  = "test the destroyAll() method " ;
        const char* suffix1  = " :- sanity check to double check that the counter was incremented for every new() call" ;
        const char* suffix2 = " :- Verify that all entries are removed and the objects are deleted" ;

        UtlContainableTestStub* uStub ;
        UtlContainableTestStub* uStubPtr ;
        UtlContainableTestStub* uStubPtr2 ;
        uStub = new UtlContainableTestStub(0) ;
        uStubPtr = new UtlContainableTestStub(201) ;
        uStubPtr2 = new UtlContainableTestStub(201) ;
        emptyList.insert(uStub) ;
        emptyList.insert(uStubPtr) ;
        emptyList.insert(uStubPtr2) ;

        cCountBefore = UtlContainableTestStub :: getCount() - cCountBefore ;
        emptyList.destroyAll() ;
        int cCountAfter = UtlContainableTestStub :: getCount() ;

        string msg ;
        // Make sure that static count was incremented for every instance
        // of the TestStub that was created.
        TestUtilities::createMessage(2, &msg, prefix, suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(),  testCount, cCountBefore) ;

        // Verify that the list has no entries left after destroyAll()
        // and also ensure that all the TestStub instances were deleted.
        TestUtilities::createMessage(2, &msg, prefix, suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ;
    } //testClearAndDestroy
예제 #2
0
   /* Check for a problem that turned up in insert():  If an object
    * was inserted that should have been put at the end of a chain,
    * it was instead inserted at the beginning.
    *
    * This test detects the problem by inserting two objects which we arrange
    * to fall into the same bucket.  The object with the largest hash is
    * inserted second, so it should go at the end of the list, but instead
    * is inserted at the beginning.  The result is that the small-hash
    * object can't be seen by a selective HashBagIterator.
    *
    * The objects we use to exercise this case have to be tuned to the hash
    * algorithm of the objects and the algorithm
    * (UtlHashBag::bucketNumber) for turning hashes into bucket numbers.
    */
   void testCollision()
      {
         UtlHashBag bag;

         // For UtlInt's, the hash is the value.
         UtlInt small_hash_object(1);
         bag.insert(&small_hash_object);

         // put in some other objects
         UtlInt other_hash_object3(3);
         bag.insert(&other_hash_object3);
         UtlInt other_hash_object4(4);
         bag.insert(&other_hash_object4);
         UtlInt other_hash_object5(5);
         bag.insert(&other_hash_object5);

         UtlContainable* found;
         {
            // check that a keyed iterator sees the small_hash_object
            UtlHashBagIterator itor(bag, new UtlInt(1));
            found = itor();
            CPPUNIT_ASSERT(found == &small_hash_object);

            // and nothing else
            found = itor();
            CPPUNIT_ASSERT(found == NULL);
         }

         // We depend on the fact that a HashBag initially has 16 buckets and
         // folds hashes with XOR.  Under these conditions, 1 & 16 collide and
         // land in the same bucket.
         UtlInt large_hash_object(16);
         bag.insert(&large_hash_object);

         {
            // check that a keyed iterator sees the small_hash_object
            UtlHashBagIterator itor(bag, new UtlInt(1));
            found = itor();
            CPPUNIT_ASSERT(found == &small_hash_object);

            // and nothing else
            found = itor();
            CPPUNIT_ASSERT(found == NULL);
         }

         {
            // check that a keyed iterator sees the large_hash_object
            UtlHashBagIterator itor(bag, new UtlInt(16));
            found = itor();
            CPPUNIT_ASSERT(found == &large_hash_object);

            // and nothing else
            found = itor();
            CPPUNIT_ASSERT(found == NULL);
         }
      } // testCollision
예제 #3
0
    /*!a test case for the interaction of remove() and key().
    */
    void removeKey()
    {
       UtlString v1("a");
       UtlString v2("b");
       UtlString v3("c");
       UtlString v4("d");
       UtlContainable* e;

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

       UtlHashBagIterator iter(h);

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

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

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

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

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

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

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

    } //removeKey()
예제 #4
0
// Get all bindings expiring before newerThanTime.
void
RegistrationDB::getAllOldBindings(int newerThanTime,
                                  UtlHashBag& rAors) const
{
   // Empty the return value.
   rAors.destroyAll();

   if ( m_pFastDB != NULL )
   {
      SMART_DB_ACCESS;

      // Note: callid set to null indicates provisioned entries and
      //        these should not be removed
      dbQuery query;
      query = "expires <", static_cast<const int&>(newerThanTime), " and (callid != '#')";
      dbCursor< RegistrationRow > cursor;
      int rows = cursor.select( query );
      if (rows > 0)
      {
         // Create UtlString containing the AOR from the "uri" column.
         UtlString* uri = new UtlString(cursor->uri);
         // Add it to the result set.
         rAors.insert(uri);
      } while ( cursor.next() );
   }
   else
   {
      OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getAllOldBindings failed - no DB");
   }

   return;
}
예제 #5
0
      void testOneThousandInserts()
      {
         // Test case used to validate fix to issue XPL-169
         const int COUNT = 1000;
         const char stringPrefix[] = "Apofur81Kb";
         UtlHashBag bag;
         char tmpString[20];

         for( int i = 0; i < COUNT; i++)
         {
            sprintf(tmpString, "%s%d", stringPrefix, i);
            UtlString *stringToInsert = new UtlString();
            *stringToInsert = tmpString;

            CPPUNIT_ASSERT( ! bag.contains( stringToInsert ) );
            bag.insert( stringToInsert );
            CPPUNIT_ASSERT_EQUAL( i+1, (int)bag.entries() );

            for( unsigned int j = 0; j < bag.entries(); j++ )
            {
               // verify that all entries are indeed in the bag
               sprintf( tmpString, "%s%d", stringPrefix, j );
               UtlString stringTolookUp( tmpString );
               CPPUNIT_ASSERT_MESSAGE( tmpString, bag.contains( &stringTolookUp ) );
            }
         }
      }
예제 #6
0
void MpCodecFactory::freeAllLoadedLibsAndCodec()
{
   OsSharedLibMgrBase* pShrMgr = OsSharedLibMgr::getOsSharedLibMgr();

   UtlHashBagIterator iter(mCodecsInfo);
   MpCodecSubInfo* pinfo;

   UtlHashBag libLoaded;
   UtlString* libName;

   while ((pinfo = (MpCodecSubInfo*)iter()))
   {  
      if ((!pinfo->getCodecCall()->isStatic()) && 
         (!libLoaded.find(&pinfo->getCodecCall()->getModuleName()))) {
         libLoaded.insert(const_cast<UtlString*>(&pinfo->getCodecCall()->getModuleName()));
      }    
   }

   UtlHashBagIterator iter2(libLoaded);
   while ((libName = (UtlString*)iter2()))
   {
      pShrMgr->unloadSharedLib(libName->data());
   }

   iter.reset();
   while ((pinfo = (MpCodecSubInfo*)iter()))
   {  
      if (!pinfo->getCodecCall()->isStatic()) {
         mCodecsInfo.remove(pinfo);
         delete pinfo;         
      }
   }

   mCodecInfoCacheValid = FALSE;
}
예제 #7
0
    void setUp()
    {
        UtlContainableTestStub::clearCount() ;
        commonString1 = UtlString(regularString) ;
        commonString1_clone = UtlString(regularString) ;
        commonString2 = UtlString("") ;
        commonString2_clone = UtlString("") ;
        commonString3 = UtlString(longAlphaNumString) ;
        commonString3_clone = UtlString(longAlphaNumString) ;

        commonInt1 = UtlInt(0) ;
        commonInt1_clone = UtlInt(0) ;
        commonInt2 = UtlInt(INT_MAX) ;
        commonInt2_clone = UtlInt(INT_MAX) ;
        commonInt3 = UtlInt(INT_MIN) ;
        commonInt3_clone = UtlInt(INT_MIN) ;
        commonList.insert(&commonString1) ;
        commonContainables[0] = &commonString1 ;
        commonContainables_Clone[0] = &commonString1_clone ;
        commonList.insert(&commonInt1) ;
        commonContainables[1] = &commonInt1 ;
        commonContainables_Clone[1] = &commonInt1_clone ;
        commonList.insert(&commonInt2) ;
        commonContainables[2] = &commonInt2 ;
        commonContainables_Clone[2] = &commonInt2_clone;
        commonList.insert(&commonString2) ;
        commonContainables[3] = &commonString2 ;
        commonContainables_Clone[3] = &commonString2_clone ;
        commonList.insert(&commonInt3) ;
        commonContainables[4] = &commonInt3 ;
        commonContainables_Clone[4] = &commonInt3_clone ;
        commonList.insert(&commonString3) ;
        commonContainables[5] = &commonString3 ;
        commonContainables_Clone[5] = &commonString3_clone ;
    }
예제 #8
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
예제 #9
0
    /*!a Test case for testRemove()
    *
    *     The Test data for this test case is
    *          a) is an entry's reference
    *          b) is an entry's value(not reference)
    *          c) is the first of multiple matches and is the value match
    *          d) is the second of multiple matches.
    *          e) has no match at all
    */
    void testRemove()
    {
        int testCount = 4 ;
        const char* prefix = "test the remove(UtlContainable* c) method where c " ;
        const char* Msgs[] = { \
               "is an entry's reference ", \
               "is an entry's value(not reference) ", \
               "is first of multiple value matches ", \
               "has no match at all " \
        } ;
        const char* suffix1 = " :- Verify returned value" ;
        const char* suffix2 = " :- Verify total entries" ;

        // Insert a new value such that its value matches(isEqual to)
        // one of the existing items
        commonList.insert(commonContainables_Clone[4]) ;
        UtlString notExistContainable("This cannot and willnot exist");

        UtlContainable* dataForRemove[] = { \
                           commonContainables[0], \
                           commonContainables_Clone[2], \
                           commonContainables[4], \
                           &notExistContainable \
        } ;

        int totalEnt = commonEntriesCount + 1;

        UtlBoolean expectedReturnValues[] = { \
            true, true, true, false \
        } ;

        int entriesValue[] = { --totalEnt, --totalEnt, --totalEnt, totalEnt } ;

        totalEnt = commonEntriesCount + 1;


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

            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ;
            UtlContainable* retValue ;
            retValue = commonList.remove(dataForRemove[i]) ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)(retValue!=NULL), \
                           (UtlBoolean)expectedReturnValues[i]) ;

            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ;
            int expCount = (int)commonList.entries() ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entriesValue[i], expCount) ;
        }
    } //testRemove
예제 #10
0
UtlBoolean
SipPublishContentMgr::buildContentTypesContainer(const char* acceptHeaderValue,
        UtlHashBag& contentTypes)
{
    // Set to TRUE when we see an element.
    UtlBoolean containsMimetypes = FALSE;

    if (acceptHeaderValue)
    {
        // Parse acceptHeaderValue into its parts.
        const char* p = acceptHeaderValue;
        while (*p != '\0')
        {
            // Skip any leading separator characters.
            size_t i = strspn(p, " \t,");
            if (*p != '\0')
            {
                p += i;
                // Identify the base MIME type (without any parameters).
                i = strcspn(p, " \t,;");
                if (i > 0)
                {
                    // Create a string containing the MIME type and put it in the
                    // bag of MIME types.
                    UtlString* value = new UtlString(p, i);
                    contentTypes.insert(value);
                    containsMimetypes = TRUE;
                    p += i;
                    // Skip until a comma or end-of-string.
                    p += strcspn(p, ",");
                }
            }
        }
    }

    return containsMimetypes;
}
예제 #11
0
    /*a! Test the insert method for a list that is not empty. Add both unique and non-unique entries.
    *
    *    The test data for this test is :-
    *      a) Add a new UtlInt
    *      b) Add a new UtlString
    *      c) Add a new UtlVoidPtr
    *      d) Add a new Containable such that a similar one (value match) exists already
    *      e) Add a new Containable such that the same one (reference match) exists already
    */
    void testInsert()
    {
        struct testInsertStructure
        {
            const char* testDescription ;
            UtlContainable* itemToAdd ;
            UtlContainable* expectedReturnValue ;
            // In case of the hashtable, searching for a key can return *ANY* of the values
            // that matches and we dont care about which one. so we need two set of expected values
            UtlContainable* expectedFoundValue ;
            UtlContainable* altExpectedFoundValue ;
        } ;
        const char* prefix = "Test the insert(UtlContainable*) method for a non empty HashTable " ;
        const char* suffix1 = " :- Verify return value" ;
        const char* suffix2 = " :- Verify that the value is inserted" ;
        const char* suffix3 = " :- Verify that the number of entries is incremented by one" ;

        UtlInt uInt = UtlInt(1234) ;
        UtlString uString = UtlString("Test String") ;
        UtlVoidPtr uVoidPtr((char*)"Hello world") ;

        testInsertStructure testData[] = { \
            { "Add a new UtlInt ", &uInt, &uInt, &uInt, &uInt}, \
            { "Add a new UtlString ", &uString, &uString, &uString, &uString}, \
            { "Add a new UtlVoidPtr ", &uVoidPtr, &uVoidPtr, &uVoidPtr, &uVoidPtr}, \
            { "Add a Containable such that an identical one(value match) " \
              "exists in the table ", commonContainables_Clone[3], commonContainables_Clone[3], \
              commonContainables[3], commonContainables_Clone[3] }, \
            { "Add a Containable such that an exact duplicate " \
              "(including reference match) exists in the table ", commonContainables[4],
              commonContainables[4], commonContainables[4] } \
        } ;

        int expCount  = commonEntriesCount;

        string msg ;
        UtlContainable* uAct ;
        UtlContainable* uReturn ;
        /* :TODO: this part of the test is in error.
         *    when there is more than one of the same value in the bage,
         *    the find() method may return any of the objects with that value.
         */
        int testCount = sizeof(testData)/sizeof(testData[0]) ;
        for (int i = 0 ; i < testCount ; i++)
        {
            uReturn = commonList.insert(testData[i].itemToAdd) ;
            expCount++ ;
            uAct = commonList.find(testData[i].itemToAdd) ;
            TestUtilities::createMessage(3, &msg, prefix, \
                 testData[i].testDescription, suffix1) ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), \
                testData[i].expectedReturnValue, uReturn) ;

            // when there is more than one of the same value in the bag,
            // the find() method may return any of the objects with that value.
            bool isFound = (uAct == testData[i].expectedFoundValue) || \
                 (uAct == testData[i].altExpectedFoundValue) ;
            TestUtilities::createMessage(3, &msg, prefix, \
                testData[i].testDescription, suffix2) ;
            CPPUNIT_ASSERT_MESSAGE(msg.data(), isFound) ;
            TestUtilities::createMessage(3, &msg, prefix, \
                testData[i].testDescription, suffix3) ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expCount, (int)commonList.entries()) ;
        }
    } //testInsert
예제 #12
0
void SipPublishContentMgr::publish(const char* resourceId,
                                   const char* eventTypeKey,
                                   const char* eventType,
                                   int numContentTypes,
                                   HttpBody* eventContent[],
                                   UtlBoolean fullState,
                                   UtlBoolean noNotify)
{
    Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::publish resourceId '%s', eventTypeKey '%s', eventType '%s', numContentTypes %d, noNotify %d, fullState %d",
                  resourceId ? resourceId : "(null)",
                  eventTypeKey, eventType, numContentTypes, noNotify, fullState);

    if (numContentTypes < 1)
    {
       Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                     "SipPublishContentMgr::publish "
                     "No content bodies supplied for resourceId '%s', "
                     "eventTypeKey '%s', fullState %d",
                     resourceId? resourceId : "(null)",
                     eventTypeKey, fullState);
       
    }

    // Construct the key to look up.
    UtlString key;
    key.append(resourceId);
    key.append(CONTENT_KEY_SEPARATOR);
    key.append(eventTypeKey);

    lock();

    // Determine the storage we will be using.
    UtlHashBag* pContent;
    // resourceId can be NULL if we are called from ::publishDefault()
    if (resourceId)
    {
       if (fullState)
       {
          // Full dialog events
          pContent = &mContentEntries;
       }
       else
       {
          // Partial dialog events
          pContent = &mPartialContentEntries;
       }
    }
    else
    {
       // Default dialog events
       if (fullState)
       {
          pContent = &mDefaultContentEntries;
       }
       else
       {
          pContent = &mDefaultPartialContentEntries;
       }
    }

    // Look up the key in the specific or default entries, as appropriate.
    PublishContentContainer* container =
       dynamic_cast <PublishContentContainer*> (pContent->find(&key));

    // If not found, create a container.
    if (container == NULL)
    {
        container = new PublishContentContainer(key);
	// Save the container in the appropriate hash.
        pContent->insert(container);
    }
    // The content for this event type already existed
    else
    {
        // Remove the old content
        container->mEventContent.destroyAll();
    }

    // Add the new content
    for (int index = 0; index < numContentTypes; index++)
    {
        Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
            "SipPublishContentMgr::publish eventContent[%d] = %p, key = '%s', content type = '%s', getBytes() = %p '%s'",
                      index,
                      eventContent[index],
                      key.data(),
                      eventContent[index]->data(),
                      eventContent[index]->getBytes(),
                      eventContent[index]->getBytes());
        container->mEventContent.append(eventContent[index]);
    }

    // Don't call the observers if noNotify is set or if this is default content.
    if (!noNotify && resourceId)
    {
       // Call the observer for the content change, if any.
       UtlString eventTypeString(eventType);
       PublishCallbackContainer* callbackContainer =
          dynamic_cast <PublishCallbackContainer*>
          (mEventContentCallbacks.find(&eventTypeString));
       if (callbackContainer)
       {
          (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                          resourceId,
                                          eventTypeKey,
                                          eventTypeString,
                                          NULL);
       }
    }

    unlock();
}
예제 #13
0
   void testRemoveReference()
      {
         // the following two entries collide if the initial bucket size is 16
         UtlInt int1(1);
         UtlInt int16(16);

         UtlInt int2a(2);
         UtlInt int2b(2);
         UtlInt int3(3);

         UtlHashBag bag;

         CPPUNIT_ASSERT( bag.numberOfBuckets() == 16 ); // check assumption of collision

         // Load all the test objects
         CPPUNIT_ASSERT( bag.insert(&int1) == &int1 );
         CPPUNIT_ASSERT( bag.insert(&int16) == &int16 );
         CPPUNIT_ASSERT( bag.insert(&int2a) == &int2a );
         CPPUNIT_ASSERT( bag.insert(&int2b) == &int2b );
         CPPUNIT_ASSERT( bag.insert(&int3) == &int3 );

         // Check that everything is there
         CPPUNIT_ASSERT( bag.entries() == 5 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) ); // cannot test for 2a and 2b independently
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // Take entry 1 out (might collide w/ 16)
         CPPUNIT_ASSERT( bag.removeReference(&int1) == &int1 );

         // Check that everything except entry 1 is still there, and that 1 is gone
         CPPUNIT_ASSERT( bag.entries() == 4 );
         CPPUNIT_ASSERT( ! bag.contains(&int1) );
         CPPUNIT_ASSERT( bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) );// cannot test for 2a and 2b independently
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // Put entry 1 back in (so that 16 will collide w/ it again)
         CPPUNIT_ASSERT( bag.insert(&int1) == &int1 );

         // Check that everything is there
         CPPUNIT_ASSERT( bag.entries() == 5 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) );
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // Take entry 16 out (might collide w/ 1)
         CPPUNIT_ASSERT( bag.removeReference(&int16) == &int16 );

         // Check that everything except entry 16 is still there, and that 16 is gone
         CPPUNIT_ASSERT( bag.entries() == 4 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) );// cannot test for 2a and 2b independently
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // remove 2a (and ensure that you don't get back 2b)
         CPPUNIT_ASSERT( bag.removeReference(&int2a) == &int2a );

         // Check that everything that should be is still there
         CPPUNIT_ASSERT( bag.entries() == 3 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // remove 3 (no collision for this one)
         CPPUNIT_ASSERT( bag.removeReference(&int3) == &int3 );

         // Check that everything that should be is still there
         CPPUNIT_ASSERT( bag.entries() == 2 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
         CPPUNIT_ASSERT( ! bag.contains(&int3) );

         // remove 3 again - should fail this time
         CPPUNIT_ASSERT( bag.removeReference(&int3) == NULL );

         // Check that everything that should be is still there
         CPPUNIT_ASSERT( bag.entries() == 2 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
         CPPUNIT_ASSERT( ! bag.contains(&int3) );

      }
예제 #14
0
int MpTopologyGraph::addTopologyResources(MpResourceTopology& resourceTopology,
                                          MpResourceFactory& resourceFactory,
                                          UtlHashBag& newResources,
                                          UtlBoolean replaceNumInName,
                                          int resourceNum)
{
    // Add the resources
    int resourceIndex = 0;
    MpResource* resourcePtr = NULL;
    MpResource* resourceArray[MAX_CONSTRUCTED_RESOURCES];
    UtlString resourceType;
    UtlString resourceName;
    MpConnectionID resourceConnId;
    int resourceStreamId;
    OsStatus result;
    while(resourceTopology.getResource(resourceIndex, resourceType, resourceName,
                                       resourceConnId, resourceStreamId) == OS_SUCCESS)
    {
        if(replaceNumInName)
        {
           MpResourceTopology::replaceNumInName(resourceName, resourceNum);
        }

        int numConstructorResources;
        OsStatus status;
        status = resourceFactory.newResource(resourceType, resourceName, MAX_CONSTRUCTED_RESOURCES,
                                             numConstructorResources, resourceArray);        
        if(status == OS_SUCCESS)
        {
           assert(numConstructorResources > 0);
           int arrayIndex;
           // We now can potentially get more than one resource back from the
           // constructor
           for(arrayIndex = 0; arrayIndex < numConstructorResources; arrayIndex++)
           {
              resourcePtr = resourceArray[arrayIndex];
              assert(resourcePtr);
              if(resourcePtr)
              {
#ifdef TEST_PRINT
                  printf("constructed and adding resource name: %s type: %s\n",
                         resourcePtr->getName().data(),
                         resourceType.data());
#endif
                  if(replaceNumInName && resourceConnId == MP_INVALID_CONNECTION_ID)
                  {
                     resourcePtr->setConnectionId(resourceNum);
                  }
                  else
                  {
                     resourcePtr->setConnectionId(resourceConnId);
                  }
                  resourcePtr->setStreamId(resourceStreamId);
                  newResources.insert(resourcePtr);
                  result = addResource(*resourcePtr, FALSE);
                  assert(result == OS_SUCCESS);
               }
           }
        }
        else
        {
           OsSysLog::add(FAC_MP, PRI_ERR, 
              "Failed to create resource type: %s name: %s status: %d",
              resourceType.data(), resourceName.data(), status);
        }
        resourceIndex++;
    }
    return(resourceIndex);
}
예제 #15
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()
예제 #16
0
    /*!a Test case to test the destroy()
    *    method.
    */
    void testRemoveAndDestroy()
    {
        const char* prefix  = "test the destroy() method " ;

        // The ContainableTestStub has been implemented such that a static
        // counter is incremented everytime an instance is created and
        // the counter is decremented everytime an instance is destroyed.
        UtlContainableTestStub* uStub = new UtlContainableTestStub(0) ;
        UtlContainableTestStub* uStubPtr = new UtlContainableTestStub(101) ;
        commonList.insert(uStub) ;
        commonList.insert(uStubPtr) ;

        string msg ;
        int cCountBefore = UtlContainableTestStub :: getCount() ;
        UtlBoolean retValue = commonList.destroy(uStubPtr) ;
        int cCountAfter  ;
        uStubPtr = NULL ;
        TestUtilities::createMessage(2, &msg, prefix, ":- Verify the return value") ;
        CPPUNIT_ASSERT_MESSAGE(msg.data(), retValue) ;

        // To verify that the object was destroyed, check to see if the static count has been
        // decremented. If yes, it means that the destructor was called.
        cCountAfter = UtlContainableTestStub :: getCount() ;
        TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the object was deleted") ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;

        // THe way to verify if the object has been removed is to
        // create a new stub such that it has the same value as
        // the removed stub. Try to find the new stub
        UtlContainableTestStub uStubNew(101) ;
        UtlContainable* uSearch = commonList.find(&uStubNew) ;
        TestUtilities::createMessage(2, &msg, prefix, ":- Verify that the entry is removed") ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)NULL, (void*)uSearch) ;

        // Now test the case when you have added multiple deletable keys
        // and the first key inserted is deleted first.
        UtlContainableTestStub* uStubPtr2 = new UtlContainableTestStub(201) ;
        UtlContainableTestStub* uStubPtr3 = new UtlContainableTestStub(201) ;
        commonList.insert(uStubPtr2) ;
        commonList.insert(uStubPtr3) ;
        UtlInt uTestInt(2031) ;
        commonList.insert(&uTestInt) ;
        // after destroying, either uStubPtr or uStubPtr3 might have gotten deleted and
        // we have no way to find out which one. So create a new ContainableTestStub
        // and use that for search
        UtlContainableTestStub uStubTemp(201) ;


        cCountBefore = UtlContainableTestStub :: getCount() ;
        commonList.destroy(&uStubTemp) ;
        cCountAfter = UtlContainableTestStub :: getCount() ;

        uSearch = commonList.find(&uStubTemp) ;
        const char*  msgTemp = "Verify that doing a removeAndDestroy on " \
             "an item that has multiple matches removes only one entry " ;
        TestUtilities::createMessage(2, &msg, msgTemp, " :- Verify value is still found") ;
        CPPUNIT_ASSERT_MESSAGE("Verify that doing a removeAndDestroy on " \
             "an item that has multiple matches removes only one entry", \
             uSearch == uStubPtr2 || uSearch == uStubPtr3) ;
        TestUtilities::createMessage(2, &msg, msgTemp, " :- Verify value *was* destroyed") ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;

        msgTemp = "Verify that the remaining entry can also be deleted" ;
        cCountBefore = UtlContainableTestStub :: getCount() ;
        commonList.destroy(&uStubTemp) ;
        cCountAfter = UtlContainableTestStub :: getCount() ;
        TestUtilities::createMessage(2, &msg, msgTemp, " :- Verify value *was* destroyed") ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), cCountBefore -1, cCountAfter) ;

        // In all the above tests, a total of 5 entries were added
       // and 3 were removed.
        int finalCount = commonEntriesCount + 2 ;
        msgTemp = "Verify that the HashTable stil has the other entries" ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msgTemp, finalCount, (int)commonList.entries()) ;
    }
예제 #17
0
OsStatus OsConfigDb::updateFile(const char* filename) const
{
   UtlString originalFileContents;
   long fileLength = OsFile::openAndRead(filename, originalFileContents);
   const char* unparsedBits = originalFileContents;
   int unparsedLength = originalFileContents.length();

   // Loop through and try to preserve comments, space and order
   int lineStart = 0;
   int lineEnd = 0;
   UtlHashBag writtenNames;
   UtlString newFileContents;
   UtlString name;
   UtlString value;
   UtlString newValue;

   while(lineStart < unparsedLength)
   {
      lineEnd = UtlTokenizer::nextDelim(unparsedBits, lineStart, unparsedLength, "\n\r");

      //printf("start: %d end: %d length: %d\n", lineStart, lineEnd, unparsedLength);

      UtlString oneLine(&unparsedBits[lineStart], lineEnd - lineStart);

      //printf("Line: <%s>\n", oneLine.data());

      // If line contains a parameter
      if(parseLine(oneLine, mCapitalizeName, filename, name, value))
      {
         //printf("name<%s> value<%s>\n", name.data(), value.data());
         if(get(name, newValue) == OS_SUCCESS &&
            !writtenNames.contains(&name))
         {
            //printf("Wrote name<%s>\n", name.data());
            // The parameter still exists in the configDb and we have not yet
            // written it out, write the potentially changed value
            newFileContents.appendFormat("%s : %s\n", name.data(), newValue.data());

            // Save names/parameters written so that we can figure out what has not
            // been written out
            writtenNames.insert(new UtlString(name));
         }
         // else the parameter was removed, do nothing
      }
   
      // The line was a comment or blank line, write it back out the same
      else
      {
         newFileContents.appendFormat("%s\n", oneLine.data());
      }

      lineStart = lineEnd + 1;
   }

   int paramIndex;
   int paramCount = numEntries();
   DbEntry* paramEntry;

   for (paramIndex = 0; paramIndex < paramCount; paramIndex++)
   {
      paramEntry = (DbEntry*) mDb.at(paramIndex);

      removeNewlineReturns(paramEntry->key);
      removeNewlineReturns(paramEntry->value);

      // We have not written the value yet
      if(!writtenNames.contains(&(paramEntry->key)))
      {
          newFileContents.appendFormat("%s : %s\n", paramEntry->key.data(), paramEntry->value.data());
          writtenNames.insert(new UtlString(paramEntry->key));
      }
   }

   fileLength = OsFile::openAndWrite(filename, newFileContents);
 
   writtenNames.destroyAll();

   return(fileLength > 0 ? OS_SUCCESS : OS_INVALID_ARGUMENT);
}
예제 #18
0
    /*!a Test case for the () operator and the key() method.
    *
    *    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_And_KeyMethod()
    {
        const int testCount = 5;
        const char* prefix = "Verify the () operator " ;
        const char* prefix_for_key = "Verify the key() method " ;
        const char* Msgs[] = { \
                     "when the entry is the first of two value matches of UtlString type", \
                     "when the entry is the first of two reference matches of UtlInt type", \
                     "when the entry is a unique Containable", \
                     "when the entry is the second of two reference matches of UtlInt type", \
                     "when the entry is the second of two value matches of UtlString type" \
        } ;

        // Create a Hashtable such that it has one unique element (commonString2) ,
        // 2 elements that has value matches (commonString1 / commonString1_clone) ,
        // and 2 elements that *ARE* the same (commonInt1)
        UtlHashBag testList ;
        testList.insert(&commonString1) ;
        testList.insert(&commonInt1) ;
        testList.insert(&commonString1_clone) ;
        testList.insert(&commonString2) ;
        testList.insert(&commonInt1) ;

        UtlContainable* exp[] = { \
                          &commonString1 , &commonInt1, &commonString2, &commonInt1, &commonString1_clone
        } ;
        int expEntries = testCount;

        UtlHashBagIterator iter(testList) ;
        UtlContainable* act ;
        UtlContainable* expected_value_for_key_method ;
        string msg ;

        // Test the key method when the iterator has been reset.
        iter.reset() ;
        act = iter.key() ;
        TestUtilities::createMessage(2, &msg, prefix, "when the iterator has been reset") ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)NULL, (void*)act) ;

        // Now iterate through the whole iterator and verify that all the items are
        // retreived. The () operator retreives the next item in the list. The
        // key item should retreive the item under the current position. (That is,
        // the key() method should always return what the previous () returned)
        for (int i = 0 ; i < testCount ; i++)
        {
             act = iter() ;
             expected_value_for_key_method = act;
             const char* curMessage = "";
             bool wasFound = false ;
             // We dont care about which item matches where. We only want to make sure
             // that each item *IS* retreived once and *ONLY* once.
             for (int j =0 ; j < testCount; j++)
             {
                 // If the item was already found during a previous iteration,
                 // we would have set the exp. value to NULL. so ignore all NULL
                 // expected values.
                 // The idea behind this is illustrated with the following example.
                 // Let us say that invoking foo.search(bar) can return either return
                 // either 90, 100 or 120 on the first search(either return is valid).
                 // Let's say that it returns 100. But if foo.search(bar) is invoked the
                 // second time, it should only return 90 or 120. So setting the element
                 // of the expected array that used to contain 100 to NULL means that
                 // that '100' is no longer a valid expected value.
                 if (exp[j] != NULL && act == exp[j])
                 {
                     wasFound = true ;
                     exp[j] = NULL ;
                     // Unlike traditional tests in which we know before hand the message
                     // for a particular iteration, in this case, the message is constructed
                     // based on the return value.
                     curMessage = Msgs[j] ;
                     break ;
                 }
              }
              if (!wasFound)
              {
                  curMessage = " :- One of the expected items was not retreived" \
                                  " using an indexing operator" ;
              }
              TestUtilities::createMessage(3, &msg, prefix, curMessage, " :- Verify return value") ;
              CPPUNIT_ASSERT_MESSAGE(msg.data(), wasFound) ;
              TestUtilities::createMessage(3, &msg, prefix, curMessage, " :- Verify that the number of entries has not changed") ;
              CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expEntries, (int)testList.entries()) ;
              // Verfiy that using the key() method retreives the value at the current position.
              // without repositioning the iterator.
              act = iter.key() ;
              TestUtilities::createMessage(2, &msg, prefix_for_key, curMessage) ;
              CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expected_value_for_key_method, act) ;
        }

        // Test the () operator when the whole list has been iterated
        act = iter() ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Verify that the indexing operator on a list that has been traversed fully returns NULL", \
                              (void*)NULL, (void*)act) ;


        // Test the () operator for an empty list
        UtlHashBagIterator emptyIter(emptyList) ;
        act = emptyIter() ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Test the () operator for an empty list iterator" , (void*)NULL, (void*)act) ;

    } //testAdvancingOperator()
예제 #19
0
      void testFiltered()
      {
         UtlString key1a("key1");
         UtlString key1b("key1");
         UtlString key2("key2");
         UtlString key3("key3");

         UtlHashBag theBag;
         theBag.insert(&key1a);
         theBag.insert(&key1b);
         theBag.insert(&key2);
         theBag.insert(&key3);

         UtlString* content;

         {
            UtlString filter("key2");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;
            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0004==foundMask);
         }
         {
            UtlString filter("key1");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;
            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0003==foundMask);
         }
         {
            UtlString filter("key1");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;

            UtlString* removed = (UtlString*)theBag.remove(&filter);
            if ( &key1a == removed )
            {
               CHECK_FOUND(foundMask,0x0001);
            }
            else if ( &key1b == removed )
            {
               CHECK_FOUND(foundMask,0x0002);
            }
            else
            {
               CPPUNIT_FAIL("Unknown element removed");
            }

            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0003==foundMask);
         }
         {
            UtlString filter("key3");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;

            UtlString* removed = (UtlString*)theBag.remove(&filter);
            CPPUNIT_ASSERT(&key3==removed);

            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0000==foundMask);
         }
         {
            UtlString filter("key4");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;

            UtlString* removed = (UtlString*)theBag.remove(&filter);
            CPPUNIT_ASSERT(NULL==removed);

            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0000==foundMask);
         }
      }
예제 #20
0
    void utlTestFind_And_Contains(FindOrContains type)
    {
        const int testCount = 7 ;
        const char* prefixFind = "Test the find() method when the match " ;
        const char* prefixContains = "Test the contains() 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 two elements to satisfy (d) and (e)
       commonList.insert( commonContainables_Clone[4]) ;
       commonList.insert( commonContainables[3]) ;

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

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

       bool expectedValues_Contains[]    = {true, true, true, true, true, true, false } ;

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

       // In case of the hashtable, searching for a key can return *ANY* of the values
       // that matches and we dont care about which one. so we need two set of expected values
       UtlContainable* expValues_Find[][2] = { \
                 {commonContainables[0], commonContainables[0]}, \
                 {commonContainables[5], commonContainables[2]}, \
                 {commonContainables[2], commonContainables[2]}, \
                 {commonContainables_Clone[4], commonContainables[4]}, \
                 {commonContainables[3], commonContainables[3]}, \
                 {commonContainables[1], commonContainables[1]}, \
                 {NULL, NULL} \
       } ;

       for (int i = 0 ; i < testCount ; i++)
       {
           string msg ;
           if (type == TEST_FIND)
           {
               bool isFound = false ;
               UtlContainable* act = commonList.find(searchValuesForFind[i]) ;
               // If we are expecting either 'A' or 'B' for the search
               isFound = (act == expValues_Find[i][0]) || (act == expValues_Find[i][1]) ;
               TestUtilities::createMessage(2, &msg, prefixFind, Msgs[i]) ;
               CPPUNIT_ASSERT_MESSAGE(msg.data(), isFound) ;
           }
           else if (type == TEST_CONTAINS)
           {
               UtlBoolean act = commonList.contains(searchValues[i]) ;
               UtlBoolean exp = (UtlBoolean)expectedValues_Contains[i] ;
               TestUtilities::createMessage(2, &msg, prefixContains, Msgs[i]) ;
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), exp, act) ;
           }
       }

    }//utlTestIndex
예제 #21
0
void SipPublishContentMgr::publish(const char* resourceId,
                                   const char* eventTypeKey,
                                   const char* eventType,
                                   int numContentTypes,
                                   HttpBody* eventContent[],
                                   const int eventVersion[],
                                   UtlBoolean noNotify,
                                   UtlBoolean fullState)
{
    OsSysLog::add(FAC_SIP, PRI_DEBUG,
                  "SipPublishContentMgr::publish resourceId '%s', eventTypeKey '%s', eventType '%s', numContentTypes %d, noNotify %d, fullState %d",
                  resourceId, eventTypeKey, eventType, numContentTypes,
                  noNotify, fullState);

    UtlBoolean resourceIdProvided = resourceId && *resourceId;

    // Construct the key to look up.
    UtlString key;
    if(resourceIdProvided)
    {
        key = resourceId;
    }

    if(eventTypeKey)
    {
        key.append(eventTypeKey);
    }

    lock();

    // Determine the type of storage we will be using
    UtlHashBag* pContent;
    if (resourceIdProvided)
    {
        if (fullState)
        {
            // Full dialog events
            pContent = &mContentEntries;
        }
        else
        {
            // Partial dialog events
            pContent = &mPartialContentEntries;
        }
    }
    else
    {
        // Default dialog events
        pContent = &mDefaultContentEntries;
    }

    // Look up the key in the specific or default entries, as appropriate.
    PublishContentContainer* container =
        dynamic_cast <PublishContentContainer*> (pContent->find(&key));

    // If not found, create a container.
    if(container == NULL)
    {
        container = new PublishContentContainer();
        *((UtlString*) container) = key;
        // Save the container in the appropriate hash.
        pContent->insert(container);
    }

    // The content for this event type already existed
    else
    {
        // Remove the old content
        container->mEventContent.destroyAll();
        container->mEventVersion.destroyAll();
    }

    // Add the new content
    for (int index = 0; index < numContentTypes; index++)
    {
        OsSysLog::add(FAC_SIP, PRI_DEBUG,
                      "SipPublishContentMgr::publish eventContent[%d] = %p, key = '%s', content type = '%s', version = %d, getBytes() = %p '%s'",
                      index,
                      eventContent[index],
                      key.data(),
                      eventContent[index]->data(),
                      eventVersion[index],
                      eventContent[index]->getBytes(),
                      eventContent[index]->getBytes());
        container->mEventContent.append(eventContent[index]);
        container->mEventVersion.append(new UtlInt(eventVersion[index]));
    }

    // Don't call the observers if noNotify is set or if this is default content.
    if (!noNotify && resourceIdProvided)
    {
        // Call the observer for the content change, if any.
        UtlString eventTypeString(eventType);
        PublishCallbackContainer* callbackContainer =
            dynamic_cast <PublishCallbackContainer*>
            (mEventContentCallbacks.find(&eventTypeString));
        if(callbackContainer && callbackContainer->mpCallback)
        {
            (callbackContainer->mpCallback)(callbackContainer->mpApplicationData,
                                            resourceId,
                                            eventTypeKey,
                                            eventTypeString);
        }
    }

    unlock();
}