2016-04-07 15:59:27 -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>
|
2017-03-08 10:38:22 -06:00
|
|
|
|
2016-10-20 16:09:00 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <Exceptions.hpp>
|
|
|
|
#include <Log.hpp>
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <UnitHTTP.hpp>
|
|
|
|
#include <helpers.hpp>
|
2016-10-20 16:09:00 -05:00
|
|
|
|
|
|
|
using namespace helpers;
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
class UnitStorage : public UnitWSD
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
enum class Phase {
|
|
|
|
Load, // load the document
|
|
|
|
Filter, // throw filter exception
|
|
|
|
Reload, // re-load the document
|
2016-10-20 16:09:00 -05:00
|
|
|
} _phase;
|
|
|
|
std::unique_ptr<UnitWebSocket> _ws;
|
2016-04-07 15:59:27 -05:00
|
|
|
public:
|
2016-10-20 16:09:00 -05:00
|
|
|
UnitStorage() :
|
2016-12-22 03:27:30 -06:00
|
|
|
_phase(Phase::Load)
|
2016-10-20 16:09:00 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-31 11:18:41 -05:00
|
|
|
bool filterCheckDiskSpace(const std::string & /* path */,
|
|
|
|
bool &newResult) override
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
2017-03-31 11:18:41 -05:00
|
|
|
newResult = _phase != Phase::Filter;
|
|
|
|
return true;
|
2016-04-07 15:59:27 -05:00
|
|
|
}
|
2016-10-20 16:09:00 -05:00
|
|
|
|
2017-03-31 11:06:47 -05:00
|
|
|
void loadDocument(bool bExpectFailure)
|
2016-10-20 16:09:00 -05:00
|
|
|
{
|
|
|
|
std::string docPath;
|
|
|
|
std::string docURL;
|
2017-02-28 15:49:24 -06:00
|
|
|
getDocumentPathAndURL("empty.odt", docPath, docURL, "unitStorage ");
|
2016-10-20 16:09:00 -05:00
|
|
|
_ws = std::unique_ptr<UnitWebSocket>(new UnitWebSocket(docURL));
|
|
|
|
assert(_ws.get());
|
2017-03-31 11:06:47 -05:00
|
|
|
int flags = 0, len;;
|
|
|
|
char reply[4096];
|
|
|
|
while ((len = _ws->getLOOLWebSocket()->receiveFrame(reply, sizeof(reply) - 1, flags)) > 0)
|
|
|
|
{
|
|
|
|
reply[len] = '\0';
|
|
|
|
if (bExpectFailure &&
|
|
|
|
!strcmp(reply, "error: cmd=internal kind=diskfull"))
|
|
|
|
{
|
|
|
|
LOG_TRC("Got expected load failure error");
|
|
|
|
_phase = Phase::Reload;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (!bExpectFailure &&
|
|
|
|
!strncmp(reply, "status: ", sizeof("status: ") - 1))
|
|
|
|
{
|
|
|
|
LOG_TRC("Load completed as expected");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
std::cerr << "reply '" << reply << "'\n";
|
|
|
|
}
|
2016-10-20 16:09:00 -05:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:18:41 -05:00
|
|
|
void invokeTest() override
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
2017-03-31 11:06:47 -05:00
|
|
|
LOG_TRC("invokeTest: " << (int)_phase);
|
2016-10-20 16:09:00 -05:00
|
|
|
switch (_phase)
|
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
case Phase::Load:
|
|
|
|
_phase = Phase::Filter;
|
2017-03-31 11:06:47 -05:00
|
|
|
loadDocument(true);
|
2016-10-20 16:09:00 -05:00
|
|
|
break;
|
2016-12-22 03:27:30 -06:00
|
|
|
case Phase::Filter:
|
2016-10-20 16:09:00 -05:00
|
|
|
break;
|
2016-12-22 03:27:30 -06:00
|
|
|
case Phase::Reload:
|
2017-03-31 11:06:47 -05:00
|
|
|
loadDocument(false);
|
2016-10-20 16:09:00 -05:00
|
|
|
_ws.reset();
|
2016-12-22 03:27:30 -06:00
|
|
|
exitTest(TestResult::Ok);
|
2016-10-20 16:09:00 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-04-07 15:59:27 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
UnitBase *unit_create_wsd(void)
|
2016-04-07 15:59:27 -05:00
|
|
|
{
|
|
|
|
return new UnitStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|