[Libreoffice-commits] online.git: loolwsd/test
Henry Castro
hcastro at collabora.com
Mon Apr 25 22:06:36 UTC 2016
loolwsd/test/httpwstest.cpp | 109 ++++++++++++--------------------------------
1 file changed, 30 insertions(+), 79 deletions(-)
New commits:
commit 8ea127407b347a9446ffcd24f8cff9de691c3010
Author: Henry Castro <hcastro at collabora.com>
Date: Mon Apr 25 18:06:50 2016 -0400
loolwsd: test: replace std::regex
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 6c183be..42aa396 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -114,6 +114,9 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
std::string& response,
const bool isLine);
+ void getPartHashCodes(const std::string response,
+ std::vector<std::string>& parts);
+
std::shared_ptr<Poco::Net::WebSocket>
connectLOKit(Poco::Net::HTTPRequest& request,
Poco::Net::HTTPResponse& response);
@@ -931,21 +934,8 @@ void HTTPWSTest::testInsertDelete()
const std::string prefix = "parts=";
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
CPPUNIT_ASSERT_EQUAL(1, totalParts);
-
- std::regex endLine("[^\n\r]+");
- std::regex number("^[0-9]+$");
- std::smatch match;
- for (std::sregex_iterator it = std::sregex_iterator(response.begin(), response.end(), endLine);
- it != std::sregex_iterator(); ++it)
- {
- const auto str = (*it).str();
- if (std::regex_match(str, match, number))
- {
- parts.push_back(match.str());
- }
- }
+ getPartHashCodes(response, parts);
CPPUNIT_ASSERT_EQUAL(totalParts, (int)parts.size());
- parts.clear();
}
// insert 10 slides
@@ -959,20 +949,8 @@ void HTTPWSTest::testInsertDelete()
const std::string prefix = "parts=";
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
- std::regex endLine("[^\n\r]+");
- std::regex number("^[0-9]+$");
- std::smatch match;
- for (std::sregex_iterator regex_it = std::sregex_iterator(response.begin(), response.end(), endLine);
- regex_it != std::sregex_iterator(); ++regex_it)
- {
- const auto str = (*regex_it).str();
- if (std::regex_match(str, match, number))
- {
- parts.push_back(match.str());
- }
- }
+ getPartHashCodes(response, parts);
CPPUNIT_ASSERT_EQUAL(totalParts, (int)parts.size());
- parts.clear();
}
}
@@ -987,20 +965,8 @@ void HTTPWSTest::testInsertDelete()
const std::string prefix = "parts=";
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
- std::regex endLine("[^\n\r]+");
- std::regex number("^[0-9]+$");
- std::smatch match;
- for (std::sregex_iterator regex_it = std::sregex_iterator(response.begin(), response.end(), endLine);
- regex_it != std::sregex_iterator(); ++regex_it)
- {
- const auto str = (*regex_it).str();
- if (std::regex_match(str, match, number))
- {
- parts.push_back(match.str());
- }
- }
+ getPartHashCodes(response, parts);
CPPUNIT_ASSERT_EQUAL(totalParts, (int)parts.size());
- parts.clear();
}
}
@@ -1015,20 +981,8 @@ void HTTPWSTest::testInsertDelete()
const std::string prefix = "parts=";
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
- std::regex endLine("[^\n\r]+");
- std::regex number("^[0-9]+$");
- std::smatch match;
- for (std::sregex_iterator regex_it = std::sregex_iterator(response.begin(), response.end(), endLine);
- regex_it != std::sregex_iterator(); ++regex_it)
- {
- const auto str = (*regex_it).str();
- if (std::regex_match(str, match, number))
- {
- parts.push_back(match.str());
- }
- }
+ getPartHashCodes(response, parts);
CPPUNIT_ASSERT_EQUAL(totalParts, (int)parts.size());
- parts.clear();
}
}
@@ -1043,20 +997,8 @@ void HTTPWSTest::testInsertDelete()
const std::string prefix = "parts=";
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
- std::regex endLine("[^\n\r]+");
- std::regex number("^[0-9]+$");
- std::smatch match;
- for (std::sregex_iterator regex_it = std::sregex_iterator(response.begin(), response.end(), endLine);
- regex_it != std::sregex_iterator(); ++regex_it)
- {
- const auto str = (*regex_it).str();
- if (std::regex_match(str, match, number))
- {
- parts.push_back(match.str());
- }
- }
+ getPartHashCodes(response, parts);
CPPUNIT_ASSERT_EQUAL(totalParts, (int)parts.size());
- parts.clear();
}
}
@@ -1070,20 +1012,8 @@ void HTTPWSTest::testInsertDelete()
const int totalParts = std::stoi(tokens[1].substr(prefix.size()));
CPPUNIT_ASSERT_EQUAL(1, totalParts);
- std::regex endLine("[^\n\r]+");
- std::regex number("^[0-9]+$");
- std::smatch match;
- for (std::sregex_iterator it = std::sregex_iterator(response.begin(), response.end(), endLine);
- it != std::sregex_iterator(); ++it)
- {
- const auto str = (*it).str();
- if (std::regex_match(str, match, number))
- {
- parts.push_back(match.str());
- }
- }
+ getPartHashCodes(response, parts);
CPPUNIT_ASSERT_EQUAL(totalParts, (int)parts.size());
- parts.clear();
}
socket.shutdown();
@@ -1301,6 +1231,27 @@ int countLoolKitProcesses()
return result;
}
+void HTTPWSTest::getPartHashCodes(const std::string response,
+ std::vector<std::string>& parts)
+{
+ Poco::RegularExpression endLine("[^\n\r]+");
+ Poco::RegularExpression number("^[0-9]+$");
+ Poco::RegularExpression::MatchVec matches;
+ int offset = 0;
+
+ parts.clear();
+ while (endLine.match(response, offset, matches) > 0)
+ {
+ CPPUNIT_ASSERT_EQUAL(1, (int)matches.size());
+ const auto str = response.substr(matches[0].offset, matches[0].length);
+ if (number.match(str, 0) > 0)
+ {
+ parts.push_back(str);
+ }
+ offset = static_cast<int>(matches[0].offset + matches[0].length);
+ }
+}
+
// Connecting to a Kit process is managed by document broker, that it does several
// jobs to establish the bridge connection between the Client and Kit process,
// The result, it is mostly time outs to get messages in the unit test and it could fail.
More information about the Libreoffice-commits
mailing list