diff --git a/sflphone-common/test/sippxml/test_1.xml b/sflphone-common/test/sippxml/test_1.xml new file mode 100644 index 0000000000000000000000000000000000000000..0bdfd4b2446e77449c5673167f059f037ed884ad --- /dev/null +++ b/sflphone-common/test/sippxml/test_1.xml @@ -0,0 +1,157 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE scenario SYSTEM "sipp.dtd"> + +<!-- This program is free software; you can redistribute it and/or --> +<!-- modify it under the terms of the GNU General Public License as --> +<!-- published by the Free Software Foundation; either version 2 of the --> +<!-- License, or (at your option) any later version. --> +<!-- --> +<!-- This program is distributed in the hope that it will be useful, --> +<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of --> +<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --> +<!-- GNU General Public License for more details. --> +<!-- --> +<!-- You should have received a copy of the GNU General Public License --> +<!-- along with this program; if not, write to the --> +<!-- Free Software Foundation, Inc., --> +<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --> +<!-- --> +<!-- Sipp default 'uas' scenario. --> +<!-- --> + +<scenario name="UAS responder put on hold then hungup"> + + <!-- This scenario implies a second call made by the uac which implies --> + <!-- This call to be put on hold automatically --> + + <recv request="INVITE" crlf="true"> + </recv> + + <send> + <![CDATA[ + + SIP/2.0 180 Ringing + [last_Via:] + [last_From:] + [last_To:];tag=[pid]SIPpTag01[call_number] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Length: 0 + + ]]> + </send> + + <send retrans="500"> + <![CDATA[ + + SIP/2.0 200 OK + [last_Via:] + [last_From:] + [last_To:];tag=[pid]SIPpTag01[call_number] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Type: application/sdp + Content-Length: [len] + + v=0 + o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] + s=- + c=IN IP[media_ip_type] [media_ip] + t=0 0 + m=audio [media_port] RTP/AVP 0 + a=rtpmap:0 PCMU/8000 + + ]]> + </send> + + <recv request="ACK" + optional="true" + rtd="true" + crlf="true"> + </recv> + + + <!-- Here process a second invite with updated sdp, this call is placed on HOLD --> + <!-- TODO: parse in sdp: Media Attribute (a): sendonly --> + <recv request="INVITE" crlf="true"> + </recv> + + <send> + <![CDATA[ + + SIP/2.0 100 Trying + [last_Via:] + [last_From:] + [last_To:];tag=[pid]SIPpTag01[call_number] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Length: 0 + + ]]> + </send> + + <send retrans="500"> + <![CDATA[ + + SIP/2.0 200 OK + [last_Via:] + [last_From:] + [last_To:];tag=[pid]SIPpTag01[call_number] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Type: application/sdp + Content-Length: [len] + + v=0 + o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] + s=- + c=IN IP[media_ip_type] [media_ip] + t=0 0 + m=audio [media_port] RTP/AVP 0 + a=rtpmap:0 PCMU/8000 + + ]]> + </send> + + <recv request="ACK" + optional="true" + rtd="true" + crlf="true"> + </recv> + + <!-- expect to be hung up immediately --> + <recv request="BYE"> + </recv> + + <send> + <![CDATA[ + + SIP/2.0 200 OK + [last_Via:] + [last_From:] + [last_To:] + [last_Call-ID:] + [last_CSeq:] + Contact: <sip:[local_ip]:[local_port];transport=[transport]> + Content-Length: 0 + + ]]> + </send> + + <!-- Keep the call open for a while in case the 200 is lost to be --> + <!-- able to retransmit it if we receive the BYE again. --> + <timewait milliseconds="4000"/> + + + <!-- definition of the response time repartition table (unit is ms) --> + <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/> + + <!-- definition of the call length repartition table (unit is ms) --> + <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/> + +</scenario> + diff --git a/sflphone-common/test/siptest.cpp b/sflphone-common/test/siptest.cpp index be44f269f976fe8a133874fb7b12c9ce6ce702e6..99c390dea0189d20bba7d5276424beb4d2cd7f72 100644 --- a/sflphone-common/test/siptest.cpp +++ b/sflphone-common/test/siptest.cpp @@ -174,32 +174,112 @@ void SIPTest::testSimpleIncomingIpCall () // Answer this call CPPUNIT_ASSERT(Manager::instance().answerCall(testcallid)); - // This is useless since manager is not aware of incoming IP2IP sip calls - /* + sleep(1); - std::map<std::string, std::string>::iterator iterCallDetails; - std::map<std::string, std::string> callDetails = Manager::instance().getCallDetails (testcallid); + rc = pthread_join(thethread, &status); + if (rc) { + std::cout << "SIPTest: ERROR; return code from pthread_join(): " << rc << std::endl; + } + else + std::cout << "SIPTest: completed join with thread" << std::endl; +} - iterCallDetails = callDetails.find("ACCOUNTID"); - std::cout << "---------------------- " << iterCallDetails->second << std::endl; - // CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "")); - iterCallDetails = callDetails.find("PEER_NUMBER"); - std::cout << "--------------------- " << iterCallDetails->second << std::endl; - // CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "<sip:test@127.0.0.1:5062>")); - iterCallDetails = callDetails.find("PEER_NAME"); - std::cout << "--------------------- " << iterCallDetails->second << std::endl; - // CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "")); - iterCallDetails = callDetails.find("DISPLAY_NAME"); - std::cout << "-------------------- " << iterCallDetails->second << std::endl; - // CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "")); - iterCallDetails = callDetails.find("CALL_STATE"); - std::cout << "-------------------- " << iterCallDetails->second << std::endl; - // CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "CURRENT")); - iterCallDetails = callDetails.find("CALL_TYPE"); - std::cout << "-------------------- " << iterCallDetails->second << std::endl; - // CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "1")); - */ + +void SIPTest::testTwoOutgoingIpCall () +{ + pthread_t firstCallThread, secondCallThread; + void *status; + + // This scenario expect to be put on hold before hangup + std::string firstCallCommand("sipp -sf sippxml/test_1.xml -i 127.0.0.1 -p 5062 -m 1"); + + // The second call uses the default user agent scenario + std::string secondCallCommand("sipp -sn uas -i 127.0.0.1 -p 5064 -m 1"); + + int rc = pthread_create(&firstCallThread, NULL, sippThread, (void *)(&firstCallCommand)); + if (rc) { + std::cout << "SIPTest: ERROR; return code from pthread_create()" << std::endl; + } + + rc = pthread_create(&secondCallThread, NULL, sippThread, (void *)(&secondCallCommand)); + if(rc) { + std::cout << "SIPTest: ERROR; return code from pthread_create()" << std::endl; + } + + sleep(1); + + std::string testAccount("IP2IP"); + + std::string firstCallID("callid1234"); + std::string firstCallNumber("sip:test@127.0.0.1:5062"); + + std::string secondCallID("callid2345"); + std::string secondCallNumber("sip:test@127.0.0.1:5064"); + + CPPUNIT_ASSERT(!Manager::instance().hasCurrentCall()); + + // start a new call sending INVITE message to sipp instance + // this call should be put on hold when making the second call + Manager::instance().outgoingCall(testAccount, firstCallID, firstCallNumber); + + // must sleep here until receiving 180 and 200 message from peer + sleep(1); + + Manager::instance().outgoingCall(testAccount, secondCallID, secondCallNumber); + + sleep(1); + + Manager::instance().hangupCall(firstCallID); + + rc = pthread_join(firstCallThread, &status); + if(rc) { + std::cout << "SIPTest: ERROR; return code from pthread_join(): " << rc << std::endl; + } + std::cout << "SIPTest: completed join with thread" << std::endl; + + Manager::instance().hangupCall(secondCallID); + + rc = pthread_join(secondCallThread, &status); + if (rc) { + std::cout << "SIPTest: ERROR; return code from pthread_join(): " << rc << std::endl; + } + else + std::cout << "SIPTest: completed join with thread" << std::endl; +} + +/* +void SIPTest::testTwoIncomingIpCall () +{ + + pthread_t thethread; + void *status; + + // command to be executed by the thread, user agent client which initiate a call and hangup + std::string command("sipp -sn uac 127.0.0.1 -i 127.0.0.1 -p 5062 -m 1"); + + int rc = pthread_create(&thethread, NULL, sippThread, (void *)(&command)); + if (rc) { + std::cout << "SIPTest: ERROR; return code from pthread_create()" << std::endl; + } + + + // sleep a while to make sure that sipp insdtance is initialized and sflphoned received + // the incoming invite. + sleep(2); + + // gtrab call id from sipvoiplink + SIPVoIPLink *siplink = SIPVoIPLink::instance (""); + + CPPUNIT_ASSERT(siplink->_callMap.size() == 1); + CallMap::iterator iterCallId = siplink->_callMap.begin(); + std::string testcallid = iterCallId->first; + + // TODO: hmmm, should IP2IP call be stored in call list.... + CPPUNIT_ASSERT(Manager::instance().getCallList().size() == 0); + + // Answer this call + CPPUNIT_ASSERT(Manager::instance().answerCall(testcallid)); sleep(1); @@ -211,3 +291,4 @@ void SIPTest::testSimpleIncomingIpCall () else std::cout << "SIPTest: completed join with thread" << std::endl; } +*/ diff --git a/sflphone-common/test/siptest.h b/sflphone-common/test/siptest.h index 24478184a97ff0ab65c7b0c743ca132d1666c523..d6b480151488000438138bb1fd65cc270f0ecb02 100644 --- a/sflphone-common/test/siptest.h +++ b/sflphone-common/test/siptest.h @@ -55,6 +55,7 @@ class SIPTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE( SIPTest ); CPPUNIT_TEST ( testSimpleOutgoingIpCall ); CPPUNIT_TEST ( testSimpleIncomingIpCall ); + CPPUNIT_TEST( testTwoOutgoingIpCall ); CPPUNIT_TEST_SUITE_END(); public: @@ -77,6 +78,8 @@ class SIPTest : public CppUnit::TestCase { void testSimpleIncomingIpCall(void); + void testTwoOutgoingIpCall(void); + private: };