Commit afa459d1 authored by Ghislain MARY's avatar Ghislain MARY

Fix Utils::split() method that was not taking the delimiter length into account.

parent 10a91108
Pipeline #408 failed with stage
in 0 seconds
......@@ -177,7 +177,7 @@ ChatMessageModifier::Result CpimChatMessageModifier::decode (const shared_ptr<Ch
if (dispositionNotificationHeader) {
vector<string> values = Utils::split(dispositionNotificationHeader->getValue(), ", ");
for (const auto &value : values) {
string trimmedValue = Utils::trim(value); //Might be better to have a Disposition-Notification parser from the CPIM paser
string trimmedValue = Utils::trim(value); // Might be better to have a Disposition-Notification parser from the CPIM parser
if (trimmedValue == "positive-delivery")
message->getPrivate()->setPositiveDeliveryNotificationRequired(true);
else if (trimmedValue == "negative-delivery")
......
......@@ -58,7 +58,7 @@ vector<string> Utils::split (const string &str, const string &delimiter) {
vector<string> out;
size_t pos = 0, oldPos = 0;
for (; (pos = str.find(delimiter, pos)) != string::npos; oldPos = pos + 1, pos = oldPos)
for (; (pos = str.find(delimiter, pos)) != string::npos; oldPos = pos + delimiter.length(), pos = oldPos)
out.push_back(str.substr(oldPos, pos - oldPos));
out.push_back(str.substr(oldPos));
......
......@@ -214,6 +214,7 @@ set(SOURCE_FILES_CXX
main-db-tester.cpp
multipart-tester.cpp
property-container-tester.cpp
utils-tester.cpp
)
set(HEADER_FILES
......
......@@ -80,6 +80,7 @@ extern test_suite_t setup_test_suite;
extern test_suite_t stun_test_suite;
extern test_suite_t tunnel_test_suite;
extern test_suite_t upnp_test_suite;
extern test_suite_t utils_test_suite;
extern test_suite_t video_test_suite;
#ifdef VCARD_ENABLED
......
......@@ -650,6 +650,7 @@ void liblinphone_tester_add_suites() {
bc_tester_add_suite(&vcard_test_suite);
#endif
bc_tester_add_suite(&group_chat_test_suite);
bc_tester_add_suite(&utils_test_suite);
}
static int linphone_core_manager_get_max_audio_bw_base(const int array[],int array_size) {
......
/*
* utils-tester.cpp
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "linphone/utils/utils.h"
#include "liblinphone_tester.h"
#include "tester_utils.h"
// =============================================================================
using namespace std;
using namespace LinphonePrivate;
static void split () {
string emptyString;
vector<string> result = Utils::split(emptyString, ",");
BC_ASSERT_EQUAL(result.size(), 1, int, "%d");
BC_ASSERT_STRING_EQUAL(result.at(0).c_str(), "");
string contentDisposition("positive-delivery, negative-delivery, display");
result = Utils::split(contentDisposition, ", ");
BC_ASSERT_EQUAL(result.size(), 3, int, "%d");
BC_ASSERT_STRING_EQUAL(result.at(0).c_str(), "positive-delivery");
BC_ASSERT_STRING_EQUAL(result.at(1).c_str(), "negative-delivery");
BC_ASSERT_STRING_EQUAL(result.at(2).c_str(), "display");
result = Utils::split(contentDisposition, ",");
BC_ASSERT_EQUAL(result.size(), 3, int, "%d");
BC_ASSERT_STRING_EQUAL(result.at(0).c_str(), "positive-delivery");
BC_ASSERT_STRING_EQUAL(result.at(1).c_str(), " negative-delivery");
BC_ASSERT_STRING_EQUAL(result.at(2).c_str(), " display");
result = Utils::split(contentDisposition, ',');
BC_ASSERT_EQUAL(result.size(), 3, int, "%d");
BC_ASSERT_STRING_EQUAL(result.at(0).c_str(), "positive-delivery");
BC_ASSERT_STRING_EQUAL(result.at(1).c_str(), " negative-delivery");
BC_ASSERT_STRING_EQUAL(result.at(2).c_str(), " display");
result = Utils::split(contentDisposition, "|");
BC_ASSERT_EQUAL(result.size(), 1, int, "%d");
BC_ASSERT_STRING_EQUAL(result.at(0).c_str(), contentDisposition.c_str());
}
static void trim () {
string emptyString;
string result = Utils::trim(emptyString);
BC_ASSERT_STRING_EQUAL(result.c_str(), "");
string stringWithLeadingSpace(" hello");
result = Utils::trim(stringWithLeadingSpace);
BC_ASSERT_STRING_EQUAL(result.c_str(), "hello");
string stringWithTailingSpace("hello ");
result = Utils::trim(stringWithTailingSpace);
BC_ASSERT_STRING_EQUAL(result.c_str(), "hello");
string stringWithSpaces(" hello ");
result = Utils::trim(stringWithSpaces);
BC_ASSERT_STRING_EQUAL(result.c_str(), "hello");
string stringContainingSpaces(" hello world! ");
result = Utils::trim(stringContainingSpaces);
BC_ASSERT_STRING_EQUAL(result.c_str(), "hello world!");
}
test_t utils_tests[] = {
TEST_NO_TAG("split", split),
TEST_NO_TAG("trim", trim)
};
test_suite_t utils_test_suite = {
"Utils", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
sizeof(utils_tests) / sizeof(utils_tests[0]), utils_tests
};
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