⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipxtapitestconfig.cpp

📁 基于sipfoundy 公司开发的sipx协议API
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        rc = sipxConfigGetLocalSipTcpPort(hHandle, &iPort) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        CPPUNIT_ASSERT_EQUAL(iPort, 8100) ;    #if 0        // Bob 2005-04-06: Wait until TLS is supported/enabled for this        // this test case        rc = sipxConfigGetLocalSipTlsPort(hHandle, &iPort) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        CPPUNIT_ASSERT_EQUAL(iPort, 8101) ;    #endif        rc = sipxInitialize(&hHandle2, 8100, 8100, 8101, 9999, DEFAULT_CONNECTIONS, DEFAULT_IDENTITY, DEFAULT_BIND_ADDRESS, TRUE) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        rc = sipxConfigGetLocalSipUdpPort(hHandle2, &iPort) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        CPPUNIT_ASSERT(portIsValid(iPort) && iPort > 8100) ;        rc = sipxConfigGetLocalSipTcpPort(hHandle2, &iPort) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        CPPUNIT_ASSERT(portIsValid(iPort) && iPort > 8100) ;                SIPX_CONTACT_ADDRESS addresses[32];        size_t actualNum = 0;                sipxConfigGetLocalContacts(hHandle2, addresses, 32, actualNum);        for (size_t i = 0; i < actualNum; i++)        {            CPPUNIT_ASSERT(addresses[i].iPort > 8100);        }            #if 0        // Bob 2005-04-06: Wait until TLS is supported/enabled for this        // this test case        rc = sipxConfigGetLocalSipTlsPort(hHandle2, &iPort) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        CPPUNIT_ASSERT(portIsValid(iPort) && iPort > 8100) ;    #endif        rc = sipxUnInitialize(hHandle) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        rc = sipxUnInitialize(hHandle2) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;        }    // Does not create a call -- no need to pause    // OsTask::delay(TEST_DELAY) ;        checkForLeaks() ;}void sipXtapiTestSuite::testConfigLog() {    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)    {        printf("\ntestConfigLog (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);        //tests sipxConfigSetLogLevel        CPPUNIT_ASSERT_EQUAL( sipxConfigSetLogLevel(LOG_LEVEL_ERR), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT_EQUAL( sipxConfigSetLogLevel(LOG_LEVEL_DEBUG), SIPX_RESULT_SUCCESS);        //tests sipxConfigSetLogFile        CPPUNIT_ASSERT_EQUAL( sipxConfigSetLogFile(NULL), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT_EQUAL( sipxConfigSetLogFile("C:\\example.log"), SIPX_RESULT_SUCCESS);        sipxLogCallback pcallBack = NULL;        CPPUNIT_ASSERT_EQUAL( sipxConfigSetLogCallback(pcallBack), SIPX_RESULT_SUCCESS);            }        // Does not create a call -- no need to pause    // OsTask::delay(TEST_DELAY) ;        checkForLeaks() ;}void sipXtapiTestSuite::testConfigOutOfBand(){    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)    {        printf("\ntestConfigOutOfBand (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);        //tests sipxConfigEnableOutOfBandDTMF and sipxConfigIsOutOfBandDTMFEnabled        CPPUNIT_ASSERT_EQUAL( sipxConfigEnableOutOfBandDTMF(g_hInst,true), SIPX_RESULT_SUCCESS);        bool test = false;        CPPUNIT_ASSERT_EQUAL( sipxConfigIsOutOfBandDTMFEnabled(g_hInst, test), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT_EQUAL(test, true);        CPPUNIT_ASSERT_EQUAL( sipxConfigEnableOutOfBandDTMF(g_hInst, false), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT_EQUAL( sipxConfigIsOutOfBandDTMFEnabled(g_hInst, test), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT_EQUAL(test, false);    }    // Does not create a call -- no need to pause    // OsTask::delay(TEST_DELAY) ;        checkForLeaks() ;}void sipXtapiTestSuite::testTeardown(){    SIPX_INST hInst1 = NULL ;    SIPX_INST hInst2 = NULL ;    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)    {        printf("\ntestTeardown (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);        // printf("\nInitializing 2 instances\n");        sipxInitialize(&hInst1, 8000, 8000, 8001, 8050) ;        sipxInitialize(&hInst2, 9100, 9100, 9101, 9050) ;        // printf("hInst1: %08X, hInst2: %08X\n", hInst1, hInst2);        // printf("Uninitializing 2 instances\n");        sipxUnInitialize(hInst2);        sipxUnInitialize(hInst1);    }    // Does not create a call -- no need to pause    // OsTask::delay(TEST_DELAY) ;        checkForLeaks() ;} bool config_callback(SIPX_EVENT_CATEGORY category,                     void* pInfo,                     void* pUserData){    if (category == EVENT_CATEGORY_CONFIG)    {        SIPX_CONFIG_INFO* pConfigInfo = (SIPX_CONFIG_INFO*) pInfo;        g_recorder.addEvent(pConfigInfo);    }        return true;}bool codec_CallBack_Place(SIPX_EVENT_CATEGORY category,                          void* pInfo,                          void* pUserData){    if (category == EVENT_CATEGORY_CALLSTATE)    {        SIPX_CALLSTATE_INFO* pCallInfo = (SIPX_CALLSTATE_INFO*)pInfo;        g_recorder.addEvent(pCallInfo->hLine, pCallInfo->event, pCallInfo->cause) ;        if (pCallInfo->cause == CALLSTATE_AUDIO_START)        {            char szMsg[128];            sprintf(szMsg, "Codec %s", pCallInfo->codecs.audioCodec.cName);            g_recorder.addMsgString(pCallInfo->hLine, (const char*)szMsg);        }    }    return true;}bool codec_CallBack_Receive(SIPX_EVENT_CATEGORY category,                             void* pInfo,                             void* pUserData){         if (category == EVENT_CATEGORY_CALLSTATE)    {        SIPX_CALLSTATE_INFO* pCallInfo = (SIPX_CALLSTATE_INFO*)pInfo;        SIPX_LINE hLine = pCallInfo->hLine;        SIPX_CALL hCall = pCallInfo->hCall;                g_recorder2.addEvent(hLine, pCallInfo->event, pCallInfo->cause) ;        // If we have user data verify the line url against it        if (pUserData)        {            char szBuffer[500] ;             size_t nBuffer ;            if (strlen((const char*) pUserData))            {                if (hLine)  // hLine can be 0, and therefore, sipxLineGetURI should fail)                {                    CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, szBuffer, sizeof(szBuffer), nBuffer), SIPX_RESULT_SUCCESS) ;                    // an event can come in with what appears to be the "wrong" user data.                    // for instance, if a listener is removed and a new listener is added immediately with new user data.                    // printf("comparing %s to %s\n", pUserData, szBuffer) ;                    //CPPUNIT_ASSERT(strcmp((char*) pUserData, szBuffer) == 0) ;                }            }            //else            //{                //CPPUNIT_ASSERT_EQUAL(sipxLineGetURI(hLine, szBuffer, sizeof(szBuffer), nBuffer), SIPX_RESULT_FAILURE) ;            //}        }        switch(pCallInfo->event)        {            case CALLSTATE_OFFERING:                sipxCallAccept(hCall) ;                break ;            case CALLSTATE_ALERTING:                sipxCallAnswer(hCall) ;                break ;            case CALLSTATE_DISCONNECTED:                sipxCallDestroy(hCall) ;                 break ;            case CALLSTATE_AUDIO_EVENT:                if (pCallInfo->cause == CALLSTATE_AUDIO_START)                {                    char szMsg[128];                    sprintf(szMsg, "Codec %s", pCallInfo->codecs.audioCodec.cName);                    g_recorder2.addMsgString(pCallInfo->hLine, (const char*)szMsg);                }                break;            default:                break ;        }    }             return true;}void sipXtapiTestSuite::testConfigCodecPreferences(){    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)    {        printf("\ntestConfigCodecPreferences (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);        SIPX_CALL hCall ;        SIPX_LINE hLine ;        SIPX_LINE hReceivingLine;        sipxConfigSetLogLevel(LOG_LEVEL_DEBUG);        sipxConfigSetLogFile("codec.log");            g_recorder.clear() ;        g_recorder2.clear() ;            sipxConfigSetAudioCodecPreferences(g_hInst, AUDIO_CODEC_BW_HIGH);        sipxConfigSetAudioCodecPreferences(g_hInst2, AUDIO_CODEC_BW_HIGH);        // Setup Auto-answer call back        sipxLineAdd(g_hInst2, "sip:foo@127.0.0.1:9100", &hReceivingLine, CONTACT_AUTO);        sipxEventListenerAdd(g_hInst2, codec_CallBack_Receive, NULL) ;        sipxEventListenerAdd(g_hInst, codec_CallBack_Place, NULL) ;        createCall(&hLine, &hCall) ;        sipxCallConnect(hCall, "sip:foo@127.0.0.1:9100") ;        OsTask::delay(CALL_DELAY*2) ;                int connectionId = -1;                CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT(connectionId != -1) ;                        destroyCall(hCall) ;        OsTask::delay(CALL_DELAY * 4) ;        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, codec_CallBack_Place, NULL), SIPX_RESULT_SUCCESS) ;        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, codec_CallBack_Receive, NULL), SIPX_RESULT_SUCCESS) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_DIALTONE, CALLSTATE_DIALTONE_UNKNOWN) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_REMOTE_OFFERING, CALLSTATE_REMOTE_OFFERING_NORMAL) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_REMOTE_ALERTING, CALLSTATE_REMOTE_ALERTING_NORMAL) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START) ;        g_recorder.addCompareMsgString(hLine, "Codec IPCMWB");        g_recorder.addCompareEvent(hLine, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE_HELD) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL) ;        g_recorder.addCompareEvent(hLine, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL) ;            CPPUNIT_ASSERT(g_recorder.compare()) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_NEWCALL, CALLSTATE_NEW_CALL_NORMAL) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_OFFERING, CALLSTATE_OFFERING_ACTIVE) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START) ;        g_recorder2.addCompareMsgString(hReceivingLine, "Codec IPCMWB");        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_STOP) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL) ;        g_recorder2.addCompareEvent(hReceivingLine, CALLSTATE_DESTROYED, CALLSTATE_DESTROYED_NORMAL) ;        CPPUNIT_ASSERT(g_recorder2.compare()) ;            CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS);        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hReceivingLine), SIPX_RESULT_SUCCESS);    }    OsTask::delay(TEST_DELAY) ;} void sipXtapiTestSuite::testConfigEnableStunSuccess() {    SIPX_INST hInst = NULL ;    SIPX_RESULT rc ;    bool bRC ;    EventValidator validator("validator") ;    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)    {        printf("\ntestConfigEnableStunSuccess (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);                rc = sipxInitialize(&hInst, 0, 0, 8031, 8050) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        rc = sipxEventListenerAdd(hInst, UniversalEventValidatorCallback, &validator) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        validator.addMarker("Waiting for STUN success") ;        rc = sipxConfigEnableStun(hInst, "stun.fwdnet.net", 28) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        bRC = validator.waitForConfigEvent(CONFIG_STUN_SUCCESS) ;        CPPUNIT_ASSERT(bRC) ;        rc = sipxEventListenerRemove(hInst, UniversalEventValidatorCallback, &validator) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        rc = sipxUnInitialize(hInst);        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);    }    // Does not create a call -- no need to pause    // OsTask::delay(TEST_DELAY) ;        checkForLeaks() ;}void sipXtapiTestSuite::testConfigEnableStunFailure() {    SIPX_INST hInst = NULL ;    SIPX_RESULT rc ;    bool bRC ;    EventValidator validator("validator") ;    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)    {        printf("\ntestConfigEnableStunFailure (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);                validator.reset() ;        rc = sipxInitialize(&hInst, 0, 0, 8031, 8050) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        rc = sipxEventListenerAdd(hInst, UniversalEventValidatorCallback, &validator) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        validator.addMarker("Waiting for STUN failure") ;        rc = sipxConfigEnableStun(hInst, "www.pingtel.com", 28) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        bRC = validator.waitForConfigEvent(CONFIG_STUN_FAILURE) ;        CPPUNIT_ASSERT(bRC) ;        rc = sipxEventListenerRemove(hInst, UniversalEventValidatorCallback, &validator) ;        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);        rc = sipxUnInitialize(hInst);        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS);    }    // Does not create a call -- no need to pause    OsTask::delay(TEST_DELAY) ;        checkForLeaks() ;   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -