[Libreoffice-commits] online.git: common/Protocol.cpp common/Protocol.hpp test/httpwstest.cpp test/WhiteBoxTests.cpp
Jan Holesovsky (via logerrit)
logerrit at kemper.freedesktop.org
Fri Nov 8 21:21:17 UTC 2019
common/Protocol.cpp | 46 +++++++++-------------------------------------
common/Protocol.hpp | 8 ++------
test/WhiteBoxTests.cpp | 2 +-
test/httpwstest.cpp | 25 ++++++++++++-------------
4 files changed, 24 insertions(+), 57 deletions(-)
New commits:
commit d906c78198468d10d70de31a23b4166924dd7550
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Fri Nov 8 14:50:33 2019 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Nov 8 22:20:58 2019 +0100
killpoco: Remove POCO from Protocol.cpp + related StringTokenizer usage.
Change-Id: I9d93c03dde110a4e88f7ec86e5934916596a27c1
Reviewed-on: https://gerrit.libreoffice.org/82301
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/common/Protocol.cpp b/common/Protocol.cpp
index 9aa4a230a..e915f8085 100644
--- a/common/Protocol.cpp
+++ b/common/Protocol.cpp
@@ -19,10 +19,6 @@
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
-#include <Poco/StringTokenizer.h>
-
-using Poco::StringTokenizer;
-
namespace LOOLProtocol
{
std::tuple<int, int, std::string> ParseVersion(const std::string& version)
@@ -31,15 +27,15 @@ namespace LOOLProtocol
int minor = -1;
std::string patch;
- StringTokenizer firstTokens(version, ".", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- if (firstTokens.count() > 0)
+ std::vector<std::string> firstTokens(tokenize(version, '.'));
+ if (firstTokens.size() > 0)
{
major = std::stoi(firstTokens[0]);
- StringTokenizer secondTokens(firstTokens[1], "-", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+ std::vector<std::string> secondTokens(tokenize(firstTokens[1], '-'));
minor = std::stoi(secondTokens[0]);
- if (secondTokens.count() > 1)
+ if (secondTokens.size() > 1)
patch = secondTokens[1];
}
return std::make_tuple(major, minor, patch);
@@ -167,9 +163,9 @@ namespace LOOLProtocol
return false;
}
- bool getTokenInteger(const Poco::StringTokenizer& tokens, const std::string& name, int& value)
+ bool getTokenInteger(const std::vector<std::string>& tokens, const std::string& name, int& value)
{
- for (size_t i = 0; i < tokens.count(); i++)
+ for (size_t i = 0; i < tokens.size(); i++)
{
if (getTokenInteger(tokens[i], name, value))
return true;
@@ -177,19 +173,9 @@ namespace LOOLProtocol
return false;
}
- bool getTokenString(const Poco::StringTokenizer& tokens, const std::string& name, std::string& value)
+ bool getTokenKeyword(const std::vector<std::string>& tokens, const std::string& name, const std::map<std::string, int>& map, int& value)
{
- for (size_t i = 0; i < tokens.count(); i++)
- {
- if (getTokenString(tokens[i], name, value))
- return true;
- }
- return false;
- }
-
- bool getTokenKeyword(const Poco::StringTokenizer& tokens, const std::string& name, const std::map<std::string, int>& map, int& value)
- {
- for (size_t i = 0; i < tokens.count(); i++)
+ for (size_t i = 0; i < tokens.size(); i++)
{
if (getTokenKeyword(tokens[i], name, map, value))
return true;
@@ -197,19 +183,6 @@ namespace LOOLProtocol
return false;
}
- bool getTokenInteger(const std::vector<std::string>& tokens, const std::string& name, int& value)
- {
- for (const auto& pair : tokens)
- {
- if (getTokenInteger(pair, name, value))
- {
- return true;
- }
- }
-
- return false;
- }
-
bool getTokenStringFromMessage(const std::string& message, const std::string& name, std::string& value)
{
if (message.size() > name.size() + 1)
@@ -235,8 +208,7 @@ namespace LOOLProtocol
bool getTokenKeywordFromMessage(const std::string& message, const std::string& name, const std::map<std::string, int>& map, int& value)
{
- Poco::StringTokenizer tokens(message, " \n", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- return getTokenKeyword(tokens, name, map, value);
+ return getTokenKeyword(tokenize(message), name, map, value);
}
};
diff --git a/common/Protocol.hpp b/common/Protocol.hpp
index cb915fa5f..b915d1a7c 100644
--- a/common/Protocol.hpp
+++ b/common/Protocol.hpp
@@ -17,9 +17,7 @@
#include <map>
#include <sstream>
#include <string>
-
-#include <Poco/Format.h>
-#include <Poco/StringTokenizer.h>
+#include <vector>
#include <Poco/Net/WebSocket.h>
@@ -76,9 +74,7 @@ namespace LOOLProtocol
bool getTokenString(const std::string& token, const std::string& name, std::string& value);
bool getTokenKeyword(const std::string& token, const std::string& name, const std::map<std::string, int>& map, int& value);
- bool getTokenInteger(const Poco::StringTokenizer& tokens, const std::string& name, int& value);
- bool getTokenString(const Poco::StringTokenizer& tokens, const std::string& name, std::string& value);
- bool getTokenKeyword(const Poco::StringTokenizer& tokens, const std::string& name, const std::map<std::string, int>& map, int& value);
+ bool getTokenKeyword(const std::vector<std::string>& tokens, const std::string& name, const std::map<std::string, int>& map, int& value);
bool getTokenInteger(const std::vector<std::string>& tokens, const std::string& name, int& value);
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index 219c3ccf2..db892fdb5 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -79,7 +79,7 @@ void WhiteBoxTests::testLOOLProtocolFunctions()
CPPUNIT_ASSERT_EQUAL(2, mumble);
std::string message("hello x=1 y=2 foo=42 bar=hello-sailor mumble='goodbye' zip zap");
- Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ std::vector<std::string> tokens(LOOLProtocol::tokenize(message));
CPPUNIT_ASSERT(LOOLProtocol::getTokenInteger(tokens, "foo", foo));
CPPUNIT_ASSERT_EQUAL(42, foo);
diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp
index e49e54a60..1f6ecf085 100644
--- a/test/httpwstest.cpp
+++ b/test/httpwstest.cpp
@@ -29,7 +29,6 @@
#include <Poco/Path.h>
#include <Poco/RegularExpression.h>
#include <Poco/StreamCopier.h>
-#include <Poco/StringTokenizer.h>
#include <Poco/URI.h>
#include <Poco/DOM/Node.h>
#include <Poco/DOM/Document.h>
@@ -659,8 +658,8 @@ void HTTPWSTest::testExcelLoad()
const auto status = assertResponseString(socket, "status:", testname);
// Expected format is something like 'status: type=text parts=2 current=0 width=12808 height=1142'.
- Poco::StringTokenizer tokens(status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(8), tokens.count());
+ std::vector<std::string> tokens(LOOLProtocol::tokenize(status, ' '));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(8), tokens.size());
}
catch (const Poco::Exception& exc)
{
@@ -857,7 +856,7 @@ void HTTPWSTest::testSlideShow()
response = getResponseString(socket, "downloadas:", testname);
CPPUNIT_ASSERT_MESSAGE("did not receive a downloadas: message as expected", !response.empty());
- Poco::StringTokenizer tokens(response.substr(11), " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ std::vector<std::string> tokens(LOOLProtocol::tokenize(response.substr(11), ' '));
// "downloadas: jail= dir= name=slideshow.svg port= id=slideshow"
const std::string jail = tokens[0].substr(std::string("jail=").size());
const std::string dir = tokens[1].substr(std::string("dir=").size());
@@ -1059,11 +1058,11 @@ void HTTPWSTest::getPartHashCodes(const std::string& testname,
TST_LOG("Reading parts from [" << response << "].");
// Expected format is something like 'type= parts= current= width= height= viewid= [hiddenparts=]'.
- Poco::StringTokenizer tokens(line, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ std::vector<std::string> tokens(LOOLProtocol::tokenize(line, ' '));
#if defined CPPUNIT_ASSERT_GREATEREQUAL
- CPPUNIT_ASSERT_GREATEREQUAL(static_cast<size_t>(7), tokens.count());
+ CPPUNIT_ASSERT_GREATEREQUAL(static_cast<size_t>(7), tokens.size());
#else
- CPPUNIT_ASSERT_MESSAGE("Expected at least 7 tokens.", static_cast<size_t>(7) <= tokens.count());
+ CPPUNIT_ASSERT_MESSAGE("Expected at least 7 tokens.", static_cast<size_t>(7) <= tokens.size());
#endif
const std::string type = tokens[0].substr(std::string("type=").size());
@@ -1107,7 +1106,7 @@ void HTTPWSTest::getCursor(const std::string& message,
CPPUNIT_ASSERT_EQUAL(std::string(".uno:CellCursor"), text);
text = command->get("commandValues").toString();
CPPUNIT_ASSERT(!text.empty());
- Poco::StringTokenizer position(text, ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ std::vector<std::string> position(LOOLProtocol::tokenize(text, ','));
cursorX = std::stoi(position[0]);
cursorY = std::stoi(position[1]);
cursorWidth = std::stoi(position[2]);
@@ -2101,8 +2100,8 @@ void HTTPWSTest::testCursorPosition()
const auto& command0 = result0.extract<Poco::JSON::Object::Ptr>();
CPPUNIT_ASSERT_MESSAGE("missing property rectangle", command0->has("rectangle"));
- Poco::StringTokenizer cursorTokens(command0->get("rectangle").toString(), ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), cursorTokens.count());
+ std::vector<std::string> cursorTokens(LOOLProtocol::tokenize(command0->get("rectangle").toString(), ','));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), cursorTokens.size());
// Create second view
std::shared_ptr<LOOLWebSocket> socket1 = loadDocAndGetSocket(_uri, docURL, testname);
@@ -2115,8 +2114,8 @@ void HTTPWSTest::testCursorPosition()
const auto& command = result.extract<Poco::JSON::Object::Ptr>();
CPPUNIT_ASSERT_MESSAGE("missing property rectangle", command->has("rectangle"));
- Poco::StringTokenizer viewTokens(command->get("rectangle").toString(), ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), viewTokens.count());
+ std::vector<std::string> viewTokens(LOOLProtocol::tokenize(command->get("rectangle").toString(), ','));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), viewTokens.size());
// check both cursor should be equal
CPPUNIT_ASSERT_EQUAL(cursorTokens[0], viewTokens[0]);
@@ -2150,7 +2149,7 @@ void HTTPWSTest::testAlertAllUsers()
for (int i = 0; i < 2; i++)
{
const std::string response = assertResponseString(socket[i], "error:", testname);
- Poco::StringTokenizer tokens(response.substr(6), " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ std::vector<std::string> tokens(LOOLProtocol::tokenize(response.substr(6), ' '));
std::string cmd;
LOOLProtocol::getTokenString(tokens, "cmd", cmd);
CPPUNIT_ASSERT_EQUAL(std::string("internal"), cmd);
More information about the Libreoffice-commits
mailing list