[Libreoffice-commits] online.git: common/UnitHTTP.cpp common/UnitHTTP.hpp test/Makefile.am test/UnitMinSocketBufferSize.cpp

Pranav Kant pranavk at collabora.co.uk
Fri Dec 16 10:25:32 UTC 2016


 common/UnitHTTP.cpp              |    4 +
 common/UnitHTTP.hpp              |    2 
 test/Makefile.am                 |    6 +-
 test/UnitMinSocketBufferSize.cpp |   84 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 2 deletions(-)

New commits:
commit 0e043853ea68e68354de5d9c87a32029319dfdc6
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Dec 16 13:16:31 2016 +0530

    tdf#104695: Unit test for missing tiles due to low socket buffer size
    
    Change-Id: I278c5d532cb9b6340dee71a4b66410b32a164704
    Reviewed-on: https://gerrit.libreoffice.org/32072
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/common/UnitHTTP.cpp b/common/UnitHTTP.cpp
index 6775695..29f5e40 100644
--- a/common/UnitHTTP.cpp
+++ b/common/UnitHTTP.cpp
@@ -33,3 +33,7 @@ UnitWebSocket::UnitWebSocket(const std::string &docURL)
     }
 }
 
+LOOLWebSocket* UnitWebSocket::getLOOLWebSocket() const
+{
+    return _socket;
+}
diff --git a/common/UnitHTTP.hpp b/common/UnitHTTP.hpp
index e70af89..ec3882a 100644
--- a/common/UnitHTTP.hpp
+++ b/common/UnitHTTP.hpp
@@ -130,6 +130,8 @@ public:
         delete _socket;
         delete _session;
     }
+
+    LOOLWebSocket* getLOOLWebSocket() const;
 };
 
 #endif
diff --git a/test/Makefile.am b/test/Makefile.am
index 2a285bc..68f8c81 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,7 +16,8 @@ noinst_LTLIBRARIES = \
         unit-timeout.la unit-prefork.la \
         unit-storage.la unit-fonts.la \
         unit-admin.la unit-tilecache.la \
-	unit-fuzz.la unit-oob.la
+	unit-fuzz.la unit-oob.la \
+	unit-minsocketbuffersize.la
 
 MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
 AM_LDFLAGS = -pthread -module $(MAGIC_TO_FORCE_SHLIB_CREATION)
@@ -59,6 +60,7 @@ unit_timeout_la_SOURCES = UnitTimeout.cpp
 unit_prefork_la_SOURCES = UnitPrefork.cpp
 unit_storage_la_SOURCES = UnitStorage.cpp
 unit_tilecache_la_SOURCES = UnitTileCache.cpp
+unit_minsocketbuffersize_la_SOURCES = UnitMinSocketBufferSize.cpp
 
 if HAVE_LO_PATH
 SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -70,7 +72,7 @@ if HAVE_LO_PATH
 check-local:
 	./run_unit.sh --log-file test.log --trs-file test.trs
 # FIXME unit-fonts.la is unstable, disabled for now.
-TESTS = unit-oob.la unit-tilecache.la unit-storage.la unit-timeout.la unit-prefork.la unit-admin.la
+TESTS = unit-oob.la unit-tilecache.la unit-storage.la unit-timeout.la unit-prefork.la unit-admin.la unit-minsocketbuffersize.la
 else
 TESTS = ${top_builddir}/test/test
 endif
diff --git a/test/UnitMinSocketBufferSize.cpp b/test/UnitMinSocketBufferSize.cpp
new file mode 100644
index 0000000..00e1dba
--- /dev/null
+++ b/test/UnitMinSocketBufferSize.cpp
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "Log.hpp"
+#include "Protocol.hpp"
+#include "Unit.hpp"
+#include "UnitHTTP.hpp"
+#include "helpers.hpp"
+
+using namespace helpers;
+
+class UnitMinSocketBufferSize: public UnitWSD
+{
+    enum {
+        PHASE_LOAD,             // load the document
+        PHASE_REQUEST,          // Request tiles etc.
+        PHASE_CHECK_RESPONSE    // Check if we got correct response
+    } _phase;
+    std::string _docURL, _docPath;
+    std::unique_ptr<UnitWebSocket> _ws;
+public:
+    UnitMinSocketBufferSize() :
+        _phase(PHASE_LOAD)
+    {
+    }
+
+    virtual void invokeTest()
+    {
+        switch (_phase)
+        {
+        case PHASE_LOAD:
+        {
+            getDocumentPathAndURL("Example.odt", _docPath, _docURL);
+            _ws = std::unique_ptr<UnitWebSocket>(new UnitWebSocket(_docURL));
+            assert(_ws.get());
+
+            _phase = PHASE_REQUEST;
+            LOG_DBG("Document loaded successfully.");
+            break;
+        }
+        case PHASE_REQUEST:
+        {
+            const std::string loadMsg = "load url=" + _docURL;
+            const std::string tilecombineMsg = "tilecombine part=0 width=256 height=256 tileposx=0,3840,7680,11520,0,3840,7680,11520,0,3840,7680,11520,0,3840,7680,11520,0,3840,7680,11520 tileposy=0,0,0,0,3840,3840,3840,3840,7680,7680,7680,7680,11520,11520,11520,11520,15360,15360,15360,15360 tilewidth=3840 tileheight=3840";
+            _ws->getLOOLWebSocket()->sendFrame(loadMsg.data(), loadMsg.size());
+            _ws->getLOOLWebSocket()->sendFrame(tilecombineMsg.data(), tilecombineMsg.size());
+
+            LOG_DBG("Tilecombine request sent");
+            _phase = PHASE_CHECK_RESPONSE;
+            break;
+        }
+        case PHASE_CHECK_RESPONSE:
+            LOG_DBG("Checking if get back all the tiles");
+            int nTiles = 20;
+            bool success = true;
+            while (nTiles--)
+            {
+                const auto tile = getResponseMessage(*_ws->getLOOLWebSocket(), "tile: part=0 width=256 height=256", "Waiting for tiles ...");
+                const auto firstLine = LOOLProtocol::getFirstLine(tile);
+                LOG_DBG("Tile received " << firstLine);
+                if (!LOOLProtocol::matchPrefix("tile:", firstLine))
+                {
+                    success = false;
+                }
+            }
+
+            exitTest(success ? TestResult::TEST_OK : TestResult::TEST_FAILED);
+            break;
+        }
+    }
+};
+
+UnitBase *unit_create_wsd(void)
+{
+    return new UnitMinSocketBufferSize();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list