[Libreoffice-commits] online.git: 2 commits - loolwsd/MessageQueue.hpp loolwsd/test
Jan Holesovsky
kendy at collabora.com
Thu Sep 29 18:37:54 UTC 2016
loolwsd/MessageQueue.hpp | 2
loolwsd/test/Makefile.am | 2
loolwsd/test/TileCacheTests.cpp | 83 ---------------------
loolwsd/test/TileQueueTests.cpp | 154 ++++++++++++++++++++++++++++++++++++++++
loolwsd/test/WhiteBoxTests.cpp | 13 ---
5 files changed, 156 insertions(+), 98 deletions(-)
New commits:
commit c8a97eb3003119ab2d75e4b776a7c51f883f990d
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Sep 29 20:32:25 2016 +0200
Move testTileQueue from WhiteBoxTests to TileQueueTests.
Change-Id: Ib592c425d595e1d3449092bd0b9008c1b857274a
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 3cf21f6..284f847 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -21,7 +21,7 @@
*/
class MessageQueue
{
- friend class WhiteBoxTests;
+ friend class TileQueueTests;
public:
diff --git a/loolwsd/test/TileQueueTests.cpp b/loolwsd/test/TileQueueTests.cpp
index aa9f0b9..49a45c2 100644
--- a/loolwsd/test/TileQueueTests.cpp
+++ b/loolwsd/test/TileQueueTests.cpp
@@ -41,11 +41,13 @@ class TileQueueTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testTileQueuePriority);
CPPUNIT_TEST(testTileCombinedRendering);
+ CPPUNIT_TEST(testTileRecombining);
CPPUNIT_TEST_SUITE_END();
void testTileQueuePriority();
void testTileCombinedRendering();
+ void testTileRecombining();
};
void TileQueueTests::testTileQueuePriority()
@@ -127,6 +129,26 @@ void TileQueueTests::testTileCombinedRendering()
CPPUNIT_ASSERT_EQUAL(payloadFull, queue.get());
}
+void TileQueueTests::testTileRecombining()
+{
+ TileQueue queue;
+
+ queue.put("tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840");
+ queue.put("tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840");
+
+ // the tilecombine's get merged, resulting in 3 "tile" messages
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(queue._queue.size()));
+
+ // but when we later extract that, it is just one "tilecombine" message
+ MessageQueue::Payload payload(queue.get());
+ std::string message(payload.data(), payload.size());
+
+ CPPUNIT_ASSERT_EQUAL(std::string("tilecombine part=0 width=256 height=256 tileposx=7680,0,3840 tileposy=0,0,0 imgsize=0,0,0 tilewidth=3840 tileheight=3840"), message);
+
+ // and nothing remains in the queue
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue._queue.size()));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(TileQueueTests);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/WhiteBoxTests.cpp b/loolwsd/test/WhiteBoxTests.cpp
index a05460e..3e43437 100644
--- a/loolwsd/test/WhiteBoxTests.cpp
+++ b/loolwsd/test/WhiteBoxTests.cpp
@@ -24,14 +24,12 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testLOOLProtocolFunctions);
CPPUNIT_TEST(testRegexListMatcher);
CPPUNIT_TEST(testRegexListMatcher_Init);
- CPPUNIT_TEST(testTileQueue);
CPPUNIT_TEST_SUITE_END();
void testLOOLProtocolFunctions();
void testRegexListMatcher();
void testRegexListMatcher_Init();
- void testTileQueue();
};
void WhiteBoxTests::testLOOLProtocolFunctions()
@@ -147,17 +145,6 @@ void WhiteBoxTests::testRegexListMatcher_Init()
CPPUNIT_ASSERT(matcher.match("192.168.."));
}
-void WhiteBoxTests::testTileQueue()
-{
- std::unique_ptr<TileQueue> queue(new TileQueue());
-
- queue->put("tilecombine part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840");
- queue->put("tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840");
-
- // the tilecombine's get merged, resulting in 3 "tile" messages
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(queue->_queue.size()));
-}
-
CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit ae179b8bce6d3f79f00643d69c3e6ddd86213e27
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Sep 29 20:04:05 2016 +0200
Move the TileQueue tests that do not require loolwsd to a separate file.
Change-Id: Iaac51e891a5c34cebc95d7631c95c84ed8aad80e
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index b277644..cf255d9 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -33,7 +33,7 @@ wsd_sources = \
../Util.cpp
test_CPPFLAGS = -DTDOC=\"$(abs_top_srcdir)/test/data\" -I$(top_srcdir) -DBUILDING_TESTS
-test_SOURCES = TileCacheTests.cpp WhiteBoxTests.cpp integration-http-server.cpp \
+test_SOURCES = TileCacheTests.cpp TileQueueTests.cpp WhiteBoxTests.cpp integration-http-server.cpp \
httpwstest.cpp httpcrashtest.cpp httpwserror.cpp test.cpp $(wsd_sources)
test_LDADD = $(CPPUNIT_LIBS)
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index f2d7f3d..c469395 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -64,8 +64,6 @@ class TileCacheTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testLoad12ods);
CPPUNIT_TEST(testTileInvalidateWriter);
//CPPUNIT_TEST(testTileInvalidateCalc);
- CPPUNIT_TEST(testTileQueuePriority);
- CPPUNIT_TEST(testTileCombinedRendering);
CPPUNIT_TEST_SUITE_END();
@@ -83,8 +81,6 @@ class TileCacheTests : public CPPUNIT_NS::TestFixture
void testTileInvalidateWriter();
void testWriterAnyKey();
void testTileInvalidateCalc();
- void testTileQueuePriority();
- void testTileCombinedRendering();
void checkTiles(Poco::Net::WebSocket& socket,
const std::string& type,
@@ -653,85 +649,6 @@ void TileCacheTests::testTileInvalidateCalc()
socket.shutdown();
}
-void TileCacheTests::testTileQueuePriority()
-{
- const std::string reqHigh = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840";
- const std::string resHigh = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 ver=-1";
- const TileQueue::Payload payloadHigh(resHigh.data(), resHigh.data() + resHigh.size());
- const std::string reqLow = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840";
- const std::string resLow = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 ver=-1";
- const TileQueue::Payload payloadLow(resLow.data(), resLow.data() + resLow.size());
-
- TileQueue queue;
-
- // Request the tiles.
- queue.put(reqLow);
- queue.put(reqHigh);
-
- // Original order.
- CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
- CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
-
- // Request the tiles.
- queue.put(reqLow);
- queue.put(reqHigh);
- queue.put(reqHigh);
- queue.put(reqLow);
-
- // Set cursor above reqHigh.
- queue.updateCursorPosition(0, 0, 0, 0, 10, 100);
-
- // Prioritized order.
- CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
- CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
-
- // Repeat with cursor position set.
- queue.put(reqLow);
- queue.put(reqHigh);
- CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
- CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
-
- // Repeat by changing cursor position.
- queue.put(reqLow);
- queue.put(reqHigh);
- queue.updateCursorPosition(0, 0, 0, 253450, 10, 100);
- CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
- CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
-}
-
-void TileCacheTests::testTileCombinedRendering()
-{
- const std::string req1 = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840";
- const std::string req2 = "tile part=0 width=256 height=256 tileposx=3840 tileposy=0 tilewidth=3840 tileheight=3840";
- const std::string req3 = "tile part=0 width=256 height=256 tileposx=0 tileposy=3840 tilewidth=3840 tileheight=3840";
- const std::string req4 = "tile part=0 width=256 height=256 tileposx=3840 tileposy=3840 tilewidth=3840 tileheight=3840";
-
- const std::string resHor = "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 imgsize=0,0 tilewidth=3840 tileheight=3840";
- const TileQueue::Payload payloadHor(resHor.data(), resHor.data() + resHor.size());
- const std::string resVer = "tilecombine part=0 width=256 height=256 tileposx=0,0 tileposy=0,3840 imgsize=0,0 tilewidth=3840 tileheight=3840";
- const TileQueue::Payload payloadVer(resVer.data(), resVer.data() + resVer.size());
- const std::string resFull = "tilecombine part=0 width=256 height=256 tileposx=0,3840,0 tileposy=0,0,3840 imgsize=0,0,0 tilewidth=3840 tileheight=3840";
- const TileQueue::Payload payloadFull(resFull.data(), resFull.data() + resFull.size());
-
- TileQueue queue;
-
- // Horizontal.
- queue.put(req1);
- queue.put(req2);
- CPPUNIT_ASSERT_EQUAL(payloadHor, queue.get());
-
- // Vertical.
- queue.put(req1);
- queue.put(req3);
- CPPUNIT_ASSERT_EQUAL(payloadVer, queue.get());
-
- // Vertical.
- queue.put(req1);
- queue.put(req2);
- queue.put(req3);
- CPPUNIT_ASSERT_EQUAL(payloadFull, queue.get());
-}
-
void TileCacheTests::checkTiles(Poco::Net::WebSocket& socket, const std::string& docType, const std::string& name)
{
const std::string current = "current=";
diff --git a/loolwsd/test/TileQueueTests.cpp b/loolwsd/test/TileQueueTests.cpp
new file mode 100644
index 0000000..aa9f0b9
--- /dev/null
+++ b/loolwsd/test/TileQueueTests.cpp
@@ -0,0 +1,132 @@
+/* -*- 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 "config.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "Common.hpp"
+#include "LOOLProtocol.hpp"
+#include "MessageQueue.hpp"
+#include "Util.hpp"
+
+namespace CPPUNIT_NS
+{
+template<>
+struct assertion_traits<std::vector<char>>
+{
+ static bool equal(const std::vector<char>& x, const std::vector<char>& y)
+ {
+ return x == y;
+ }
+
+ static std::string toString(const std::vector<char>& x)
+ {
+ const std::string text = '"' + (!x.empty() ? std::string(x.data(), x.size()) : "<empty>") + '"';
+ return text;
+ }
+};
+}
+
+/// TileQueue unit-tests.
+class TileQueueTests : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE(TileQueueTests);
+
+ CPPUNIT_TEST(testTileQueuePriority);
+ CPPUNIT_TEST(testTileCombinedRendering);
+
+ CPPUNIT_TEST_SUITE_END();
+
+ void testTileQueuePriority();
+ void testTileCombinedRendering();
+};
+
+void TileQueueTests::testTileQueuePriority()
+{
+ const std::string reqHigh = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840";
+ const std::string resHigh = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 ver=-1";
+ const TileQueue::Payload payloadHigh(resHigh.data(), resHigh.data() + resHigh.size());
+ const std::string reqLow = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840";
+ const std::string resLow = "tile part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 ver=-1";
+ const TileQueue::Payload payloadLow(resLow.data(), resLow.data() + resLow.size());
+
+ TileQueue queue;
+
+ // Request the tiles.
+ queue.put(reqLow);
+ queue.put(reqHigh);
+
+ // Original order.
+ CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
+ CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
+
+ // Request the tiles.
+ queue.put(reqLow);
+ queue.put(reqHigh);
+ queue.put(reqHigh);
+ queue.put(reqLow);
+
+ // Set cursor above reqHigh.
+ queue.updateCursorPosition(0, 0, 0, 0, 10, 100);
+
+ // Prioritized order.
+ CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
+ CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
+
+ // Repeat with cursor position set.
+ queue.put(reqLow);
+ queue.put(reqHigh);
+ CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
+ CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
+
+ // Repeat by changing cursor position.
+ queue.put(reqLow);
+ queue.put(reqHigh);
+ queue.updateCursorPosition(0, 0, 0, 253450, 10, 100);
+ CPPUNIT_ASSERT_EQUAL(payloadLow, queue.get());
+ CPPUNIT_ASSERT_EQUAL(payloadHigh, queue.get());
+}
+
+void TileQueueTests::testTileCombinedRendering()
+{
+ const std::string req1 = "tile part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840";
+ const std::string req2 = "tile part=0 width=256 height=256 tileposx=3840 tileposy=0 tilewidth=3840 tileheight=3840";
+ const std::string req3 = "tile part=0 width=256 height=256 tileposx=0 tileposy=3840 tilewidth=3840 tileheight=3840";
+ const std::string req4 = "tile part=0 width=256 height=256 tileposx=3840 tileposy=3840 tilewidth=3840 tileheight=3840";
+
+ const std::string resHor = "tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 imgsize=0,0 tilewidth=3840 tileheight=3840";
+ const TileQueue::Payload payloadHor(resHor.data(), resHor.data() + resHor.size());
+ const std::string resVer = "tilecombine part=0 width=256 height=256 tileposx=0,0 tileposy=0,3840 imgsize=0,0 tilewidth=3840 tileheight=3840";
+ const TileQueue::Payload payloadVer(resVer.data(), resVer.data() + resVer.size());
+ const std::string resFull = "tilecombine part=0 width=256 height=256 tileposx=0,3840,0 tileposy=0,0,3840 imgsize=0,0,0 tilewidth=3840 tileheight=3840";
+ const TileQueue::Payload payloadFull(resFull.data(), resFull.data() + resFull.size());
+
+ TileQueue queue;
+
+ // Horizontal.
+ queue.put(req1);
+ queue.put(req2);
+ CPPUNIT_ASSERT_EQUAL(payloadHor, queue.get());
+
+ // Vertical.
+ queue.put(req1);
+ queue.put(req3);
+ CPPUNIT_ASSERT_EQUAL(payloadVer, queue.get());
+
+ // Vertical.
+ queue.put(req1);
+ queue.put(req2);
+ queue.put(req3);
+ CPPUNIT_ASSERT_EQUAL(payloadFull, queue.get());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TileQueueTests);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list