Skip to content
Snippets Groups Projects
Commit ac4a8a89 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#4123] Move thread init from Unit test setUp to test method itself

parent f4ba5dac
No related branches found
No related tags found
No related merge requests found
...@@ -42,12 +42,6 @@ ...@@ -42,12 +42,6 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
pthread_t thethread;
void *sippThread(void *str) void *sippThread(void *str)
{ {
...@@ -66,8 +60,6 @@ void *sippThread(void *str) ...@@ -66,8 +60,6 @@ void *sippThread(void *str)
CPPUNIT_ASSERT(i==0); CPPUNIT_ASSERT(i==0);
delete command;
pthread_exit(NULL); pthread_exit(NULL);
} }
...@@ -76,36 +68,29 @@ void *sippThread(void *str) ...@@ -76,36 +68,29 @@ void *sippThread(void *str)
void SIPTest::setUp() 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 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"); 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 testaccount("IP2IP");
std::string testcallid("callid1234"); std::string testcallid("callid1234");
...@@ -119,11 +104,10 @@ void SIPTest::testSimpleIpCall () ...@@ -119,11 +104,10 @@ void SIPTest::testSimpleIpCall ()
// must sleep here until receiving 180 and 200 message from peer // must sleep here until receiving 180 and 200 message from peer
sleep(2); sleep(2);
// call list should be empty for outgoing calls, only used for incoming calls
CPPUNIT_ASSERT(Manager::instance().getCallList().size() == 1); CPPUNIT_ASSERT(Manager::instance().getCallList().size() == 0);
CPPUNIT_ASSERT(Manager::instance().hasCurrentCall()); CPPUNIT_ASSERT(Manager::instance().hasCurrentCall());
CPPUNIT_ASSERT(Manager::instance().getCurrentCallId() == testcallid); CPPUNIT_ASSERT(Manager::instance().getCurrentCallId() == testcallid);
std::map<std::string, std::string>::iterator iterCallDetails; std::map<std::string, std::string>::iterator iterCallDetails;
...@@ -144,8 +128,12 @@ void SIPTest::testSimpleIpCall () ...@@ -144,8 +128,12 @@ void SIPTest::testSimpleIpCall ()
Manager::instance().hangupCall(testcallid); 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;
}
...@@ -53,7 +53,7 @@ class SIPTest : public CppUnit::TestCase { ...@@ -53,7 +53,7 @@ class SIPTest : public CppUnit::TestCase {
* Use cppunit library macros to add unit test the factory * Use cppunit library macros to add unit test the factory
*/ */
CPPUNIT_TEST_SUITE( SIPTest ); CPPUNIT_TEST_SUITE( SIPTest );
CPPUNIT_TEST ( testSimpleIpCall ); CPPUNIT_TEST ( testSimpleOutgoingIpCall );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
...@@ -72,7 +72,7 @@ class SIPTest : public CppUnit::TestCase { ...@@ -72,7 +72,7 @@ class SIPTest : public CppUnit::TestCase {
inline void tearDown (); inline void tearDown ();
void testSimpleIpCall(void); void testSimpleOutgoingIpCall(void);
private: private:
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment