/*!a Test case for the get() method. * * The test data for this test is :- * 1) The first entry is a CollectableString * 2) The first entry is a CollectableInt * 3) The List has only one entry * 4) The List has no entries */ void testGet() { const int testCount = 4 ; const char* prefix = "Verify the get() method for a list when " ; const char* Msgs[] = { \ "the first entry is a CollectableString", \ "the first entry is a CollectableInt", \ "when the list has only one entry", \ "when the list is empty" \ } ; const char* suffix1 = ":- verify return value" ; const char* suffix2 = ":- verify the number of entries in the list" ; UtlSList testList ; testList.append(&commonString1) ; testList.append(&commonInt1) ; testList.append(&commonString2) ; UtlContainable* expectedValue[] = { \ &commonString1 , &commonInt1, &commonString2, NULL \ } ; int entryCount[] = { 2, 1, 0, 0 } ; for (int i = 0 ; i < testCount ; i++) { UtlContainable* actual = testList.get() ; string msg ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], actual) ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entryCount[i], (int)testList.entries()) ; } } //testGet()
/*!a Test case to test the destroyAll() * method. */ void testClearAndDestroy() { const char* prefix = "test the destroyAll() method " ; const char* suffix1 = ":- Verify that all entries are removed" ; const char* suffix2 = ":- The objects are deleted" ; UtlContainableTestStub* uStub ; UtlContainableTestStub* uStubPtr ; uStub = new UtlContainableTestStub(0) ; uStubPtr = new UtlContainableTestStub(1) ; emptyList.append(uStub) ; emptyList.append(uStubPtr) ; emptyList.destroyAll() ; int cCountAfter = UtlContainableTestStub::getCount() ; string msg ; TestUtilities::createMessage(2, &msg, prefix, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ; // Since the TestStub has been implemented such that destructor // decrements the static counter, to verify that the objects have // been deleted, verify that the static counter has been decremented. TestUtilities::createMessage(2, &msg, prefix, suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ; } //testClearAndDestroy
/*!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) ; }
OsStatus SmsNotifier::handleAlarm(const OsTime alarmTime, const UtlString& callingHost, const cAlarmData* alarmData, const UtlString& alarmMsg) { OsStatus retval = OS_FAILED; //execute the mail command for each user UtlString groupKey(alarmData->getGroupName()); if (!groupKey.isNull()) { UtlContainable* pContact = mContacts.findValue(&groupKey); if (pContact) { // Process the comma separated list of contacts UtlString* contactList = dynamic_cast<UtlString*> (pContact); if (!contactList->isNull()) { MailMessage message(mSmsStrFrom, mReplyTo, mSmtpServer); UtlTokenizer tokenList(*contactList); UtlString entry; while (tokenList.next(entry, ",")) { message.To(entry, entry); } UtlString body; UtlString tempStr; UtlString sevStr = Os::Logger::instance().priorityName(alarmData->getSeverity()); body.append(alarmMsg); Os::Logger::instance().log(FAC_ALARM, PRI_DEBUG, "AlarmServer: sms body is %s", body.data()); message.Body(body); UtlSList subjectParams; UtlString codeStr(alarmData->getCode()); UtlString titleStr(sevStr); subjectParams.append(&codeStr); subjectParams.append(&titleStr); assembleMsg(mSmsStrSubject, subjectParams, tempStr); message.Subject(tempStr); // delegate send to separate task so as not to block EmailSendTask::getInstance()->sendMessage(message); } } } return retval; }
/*!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. * d) When all the entries in a list have been removed using get. * e) When all the entries in a list have been removed using removeAll() */ void testIsEmpty() { const int testCount = 5 ; 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 retreieved using get()", \ "all the list entries have been retreived using removeAll()" \ } ; UtlSList newList ; UtlSList secondNewList ; UtlSList commonList_Clone ; // first populate a list and then retreive all elements using get for (int i = 0 ; i < commonEntriesCount ; i++) { commonList_Clone.append(commonContainables_Clone[i]) ; } for (int j = 0 ; j < commonEntriesCount; j++) { commonList_Clone.get(); } UtlString uS1 = UtlString("Lone Entry") ; newList.append(&uS1) ; // populate the second list and then clear all entries. secondNewList.append(&uS1) ; UtlInt uI1 = UtlInt(232) ; secondNewList.append(&uI1) ; secondNewList.removeAll() ; UtlSList* testLists[] = { \ &emptyList, &newList, &commonList, &commonList_Clone, &secondNewList \ } ; bool expectedValue[] = { true, false, false, true, true } ; for (int k = 0 ; k < testCount; k++) { string msg ; TestUtilities::createMessage(2, &msg, prefix, Msgs[k]) ; UtlBoolean actual = testLists[k] -> isEmpty() ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)expectedValue[k], \ actual) ; } } // testIsEmpty
// Generate the partial RLMI list. // Generate list of ResourceReference's corresponding to the URIs in mResourcesList. // Returns true if partialList is non-empty. UtlBoolean ResourceList::genPartialList(UtlSList& partialList) { UtlSListIterator resourcesItor(mResourcesList); ResourceReference* resource; UtlBoolean any_found = FALSE; // Check the resource list for changed items. while ((resource = dynamic_cast <ResourceReference*> (resourcesItor()))) { UtlSListIterator changesItor(mChangesList); UtlString* changedRsrc; UtlBoolean found = FALSE; while ((changedRsrc = dynamic_cast <UtlString*> (changesItor()))) { // Send a partial RLMI (only for resources that changed). if (strcmp(resource->getUri()->data(), changedRsrc->data()) == 0) { found = TRUE; any_found = TRUE; } } if (found) { partialList.append(resource); } } return any_found; }
// Loads a list of strings from the configuration datadase using the // designated prefix as the base for the list items. int OsConfigDb::loadList(const UtlString& rPrefix, UtlSList& rList) const { OsReadLock lock(mRWMutex); int iNumEntries ; int rc = 0 ; UtlString key ; UtlString value ; char cTemp[64] ; // Get number of items key = rPrefix ; key.append(".COUNT") ; if (get(key, iNumEntries) == OS_SUCCESS) { for (int i = 0; i < iNumEntries; i++) { sprintf(cTemp, "%d", i+1); key = rPrefix ; key.append(".") ; key.append(cTemp) ; if (get(key, value) == OS_SUCCESS) { rList.append(new UtlString(value)) ; rc++ ; } } } return rc ; }
void RegistrationDB::getUnexpiredContactsFieldsContaining ( UtlString& substringToMatch, const int& timeNow, UtlSList& matchingContactFields ) const { // Clear the results matchingContactFields.destroyAll(); if( m_pFastDB != NULL ) { SMART_DB_ACCESS; dbCursor< RegistrationRow > cursor; UtlString queryString = "contact like '%" + substringToMatch + "%' and expires>"; queryString.appendNumber( timeNow ); dbQuery query; query = queryString; if ( cursor.select(query) > 0 ) { // Copy all the unexpired contacts into the result list do { UtlString* contactValue = new UtlString(cursor->contact); matchingContactFields.append( contactValue ); } while ( cursor.next() ); } } else { OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getUnexpiredContactsFieldsContaining failed - no DB"); } }
int RegistrationDB::getUpdatesForRegistrar(dbQuery& query, UtlSList& bindings) const { int numRows = 0; if ( m_pFastDB != NULL ) { SMART_DB_ACCESS; dbCursor<RegistrationRow> cursor(dbCursorForUpdate); numRows = cursor.select(query); if (numRows > 0) { do { RegistrationBinding* reg = copyRowToRegistrationBinding(cursor); bindings.append(reg); } while (cursor.next()); } } else { OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getNewUpdatesForRegistrar failed - no DB"); } return numRows; }
/*!a Test case for the () operator. * * 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() { struct TestAdvancingOperatorStruct { const char* testDescription ; const UtlContainable* expectedValue ; } ; const int testCount = 4 ; const char* prefix = "Verify the () operator for an iterator when " ; const char* suffix1 = " :- verify return value" ; const char* suffix2 = " :- verify number of entries in the list" ; UtlSList testList ; testList.append(&commonString1) ; testList.append(&commonInt1) ; testList.append(&commonString2) ; UtlSListIterator iter(testList) ; TestAdvancingOperatorStruct testData[] = { \ { "the first entry is a UtlString", &commonString1 }, \ { "the first entry is a UtlInt", &commonInt1 }, \ { "when the list has only one entry", &commonString2 }, \ { "when the list is empty", NULL } \ } ; int expectedEntries = 3 ; for (int i = 0 ; i < testCount ; i++) { string msg ; TestUtilities::createMessage(3, &msg, prefix, \ testData[i].testDescription, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[i].expectedValue, \ (void*)iter()) ; TestUtilities::createMessage(3, &msg, prefix, testData[i].testDescription, \ suffix2); CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedEntries, \ (int)testList.entries()) ; } // Test the () operator for an empty list UtlSListIterator emptyIter(emptyList) ; CPPUNIT_ASSERT_EQUAL_MESSAGE("Test the () operator for an empty list iterator" , \ (void*)NULL, (void*)emptyIter()) ; } //testAdvancingOperator()
void testNewlinesInStrings() { OsSysLog::add(FAC_SUPERVISOR, PRI_DEBUG, "AlarmServerTest::testNewlinesInStrings"); UtlString localhost("localhost"); UtlString alarmId("MESSAGE_WITH_NEWLINES"); UtlSList alarmParams; UtlString alarmParam("1"); alarmParams.append(&alarmParam); UtlString alarmParam2 = "\nparam on new line"; alarmParams.append(&alarmParam2); cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(DELAY); UtlString actualString; UtlString expectedString = "param on new line"; tail(mAlarmFile, actualString); char msg[1000]; sprintf(msg, "incorrect message was logged: actualString '%s' expected '%s'", actualString.data(), expectedString.data()); CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString)); }
void appendCountItems(UtlSList& list, size_t itemsToAdd) { assert(itemsToAdd); size_t item; for (item = 0; item < itemsToAdd; item++) { list.append(new UtlString(string[item])); } }
void testParameterSubstitution() { OsSysLog::add(FAC_SUPERVISOR, PRI_DEBUG, "AlarmServerTest::testParameterSubstitution"); UtlString localhost("localhost"); UtlString alarmId("PARAMETER_SUBSTITUTION"); UtlSList alarmParams; UtlString alarmParam("1"); alarmParams.append(&alarmParam); UtlString alarmParam2 = "2"; alarmParams.append(&alarmParam2); cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(DELAY); UtlString actualString; UtlString expectedString = "Parameter 2, then parameter 1"; tail(mAlarmFile, actualString); char msg[1000]; sprintf(msg, "incorrect message was logged: actualString '%s' expected '%s'", actualString.data(), expectedString.data()); CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString)); }
void setUp() { 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.append(&commonString1) ; commonContainables[0] = &commonString1 ; commonContainables_Clone[0] = &commonString1_clone ; commonList.append(&commonInt1) ; commonContainables[1] = &commonInt1 ; commonContainables_Clone[1] = &commonInt1_clone ; commonList.append(&commonInt2) ; commonContainables[2] = &commonInt2 ; commonContainables_Clone[2] = &commonInt2_clone; commonList.append(&commonString2) ; commonContainables[3] = &commonString2 ; commonContainables_Clone[3] = &commonString2_clone ; commonList.append(&commonInt3) ; commonContainables[4] = &commonInt3 ; commonContainables_Clone[4] = &commonInt3_clone ; commonList.append(&commonString3) ; commonContainables[5] = &commonString3 ; commonContainables_Clone[5] = &commonString3_clone ; }
bool ACDQueue_Linear::buildTargetAgentList(UtlSList& rTargetAgentList, ACDCall* pCallRef) { ACDAgent* pAgent; ACDAgent* pLastAttemptedAgent; // Always rebuild the list to get the agents added on the fly buildACDAgentList(); UtlSListIterator listIterator(mAcdAgentList); int numAgents = mAcdAgentList.entries(); // Iterate through the ACDAgent list, starting after the agent that // The ACDCall was last using. If the end of the list is // reached, wrap around to the beginning. If this LastAttemptedAgent // is NULL, start from the head of the list pLastAttemptedAgent = pCallRef->getLastAgent(); if (pLastAttemptedAgent != NULL) { // walk the iterator to point after pLastAttemptedAgent if (listIterator.findNext(pLastAttemptedAgent) == NULL) { // Didn't find pLastAttemptedAgent, start again from the top. listIterator.reset(); pCallRef->setLastAgent(NULL); } } for(int i=0; i<numAgents; i++) { // Check the next agent pAgent = dynamic_cast<ACDAgent*>(listIterator()); if (pAgent == NULL) { // We've hit the end of the list start back from the head of the list listIterator.reset(); pAgent = dynamic_cast<ACDAgent*>(listIterator()); if (pAgent == NULL) { // All out of agents to try return false; } } if (pAgent->isAvailable(true)) { rTargetAgentList.append(pAgent); // Remember the agent chosen pCallRef->setLastAgent(pAgent); OsSysLog::add(FAC_ACD, gACD_DEBUG, "%s::buildTargetAgentList - agent(%s) is added to the target list", mAcdSchemeString, pAgent->getUriString()->data()); return true; } } // The whole list was tried, yet no appropriate agents were found. return false; }
//deep copy of aliases void SipLine::copyAliases(UtlSList& dest, const UtlSList& source) const { // Clear dest list if (!dest.isEmpty()) { dest.destroyAll() ; } // Copy maintaining order int length = source.entries() ; for (int i=0; i<length; i++) { UtlString* pEntry = (UtlString*) source.at(i) ; dest.append(new UtlString(*pEntry)) ; } }
/** * Test for SListIterator::findNext only at places that could break * - find item not in list * - find items at endpoints * - find items after reseting iterator */ void testFindNextForDummies() { UtlString fruitData[] = { UtlString("apple"), // 0 UtlString("orange"), // 1 UtlString("banana"), // 2 UtlString("apple"), // 3 UtlString("banana"), // 4 UtlString("apple") // 5 }; int n = sizeof(fruitData) / sizeof(fruitData[0]); UtlSList fruit; for (int i = 0; i < n; i++) { fruit.append(&fruitData[i]); } // nonexistant items UtlSListIterator pineapples(fruit); UtlString pineapple("pineapple"); CPPUNIT_ASSERT_MESSAGE("Do not find item not in list", pineapples.findNext(&pineapple) == NULL); // test items at endpoints UtlSListIterator apples(fruit); UtlString apple("apple"); CPPUNIT_ASSERT_MESSAGE("Find first item", apples.findNext(&apple) == &fruitData[0]); CPPUNIT_ASSERT_MESSAGE("Find second item", apples.findNext(&apple) == &fruitData[3]); CPPUNIT_ASSERT_MESSAGE("Find third item", apples.findNext(&apple) == &fruitData[5]); CPPUNIT_ASSERT_MESSAGE("Find no more items", apples.findNext(&apple) == NULL); // test scattered items UtlSListIterator bananas(fruit); UtlString banana("banana"); CPPUNIT_ASSERT_MESSAGE("Find first item", bananas.findNext(&banana) == &fruitData[2]); CPPUNIT_ASSERT_MESSAGE("Find second item", bananas.findNext(&banana) == &fruitData[4]); CPPUNIT_ASSERT_MESSAGE("Find no more items", bananas.findNext(&banana) == NULL); // test adjustments in iterator UtlSListIterator picker(fruit); CPPUNIT_ASSERT_MESSAGE("Find first item", picker.findNext(&apple) == &fruitData[0]); picker.reset(); CPPUNIT_ASSERT_MESSAGE("Find first item again after reset", picker.findNext(&apple) == &fruitData[0]); CPPUNIT_ASSERT_MESSAGE("Find second item after initial reset", picker.findNext(&apple) == &fruitData[3]); }
void testReservedCharsInParameters() { OsSysLog::add(FAC_SUPERVISOR, PRI_DEBUG, "AlarmServerTest::testReservedCharsInParameters"); UtlString localhost("localhost"); UtlString alarmId("PARAMETER_WITH_RESERVED_CHARS"); UtlSList alarmParams; UtlString alarmParam("<sample>; \"x=y\""); alarmParams.append(&alarmParam); cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(DELAY); UtlString actualString; UtlString expectedString = "Parameters may contain xml reserved characters e.g. '<sample>; \\\"x=y\\\"'"; tail(mAlarmFile, actualString); char msg[1000]; sprintf(msg, "incorrect message was logged: actualString '%s' expected '%s'", actualString.data(), expectedString.data()); CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString)); }
// Get a list of the user-parts of all resource lists. void ResourceListSet::getAllResourceLists(UtlSList& list) { Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceListSet::getAllResourceLists this = %p", this); // Serialize access to the ResourceListSet. OsLock lock(mSemaphore); // Iterate through the resource lists. UtlSListIterator resourceListItor(mResourceLists); ResourceList* resourceList; while ((resourceList = dynamic_cast <ResourceList*> (resourceListItor()))) { list.append(new UtlString(*resourceList->getUserPart())); } }
// Get a list of all Appearance Groups. void AppearanceGroupSet::getAllAppearanceGroups(UtlSList& list) { OsSysLog::add(FAC_SAA, PRI_DEBUG, "AppearanceGroupSet::getAllAppearanceGroups this = %p", this); // Serialize access to the AppearanceGroupSet. OsLock lock(mSemaphore); // Iterate through the Appearance Groups. UtlSListIterator appearanceGroupItor(mAppearanceGroups); AppearanceGroup* appearanceGroup; while ((appearanceGroup = dynamic_cast <AppearanceGroup*> (appearanceGroupItor()))) { list.append(new UtlString(appearanceGroup->getUser())); } }
void SipLineList::getLineUris(UtlSList& lineUris) const { SipLine* pLine = NULL; UtlHashMapIterator itor(m_lineMap); UtlContainable* pKey = NULL; int i = 0; while ((pKey = itor()) != NULL) { pLine = dynamic_cast<SipLine*>(itor.value()); if (pLine) { // copy line uri into list lineUris.append(pLine->getLineUri().toString().clone()); } } }
void SipLineList::getLineCopies(UtlSList& lineList) const { SipLine* pLine = NULL; UtlHashMapIterator itor(m_lineMap); UtlContainable* pKey = NULL; int i = 0; while ((pKey = itor()) != NULL) { pLine = dynamic_cast<SipLine*>(itor.value()); if (pLine) { // copy line into list lineList.append(new SipLine(*pLine)); } } }
bool ACDQueue_LongestIdle::buildTargetAgentList(UtlSList& rTargetAgentList, ACDCall* pCallRef) { // Always rebuild the list to get the agents added on the fly buildACDAgentList(); // Iterate through the ACDAgent list, starting at the head of the list // and find the agent that has been idle the longest. for(;;) { ACDAgent* pAgent; ACDAgent* pLongestIdleAgent = NULL; unsigned long maxIdleTime = 0; UtlSListIterator listIterator(mAcdAgentList); // Find the available agent with the longest idle time while ((pAgent = dynamic_cast<ACDAgent*>(listIterator())) != NULL) { if (pAgent->isAvailable(false)) { if (pAgent->getIdleTime() >= maxIdleTime) { maxIdleTime = pAgent->getIdleTime(); pLongestIdleAgent = pAgent; } } } if (pLongestIdleAgent == NULL) { // None available break ; } // If he is still available, use him. Otherwise start again. if (pLongestIdleAgent->isAvailable(true)) { rTargetAgentList.append(pLongestIdleAgent); OsSysLog::add(FAC_ACD, gACD_DEBUG, "%s::buildTargetAgentList - agent(%s) is added to the target list. Idle time was %lu seconds", mAcdSchemeString, pLongestIdleAgent->getUriString()->data(), maxIdleTime); return true ; } } // The whole list was tried, yet no appropriate agents were found. return false; }
/*!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 * d) When the removeAll is called twice on the list. */ void testClear() { const int testCount = 5 ; 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", \ "removeAll() has been called and entries are added again", \ "removeAll() has already been called", \ } ; const char* suffix = " :- Verify number of entries after removeAll()" ; UtlSList uSingleList ; UtlSList uAddAfterClear ; UtlSList uDoubleClear ; uSingleList.append(&commonString1) ; // call removeAll() on a list and then add entries again. uAddAfterClear.append(&commonInt1) ; uAddAfterClear.append(&commonString1) ; uAddAfterClear.removeAll() ; uAddAfterClear.append(&commonInt2) ; // call removeAll on a list twice. uDoubleClear.append(&commonString3) ; uDoubleClear.append(&commonInt3) ; uDoubleClear.removeAll() ; UtlSList* testLists[] = { \ &emptyList, &uSingleList, &commonList, &uAddAfterClear, &uDoubleClear } ; int expectedEntries[] = { 0 , 0, 0, 1, 0 } ; // since we are not calling removeAll for all the data, do it outside the for loop. emptyList.removeAll() ; uSingleList.removeAll() ; commonList.removeAll() ; // no removeAll() for uAddAfterClear uDoubleClear.removeAll() ; for ( int i = 0 ; i < testCount ; i++) { string msg ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data() , expectedEntries[i], \ (int)testLists[i]->entries()) ; } } //testClear()
OsStatus CpNotificationRegister::subscribe(CP_NOTIFICATION_TYPE notificationType, const SipDialog& callbackSipDialog) { OsStatus result = OS_FAILED; UtlInt key((int)notificationType); UtlSList* pDialogList = dynamic_cast<UtlSList*>(m_register.findValue(&key)); if (!pDialogList) { pDialogList = new UtlSList(); m_register.insertKeyAndValue(key.clone(), pDialogList); } if (pDialogList) { pDialogList->append(new SipDialog(callbackSipDialog)); result = OS_SUCCESS; } return result; }
void stalledMediaStreamDetectionTest_StreamStalled() { SetFakeReceptionOfPacketsFlag( false ); RouteState::setSecret("fixed"); const char* message = "INVITE sip:[email protected]:5060;x-sipX-pubcontact=47.135.162.145%3A29544 SIP/2.0\r\n" "Record-Route: <sip:192.168.0.2:5060;lr>\r\n" "From: \"L3\"<sip:[email protected]>;tag=94bb9480-c0a80065-13c4-50045-20c55bd3-50045\r\n" "To: <sip:[email protected]>\r\n" "Call-Id: 94bb55a0-c0a80065-13c4-50045-61a3ad3-50045@rjolyscs2.ca.nortel.com\r\n" "Cseq: 1 INVITE\r\n" "Via: SIP/2.0/UDP 192.168.0.2;branch=z9hG4bK-sipXecs-8130adee90e0277761fec4ee1c194a56838f~9d6590763d78764b93a42e94dbd6b75a\r\n" "Via: SIP/2.0/UDP 192.168.0.101:5060;branch=z9hG4bK-50045-13890e4e-4f17a229\r\n" "Max-Forwards: 19\r\n" "Supported: replaces\r\n" "User-Agent: LG-Nortel LIP 6812 v1.2.38sp SN/00405A183385\r\n" "Contact: <sip:[email protected]:5060;x-sipX-nonat>\r\n" "Content-Type: application/sdp\r\n" "Content-Length: 301\r\n" "Date: Fri, 13 Jun 2008 14:48:44 GMT\r\n" "\r\n" "\r\n" "v=0\r\n" "o=LGEIPP 14595 14595 IN IP4 192.168.0.101\r\n" "s=SIP Call\r\n" "c=IN IP4 192.168.0.101\r\n" "t=0 0\r\n" "m=audio 23016 RTP/AVP 18 4 0 8 101\r\n" "a=rtpmap:18 G729/8000\r\n" "a=rtpmap:4 G723/8000\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:8 PCMA/8000\r\n" "a=rtpmap:101 telephone-event/8000\r\n" "a=fmtp:18 annexb=no\r\n" "a=fmtp:101 0-11\r\n" "a=sendrecv\r\n"; SipMessage testMsg(message, strlen(message)); UtlString rejectReason; UtlSList emptyList; RouteState routeState( message, emptyList, "192.168.0.2:5060" ); AuthPlugin::AuthResult result; result = pNatTraversalAgent->authorizeAndModify( "id", //dummy Url("sip:[email protected]:5060"), //dummy routeState, "INVITE", AuthPlugin::CONTINUE, testMsg, false, rejectReason ); // check auth result CPPUNIT_ASSERT( result == AuthPlugin::CONTINUE ); routeState.update( &testMsg ); pNatTraversalAgent->handleOutputMessage( testMsg, "47.135.162.145", 29544 ); // Mow simulalate the reception of the response const char* response = "SIP/2.0 200 OK\r\n" "From: \"L3\"<sip:[email protected]>;tag=94bb9480-c0a80065-13c4-50045-20c55bd3-50045\r\n" "To: <sip:[email protected]>;tag=94bf81c0-c0a8010b-13c4-4fc07-650a9211-4fc07\r\n" "Call-Id: 94bb55a0-c0a80065-13c4-50045-61a3ad3-50045@rjolyscs2.ca.nortel.com\r\n" "Cseq: 1 INVITE\r\n" "Via: SIP/2.0/UDP 192.168.0.101:5060;branch=z9hG4bK-50045-13890e4e-4f17a229;id=1234-3\r\n" "Supported: replaces\r\n" "Contact: <sip:[email protected]:5060>\r\n" "Record-Route: <sip:47.135.162.140:5060;lr;sipXecs-rs=%2Afrom%7EOTRiYjk0ODAtYzBhODAwNjUtMTNjNC01MDA0NS0yMGM1NWJkMy01MDA0NQ%60%60.ntap%2ACeT%7ENDcuMTM1LjE2Mi4xNDU6Mjk1NDQ7dHJhbnNwb3J0PXVkcA%60%60.ntap%2Aid%7EMTIzNC0z%213d7b53562948991d1cf59dfe7fdaaf24>\r\n" "Content-Type: application/sdp\r\n" "Content-Length: 250\r\n" "Date: Fri, 13 Jun 2008 14:48:46 GMT\r\n" "\r\n" "\r\n" "v=0\r\n" "o=LGEIPP 12617 12617 IN IP4 192.168.1.11\r\n" "s=SIP Call\r\n" "c=IN IP4 192.168.1.11\r\n" "t=0 0\r\n" "m=audio 25038 RTP/AVP 4 101\r\n" "c=IN IP4 192.168.0.2\r\n" "a=rtpmap:4 G723/8000\r\n" "a=rtpmap:101 telephone-event/8000\r\n" "a=fmtp:101 0-11\r\n" "a=sendrecv\r\n" "a=x-sipx-ntap:192.168.0.2;3\r\n"; SipMessage okResp( response, strlen(response) ); pNatTraversalAgent->handleOutputMessage( okResp, "192.168.0.101", 5060 ); // Mow simulalate the reception of the ACK const char* ack = "ACK sip:[email protected]:5060;x-sipX-pubcontact=47.135.162.145%3A29544 SIP/2.0\r\n" "From: \"L3\"<sip:[email protected]>;tag=94bb9480-c0a80065-13c4-50045-20c55bd3-50045\r\n" "To: <sip:[email protected]>;tag=94bf81c0-c0a8010b-13c4-4fc07-650a9211-4fc07\r\n" "Call-Id: 94bb55a0-c0a80065-13c4-50045-61a3ad3-50045@rjolyscs2.ca.nortel.com\r\n" "Cseq: 1 ACK\r\n" "Via: SIP/2.0/UDP 192.168.0.2;branch=z9hG4bK-sipXecs-8130adee90e0277761fec4ee1c194a56838f~9d6590763d78764b93a42e94dbd6b75a\r\n" "Via: SIP/2.0/UDP 192.168.0.101:5060;branch=z9hG4bK-50045-13890e4e-4f17a229\r\n" "Max-Forwards: 19\r\n" "Supported: replaces\r\n" "User-Agent: LG-Nortel LIP 6812 v1.2.38sp SN/00405A183385\r\n" "Contact: <sip:[email protected]:5060;x-sipX-nonat>\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage ackRequest( ack, strlen(ack) ); UtlSList routeList; UtlString poppedRoute("<sip:47.135.162.140:5060;lr;sipXecs-rs=%2Afrom%7EOTRiYjk0ODAtYzBhODAwNjUtMTNjNC01MDA0NS0yMGM1NWJkMy01MDA0NQ%60%60.ntap%2ACeT%7ENDcuMTM1LjE2Mi4xNDU6Mjk1NDQ7dHJhbnNwb3J0PXVkcA%60%60.ntap%2Aid%7EMTIzNC0z%213d7b53562948991d1cf59dfe7fdaaf24>"); routeList.append( &poppedRoute ); RouteState newRouteState( message, routeList, "192.168.0.2:5060" ); result = pNatTraversalAgent->authorizeAndModify( "id", //dummy Url("sip:[email protected]:5060"), //dummy newRouteState, "ACK", AuthPlugin::CONTINUE, ackRequest, false, rejectReason ); // check auth result CPPUNIT_ASSERT( result == AuthPlugin::CONTINUE ); pNatTraversalAgent->handleOutputMessage( ackRequest, "47.135.162.145", 29544 ); // Check that the DialogTracker is still around after 10 seconds. CallTracker* pTracker; UtlString callId; testMsg.getCallIdField( &callId ); pTracker = pNatTraversalAgent->getCallTrackerFromCallId( callId ); CPPUNIT_ASSERT( pTracker != 0 ); CPPUNIT_ASSERT( pTracker->mSessionContextsMap.entries() == 1 ); sleep( MAX_TIMER_TICK_COUNTS_BEFORE_CALL_TRACKER_CLEAN_UP * CLEAN_UP_TIMER_IN_SECS * 2 /*safety margin*/ ); pTracker = pNatTraversalAgent->getCallTrackerFromCallId( callId ); CPPUNIT_ASSERT( pTracker == 0 ); }
// Read and parse the appearance group file and install the appearance groups // into the AppearanceGroupSet. OsStatus AppearanceGroupFileReader::initialize() { Os::Logger::instance().log(FAC_SAA, PRI_DEBUG, "AppearanceGroupFileReader::initialize entered"); int changeDelay = mAppearanceGroupSet->getAppearanceAgent()->getChangeDelay(); // The status to return. OsStatus ret = OS_SUCCESS; // No work to be done if file name is not set. if (!mFileName.isNull()) { // Initialize Tiny XML document object. TiXmlDocument document; TiXmlNode* lists_node; if ( // Load the XML into it. document.LoadFile(mFileName.data()) && // Find the top element, which should be <appearanceGroups>. (lists_node = document.FirstChild("appearanceGroups")) != NULL && lists_node->Type() == TiXmlNode::ELEMENT) { UtlSList newGroupList; // Find all the <resource> children and add them to the AppearanceGroup. for (TiXmlNode* resource_node = 0; (resource_node = lists_node->IterateChildren( "resource", resource_node));) { if (resource_node->Type() == TiXmlNode::ELEMENT) { TiXmlElement* resource_element = resource_node->ToElement(); // Process each <resource> element. bool resource_valid = true; // Process the 'uri' attribute. const char* uri_attribute = resource_element->Attribute("uri"); if (!uri_attribute || *uri_attribute == '\0') { // URI missing or null. Os::Logger::instance().log(FAC_SAA, PRI_ERR, "AppearanceGroupFileReader::initialize " "uri attribute of <resource> was missing or null"); resource_valid = false; ret = OS_FAILED; } if (resource_valid) { newGroupList.append(new UtlString(uri_attribute)); } } } Os::Logger::instance().log(FAC_SAA, PRI_DEBUG, "AppearanceGroupFileReader::initialize Done loading file '%s'", mFileName.data()); // For all groups in the current GroupSet, remove them if not in the new list. // Since these loops contain a delay and can run for a long time, // we have to check gShutdownFlag to abort processing when // a shutdown has been requested. UtlSList oldGroupList; mAppearanceGroupSet->getAllAppearanceGroups(oldGroupList); UtlSListIterator oldGroupItor(oldGroupList); UtlString* group; while (!gShutdownFlag && (group = dynamic_cast <UtlString*> (oldGroupItor()))) { UtlSListIterator newGroupItor(newGroupList); UtlString* newGroup; bool found = false; while (!found && (newGroup = dynamic_cast <UtlString*> (newGroupItor()))) { if (newGroup->compareTo(*group) == 0) { found = true; } } if (!found) { mAppearanceGroupSet->removeAppearanceGroup(group->data()); OsTask::delay(changeDelay); } } // For all groups in the new list, add to GroupSet if they are not there. UtlSListIterator groupItor(newGroupList); while (!gShutdownFlag && (group = dynamic_cast <UtlString*> (groupItor()))) { if (!mAppearanceGroupSet->findAppearanceGroup(group->data())) { mAppearanceGroupSet->addAppearanceGroup(group->data()); OsTask::delay(changeDelay); } } newGroupList.destroyAll(); } else { // Report error parsing file. Os::Logger::instance().log(FAC_SAA, PRI_CRIT, "AppearanceGroupFileReader::initialize " "Appearance group file '%s' could not be parsed.", mFileName.data()); ret = OS_FAILED; } } else { // Report that there is no file. Os::Logger::instance().log(FAC_SAA, PRI_WARNING, "AppearanceGroupFileReader::initialize No Appearance group file set."); } return ret; }
OsStatus EmailNotifier::handleAlarm(const OsTime alarmTime, const UtlString& callingHost, const cAlarmData* alarmData, const UtlString& alarmMsg) { OsStatus retval = OS_FAILED; //execute the mail command for each user UtlString groupKey(alarmData->getGroupName()); if (!groupKey.isNull()) { UtlContainable* pContact = mContacts.findValue(&groupKey); if (pContact) { // Process the comma separated list of contacts UtlString* contactList = dynamic_cast<UtlString*> (pContact); if (!contactList->isNull()) { MailMessage message(mEmailStrFrom, mReplyTo, mSmtpServer); UtlTokenizer tokenList(*contactList); UtlString entry; while (tokenList.next(entry, ",")) { message.To(entry, entry); } UtlString body; UtlString tempStr; body = mEmailStrIntro; body.append("\n"); assembleMsg(mEmailStrAlarm, alarmData->getCode(), tempStr); body.append(tempStr); body.append("\n"); assembleMsg(mEmailStrHost, callingHost, tempStr); body.append(tempStr); body.append("\n"); OsDateTime logTime(alarmTime); UtlString strTime; logTime.getIsoTimeStringZus(strTime); assembleMsg(mEmailStrTime, strTime, tempStr); body.append(tempStr); body.append("\n"); UtlString sevStr = OsSysLog::priorityName(alarmData->getSeverity()); assembleMsg(mEmailStrSeverity, sevStr, tempStr); body.append(tempStr); body.append("\n"); assembleMsg(mEmailStrDescription, alarmMsg, tempStr); body.append(tempStr); body.append("\n"); assembleMsg(mEmailStrResolution, alarmData->getResolution(), tempStr); body.append(tempStr); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "AlarmServer: email body is %s", body.data()); message.Body(body); UtlSList subjectParams; UtlString codeStr(alarmData->getCode()); UtlString titleStr(alarmData->getShortTitle()); subjectParams.append(&codeStr); subjectParams.append(&titleStr); assembleMsg(mEmailStrSubject, subjectParams, tempStr); message.Subject(tempStr); // delegate send to separate task so as not to block EmailSendTask::getInstance()->sendMessage(message); } } } return retval; }
ProvisioningAttrList* ACDAudioManager::Get(ProvisioningAttrList& rRequestAttributes) { ProvisioningAttrList* pResponse; ProvisioningAttrList* pAudioInstance; UtlString name; UtlSList* pAudioList; osPrintf("{method} = get\n{object-class} = acd-audio\n"); rRequestAttributes.dumpAttributes(); osPrintf("\n"); mLock.acquire(); // Extract the instance index from the request attributes. if (rRequestAttributes.getAttribute(AUDIO_NAME_TAG, name)) { // A specific instance has been specified, verify that it exists ACDAudio* pAudioRef = getAcdAudioReference(name); if (pAudioRef == NULL) { // There is no instance. mLock.release(); pResponse = new ProvisioningAttrList; pResponse->setAttribute("method-name", "get"); pResponse->setAttribute("result-code", ProvisioningAgent::UNKNOWN_OBJECT); pResponse->setAttribute("result-text", "Unknown instance"); return pResponse; } // Call the instance to get the requested attributes pResponse = new ProvisioningAttrList; try { pAudioRef->getAttributes(rRequestAttributes, pResponse); } catch (UtlString error) { // The request for attributes failed, send back the response mLock.release(); pResponse->setAttribute("method-name", "get"); pResponse->setAttribute("result-code", ProvisioningAgent::FAILURE); pResponse->setAttribute("result-text", error); return pResponse; } // Send back the response mLock.release(); pResponse->setAttribute("method-name", "get"); pResponse->setAttribute("result-code", ProvisioningAgent::SUCCESS); pResponse->setAttribute("result-text", "SUCCESS"); pResponse->setAttribute("object-class", ACD_AUDIO_TAG); pResponse->setAttribute(AUDIO_NAME_TAG, name); return pResponse; } else { // No specific instance was requested, send back a list of the available instances // Find the first instance. TiXmlNode* pInstanceNode = findPSInstance(ACD_AUDIO_TAG); pAudioList = new UtlSList; // Build up a list of instances while (pInstanceNode != NULL) { // Read the index parameter getPSAttribute(pInstanceNode, AUDIO_NAME_TAG, name); // Create the list entry pAudioInstance = new ProvisioningAttrList; pAudioInstance->setAttribute("object-class", ACD_AUDIO_TAG); pAudioInstance->setAttribute(AUDIO_NAME_TAG, name); pAudioList->append(pAudioInstance->getData()); // Get the next instance. pInstanceNode = pInstanceNode->NextSibling(); } // Send back the response mLock.release(); pResponse = new ProvisioningAttrList; pResponse->setAttribute("method-name", "get"); pResponse->setAttribute("result-code", ProvisioningAgent::SUCCESS); pResponse->setAttribute("result-text", "SUCCESS"); pResponse->setAttribute("object-class-list", pAudioList); return pResponse; } }
void testHandleAlarm() { OsSysLog::add(FAC_ALARM, PRI_DEBUG, "AlarmServerTest::testHandleAlarm"); UtlString localhost("localhost"); UtlString alarmId("NO_LOG"); UtlString alarmParam("testing"); UtlSList alarmParams; alarmParams.append(&alarmParam); UtlString oldLastString; tail(mAlarmFile, oldLastString); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "oldLastString %s", oldLastString.data()); bool rc=cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(500); CPPUNIT_ASSERT_MESSAGE("handleAlarm('NO_LOG') failed", rc==true); UtlString newLastString; tail(mAlarmFile, newLastString); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "newLastString %s", newLastString.data()); CPPUNIT_ASSERT_MESSAGE("alarm with 'NO_LOG' was logged", !oldLastString.compareTo(newLastString)); alarmId = "TEST_LOG"; alarmParam = "single parameter"; alarmParams.removeAll(); alarmParams.append(&alarmParam); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "Test TEST_LOG"); cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(DELAY); UtlString actualString; UtlString expectedString = "This is a test of the log function. Single parameter should be here: single parameter, and that's all that is required"; tail(mAlarmFile, actualString); char msg[1000]; sprintf(msg, "incorrect message was logged: actualString '%s' expected '%s'", actualString.data(), expectedString.data()); CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString)); // test that non-existant alarm returns false alarmId = "NONEXISTANT_ID"; rc=cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); CPPUNIT_ASSERT_MESSAGE("handleAlarm('NONEXISTANT_ID') did not fail, and should have", rc!=true); // test that alarm with min_threshold is only logged after n attempts alarmId = "MIN_THRESHOLD"; alarmParam = "one"; alarmParams.removeAll(); alarmParams.append(&alarmParam); tail(mAlarmFile, oldLastString); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "oldLastString %s", oldLastString.data()); cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(DELAY); tail(mAlarmFile, newLastString); OsSysLog::add(FAC_ALARM, PRI_DEBUG, "newLastString %s", newLastString.data()); CPPUNIT_ASSERT_MESSAGE("first instance of alarm with 'min_threshold' was logged", !oldLastString.compareTo(newLastString)); alarmParam = "two"; alarmParams.append(&alarmParam); cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams); OsTask::delay(DELAY); tail(mAlarmFile, actualString); expectedString = "This should only be logged the second time"; sprintf(msg, "incorrect message was logged: actualString '%s' expected '%s'", actualString.data(), expectedString.data()); CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString)); }