2016-09-29 13:04:05 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2016-09-29 13:04:05 -05:00
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
#include <test/lokassert.hpp>
|
2016-09-29 13:04:05 -05:00
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <Common.hpp>
|
|
|
|
#include <Protocol.hpp>
|
|
|
|
#include <Message.hpp>
|
|
|
|
#include <MessageQueue.hpp>
|
|
|
|
#include <SenderQueue.hpp>
|
|
|
|
#include <Util.hpp>
|
2016-09-29 13:04:05 -05:00
|
|
|
|
|
|
|
/// TileQueue unit-tests.
|
|
|
|
class TileQueueTests : public CPPUNIT_NS::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE(TileQueueTests);
|
|
|
|
|
|
|
|
CPPUNIT_TEST(testTileQueuePriority);
|
|
|
|
CPPUNIT_TEST(testTileCombinedRendering);
|
2016-09-29 13:32:25 -05:00
|
|
|
CPPUNIT_TEST(testTileRecombining);
|
2016-09-30 15:02:22 -05:00
|
|
|
CPPUNIT_TEST(testViewOrder);
|
2016-10-04 07:23:42 -05:00
|
|
|
CPPUNIT_TEST(testPreviewsDeprioritization);
|
2016-12-18 11:04:18 -06:00
|
|
|
CPPUNIT_TEST(testSenderQueue);
|
|
|
|
CPPUNIT_TEST(testSenderQueueTileDeduplication);
|
2016-12-18 16:28:35 -06:00
|
|
|
CPPUNIT_TEST(testInvalidateViewCursorDeduplication);
|
2020-09-21 10:41:20 -05:00
|
|
|
CPPUNIT_TEST(testCallbackModifiedStatusIsSkipped);
|
2017-01-25 11:21:56 -06:00
|
|
|
CPPUNIT_TEST(testCallbackInvalidation);
|
2017-04-07 05:29:01 -05:00
|
|
|
CPPUNIT_TEST(testCallbackIndicatorValue);
|
|
|
|
CPPUNIT_TEST(testCallbackPageSize);
|
2016-09-29 13:04:05 -05:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void testTileQueuePriority();
|
|
|
|
void testTileCombinedRendering();
|
2016-09-29 13:32:25 -05:00
|
|
|
void testTileRecombining();
|
2016-09-30 15:02:22 -05:00
|
|
|
void testViewOrder();
|
2016-10-04 07:23:42 -05:00
|
|
|
void testPreviewsDeprioritization();
|
2016-12-18 11:04:18 -06:00
|
|
|
void testSenderQueue();
|
|
|
|
void testSenderQueueTileDeduplication();
|
2016-12-18 16:28:35 -06:00
|
|
|
void testInvalidateViewCursorDeduplication();
|
2020-09-21 10:41:20 -05:00
|
|
|
void testCallbackModifiedStatusIsSkipped();
|
2017-01-25 11:21:56 -06:00
|
|
|
void testCallbackInvalidation();
|
2017-04-07 05:29:01 -05:00
|
|
|
void testCallbackIndicatorValue();
|
|
|
|
void testCallbackPageSize();
|
2016-09-29 13:04:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
void TileQueueTests::testTileQueuePriority()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2019-10-15 08:41:33 -05:00
|
|
|
const std::string reqHigh = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0";
|
|
|
|
const std::string resHigh = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1";
|
2016-09-29 13:04:05 -05:00
|
|
|
const TileQueue::Payload payloadHigh(resHigh.data(), resHigh.data() + resHigh.size());
|
2019-10-15 08:41:33 -05:00
|
|
|
const std::string reqLow = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 oldwid=0 wid=0";
|
|
|
|
const std::string resLow = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=253440 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1";
|
2016-09-29 13:04:05 -05:00
|
|
|
const TileQueue::Payload payloadLow(resLow.data(), resLow.data() + resLow.size());
|
|
|
|
|
|
|
|
TileQueue queue;
|
|
|
|
|
|
|
|
// Request the tiles.
|
|
|
|
queue.put(reqLow);
|
|
|
|
queue.put(reqHigh);
|
|
|
|
|
|
|
|
// Original order.
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadLow, queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(payloadHigh, queue.get());
|
2016-09-29 13:04:05 -05:00
|
|
|
|
|
|
|
// 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.
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadHigh, queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(payloadLow, queue.get());
|
2016-09-29 13:04:05 -05:00
|
|
|
|
|
|
|
// Repeat with cursor position set.
|
|
|
|
queue.put(reqLow);
|
|
|
|
queue.put(reqHigh);
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadHigh, queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(payloadLow, queue.get());
|
2016-09-29 13:04:05 -05:00
|
|
|
|
|
|
|
// Repeat by changing cursor position.
|
|
|
|
queue.put(reqLow);
|
|
|
|
queue.put(reqHigh);
|
|
|
|
queue.updateCursorPosition(0, 0, 0, 253450, 10, 100);
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadLow, queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(payloadHigh, queue.get());
|
2016-09-29 13:04:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileQueueTests::testTileCombinedRendering()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2019-10-15 08:41:33 -05:00
|
|
|
const std::string req1 = "tile nviewid=0 nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840";
|
|
|
|
const std::string req2 = "tile nviewid=0 part=0 width=256 height=256 tileposx=3840 tileposy=0 tilewidth=3840 tileheight=3840";
|
|
|
|
const std::string req3 = "tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=3840 tilewidth=3840 tileheight=3840";
|
2016-09-29 13:04:05 -05:00
|
|
|
|
2019-10-15 08:41:33 -05:00
|
|
|
const std::string resHor = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 imgsize=0,0 tilewidth=3840 tileheight=3840 ver=-1,-1 oldwid=0,0 wid=0,0";
|
2016-09-29 13:04:05 -05:00
|
|
|
const TileQueue::Payload payloadHor(resHor.data(), resHor.data() + resHor.size());
|
2019-10-15 08:41:33 -05:00
|
|
|
const std::string resVer = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,0 tileposy=0,3840 imgsize=0,0 tilewidth=3840 tileheight=3840 ver=-1,-1 oldwid=0,0 wid=0,0";
|
2016-11-28 20:44:09 -06:00
|
|
|
const TileQueue::Payload payloadVer(resVer.data(), resVer.data() + resVer.size());
|
2019-10-15 08:41:33 -05:00
|
|
|
const std::string resFull = "tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,0 tileposy=0,0,3840 imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0";
|
2016-09-29 13:04:05 -05:00
|
|
|
const TileQueue::Payload payloadFull(resFull.data(), resFull.data() + resFull.size());
|
|
|
|
|
|
|
|
TileQueue queue;
|
|
|
|
|
2016-11-28 20:44:09 -06:00
|
|
|
// Horizontal.
|
2016-09-29 13:04:05 -05:00
|
|
|
queue.put(req1);
|
|
|
|
queue.put(req2);
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadHor, queue.get());
|
2016-09-29 13:04:05 -05:00
|
|
|
|
2016-11-28 20:44:09 -06:00
|
|
|
// Vertical.
|
2016-09-29 13:04:05 -05:00
|
|
|
queue.put(req1);
|
|
|
|
queue.put(req3);
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadVer, queue.get());
|
2016-09-29 13:04:05 -05:00
|
|
|
|
2016-11-28 20:44:09 -06:00
|
|
|
// Vertical.
|
2016-09-29 13:04:05 -05:00
|
|
|
queue.put(req1);
|
|
|
|
queue.put(req2);
|
|
|
|
queue.put(req3);
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(payloadFull, queue.get());
|
2016-10-04 07:23:42 -05:00
|
|
|
}
|
|
|
|
|
2016-09-29 13:32:25 -05:00
|
|
|
void TileQueueTests::testTileRecombining()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2016-09-29 13:32:25 -05:00
|
|
|
TileQueue queue;
|
|
|
|
|
2019-10-15 08:41:33 -05:00
|
|
|
queue.put("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840,7680 tileposy=0,0,0 tilewidth=3840 tileheight=3840");
|
|
|
|
queue.put("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840");
|
2016-09-29 13:32:25 -05:00
|
|
|
|
|
|
|
// the tilecombine's get merged, resulting in 3 "tile" messages
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(3, static_cast<int>(queue.getQueue().size()));
|
2016-09-29 13:32:25 -05:00
|
|
|
|
|
|
|
// but when we later extract that, it is just one "tilecombine" message
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(
|
|
|
|
"tilecombine nviewid=0 part=0 width=256 height=256 tileposx=7680,0,3840 tileposy=0,0,0 "
|
|
|
|
"imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0",
|
|
|
|
queue.get());
|
2016-09-29 13:32:25 -05:00
|
|
|
|
|
|
|
// and nothing remains in the queue
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
|
2016-09-29 13:32:25 -05:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:02:22 -05:00
|
|
|
void TileQueueTests::testViewOrder()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2016-09-30 15:02:22 -05:00
|
|
|
TileQueue queue;
|
|
|
|
|
|
|
|
// should result in the 3, 2, 1, 0 order of the views
|
|
|
|
queue.updateCursorPosition(0, 0, 0, 0, 10, 100);
|
|
|
|
queue.updateCursorPosition(2, 0, 0, 0, 10, 100);
|
|
|
|
queue.updateCursorPosition(1, 0, 0, 7680, 10, 100);
|
|
|
|
queue.updateCursorPosition(3, 0, 0, 0, 10, 100);
|
|
|
|
queue.updateCursorPosition(2, 0, 0, 15360, 10, 100);
|
|
|
|
queue.updateCursorPosition(3, 0, 0, 23040, 10, 100);
|
|
|
|
|
|
|
|
const std::vector<std::string> tiles =
|
|
|
|
{
|
2019-10-15 08:41:33 -05:00
|
|
|
"tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1",
|
|
|
|
"tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1",
|
|
|
|
"tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=15360 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1",
|
|
|
|
"tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=23040 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1"
|
2016-09-30 15:02:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto &tile : tiles)
|
|
|
|
queue.put(tile);
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(4, static_cast<int>(queue.getQueue().size()));
|
2016-09-30 15:02:22 -05:00
|
|
|
|
|
|
|
// should result in the 3, 2, 1, 0 order of the tiles thanks to the cursor
|
|
|
|
// positions
|
|
|
|
for (size_t i = 0; i < tiles.size(); ++i)
|
|
|
|
{
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(tiles[3 - i], queue.get());
|
2016-10-04 07:23:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileQueueTests::testPreviewsDeprioritization()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2016-10-04 07:23:42 -05:00
|
|
|
TileQueue queue;
|
|
|
|
|
|
|
|
// simple case - put previews to the queue and get everything back again
|
|
|
|
const std::vector<std::string> previews =
|
|
|
|
{
|
2019-10-15 08:41:33 -05:00
|
|
|
"tile nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=0",
|
|
|
|
"tile nviewid=0 part=1 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=1",
|
|
|
|
"tile nviewid=0 part=2 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=2",
|
|
|
|
"tile nviewid=0 part=3 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1 id=3"
|
2016-10-04 07:23:42 -05:00
|
|
|
};
|
2016-09-30 15:02:22 -05:00
|
|
|
|
2016-10-04 07:23:42 -05:00
|
|
|
for (auto &preview : previews)
|
|
|
|
queue.put(preview);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < previews.size(); ++i)
|
|
|
|
{
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(previews[i], queue.get());
|
2016-09-30 15:02:22 -05:00
|
|
|
}
|
|
|
|
|
2016-10-04 07:23:42 -05:00
|
|
|
// stays empty after all is done
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
|
2016-10-04 07:23:42 -05:00
|
|
|
|
|
|
|
// re-ordering case - put previews and normal tiles to the queue and get
|
|
|
|
// everything back again but this time the tiles have to interleave with
|
|
|
|
// the previews
|
|
|
|
const std::vector<std::string> tiles =
|
|
|
|
{
|
2019-10-15 08:41:33 -05:00
|
|
|
"tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=0 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1",
|
|
|
|
"tile nviewid=0 part=0 width=256 height=256 tileposx=0 tileposy=7680 tilewidth=3840 tileheight=3840 oldwid=0 wid=0 ver=-1"
|
2016-10-04 07:23:42 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto &preview : previews)
|
|
|
|
queue.put(preview);
|
|
|
|
|
|
|
|
queue.put(tiles[0]);
|
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(previews[0], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(tiles[0], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(previews[1], queue.get());
|
2016-10-04 07:23:42 -05:00
|
|
|
|
|
|
|
queue.put(tiles[1]);
|
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(previews[2], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(tiles[1], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(previews[3], queue.get());
|
2016-10-04 07:23:42 -05:00
|
|
|
|
|
|
|
// stays empty after all is done
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
|
2016-10-04 07:23:42 -05:00
|
|
|
|
|
|
|
// cursor positioning case - the cursor position should not prioritize the
|
|
|
|
// previews
|
|
|
|
queue.updateCursorPosition(0, 0, 0, 0, 10, 100);
|
|
|
|
|
|
|
|
queue.put(tiles[1]);
|
|
|
|
queue.put(previews[0]);
|
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(tiles[1], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(previews[0], queue.get());
|
2016-10-04 07:23:42 -05:00
|
|
|
|
|
|
|
// stays empty after all is done
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
|
2016-09-30 15:02:22 -05:00
|
|
|
}
|
|
|
|
|
2016-12-18 11:04:18 -06:00
|
|
|
void TileQueueTests::testSenderQueue()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2017-01-21 18:51:02 -06:00
|
|
|
SenderQueue<std::shared_ptr<Message>> queue;
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2017-01-21 18:51:02 -06:00
|
|
|
std::shared_ptr<Message> item;
|
2016-12-18 11:04:18 -06:00
|
|
|
|
|
|
|
// Empty queue
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(false, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 11:04:18 -06:00
|
|
|
|
|
|
|
const std::vector<std::string> messages =
|
|
|
|
{
|
|
|
|
"message 1",
|
|
|
|
"message 2",
|
|
|
|
"message 3"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& msg : messages)
|
|
|
|
{
|
2017-01-21 18:51:02 -06:00
|
|
|
queue.enqueue(std::make_shared<Message>(msg, Message::Dir::Out));
|
2016-12-18 11:04:18 -06:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(3), queue.size());
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(2), queue.size());
|
|
|
|
LOK_ASSERT_EQUAL(messages[0], std::string(item->data().data(), item->data().size()));
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
|
|
|
|
LOK_ASSERT_EQUAL(messages[1], std::string(item->data().data(), item->data().size()));
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
|
|
|
LOK_ASSERT_EQUAL(messages[2], std::string(item->data().data(), item->data().size()));
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 11:04:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileQueueTests::testSenderQueueTileDeduplication()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2017-01-21 18:51:02 -06:00
|
|
|
SenderQueue<std::shared_ptr<Message>> queue;
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2017-01-21 18:51:02 -06:00
|
|
|
std::shared_ptr<Message> item;
|
2016-12-18 11:04:18 -06:00
|
|
|
|
|
|
|
// Empty queue
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(false, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 11:04:18 -06:00
|
|
|
|
|
|
|
const std::vector<std::string> part_messages =
|
|
|
|
{
|
2019-10-15 08:41:33 -05:00
|
|
|
"tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=0",
|
|
|
|
"tile: nviewid=0 part=1 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1",
|
|
|
|
"tile: nviewid=0 part=2 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1"
|
2016-12-18 11:04:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& msg : part_messages)
|
|
|
|
{
|
2017-01-21 18:51:02 -06:00
|
|
|
queue.enqueue(std::make_shared<Message>(msg, Message::Dir::Out));
|
2016-12-18 11:04:18 -06:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(3), queue.size());
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 11:04:18 -06:00
|
|
|
|
|
|
|
const std::vector<std::string> dup_messages =
|
|
|
|
{
|
2019-10-15 08:41:33 -05:00
|
|
|
"tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=-1",
|
|
|
|
"tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1",
|
|
|
|
"tile: nviewid=0 part=0 width=180 height=135 tileposx=0 tileposy=0 tilewidth=15875 tileheight=11906 ver=1"
|
2016-12-18 11:04:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& msg : dup_messages)
|
|
|
|
{
|
2017-01-21 18:51:02 -06:00
|
|
|
queue.enqueue(std::make_shared<Message>(msg, Message::Dir::Out));
|
2016-12-18 11:04:18 -06:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2016-12-18 11:04:18 -06:00
|
|
|
|
|
|
|
// The last one should persist.
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(dup_messages[2], std::string(item->data().data(), item->data().size()));
|
2016-12-18 11:04:18 -06:00
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 11:04:18 -06:00
|
|
|
}
|
|
|
|
|
2016-12-18 16:28:35 -06:00
|
|
|
void TileQueueTests::testInvalidateViewCursorDeduplication()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2017-01-21 18:51:02 -06:00
|
|
|
SenderQueue<std::shared_ptr<Message>> queue;
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2017-01-21 18:51:02 -06:00
|
|
|
std::shared_ptr<Message> item;
|
2016-12-18 16:28:35 -06:00
|
|
|
|
|
|
|
// Empty queue
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(false, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 16:28:35 -06:00
|
|
|
|
|
|
|
const std::vector<std::string> view_messages =
|
|
|
|
{
|
|
|
|
"invalidateviewcursor: { \"viewId\": \"1\", \"rectangle\": \"3999, 1418, 0, 298\", \"part\": \"0\" }",
|
|
|
|
"invalidateviewcursor: { \"viewId\": \"2\", \"rectangle\": \"3999, 1418, 0, 298\", \"part\": \"0\" }",
|
|
|
|
"invalidateviewcursor: { \"viewId\": \"3\", \"rectangle\": \"3999, 1418, 0, 298\", \"part\": \"0\" }",
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& msg : view_messages)
|
|
|
|
{
|
2017-01-21 18:51:02 -06:00
|
|
|
queue.enqueue(std::make_shared<Message>(msg, Message::Dir::Out));
|
2016-12-18 16:28:35 -06:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(3), queue.size());
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(2), queue.size());
|
|
|
|
LOK_ASSERT_EQUAL(view_messages[0], std::string(item->data().data(), item->data().size()));
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
|
|
|
|
LOK_ASSERT_EQUAL(view_messages[1], std::string(item->data().data(), item->data().size()));
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
|
|
|
LOK_ASSERT_EQUAL(view_messages[2], std::string(item->data().data(), item->data().size()));
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 16:28:35 -06:00
|
|
|
|
|
|
|
const std::vector<std::string> dup_messages =
|
|
|
|
{
|
|
|
|
"invalidateviewcursor: { \"viewId\": \"1\", \"rectangle\": \"3999, 1418, 0, 298\", \"part\": \"0\" }",
|
|
|
|
"invalidateviewcursor: { \"viewId\": \"1\", \"rectangle\": \"1000, 1418, 0, 298\", \"part\": \"0\" }",
|
|
|
|
"invalidateviewcursor: { \"viewId\": \"1\", \"rectangle\": \"2000, 1418, 0, 298\", \"part\": \"0\" }",
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& msg : dup_messages)
|
|
|
|
{
|
2017-01-21 18:51:02 -06:00
|
|
|
queue.enqueue(std::make_shared<Message>(msg, Message::Dir::Out));
|
2016-12-18 16:28:35 -06:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(1), queue.size());
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(true, queue.dequeue(item));
|
2016-12-18 16:28:35 -06:00
|
|
|
|
|
|
|
// The last one should persist.
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(dup_messages[2], std::string(item->data().data(), item->data().size()));
|
2016-12-18 16:28:35 -06:00
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(0), queue.size());
|
2016-12-18 16:28:35 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:21:56 -06:00
|
|
|
void TileQueueTests::testCallbackInvalidation()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2017-01-25 11:21:56 -06:00
|
|
|
TileQueue queue;
|
|
|
|
|
|
|
|
// join tiles
|
|
|
|
queue.put("callback all 0 284, 1418, 11105, 275, 0");
|
|
|
|
queue.put("callback all 0 4299, 1418, 7090, 275, 0");
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
|
2017-01-25 11:21:56 -06:00
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR("callback all 0 284, 1418, 11105, 275, 0", queue.get());
|
2017-01-25 11:21:56 -06:00
|
|
|
|
2019-10-08 04:23:29 -05:00
|
|
|
// invalidate everything with EMPTY, but keep the different part intact
|
2017-01-25 11:21:56 -06:00
|
|
|
queue.put("callback all 0 284, 1418, 11105, 275, 0");
|
|
|
|
queue.put("callback all 0 4299, 1418, 7090, 275, 1");
|
|
|
|
queue.put("callback all 0 4299, 10418, 7090, 275, 0");
|
|
|
|
queue.put("callback all 0 4299, 20418, 7090, 275, 0");
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(4, static_cast<int>(queue.getQueue().size()));
|
2017-01-25 11:21:56 -06:00
|
|
|
|
|
|
|
queue.put("callback all 0 EMPTY, 0");
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(2, static_cast<int>(queue.getQueue().size()));
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR("callback all 0 4299, 1418, 7090, 275, 1", queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR("callback all 0 EMPTY, 0", queue.get());
|
2017-01-25 11:21:56 -06:00
|
|
|
}
|
|
|
|
|
2017-04-07 05:29:01 -05:00
|
|
|
void TileQueueTests::testCallbackIndicatorValue()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2017-04-07 05:29:01 -05:00
|
|
|
TileQueue queue;
|
|
|
|
|
|
|
|
// join tiles
|
|
|
|
queue.put("callback all 10 25");
|
|
|
|
queue.put("callback all 10 50");
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR("callback all 10 50", queue.get());
|
2017-04-07 05:29:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileQueueTests::testCallbackPageSize()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2017-04-07 05:29:01 -05:00
|
|
|
TileQueue queue;
|
|
|
|
|
|
|
|
// join tiles
|
|
|
|
queue.put("callback all 13 12474, 188626");
|
|
|
|
queue.put("callback all 13 12474, 205748");
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR("callback all 13 12474, 205748", queue.get());
|
2017-04-07 05:29:01 -05:00
|
|
|
}
|
|
|
|
|
2020-09-21 10:41:20 -05:00
|
|
|
void TileQueueTests::testCallbackModifiedStatusIsSkipped()
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
constexpr auto testname = __func__;
|
|
|
|
|
2020-09-21 10:41:20 -05:00
|
|
|
TileQueue queue;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "callback all " << LOK_CALLBACK_STATE_CHANGED;
|
|
|
|
|
|
|
|
const std::vector<std::string> messages =
|
|
|
|
{
|
|
|
|
ss.str() + " .uno:ModifiedStatus=false",
|
|
|
|
ss.str() + " .uno:ModifiedStatus=true",
|
|
|
|
ss.str() + " .uno:ModifiedStatus=true",
|
|
|
|
ss.str() + " .uno:ModifiedStatus=false"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& msg : messages)
|
|
|
|
{
|
|
|
|
queue.put(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(4), queue.getQueue().size());
|
|
|
|
|
2021-11-09 18:05:46 -06:00
|
|
|
LOK_ASSERT_EQUAL_STR(messages[0], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(messages[1], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(messages[2], queue.get());
|
|
|
|
LOK_ASSERT_EQUAL_STR(messages[3], queue.get());
|
2020-09-21 10:41:20 -05:00
|
|
|
}
|
|
|
|
|
2016-09-29 13:04:05 -05:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(TileQueueTests);
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|