📄 sipxtapitestline.cpp
字号:
//// Copyright (C) 2004, 2005 Pingtel Corp.// //// $$//////////////////////////////////////////////////////////////////////////////#include <string.h>#include <os/OsDefs.h>#include <cppunit/CompilerOutputter.h>#include <cppunit/extensions/TestFactoryRegistry.h>#include <cppunit/ui/text/TestRunner.h>#include "sipXtapiTest.h"#include "TestRegistrar.h"#include "EventRecorder.h"#include "EventValidator.h"#include "callbacks.h"extern SIPX_INST g_hInst;extern EventRecorder g_recorder ;extern EventRecorder g_lineRecorder; EventRecorder g_lineRecorder2; extern SIPX_INST g_hInst2;extern EventRecorder g_recorder2 ;extern SIPX_INST g_hInst3;extern EventRecorder g_recorder3 ;extern SIPX_INST g_hInst4;extern EventRecorder g_recorder4;extern SIPX_INST g_hInstInfo;extern bool g_bCallbackCalled;void sipXtapiTestSuite::testLineAPI_Add() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_LINE hLine = SIPX_LINE_NULL ; SIPX_LINE hLine2 = SIPX_LINE_NULL ; printf("\ntestLineAPI_Add (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); // Add Line CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:bandreasen@pingtel.com", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(hLine) ; // Re-Add Line CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:bandreasen@pingtel.com", &hLine2), SIPX_RESULT_FAILURE) ; CPPUNIT_ASSERT(hLine2 == SIPX_LINE_NULL) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}void sipXtapiTestSuite::testLineAPI_Remove() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_LINE hLine = SIPX_LINE_NULL ; printf("\ntestLineAPI_Remove (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); // Add a line to remove CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:removeme@pingtel.com", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(hLine) ; // Remove it and remove it again CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_FAILURE) ; // Remove something invalid CPPUNIT_ASSERT_EQUAL(sipxLineRemove(SIPX_LINE_NULL), SIPX_RESULT_INVALID_ARGS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}void sipXtapiTestSuite::testLineAPI_Credential() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_LINE hLine = SIPX_LINE_NULL ; printf("\ntestLineAPI_Credential (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); // Add a line to remove CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:credential@pingtel.com", &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(hLine) ; CPPUNIT_ASSERT_EQUAL(sipxLineAddCredential(hLine, "userID", "passwd", "pingtel.com"), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineAddCredential(hLine, "userID", "passwd", "pingtel2.com"), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}void sipXtapiTestSuite::testLineAPI_Get() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_LINE hLine = SIPX_LINE_NULL ; SIPX_LINE hLines[32] ; size_t nLines ; size_t i; const char* szURI = "sip:removeme@pingtel.com" ; printf("\ntestLineAPI_Get (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); // First clear any lines CPPUNIT_ASSERT_EQUAL(sipxLineGet(g_hInst, hLines, 32, nLines), SIPX_RESULT_SUCCESS) ; for (i=0; i<nLines; i++) { CPPUNIT_ASSERT(hLines[i] != SIPX_LINE_NULL) ; CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLines[i]), SIPX_RESULT_SUCCESS) ; } // Make sure the list is empty nLines = 203431 ; CPPUNIT_ASSERT_EQUAL(sipxLineGet(g_hInst, hLines, 32, nLines), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(nLines, (size_t) 0) ; // Add and element and verify it is present CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, szURI, &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(hLine) ; CPPUNIT_ASSERT_EQUAL(sipxLineGet(g_hInst, hLines, 32, nLines), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(nLines, (size_t) 1) ; CPPUNIT_ASSERT(hLines[0] != SIPX_LINE_NULL) ; char cBuf[256] ; size_t nActual ; CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, cBuf, sizeof(cBuf), nActual), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(strcasecmp(cBuf, szURI) == 0) ; CPPUNIT_ASSERT_EQUAL(strlen(cBuf)+1, nActual) ; // Clean up CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLines[i]), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}void sipXtapiTestSuite::testLineAPI_GetURI() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { SIPX_LINE hLine = SIPX_LINE_NULL ; const char* szURI = "sip:removeme@pingtel.com" ; printf("\ntestLineAPI_GetURI (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); // Add and element CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, szURI, &hLine), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(hLine) ; // Standard get char cBuf[256] ; size_t nActual ; CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, cBuf, sizeof(cBuf), nActual), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(strcasecmp(cBuf, szURI) == 0) ; CPPUNIT_ASSERT_EQUAL(strlen(cBuf)+1, nActual) ; // Ask for length CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, NULL, sizeof(cBuf), nActual), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT_EQUAL(nActual, strlen(szURI) + 1) ; // Small Buffer (doesn't stomp, etc) strcpy(cBuf, "1234567890") ; CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, cBuf, 5, nActual), SIPX_RESULT_SUCCESS) ; CPPUNIT_ASSERT(strcasecmp(cBuf, "sip:") == 0) ; CPPUNIT_ASSERT(cBuf[5] == '6') ; // Clean up CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks() ;}bool linetest_verify_lineurl(SIPX_EVENT_CATEGORY event, void* pInfo, void* pUserData){ if (event == EVENT_CATEGORY_LINESTATE) { SIPX_LINESTATE_INFO* pLineInfo = (SIPX_LINESTATE_INFO*) pInfo; SIPX_LINE hLine = pLineInfo->hLine; g_lineRecorder2.addEvent(pLineInfo->hLine, pLineInfo->event, pLineInfo->cause); char szBuffer[500] ; size_t nBuffer ; CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, szBuffer, sizeof(szBuffer), nBuffer), SIPX_RESULT_SUCCESS) ; // printf("comparing %s to %s\n", pUserData, szBuffer) ; CPPUNIT_ASSERT(strcmp((char*) pUserData, szBuffer) == 0) ; } return true;}/** * Source Call: * Line1: george@thejungle.com * Line2: jane@thejungle.com * * Target Call: * Line1: bob@127.0.0.1:9100 * Line2: jill@127.0.0.1:9100 * * This test verifies that the line handles return with the sipX events are sane */#define URL_GEORGE_AT_JUNGLE "sip:george@thejungle.com"#define URL_JANE_AT_JUNGLE "sip:jane@thejungle.com"#define URL_BOB_AT_LOCALHOST "sip:bob@127.0.0.1:9100"#define URL_JILL_AT_LOCALHOST "sip:jill@127.0.0.1:9100"#define URL_BOGUS_AT_LOCALHOST "sip:bogus@127.0.0.1:900"#define URL_EMPTY_STRING ""void sipXtapiTestSuite::testLines() { 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) ; 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() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST), 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) ; 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();}bool lineCallback(SIPX_EVENT_CATEGORY event, void* pInfo, void* pUser){ if (event == EVENT_CATEGORY_LINESTATE) { SIPX_LINESTATE_INFO* pLineInfo = (SIPX_LINESTATE_INFO*) pInfo; g_lineRecorder.addEvent(pLineInfo->hLine, pLineInfo->event, pLineInfo->cause); } return true;}void sipXtapiTestSuite::testLineEvents() { for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++) { printf("\ntestLineEvents (%2d of %2d)", iStressFactor+1, STRESS_FACTOR); g_lineRecorder.clear() ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerAdd(g_hInst, lineCallback, NULL), SIPX_RESULT_SUCCESS); // TODO - we need to figure out how to better test registrar interaction. // It might require creating a test registrar that responds to REGISTER messages. SIPX_LINE hLine; CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, "sip:115@hopefullythisisnotarealdomain.com", &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_REGISTER_FAILED, LINESTATE_REGISTER_FAILED_COULD_NOT_CONNECT); OsTask::delay(500); CPPUNIT_ASSERT(g_lineRecorder.compare()) ; CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, lineCallback, NULL), SIPX_RESULT_SUCCESS); CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS) ; } OsTask::delay(TEST_DELAY) ; checkForLeaks();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -