summaryrefslogtreecommitdiffstats
path: root/test/UnitMinSocketBufferSize.cpp
blob: 6bfb678b22588c26cbb6ed9474866f49349ed882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* -*- 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 "Log.hpp"
#include "Protocol.hpp"
#include "Unit.hpp"
#include "UnitHTTP.hpp"
#include "helpers.hpp"

using namespace helpers;

class UnitMinSocketBufferSize: public UnitWSD
{
    enum class Phase {
        Load,             // load the document
        Request,          // Request tiles etc.
        CheckResponse     // 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, "unitMinSocketBufferSize ");
            _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::CheckResponse;
            break;
        }
        case Phase::CheckResponse:
            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::Ok : TestResult::Failed);
            break;
        }
    }
};

UnitBase *unit_create_wsd(void)
{
    return new UnitMinSocketBufferSize();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */