[Libreoffice-commits] online.git: loolwsd/test
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Oct 10 06:25:37 UTC 2016
loolwsd/test/helpers.hpp | 71 ++++++++------------------------------------
loolwsd/test/httpwstest.cpp | 33 ++++++++------------
2 files changed, 28 insertions(+), 76 deletions(-)
New commits:
commit 0f4ccd8429bec6abf044ecfd2b61e78afae3d1ed
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat Oct 8 19:40:49 2016 -0400
loolwsd: remove unnecessary unittest helpers
Change-Id: I85962c2c96c99a8132aa015670521dd5f6166097
Reviewed-on: https://gerrit.libreoffice.org/29640
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index 28de935..bb18cfc 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -217,56 +217,6 @@ int getErrorCode(Poco::Net::WebSocket& ws, std::string& message)
}
inline
-void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string& response, const bool isLine, const std::string& name = "")
-{
- try
- {
- int flags = 0;
- int retries = 20;
- const Poco::Timespan waitTime(1000000);
-
- response.clear();
- ws.setReceiveTimeout(0);
- do
- {
- if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
- {
- char buffer[READ_BUFFER_SIZE];
- int bytes = ws.receiveFrame(buffer, sizeof(buffer), flags);
- if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
- {
- std::cerr << name << "Got " << bytes << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << std::endl;
- const std::string message = isLine ?
- LOOLProtocol::getFirstLine(buffer, bytes) :
- std::string(buffer, bytes);
-
- if (message.find(prefix) == 0)
- {
- response = message.substr(prefix.length());
- break;
- }
- }
- else
- {
- std::cerr << name << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
- }
- retries = 10;
- }
- else
- {
- std::cerr << name << "Timeout waiting for " << prefix << "\n";
- --retries;
- }
- }
- while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
- }
- catch (const Poco::Net::WebSocketException& exc)
- {
- std::cerr << exc.message();
- }
-}
-
-inline
std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string name = "", const size_t timeoutMs = 10000)
{
name = name + '[' + prefix + "] ";
@@ -367,6 +317,19 @@ std::vector<char> getResponseMessage(const std::shared_ptr<Poco::Net::WebSocket>
return getResponseMessage(*ws, prefix, name, timeoutMs);
}
+inline
+std::string getResponseMessageString(Poco::Net::WebSocket& ws, const std::string& prefix, const std::string& name = "", const size_t timeoutMs = 10000)
+{
+ const auto response = getResponseMessage(ws, prefix, name, timeoutMs);
+ return std::string(response.data(), response.size());
+}
+
+inline
+std::string getResponseMessageString(const std::shared_ptr<Poco::Net::WebSocket>& ws, const std::string& prefix, const std::string& name = "", const size_t timeoutMs = 10000)
+{
+ return getResponseMessageString(*ws, prefix, name, timeoutMs);
+}
+
template <typename T>
std::string getResponseLine(T& ws, const std::string& prefix, const std::string name = "", const size_t timeoutMs = 10000)
{
@@ -385,17 +348,11 @@ std::string assertResponseLine(T& ws, const std::string& prefix, const std::stri
template <typename T>
std::string assertNotInResponse(T& ws, const std::string& prefix, const std::string name = "")
{
- const auto res = getResponseLine(ws, prefix, name, 2000);
+ const auto res = getResponseLine(ws, prefix, name, 1000);
CPPUNIT_ASSERT_MESSAGE("Did not expect getting message [" + res + "].", res.empty());
return res;
}
-inline
-void getResponseMessage(const std::shared_ptr<Poco::Net::WebSocket>& ws, const std::string& prefix, std::string& response, const bool isLine, const std::string& name = "")
-{
- getResponseMessage(*ws, prefix, response, isLine, name);
-}
-
// 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.
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index fdf82cf..dee4717 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -1149,28 +1149,25 @@ void HTTPWSTest::testLimitCursor( std::function<void(const std::shared_ptr<Poco:
// check document size
sendTextFrame(socket, "status", testname);
- getResponseMessage(socket, "status:", response, false, testname);
- CPPUNIT_ASSERT_MESSAGE("did not receive a status: message as expected", !response.empty());
- parseDocSize(response, "spreadsheet", docSheet, docSheets, docWidth, docHeight, docViewId);
+ response = assertResponseLine(socket, "status:", testname);
+ parseDocSize(response.substr(7), "spreadsheet", docSheet, docSheets, docWidth, docHeight, docViewId);
// Send an arrow key to initialize the CellCursor, otherwise we get "EMPTY".
sendTextFrame(socket, "key type=input char=0 key=1027", testname);
text.clear();
Poco::format(text, "commandvalues command=.uno:CellCursor?outputHeight=%d&outputWidth=%d&tileHeight=%d&tileWidth=%d",
- 256, 256, 3840, 3840);
+ 256, 256, 3840, 3840);
sendTextFrame(socket, text, testname);
- getResponseMessage(socket, "commandvalues:", response, false, testname);
- CPPUNIT_ASSERT_MESSAGE("did not receive a commandvalues: message as expected", !response.empty());
- getCursor(response, cursorX, cursorY, cursorWidth, cursorHeight);
+ const auto cursor = getResponseMessageString(socket, "commandvalues:", testname);
+ getCursor(cursor.substr(14), cursorX, cursorY, cursorWidth, cursorHeight);
// move cursor
keyhandler(socket, cursorX, cursorY, cursorWidth, cursorHeight, docWidth, docHeight);
// filter messages, and expect to receive new document size
- getResponseMessage(socket, "status:", response, false, testname);
- CPPUNIT_ASSERT_MESSAGE("did not receive a status: message as expected", !response.empty());
- parseDocSize(response, "spreadsheet", newSheet, newSheets, newWidth, newHeight, docViewId);
+ response = assertResponseLine(socket, "status:", testname);
+ parseDocSize(response.substr(7), "spreadsheet", newSheet, newSheets, newWidth, newHeight, docViewId);
CPPUNIT_ASSERT_EQUAL(docSheets, newSheets);
CPPUNIT_ASSERT_EQUAL(docSheet, newSheet);
@@ -2025,13 +2022,12 @@ void HTTPWSTest::testCursorPosition()
std::string docPath;
std::string docURL;
std::string response;
- std::vector<std::string> responses;
getDocumentPathAndURL("Example.odt", docPath, docURL);
auto socket0 = *loadDocAndGetSocket(_uri, docURL, testname);
// receive cursor position
- getResponseMessage(socket0, "invalidatecursor:", response, false, testname);
+ response = getResponseLine(socket0, "invalidatecursor:", testname);
Poco::StringTokenizer cursorTokens(response, ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), cursorTokens.count());
@@ -2039,7 +2035,7 @@ void HTTPWSTest::testCursorPosition()
auto socket1 = *loadDocAndGetSocket(_uri, docURL, testname);
//receive view cursor position
- getResponseMessage(socket1, "invalidateviewcursor:", response, false, testname);
+ response = getResponseMessageString(socket1, "invalidateviewcursor:", testname);
Poco::JSON::Parser parser;
const auto result = parser.parse(response);
@@ -2129,11 +2125,11 @@ void HTTPWSTest::testViewInfoMsg()
{
// Load first view and remember the viewid
sendTextFrame(socket0, "load url=" + docURL);
- getResponseMessage(socket0, "status:", response, false, testname + "socket[0] ");
+ response = getResponseLine(socket0, "status:", testname + "socket[0] ");
parseDocSize(response, "text", part, parts, width, height, viewid[0]);
// Check if viewinfo message also mentions the same viewid
- getResponseMessage(socket0, "viewinfo: ", response, false, testname + "socket[0] ");
+ response = getResponseMessageString(socket0, "viewinfo: ", testname + "socket[0] ");
Poco::JSON::Parser parser0;
Poco::JSON::Array::Ptr array = parser0.parse(response).extract<Poco::JSON::Array::Ptr>();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), array->size());
@@ -2144,12 +2140,12 @@ void HTTPWSTest::testViewInfoMsg()
// Load second view and remember the viewid
sendTextFrame(socket1, "load url=" + docURL);
- getResponseMessage(socket1, "status:", response, false, testname + "socket[1] ");
+ response = getResponseLine(socket1, "status:", testname + "socket[1] ");
parseDocSize(response, "text", part, parts, width, height, viewid[1]);
// Check if viewinfo message in this view mentions
// viewid of both first loaded view and this view
- getResponseMessage(socket1, "viewinfo: ", response, false, testname + "socket[1] ");
+ response = getResponseMessageString(socket1, "viewinfo: ", testname + "socket[1] ");
Poco::JSON::Parser parser1;
array = parser1.parse(response).extract<Poco::JSON::Array::Ptr>();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), array->size());
@@ -2167,8 +2163,7 @@ void HTTPWSTest::testViewInfoMsg()
CPPUNIT_FAIL("Inconsistent viewid in viewinfo and status messages");
// Check if first view also got the same viewinfo message
- std::string response1;
- getResponseMessage(socket0, "viewinfo: ", response1, false, testname + "socket[0] ");
+ const auto response1 = getResponseMessageString(socket0, "viewinfo: ", testname + "socket[0] ");
CPPUNIT_ASSERT_EQUAL(response, response1);
}
catch(const Poco::Exception& exc)
More information about the Libreoffice-commits
mailing list