From 35360c5b6680a2b80ff031471e98b4a8b165d66f Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Mon, 13 Sep 2010 11:09:22 -0400
Subject: [PATCH] [#4056] Fix unit test for instant message parsing

---
 .../src/sip/im/InstantMessaging.cpp           |  6 ++---
 sflphone-common/src/sip/im/InstantMessaging.h |  2 +-
 sflphone-common/test/instantmessagingtest.cpp | 22 +++++++++----------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/sflphone-common/src/sip/im/InstantMessaging.cpp b/sflphone-common/src/sip/im/InstantMessaging.cpp
index c88c166757..34de71fe5b 100644
--- a/sflphone-common/src/sip/im/InstantMessaging.cpp
+++ b/sflphone-common/src/sip/im/InstantMessaging.cpp
@@ -325,7 +325,7 @@ 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() +2;
+    begin = pos+cdispo.size();
 
     // find final boundary
     if ( (end = text.find (boundary, begin)) == std::string::npos)
@@ -348,13 +348,13 @@ std::string InstantMessaging::findTextMessage (std::string& text)
         throw InstantMessageException ("Could not find Content-Type tag while parsing sip message for text");
 
     // plain text content start after content type tag (plus \n\n)
-    begin = pos+ctype.size() +2;
+    begin = pos+ctype.size();
 
     // retrive end of the text content
     if ( (end = text.find (boundary, begin)) == std::string::npos)
         throw InstantMessageException ("Could not find end of text \"boundary\" while parsing sip message for text");
 
-    return text.substr (begin, end-begin-1);
+    return text.substr (begin, end-begin);
 }
 
 
diff --git a/sflphone-common/src/sip/im/InstantMessaging.h b/sflphone-common/src/sip/im/InstantMessaging.h
index 8924c9d436..576b3d781b 100644
--- a/sflphone-common/src/sip/im/InstantMessaging.h
+++ b/sflphone-common/src/sip/im/InstantMessaging.h
@@ -40,7 +40,7 @@ class InstantMessageException : public std::exception
         virtual ~InstantMessageException() throw() {}
 
         virtual const char *what() const throw() {
-            std::string expt ("YamlParserException occured: ");
+            std::string expt ("InstantMessageException occured: ");
             expt.append (errstr);
 
             return expt.c_str();
diff --git a/sflphone-common/test/instantmessagingtest.cpp b/sflphone-common/test/instantmessagingtest.cpp
index 4909e2eb14..f36a92136e 100644
--- a/sflphone-common/test/instantmessagingtest.cpp
+++ b/sflphone-common/test/instantmessagingtest.cpp
@@ -266,11 +266,11 @@ void InstantMessagingTest::testXmlUriListParsing ()
 void InstantMessagingTest::testGetTextArea ()
 {
 
-    std::string formatedText = "--boundary\n Content-Type: text/plain\n\n";
+    std::string formatedText = "--boundary Content-Type: text/plain";
     formatedText.append ("Here is the text area");
 
-    formatedText.append ("\n--boundary\nContent-Type: application/resource-lists+xml\n");
-    formatedText.append ("Content-Disposition: recipient-list\n\n");
+    formatedText.append ("--boundary Content-Type: application/resource-lists+xml");
+    formatedText.append ("Content-Disposition: recipient-list");
     formatedText.append ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
     formatedText.append ("<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\">");
     formatedText.append ("<list>");
@@ -282,19 +282,19 @@ void InstantMessagingTest::testGetTextArea ()
 
     std::string message = _im->findTextMessage(formatedText);
 
-    CPPUNIT_ASSERT(message == "Here is the text area");
+    std::cout << "message " << message << std::endl;
 
-    std::cout << "message: " << message << std::endl;
+    CPPUNIT_ASSERT(message == "Here is the text area");
 }
 
 
 void InstantMessagingTest::testGetUriListArea ()
 {
-    std::string formatedText = "--boundary\n Content-Type: text/plain\n\n";
+    std::string formatedText = "--boundary Content-Type: text/plain";
     formatedText.append ("Here is the text area");
 
-    formatedText.append ("\n--boundary\nContent-Type: application/resource-lists+xml\n");
-    formatedText.append ("Content-Disposition: recipient-list\n\n");
+    formatedText.append ("--boundary Content-Type: application/resource-lists+xml");
+    formatedText.append ("Content-Disposition: recipient-list");
     formatedText.append ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
     formatedText.append ("<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\">");
     formatedText.append ("<list>");
@@ -334,11 +334,11 @@ void InstantMessagingTest::testIllFormatedMessage ()
     bool exceptionCaught = false;
 
     // SHOULD BE: Content-Type: text/plain
-    std::string formatedText = "--boundary\n Content-Ty\n\n";
+    std::string formatedText = "--boundary Content-Ty";
     formatedText.append ("Here is the text area");
 
-    formatedText.append ("\n--boundary\nContent-Type: application/resource-lists+xml\n");
-    formatedText.append ("Content-Disposition: recipient-list\n\n");
+    formatedText.append ("--boundary Content-Type: application/resource-lists+xml");
+    formatedText.append ("Content-Disposition: recipient-list");
     formatedText.append ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
     formatedText.append ("<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\">");
     formatedText.append ("<list>");
-- 
GitLab