refactor: extract InvokationHandler interface

pull/79/head
Falk Werner 4 years ago
parent 8df7f08ed5
commit cdb36eaea1

@ -1,13 +1,13 @@
#ifndef WF_MOCK_INVOKATION_HANDLER_HPP
#define WF_MOCK_INVOKATION_HANDLER_HPP
#include "webfuse/test_util/ws_server.hpp"
#include "webfuse/test_util/invokation_handler.hpp"
#include <gtest/gtest.h>
namespace webfuse_test
{
class MockInvokationHander: public IIvokationHandler
class MockInvokationHander: public InvokationHandler
{
public:
MOCK_METHOD2(Invoke, std::string(char const * method, json_t * params));

@ -0,0 +1,19 @@
#ifndef WF_TEST_UTIL_INVOKATION_HANDLER_HPP
#define WF_TEST_UTIL_INVOKATION_HANDLER_HPP
#include <jansson.h>
#include <string>
namespace webfuse_test
{
class InvokationHandler
{
public:
virtual ~InvokationHandler() = default;
virtual std::string Invoke(char const * method, json_t * params) = 0;
};
}
#endif

@ -1,4 +1,5 @@
#include "webfuse/test_util/ws_server.hpp"
#include "webfuse/test_util/invokation_handler.hpp"
#include "webfuse/impl/util/lws_log.h"
#include <libwebsockets.h>
@ -75,7 +76,7 @@ class WsServer::Private : public IServer
Private(Private const &) = delete;
Private & operator=(Private const &) = delete;
public:
Private(IIvokationHandler & handler, std::string const & protocol, int port, bool enable_tls);
Private(InvokationHandler & handler, std::string const & protocol, int port, bool enable_tls);
~Private();
std::string const & GetUrl() const;
void OnConnected(lws * wsi) override;
@ -88,7 +89,7 @@ public:
private:
static void Run(Private * self);
IIvokationHandler & handler_;
InvokationHandler & handler_;
std::string protocol_;
bool is_shutdown_requested;
lws * wsi_;
@ -102,7 +103,7 @@ private:
};
WsServer::WsServer(
IIvokationHandler& handler,
InvokationHandler& handler,
std::string const & protocol,
int port,
bool enable_tls)
@ -133,7 +134,7 @@ void WsServer::SendMessage(json_t * message)
WsServer::Private::Private(
IIvokationHandler & handler,
InvokationHandler & handler,
std::string const & protocol,
int port,
bool enable_tls)

@ -7,12 +7,7 @@
namespace webfuse_test
{
class IIvokationHandler
{
public:
virtual ~IIvokationHandler() = default;
virtual std::string Invoke(char const * method, json_t * params) = 0;
};
class InvokationHandler;
class WsServer
{
@ -20,7 +15,7 @@ class WsServer
WsServer & operator=(WsServer const & ) = delete;
public:
WsServer(
IIvokationHandler& handler,
InvokationHandler& handler,
std::string const & protocol,
int port = 0,
bool enable_tls = false);

Loading…
Cancel
Save