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

Henry Castro hcastro at collabora.com
Sat Sep 24 14:54:35 UTC 2016


 loolwsd/test/data/shape.ods |binary
 loolwsd/test/helpers.hpp    |   36 ++++++++++++++++++++++++++++++++++++
 loolwsd/test/httpwstest.cpp |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)

New commits:
commit 02793428c717613c92989aaebe73738e473bc528
Author: Henry Castro <hcastro at collabora.com>
Date:   Sat Sep 24 10:55:38 2016 -0400

    loolwsd: test: graphic invalidate tiles

diff --git a/loolwsd/test/data/shape.ods b/loolwsd/test/data/shape.ods
new file mode 100644
index 0000000..d2525f1
Binary files /dev/null and b/loolwsd/test/data/shape.ods differ
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index ddb571f..90cb973 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -238,6 +238,42 @@ void getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std
 }
 
 inline
+void collectMessages(Poco::Net::WebSocket& ws, const std::string& prefix, std::vector<std::string>& responses, int retries, const std::string& name = "")
+{
+    int flags = 0;
+    const Poco::Timespan waitTime(1000000);
+
+    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 = std::string(buffer, bytes);
+                if (message.find(prefix) == 0)
+                {
+                    responses.push_back(message);
+                }
+            }
+            else
+            {
+                std::cerr << name << "Got " << bytes << " bytes, flags: " << std::hex << flags << std::dec << '\n';
+            }
+        }
+        else
+        {
+            std::cerr << name << "Timeout waiting for " << prefix << std::endl;
+            --retries;
+        }
+    }
+    while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
+}
+
+inline
 std::vector<char> getResponseMessage(Poco::Net::WebSocket& ws, const std::string& prefix, std::string name = "", const size_t timeoutMs = 10000)
 {
     name = name + '[' + prefix + "] ";
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index e222e13..333a62f 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -93,6 +93,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testViewCursorVisible);
     CPPUNIT_TEST(testCellViewCursor);
     CPPUNIT_TEST(testGraphicViewSelection);
+    CPPUNIT_TEST(testGraphicInvalidate);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -134,6 +135,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     void testViewCursorVisible();
     void testCellViewCursor();
     void testGraphicViewSelection();
+    void testGraphicInvalidate();
 
     void loadDoc(const std::string& documentURL);
 
@@ -2110,6 +2112,46 @@ void HTTPWSTest::testGraphicViewSelection()
     }
 }
 
+void HTTPWSTest::testGraphicInvalidate()
+{
+    try
+    {
+        // Load a document.
+        std::string docPath;
+        std::string docURL;
+        std::string response;
+        std::vector<std::string> responses;
+
+        getDocumentPathAndURL("shape.ods", docPath, docURL);
+        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
+        Poco::Net::WebSocket socket = *connectLOKit(_uri, request, _response);
+
+        sendTextFrame(socket, "load url=" + docURL);
+        CPPUNIT_ASSERT_MESSAGE("cannot load the document " + docURL, isDocumentLoaded(socket));
+
+        // Send click message
+        sendTextFrame(socket, "mouse type=buttondown x=1035 y=400 count=1 buttons=1 modifier=0");
+        sendTextFrame(socket, "mouse type=buttonup x=1035 y=400 count=1 buttons=1 modifier=0");
+        getResponseMessage(socket, "graphicselection:", response, false, "testGraphicInvalidate ");
+
+        // Drag & drop graphic
+        sendTextFrame(socket, "mouse type=buttondown x=1035 y=400 count=1 buttons=1 modifier=0");
+        sendTextFrame(socket, "mouse type=move x=1035 y=450 count=1 buttons=1 modifier=0");
+        sendTextFrame(socket, "mouse type=buttonup x=1035 y=450 count=1 buttons=1 modifier=0");
+
+        collectMessages(socket, "invalidatetiles:", responses, 3, "testGraphicInvalidate ");
+        CPPUNIT_ASSERT_MESSAGE("No invalidatetiles: received", responses.size() > 0);
+        for (auto message : responses)
+        {
+            CPPUNIT_ASSERT_MESSAGE("Drag & Drop graphic invalidate all tiles", message.find("EMPTY") == std::string::npos);
+        }
+    }
+    catch (const Poco::Exception& exc)
+    {
+        CPPUNIT_FAIL(exc.displayText());
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSTest);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list