[Libreoffice-commits] online.git: loolwsd/test

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri May 13 12:58:16 UTC 2016


 loolwsd/test/TileCacheTests.cpp |    8 +++---
 loolwsd/test/helpers.hpp        |   51 ++++++++++++++--------------------------
 loolwsd/test/httpwstest.cpp     |   14 +++++-----
 3 files changed, 30 insertions(+), 43 deletions(-)

New commits:
commit 0c004f46d0e55db1adacb50476417a7135e20f96
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri May 13 08:46:39 2016 -0400

    loolwsd: improved test logging
    
    Change-Id: I1f663d9f3eac0d03cda0f4bbbd3c0b9102bec12b
    Reviewed-on: https://gerrit.libreoffice.org/24968
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index da10783..65eb729 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -158,7 +158,7 @@ void TileCacheTests::testSimpleCombine()
     getDocumentPathAndURL("hello.odt", documentPath, documentURL);
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
 
-    auto socket1 = *loadDocAndGetSocket(_uri, documentURL);
+    auto socket1 = *loadDocAndGetSocket(_uri, documentURL, "simpleCombine-1 ");
 
     getResponseMessage(socket1, "invalidatetiles");
 
@@ -176,7 +176,7 @@ void TileCacheTests::testSimpleCombine()
     CPPUNIT_ASSERT_MESSAGE("did not receive a tile: message as expected", !tile1b.empty());
 
     std::cerr << "Connecting second client." << std::endl;
-    auto socket2 = *loadDocAndGetSocket(_uri, documentURL, true);
+    auto socket2 = *loadDocAndGetSocket(_uri, documentURL, "simpleCombine-2 ", true);
     sendTextFrame(socket2, "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840");
 
     auto tile2a = getResponseMessage(socket2, "tile:");
@@ -194,12 +194,12 @@ void TileCacheTests::testUnresponsiveClient()
     getDocumentPathAndURL("hello.odt", documentPath, documentURL);
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
 
-    auto socket1 = *loadDocAndGetSocket(_uri, documentURL);
+    auto socket1 = *loadDocAndGetSocket(_uri, documentURL, "unresponsiveClient-1 ");
 
     getResponseMessage(socket1, "invalidatetiles");
 
     std::cerr << "Connecting second client." << std::endl;
-    auto socket2 = *loadDocAndGetSocket(_uri, documentURL, true);
+    auto socket2 = *loadDocAndGetSocket(_uri, documentURL, "unresponsiveClient-2 ", true);
 
     // Pathologically request tiles and fail to read (say slow connection).
     // Meanwhile, verify that others can get all tiles fine.
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index 65b95a3..67410e7 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -58,26 +58,21 @@ void getDocumentPathAndURL(const char* document, std::string& documentPath, std:
 }
 
 inline
-void sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string)
+void sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string, const std::string& name = "")
 {
-    std::cerr << "Sending " << string.size() << " bytes: " << LOOLProtocol::getAbbreviatedMessage(string) << std::endl;
+    std::cerr << name << "Sending " << string.size() << " bytes: " << LOOLProtocol::getAbbreviatedMessage(string) << std::endl;
     socket.sendFrame(string.data(), string.size());
 }
 
 inline
-void sendTextFrame(const std::shared_ptr<Poco::Net::WebSocket>& socket, const std::string& string)
+void sendTextFrame(const std::shared_ptr<Poco::Net::WebSocket>& socket, const std::string& string, const std::string& name = "")
 {
-    sendTextFrame(*socket, string);
+    sendTextFrame(*socket, string, name);
 }
 
 inline
