From 54e6b0da0d9246e6d50760f149fb06b55405a4eb Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Wed, 22 Sep 2010 16:44:23 -0400 Subject: [PATCH] [#4123] Add single outgoing call unit test --- sflphone-common/src/managerimpl.cpp | 2 ++ sflphone-common/src/managerimpl.h | 4 ++- sflphone-common/test/siptest.cpp | 43 +++++++++++++++++++++++++++++ sflphone-common/test/siptest.h | 3 ++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index de54ca7dfb..8eabaedd69 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 d5529ece7b..d6a122fc8e 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 a61b95721c..3293f03946 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 11b48a44cc..24478184a9 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: }; -- GitLab