[Libreoffice-commits] online.git: loolwsd/test
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Oct 10 06:27:44 UTC 2016
loolwsd/test/helpers.hpp | 74 +++++++++--------------------------------------
1 file changed, 15 insertions(+), 59 deletions(-)
New commits:
commit 46aec10c3c71a69f6308a404aa8bbac08af42ff3
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat Oct 8 21:48:41 2016 -0400
loolwsd: cleanup of isDocumentLoaded
Change-Id: I28321bda3000b443aff4603ad438183fa6cfb2f9
Reviewed-on: https://gerrit.libreoffice.org/29644
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 651e247..bed5788 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -106,64 +106,6 @@ void sendTextFrame(const std::shared_ptr<Poco::Net::WebSocket>& socket, const st
}
inline
-bool isDocumentLoaded(Poco::Net::WebSocket& ws, const std::string& name = "", bool isView = true)
-{
- bool isLoaded = false;
- try
- {
- int flags = 0;
- int retries = 30;
- const Poco::Timespan waitTime(1000000);
-
- ws.setReceiveTimeout(0);
- do
- {
- char buffer[READ_BUFFER_SIZE];
- if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
- {
- 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 line = LOOLProtocol::getFirstLine(buffer, bytes);
- const std::string prefix = isView ? "status:" : "statusindicatorfinish:";
- if (line.find(prefix) == 0)
- {
- isLoaded = true;
- break;
- }
- }
- else
- {
- std::cerr << name << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << std::endl;
- break;
- }
-
- retries = 10;
- }
- else
- {
- std::cerr << "Timeout\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();
- }
-
- return isLoaded;
-}
-
-inline
-bool isDocumentLoaded(std::shared_ptr<Poco::Net::WebSocket>& ws, const std::string& name = "", bool isView = true)
-{
- return isDocumentLoaded(*ws, name, isView);
-}
-
-inline
Poco::Net::HTTPClientSession* createSession(const Poco::URI& uri)
{
#if ENABLE_SSL
@@ -290,7 +232,7 @@ std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string
{
if (!timedout)
{
- std::cerr << name << "Timeout " ;
+ std::cerr << name << "Timeout ";
}
else
{
@@ -341,6 +283,20 @@ std::string assertNotInResponse(T& ws, const std::string& prefix, const std::str
return res;
}
+inline
+bool isDocumentLoaded(Poco::Net::WebSocket& ws, const std::string& name = "", bool isView = true)
+{
+ const std::string prefix = isView ? "status:" : "statusindicatorfinish:";
+ const auto message = getResponseString(ws, prefix, name);
+ return LOOLProtocol::getFirstToken(message) == prefix;
+}
+
+inline
+bool isDocumentLoaded(std::shared_ptr<Poco::Net::WebSocket>& ws, const std::string& name = "", bool isView = true)
+{
+ return isDocumentLoaded(*ws, name, isView);
+}
+
// 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