From ac4a8a8968b45fd5ef0ce5a173b31038d56d4079 Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Wed, 22 Sep 2010 15:05:24 -0400 Subject: [PATCH] [#4123] Move thread init from Unit test setUp to test method itself --- sflphone-common/test/siptest.cpp | 52 ++++++++++++-------------------- sflphone-common/test/siptest.h | 4 +-- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/sflphone-common/test/siptest.cpp b/sflphone-common/test/siptest.cpp index 0c2915e563..a61b95721c 100644 --- a/sflphone-common/test/siptest.cpp +++ b/sflphone-common/test/siptest.cpp @@ -42,12 +42,6 @@ using std::cout; using std::endl; -pthread_t thethread; - - - - - void *sippThread(void *str) { @@ -66,8 +60,6 @@ void *sippThread(void *str) CPPUNIT_ASSERT(i==0); - delete command; - pthread_exit(NULL); } @@ -75,38 +67,31 @@ void *sippThread(void *str) void SIPTest::setUp() { - - std::string *command = new std::string("sipp -sn uas -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; - } } void SIPTest::tearDown() { - void *status; - + // in order to stop any currently running threads + std::cout << "SIPTest: Clean all remaining sipp instances" << std::endl; system("killall sipp"); - int 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; - } -void SIPTest::testSimpleIpCall () +void SIPTest::testSimpleOutgoingIpCall () { + pthread_t thethread; + void *status; - + std::string command("sipp -sn uas -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; + } + std::string testaccount("IP2IP"); std::string testcallid("callid1234"); std::string testcallnumber("sip:test@127.0.0.1:5062"); @@ -119,11 +104,10 @@ void SIPTest::testSimpleIpCall () // must sleep here until receiving 180 and 200 message from peer sleep(2); - - CPPUNIT_ASSERT(Manager::instance().getCallList().size() == 1); + // call list should be empty for outgoing calls, only used for incoming calls + CPPUNIT_ASSERT(Manager::instance().getCallList().size() == 0); CPPUNIT_ASSERT(Manager::instance().hasCurrentCall()); - CPPUNIT_ASSERT(Manager::instance().getCurrentCallId() == testcallid); std::map<std::string, std::string>::iterator iterCallDetails; @@ -144,8 +128,12 @@ void SIPTest::testSimpleIpCall () Manager::instance().hangupCall(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; +} diff --git a/sflphone-common/test/siptest.h b/sflphone-common/test/siptest.h index 7f11021049..11b48a44cc 100644 --- a/sflphone-common/test/siptest.h +++ b/sflphone-common/test/siptest.h @@ -53,7 +53,7 @@ class SIPTest : public CppUnit::TestCase { * Use cppunit library macros to add unit test the factory */ CPPUNIT_TEST_SUITE( SIPTest ); - CPPUNIT_TEST ( testSimpleIpCall ); + CPPUNIT_TEST ( testSimpleOutgoingIpCall ); CPPUNIT_TEST_SUITE_END(); public: @@ -72,7 +72,7 @@ class SIPTest : public CppUnit::TestCase { inline void tearDown (); - void testSimpleIpCall(void); + void testSimpleOutgoingIpCall(void); private: }; -- GitLab