mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
renamed ws_server2 to ws_server
This commit is contained in:
parent
15abbeb86a
commit
bde84b0fc0
@ -127,7 +127,7 @@ alltests = executable('alltests',
|
||||
'test/webfuse/test_util/tempdir.cc',
|
||||
'test/webfuse/test_util/file_utils.cc',
|
||||
'test/webfuse/test_util/timeout_watcher.cc',
|
||||
'test/webfuse/test_util/ws_server2.cc',
|
||||
'test/webfuse/test_util/ws_server.cc',
|
||||
'test/webfuse/test_util/adapter_client.cc',
|
||||
'test/webfuse/test_util/jansson_test_environment.cc',
|
||||
'test/webfuse/mocks/mock_authenticator.cc',
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef WF_MOCK_INVOKATION_HANDLER_HPP
|
||||
#define WF_MOCK_INVOKATION_HANDLER_HPP
|
||||
|
||||
#include "webfuse/test_util/ws_server2.hpp"
|
||||
#include "webfuse/test_util/ws_server.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace webfuse_test
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "webfuse/client_tlsconfig.h"
|
||||
#include "webfuse/credentials.h"
|
||||
#include "webfuse/protocol_names.h"
|
||||
#include "webfuse/test_util/ws_server2.hpp"
|
||||
#include "webfuse/test_util/ws_server.hpp"
|
||||
#include "webfuse/mocks/mock_adapter_client_callback.hpp"
|
||||
#include "webfuse/mocks/mock_invokation_handler.hpp"
|
||||
#include "webfuse/test_util/timeout_watcher.hpp"
|
||||
@ -13,7 +13,7 @@
|
||||
#include "webfuse/mocks/lookup_matcher.hpp"
|
||||
|
||||
using webfuse_test::AdapterClient;
|
||||
using webfuse_test::WsServer2;
|
||||
using webfuse_test::WsServer;
|
||||
using webfuse_test::MockInvokationHander;
|
||||
using webfuse_test::MockAdapterClientCallback;
|
||||
using webfuse_test::TimeoutWatcher;
|
||||
@ -61,7 +61,7 @@ TEST(AdapterClient, Connect)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
@ -92,7 +92,7 @@ TEST(AdapterClient, IgnoreNonJsonMessage)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
@ -126,7 +126,7 @@ TEST(AdapterClient, IgnoreInvalidJsonMessage)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
@ -160,7 +160,7 @@ TEST(AdapterClient, ConnectWithTls)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER, 0, true);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER, 0, true);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
@ -219,7 +219,7 @@ TEST(AdapterClient, Authenticate)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("authenticate"),_)).Times(1)
|
||||
.WillOnce(Return("{}"));
|
||||
|
||||
@ -278,7 +278,7 @@ TEST(AdapterClient, AuthenticationFailed)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("authenticate"),_)).Times(1)
|
||||
.WillOnce(Throw(std::runtime_error("authentication failed")));
|
||||
|
||||
@ -319,7 +319,7 @@ TEST(AdapterClient, AddFileSystem)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": \"test\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
@ -359,7 +359,7 @@ TEST(AdapterClient, FailToAddFileSystemTwice)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": \"test\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
@ -408,7 +408,7 @@ TEST(AdapterClient, FailToAddFileSystemMissingId)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
@ -448,7 +448,7 @@ TEST(AdapterClient, FailToAddFileSystemIdNotString)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": 42}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
@ -489,7 +489,7 @@ TEST(AdapterClient, AddFileSystemFailed)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Throw(std::runtime_error("failed")));
|
||||
|
||||
@ -527,7 +527,7 @@ TEST(AdapterClient, LookupFile)
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
WsServer server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": \"test\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "webfuse/test_util/ws_server2.hpp"
|
||||
#include "webfuse/test_util/ws_server.hpp"
|
||||
#include "webfuse/impl/util/lws_log.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
@ -70,7 +70,7 @@ static int wf_test_utils_ws_server_callback(
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class WsServer2::Private : public IServer
|
||||
class WsServer::Private : public IServer
|
||||
{
|
||||
Private(Private const &) = delete;
|
||||
Private & operator=(Private const &) = delete;
|
||||
@ -101,38 +101,38 @@ private:
|
||||
std::queue<std::string> writeQueue;
|
||||
};
|
||||
|
||||
WsServer2::WsServer2(
|
||||
WsServer::WsServer(
|
||||
IIvokationHandler& handler,
|
||||
std::string const & protocol,
|
||||
int port,
|
||||
bool enable_tls)
|
||||
: d(new WsServer2::Private(handler, protocol, port, enable_tls))
|
||||
: d(new WsServer::Private(handler, protocol, port, enable_tls))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WsServer2::~WsServer2()
|
||||
WsServer::~WsServer()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
std::string const & WsServer2::GetUrl() const
|
||||
std::string const & WsServer::GetUrl() const
|
||||
{
|
||||
return d->GetUrl();
|
||||
}
|
||||
|
||||
void WsServer2::SendMessage(char const * message)
|
||||
void WsServer::SendMessage(char const * message)
|
||||
{
|
||||
d->SendMessage(message);
|
||||
}
|
||||
|
||||
void WsServer2::SendMessage(json_t * message)
|
||||
void WsServer::SendMessage(json_t * message)
|
||||
{
|
||||
d->SendMessage(message);
|
||||
}
|
||||
|
||||
|
||||
WsServer2::Private::Private(
|
||||
WsServer::Private::Private(
|
||||
IIvokationHandler & handler,
|
||||
std::string const & protocol,
|
||||
int port,
|
||||
@ -178,7 +178,7 @@ WsServer2::Private::Private(
|
||||
context = std::thread(&Run, this);
|
||||
}
|
||||
|
||||
WsServer2::Private::~Private()
|
||||
WsServer::Private::~Private()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
@ -190,7 +190,7 @@ WsServer2::Private::~Private()
|
||||
lws_context_destroy(ws_context);
|
||||
}
|
||||
|
||||
void WsServer2::Private::Run(Private * self)
|
||||
void WsServer::Private::Run(Private * self)
|
||||
{
|
||||
bool is_running = true;
|
||||
while (is_running)
|
||||
@ -203,13 +203,13 @@ void WsServer2::Private::Run(Private * self)
|
||||
}
|
||||
}
|
||||
|
||||
void WsServer2::Private::OnConnected(lws * wsi)
|
||||
void WsServer::Private::OnConnected(lws * wsi)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
wsi_ = wsi;
|
||||
}
|
||||
|
||||
void WsServer2::Private::OnConnectionClosed(lws * wsi)
|
||||
void WsServer::Private::OnConnectionClosed(lws * wsi)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (wsi == wsi_)
|
||||
@ -218,7 +218,7 @@ void WsServer2::Private::OnConnectionClosed(lws * wsi)
|
||||
}
|
||||
}
|
||||
|
||||
void WsServer2::Private::OnWritable(struct lws * wsi)
|
||||
void WsServer::Private::OnWritable(struct lws * wsi)
|
||||
{
|
||||
bool notify = false;
|
||||
|
||||
@ -245,7 +245,7 @@ void WsServer2::Private::OnWritable(struct lws * wsi)
|
||||
}
|
||||
}
|
||||
|
||||
void WsServer2::Private::SendMessage(char const * message)
|
||||
void WsServer::Private::SendMessage(char const * message)
|
||||
{
|
||||
lws * wsi = nullptr;
|
||||
|
||||
@ -265,7 +265,7 @@ void WsServer2::Private::SendMessage(char const * message)
|
||||
}
|
||||
}
|
||||
|
||||
void WsServer2::Private::SendMessage(json_t * message)
|
||||
void WsServer::Private::SendMessage(json_t * message)
|
||||
{
|
||||
char* message_text = json_dumps(message, JSON_COMPACT);
|
||||
SendMessage(message_text);
|
||||
@ -273,7 +273,7 @@ void WsServer2::Private::SendMessage(json_t * message)
|
||||
free(message_text);
|
||||
}
|
||||
|
||||
void WsServer2::Private::OnMessageReceived(struct lws * wsi, char const * data, size_t length)
|
||||
void WsServer::Private::OnMessageReceived(struct lws * wsi, char const * data, size_t length)
|
||||
{
|
||||
(void) wsi;
|
||||
|
||||
@ -306,7 +306,7 @@ void WsServer2::Private::OnMessageReceived(struct lws * wsi, char const * data,
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
std::string const & WsServer2::Private::GetUrl() const
|
||||
std::string const & WsServer::Private::GetUrl() const
|
||||
{
|
||||
return url;
|
||||
}
|
@ -14,17 +14,17 @@ public:
|
||||
virtual std::string Invoke(char const * method, json_t * params) = 0;
|
||||
};
|
||||
|
||||
class WsServer2
|
||||
class WsServer
|
||||
{
|
||||
WsServer2(WsServer2 const &) = delete;
|
||||
WsServer2 & operator=(WsServer2 const & ) = delete;
|
||||
WsServer(WsServer const &) = delete;
|
||||
WsServer & operator=(WsServer const & ) = delete;
|
||||
public:
|
||||
WsServer2(
|
||||
WsServer(
|
||||
IIvokationHandler& handler,
|
||||
std::string const & protocol,
|
||||
int port = 0,
|
||||
bool enable_tls = false);
|
||||
virtual ~WsServer2();
|
||||
virtual ~WsServer();
|
||||
std::string const & GetUrl() const;
|
||||
void SendMessage(char const * message);
|
||||
void SendMessage(json_t * message);
|
Loading…
Reference in New Issue
Block a user