diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index de54ca7dfb88d3eb315ccffc0ccfe915f53d8cfb..8eabaedd69e2bd64d95c5d2f78793d1375d18b03 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -3687,6 +3687,8 @@ CallID ManagerImpl::getNewCallID () random_id << (unsigned) rand(); } + _lastCallID = random_id.str(); + return random_id.str(); } diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h index d5529ece7ba4b2e4942da7e37d4e815ef86c92de..d6a122fc8e712cec3f4aaeb1e080592f5b1d1900 100644 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -1426,11 +1426,13 @@ class ManagerImpl Conf::YamlParser *parser; Conf::YamlEmitter *emitter; + std::string _lastCallID; + #ifdef TEST bool testCallAccountMap(); bool testAccountMap(); #endif - friend class SipTest; + friend class SIPTest; friend class ConfigurationTest; friend class HistoryTest; }; diff --git a/sflphone-common/test/siptest.cpp b/sflphone-common/test/siptest.cpp index a61b95721ca4af5852841c025d8f962373bf5459..3293f039462243953fbc6ec96305bbcac428c2a1 100644 --- a/sflphone-common/test/siptest.cpp +++ b/sflphone-common/test/siptest.cpp @@ -85,6 +85,7 @@ void SIPTest::testSimpleOutgoingIpCall () pthread_t thethread; void *status; + // command to be executed by the thread std::string command("sipp -sn uas -i 127.0.0.1 -p 5062 -m 1"); int rc = pthread_create(&thethread, NULL, sippThread, (void *)(&command)); @@ -137,3 +138,45 @@ void SIPTest::testSimpleOutgoingIpCall () } + + +void SIPTest::testSimpleIncomingIpCall () +{ + + pthread_t thethread; + void *status; + + // command to be executed by the thread + 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); + + // CallList should not be used if receiving only one call + CPPUNIT_ASSERT(Manager::instance().getCallList().size() == 0); + // CPPUNIT_ASSERT(Manager::instance()._callAccountMap.size() == 1); + + // TODO: hmmm, need to find a better way to retreive the call id + // std::map<std::string, std::string>::iterator iterCallId = Manager::instance()._callAccountMap.begin(); + // CPPUNIT_ASSERT(iterCallId != Manager::instance()._callAccountMap.end()); + + std::string testcallid = Manager::instance()._lastCallID; + + CPPUNIT_ASSERT(Manager::instance().answerCall(testcallid)); + + sleep(2); + + 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; + +} diff --git a/sflphone-common/test/siptest.h b/sflphone-common/test/siptest.h index 11b48a44cc6d25fa353c4f104cd66787e3690b7c..24478184a97ff0ab65c7b0c743ca132d1666c523 100644 --- a/sflphone-common/test/siptest.h +++ b/sflphone-common/test/siptest.h @@ -54,6 +54,7 @@ class SIPTest : public CppUnit::TestCase { */ CPPUNIT_TEST_SUITE( SIPTest ); CPPUNIT_TEST ( testSimpleOutgoingIpCall ); + CPPUNIT_TEST ( testSimpleIncomingIpCall ); CPPUNIT_TEST_SUITE_END(); public: @@ -74,6 +75,8 @@ class SIPTest : public CppUnit::TestCase { void testSimpleOutgoingIpCall(void); + void testSimpleIncomingIpCall(void); + private: };