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() ; validatorCalling.ignoreEventCategory(EVENT_CATEGORY_MEDIA); validatorCalled.ignoreEventCategory(EVENT_CATEGORY_MEDIA); // 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:[email protected]:9100", &hReceivingLine, CONTACT_AUTO); bRC = validatorCalled.waitForLineEvent(hReceivingLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; rc = sipxLineAddAlias(hReceivingLine, "sip:[email protected]: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:[email protected]:9100") ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, 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_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; validatorCalling.reset() ; validatorCalled.reset() ; validatorCalling.ignoreEventCategory(EVENT_CATEGORY_MEDIA); validatorCalled.ignoreEventCategory(EVENT_CATEGORY_MEDIA); 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:[email protected]:9100") ; // Validate Calling Side bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, 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_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; // Validate Called Side bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ; CPPUNIT_ASSERT(bRC) ; bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_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(); }
// Place a call to szSipUrl as szFromIdentity bool placeCall(char* szSipUrl, char* szFromIdentity, char* szUsername, char* szPassword, char *szRealm) { bool bRC = false ; if ((szFromIdentity == NULL) || strlen(szFromIdentity) == 0) { szFromIdentity = "\"PlaceCall Demo\" <sip:placecalldemo@localhost>" ; } printf("<-> Placing call to \"%s\" as \"%s\"\n", szSipUrl, szFromIdentity) ; printf("<-> Username: %s, passwd: %s, realm: %s (all required for auth)\n", szUsername, szPassword, szRealm) ; sipxLineAdd(g_hInst, szFromIdentity, &g_hLine) ; if (szUsername && szPassword && szRealm) { sipxLineAddCredential(g_hLine, szUsername, szPassword, szRealm) ; } #if defined(_WIN32) && defined(VIDEO) if (bVideo) { gPreviewDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gPreviewDisplay.handle = ghPreview; sipxConfigSetVideoPreviewDisplay(g_hInst, &gPreviewDisplay); } #endif sipxCallCreate(g_hInst, g_hLine, &g_hCall) ; dumpLocalContacts(g_hCall) ; // get first contact size_t numAddresses = 0; SIPX_CONTACT_ADDRESS address; sipxConfigGetLocalContacts(g_hInst, &address, 1, numAddresses); if (bUseCustomTransportReliable) { sipxConfigExternalTransportAdd(g_hInst, ghTransport, true, "tribble", address.cIpAddress, -1, tribbleProc, "tribble"); startTribbleListener(address.cIpAddress); } if (bUseCustomTransportUnreliable) { startFlibbleListener(address.cIpAddress); sipxConfigExternalTransportAdd(g_hInst, ghTransport, true, "flibble", address.cIpAddress, -1, flibbleProc, address.cIpAddress); gContactId = lookupContactId(address.cIpAddress, "flibble", ghTransport); } #if defined(_WIN32) && defined(VIDEO) if (bVideo) { gDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gDisplay.handle = ghVideo; sipxCallConnect(g_hCall, szSipUrl, gContactId, &gDisplay, NULL); } else #endif { sipxCallConnect(g_hCall, szSipUrl, gContactId); } bRC = WaitForSipXEvent(CALLSTATE_CONNECTED, 30) ; return bRC ; }
void sipXtapiTestSuite::testLines() { OsSysLog::initialize(0, "sipxTapi_testLines"); OsSysLog::setLoggingPriority(PRI_DEBUG); OsSysLog::setOutputFile(0, "/sdcard/sipxtapi.log"); for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_CALL hCall ; SIPX_LINE hLineGeorge ; SIPX_LINE hLineJane ; SIPX_LINE hLineBob ; SIPX_LINE hLineJill ; printf("\ntestLines (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, URL_GEORGE_AT_JUNGLE, &hLineGeorge), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, URL_JANE_AT_JUNGLE, &hLineJane), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, URL_BOB_AT_LOCALHOST, &hLineBob), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, URL_JILL_AT_LOCALHOST, &hLineJill), SIPX_RESULT_SUCCESS) ; /** * Make call as George to Jill */ // Setup Auto-answer call back sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST) ; printf("createCall line: %d %s\n", hLineGeorge, URL_GEORGE_AT_JUNGLE); createCall(hLineGeorge, &hCall) ; sipxCallConnect(hCall, URL_JILL_AT_LOCALHOST) ; OsTask::delay(CALL_DELAY*2) ; destroyCall(hCall) ; OsTask::delay(CALL_DELAY*4) ; // Remove George's line g_lineRecorder2.clear() ; SIPX_RESULT rc = sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST); CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineGeorge), SIPX_RESULT_SUCCESS) ; OsTask::delay(CALL_DELAY*2); /** * Make call as Jane to Bob */ sipxEventListenerAdd(g_hInst, linetest_verify_lineurl, (void*)URL_JANE_AT_JUNGLE) ; sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_BOB_AT_LOCALHOST) ; printf("createCall line: %d %s\n", hLineJane, URL_JANE_AT_JUNGLE); createCall(hLineJane, &hCall) ; sipxCallConnect(hCall, URL_BOB_AT_LOCALHOST) ; OsTask::delay(CALL_DELAY*2) ; destroyCall(hCall) ; OsTask::delay(CALL_DELAY*4) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, linetest_verify_lineurl, (void*)URL_JANE_AT_JUNGLE), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_BOB_AT_LOCALHOST), SIPX_RESULT_SUCCESS) ; /** * Make call as Jane to BOGUS (line not defined) */ sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_EMPTY_STRING) ; createCall(hLineJane, &hCall) ; sipxCallConnect(hCall, URL_BOGUS_AT_LOCALHOST) ; OsTask::delay(22000) ; destroyCall(hCall) ; OsTask::delay(CALL_DELAY*4) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_EMPTY_STRING), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineJane), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineBob), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineJill), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks(); }