2016-04-05 11:41:10 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
2020-04-18 03:39:50 -05:00
|
|
|
|
|
|
|
#pragma once
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2016-04-08 11:36:08 -05:00
|
|
|
#include <atomic>
|
2016-08-30 02:06:39 -05:00
|
|
|
#include <cassert>
|
2020-12-14 13:00:55 -06:00
|
|
|
#include <chrono>
|
2016-10-29 20:15:00 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2022-02-15 16:45:01 -06:00
|
|
|
#include <vector>
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2017-10-26 03:38:57 -05:00
|
|
|
#include "net/Socket.hpp"
|
2016-04-18 08:29:17 -05:00
|
|
|
|
2022-02-15 16:45:01 -06:00
|
|
|
#include <test/testlog.hpp>
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
class UnitBase;
|
|
|
|
class UnitWSD;
|
|
|
|
class UnitKit;
|
2016-04-08 11:36:08 -05:00
|
|
|
class UnitTimeout;
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2017-10-26 03:38:57 -05:00
|
|
|
class WebSocketHandler;
|
2022-02-10 08:59:47 -06:00
|
|
|
class ClientSession;
|
2017-10-26 03:38:57 -05:00
|
|
|
|
2016-04-16 13:37:38 -05:00
|
|
|
// Forward declaration to avoid pulling the world here.
|
2016-10-29 20:15:00 -05:00
|
|
|
namespace Poco
|
|
|
|
{
|
2018-02-08 12:51:54 -06:00
|
|
|
class MemoryInputStream;
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
namespace Net
|
|
|
|
{
|
2016-04-12 15:30:06 -05:00
|
|
|
class HTTPServerRequest;
|
|
|
|
class HTTPServerResponse;
|
2016-04-16 13:37:38 -05:00
|
|
|
}
|
|
|
|
|
2016-10-29 20:15:00 -05:00
|
|
|
namespace Util
|
|
|
|
{
|
2016-04-16 13:37:38 -05:00
|
|
|
class LayeredConfiguration;
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 15:30:06 -05:00
|
|
|
|
2016-12-12 18:53:58 -06:00
|
|
|
class Session;
|
2016-04-07 15:59:27 -05:00
|
|
|
class StorageBase;
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
typedef UnitBase *(CreateUnitHooksFunction)();
|
|
|
|
extern "C" { UnitBase *unit_create_wsd(void); }
|
|
|
|
extern "C" { UnitBase *unit_create_kit(void); }
|
2016-05-01 03:04:19 -05:00
|
|
|
extern "C" { typedef struct _LibreOfficeKit LibreOfficeKit; }
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
/// Derive your WSD unit test / hooks from me.
|
|
|
|
class UnitBase
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
2016-04-08 11:36:08 -05:00
|
|
|
friend UnitTimeout;
|
2016-04-09 11:30:48 -05:00
|
|
|
friend UnitWSD;
|
|
|
|
friend UnitKit;
|
2016-04-08 11:36:08 -05:00
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
public:
|
|
|
|
enum class UnitType
|
|
|
|
{
|
|
|
|
Wsd,
|
|
|
|
Kit,
|
|
|
|
Tool
|
|
|
|
};
|
|
|
|
|
2016-04-06 13:50:55 -05:00
|
|
|
protected:
|
2016-04-07 15:59:27 -05:00
|
|
|
// ---------------- Helper API ----------------
|
2016-04-08 11:36:08 -05:00
|
|
|
/// After this time we invoke 'timeout' default 30 seconds
|
2020-12-14 13:00:55 -06:00
|
|
|
void setTimeout(std::chrono::milliseconds timeoutMilliSeconds);
|
2016-04-08 11:36:08 -05:00
|
|
|
|
2016-12-22 03:27:30 -06:00
|
|
|
enum class TestResult
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
Failed,
|
|
|
|
Ok,
|
|
|
|
TimedOut
|
2016-10-29 20:15:00 -05:00
|
|
|
};
|
2016-04-09 11:30:48 -05:00
|
|
|
|
2020-06-22 07:24:11 -05:00
|
|
|
static const std::string testResultAsString(TestResult res)
|
|
|
|
{
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case TestResult::Failed:
|
|
|
|
return "Failed";
|
|
|
|
case TestResult::Ok:
|
|
|
|
return "Ok";
|
|
|
|
case TestResult::TimedOut:
|
|
|
|
return "TimedOut";
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!"Unknown TestResult entry.");
|
|
|
|
return std::to_string(static_cast<int>(res));
|
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
/// Encourages the process to exit with this value (unless hooked)
|
2016-04-06 13:50:55 -05:00
|
|
|
void exitTest(TestResult result);
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2021-01-10 15:44:24 -06:00
|
|
|
/// Fail the test with the given reason.
|
|
|
|
void failTest(const std::string& reason)
|
|
|
|
{
|
|
|
|
LOG_TST("FAILURE: " << getTestname() << " finished: " << reason);
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pass the test with the given optional reason.
|
|
|
|
void passTest(const std::string& reason = std::string())
|
|
|
|
{
|
|
|
|
LOG_TST("SUCCESS: " << getTestname() << " finished: " << reason);
|
|
|
|
exitTest(TestResult::Ok);
|
|
|
|
}
|
|
|
|
|
2021-04-12 14:14:49 -05:00
|
|
|
/// Construct a UnitBase instance with a default name.
|
2021-09-16 06:25:29 -05:00
|
|
|
explicit UnitBase(std::string name, UnitType type)
|
2021-04-12 14:14:49 -05:00
|
|
|
: _dlHandle(nullptr)
|
|
|
|
, _setRetValue(false)
|
|
|
|
, _retValue(0)
|
|
|
|
, _timeoutMilliSeconds(std::chrono::seconds(30))
|
2021-09-16 06:25:29 -05:00
|
|
|
, _type(type)
|
2022-02-16 16:22:18 -06:00
|
|
|
, _socketPoll(std::make_shared<SocketPoll>(name))
|
|
|
|
, testname(std::move(name))
|
2020-12-20 21:11:33 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
virtual ~UnitBase();
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Load unit test hook shared library from this path
|
2016-10-29 20:15:00 -05:00
|
|
|
static bool init(UnitType type, const std::string& unitLibPath);
|
2016-04-09 11:30:48 -05:00
|
|
|
|
2016-10-22 10:35:30 -05:00
|
|
|
/// Do we have a unit test library hooking things & loaded
|
|
|
|
static bool isUnitTesting();
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
/// Tweak the return value from the process.
|
2016-10-29 20:15:00 -05:00
|
|
|
virtual void returnValue(int& /* retValue */);
|
2016-04-09 11:30:48 -05:00
|
|
|
|
2021-11-30 10:07:38 -06:00
|
|
|
/// Trigger a failure due to any reason.
|
|
|
|
virtual void fail(const std::string& reason)
|
|
|
|
{
|
|
|
|
failTest(reason);
|
|
|
|
}
|
|
|
|
|
2016-12-07 15:32:08 -06:00
|
|
|
/// Input message either for WSD or Kit
|
2016-12-12 18:53:58 -06:00
|
|
|
virtual bool filterSessionInput(Session *, const char */* buffer */,
|
2016-12-07 15:32:08 -06:00
|
|
|
int /* length */,
|
|
|
|
std::unique_ptr< std::vector<char> > & /* replace */)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-26 03:38:57 -05:00
|
|
|
|
|
|
|
/// Message that is about to be sent via the websocket.
|
2021-01-04 17:35:43 -06:00
|
|
|
/// To override, handle onFilterSendMessage or any of the onDocument...() handlers.
|
|
|
|
bool filterSendMessage(const char* data, const std::size_t len, const WSOpCode code,
|
|
|
|
const bool flush, int& unitReturn)
|
2017-10-26 03:38:57 -05:00
|
|
|
{
|
2021-01-04 17:35:43 -06:00
|
|
|
const std::string message(data, len);
|
|
|
|
|
|
|
|
if (Util::startsWith(message, "status:"))
|
|
|
|
{
|
|
|
|
if (onDocumentLoaded(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (message == "statechanged: .uno:ModifiedStatus=true")
|
|
|
|
{
|
|
|
|
if (onDocumentModified(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (Util::startsWith(message, "statechanged:"))
|
|
|
|
{
|
|
|
|
if (onDocumentStateChanged(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (Util::startsWith(message, "error:"))
|
|
|
|
{
|
|
|
|
if (onDocumentError(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return onFilterSendMessage(data, len, code, flush, unitReturn);
|
2017-10-26 03:38:57 -05:00
|
|
|
}
|
2016-12-07 15:32:08 -06:00
|
|
|
|
2017-03-31 11:18:41 -05:00
|
|
|
/// Hook the disk space check
|
|
|
|
virtual bool filterCheckDiskSpace(const std::string & /* path */,
|
|
|
|
bool & /* newResult */)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-16 11:55:23 -05:00
|
|
|
/// Trap and filter alerting all users
|
|
|
|
virtual bool filterAlertAllusers(const std::string & /* msg */)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-09 15:02:29 -05:00
|
|
|
/// Custom response to a http request.
|
2021-01-04 17:35:43 -06:00
|
|
|
virtual bool handleHttpRequest(const Poco::Net::HTTPRequest& /*request*/,
|
|
|
|
Poco::MemoryInputStream& /*message*/,
|
|
|
|
std::shared_ptr<StreamSocket>& /*socket*/)
|
2017-08-09 15:02:29 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:35:43 -06:00
|
|
|
/// Called when the document has been loaded,
|
|
|
|
/// based on the "status:" message, in the context of filterSendMessage.
|
|
|
|
/// Return true to stop further handling of messages.
|
|
|
|
virtual bool onDocumentLoaded(const std::string&) { return false; }
|
|
|
|
|
|
|
|
/// Called when the document's 'modified' status
|
|
|
|
/// changes to true.
|
|
|
|
/// Return true to stop further handling of messages.
|
|
|
|
virtual bool onDocumentModified(const std::string&) { return false; }
|
|
|
|
|
|
|
|
/// Called when the document has been saved.
|
|
|
|
/// Return true to stop further handling of messages.
|
|
|
|
virtual bool onDocumentSaved(const std::string&) { return false; }
|
|
|
|
|
|
|
|
/// Called when the document issues a 'statechanged:' message.
|
|
|
|
/// Return true to stop further handling of messages.
|
|
|
|
virtual bool onDocumentStateChanged(const std::string&) { return false; }
|
|
|
|
|
|
|
|
/// Called when the document issues an 'error:' message.
|
|
|
|
/// Return true to stop further handling of messages.
|
|
|
|
virtual bool onDocumentError(const std::string&) { return false; }
|
|
|
|
|
2017-03-16 13:52:49 -05:00
|
|
|
/// If the test times out this gets invoked, the default just exits.
|
|
|
|
virtual void timeout();
|
|
|
|
|
2022-02-15 20:19:26 -06:00
|
|
|
/// True iff exitTest is called.
|
2022-02-09 18:37:40 -06:00
|
|
|
bool isFinished() const { return _setRetValue; }
|
|
|
|
|
2022-02-15 20:19:26 -06:00
|
|
|
/// True iff exitTest was called with anything but TestResult::Ok.
|
|
|
|
/// Meaningful only when isFinished() is true.
|
|
|
|
bool failed() const { return _retValue; }
|
|
|
|
|
2020-12-14 13:00:55 -06:00
|
|
|
std::chrono::milliseconds getTimeoutMilliSeconds() const
|
2017-03-16 13:52:49 -05:00
|
|
|
{
|
|
|
|
return _timeoutMilliSeconds;
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:37:40 -06:00
|
|
|
void checkTimeout(const std::chrono::milliseconds elapsedTime)
|
|
|
|
{
|
|
|
|
if (isUnitTesting() && !isFinished() && elapsedTime > getTimeoutMilliSeconds())
|
|
|
|
{
|
|
|
|
LOG_TST("ERROR Test exceeded its time limit of "
|
|
|
|
<< getTimeoutMilliSeconds() << ". It's been running for " << elapsedTime);
|
|
|
|
timeout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 15:32:08 -06:00
|
|
|
static UnitBase& get()
|
|
|
|
{
|
|
|
|
assert(Global);
|
2016-12-23 01:02:19 -06:00
|
|
|
return *Global;
|
2016-12-07 15:32:08 -06:00
|
|
|
}
|
|
|
|
|
2020-01-17 14:49:38 -06:00
|
|
|
static std::string getUnitLibPath() { return std::string(UnitLibPath); }
|
|
|
|
|
2022-02-16 16:22:18 -06:00
|
|
|
const std::string& getTestname() const { return testname; }
|
|
|
|
void setTestname(const std::string& name) { testname = name; }
|
2020-12-20 21:11:33 -06:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPoll() { return _socketPoll; }
|
2021-04-12 16:22:08 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
private:
|
2020-01-17 14:49:38 -06:00
|
|
|
void setHandle(void *dlHandle)
|
|
|
|
{
|
2021-05-04 21:03:58 -05:00
|
|
|
assert(_dlHandle == nullptr && "setHandle must only be called once");
|
|
|
|
assert(dlHandle != nullptr && "Invalid handle to set");
|
2020-01-17 14:49:38 -06:00
|
|
|
_dlHandle = dlHandle;
|
2021-05-04 21:03:58 -05:00
|
|
|
_socketPoll->startThread();
|
2020-01-17 14:49:38 -06:00
|
|
|
}
|
2016-10-29 20:15:00 -05:00
|
|
|
static UnitBase *linkAndCreateUnit(UnitType type, const std::string& unitLibPath);
|
2016-04-09 11:30:48 -05:00
|
|
|
|
2021-01-04 17:35:43 -06:00
|
|
|
/// Handles messages sent via WebSocket.
|
|
|
|
virtual bool onFilterSendMessage(const char* /*data*/, const std::size_t /*len*/,
|
|
|
|
const WSOpCode /* code */, const bool /* flush */,
|
|
|
|
int& /*unitReturn*/)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
static UnitBase* get(UnitType type);
|
|
|
|
|
2021-09-14 10:05:31 -05:00
|
|
|
/// setup global instance for get() method
|
2021-09-16 06:25:29 -05:00
|
|
|
static void rememberInstance(UnitType type, UnitBase* instance);
|
2021-09-14 10:05:31 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
void *_dlHandle;
|
2020-01-17 14:49:38 -06:00
|
|
|
static char *UnitLibPath;
|
2016-04-09 11:30:48 -05:00
|
|
|
bool _setRetValue;
|
2016-10-29 20:15:00 -05:00
|
|
|
int _retValue;
|
2020-12-14 13:00:55 -06:00
|
|
|
std::chrono::milliseconds _timeoutMilliSeconds;
|
2016-06-07 02:18:49 -05:00
|
|
|
static UnitBase *Global;
|
2016-04-09 11:30:48 -05:00
|
|
|
UnitType _type;
|
2020-12-20 21:11:33 -06:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
std::shared_ptr<SocketPoll> _socketPoll; //< Poll thread for async http comm.
|
2022-02-16 16:22:18 -06:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/// The name of the current test. Accessed from logs in derived classes.
|
|
|
|
std::string testname;
|
2016-04-09 11:30:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Derive your WSD unit test / hooks from me.
|
|
|
|
class UnitWSD : public UnitBase
|
|
|
|
{
|
|
|
|
bool _hasKitHooks;
|
2016-10-29 20:15:00 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
public:
|
2020-12-20 21:11:33 -06:00
|
|
|
UnitWSD(std::string testname = std::string());
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
virtual ~UnitWSD();
|
|
|
|
|
2021-09-14 10:05:31 -05:00
|
|
|
static UnitWSD& get();
|
2016-04-09 11:30:48 -05:00
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
virtual void returnValue(int& /* retValue */);
|
|
|
|
|
2016-12-22 03:27:30 -06:00
|
|
|
enum class TestRequest
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
Client,
|
|
|
|
Prisoner
|
2016-10-29 20:15:00 -05:00
|
|
|
};
|
2021-10-08 15:51:41 -05:00
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
/// Do we have hooks for the Kit too
|
|
|
|
bool hasKitHooks() { return _hasKitHooks; }
|
|
|
|
/// set in your unit if you want to be injected into the kit too.
|
2017-01-16 04:59:03 -06:00
|
|
|
void setHasKitHooks() { _hasKitHooks = true; }
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2016-04-09 12:26:33 -05:00
|
|
|
// ---------------- WSD hooks ----------------
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2016-04-16 13:37:38 -05:00
|
|
|
/// Manipulate and modify the configuration before any usage.
|
2016-10-29 20:15:00 -05:00
|
|
|
virtual void configure(Poco::Util::LayeredConfiguration& /* config */);
|
2020-12-24 11:15:37 -06:00
|
|
|
|
|
|
|
/// Main-loop reached, time for testing.
|
2021-11-18 06:08:14 -06:00
|
|
|
/// Invoked from coolwsd's main thread.
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeTest()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Invoke the test, expect no exceptions.
|
|
|
|
invokeWSDTest();
|
|
|
|
}
|
2021-05-01 15:33:09 -05:00
|
|
|
catch (const Poco::Exception& ex)
|
|
|
|
{
|
|
|
|
LOG_ERR("ERROR: unexpected exception while invoking WSD Test: : "
|
|
|
|
<< ex.displayText()
|
|
|
|
<< (ex.nested() ? "( " + ex.nested()->displayText() + ')' : ""));
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
}
|
2020-12-24 11:15:37 -06:00
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
LOG_TST("ERROR: unexpected exception while invoking WSD Test: " << ex.what());
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
LOG_TST("ERROR: unexpected unknown exception while invoking WSD Test");
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 13:50:55 -05:00
|
|
|
/// When a new child kit process reports
|
2017-03-16 13:32:12 -05:00
|
|
|
virtual void newChild(WebSocketHandler &/* socket */) {}
|
2016-04-07 15:59:27 -05:00
|
|
|
/// Intercept createStorage
|
2016-10-14 05:09:43 -05:00
|
|
|
virtual bool createStorage(const Poco::URI& /* uri */,
|
|
|
|
const std::string& /* jailRoot */,
|
2016-04-07 15:59:27 -05:00
|
|
|
const std::string& /* jailPath */,
|
2017-01-13 06:52:08 -06:00
|
|
|
std::unique_ptr<StorageBase>& /* storage */)
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-20 21:31:53 -05:00
|
|
|
/// Child sent a message
|
|
|
|
virtual bool filterChildMessage(const std::vector<char>& /* payload */)
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-20 21:31:53 -05:00
|
|
|
|
2016-05-01 09:24:31 -05:00
|
|
|
// ---------------- TileCache hooks ----------------
|
|
|
|
/// Called before the lookupTile call returns. Should always be called to fire events.
|
|
|
|
virtual void lookupTile(int part, int width, int height, int tilePosX, int tilePosY,
|
2019-02-14 13:01:43 -06:00
|
|
|
int tileWidth, int tileHeight,
|
|
|
|
std::shared_ptr<std::vector<char>> &tile);
|
2016-05-01 09:24:31 -05:00
|
|
|
|
2016-10-20 16:09:00 -05:00
|
|
|
// ---------------- DocumentBroker hooks ----------------
|
2016-10-29 20:15:00 -05:00
|
|
|
virtual bool filterLoad(const std::string& /* sessionId */,
|
|
|
|
const std::string& /* jailId */,
|
|
|
|
bool& /* result */)
|
2016-10-20 16:09:00 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
/// To force the save operation being handled as auto-save from a unit test.
|
|
|
|
virtual bool isAutosave()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-21 05:47:07 -05:00
|
|
|
/// hook and allow through clipboard authentication
|
|
|
|
virtual bool filterClipboardAuth(const std::string & /* serverId */, const std::string &/* tag */)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-17 08:54:05 -05:00
|
|
|
// ---------------- WSD events ----------------
|
|
|
|
virtual void onChildConnected(const int /* pid */, const std::string& /* sessionId */) {}
|
2016-04-18 08:29:17 -05:00
|
|
|
/// When admin notify message is sent
|
|
|
|
virtual void onAdminNotifyMessage(const std::string& /* message */) {}
|
|
|
|
/// When admin message is sent in response to a query
|
|
|
|
virtual void onAdminQueryMessage(const std::string& /* message */) {}
|
2016-05-01 09:24:31 -05:00
|
|
|
|
2022-02-15 16:45:20 -06:00
|
|
|
// ---------------- DocBroker events ----------------
|
|
|
|
|
|
|
|
/// Called when a DocumentBroker is created (from the constructor).
|
|
|
|
/// Useful to detect track the beginning of a document's life cycle.
|
|
|
|
virtual void onDocBrokerCreate(const std::string&) {}
|
|
|
|
|
2022-03-30 20:09:18 -05:00
|
|
|
/// Called when the Kit process is attached to a DocBroker.
|
|
|
|
virtual void onDocBrokerAttachKitProcess(const std::string&, int) {}
|
|
|
|
|
2022-02-15 16:45:20 -06:00
|
|
|
/// Called when a new client session is added to a DocumentBroker.
|
|
|
|
virtual void onDocBrokerAddSession(const std::string&, const std::shared_ptr<ClientSession>&) {}
|
|
|
|
|
|
|
|
/// Called when a client session is removed to a DocumentBroker.
|
|
|
|
virtual void onDocBrokerRemoveSession(const std::string&, const std::shared_ptr<ClientSession>&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Called when a DocumentBroker is destroyed (from the destructor).
|
|
|
|
/// Useful to detect when unloading was clean and to (re)load again.
|
|
|
|
virtual void onDocBrokerDestroy(const std::string&) {}
|
|
|
|
|
2016-05-01 09:24:31 -05:00
|
|
|
// ---------------- TileCache events ----------------
|
|
|
|
virtual void onTileCacheHit(int /*part*/, int /*width*/, int /*height*/,
|
|
|
|
int /*tilePosX*/, int /*tilePosY*/,
|
|
|
|
int /*tileWidth*/, int /*tileHeight*/) {}
|
|
|
|
virtual void onTileCacheMiss(int /*part*/, int /*width*/, int /*height*/,
|
|
|
|
int /*tilePosX*/, int /*tilePosY*/,
|
|
|
|
int /*tileWidth*/, int /*tileHeight*/) {}
|
|
|
|
virtual void onTileCacheSubscribe(int /*part*/, int /*width*/, int /*height*/,
|
|
|
|
int /*tilePosX*/, int /*tilePosY*/,
|
|
|
|
int /*tileWidth*/, int /*tileHeight*/) {}
|
2020-12-24 11:15:37 -06:00
|
|
|
private:
|
|
|
|
/// The actual test implementation.
|
|
|
|
virtual void invokeWSDTest() {}
|
2016-04-09 11:30:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Derive your Kit unit test / hooks from me.
|
|
|
|
class UnitKit : public UnitBase
|
|
|
|
{
|
|
|
|
public:
|
2021-04-22 20:58:49 -05:00
|
|
|
explicit UnitKit(std::string testname = std::string());
|
2016-04-09 11:30:48 -05:00
|
|
|
virtual ~UnitKit();
|
2021-09-14 10:05:31 -05:00
|
|
|
static UnitKit& get();
|
2016-04-09 12:26:33 -05:00
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
virtual void returnValue(int& /* retValue */);
|
|
|
|
|
2016-04-09 12:26:33 -05:00
|
|
|
// ---------------- ForKit hooks ----------------
|
|
|
|
|
|
|
|
/// main-loop reached, time for testing
|
|
|
|
virtual void invokeForKitTest() {}
|
|
|
|
|
2016-04-12 15:30:06 -05:00
|
|
|
/// Post fork hook - just after we fork to init the child kit
|
|
|
|
virtual void launchedKit(int /* pid */) {}
|
|
|
|
|
2016-04-09 12:26:33 -05:00
|
|
|
// ---------------- Kit hooks ----------------
|
|
|
|
|
|
|
|
/// Post fork hook - just before we init the child kit
|
|
|
|
virtual void postFork() {}
|
|
|
|
|
|
|
|
/// Kit got a message
|
2018-11-07 17:00:32 -06:00
|
|
|
virtual bool filterKitMessage(WebSocketHandler *, std::string &/* message */ )
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-01 03:04:19 -05:00
|
|
|
|
2019-06-21 05:47:07 -05:00
|
|
|
/// LOKit (and some synthetic internal) callbacks
|
|
|
|
virtual bool filterLoKitCallback(const int /* type */, const std::string& /* payload */)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-01 03:04:19 -05:00
|
|
|
/// Allow a custom LibreOfficeKit wrapper
|
|
|
|
virtual LibreOfficeKit *lok_init(const char * /* instdir */,
|
|
|
|
const char * /* userdir */)
|
2016-10-29 20:15:00 -05:00
|
|
|
{
|
2016-12-22 08:04:07 -06:00
|
|
|
return nullptr;
|
2016-10-29 20:15:00 -05:00
|
|
|
}
|
2016-04-05 11:41:10 -05:00
|
|
|
};
|
|
|
|
|
2021-08-10 22:41:02 -05:00
|
|
|
/// Derive your Tool unit test / hooks from me.
|
|
|
|
class UnitTool : public UnitBase
|
|
|
|
{
|
|
|
|
public:
|
2022-02-16 16:22:18 -06:00
|
|
|
explicit UnitTool(std::string name = std::string())
|
|
|
|
: UnitBase(name, UnitType::Tool) {}
|
2021-08-10 22:41:02 -05:00
|
|
|
virtual ~UnitTool() {}
|
|
|
|
};
|
|
|
|
|
2021-11-26 17:09:16 -06:00
|
|
|
/// Enum macro specifically for state-machines.
|
|
|
|
/// Has several limitations, some intentional. For example,
|
|
|
|
/// the states must have automatic, sequential, values.
|
|
|
|
/// But also has some advantages, for example it can be used inside classes.
|
|
|
|
/// Some ideas from https://stackoverflow.com/questions/28828957/enum-to-string-in-modern-c11-c14-c17-and-future-c20
|
|
|
|
/// and from https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms
|
|
|
|
|
|
|
|
#define STRINGIFY(NAME, e) #NAME "::" #e,
|
|
|
|
#define CONCAT(X, Y) X##Y
|
|
|
|
#define CALL(X, ...) X(__VA_ARGS__)
|
|
|
|
|
|
|
|
#define APPLY1(MACRO, NAME, e) MACRO(NAME, e)
|
|
|
|
#define APPLY2(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY1(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY3(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY2(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY4(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY3(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY5(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY4(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY6(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY5(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY7(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY6(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY8(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY7(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY9(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY8(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY10(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY9(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY11(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY10(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY12(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY11(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY13(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY12(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY14(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY13(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define APPLY15(MACRO, NAME, e, ...) MACRO(NAME, e) APPLY14(MACRO, NAME, __VA_ARGS__)
|
|
|
|
|
|
|
|
// Credit to Anton Bachin for this trick.
|
|
|
|
#define GET_COUNT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, c, ...) c
|
|
|
|
#define COUNT_ARGS(...) GET_COUNT(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
|
|
|
|
|
|
|
|
#define APPLY(MACRO, NAME, ...) \
|
|
|
|
CALL(CONCAT, APPLY, COUNT_ARGS(__VA_ARGS__))(MACRO, NAME, __VA_ARGS__)
|
|
|
|
#define FOR_EACH(MACRO, NAME, ...) APPLY(MACRO, NAME, __VA_ARGS__)
|
|
|
|
|
|
|
|
/// Define a state-machine states, typically used to organize the phases
|
|
|
|
/// of a multi-stage test.
|
|
|
|
/// NAME is the name of the state enum, VAR is the name of the enum variable,
|
|
|
|
/// followed by the names of the states.
|
|
|
|
#define STATES_ENUM(NAME, VAR, ...) \
|
|
|
|
enum class NAME : char \
|
|
|
|
{ \
|
|
|
|
__VA_ARGS__ \
|
|
|
|
} VAR; \
|
2022-01-28 07:43:44 -06:00
|
|
|
static const char* name(NAME e) \
|
2021-11-26 17:09:16 -06:00
|
|
|
{ \
|
|
|
|
static const char* const NAME##_names[] = { FOR_EACH(STRINGIFY, NAME, __VA_ARGS__) }; \
|
|
|
|
assert(static_cast<unsigned>(e) < sizeof(NAME##_names) / sizeof(NAME##_names[0]) && \
|
|
|
|
"Enum value is out of range."); \
|
|
|
|
return NAME##_names[static_cast<int>(e)]; \
|
2022-01-28 07:43:44 -06:00
|
|
|
} \
|
|
|
|
static std::string toString(NAME e) { return name(e); }
|
2021-11-26 17:09:16 -06:00
|
|
|
|
|
|
|
/// Transition the test state of VAR to STATE, with a prefix message, and resume the test.
|
|
|
|
/// This will wake up all polls and the new state may be processed in parallel.
|
|
|
|
#define TRANSITION_STATE_MSG(VAR, STATE, MSG) \
|
|
|
|
do \
|
|
|
|
{ \
|
2022-01-28 07:43:44 -06:00
|
|
|
LOG_TST(MSG << ' ' << name(VAR) << " -> " #STATE); \
|
2021-11-26 17:09:16 -06:00
|
|
|
VAR = STATE; \
|
|
|
|
SocketPoll::wakeupWorld(); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
/// Transition the test state of VAR to STATE and resume the test.
|
|
|
|
/// This will wake up all polls and the new state may be processed in parallel.
|
2022-01-28 07:43:44 -06:00
|
|
|
#define TRANSITION_STATE(VAR, STATE) TRANSITION_STATE_MSG(VAR, STATE, "Transitioning " #VAR " from")
|
|
|
|
|
|
|
|
#define LOK_ASSERT_STATE(VAR, STATE) \
|
|
|
|
LOK_ASSERT_MESSAGE("Expected " #VAR " to be in " #STATE " but was " + toString(VAR), \
|
|
|
|
_phase == STATE)
|
2021-11-26 17:09:16 -06:00
|
|
|
|
2016-04-05 11:41:10 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|