📄 sipxtapitestconference.cpp
字号:
////// Copyright (C) 2005-2006 SIPez LLC.// Licensed to SIPfoundry under a Contributor Agreement.//// Copyright (C) 2004-2006 SIPfoundry Inc.// Licensed by SIPfoundry under the LGPL license.//// Copyright (C) 2004-2006 Pingtel Corp.// Licensed to SIPfoundry under a Contributor Agreement.// //// $$//////////////////////////////////////////////////////////////////////////////#include <cppunit/CompilerOutputter.h>#include <cppunit/extensions/TestFactoryRegistry.h>#include <cppunit/ui/text/TestRunner.h>#include "sipXtapiTest.h"#include "EventValidator.h"#include "callbacks.h"extern SIPX_INST g_hInst;extern SIPX_INST g_hInst2;extern SIPX_INST g_hInst3;extern SIPX_INST g_hInst5;extern bool g_bCallbackCalled;// Do not check in with print enabled//#define TEST_PRINT// Setup conference and drop conference as a wholevoid sipXtapiTestSuite::testConfBasic1(){ bool bRC ; EventValidator validatorCalling("testConfBasic1.calling") ; EventValidator validatorCalled1("testConfBasic1.called1") ; EventValidator validatorCalled2("testConfBasic1.called2") ; for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestConfBasic1 (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); SIPX_CALL hCall1 ; SIPX_CALL hCall2 ; SIPX_CONF hConf ; SIPX_LINE hLine ; SIPX_LINE hReceivingLine1; SIPX_LINE hReceivingLine2; SIPX_CALL hCheckCalls[10] ; size_t nCheckCalls ; validatorCalling.reset() ; validatorCalled1.reset() ; validatorCalled2.reset() ; // Setup Auto-answer call back resetAutoAnswerCallback() ; resetAutoAnswerCallback2() ; sipxEventListenerAdd(g_hInst, UniversalEventValidatorCallback, &validatorCalling) ; sipxEventListenerAdd(g_hInst2, UniversalEventValidatorCallback, &validatorCalled1) ; sipxEventListenerAdd(g_hInst2, AutoAnswerCallback, NULL) ; sipxEventListenerAdd(g_hInst3, UniversalEventValidatorCallback, &validatorCalled2) ; sipxEventListenerAdd(g_hInst3, AutoAnswerCallback2, NULL) ; // Create Lines CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:foo@127.0.0.1:8000", &hLine), SIPX_RESULT_SUCCESS) ; bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, "sip:foo@127.0.0.1:9100", &hReceivingLine1, CONTACT_AUTO), SIPX_RESULT_SUCCESS) ; bRC = validatorCalled1.waitForLineEvent(hReceivingLine1, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst3, "sip:foo@127.0.0.1:10000", &hReceivingLine2, CONTACT_AUTO), SIPX_RESULT_SUCCESS) ; bRC = validatorCalled2.waitForLineEvent(hReceivingLine2, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Setup first leg CPPUNIT_ASSERT_EQUAL(sipxConferenceCreate(g_hInst, &hConf), SIPX_RESULT_SUCCESS) ; // Cannot set property on media interface until at least one call is in the conference CPPUNIT_ASSERT(sipxConferenceSetMediaProperty(hConf, "foo", "bar") != SIPX_RESULT_SUCCESS);#ifdef TEST_PRINT UtlString confDumpString; sipxConfDataToString(hConf, confDumpString); printf("testConfBasic1 Setup first leg conf:\n %s\n", confDumpString.data());#endif CPPUNIT_ASSERT_EQUAL(sipxConferenceAdd(hConf, hLine, "sip:blah@127.0.0.1:9100", &hCall1), SIPX_RESULT_SUCCESS) ;#ifdef TEST_PRINT UtlString callDumpString; sipxConfDataToString(hConf, confDumpString); printf("testConfBasic1 add first leg conf:\n %s\n", confDumpString.data()); sipxCallDataToString(hCall1, callDumpString); printf("testConfBasic1 add first leg call:\n %s\n", callDumpString.data());#endif CPPUNIT_ASSERT(sipxConferenceSetMediaProperty(hConf, "foo", "bar") == SIPX_RESULT_SUCCESS); // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_DIALTONE, CALLSTATE_DIALTONE_CONFERENCE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_REMOTE_OFFERING, CALLSTATE_REMOTE_OFFERING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_REMOTE_ALERTING, CALLSTATE_REMOTE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; CPPUNIT_ASSERT(sipxCallSetMediaProperty(hCall1, "connectionName", "connect1") == SIPX_RESULT_SUCCESS); // Validate Called Side bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; // Make sure we don't have any unexpected events CPPUNIT_ASSERT(!validatorCalling.validateNoWaitingEvent()) ; CPPUNIT_ASSERT(!validatorCalled1.validateNoWaitingEvent()) ; CPPUNIT_ASSERT(!validatorCalled2.validateNoWaitingEvent()) ; // Validate Get Calls CPPUNIT_ASSERT_EQUAL(sipxConferenceGetCalls(hConf, hCheckCalls, 10, nCheckCalls), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(nCheckCalls == 1) ; CPPUNIT_ASSERT(hCheckCalls[0] == hCall1) ;#ifdef TEST_PRINT sipxConfDataToString(hConf, confDumpString); printf("testConfBasic1 steady state first leg conf:\n %s\n", confDumpString.data()); sipxCallDataToString(hCall1, callDumpString); printf("testConfBasic1 steady state first leg call:\n %s\n", callDumpString.data());#endif // Setup 2nd Leg CPPUNIT_ASSERT_EQUAL(sipxConferenceAdd(hConf, hLine, "sip:blah2@127.0.0.1:10000", &hCall2), SIPX_RESULT_SUCCESS) ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_DIALTONE, CALLSTATE_DIALTONE_CONFERENCE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_REMOTE_OFFERING, CALLSTATE_REMOTE_OFFERING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_REMOTE_ALERTING, CALLSTATE_REMOTE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; // Make sure we don't have any unexpected events CPPUNIT_ASSERT(!validatorCalling.validateNoWaitingEvent()) ; CPPUNIT_ASSERT(!validatorCalled1.validateNoWaitingEvent()) ; CPPUNIT_ASSERT(!validatorCalled2.validateNoWaitingEvent()) ; // Validate Get Calls CPPUNIT_ASSERT_EQUAL(sipxConferenceGetCalls(hConf, hCheckCalls, 10, nCheckCalls), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(nCheckCalls == 2) ; CPPUNIT_ASSERT(hCheckCalls[0] == hCall1) ; CPPUNIT_ASSERT(hCheckCalls[1] == hCall2) ; CPPUNIT_ASSERT(hCheckCalls[0] != hCheckCalls[1]) ;#ifdef TEST_PRINT sipxConfDataToString(hConf, confDumpString); printf("testConfBasic1 steady state second leg conf:\n %s\n", confDumpString.data()); sipxCallDataToString(hCall1, callDumpString); printf("testConfBasic1 steady state second leg call1:\n %s\n", callDumpString.data()); sipxCallDataToString(hCall2, callDumpString); printf("testConfBasic1 steady state second leg call2:\n %s\n", callDumpString.data());#endif // Tear down conference CPPUNIT_ASSERT_EQUAL(sipxConferenceDestroy(hConf), SIPX_RESULT_SUCCESS) ; // Validate Calling Side // TODO: FIX PT-1 //bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; //CPPUNIT_ASSERT(bRC) ; //bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; //CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, false) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, false) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall1, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, false) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall2, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, false) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Sides bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled1.waitForCallEvent(g_hAutoAnswerCallbackLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled2.waitForCallEvent(g_hAutoAnswerCallbackLine2, g_hAutoAnswerCallbackCall2, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -