📄 sipxtapitestcall.cpp
字号:
bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_DIALTONE_UNKNOWN, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_REMOTE_OFFERING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_REMOTE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; int connectionId = -1; CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT(connectionId != -1) ; const char* requestMethod = "FOO"; // BEGIN DIRTY USE OF SIPXTAPI // Here we do some unnatural or dirty messing about with some of // the sipXtapi internals. SIPX_INSTANCE_DATA* sipXtapiCallingContext = (SIPX_INSTANCE_DATA*) g_hInst; // Create a queue to recieve FOO requests and register the queue with // the calling side SipUserAgent. OsMsgQ requestReceiveQueue; sipXtapiCallingContext->pSipUserAgent->addMessageObserver(requestReceiveQueue, requestMethod, TRUE, // get requests FALSE, // ignore responses TRUE); // want incoming messages // Create a request and add a header to be sure it gets passed through SipMessage request; request.setRequestData(requestMethod, "bogusRequestUri", "bogusFrom", "bogusTo", "bogusCallId", 11111111, "bogusLocalContact"); request.setHeaderValue("bar", "splat"); // Create a queue to recieve the response on responseReceiveQueue[iStressFactor] = new OsMsgQ; int applicationData = 22222222; SIPX_INSTANCE_DATA* sipXtapiCalledContext = (SIPX_INSTANCE_DATA*) g_hInst2; // get the dialog info to be validated SIPX_INSTANCE_DATA* dummyHandle = NULL; UtlString calledSideCallId; UtlString remoteCallerAddress; sipxCallGetCommonData(g_hAutoAnswerCallbackCall, &dummyHandle, &calledSideCallId, &remoteCallerAddress, NULL); SipDialog calledSipDialog; // Dialog info for the called party side sipXtapiCalledContext->pCallManager->getSipDialog(calledSideCallId, remoteCallerAddress, calledSipDialog); // Send the request in the dialog of the call sipXtapiCalledContext->pCallManager->sendInDialog(calledSideCallId, remoteCallerAddress, request, responseReceiveQueue[iStressFactor], (void*) applicationData); // Wait for the request OsMsg* requestEvent = NULL; OsTime queueWaitTime(5,0); // (secs, usecs) requestReceiveQueue.receive(requestEvent, queueWaitTime); CPPUNIT_ASSERT(requestEvent); CPPUNIT_ASSERT(requestEvent->getMsgType() == OsMsg::PHONE_APP); CPPUNIT_ASSERT(requestEvent->getMsgSubType() == CpCallManager::CP_SIP_MESSAGE); // Get the actual request const SipMessage* requestPtr = ((SipMessageEvent&)requestEvent).getMessage(); // TODO: validate the request transaction info. // END DIRTY USE OF SIPXTAPI SIPX_CALL hDestroyedCall = hCall ; destroyCall(hCall) ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE_HELD, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, UniversalEventValidatorCallback, &validatorCalling), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, AutoAnswerCallback, NULL), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, UniversalEventValidatorCallback, &validatorCalled), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hReceivingLine), SIPX_RESULT_SUCCESS); // Delay to finish transaction on in dialog request and response OsTask::delay(TEST_DELAY); } // Wait a transaction timeout to be sure the in dialog request/response queues are no // longer used SIPX_INSTANCE_DATA* sipXtapiCallingContext = (SIPX_INSTANCE_DATA*) g_hInst; OsTask::delay(sipXtapiCallingContext->pSipUserAgent->getSipStateTransactionTimeout()); //OsTask::delay(TEST_DELAY); for (iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { delete (responseReceiveQueue[iStressFactor]); responseReceiveQueue[iStressFactor] = NULL; } checkForLeaks();}// A calls B, B is busyvoid sipXtapiTestSuite::testCallBusy() { bool bRC ; EventValidator validatorCalling("testCallBusy.calling") ; EventValidator validatorCalled("testCallBusy.calling") ; for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestCallBusy (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); SIPX_CALL hCall ; SIPX_LINE hLine ; SIPX_LINE hReceivingLine; validatorCalling.reset() ; validatorCalled.reset() ; // Setup Auto-answer call back sipxEventListenerAdd(g_hInst2, AutoRejectCallback, NULL) ; sipxEventListenerAdd(g_hInst2, UniversalEventValidatorCallback, &validatorCalled) ; sipxEventListenerAdd(g_hInst, UniversalEventValidatorCallback, &validatorCalling) ; sipxLineAdd(g_hInst2, "sip:foo@127.0.0.1:9100", &hReceivingLine, CONTACT_LOCAL); bRC = validatorCalled.waitForLineEvent(hReceivingLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; createCall(&hLine, &hCall) ; bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; sipxCallConnect(hCall, "sip:foo@127.0.0.1:9100") ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_DIALTONE_UNKNOWN, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_REMOTE_OFFERING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_BUSY, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side (auto rejects) bRC = validatorCalled.waitForCallEvent(g_hAutoRejectCallbackLine, g_hAutoRejectCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoRejectCallbackLine, g_hAutoRejectCallbackCall, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoRejectCallbackLine, g_hAutoRejectCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(g_hAutoRejectCallbackLine, g_hAutoRejectCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Calling side should disconnect SIPX_CALL hDestroyedCall = hCall ; destroyCall(hCall) ; // Finally, calling side is cleaned up bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, UniversalEventValidatorCallback, &validatorCalling), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, AutoRejectCallback, NULL), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, UniversalEventValidatorCallback, &validatorCalled), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hReceivingLine), SIPX_RESULT_SUCCESS); } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}// A calls B, B redirects to Cvoid sipXtapiTestSuite::testCallRedirect(){ bool bRC ; EventValidator validatorCalling("testCallRedirect.calling") ; EventValidator validatorRedirector("testCallRedirect.redirector") ; EventValidator validatorCalled("testCallRedirected.called") ; for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestCallRedirect (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); SIPX_CALL hCall ; SIPX_LINE hLine ; SIPX_LINE hRedirectLine ; SIPX_LINE hCalledLine ; validatorCalling.reset() ; validatorRedirector.reset() ; validatorCalled.reset() ; // Setup callbacks resetAutoAnswerCallback() ; sipxEventListenerAdd(g_hInst, UniversalEventValidatorCallback, &validatorCalling) ; sipxEventListenerAdd(g_hInst2, UniversalEventValidatorCallback, &validatorRedirector) ; sipxEventListenerAdd(g_hInst2, AutoRedirectCallback, NULL) ; sipxEventListenerAdd(g_hInst3, UniversalEventValidatorCallback, &validatorCalled) ; sipxEventListenerAdd(g_hInst3, AutoAnswerCallback, NULL) ; sipxLineAdd(g_hInst2, "sip:foo@127.0.0.1:9100", &hRedirectLine, CONTACT_LOCAL); sipxLineAdd(g_hInst3, "sip:foo@127.0.0.1:10000", &hCalledLine, CONTACT_LOCAL); bRC = validatorRedirector.waitForLineEvent(hRedirectLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForLineEvent(hCalledLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -