From bbedf7a3edcde88fbe44bd64366ca8f2c0e263c7 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Wed, 29 Feb 2012 15:37:37 -0500 Subject: [PATCH] * #9026: sfl::InstantMessaging is now a namespace --- daemon/src/iax/iaxvoiplink.cpp | 7 +-- daemon/src/iax/iaxvoiplink.h | 6 +-- daemon/src/im/instant_messaging.cpp | 80 +++++++++++++--------------- daemon/src/im/instant_messaging.h | 28 ++++------ daemon/src/managerimpl.cpp | 11 ++-- daemon/src/managerimpl.h | 22 +------- daemon/src/sip/sipvoiplink.cpp | 18 +++---- daemon/src/sip/sipvoiplink.h | 8 +-- daemon/src/voiplink.h | 8 +-- daemon/test/instantmessagingtest.cpp | 52 ++++++------------ daemon/test/instantmessagingtest.h | 40 ++------------ daemon/test/siptest.h | 2 - 12 files changed, 87 insertions(+), 195 deletions(-) diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 610984b0c2..1b4cf25c76 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -396,8 +396,7 @@ IAXVoIPLink::carryingDTMFdigits(const std::string& id, char code) } void -IAXVoIPLink::sendTextMessage(sfl::InstantMessaging &module, - const std::string& callID, +IAXVoIPLink::sendTextMessage(const std::string& callID, const std::string& message, const std::string& /*from*/) { @@ -405,11 +404,10 @@ IAXVoIPLink::sendTextMessage(sfl::InstantMessaging &module, if (call) { ost::MutexLock lock(mutexIAX_); - module.send_iax_message(call->session, callID, message.c_str()); + sfl::InstantMessaging::send_iax_message(call->session, callID, message.c_str()); } } - std::string IAXVoIPLink::getCurrentCodecName(Call *c) const { @@ -418,7 +416,6 @@ IAXVoIPLink::getCurrentCodecName(Call *c) const return audioCodec ? audioCodec->getMimeSubtype() : ""; } - void IAXVoIPLink::iaxOutgoingInvite(IAXCall* call) { diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index d633dbb379..cd8c6efca5 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -39,10 +39,6 @@ #include "noncopyable.h" #include "audio/samplerateconverter.h" -namespace sfl { -class InstantMessaging; -} - class EventThread; class IAXCall; @@ -167,7 +163,7 @@ class IAXVoIPLink : public VoIPLink { virtual void carryingDTMFdigits(const std::string& id, char code); - virtual void sendTextMessage(sfl::InstantMessaging &module, const std::string& callID, const std::string& message, const std::string& from); + virtual void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from); /** * Return the codec protocol used for this call diff --git a/daemon/src/im/instant_messaging.cpp b/daemon/src/im/instant_messaging.cpp index 8c4de04741..9b86d99653 100644 --- a/daemon/src/im/instant_messaging.cpp +++ b/daemon/src/im/instant_messaging.cpp @@ -33,9 +33,9 @@ #include "logger.h" #include "expat.h" -namespace sfl { - -static void XMLCALL startElementCallback(void *userData, const char *name, const char **atts) +namespace { +void XMLCALL +startElementCallback(void *userData, const char *name, const char **atts) { if (strcmp(name, "entry")) return; @@ -45,13 +45,15 @@ static void XMLCALL startElementCallback(void *userData, const char *name, const for (const char **att = atts; *att; att += 2) entry.insert(std::pair<std::string, std::string> (*att, *(att+1))); - (static_cast<sfl::InstantMessaging::UriList *>(userData))->push_back(entry); + static_cast<sfl::InstantMessaging::UriList *>(userData)->push_back(entry); } -static void XMLCALL endElementCallback(void * /*userData*/, const char * /*name*/) +void XMLCALL endElementCallback(void * /*userData*/, const char * /*name*/) {} +} // end anonymous namespace -bool InstantMessaging::saveMessage(const std::string& message, const std::string& author, const std::string& id, int mode) +namespace sfl { +bool InstantMessaging::saveMessage(const std::string &message, const std::string &author, const std::string &id, int mode) { std::ofstream File; std::string filename = "im:" + id; @@ -81,24 +83,22 @@ void InstantMessaging::sip_send(pjsip_inv_session *session, const std::string& i return; } - const pj_str_t type = pj_str((char*)"text"); - - const pj_str_t subtype = pj_str((char*)"plain"); + const pj_str_t type = pj_str((char*) "text"); + const pj_str_t subtype = pj_str((char*) "plain"); pj_str_t message = pj_str((char*) text.c_str()); tdata->msg->body = pjsip_msg_body_create(tdata->pool, &type, &subtype, &message); pjsip_dlg_send_request(dialog, tdata, -1, NULL); - pjsip_dlg_dec_lock(dialog); saveMessage(text, "Me", id); } -void InstantMessaging::send_sip_message(pjsip_inv_session *session, const std::string& id, const std::string& message) +void InstantMessaging::send_sip_message(pjsip_inv_session *session, const std::string &id, const std::string &message) { - std::vector<std::string> msgs = split_message(message); + std::vector<std::string> msgs(split_message(message)); std::vector<std::string>::const_iterator iter; for (iter = msgs.begin(); iter != msgs.end(); ++iter) @@ -106,9 +106,9 @@ void InstantMessaging::send_sip_message(pjsip_inv_session *session, const std::s } -void InstantMessaging::send_iax_message(iax_session* session, const std::string& /* id */, const std::string& message) +void InstantMessaging::send_iax_message(iax_session *session, const std::string &/* id */, const std::string &message) { - std::vector<std::string> msgs = split_message(message); + std::vector<std::string> msgs(split_message(message)); std::vector<std::string>::const_iterator iter; for (iter = msgs.begin(); iter != msgs.end(); ++iter) @@ -119,7 +119,7 @@ void InstantMessaging::send_iax_message(iax_session* session, const std::string& std::vector<std::string> InstantMessaging::split_message(std::string text) { std::vector<std::string> messages; - size_t len = getMessageMaximumSize(); + size_t len = MAXIMUM_MESSAGE_LENGTH; while (text.length() > len - 2) { messages.push_back(text.substr(len - 2) + "\n\n"); @@ -131,11 +131,11 @@ std::vector<std::string> InstantMessaging::split_message(std::string text) return messages; } -std::string InstantMessaging::generateXmlUriList(UriList& list) +std::string InstantMessaging::generateXmlUriList(UriList &list) { std::string xmlbuffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\">" - "<list>"; + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\">" + "<list>"; for (UriList::iterator iter = list.begin(); iter != list.end(); ++iter) xmlbuffer += "<entry uri=" + (*iter)[sfl::IM_XML_URI] + " cp:copyControl=\"to\" />"; @@ -144,7 +144,8 @@ std::string InstantMessaging::generateXmlUriList(UriList& list) } -InstantMessaging::UriList InstantMessaging::parseXmlUriList(std::string& urilist) +InstantMessaging::UriList +InstantMessaging::parseXmlUriList(const std::string &urilist) { InstantMessaging::UriList list; @@ -161,27 +162,22 @@ InstantMessaging::UriList InstantMessaging::parseXmlUriList(std::string& urilist return list; } -std::string InstantMessaging::appendUriList(std::string text, UriList& list) +std::string InstantMessaging::appendUriList(const std::string &text, UriList& list) { - return - "--boundary Content-Type: text/plain" + - text + - "--boundary Content-Type: application/resource-lists+xml" + - "Content-Disposition: recipient-list" + - generateXmlUriList(list) + - "--boundary--"; + return "--boundary Content-Type: text/plain" + text + + "--boundary Content-Type: application/resource-lists+xml" + + "Content-Disposition: recipient-list" + generateXmlUriList(list) + + "--boundary--"; } -std::string InstantMessaging::findTextUriList(std::string& text) +std::string InstantMessaging::findTextUriList(const std::string &text) { - std::string ctype = "Content-Type: application/resource-lists+xml"; - std::string cdispo = "Content-Disposition: recipient-list"; - std::string boundary = ("--boundary--"); + const std::string ctype("Content-Type: application/resource-lists+xml"); + const std::string cdispo("Content-Disposition: recipient-list"); + const std::string boundary("--boundary--"); // init position pointer size_t pos = 0; - size_t begin = 0; - size_t end = 0; // find the content type if ((pos = text.find(ctype)) == std::string::npos) @@ -192,32 +188,30 @@ std::string InstantMessaging::findTextUriList(std::string& text) throw InstantMessageException("Could not find Content-Disposition tag while parsing sip message for recipient-list"); // xml content start after content disposition tag (plus \n\n) - begin = pos+cdispo.size(); + const size_t begin = pos + cdispo.size(); // find final boundary + size_t end; if ((end = text.find(boundary, begin)) == std::string::npos) throw InstantMessageException("Could not find final \"boundary\" while parsing sip message for recipient-list"); - return text.substr(begin, end-begin); + return text.substr(begin, end - begin); } -std::string InstantMessaging::findTextMessage(std::string& text) +std::string InstantMessaging::findTextMessage(const std::string &text) { std::string ctype = "Content-Type: text/plain"; - - size_t pos = text.find(ctype); - + const size_t pos = text.find(ctype); if (pos == std::string::npos) throw InstantMessageException("Could not find Content-Type tag while parsing sip message for text"); - size_t begin = pos+ctype.size(); - - size_t end = text.find("--boundary", begin); + const size_t begin = pos + ctype.size(); + const size_t end = text.find("--boundary", begin); if (end == std::string::npos) throw InstantMessageException("Could not find end of text \"boundary\" while parsing sip message for text"); - return text.substr(begin, end-begin); + return text.substr(begin, end - begin); } diff --git a/daemon/src/im/instant_messaging.h b/daemon/src/im/instant_messaging.h index 17018b56ca..be0a71ce35 100644 --- a/daemon/src/im/instant_messaging.h +++ b/daemon/src/im/instant_messaging.h @@ -66,18 +66,9 @@ class InstantMessageException : public std::runtime_error { std::runtime_error("InstantMessageException occured: " + str) {} }; -class InstantMessaging { - public: - typedef std::map <std::string, std::string> UriEntry; - typedef std::list <UriEntry> UriList; - - /** - * Return the maximum number if character for a single SIP MESSAGE. - * Longer messages should be splitted in several smaller messages using split_message - */ - static size_t getMessageMaximumSize() { - return MAXIMUM_MESSAGE_LENGTH; - } +namespace InstantMessaging { + typedef std::map<std::string, std::string> UriEntry; + typedef std::list<UriEntry> UriList; /* * Write the text message to the right file @@ -102,7 +93,6 @@ class InstantMessaging { std::vector<std::string> split_message(std::string); - /** * Generate Xml participant list for multi recipient based on RFC Draft 5365 * @@ -111,7 +101,7 @@ class InstantMessaging { * @return A string containing the full XML formated information to be included in the * sip instant message. */ - std::string generateXmlUriList(UriList& list); + std::string generateXmlUriList(UriList &list); /** * Parse the Urilist from a SIP Instant Message provided by a UriList service. @@ -120,7 +110,7 @@ class InstantMessaging { * * @return An UriList of UriEntry containing parsed XML information as a map. */ - UriList parseXmlUriList(std::string& urilist); + UriList parseXmlUriList(const std::string &urilist); /** * Format text message according to RFC 5365, append recipient-list to the message @@ -130,7 +120,7 @@ class InstantMessaging { * * @return formated text stored into a string to be included in sip MESSAGE */ - std::string appendUriList(std::string text, UriList& list); + std::string appendUriList(const std::string &text, UriList &list); /** * Retreive the xml formated uri list in formated text data according to RFC 5365 @@ -139,7 +129,7 @@ class InstantMessaging { * * @return A string containing the XML content */ - std::string findTextUriList(std::string& text); + std::string findTextUriList(const std::string &text); /** * Retrive the plain text message in formated text data according to RFC 5365 @@ -148,7 +138,7 @@ class InstantMessaging { * * @return A string containing the actual message */ - std::string findTextMessage(std::string& text); -}; + std::string findTextMessage(const std::string &text); +} // end namespace InstantMessaging } #endif // __INSTANT_MESSAGING_H_ diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index db774583f7..29479d0eac 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -81,8 +81,7 @@ ManagerImpl::ManagerImpl() : toneMutex_(), telephoneTone_(0), audiofile_(0), audioLayerMutex_(), waitingCall_(), waitingCallMutex_(), nbIncomingWaitingCall_(0), path_(), callAccountMap_(), callAccountMapMutex_(), IPToIPMap_(), accountMap_(), - mainBuffer_(), conferenceMap_(), history_(new History), - imModule_(new sfl::InstantMessaging) + mainBuffer_(), conferenceMap_(), history_(new History) { // initialize random generator for call id srand(time(NULL)); @@ -1419,7 +1418,7 @@ void ManagerImpl::incomingMessage(const std::string& callID, return; } - account->getVoIPLink()->sendTextMessage(*imModule_, callID, message, from); + account->getVoIPLink()->sendTextMessage(callID, message, from); } // in case of a conference we must notify client using conference id @@ -1459,7 +1458,7 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string& return false; } - account->getVoIPLink()->sendTextMessage(*imModule_, *iter_p, message, from); + account->getVoIPLink()->sendTextMessage(*iter_p, message, from); } return true; @@ -1486,7 +1485,7 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string& return false; } - account->getVoIPLink()->sendTextMessage(*imModule_, *iter_p, message, from); + account->getVoIPLink()->sendTextMessage(*iter_p, message, from); } } else { Account *account = getAccount(getAccountFromCall(callID)); @@ -1496,7 +1495,7 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string& return false; } - account->getVoIPLink()->sendTextMessage(*imModule_, callID, message, from); + account->getVoIPLink()->sendTextMessage(callID, message, from); } return true; diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index ac0f30321e..af86e0bd03 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -55,13 +55,9 @@ #include "preferences.h" #include "noncopyable.h" -namespace sfl { -class InstantMessaging; -} - namespace Conf { -class YamlParser; -class YamlEmitter; + class YamlParser; + class YamlEmitter; } class DTMF; @@ -1036,13 +1032,6 @@ class ManagerImpl { return &mainBuffer_; } - /** - * Return a pointer to the instance of InstantMessaging - */ - sfl::InstantMessaging &getInstantMessageModule() { - return *imModule_; - } - /** * Tell if there is a current call processed * @return bool True if there is a current call @@ -1114,12 +1103,5 @@ class ManagerImpl { * TODO: move this to ConfigurationManager */ std::auto_ptr<History> history_; - - /** - * Instant messaging module, resposible to initiate, format, parse, - * send, and receive instant messages. - */ - std::auto_ptr<sfl::InstantMessaging> imModule_; }; - #endif // __MANAGER_H__ diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 16dc0bf124..7f9c9f93cc 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -874,11 +874,11 @@ SIPVoIPLink::offhold(const std::string& id) call->setState(Call::ACTIVE); } -void SIPVoIPLink::sendTextMessage(sfl::InstantMessaging &module, - const std::string &callID, +void SIPVoIPLink::sendTextMessage(const std::string &callID, const std::string &message, const std::string &from) { + using namespace sfl::InstantMessaging; SIPCall *call; try { @@ -888,11 +888,11 @@ void SIPVoIPLink::sendTextMessage(sfl::InstantMessaging &module, } /* Send IM message */ - sfl::InstantMessaging::UriList list; - sfl::InstantMessaging::UriEntry entry; + UriList list; + UriEntry entry; entry[sfl::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating list.push_front(entry); - module.send_sip_message(call->inv, callID, module.appendUriList(message, list)); + send_sip_message(call->inv, callID, appendUriList(message, list)); } bool @@ -1844,12 +1844,12 @@ void transaction_state_changed_cb(pjsip_inv_session *inv UNUSED, pjsip_transacti pjsip_dlg_create_response(inv->dlg, r_data, PJSIP_SC_OK, NULL, &t_data); pjsip_dlg_send_response(inv->dlg, tsx, t_data); - sfl::InstantMessaging &module = Manager::instance().getInstantMessageModule(); + using namespace sfl::InstantMessaging; try { // retreive the recipient-list of this message - std::string urilist = module.findTextUriList(formattedMessage); - sfl::InstantMessaging::UriList list = module.parseXmlUriList(urilist); + std::string urilist = findTextUriList(formattedMessage); + UriList list = parseXmlUriList(urilist); // If no item present in the list, peer is considered as the sender std::string from; @@ -1867,7 +1867,7 @@ void transaction_state_changed_cb(pjsip_inv_session *inv UNUSED, pjsip_transacti if (from[0] == '<' && from[from.size()-1] == '>') from = from.substr(1, from.size()-2); - Manager::instance().incomingMessage(call->getCallId(), from, module.findTextMessage(formattedMessage)); + Manager::instance().incomingMessage(call->getCallId(), from, findTextMessage(formattedMessage)); } catch (const sfl::InstantMessageException &except) { ERROR("SipVoipLink: %s", except.what()); diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index c40e8eb3be..e5869b674a 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -49,10 +49,6 @@ #include "sipaccount.h" #include "voiplink.h" -namespace sfl { -class InstantMessaging; -} - class EventThread; class SIPCall; class SIPAccount; @@ -270,13 +266,11 @@ class SIPVoIPLink : public VoIPLink { /** * Send a SIP message to a call identified by its callid * - * @param The InstantMessaging module which contains formating, parsing and sending method * @param The Id of the call to send the message to * @param The actual message to be transmitted * @param The sender of this message (could be another participant of a conference) */ - void sendTextMessage(sfl::InstantMessaging &module, - const std::string& callID, + void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from); diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index 2df49ba924..957de09c12 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -41,10 +41,6 @@ class Call; class Account; -namespace sfl { -class InstantMessaging; -}; - /** Define a map that associate a Call object to a call identifier */ typedef std::map<std::string, Call*> CallMap; @@ -165,13 +161,11 @@ class VoIPLink { /** * Send a message to a call identified by its callid * - * @param The InstantMessaging module which contains formating, parsing and sending method * @param The Id of the call to send the message to * @param The actual message to be transmitted * @param The sender of this message (could be another participant of a conference) */ - virtual void sendTextMessage(sfl::InstantMessaging &module, - const std::string &callID, + virtual void sendTextMessage(const std::string &callID, const std::string &message, const std::string &from) = 0; diff --git a/daemon/test/instantmessagingtest.cpp b/daemon/test/instantmessagingtest.cpp index 89f0041a3f..d88185d01e 100644 --- a/daemon/test/instantmessagingtest.cpp +++ b/daemon/test/instantmessagingtest.cpp @@ -28,26 +28,21 @@ * as that of the covered work. */ -#include <stdio.h> #include <iostream> #include <fstream> #include "instantmessagingtest.h" +#include "im/instant_messaging.h" #include "expat.h" -#include <stdio.h> +#include <cstdio> #define MAXIMUM_SIZE 10 #define DELIMITER_CHAR "\n\n" using std::cout; using std::endl; - - -void InstantMessagingTest::setUp() -{ - im_ = new sfl::InstantMessaging(); -} +using namespace sfl::InstantMessaging; void InstantMessagingTest::testSaveSingleMessage() { @@ -58,7 +53,7 @@ void InstantMessagingTest::testSaveSingleMessage() std::string filename = "im:"; // Open a file stream and try to write in it - CPPUNIT_ASSERT(im_->saveMessage("Bonjour, c'est un test d'archivage de message", "Manu", callID, std::ios::out) == true); + CPPUNIT_ASSERT(saveMessage("Bonjour, c'est un test d'archivage de message", "Manu", callID, std::ios::out) == true); filename.append(callID); // Read it to check it has been successfully written @@ -83,8 +78,8 @@ void InstantMessagingTest::testSaveMultipleMessage() std::string filename = "im:"; // Open a file stream and try to write in it - CPPUNIT_ASSERT(im_->saveMessage("Bonjour, c'est un test d'archivage de message", "Manu", callID, std::ios::out) == true); - CPPUNIT_ASSERT(im_->saveMessage("Cool", "Alex", callID, std::ios::out || std::ios::app) == true); + CPPUNIT_ASSERT(saveMessage("Bonjour, c'est un test d'archivage de message", "Manu", callID, std::ios::out) == true); + CPPUNIT_ASSERT(saveMessage("Cool", "Alex", callID, std::ios::out || std::ios::app) == true); filename.append(callID); // Read it to check it has been successfully written @@ -140,17 +135,14 @@ static void XMLCALL startElementCallback(void *userData, const char *name, const } *nbEntry += 1; - } -static void XMLCALL endElementCallback(void * /*userData*/, const char * /*name*/) -{ - // std::cout << "endElement " << name << std::endl; -} +static void XMLCALL +endElementCallback(void * /*userData*/, const char * /*name*/) +{} void InstantMessagingTest::testGenerateXmlUriList() { - std::cout << std::endl; // Create a test list with two entries @@ -165,7 +157,7 @@ void InstantMessagingTest::testGenerateXmlUriList() list.push_front(entry1); list.push_front(entry2); - std::string buffer = im_->generateXmlUriList(list); + std::string buffer = generateXmlUriList(list); CPPUNIT_ASSERT(buffer.size() != 0); std::cout << buffer << std::endl; @@ -185,8 +177,6 @@ void InstantMessagingTest::testGenerateXmlUriList() XML_ParserFree(parser); CPPUNIT_ASSERT(nbEntry == 4); - - CPPUNIT_ASSERT(true); } void InstantMessagingTest::testXmlUriListParsing() @@ -200,7 +190,7 @@ void InstantMessagingTest::testXmlUriListParsing() xmlbuffer.append("</resource-lists>"); - sfl::InstantMessaging::UriList list = im_->parseXmlUriList(xmlbuffer); + sfl::InstantMessaging::UriList list = parseXmlUriList(xmlbuffer); CPPUNIT_ASSERT(list.size() == 2); // An iterator over xml attribute @@ -241,14 +231,13 @@ void InstantMessagingTest::testGetTextArea() formatedText.append("</resource-lists>"); formatedText.append("--boundary--"); - std::string message = im_->findTextMessage(formatedText); + std::string message = findTextMessage(formatedText); std::cout << "message " << message << std::endl; CPPUNIT_ASSERT(message == "Here is the text area"); } - void InstantMessagingTest::testGetUriListArea() { std::string formatedText = "--boundary Content-Type: text/plain"; @@ -265,13 +254,13 @@ void InstantMessagingTest::testGetUriListArea() formatedText.append("</resource-lists>"); formatedText.append("--boundary--"); - std::string urilist = im_->findTextUriList(formatedText); + std::string urilist = findTextUriList(formatedText); CPPUNIT_ASSERT(urilist.compare("<?xml version=\"1.0\" encoding=\"UTF-8\"?><resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\"><list><entry uri=\"sip:alex@example.com\" cp:copyControl=\"to\" /><entry uri=\"sip:manu@example.com\" cp:copyControl=\"to\" /></list></resource-lists>") == 0); std::cout << "urilist: " << urilist << std::endl; - sfl::InstantMessaging::UriList list = im_->parseXmlUriList(urilist); + sfl::InstantMessaging::UriList list = parseXmlUriList(urilist); CPPUNIT_ASSERT(list.size() == 2); // order may be important, for example to identify message sender @@ -289,7 +278,6 @@ void InstantMessagingTest::testGetUriListArea() CPPUNIT_ASSERT(from == "sip:alex@example.com"); } - void InstantMessagingTest::testIllFormatedMessage() { bool exceptionCaught = false; @@ -310,8 +298,8 @@ void InstantMessagingTest::testIllFormatedMessage() formatedText.append("--boundary--"); try { - std::string message = im_->findTextMessage(formatedText); - } catch (sfl::InstantMessageException &e) { + std::string message = findTextMessage(formatedText); + } catch (const sfl::InstantMessageException &e) { exceptionCaught = true; } @@ -319,12 +307,4 @@ void InstantMessagingTest::testIllFormatedMessage() CPPUNIT_ASSERT(true); else CPPUNIT_ASSERT(false); - -} - - -void InstantMessagingTest::tearDown() -{ - delete im_; - im_ = 0; } diff --git a/daemon/test/instantmessagingtest.h b/daemon/test/instantmessagingtest.h index 867e19eedf..0977397e6a 100644 --- a/daemon/test/instantmessagingtest.h +++ b/daemon/test/instantmessagingtest.h @@ -34,25 +34,15 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> -#include <cassert> - -// Application import -#include "im/instant_messaging.h" -#include "noncopyable.h" - /* * @file instantmessagingtest.h - * @brief Regroups unitary tests related to the instant messagin module + * @brief Unit tests related to the instant messaging module */ -#ifndef _INSTANTMANAGER_TEST_ -#define _INSTANTMANAGER_TEST_ +#ifndef INSTANTMANAGER_TEST_ +#define INSTANTMANAGER_TEST_ class InstantMessagingTest : public CppUnit::TestCase { - - /** - * Use cppunit library macros to add unit test the factory - */ CPPUNIT_TEST_SUITE(InstantMessagingTest); CPPUNIT_TEST(testSaveSingleMessage); CPPUNIT_TEST(testSaveMultipleMessage); @@ -64,37 +54,15 @@ class InstantMessagingTest : public CppUnit::TestCase { CPPUNIT_TEST_SUITE_END(); public: - InstantMessagingTest() : CppUnit::TestCase("Instant messaging module Tests"), im_(0) {} - - /* - * Code factoring - Common resources can be initialized here. - * This method is called by unitcpp before each test - */ - void setUp(); - - /* - * Code factoring - Common resources can be released here. - * This method is called by unitcpp after each test - */ - void tearDown(); + InstantMessagingTest() : CppUnit::TestCase("Instant messaging module Tests") {} void testSaveSingleMessage(); - void testSaveMultipleMessage(); - void testGenerateXmlUriList(); - void testXmlUriListParsing(); - void testGetTextArea(); - void testGetUriListArea(); - void testIllFormatedMessage(); - - private: - NON_COPYABLE(InstantMessagingTest); - sfl::InstantMessaging *im_; }; /* Register our test module */ diff --git a/daemon/test/siptest.h b/daemon/test/siptest.h index 0e11f44158..3b5152bdfe 100644 --- a/daemon/test/siptest.h +++ b/daemon/test/siptest.h @@ -34,8 +34,6 @@ #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> -#include <assert.h> - // Application import #include "manager.h" -- GitLab