[Libreoffice-commits] online.git: 2 commits - loolwsd/test
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed May 4 10:38:04 UTC 2016
loolwsd/test/helpers.hpp | 89 ++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 80 insertions(+), 9 deletions(-)
New commits:
commit 2b02caa0b58d30efb38458d31b0b5847d47d92b8
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Tue May 3 23:35:34 2016 -0400
loolwsd: getResponseMessage that can return large binary payloads
Change-Id: Ie2cd3db5abdf00a04a6970825359095608fdb660
Reviewed-on: https://gerrit.libreoffice.org/24645
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 46f1eb5..4dba8ac 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -240,6 +240,77 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
}
inline
+std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix)
+{
+ try
+ {
+ int flags;
+ int bytes;
+ int retries = 20;
+ const Poco::Timespan waitTime(1000000);
+ std::vector<char> response;
+
+ ws.setReceiveTimeout(0);
+ do
+ {
+ if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
+ {
+ response.resize(READ_BUFFER_SIZE);
+ bytes = ws.receiveFrame(response.data(), response.size(), flags);
+ response.resize(bytes >= 0 ? bytes : 0);
+ auto message = LOOLProtocol::getAbbreviatedMessage(response);
+ std::cerr << "Got " << bytes << " bytes: " << message << std::endl;
+ if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+ {
+ if (message.find(prefix) == 0)
+ {
+ return response;
+ }
+ else if (message.find("nextmessage") == 0)
+ {
+ Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ int size = 0;
+ if (tokens.count() == 2 &&
+ tokens[0] == "nextmessage:" && LOOLProtocol::getTokenInteger(tokens[1], "size", size) && size > 0)
+ {
+ response.resize(size);
+ bytes = ws.receiveFrame(response.data(), response.size(), flags);
+ response.resize(bytes >= 0 ? bytes : 0);
+ message = LOOLProtocol::getAbbreviatedMessage(response);
+ std::cerr << "Got " << bytes << " bytes: " << message << std::endl;
+ if (bytes > 0 && message.find(prefix) == 0)
+ {
+ return response;
+ }
+ }
+ }
+ }
+ else
+ {
+ response.resize(0);
+ std::cerr << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
+ }
+
+ 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 std::vector<char>();
+}
+
+
+inline
std::shared_ptr<Poco::Net::WebSocket> loadDocAndGetSocket(const Poco::URI& uri, const std::string& documentURL)
{
try
commit a760c71ed6241ea9d25b4feaa523cc1dd3649460
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Tue May 3 23:32:26 2016 -0400
loolwsd: tests should print progress and errors to cerr
Change-Id: I07341ef26de877b01f6dff0d8df81be4e1b4bed2
Reviewed-on: https://gerrit.libreoffice.org/24644
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 a0adaeb..46f1eb5 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -89,7 +89,7 @@ bool isDocumentLoaded(Poco::Net::WebSocket& ws, std::string name = "")
bytes = ws.receiveFrame(buffer, sizeof(buffer), flags);
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
{
- std::cout << name << "Got " << bytes << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << std::endl;
+ std::cerr << name << "Got " << bytes << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << std::endl;
const std::string line = LOOLProtocol::getFirstLine(buffer, bytes);
const std::string prefixIndicator = "statusindicatorfinish:";
const std::string prefixStatus = "status:";
@@ -108,7 +108,7 @@ bool isDocumentLoaded(Poco::Net::WebSocket& ws, std::string name = "")
}
else
{
- std::cout << "Timeout\n";
+ std::cerr << "Timeout\n";
--retries;
}
}
@@ -116,7 +116,7 @@ bool isDocumentLoaded(Poco::Net::WebSocket& ws, std::string name = "")
}
catch (const Poco::Net::WebSocketException& exc)
{
- std::cout << exc.message();
+ std::cerr << exc.message();
}
return isLoaded;
@@ -174,7 +174,7 @@ connectLOKit(Poco::URI uri,
}
catch (const Poco::TimeoutException& exc)
{
- std::cout << exc.displayText() << std::endl;
+ std::cerr << exc.displayText() << std::endl;
}
}
while (received > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
@@ -208,7 +208,7 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
bytes = ws.receiveFrame(buffer, sizeof(buffer), flags);
if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
{
- std::cout << "Got " << bytes << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << std::endl;
+ std::cerr << "Got " << bytes << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, bytes) << std::endl;
const std::string message = isLine ?
LOOLProtocol::getFirstLine(buffer, bytes) :
std::string(buffer, bytes);
@@ -221,13 +221,13 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
}
else
{
- std::cout << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
+ std::cerr << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
}
retries = 10;
}
else
{
- std::cout << "Timeout\n";
+ std::cerr << "Timeout\n";
--retries;
}
}
@@ -235,7 +235,7 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
}
catch (const Poco::Net::WebSocketException& exc)
{
- std::cout << exc.message();
+ std::cerr << exc.message();
}
}
@@ -291,7 +291,7 @@ void SocketProcessor(std::string name,
n = socket->receiveFrame(buffer, sizeof(buffer), flags);
if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
{
- std::cout << name << "Got " << n << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl;
+ std::cerr << name << "Got " << n << " bytes: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << std::endl;
if (!handler(std::string(buffer, n)))
{
break;
More information about the Libreoffice-commits
mailing list