2016-04-05 11:41:10 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
#ifndef LOOL_UNIT_HPP
|
|
|
|
#define LOOL_UNIT_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2016-04-07 15:59:27 -05:00
|
|
|
#include <memory>
|
2016-04-05 11:41:10 -05:00
|
|
|
|
|
|
|
class UnitHooks;
|
2016-04-07 15:59:27 -05:00
|
|
|
class UnitHTTPServerRequest;
|
|
|
|
class UnitHTTPServerResponse;
|
|
|
|
|
|
|
|
class StorageBase;
|
2016-04-05 11:41:10 -05:00
|
|
|
|
|
|
|
#define CREATE_UNIT_HOOKS_SYMBOL "unit_create"
|
|
|
|
typedef UnitHooks *(CreateUnitHooksFunction)();
|
|
|
|
extern "C" { UnitHooks *unit_create(void); }
|
|
|
|
|
|
|
|
/// Derive your unit test / hooks from me.
|
|
|
|
class UnitHooks
|
|
|
|
{
|
|
|
|
void *_dlHandle;
|
2016-04-06 13:50:55 -05:00
|
|
|
bool _setRetValue;
|
|
|
|
int _retValue;
|
2016-04-05 11:41:10 -05:00
|
|
|
static UnitHooks *_global;
|
|
|
|
|
|
|
|
void setHandle(void *dlHandle) { _dlHandle = dlHandle; }
|
|
|
|
static UnitHooks *linkAndCreateUnit(const std::string &unitLibPath);
|
2016-04-06 13:50:55 -05:00
|
|
|
protected:
|
2016-04-07 15:59:27 -05:00
|
|
|
|
|
|
|
// ---------------- Helper API ----------------
|
|
|
|
|
2016-04-06 13:50:55 -05:00
|
|
|
enum TestResult { TEST_FAILED, TEST_OK, TEST_TIMED_OUT };
|
|
|
|
/// Encourages loolwsd to exit with this value (unless hooked)
|
|
|
|
void exitTest(TestResult result);
|
2016-04-07 15:59:27 -05:00
|
|
|
|
|
|
|
enum TestRequest { TEST_REQ_CLIENT, TEST_REQ_PRISONER };
|
|
|
|
/// Simulate an incoming request
|
|
|
|
void testHandleRequest(TestRequest type,
|
|
|
|
UnitHTTPServerRequest& request,
|
|
|
|
UnitHTTPServerResponse& response);
|
|
|
|
|
2016-04-05 11:41:10 -05:00
|
|
|
public:
|
|
|
|
UnitHooks();
|
|
|
|
virtual ~UnitHooks();
|
|
|
|
static UnitHooks &get() { return *_global; }
|
|
|
|
/// Load unit test hook shared library from this path
|
|
|
|
static bool init(const std::string &unitLibPath);
|
|
|
|
|
2016-04-07 15:59:27 -05:00
|
|
|
// ---------------- Hooks ----------------
|
|
|
|
|
|
|
|
/// Main-loop reached, time for testing
|
|
|
|
virtual void invokeTest() {}
|
2016-04-06 13:50:55 -05:00
|
|
|
/// Tweak the count of pre-spawned kits.
|
2016-04-05 11:41:10 -05:00
|
|
|
virtual void preSpawnCount(int & /* numPrefork */) {}
|
2016-04-06 13:50:55 -05:00
|
|
|
/// Tweak the return value from LOOLWSD.
|
|
|
|
virtual void returnValue(int & /* retValue */);
|
|
|
|
/// When a new child kit process reports
|
|
|
|
virtual void newChild() {}
|
2016-04-07 15:59:27 -05:00
|
|
|
/// If the test times out this gets invoked
|
2016-04-06 13:50:55 -05:00
|
|
|
virtual void timeout();
|
2016-04-07 15:59:27 -05:00
|
|
|
/// Intercept createStorage
|
|
|
|
virtual bool createStorage(const std::string& /* jailRoot */,
|
|
|
|
const std::string& /* jailPath */,
|
|
|
|
const Poco::URI& /* uri */,
|
|
|
|
std::unique_ptr<StorageBase> & /*rStorage */) { return false; }
|
2016-04-05 11:41:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LOOL_UNIT_HPP
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|