-bool isDocumentLoaded(Poco::Net::WebSocket& ws, std::string name = "", bool isView = false)
+bool isDocumentLoaded(Poco::Net::WebSocket& ws, const std::string& name = "", bool isView = false)
 {
-    if (!name.empty())
-    {
-        name += ' ';
-    }
-
     bool isLoaded = false;
     try
     {
@@ -205,13 +200,8 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
 }
 
 inline
-std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string name = "")
+std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, const std::string& name = "")
 {
-    if (!name.empty())
-    {
-        name += ": ";
-    }
-
     try
     {
         int flags = 0;
@@ -314,16 +304,17 @@ inline
 std::shared_ptr<Poco::Net::WebSocket>
 connectLOKit(Poco::URI uri,
              Poco::Net::HTTPRequest& request,
-             Poco::Net::HTTPResponse& response)
+             Poco::Net::HTTPResponse& response,
+             const std::string& name = "")
 {
     int retries = 10;
     do
     {
         std::unique_ptr<Poco::Net::HTTPClientSession> session(createSession(uri));
 
-            std::cerr << "Connecting... ";
+        std::cerr << name << "Connecting... " << std::endl;
         auto ws = std::make_shared<Poco::Net::WebSocket>(*session, request, response);
-        getResponseMessage(ws, "statusindicator: ready");
+        getResponseMessage(ws, "statusindicator: ready", name);
 
         return ws;
     }
@@ -333,18 +324,19 @@ connectLOKit(Poco::URI uri,
 }
 
 inline
-std::shared_ptr<Poco::Net::WebSocket> loadDocAndGetSocket(const Poco::URI& uri, const std::string& documentURL, bool isView = false)
+std::shared_ptr<Poco::Net::WebSocket> loadDocAndGetSocket(const Poco::URI& uri, const std::string& documentURL, const std::string& name = "", bool isView = false)
 {
     try
     {
         // Load a document and get its status.
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
         Poco::Net::HTTPResponse response;
-        auto socket = connectLOKit(uri, request, response);
+        auto socket = connectLOKit(uri, request, response, name);
 
-        sendTextFrame(socket, "load url=" + documentURL);
-        CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(*socket, "", isView));
+        sendTextFrame(socket, "load url=" + documentURL, name);
+        CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(*socket, name, isView));
 
+        std::cerr << name << "Loaded document [" << documentURL << "]." << std::endl;
         return socket;
     }
     catch (const Poco::Exception& exc)
@@ -357,27 +349,22 @@ std::shared_ptr<Poco::Net::WebSocket> loadDocAndGetSocket(const Poco::URI& uri,
 }
 
 inline
-void SocketProcessor(std::string name,
+void SocketProcessor(const std::string& name,
                      const std::shared_ptr<Poco::Net::WebSocket>& socket,
                      std::function<bool(const std::string& msg)> handler,
                      const size_t timeoutMs = 10000)
 {
-    if (!name.empty())
-    {
-        name += ' ';
-    }
-
     socket->setReceiveTimeout(0);
 
     const Poco::Timespan waitTime(timeoutMs * 1000);
-    int flags;
-    int n;
+    int flags = 0;
+    int n = 0;
     char buffer[READ_BUFFER_SIZE];
     do
     {
         if (!socket->poll(waitTime, Poco::Net::Socket::SELECT_READ))
         {
-            std::cerr << "Timeout." << std::endl;
+            std::cerr << name << "Timeout." << std::endl;
             break;
         }
 
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 662b7b9..dc7f000 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -1027,7 +1027,7 @@ void HTTPWSTest::testEditLock()
             try
             {
                 std::cerr << "First client loading." << std::endl;
-                auto socket = loadDocAndGetSocket(_uri, documentURL, true);
+                auto socket = loadDocAndGetSocket(_uri, documentURL, "editLock-1 ", true);
                 std::string editlock1;
                 sendTextFrame(socket, "status");
                 SocketProcessor("First", socket, [&](const std::string& msg)
@@ -1088,9 +1088,9 @@ void HTTPWSTest::testEditLock()
     try
     {
         std::cerr << "Second client loading." << std::endl;
-        auto socket = loadDocAndGetSocket(_uri, documentURL);
+        auto socket = loadDocAndGetSocket(_uri, documentURL, "editLock-2 ", true);
         std::string editlock1;
-        SocketProcessor("Second", socket, [&](const std::string& msg)
+        SocketProcessor("Second ", socket, [&](const std::string& msg)
                 {
                     if (msg.find("editlock") == 0)
                     {
@@ -1189,12 +1189,12 @@ void HTTPWSTest::testInactiveClient()
         getDocumentPathAndURL("hello.odt", documentPath, documentURL);
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
 
-        auto socket1 = loadDocAndGetSocket(_uri, documentURL);
+        auto socket1 = loadDocAndGetSocket(_uri, documentURL, "inactiveClient-1 ");
         getResponseMessage(socket1, "invalidatetiles");
 
         // Connect another and go inactive.
         std::cerr << "Connecting second client." << std::endl;
-        auto socket2 = loadDocAndGetSocket(_uri, documentURL, true);
+        auto socket2 = loadDocAndGetSocket(_uri, documentURL, "inactiveClient-2 ", true);
         sendTextFrame(socket2, "userinactive");
 
         // While second is inactive, make some changes.
@@ -1203,7 +1203,7 @@ void HTTPWSTest::testInactiveClient()
 
         // Activate second.
         sendTextFrame(socket2, "useractive");
-        SocketProcessor("Second", socket2, [&](const std::string& msg)
+        SocketProcessor("Second ", socket2, [&](const std::string& msg)
                 {
                     const auto token = LOOLProtocol::getFirstToken(msg);
                     CPPUNIT_ASSERT_MESSAGE("unexpected message: " + msg,
@@ -1424,7 +1424,7 @@ void HTTPWSTest::testLimitCursor( std::function<void(const std::shared_ptr<Poco:
     getDocumentPathAndURL("setclientpart.ods", docPath, docURL);
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
 
-    auto socket = loadDocAndGetSocket(_uri, docURL);
+    auto socket = loadDocAndGetSocket(_uri, docURL, "limitCursor ");
     // check document size
     sendTextFrame(socket, "status");
     getResponseMessage(socket, "status:", response, false);


More information about the Libreoffice-commits mailing list