Commit 92f1c04e authored by Alexandre Savard's avatar Alexandre Savard

[#4123] Set up unit tests for calls

parent 7d9f1e41
......@@ -146,7 +146,7 @@ im_window_is_active ()
if (!im_window)
return FALSE;
else
return gtk_window_is_active (im_window);
return gtk_window_is_active (GTK_WINDOW (im_window));
}
gboolean
......
......@@ -39,7 +39,7 @@ Account::Account (const AccountID& accountID, std::string type) :
, _enabled (true)
, _type (type)
, _codecOrder ()
, _codecStr ("")
, _codecStr ("0/")
, _ringtonePath ("/usr/share/sflphone/ringtones/konga.ul")
, _ringtoneEnabled (true)
, _displayName ("")
......@@ -83,11 +83,12 @@ void Account::loadAudioCodecs (void)
// if the user never set the codec list, use the default configuration for this account
if (_codecStr == "") {
_info ("Account: use the default order");
_info ("Account: Use default codec order");
Manager::instance ().getCodecDescriptorMap ().setDefaultOrder();
}
// else retrieve the one set in the user config file
else {
_debug ("Account: Set codec order from configuration file");
std::vector<std::string> active_list = Manager::instance ().retrieveActiveCodecs();
// This property is now set per account basis
// std::string s = Manager::instance ().getConfigString (_accountID, "ActiveCodecs");
......
......@@ -346,9 +346,10 @@ class Account : public Serializable
// assignment operator
Account& operator= (const Account& rh);
protected:
void loadAudioCodecs (void);
protected:
/**
* Account ID are assign in constructor and shall not changed
*/
......
......@@ -2342,7 +2342,6 @@ void ManagerImpl::initConfigFile (bool load_user_value, std::string alternate)
(alternate == "") ? path = _path : path = alternate;
std::cout << path << std::endl;
_exist = _config.populateFromFile (path);
}
_debug ("Manager: configuration file path: %s", path.c_str());
......
......@@ -663,6 +663,9 @@ void Sdp::set_local_media_capabilities (CodecOrder selectedCodecs)
/* We retrieve the codecs selected by the user */
codecs_list = Manager::instance().getCodecDescriptorMap().getCodecsMap();
if (selectedCodecs.size() == 0)
_warn ("SDP: No selected codec while building local SDP offer");
for (i=0; i<selectedCodecs.size(); i++) {
iter=codecs_list.find (selectedCodecs[i]);
......
......@@ -614,6 +614,8 @@ void SIPAccount::unserialize (Conf::MappingNode *map)
val = NULL;
}
Account::loadAudioCodecs();
}
......
......@@ -1535,7 +1535,6 @@ SIPVoIPLink::SIPStartCall (SIPCall* call, const std::string& subject UNUSED)
pjsip_dlg_set_route_set (dialog, route_set);
}
PJ_ASSERT_RETURN (status == PJ_SUCCESS, false);
// Set auth information
......@@ -1733,7 +1732,6 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to)
call->getLocalSDP()->set_ip_address (addrSdp);
call->getLocalSDP()->create_initial_offer (account->getActiveCodecs ());
// Audio Rtp Session must be initialized before creating initial offer in SDP session
// since SDES require crypto attribute.
try {
......@@ -1797,10 +1795,12 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to)
// Create the dialog (UAC)
// (Parameters are "strduped" inside this function)
_debug ("UserAgent: Creating dialog for this call");
status = pjsip_dlg_create_uac (pjsip_ua_instance(), &pjFrom, &pjContact, &pjTo, NULL, &dialog);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, false);
// Create the invite session for this call
_debug ("UserAgent: Creating invite session for this call");
status = pjsip_inv_create_uac (dialog, call->getLocalSDP()->get_local_sdp_session(), 0, &inv);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, false);
......@@ -3208,7 +3208,9 @@ void call_on_state_changed (pjsip_inv_session *inv, pjsip_event *e)
const pj_str_t * description = pjsip_get_status_text (statusCode);
if (statusCode) {
DBusManager::instance().getCallManager()->sipCallStateChanged (call->getCallId(), std::string (description->ptr, description->slen), statusCode);
// test wether or not dbus manager is instantiated, if not no need to notify the client
if (Manager::instance().getDbusManager())
DBusManager::instance().getCallManager()->sipCallStateChanged (call->getCallId(), std::string (description->ptr, description->slen), statusCode);
}
}
......
......@@ -23,6 +23,8 @@ test_SOURCES = \
numbercleanertest.cpp \
pluginmanagertest.h \
pluginmanagertest.cpp \
siptest.h \
siptest.cpp \
rtptest.h \
rtptest.cpp \
sdesnegotiatortest.h \
......
......@@ -28,19 +28,113 @@
* as that of the covered work.
*/
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <pthread.h>
#include <string>
#include "siptest.h"
#include "manager.h"
using std::cout;
using std::endl;
pthread_t thethread;
void *sippThread(void *threadid)
{
std::cout << "SIPTest: Starting sipp" << std::endl;
// Set up the sipp instance in this thread in order to catch return value
// 0: All calls were successful
// 1: At least one call failed
// 97: exit on internal command. Calls may have been processed
// 99: Normal exit without calls processed
// -1: Fatal error
// -2: Fatal error binding a socket
int i = system("sipp -sn uas -i 127.0.0.1 -p 5062 -m 1 -f 0 -trace_msg -trace_stat");
CPPUNIT_ASSERT(i==0);
pthread_exit(NULL);
}
void SIPTest::setUp()
{
/*
int rc = pthread_create(&thethread, NULL, sippThread, NULL);
if (rc) {
std::cout << "SIPTest: ERROR; return code from pthread_create()" << std::endl;
}
*/
}
void SIPTest::tearDown()
{
/*
void *status;
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 ()
{
std::string testaccount("IP2IP");
std::string testcallid("callid1234");
std::string testcallnumber("sip:test@127.0.0.1:5062");
CPPUNIT_ASSERT(!Manager::instance().hasCurrentCall());
// start a new call sending INVITE message to sipp instance
Manager::instance().outgoingCall(testaccount, testcallid, testcallnumber);
// must sleep here until receiving 180 and 200 message from peer
sleep(2);
CPPUNIT_ASSERT(Manager::instance().hasCurrentCall());
CPPUNIT_ASSERT(Manager::instance().getCurrentCallId() == testcallid);
std::map<std::string, std::string>::iterator iterCallDetails;
std::map<std::string, std::string> callDetails = Manager::instance().getCallDetails (testcallid);
iterCallDetails = callDetails.find("ACCOUNTID");
CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == ""));
iterCallDetails = callDetails.find("PEER_NUMBER");
CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "<sip:test@127.0.0.1:5062>"));
iterCallDetails = callDetails.find("PEER_NAME");
CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == ""));
iterCallDetails = callDetails.find("DISPLAY_NAME");
CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == ""));
iterCallDetails = callDetails.find("CALL_STATE");
CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "CURRENT"));
iterCallDetails = callDetails.find("CALL_TYPE");
CPPUNIT_ASSERT((iterCallDetails != callDetails.end()) && (iterCallDetails->second == "1"));
Manager::instance().hangupCall(testcallid);
}
......@@ -52,7 +52,8 @@ class SIPTest : public CppUnit::TestCase {
/**
* Use cppunit library macros to add unit test the factory
*/
CPPUNIT_TEST_SUITE( InstantMessagingTest );
CPPUNIT_TEST_SUITE( SIPTest );
CPPUNIT_TEST ( testSimpleIpCall );
CPPUNIT_TEST_SUITE_END();
public:
......@@ -70,6 +71,9 @@ class SIPTest : public CppUnit::TestCase {
*/
inline void tearDown ();
void testSimpleIpCall(void);
private:
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment