📄 sipxtapitestline.cpp
字号:
}void sipXtapiTestSuite::testLineAliases() { bool bRC ; EventValidator validatorCalling("testLineAliases.calling") ; EventValidator validatorCalled("testLineAliases.called") ; for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestLineAliases (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); SIPX_CALL hCall ; SIPX_LINE hLine ; SIPX_LINE hReceivingLine; SIPX_RESULT rc ; validatorCalling.reset() ; validatorCalled.reset() ; // Setup Auto-answer call back resetAutoAnswerCallback() ; sipxEventListenerAdd(g_hInst2, AutoAnswerCallback, NULL) ; sipxEventListenerAdd(g_hInst2, UniversalEventValidatorCallback, &validatorCalled) ; sipxEventListenerAdd(g_hInst, UniversalEventValidatorCallback, &validatorCalling) ; sipxLineAdd(g_hInst2, "sip:foo@127.0.0.1:9100", &hReceivingLine, CONTACT_AUTO); bRC = validatorCalled.waitForLineEvent(hReceivingLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; rc = sipxLineAddAlias(hReceivingLine, "sip:alias@127.0.0.1:9100") ; CPPUNIT_ASSERT(rc == SIPX_RESULT_SUCCESS) ; 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_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(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, 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) ; 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(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; validatorCalling.reset() ; validatorCalled.reset() ; resetAutoAnswerCallback() ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS); createCall(&hLine, &hCall) ; bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; sipxCallConnect(hCall, "sip:alias@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_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(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, true) ; CPPUNIT_ASSERT(bRC) ; connectionId = -1; CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT(connectionId != -1) ; 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(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, 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); } OsTask::delay(TEST_DELAY) ; checkForLeaks();}void sipXtapiTestSuite::testRegistration(){ for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { TestRegistrar testRegistrar; SIPX_RESULT rc ; testRegistrar.init(); printf("\ntestRegistration (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; rc = sipxEventListenerAdd(g_hInst4, lineCallback, NULL) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; rc = sipxConfigSetOutboundProxy(g_hInst4, "127.0.0.1:5070") ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; SIPX_LINE hLine; rc =sipxLineAdd(g_hInst4, "sip:anon@127.0.0.1:12070", &hLine) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; rc =sipxLineRegister(hLine, true) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; g_lineRecorder.clear() ; // try to register, for a user that needs credentials, // but without credentials rc = sipxLineRemove(hLine); CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_UNREGISTERING, LINESTATE_UNREGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_UNREGISTERED, LINESTATE_UNREGISTERED_NORMAL); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; g_lineRecorder.clear() ; rc = sipxLineAdd(g_hInst4, "sip:mike@127.0.0.1:12070", &hLine) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; rc = sipxLineRegister(hLine, true) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_REGISTER_FAILED_NOT_AUTHORIZED); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; g_lineRecorder.clear() ; rc = sipxLineAddCredential(hLine, "mike", "1234", "TestRegistrar") ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; rc = sipxLineRegister(hLine, true) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; rc = sipxLineRemove(hLine) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_UNREGISTERING, LINESTATE_UNREGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_UNREGISTERED, LINESTATE_UNREGISTERED_NORMAL); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; rc = sipxEventListenerRemove(g_hInst4, lineCallback, NULL) ; CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}void sipXtapiTestSuite::testBadRegistrarRegistration(){ for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { TestRegistrar testRegistrar; testRegistrar.init(); printf("\ntestBadRegistrarRegistration (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxConfigSetOutboundProxy(g_hInst4, "127.0.0.1:5070"), SIPX_RESULT_SUCCESS); // receiving a 480 response SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:xyzzy480@127.0.0.1:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_CAUSE_UNKNOWN); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; g_lineRecorder.clear() ; // receiving a 503 response CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:xyzzy503@127.0.0.1:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_CAUSE_UNKNOWN); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; g_lineRecorder.clear() ; // receiving a 600 response CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:xyzzy600@127.0.0.1:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTER_FAILED, LINESTATE_CAUSE_UNKNOWN); OsTask::delay(1000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}void sipXtapiTestSuite::testReRegistration(){ for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { TestRegistrar testRegistrar; testRegistrar.init(); printf("\ntestReRegistration (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxConfigSetOutboundProxy(g_hInst4, "127.0.0.1:5070"), SIPX_RESULT_SUCCESS); SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst4, "sip:mike@127.0.0.1:12070", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxConfigSetRegisterExpiration(g_hInst4, 10), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineAddCredential(hLine, "mike", "1234", "TestRegistrar"), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRegister(hLine, true), SIPX_RESULT_SUCCESS) ; g_lineRecorder.addCompareEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERING, LINESTATE_REGISTERING_NORMAL); g_lineRecorder.addCompareEvent(hLine, LINESTATE_REGISTERED, LINESTATE_REGISTERED_NORMAL); printf("\nWaiting for 12 seconds! (for the re-registration test)"); OsTask::delay(12000); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; OsTask::delay(1000); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst4, lineCallback, NULL), SIPX_RESULT_SUCCESS); } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -