2016-04-07 15:59:27 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2016-04-07 15:59:27 -05:00
|
|
|
* 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>
|
2017-03-08 10:38:22 -06:00
|
|
|
|
2022-03-06 12:07:47 -06:00
|
|
|
#include "Unit.hpp"
|
|
|
|
#include "WopiTestServer.hpp"
|
2016-10-20 16:09:00 -05:00
|
|
|
|
|
|
|
using namespace helpers;
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2022-03-06 12:07:47 -06:00
|
|
|
class UnitStorage : public WopiTestServer
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
2022-04-01 20:04:41 -05:00
|
|
|
STATE_ENUM(Phase,
|
|
|
|
Load, // load the document
|
|
|
|
Filter, // throw filter exception
|
|
|
|
Reload, // re-load the document
|
|
|
|
Done)
|
|
|
|
_phase;
|
2022-03-06 12:07:47 -06:00
|
|
|
|
2016-04-07 15:59:27 -05:00
|
|
|
public:
|
2022-03-06 12:07:47 -06:00
|
|
|
UnitStorage()
|
|
|
|
: WopiTestServer("UnitStorage")
|
|
|
|
, _phase(Phase::Load)
|
2016-10-20 16:09:00 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-06 12:07:47 -06:00
|
|
|
bool filterCheckDiskSpace(const std::string& /* path */, bool& newResult) override
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
2022-03-06 12:07:47 -06:00
|
|
|
// Fail the disk-space check in Filter phase.
|
2017-03-31 11:18:41 -05:00
|
|
|
newResult = _phase != Phase::Filter;
|
2022-03-06 12:07:47 -06:00
|
|
|
LOG_TST("Result: " << (newResult ? "success" : "out-of-disk-space"));
|
2017-03-31 11:18:41 -05:00
|
|
|
return true;
|
2016-04-07 15:59:27 -05:00
|
|
|
}
|
2016-10-20 16:09:00 -05:00
|
|
|
|
2022-03-06 12:07:47 -06:00
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
2016-10-20 16:09:00 -05:00
|
|
|
{
|
2022-03-06 12:07:47 -06:00
|
|
|
LOG_TST("Loaded: [" << message << ']');
|
|
|
|
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::Done);
|
|
|
|
passTest("Loaded successfully");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onDocumentError(const std::string& message) override
|
|
|
|
{
|
|
|
|
// This may trigger multiple times.
|
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Expect only documentunloading errors",
|
|
|
|
std::string("error: cmd=internal kind=diskfull"), message);
|
|
|
|
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::Filter);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When we fail to load, we must destroy the DocBroker.
|
|
|
|
void onDocBrokerDestroy(const std::string&) override
|
|
|
|
{
|
|
|
|
if (_phase == Phase::Filter)
|
2017-03-31 11:06:47 -05:00
|
|
|
{
|
2022-03-06 12:07:47 -06:00
|
|
|
TRANSITION_STATE(_phase, Phase::Reload);
|
2017-03-31 11:06:47 -05:00
|
|
|
}
|
2016-10-20 16:09:00 -05:00
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
2022-03-06 12:07:47 -06:00
|
|
|
LOG_TRC("invokeWSDTest: " << toString(_phase));
|
2016-10-20 16:09:00 -05:00
|
|
|
switch (_phase)
|
|
|
|
{
|
2022-03-06 12:07:47 -06:00
|
|
|
case Phase::Load:
|
|
|
|
TRANSITION_STATE(_phase, Phase::Filter);
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
|
|
|
break;
|
|
|
|
case Phase::Filter:
|
|
|
|
break;
|
|
|
|
case Phase::Reload:
|
|
|
|
LOG_TST("Reloading the document");
|
|
|
|
TRANSITION_STATE(_phase, Phase::Done);
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
|
|
|
break;
|
|
|
|
case Phase::Done:
|
|
|
|
break;
|
2016-10-20 16:09:00 -05:00
|
|
|
}
|
2016-04-07 15:59:27 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-06 12:07:47 -06:00
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitStorage(); }
|
2016-04-07 15:59:27 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|