Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
ce59602a
Commit
ce59602a
authored
Aug 31, 2010
by
Alexandre Savard
Browse files
[#3619] Fix instant messaging unit tests
parent
d70aab06
Changes
3
Hide whitespace changes
Inline
Side-by-side
sflphone-common/src/sip/im/InstantMessaging.cpp
View file @
ce59602a
...
...
@@ -4,7 +4,8 @@ namespace sfl
{
InstantMessaging
::
InstantMessaging
()
:
imFiles
()
{}
:
imFiles
()
,
messageMaxSize
(
MAXIMUM_MESSAGE_LENGTH
)
{}
InstantMessaging
::~
InstantMessaging
()
{}
...
...
@@ -40,7 +41,7 @@ bool InstantMessaging::saveMessage (const std::string& message, const std::strin
// We will use the Call ID
std
::
ofstream
File
;
std
::
string
filename
=
"
sip
:"
;
std
::
string
filename
=
"
im
:"
;
filename
.
append
(
id
);
File
.
open
(
filename
.
c_str
(),
(
std
::
_Ios_Openmode
)
mode
);
...
...
@@ -127,7 +128,7 @@ pj_status_t InstantMessaging::send_message (pjsip_inv_session *session, CallID&
{
/* Check the length of the message */
if
(
message
.
length
()
<
MAXIMUM_MESSAGE_LENGTH
)
{
if
(
message
.
length
()
<
getMessageMaximumSize
()
)
{
/* No problem here */
send
(
session
,
id
,
message
);
}
...
...
@@ -155,17 +156,17 @@ std::vector<std::string> InstantMessaging::split_message (const std::string& tex
std
::
string
text_to_split
=
text
;
/* Iterate over the message length */
while
(
text_to_split
.
length
()
>
MAXIMUM_MESSAGE_LENGTH
)
{
while
(
text_to_split
.
length
()
>
getMessageMaximumSize
()
)
{
/* The remaining string is still too long */
/* Compute the substring */
std
::
string
split_message
=
text_to_split
.
substr
(
0
,
(
size_t
)
MAXIMUM_MESSAGE_LENGTH
);
std
::
string
split_message
=
text_to_split
.
substr
(
0
,
(
size_t
)
getMessageMaximumSize
()
);
/* Append our split character \n\n */
split_message
.
append
(
DELIMITER_CHAR
);
/* Append in the vector */
messages
.
push_back
(
split_message
);
/* Use the remaining string to not loop forever */
text_to_split
=
text_to_split
.
substr
(
(
size_t
)
MAXIMUM_MESSAGE_LENGTH
);
text_to_split
=
text_to_split
.
substr
(
(
size_t
)
getMessageMaximumSize
()
);
}
/* Push the last message */
...
...
sflphone-common/src/sip/im/InstantMessaging.h
View file @
ce59602a
...
...
@@ -37,6 +37,17 @@ namespace sfl {
*/
~
InstantMessaging
();
/**
* Set maximum size fo this module.
*/
void
setMessageMaximumSize
(
unsigned
int
max
)
{
messageMaxSize
=
max
;
}
/**
* Return the maximum number if character for a single SIP MESSAGE.
* Longer messages should be splitted in several smaller messages using split_message
*/
unsigned
int
getMessageMaximumSize
(
void
)
{
return
messageMaxSize
;
}
/*
* Register and initialize instant messaging support
*/
...
...
@@ -126,6 +137,11 @@ namespace sfl {
InstantMessaging
(
const
InstantMessaging
&
);
//No Copy Constructor
InstantMessaging
&
operator
=
(
const
InstantMessaging
&
);
//No Assignment Operator
/**
* Store the maximum number of character for a SIP MESSAGE
*/
unsigned
int
messageMaxSize
;
};
}
#endif // _INSTANT_MESSAGING_H
sflphone-common/test/instantmessagingtest.cpp
View file @
ce59602a
...
...
@@ -52,12 +52,14 @@ void InstantMessagingTest::testSaveSingleMessage ()
std
::
string
input
,
tmp
;
std
::
string
callID
=
"testfile1.txt"
;
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
);
filename
.
append
(
callID
);
// Read it to check it has been successfully written
std
::
ifstream
testfile
(
callID
.
c_str
(),
std
::
ios
::
in
);
std
::
ifstream
testfile
(
filename
.
c_str
(),
std
::
ios
::
in
);
CPPUNIT_ASSERT
(
testfile
.
is_open
()
==
true
);
while
(
!
testfile
.
eof
())
{
...
...
@@ -75,13 +77,15 @@ void InstantMessagingTest::testSaveMultipleMessage ()
std
::
string
input
,
tmp
;
std
::
string
callID
=
"testfile2.txt"
;
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
);
filename
.
append
(
callID
);
// Read it to check it has been successfully written
std
::
ifstream
testfile
(
callID
.
c_str
(),
std
::
ios
::
in
);
std
::
ifstream
testfile
(
filename
.
c_str
(),
std
::
ios
::
in
);
CPPUNIT_ASSERT
(
testfile
.
is_open
()
==
true
);
while
(
!
testfile
.
eof
())
{
...
...
@@ -97,10 +101,13 @@ void InstantMessagingTest::testSaveMultipleMessage ()
void
InstantMessagingTest
::
testSplitMessage
()
{
_im
->
setMessageMaximumSize
(
10
);
unsigned
int
maxSize
=
_im
->
getMessageMaximumSize
();
/* A message that does not need to be split */
std
::
string
short_message
=
"Salut"
;
std
::
vector
<
std
::
string
>
messages
=
_im
->
split_message
(
short_message
);
CPPUNIT_ASSERT
(
messages
.
size
()
==
short_message
.
length
()
/
MAXIMUM_SIZE
+
1
);
CPPUNIT_ASSERT
(
messages
.
size
()
==
short_message
.
length
()
/
maxSize
+
1
);
CPPUNIT_ASSERT
(
messages
[
0
]
==
short_message
);
/* A message that needs to be split into two messages */
...
...
@@ -108,15 +115,15 @@ void InstantMessagingTest::testSplitMessage ()
messages
=
_im
->
split_message
(
long_message
);
int
size
=
messages
.
size
();
int
i
=
0
;
CPPUNIT_ASSERT
(
size
==
(
int
)
long_message
.
length
()
/
MAXIMUM_SIZE
+
1
);
CPPUNIT_ASSERT
(
size
==
(
int
)
(
long_message
.
length
()
/
maxSize
+
1
)
)
;
/* If only one element, do not enter the loop */
for
(
i
=
0
;
i
<
size
-
1
;
i
++
)
{
CPPUNIT_ASSERT
(
messages
[
i
]
==
long_message
.
substr
(
(
MAXIMUM_SIZE
*
i
),
MAXIMUM_SIZE
)
+
DELIMITER_CHAR
);
}
CPPUNIT_ASSERT
(
messages
[
i
]
==
long_message
.
substr
(
(
maxSize
*
i
),
maxSize
)
+
DELIMITER_CHAR
);
}
/* Works for the last element, or for the only element */
CPPUNIT_ASSERT
(
messages
[
size
-
1
]
==
long_message
.
substr
(
MAXIMUM_SIZE
*
(
size
-
1
)));
CPPUNIT_ASSERT
(
messages
[
size
-
1
]
==
long_message
.
substr
(
maxSize
*
(
size
-
1
)));
/* A message that needs to be split into four messages */
std
::
string
very_long_message
=
"A message that needs to be split into many messages"
;
...
...
@@ -125,11 +132,11 @@ void InstantMessagingTest::testSplitMessage ()
/* If only one element, do not enter the loop */
for
(
i
=
0
;
i
<
size
-
1
;
i
++
)
{
CPPUNIT_ASSERT
(
messages
[
i
]
==
very_long_message
.
substr
(
(
MAXIMUM_SIZE
*
i
),
MAXIMUM_SIZE
)
+
DELIMITER_CHAR
);
CPPUNIT_ASSERT
(
messages
[
i
]
==
very_long_message
.
substr
(
(
maxSize
*
i
),
maxSize
)
+
DELIMITER_CHAR
);
}
/* Works for the last element, or for the only element */
CPPUNIT_ASSERT
(
messages
[
size
-
1
]
==
very_long_message
.
substr
(
MAXIMUM_SIZE
*
(
size
-
1
)));
CPPUNIT_ASSERT
(
messages
[
size
-
1
]
==
very_long_message
.
substr
(
maxSize
*
(
size
-
1
)));
}
void
InstantMessagingTest
::
tearDown
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment