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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Apr 18 03:38:12 UTC 2016


 loolwsd/test/httpwstest.cpp |   85 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

New commits:
commit 385359824a1f4f37d61a9af637df768e7e55f531
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 17 23:31:17 2016 -0400

    loolwsd: unittest to validate correct doc reloading while unloading
    
    Change-Id: Id956fc9e243c44ecd3914b448ab92f87e011d3ee
    Reviewed-on: https://gerrit.libreoffice.org/24185
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 38e7f16..101824e 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -57,6 +57,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testBadLoad);
     CPPUNIT_TEST(testReload);
     CPPUNIT_TEST(testSaveOnDisconnect);
+    CPPUNIT_TEST(testReloadWhileDisconnecting);
     CPPUNIT_TEST(testExcelLoad);
     CPPUNIT_TEST(testPaste);
     CPPUNIT_TEST(testLargePaste);
@@ -79,6 +80,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     void testBadLoad();
     void testReload();
     void testSaveOnDisconnect();
+    void testReloadWhileDisconnecting();
     void testExcelLoad();
     void testPaste();
     void testLargePaste();
@@ -454,6 +456,89 @@ void HTTPWSTest::testSaveOnDisconnect()
     }
 }
 
+void HTTPWSTest::testReloadWhileDisconnecting()
+{
+    const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
+    const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+
+    int kitcount = -1;
+    try
+    {
+        // Load a document and get its status.
+        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+        Poco::Net::WebSocket socket = *connectLOKit(request, _response);
+
+        sendTextFrame(socket, "load url=" + documentURL);
+        CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
+
+        sendTextFrame(socket, "uno .uno:SelectAll");
+        sendTextFrame(socket, "uno .uno:Delete");
+        sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc");
+
+        kitcount = countLoolKitProcesses();
+
+        // Shutdown abruptly.
+        socket.shutdown();
+    }
+    catch (const Poco::Exception& exc)
+    {
+        CPPUNIT_FAIL(exc.displayText());
+    }
+
+    std::cout << "Loading again." << std::endl;
+    try
+    {
+        // Load the same document and check that the last changes (pasted text) is saved.
+        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+        Poco::Net::WebSocket socket = *connectLOKit(request, _response);
+
+        sendTextFrame(socket, "load url=" + documentURL);
+        sendTextFrame(socket, "status");
+        CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
+
+        // Should have no new instances.
+        CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses());
+
+        // Check if the document contains the pasted text.
+        sendTextFrame(socket, "uno .uno:SelectAll");
+        sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8");
+        std::string selection;
+        int flags;
+        int n;
+        do
+        {
+            char buffer[READ_BUFFER_SIZE];
+            n = socket.receiveFrame(buffer, sizeof(buffer), flags);
+            std::cout << "Got " << n << " bytes, flags: " << std::hex << flags << std::dec << '\n';
+            if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+            {
+                std::cout << "Received message: " << LOOLProtocol::getAbbreviatedMessage(buffer, n) << '\n';
+                const std::string line = LOOLProtocol::getFirstLine(buffer, n);
+                if (line.find("editlock: ") == 0)
+                {
+                    // We must have the editlock, otherwise we aren't alone.
+                    CPPUNIT_ASSERT_EQUAL(std::string("editlock: 1"), line);
+                }
+
+                const std::string prefix = "textselectioncontent: ";
+                if (line.find(prefix) == 0)
+                {
+                    selection = line.substr(prefix.length());
+                    break;
+                }
+            }
+        }
+        while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
+        socket.shutdown();
+        Util::removeFile(documentPath);
+        CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection);
+    }
+    catch (const Poco::Exception& exc)
+    {
+        CPPUNIT_FAIL(exc.displayText());
+    }
+}
+
 void HTTPWSTest::testExcelLoad()
 {
     try


More information about the Libreoffice-commits mailing list