1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

added unit tests

This commit is contained in:
Falk Werner
2020-06-15 16:58:04 +02:00
parent 4e42c856c7
commit 6bafbdd43a
3 changed files with 94 additions and 8 deletions

View File

@@ -70,7 +70,7 @@ static int wf_test_utils_ws_server_callback(
namespace webfuse_test
{
class WsServer2::Private : IServer
class WsServer2::Private : public IServer
{
Private(Private const &) = delete;
Private & operator=(Private const &) = delete;
@@ -84,8 +84,9 @@ public:
void OnMessageReceived(struct lws * wsi, char const * data, size_t length) override;
void OnWritable(struct lws * wsi) override;
private:
void SendMessage(char const * message);
void SendMessage(json_t * message);
private:
static void Run(Private * self);
IIvokationHandler & handler_;
@@ -127,6 +128,17 @@ std::string const & WsServer2::GetUrl() const
return d->GetUrl();
}
void WsServer2::SendMessage(char const * message)
{
d->SendMessage(message);
}
void WsServer2::SendMessage(json_t * message)
{
d->SendMessage(message);
}
WsServer2::Private::Private(
IIvokationHandler & handler,
std::string const & protocol,
@@ -249,8 +261,7 @@ void WsServer2::Private::OnWritable(struct lws * wsi)
}
}
void WsServer2::Private::SendMessage(json_t * message)
void WsServer2::Private::SendMessage(char const * message)
{
lws * wsi = nullptr;
@@ -259,10 +270,7 @@ void WsServer2::Private::SendMessage(json_t * message)
if (nullptr != wsi_)
{
char* message_text = json_dumps(message, JSON_COMPACT);
writeQueue.push(message_text);
json_decref(message);
free(message_text);
writeQueue.push(message);
wsi = wsi_;
}
}
@@ -273,6 +281,14 @@ void WsServer2::Private::SendMessage(json_t * message)
}
}
void WsServer2::Private::SendMessage(json_t * message)
{
char* message_text = json_dumps(message, JSON_COMPACT);
SendMessage(message_text);
json_decref(message);
free(message_text);
}
void WsServer2::Private::OnMessageReceived(struct lws * wsi, char const * data, size_t length)
{
(void) wsi;

View File

@@ -27,6 +27,8 @@ public:
virtual ~WsServer2();
bool IsConnected();
std::string const & GetUrl() const;
void SendMessage(char const * message);
void SendMessage(json_t * message);
private:
class Private;
Private * d;