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

switched prefix to wfp for old wf stuff

This commit is contained in:
Falk Werner
2020-06-16 23:57:41 +02:00
parent 2f80ebffcc
commit 83b76a1a5a
133 changed files with 1324 additions and 1324 deletions

View File

@@ -1,4 +1,4 @@
#ifndef WF_JSON_MATCHER_HPP
#ifndef WFP_JSON_MATCHER_HPP
#define FW_JSON_MATCHER_HPP
#include <gtest/gtest.h>

View File

@@ -1,5 +1,5 @@
#ifndef WF_LOOKUP_MATCHER_HPP
#define WF_LOOKUP_MATCHER_HPP
#ifndef WFP_LOOKUP_MATCHER_HPP
#define WFP_LOOKUP_MATCHER_HPP
#include <gmock/gmock.h>
#include <jansson.h>

View File

@@ -1,5 +1,5 @@
#ifndef WF_MOCK_INVOKATION_HANDLER_HPP
#define WF_MOCK_INVOKATION_HANDLER_HPP
#ifndef WFP_MOCK_INVOKATION_HANDLER_HPP
#define WFP_MOCK_INVOKATION_HANDLER_HPP
#include "webfuse/utils/ws_server2.hpp"
#include <gtest/gtest.h>

View File

@@ -5,15 +5,15 @@ extern "C"
{
static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr;
WF_WRAP_VFUNC5(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke,
struct wf_jsonrpc_proxy *,
wf_jsonrpc_proxy_finished_fn *,
WFP_WRAP_VFUNC5(webfuse_test_MockJsonRpcProxy, void, wfp_jsonrpc_proxy_vinvoke,
struct wfp_jsonrpc_proxy *,
wfp_jsonrpc_proxy_finished_fn *,
void *,
char const *,
char const *);
WF_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify,
struct wf_jsonrpc_proxy *,
WFP_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wfp_jsonrpc_proxy_vnotify,
struct wfp_jsonrpc_proxy *,
char const *,
char const *);
}

View File

@@ -12,14 +12,14 @@ class MockJsonRpcProxy
public:
MockJsonRpcProxy();
virtual ~MockJsonRpcProxy();
MOCK_METHOD5(wf_jsonrpc_proxy_vinvoke, void (
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
MOCK_METHOD5(wfp_jsonrpc_proxy_vinvoke, void (
struct wfp_jsonrpc_proxy * proxy,
wfp_jsonrpc_proxy_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info));
MOCK_METHOD3(wf_jsonrpc_proxy_vnotify, void (
struct wf_jsonrpc_proxy * proxy,
MOCK_METHOD3(wfp_jsonrpc_proxy_vnotify, void (
struct wfp_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info));

View File

@@ -5,9 +5,9 @@ extern "C"
{
static webfuse_test::MockOperationContext * webfuse_test_MockOperationContext = nullptr;
WF_WRAP_FUNC1(webfuse_test_MockOperationContext,
struct wf_jsonrpc_proxy *, wf_impl_operation_context_get_proxy,
struct wf_impl_operation_context *);
WFP_WRAP_FUNC1(webfuse_test_MockOperationContext,
struct wfp_jsonrpc_proxy *, wfp_impl_operation_context_get_proxy,
struct wfp_impl_operation_context *);
}

View File

@@ -12,8 +12,8 @@ class MockOperationContext
public:
MockOperationContext();
virtual ~MockOperationContext();
MOCK_METHOD1(wf_impl_operation_context_get_proxy, wf_jsonrpc_proxy * (
struct wf_impl_operation_context * context));
MOCK_METHOD1(wfp_impl_operation_context_get_proxy, wfp_jsonrpc_proxy * (
struct wfp_impl_operation_context * context));
};

View File

@@ -1,5 +1,5 @@
#ifndef WF_MOCK_PROVIDER_HPP
#define WF_MOCK_PROVIDER_HPP
#ifndef WFP_MOCK_PROVIDER_HPP
#define WFP_MOCK_PROVIDER_HPP
#include "webfuse_provider/impl/provider.h"
#include <gmock/gmock.h>

View File

@@ -41,7 +41,7 @@ static void webfuse_test_iproviderclient_onlookup(
}
catch (...)
{
wfp_respond_error(request, WF_BAD);
wfp_respond_error(request, WFP_BAD);
}
}
@@ -65,7 +65,7 @@ static void webfuse_test_iproviderclient_ongetattr(
}
catch (...)
{
wfp_respond_error(request, WF_BAD);
wfp_respond_error(request, WFP_BAD);
}
}
@@ -89,7 +89,7 @@ static void webfuse_test_iproviderclient_onreaddir(
}
catch (...)
{
wfp_respond_error(request, WF_BAD);
wfp_respond_error(request, WFP_BAD);
}
wfp_dirbuffer_dispose(buffer);
@@ -116,7 +116,7 @@ static void webfuse_test_iproviderclient_onopen(
}
catch (...)
{
wfp_respond_error(request, WF_BAD);
wfp_respond_error(request, WFP_BAD);
}
}
@@ -154,7 +154,7 @@ static void webfuse_test_iproviderclient_onread(
}
catch (...)
{
wfp_respond_error(request, WF_BAD);
wfp_respond_error(request, WFP_BAD);
}
delete[] data;
@@ -181,14 +181,14 @@ static void webfuse_test_iproviderclient_get_credentials(
namespace webfuse_test
{
ProviderClientException::ProviderClientException(wf_status error_code)
ProviderClientException::ProviderClientException(wfp_status error_code)
: runtime_error("ProviderClientException")
, error_code_(error_code)
{
}
wf_status ProviderClientException::GetErrorCode()
wfp_status ProviderClientException::GetErrorCode()
{
return error_code_;
}

View File

@@ -1,5 +1,5 @@
#ifndef WF_MOCK_PROVIDER_CLIENT_HPP
#define WF_MOCK_PROVIDER_CLIENT_HPP
#ifndef WFP_MOCK_PROVIDER_CLIENT_HPP
#define WFP_MOCK_PROVIDER_CLIENT_HPP
#include <gmock/gmock.h>
#include "webfuse_provider/client_config.h"
@@ -11,10 +11,10 @@ namespace webfuse_test
class ProviderClientException: public std::runtime_error
{
public:
explicit ProviderClientException(wf_status error_code);
wf_status GetErrorCode();
explicit ProviderClientException(wfp_status error_code);
wfp_status GetErrorCode();
private:
wf_status error_code_;
wfp_status error_code_;
};
class IProviderClient

View File

@@ -1,5 +1,5 @@
#ifndef WF_MOCK_REQUEST_HPP
#define WF_MOCK_REQUEST_HPP
#ifndef WFP_MOCK_REQUEST_HPP
#define WFP_MOCK_REQUEST_HPP
#include <gmock/gmock.h>
#include <jansson.h>

View File

@@ -3,29 +3,29 @@
extern "C"
{
static wf_jsonrpc_test::ITimer * wf_jsonrpc_MockTimer = nullptr;
static wfp_jsonrpc_test::ITimer * wfp_jsonrpc_MockTimer = nullptr;
WF_WRAP_FUNC0(wf_jsonrpc_MockTimer, wf_timer_manager *, wf_timer_manager_create);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_dispose, wf_timer_manager *);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_check, wf_timer_manager *);
WFP_WRAP_FUNC0(wfp_jsonrpc_MockTimer, wfp_timer_manager *, wfp_timer_manager_create);
WFP_WRAP_FUNC1(wfp_jsonrpc_MockTimer, void, wfp_timer_manager_dispose, wfp_timer_manager *);
WFP_WRAP_FUNC1(wfp_jsonrpc_MockTimer, void, wfp_timer_manager_check, wfp_timer_manager *);
WF_WRAP_FUNC3(wf_jsonrpc_MockTimer, wf_timer *, wf_timer_create, wf_timer_manager *, wf_timer_on_timer_fn *, void *);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_dispose, wf_timer *);
WF_WRAP_FUNC2(wf_jsonrpc_MockTimer, void, wf_timer_start, wf_timer *, int);
WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_cancel, wf_timer *);
WFP_WRAP_FUNC3(wfp_jsonrpc_MockTimer, wfp_timer *, wfp_timer_create, wfp_timer_manager *, wfp_timer_on_timer_fn *, void *);
WFP_WRAP_FUNC1(wfp_jsonrpc_MockTimer, void, wfp_timer_dispose, wfp_timer *);
WFP_WRAP_FUNC2(wfp_jsonrpc_MockTimer, void, wfp_timer_start, wfp_timer *, int);
WFP_WRAP_FUNC1(wfp_jsonrpc_MockTimer, void, wfp_timer_cancel, wfp_timer *);
}
namespace wf_jsonrpc_test
namespace wfp_jsonrpc_test
{
MockTimer::MockTimer()
{
wf_jsonrpc_MockTimer = this;
wfp_jsonrpc_MockTimer = this;
}
MockTimer::~MockTimer()
{
wf_jsonrpc_MockTimer = nullptr;
wfp_jsonrpc_MockTimer = nullptr;
}
}

View File

@@ -1,27 +1,27 @@
#ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP
#define WF_JSONRPC_MOCK_TIMERMANAGER_HPP
#ifndef WFP_JSONRPC_MOCK_TIMERMANAGER_HPP
#define WFP_JSONRPC_MOCK_TIMERMANAGER_HPP
#include "webfuse_provider/impl/timer/timer.h"
#include "webfuse_provider/impl/timer/manager.h"
#include <gmock/gmock.h>
namespace wf_jsonrpc_test
namespace wfp_jsonrpc_test
{
class ITimer
{
public:
virtual ~ITimer() = default;
virtual wf_timer_manager * wf_timer_manager_create() = 0;
virtual void wf_timer_manager_dispose(wf_timer_manager * manager) = 0;
virtual void wf_timer_manager_check(wf_timer_manager * manager) = 0;
virtual wf_timer * wf_timer_create(
wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
virtual wfp_timer_manager * wfp_timer_manager_create() = 0;
virtual void wfp_timer_manager_dispose(wfp_timer_manager * manager) = 0;
virtual void wfp_timer_manager_check(wfp_timer_manager * manager) = 0;
virtual wfp_timer * wfp_timer_create(
wfp_timer_manager * manager,
wfp_timer_on_timer_fn * on_timer,
void * user_data) = 0;
virtual void wf_timer_dispose(wf_timer * timer) = 0;
virtual void wf_timer_start(wf_timer * timer, int timeout_ms) = 0;
virtual void wf_timer_cancel(wf_timer * timer) = 0;
virtual void wfp_timer_dispose(wfp_timer * timer) = 0;
virtual void wfp_timer_start(wfp_timer * timer, int timeout_ms) = 0;
virtual void wfp_timer_cancel(wfp_timer * timer) = 0;
};
class MockTimer: public ITimer
@@ -29,16 +29,16 @@ class MockTimer: public ITimer
public:
MockTimer();
~MockTimer() override;
MOCK_METHOD0(wf_timer_manager_create, wf_timer_manager * ());
MOCK_METHOD1(wf_timer_manager_dispose, void(wf_timer_manager * manager));
MOCK_METHOD1(wf_timer_manager_check, void (wf_timer_manager * manager));
MOCK_METHOD3(wf_timer_create, wf_timer *(
wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
MOCK_METHOD0(wfp_timer_manager_create, wfp_timer_manager * ());
MOCK_METHOD1(wfp_timer_manager_dispose, void(wfp_timer_manager * manager));
MOCK_METHOD1(wfp_timer_manager_check, void (wfp_timer_manager * manager));
MOCK_METHOD3(wfp_timer_create, wfp_timer *(
wfp_timer_manager * manager,
wfp_timer_on_timer_fn * on_timer,
void * user_data));
MOCK_METHOD1(wf_timer_dispose, void (wf_timer * timer));
MOCK_METHOD2(wf_timer_start, void (wf_timer * timer, int timeout_ms));
MOCK_METHOD1(wf_timer_cancel, void (wf_timer * timer));
MOCK_METHOD1(wfp_timer_dispose, void (wfp_timer * timer));
MOCK_METHOD2(wfp_timer_start, void (wfp_timer * timer, int timeout_ms));
MOCK_METHOD1(wfp_timer_cancel, void (wfp_timer * timer));
};

View File

@@ -2,10 +2,10 @@
extern "C"
{
using wf_jsonrpc_test::MockTimerCallback;
using wfp_jsonrpc_test::MockTimerCallback;
static void wf_jsonrpc_test_MockTimerCallback_on_timer(
wf_timer * timer,
static void wfp_jsonrpc_test_MockTimerCallback_on_timer(
wfp_timer * timer,
void * user_data)
{
auto * self = reinterpret_cast<MockTimerCallback*>(user_data);
@@ -14,7 +14,7 @@ static void wf_jsonrpc_test_MockTimerCallback_on_timer(
}
namespace wf_jsonrpc_test
namespace wfp_jsonrpc_test
{
MockTimerCallback::MockTimerCallback()
@@ -27,9 +27,9 @@ MockTimerCallback::~MockTimerCallback()
}
wf_timer_on_timer_fn * MockTimerCallback::on_timer_fn()
wfp_timer_on_timer_fn * MockTimerCallback::on_timer_fn()
{
return &wf_jsonrpc_test_MockTimerCallback_on_timer;
return &wfp_jsonrpc_test_MockTimerCallback_on_timer;
}
void * MockTimerCallback::user_data()

View File

@@ -1,20 +1,20 @@
#ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP
#define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP
#ifndef WFP_JSONRPC_MOCK_TIMERCALLBACK_HPP
#define WFP_JSONRPC_MOCK_TIMERCALLBACK_HPP
#include "webfuse_provider/impl/timer/on_timer_fn.h"
#include <gmock/gmock.h>
namespace wf_jsonrpc_test
namespace wfp_jsonrpc_test
{
class MockTimerCallback
{
public:
MockTimerCallback();
virtual ~MockTimerCallback();
wf_timer_on_timer_fn * on_timer_fn();
wfp_timer_on_timer_fn * on_timer_fn();
void * user_data();
MOCK_METHOD2(on_timer, void (wf_timer * timer, void * user_data));
MOCK_METHOD2(on_timer, void (wfp_timer * timer, void * user_data));
};

View File

@@ -1,112 +1,112 @@
#include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/request.h"
TEST(wf_jsonrpc_is_request, request_with_object_params)
TEST(wfp_jsonrpc_is_request, request_with_object_params)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_request(request));
ASSERT_TRUE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, request_with_array_params)
TEST(wfp_jsonrpc_is_request, request_with_array_params)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_request(request));
ASSERT_TRUE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, null_request)
TEST(wfp_jsonrpc_is_request, null_request)
{
ASSERT_FALSE(wf_jsonrpc_is_request(nullptr));
ASSERT_FALSE(wfp_jsonrpc_is_request(nullptr));
}
TEST(wf_jsonrpc_is_request, invalid_request)
TEST(wfp_jsonrpc_is_request, invalid_request)
{
json_t * request = json_array();
json_array_append_new(request, json_string("method"));
json_array_append_new(request, json_object());
json_array_append_new(request, json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, invalid_request_without_id)
TEST(wfp_jsonrpc_is_request, invalid_request_without_id)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "params", json_object());
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_id)
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_id)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_string("42"));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, invalid_request_without_method)
TEST(wfp_jsonrpc_is_request, invalid_request_without_method)
{
json_t * request = json_object();
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_method)
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_method)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_integer(42));
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, invalid_request_without_params)
TEST(wfp_jsonrpc_is_request, invalid_request_without_params)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("method"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_params)
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_params)
{
json_t * request = json_object();
json_object_set_new(request, "methdo", json_string("method"));
json_object_set_new(request, "params", json_string("params"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}

View File

@@ -1,94 +1,94 @@
#include <gtest/gtest.h>
#include "webfuse_provider/impl/jsonrpc/response.h"
TEST(wf_jsonrpc_is_response, valid_result)
TEST(wfp_jsonrpc_is_response, valid_result)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_response(message));
ASSERT_TRUE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, valid_result_string)
TEST(wfp_jsonrpc_is_response, valid_result_string)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_string("also valid"));
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_response(message));
ASSERT_TRUE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, valid_error)
TEST(wfp_jsonrpc_is_response, valid_error)
{
json_t * message = json_object();
json_object_set_new(message, "error", json_object());
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_response(message));
ASSERT_TRUE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, invalid_null)
TEST(wfp_jsonrpc_is_response, invalid_null)
{
ASSERT_FALSE(wf_jsonrpc_is_response(nullptr));
ASSERT_FALSE(wfp_jsonrpc_is_response(nullptr));
}
TEST(wf_jsonrpc_is_response, invalid_message)
TEST(wfp_jsonrpc_is_response, invalid_message)
{
json_t * message = json_array();
json_array_append_new(message, json_object());
json_array_append_new(message, json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, invalid_missing_id)
TEST(wfp_jsonrpc_is_response, invalid_missing_id)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, invalid_id_wrong_type)
TEST(wfp_jsonrpc_is_response, invalid_id_wrong_type)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
json_object_set_new(message, "id", json_string("42"));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, invalid_missing_result_and_error)
TEST(wfp_jsonrpc_is_response, invalid_missing_result_and_error)
{
json_t * message = json_object();
json_object_set_new(message, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wfp_jsonrpc_is_response(message));
json_decref(message);
}
TEST(wf_jsonrpc_is_response, invalid_error_wrong_type)
TEST(wfp_jsonrpc_is_response, invalid_error_wrong_type)
{
json_t * message = json_object();
json_object_set_new(message, "error", json_array());
json_object_set_new(message, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_response(message));
ASSERT_FALSE(wfp_jsonrpc_is_response(message));
json_decref(message);
}

View File

@@ -9,20 +9,20 @@
#include <chrono>
using namespace std::chrono_literals;
using wf_jsonrpc_test::MockTimer;
using wfp_jsonrpc_test::MockTimer;
using testing::Return;
using testing::_;
using testing::DoAll;
using testing::SaveArg;
#define WF_DEFAULT_TIMEOUT (10 * 1000)
#define WFP_DEFAULT_TIMEOUT (10 * 1000)
namespace
{
int jsonrpc_get_status(json_t * error)
{
json_t * code = json_object_get(error, "code");
return (json_is_integer(code)) ? json_integer_value(code) : WF_BAD_FORMAT;
return (json_is_integer(code)) ? json_integer_value(code) : WFP_BAD_FORMAT;
}
struct SendContext
@@ -99,31 +99,31 @@ namespace
}
}
TEST(wf_jsonrpc_proxy, init)
TEST(wfp_jsonrpc_proxy, init)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext context;
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, user_data);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
ASSERT_FALSE(context.is_called);
}
TEST(wf_jsonrpc_proxy, invoke)
TEST(wfp_jsonrpc_proxy, invoke)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@@ -145,24 +145,24 @@ TEST(wf_jsonrpc_proxy, invoke)
ASSERT_FALSE(finished_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
ASSERT_TRUE(finished_context.is_called);
ASSERT_FALSE(nullptr == finished_context.error);
}
TEST(wf_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
TEST(wfp_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context(false);
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@@ -170,25 +170,25 @@ TEST(wf_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
ASSERT_TRUE(finished_context.is_called);
ASSERT_FALSE(nullptr == finished_context.error);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
TEST(wfp_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
FinishedContext finished_context2;
void * finished_data2 = reinterpret_cast<void*>(&finished_context2);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", "");
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data2, "foo", "");
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@@ -196,44 +196,44 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
ASSERT_FALSE(finished_context.is_called);
ASSERT_TRUE(finished_context2.is_called);
ASSERT_EQ(WF_BAD_BUSY, jsonrpc_get_status(finished_context2.error));
ASSERT_EQ(WFP_BAD_BUSY, jsonrpc_get_status(finished_context2.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
TEST(wfp_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
ASSERT_FALSE(send_context.is_called);
ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_BAD, jsonrpc_get_status(finished_context.error));
ASSERT_EQ(WFP_BAD, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, on_result)
TEST(wfp_jsonrpc_proxy, on_result)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@@ -245,7 +245,7 @@ TEST(wf_jsonrpc_proxy, on_result)
json_object_set_new(response, "result", json_string("okay"));
json_object_set(response, "id", id);
wf_jsonrpc_proxy_onresult(proxy, response);
wfp_jsonrpc_proxy_onresult(proxy, response);
json_decref(response);
ASSERT_TRUE(finished_context.is_called);
@@ -253,21 +253,21 @@ TEST(wf_jsonrpc_proxy, on_result)
ASSERT_TRUE(json_is_string(finished_context.result));
ASSERT_STREQ("okay", json_string_value(finished_context.result));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
TEST(wfp_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@@ -279,75 +279,75 @@ TEST(wf_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
json_object_set_new(response, "result", json_string("okay"));
json_object_set_new(response, "id", json_integer(1 + json_integer_value(id)));
wf_jsonrpc_proxy_onresult(proxy, response);
wfp_jsonrpc_proxy_onresult(proxy, response);
json_decref(response);
ASSERT_FALSE(finished_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, timeout)
TEST(wfp_jsonrpc_proxy, timeout)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, 0, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
std::this_thread::sleep_for(10ms);
wf_timer_manager_check(timer_manager);
wfp_timer_manager_check(timer_manager);
ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error));
ASSERT_EQ(WFP_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, cleanup_pending_request)
TEST(wfp_jsonrpc_proxy, cleanup_pending_request)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, 10, &jsonrpc_send, send_data);
FinishedContext finished_context;
void * finished_data = reinterpret_cast<void*>(&finished_context);
wf_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
ASSERT_FALSE(finished_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wfp_jsonrpc_proxy_dispose(proxy);
ASSERT_TRUE(finished_context.is_called);
wf_timer_manager_dispose(timer_manager);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, notify)
TEST(wfp_jsonrpc_proxy, notify)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
wf_jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42);
wfp_jsonrpc_proxy_notify(proxy, "foo", "si", "bar", 42);
ASSERT_TRUE(send_context.is_called);
ASSERT_TRUE(json_is_object(send_context.response));
@@ -367,64 +367,64 @@ TEST(wf_jsonrpc_proxy, notify)
json_t * id = json_object_get(send_context.response, "id");
ASSERT_EQ(nullptr, id);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, notify_dont_send_invalid_request)
TEST(wfp_jsonrpc_proxy, notify_dont_send_invalid_request)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
wf_jsonrpc_proxy_notify(proxy, "foo", "?");
wfp_jsonrpc_proxy_notify(proxy, "foo", "?");
ASSERT_FALSE(send_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}
TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending)
TEST(wfp_jsonrpc_proxy, swallow_timeout_if_no_request_pending)
{
MockTimer timer_api;
wf_timer_on_timer_fn * on_timer = nullptr;
wfp_timer_on_timer_fn * on_timer = nullptr;
void * timer_context = nullptr;
EXPECT_CALL(timer_api, wf_timer_create(_, _, _))
EXPECT_CALL(timer_api, wfp_timer_create(_, _, _))
.Times(1)
.WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr)));
EXPECT_CALL(timer_api, wf_timer_dispose(_)).Times(1);
EXPECT_CALL(timer_api, wfp_timer_dispose(_)).Times(1);
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(nullptr, 1, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(nullptr, 1, &jsonrpc_send, send_data);
on_timer(nullptr, timer_context);
ASSERT_FALSE(send_context.is_called);
wf_jsonrpc_proxy_dispose(proxy);
wfp_jsonrpc_proxy_dispose(proxy);
}
TEST(wf_jsonrpc_proxy, on_result_swallow_if_no_request_pending)
TEST(wfp_jsonrpc_proxy, on_result_swallow_if_no_request_pending)
{
struct wf_timer_manager * timer_manager = wf_timer_manager_create();
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context);
struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
json_t * response = json_object();
json_object_set_new(response, "result", json_string("okay"));
json_object_set_new(response, "id", json_integer(42));
wf_jsonrpc_proxy_onresult(proxy, response);
wfp_jsonrpc_proxy_onresult(proxy, response);
json_decref(response);
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
wfp_jsonrpc_proxy_dispose(proxy);
wfp_timer_manager_dispose(timer_manager);
}

View File

@@ -23,29 +23,29 @@ bool jsonrpc_send(
}
TEST(wf_jsonrpc_request, create_dispose)
TEST(wfp_jsonrpc_request, create_dispose)
{
Context context{nullptr};
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
struct wfp_jsonrpc_request * request =
wfp_jsonrpc_request_create(42, &jsonrpc_send, user_data);
ASSERT_NE(nullptr, request);
ASSERT_EQ(user_data, wf_jsonrpc_request_get_userdata(request));
ASSERT_EQ(user_data, wfp_jsonrpc_request_get_userdata(request));
wf_jsonrpc_request_dispose(request);
wfp_jsonrpc_request_dispose(request);
}
TEST(wf_jsonrpc_request, respond)
TEST(wfp_jsonrpc_request, respond)
{
Context context{nullptr};
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
struct wfp_jsonrpc_request * request =
wfp_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_jsonrpc_respond(request, json_string("okay"));
wfp_jsonrpc_respond(request, json_string("okay"));
ASSERT_NE(nullptr, context.response);
@@ -66,15 +66,15 @@ TEST(wf_jsonrpc_request, respond)
json_decref(response);
}
TEST(wf_jsonrpc_request, respond_error)
TEST(wfp_jsonrpc_request, respond_error)
{
Context context{nullptr};
void * user_data = reinterpret_cast<void*>(&context);
struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
struct wfp_jsonrpc_request * request =
wfp_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_jsonrpc_respond_error(request, WF_BAD, "Bad");
wfp_jsonrpc_respond_error(request, WFP_BAD, "Bad");
ASSERT_NE(nullptr, context.response);
@@ -93,7 +93,7 @@ TEST(wf_jsonrpc_request, respond_error)
json_t * err_code = json_object_get(err, "code");
ASSERT_TRUE(json_is_integer(err_code));
ASSERT_EQ(WF_BAD, json_integer_value(err_code));
ASSERT_EQ(WFP_BAD, json_integer_value(err_code));
json_t * err_message = json_object_get(err, "message");
ASSERT_TRUE(json_is_string(err_message));
@@ -102,37 +102,37 @@ TEST(wf_jsonrpc_request, respond_error)
json_decref(response);
}
TEST(wf_jsonrpc_request, is_request_object_params)
TEST(wfp_jsonrpc_request, is_request_object_params)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("some_method"));
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(42));
ASSERT_TRUE(wf_jsonrpc_is_request(request));
ASSERT_TRUE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_request, is_request_fail_missing_params)
TEST(wfp_jsonrpc_request, is_request_fail_missing_params)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("some_method"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}
TEST(wf_jsonrpc_request, is_request_fail_params_wrong_type)
TEST(wfp_jsonrpc_request, is_request_fail_params_wrong_type)
{
json_t * request = json_object();
json_object_set_new(request, "method", json_string("some_method"));
json_object_set_new(request, "params", json_string("invalid_params"));
json_object_set_new(request, "id", json_integer(42));
ASSERT_FALSE(wf_jsonrpc_is_request(request));
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
json_decref(request);
}

View File

@@ -2,25 +2,25 @@
#include "webfuse_provider/impl/jsonrpc/response_intern.h"
#include "webfuse_provider/status.h"
TEST(wf_json_response, init_result)
TEST(wfp_json_response, init_result)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_integer(47));
json_object_set_new(message, "id", json_integer(11));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(nullptr, response.error);
ASSERT_TRUE(json_is_integer(response.result));
ASSERT_EQ(47, json_integer_value(response.result));
ASSERT_EQ(11, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_error)
TEST(wfp_json_response, init_error)
{
json_t * message = json_object();
json_t * err = json_object();
@@ -29,68 +29,68 @@ TEST(wf_json_response, init_error)
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_fail_missing_result_and_error)
TEST(wfp_json_response, init_fail_missing_result_and_error)
{
json_t * message = json_object();
json_object_set_new(message, "id", json_integer(12));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(12, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_fail_missing_id)
TEST(wfp_json_response, init_fail_missing_id)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_integer(47));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_fail_wrong_id_type)
TEST(wfp_json_response, init_fail_wrong_id_type)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_integer(47));
json_object_set_new(message, "id", json_string("42"));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_fail_error_missing_code)
TEST(wfp_json_response, init_fail_error_missing_code)
{
json_t * message = json_object();
json_t * err = json_object();
@@ -98,18 +98,18 @@ TEST(wf_json_response, init_fail_error_missing_code)
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_fail_error_wrong_code_type)
TEST(wfp_json_response, init_fail_error_wrong_code_type)
{
json_t * message = json_object();
json_t * err = json_object();
@@ -118,30 +118,30 @@ TEST(wf_json_response, init_fail_error_wrong_code_type)
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}
TEST(wf_json_response, init_fail_error_wrong_type)
TEST(wfp_json_response, init_fail_error_wrong_type)
{
json_t * message = json_object();
json_object_set_new(message, "error", json_string("invalid error type"));
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_response_init(&response, message);
struct wfp_jsonrpc_response response;
wfp_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(WFP_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
json_decref(message);
}

View File

@@ -6,40 +6,40 @@
static void response_parse_str(
std::string const & buffer,
struct wf_jsonrpc_response * response)
struct wfp_jsonrpc_response * response)
{
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
if (nullptr != message)
{
wf_jsonrpc_response_init(response, message);
wfp_jsonrpc_response_init(response, message);
json_decref(message);
}
}
TEST(response_parser, test)
{
struct wf_jsonrpc_response response;
struct wfp_jsonrpc_response response;
// no object
response_parse_str("[]", &response);
ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
// empty
response_parse_str("{}", &response);
ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
// no data
response_parse_str("{\"id\":42}", &response);
ASSERT_NE(nullptr, response.error);
ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
// custom error code
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
@@ -47,12 +47,12 @@ TEST(response_parser, test)
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
// valid response
response_parse_str("{\"result\": true, \"id\": 42}", &response);
ASSERT_EQ(nullptr, response.error);
ASSERT_EQ(42, response.id);
ASSERT_NE(nullptr, response.result);
wf_jsonrpc_response_cleanup(&response);
wfp_jsonrpc_response_cleanup(&response);
}

View File

@@ -24,7 +24,7 @@ namespace
}
void sayHello(
struct wf_jsonrpc_request * request,
struct wfp_jsonrpc_request * request,
char const * method_name,
json_t * params,
void * user_data)
@@ -34,15 +34,15 @@ namespace
(void) user_data;
json_t * result = json_string("Hello");
wf_jsonrpc_respond(request, result);
wfp_jsonrpc_respond(request, result);
}
}
TEST(wf_jsonrpc_server, process_request)
TEST(wfp_jsonrpc_server, process_request)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
wfp_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@@ -50,7 +50,7 @@ TEST(wf_jsonrpc_server, process_request)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(23));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_TRUE(context.is_called);
ASSERT_NE(nullptr, context.response);
@@ -66,13 +66,13 @@ TEST(wf_jsonrpc_server, process_request)
json_decref(context.response);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, process_request_with_oject_params)
TEST(wfp_jsonrpc_server, process_request_with_oject_params)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
wfp_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@@ -80,7 +80,7 @@ TEST(wf_jsonrpc_server, process_request_with_oject_params)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_object());
json_object_set_new(request, "id", json_integer(23));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_TRUE(context.is_called);
ASSERT_NE(nullptr, context.response);
@@ -96,13 +96,13 @@ TEST(wf_jsonrpc_server, process_request_with_oject_params)
json_decref(context.response);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, invoke_unknown_method)
TEST(wfp_jsonrpc_server, invoke_unknown_method)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
wfp_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr);
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@@ -110,7 +110,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method)
json_object_set_new(request, "method", json_string("greet"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_TRUE(context.is_called);
ASSERT_NE(nullptr, context.response);
@@ -125,36 +125,36 @@ TEST(wf_jsonrpc_server, invoke_unknown_method)
json_t * err_code = json_object_get(err, "code");
ASSERT_TRUE(json_is_integer(err_code));
ASSERT_EQ(WF_BAD_NOTIMPLEMENTED, json_integer_value(err_code));
ASSERT_EQ(WFP_BAD_NOTIMPLEMENTED, json_integer_value(err_code));
json_t * err_message = json_object_get(err, "message");
ASSERT_TRUE(json_is_string(err_message));
json_decref(context.response);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_missing_id)
TEST(wfp_jsonrpc_server, skip_invalid_request_missing_id)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
json_t * request = json_object();
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_array());
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_wrong_id_type)
TEST(wfp_jsonrpc_server, skip_invalid_request_wrong_id_type)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@@ -162,34 +162,34 @@ TEST(wf_jsonrpc_server, skip_invalid_request_wrong_id_type)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_string("42"));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_missing_params)
TEST(wfp_jsonrpc_server, skip_invalid_request_missing_params)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
json_t * request = json_object();
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_wrong_params_type)
TEST(wfp_jsonrpc_server, skip_invalid_request_wrong_params_type)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@@ -197,34 +197,34 @@ TEST(wf_jsonrpc_server, skip_invalid_request_wrong_params_type)
json_object_set_new(request, "method", json_string("sayHello"));
json_object_set_new(request, "params", json_string("invalid"));
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_missing_method)
TEST(wfp_jsonrpc_server, skip_invalid_request_missing_method)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
json_t * request = json_object();
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}
TEST(wf_jsonrpc_server, skip_invalid_request_wront_method_type)
TEST(wfp_jsonrpc_server, skip_invalid_request_wront_method_type)
{
struct wf_jsonrpc_server * server = wf_jsonrpc_server_create();
struct wfp_jsonrpc_server * server = wfp_jsonrpc_server_create();
Context context{nullptr, false};
void * user_data = reinterpret_cast<void*>(&context);
@@ -232,10 +232,10 @@ TEST(wf_jsonrpc_server, skip_invalid_request_wront_method_type)
json_object_set_new(request, "method", json_integer(42));
json_object_set_new(request, "params", json_array());
json_object_set_new(request, "id", json_integer(42));
wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
wfp_jsonrpc_server_process(server, request, &jsonrpc_send, user_data);
ASSERT_FALSE(context.is_called);
json_decref(request);
wf_jsonrpc_server_dispose(server);
wfp_jsonrpc_server_dispose(server);
}

View File

@@ -3,15 +3,15 @@
TEST(Base64, EncodedSize)
{
ASSERT_EQ(4, wf_base64_encoded_size(1));
ASSERT_EQ(4, wf_base64_encoded_size(2));
ASSERT_EQ(4, wf_base64_encoded_size(3));
ASSERT_EQ(4, wfp_base64_encoded_size(1));
ASSERT_EQ(4, wfp_base64_encoded_size(2));
ASSERT_EQ(4, wfp_base64_encoded_size(3));
ASSERT_EQ(8, wf_base64_encoded_size(4));
ASSERT_EQ(8, wf_base64_encoded_size(5));
ASSERT_EQ(8, wf_base64_encoded_size(6));
ASSERT_EQ(8, wfp_base64_encoded_size(4));
ASSERT_EQ(8, wfp_base64_encoded_size(5));
ASSERT_EQ(8, wfp_base64_encoded_size(6));
ASSERT_EQ(120, wf_base64_encoded_size(90));
ASSERT_EQ(120, wfp_base64_encoded_size(90));
}
TEST(Base64, Encode)
@@ -19,17 +19,17 @@ TEST(Base64, Encode)
char buffer[42];
std::string in = "Hello";
size_t length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
size_t length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
ASSERT_EQ(8, length);
ASSERT_STREQ("SGVsbG8=", buffer);
in = "Hello\n";
length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
ASSERT_EQ(8, length);
ASSERT_STREQ("SGVsbG8K", buffer);
in = "Blue";
length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
ASSERT_EQ(8, length);
ASSERT_STREQ("Qmx1ZQ==", buffer);
}
@@ -39,53 +39,53 @@ TEST(Base64, FailedToEncodeBufferTooSmall)
char buffer[1];
std::string in = "Hello";
size_t length = wf_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1);
size_t length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1);
ASSERT_EQ(0, length);
}
TEST(Base64, DecodedSize)
{
std::string in = "SGVsbG8="; // Hello
size_t length = wf_base64_decoded_size(in.c_str(), in.size());
size_t length = wfp_base64_decoded_size(in.c_str(), in.size());
ASSERT_EQ(5, length);
in = "SGVsbG8K"; // Hello\n
length = wf_base64_decoded_size(in.c_str(), in.size());
length = wfp_base64_decoded_size(in.c_str(), in.size());
ASSERT_EQ(6, length);
in = "Qmx1ZQ=="; // Blue
length = wf_base64_decoded_size(in.c_str(), in.size());
length = wfp_base64_decoded_size(in.c_str(), in.size());
ASSERT_EQ(4, length);
}
TEST(Base64, IsValid)
{
std::string in = "SGVsbG8="; // Hello
ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_TRUE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "SGVsbG8K"; // Hello\n
ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_TRUE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ=="; // Blue
ASSERT_TRUE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_TRUE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ=a";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ=";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1Z===";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qmx1ZQ?=";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size()));
in = "Qm?1ZQ==";
ASSERT_FALSE(wf_base64_isvalid(in.c_str(), in.size()));
ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size()));
}
TEST(Base64, Decode)
@@ -93,19 +93,19 @@ TEST(Base64, Decode)
char buffer[42];
std::string in = "SGVsbG8="; // Hello
size_t length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
size_t length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
ASSERT_EQ(5, length);
buffer[length] = '\0';
ASSERT_STREQ("Hello", buffer);
in = "SGVsbG8K"; // Hello\n
length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
ASSERT_EQ(6, length);
buffer[length] = '\0';
ASSERT_STREQ("Hello\n", buffer);
in = "Qmx1ZQ=="; // Blue
length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
ASSERT_EQ(4, length);
buffer[length] = '\0';
ASSERT_STREQ("Blue", buffer);
@@ -116,7 +116,7 @@ TEST(Base64, FailToDecodeBufferTooSmall)
char buffer[1];
std::string in = "SGVsbG8="; // Hello
size_t length = wf_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1);
size_t length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1);
ASSERT_EQ(0, length);
}

View File

@@ -17,7 +17,7 @@ TEST(ContainerOf, FirstMember)
MyStruct my_struct = {23, 42};
int * first = &my_struct.first;
ASSERT_EQ(&my_struct, wf_container_of(first, MyStruct, first));
ASSERT_EQ(&my_struct, wfp_container_of(first, MyStruct, first));
}
TEST(ContainerOf, SecondMember)
@@ -25,5 +25,5 @@ TEST(ContainerOf, SecondMember)
MyStruct my_struct = {23, 42};
int * second = &my_struct.second;
ASSERT_EQ(&my_struct, wf_container_of(second, MyStruct, second));
ASSERT_EQ(&my_struct, wfp_container_of(second, MyStruct, second));
}

View File

@@ -2,21 +2,21 @@
#include <cstring>
#include "webfuse_provider/impl/message.h"
TEST(wf_message, create)
TEST(wfp_message, create)
{
json_t * value = json_object();
struct wf_message * message = wf_message_create(value);
struct wfp_message * message = wfp_message_create(value);
ASSERT_NE(nullptr, message);
ASSERT_EQ(2, message->length);
ASSERT_TRUE(0 == strncmp("{}", message->data, 2));
wf_message_dispose(message);
wfp_message_dispose(message);
json_decref(value);
}
TEST(wf_message, fail_to_create)
TEST(wfp_message, fail_to_create)
{
struct wf_message * message = wf_message_create(nullptr);
struct wfp_message * message = wfp_message_create(nullptr);
ASSERT_EQ(nullptr, message);
}

View File

@@ -6,11 +6,11 @@
namespace
{
struct wf_slist_item * create_message(char const * content)
struct wfp_slist_item * create_message(char const * content)
{
json_t * value = json_object();
json_object_set_new(value, "content", json_string(content));
struct wf_message * message = wf_message_create(value);
struct wfp_message * message = wfp_message_create(value);
json_decref(value);
return &message->item;
@@ -18,35 +18,35 @@ namespace
}
TEST(wf_message_queue, cleanup_empty_list)
TEST(wfp_message_queue, cleanup_empty_list)
{
struct wf_slist queue;
wf_slist_init(&queue);
struct wfp_slist queue;
wfp_slist_init(&queue);
wf_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_slist_empty(&queue));
wfp_message_queue_cleanup(&queue);
ASSERT_TRUE(wfp_slist_empty(&queue));
}
TEST(wf_message_queue, cleanup_one_element)
TEST(wfp_message_queue, cleanup_one_element)
{
struct wf_slist queue;
wf_slist_init(&queue);
struct wfp_slist queue;
wfp_slist_init(&queue);
wf_slist_append(&queue, create_message("Hello"));
wfp_slist_append(&queue, create_message("Hello"));
wf_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_slist_empty(&queue));
wfp_message_queue_cleanup(&queue);
ASSERT_TRUE(wfp_slist_empty(&queue));
}
TEST(wf_message_queue, cleanup_multiple_element)
TEST(wfp_message_queue, cleanup_multiple_element)
{
struct wf_slist queue;
wf_slist_init(&queue);
struct wfp_slist queue;
wfp_slist_init(&queue);
wf_slist_append(&queue, create_message("Hello"));
wf_slist_append(&queue, create_message("World"));
wf_slist_append(&queue, create_message("!"));
wfp_slist_append(&queue, create_message("Hello"));
wfp_slist_append(&queue, create_message("World"));
wfp_slist_append(&queue, create_message("!"));
wf_message_queue_cleanup(&queue);
ASSERT_TRUE(wf_slist_empty(&queue));
wfp_message_queue_cleanup(&queue);
ASSERT_TRUE(wfp_slist_empty(&queue));
}

View File

@@ -1,49 +1,49 @@
#include <gtest/gtest.h>
#include "webfuse_provider/impl/slist.h"
TEST(wf_slist, init)
TEST(wfp_slist, init)
{
struct wf_slist list;
wf_slist_init(&list);
struct wfp_slist list;
wfp_slist_init(&list);
ASSERT_EQ(nullptr, list.head.next);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&list.head, list.last);
ASSERT_TRUE(wf_slist_empty(&list));
ASSERT_EQ(nullptr, wf_slist_first(&list));
ASSERT_TRUE(wfp_slist_empty(&list));
ASSERT_EQ(nullptr, wfp_slist_first(&list));
}
TEST(wf_slist, append)
TEST(wfp_slist, append)
{
struct wf_slist list;
struct wf_slist_item item[3];
struct wfp_slist list;
struct wfp_slist_item item[3];
wf_slist_init(&list);
ASSERT_TRUE(wf_slist_empty(&list));
wfp_slist_init(&list);
ASSERT_TRUE(wfp_slist_empty(&list));
wf_slist_append(&list, &item[0]);
wfp_slist_append(&list, &item[0]);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[0], wfp_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[0], list.last);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(nullptr, item[0].next);
wf_slist_append(&list, &item[1]);
wfp_slist_append(&list, &item[1]);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[0], wfp_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[1], list.last);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&item[1], item[0].next);
ASSERT_EQ(nullptr, item[1].next);
wf_slist_append(&list, &item[2]);
wfp_slist_append(&list, &item[2]);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[0], wfp_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[2], list.last);
ASSERT_EQ(nullptr, list.last->next);
@@ -52,85 +52,85 @@ TEST(wf_slist, append)
ASSERT_EQ(nullptr, item[2].next);
}
TEST(wf_slist_remove_after, remove_first)
TEST(wfp_slist_remove_after, remove_first)
{
struct wf_slist list;
struct wf_slist_item item[3];
struct wfp_slist list;
struct wfp_slist_item item[3];
wf_slist_init(&list);
wf_slist_append(&list, &item[0]);
wf_slist_append(&list, &item[1]);
wf_slist_append(&list, &item[2]);
wfp_slist_init(&list);
wfp_slist_append(&list, &item[0]);
wfp_slist_append(&list, &item[1]);
wfp_slist_append(&list, &item[2]);
wf_slist_item * removed;
wfp_slist_item * removed;
removed = wf_slist_remove_first(&list);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wfp_slist_remove_first(&list);
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[0], removed);
removed = wf_slist_remove_first(&list);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wfp_slist_remove_first(&list);
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[1], removed);
removed = wf_slist_remove_first(&list);
ASSERT_TRUE(wf_slist_empty(&list));
removed = wfp_slist_remove_first(&list);
ASSERT_TRUE(wfp_slist_empty(&list));
ASSERT_EQ(&item[2], removed);
ASSERT_EQ(nullptr, list.head.next);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&list.head, list.last);
ASSERT_EQ(nullptr, wf_slist_first(&list));
ASSERT_EQ(nullptr, wfp_slist_first(&list));
}
TEST(wf_slist_remove_after, remove_last)
TEST(wfp_slist_remove_after, remove_last)
{
struct wf_slist list;
struct wf_slist_item item[3];
struct wfp_slist list;
struct wfp_slist_item item[3];
wf_slist_init(&list);
wf_slist_append(&list, &item[0]);
wf_slist_append(&list, &item[1]);
wf_slist_append(&list, &item[2]);
wfp_slist_init(&list);
wfp_slist_append(&list, &item[0]);
wfp_slist_append(&list, &item[1]);
wfp_slist_append(&list, &item[2]);
wf_slist_item * removed;
wfp_slist_item * removed;
removed = wf_slist_remove_after(&list, &item[1]);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wfp_slist_remove_after(&list, &item[1]);
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[2], removed);
removed = wf_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wfp_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[1], removed);
removed = wf_slist_remove_after(&list, &list.head);
ASSERT_TRUE(wf_slist_empty(&list));
removed = wfp_slist_remove_after(&list, &list.head);
ASSERT_TRUE(wfp_slist_empty(&list));
ASSERT_EQ(&item[0], removed);
ASSERT_EQ(nullptr, list.head.next);
ASSERT_EQ(nullptr, list.last->next);
ASSERT_EQ(&list.head, list.last);
ASSERT_EQ(nullptr, wf_slist_first(&list));
ASSERT_EQ(nullptr, wfp_slist_first(&list));
}
TEST(wf_slist_remove_after, remove_after)
TEST(wfp_slist_remove_after, remove_after)
{
struct wf_slist list;
struct wf_slist_item item[3];
struct wfp_slist list;
struct wfp_slist_item item[3];
wf_slist_init(&list);
wf_slist_append(&list, &item[0]);
wf_slist_append(&list, &item[1]);
wf_slist_append(&list, &item[2]);
wfp_slist_init(&list);
wfp_slist_append(&list, &item[0]);
wfp_slist_append(&list, &item[1]);
wfp_slist_append(&list, &item[2]);
wf_slist_item * removed;
wfp_slist_item * removed;
removed = wf_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wf_slist_empty(&list));
removed = wfp_slist_remove_after(&list, &item[0]);
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[1], removed);
ASSERT_NE(&list.head, list.last);
ASSERT_FALSE(wf_slist_empty(&list));
ASSERT_EQ(&item[0], wf_slist_first(&list));
ASSERT_FALSE(wfp_slist_empty(&list));
ASSERT_EQ(&item[0], wfp_slist_first(&list));
ASSERT_EQ(&item[0], list.head.next);
ASSERT_EQ(&item[2], list.last);
ASSERT_EQ(nullptr, list.last->next);

View File

@@ -1,30 +1,30 @@
#include <gtest/gtest.h>
#include "webfuse_provider/impl/status_intern.h"
TEST(wf_status, tostring)
TEST(wfp_status, tostring)
{
ASSERT_STREQ("Good", wf_status_tostring(WF_GOOD));
ASSERT_STREQ("Bad", wf_status_tostring(WF_BAD));
ASSERT_STREQ("Bad (not implemented)", wf_status_tostring(WF_BAD_NOTIMPLEMENTED));
ASSERT_STREQ("Bad (busy)", wf_status_tostring(WF_BAD_BUSY));
ASSERT_STREQ("Bad (timeout)", wf_status_tostring(WF_BAD_TIMEOUT));
ASSERT_STREQ("Bad (format)", wf_status_tostring(WF_BAD_FORMAT));
ASSERT_STREQ("Bad (no entry)", wf_status_tostring(WF_BAD_NOENTRY));
ASSERT_STREQ("Bad (access denied)", wf_status_tostring(WF_BAD_ACCESS_DENIED));
ASSERT_STREQ("Good", wfp_status_tostring(WFP_GOOD));
ASSERT_STREQ("Bad", wfp_status_tostring(WFP_BAD));
ASSERT_STREQ("Bad (not implemented)", wfp_status_tostring(WFP_BAD_NOTIMPLEMENTED));
ASSERT_STREQ("Bad (busy)", wfp_status_tostring(WFP_BAD_BUSY));
ASSERT_STREQ("Bad (timeout)", wfp_status_tostring(WFP_BAD_TIMEOUT));
ASSERT_STREQ("Bad (format)", wfp_status_tostring(WFP_BAD_FORMAT));
ASSERT_STREQ("Bad (no entry)", wfp_status_tostring(WFP_BAD_NOENTRY));
ASSERT_STREQ("Bad (access denied)", wfp_status_tostring(WFP_BAD_ACCESS_DENIED));
ASSERT_STREQ("Bad (unknown)", wf_status_tostring(-1));
ASSERT_STREQ("Bad (unknown)", wfp_status_tostring(-1));
}
TEST(wf_status, to_rc)
TEST(wfp_status, to_rc)
{
ASSERT_EQ(0, wf_status_to_rc(WF_GOOD));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD));
ASSERT_EQ(-ENOSYS, wf_status_to_rc(WF_BAD_NOTIMPLEMENTED));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD_BUSY));
ASSERT_EQ(-ETIMEDOUT, wf_status_to_rc(WF_BAD_TIMEOUT));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD_FORMAT));
ASSERT_EQ(-ENOENT, wf_status_to_rc(WF_BAD_NOENTRY));
ASSERT_EQ(-EACCES, wf_status_to_rc(WF_BAD_ACCESS_DENIED));
ASSERT_EQ(0, wfp_status_to_rc(WFP_GOOD));
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD));
ASSERT_EQ(-ENOSYS, wfp_status_to_rc(WFP_BAD_NOTIMPLEMENTED));
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD_BUSY));
ASSERT_EQ(-ETIMEDOUT, wfp_status_to_rc(WFP_BAD_TIMEOUT));
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD_FORMAT));
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD_NOENTRY));
ASSERT_EQ(-EACCES, wfp_status_to_rc(WFP_BAD_ACCESS_DENIED));
ASSERT_EQ(-ENOENT, wf_status_to_rc(-1));
ASSERT_EQ(-ENOENT, wfp_status_to_rc(-1));
}

View File

@@ -4,66 +4,66 @@
TEST(url, ParseWs)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost/");
struct wfp_url url;
bool result = wfp_url_init(&url, "ws://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_FALSE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
wf_url_cleanup(&url);
wfp_url_cleanup(&url);
}
TEST(url, ParswWss)
{
struct wf_url url;
bool result = wf_url_init(&url, "wss://localhost/");
struct wfp_url url;
bool result = wfp_url_init(&url, "wss://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(443, url.port);
ASSERT_TRUE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
wf_url_cleanup(&url);
wfp_url_cleanup(&url);
}
TEST(url, ParseIPAdress)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://127.0.0.1/");
struct wfp_url url;
bool result = wfp_url_init(&url, "ws://127.0.0.1/");
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_STREQ("127.0.0.1", url.host);
ASSERT_STREQ("/", url.path);
wf_url_cleanup(&url);
wfp_url_cleanup(&url);
}
TEST(url, ParsePort)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost:54321/");
struct wfp_url url;
bool result = wfp_url_init(&url, "ws://localhost:54321/");
ASSERT_TRUE(result);
ASSERT_EQ(54321, url.port);
wf_url_cleanup(&url);
wfp_url_cleanup(&url);
}
TEST(url, ParseNonEmptyPath)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost/some_path?query");
struct wfp_url url;
bool result = wfp_url_init(&url, "ws://localhost/some_path?query");
ASSERT_TRUE(result);
ASSERT_STREQ("/some_path?query", url.path);
wf_url_cleanup(&url);
wfp_url_cleanup(&url);
}
TEST(url, FailToParseUnknownProtocol)
{
struct wf_url url;
bool result = wf_url_init(&url, "unknown://localhost/");
struct wfp_url url;
bool result = wfp_url_init(&url, "unknown://localhost/");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);
@@ -72,8 +72,8 @@ TEST(url, FailToParseUnknownProtocol)
TEST(url, FailToParseMissingProtocol)
{
struct wf_url url;
bool result = wf_url_init(&url, "unknown");
struct wfp_url url;
bool result = wfp_url_init(&url, "unknown");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);
@@ -82,8 +82,8 @@ TEST(url, FailToParseMissingProtocol)
TEST(url, FailToParseMissingPath)
{
struct wf_url url;
bool result = wf_url_init(&url, "ws://localhost");
struct wfp_url url;
bool result = wfp_url_init(&url, "ws://localhost");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);

View File

@@ -5,7 +5,7 @@ TEST(jsonrpc_util, get_int)
{
json_t * object = json_object();
json_object_set_new(object, "key", json_integer(23));
int value = wf_impl_json_get_int(object, "key", 42);
int value = wfp_impl_json_get_int(object, "key", 42);
ASSERT_EQ(23, value);
json_decref(object);
@@ -13,7 +13,7 @@ TEST(jsonrpc_util, get_int)
TEST(jsonrpc_util, failed_to_get_null_object)
{
int value = wf_impl_json_get_int(nullptr, "key", 42);
int value = wfp_impl_json_get_int(nullptr, "key", 42);
ASSERT_EQ(42, value);
}
@@ -21,7 +21,7 @@ TEST(jsonrpc_util, failed_to_get_null_object)
TEST(jsonrpc_util, failed_to_get_not_object)
{
json_t * object = json_array();
int value = wf_impl_json_get_int(nullptr, "key", 42);
int value = wfp_impl_json_get_int(nullptr, "key", 42);
ASSERT_EQ(42, value);
json_decref(object);
@@ -30,7 +30,7 @@ TEST(jsonrpc_util, failed_to_get_not_object)
TEST(jsonrpc_util, failed_to_get_invalid_key)
{
json_t * object = json_object();
int value = wf_impl_json_get_int(object, "key", 42);
int value = wfp_impl_json_get_int(object, "key", 42);
ASSERT_EQ(42, value);
json_decref(object);
@@ -40,7 +40,7 @@ TEST(jsonrpc_util, failed_to_get_invalid_value_type)
{
json_t * object = json_object();
json_object_set_new(object, "key", json_string("42"));
int value = wf_impl_json_get_int(object, "key", 42);
int value = wfp_impl_json_get_int(object, "key", 42);
ASSERT_EQ(42, value);
json_decref(object);

View File

@@ -7,32 +7,32 @@
using namespace std::chrono_literals;
TEST(wf_timer_timepoint, now)
TEST(wfp_timer_timepoint, now)
{
wf_timer_timepoint start = wf_timer_timepoint_now();
wfp_timer_timepoint start = wfp_timer_timepoint_now();
std::this_thread::sleep_for(42ms);
wf_timer_timepoint end = wf_timer_timepoint_now();
wfp_timer_timepoint end = wfp_timer_timepoint_now();
ASSERT_LT(start, end);
ASSERT_LT(end, start + 500);
}
TEST(wf_timer_timepoint, in_msec)
TEST(wfp_timer_timepoint, in_msec)
{
wf_timer_timepoint now = wf_timer_timepoint_now();
wf_timer_timepoint later = wf_timer_timepoint_in_msec(42);
wfp_timer_timepoint now = wfp_timer_timepoint_now();
wfp_timer_timepoint later = wfp_timer_timepoint_in_msec(42);
ASSERT_LT(now, later);
ASSERT_LT(later, now + 500);
}
TEST(wf_timer_timepoint, elapsed)
TEST(wfp_timer_timepoint, elapsed)
{
wf_timer_timepoint now;
wfp_timer_timepoint now;
now = wf_timer_timepoint_now();
ASSERT_TRUE(wf_timer_timepoint_is_elapsed(now - 1));
now = wfp_timer_timepoint_now();
ASSERT_TRUE(wfp_timer_timepoint_is_elapsed(now - 1));
now = wf_timer_timepoint_now();
ASSERT_FALSE(wf_timer_timepoint_is_elapsed(now + 500));
now = wfp_timer_timepoint_now();
ASSERT_FALSE(wfp_timer_timepoint_is_elapsed(now + 500));
}

View File

@@ -12,7 +12,7 @@ using namespace std::chrono_literals;
extern "C"
{
void on_timeout(struct wf_timer * timer, void * user_data)
void on_timeout(struct wfp_timer * timer, void * user_data)
{
(void) timer;
@@ -21,128 +21,128 @@ extern "C"
}
}
TEST(wf_timer, init)
TEST(wfp_timer, init)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer = wfp_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wfp_timer_dispose(timer);
wfp_timer_manager_dispose(manager);
}
TEST(wf_timer, trigger)
TEST(wfp_timer, trigger)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer = wfp_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer, -1);
wf_timer_manager_check(manager);
wfp_timer_start(timer, -1);
wfp_timer_manager_check(manager);
ASSERT_TRUE(triggered);
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wfp_timer_dispose(timer);
wfp_timer_manager_dispose(manager);
}
TEST(wf_timer, trigger_on_dispose)
TEST(wfp_timer, trigger_on_dispose)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer = wfp_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer, (5 * 60 * 1000));
wfp_timer_start(timer, (5 * 60 * 1000));
wf_timer_manager_dispose(manager);
wfp_timer_manager_dispose(manager);
ASSERT_TRUE(triggered);
wf_timer_dispose(timer);
wfp_timer_dispose(timer);
}
TEST(wf_timer, cancel)
TEST(wfp_timer, cancel)
{
bool triggered = false;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer = wfp_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer, 250);
wfp_timer_start(timer, 250);
std::this_thread::sleep_for(500ms);
wf_timer_cancel(timer);
wf_timer_manager_check(manager);
wfp_timer_cancel(timer);
wfp_timer_manager_check(manager);
ASSERT_FALSE(triggered);
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wfp_timer_dispose(timer);
wfp_timer_manager_dispose(manager);
}
TEST(wf_timer, cancel_multiple_timers)
TEST(wfp_timer, cancel_multiple_timers)
{
static size_t const count = 5;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer[count];
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer[count];
bool triggered = false;
for(size_t i = 0; i < count; i++)
{
timer[i] = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wf_timer_start(timer[i], 0);
timer[i] = wfp_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered));
wfp_timer_start(timer[i], 0);
}
std::this_thread::sleep_for(10ms);
for(size_t i = 0; i < count; i++)
{
wf_timer_cancel(timer[i]);
wfp_timer_cancel(timer[i]);
}
wf_timer_manager_check(manager);
wfp_timer_manager_check(manager);
ASSERT_FALSE(triggered);
for(size_t i = 0; i < count; i++)
{
wf_timer_dispose(timer[i]);
wfp_timer_dispose(timer[i]);
}
wf_timer_manager_dispose(manager);
wfp_timer_manager_dispose(manager);
}
TEST(wf_timer, multiple_timers)
TEST(wfp_timer, multiple_timers)
{
static size_t const count = 5;
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer[count];
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer[count];
bool triggered[count];
for(size_t i = 0; i < count; i++)
{
timer[i] = wf_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered[i]));
timer[i] = wfp_timer_create(manager, &on_timeout, reinterpret_cast<void*>(&triggered[i]));
triggered[i] = false;
wf_timer_start(timer[i], (300 - (50 * i)));
wfp_timer_start(timer[i], (300 - (50 * i)));
}
for(size_t i = 0; i < count; i++)
{
std::this_thread::sleep_for(100ms);
wf_timer_manager_check(manager);
wfp_timer_manager_check(manager);
}
for(size_t i = 0; i < count; i++)
{
ASSERT_TRUE(triggered[i]);
wf_timer_dispose(timer[i]);
wfp_timer_dispose(timer[i]);
}
wf_timer_manager_dispose(manager);
wfp_timer_manager_dispose(manager);
}
TEST(wf_timer, dont_trigger_null_callback)
TEST(wfp_timer, dont_trigger_null_callback)
{
struct wf_timer_manager * manager = wf_timer_manager_create();
struct wf_timer * timer = wf_timer_create(manager, nullptr, nullptr);
struct wfp_timer_manager * manager = wfp_timer_manager_create();
struct wfp_timer * timer = wfp_timer_create(manager, nullptr, nullptr);
wf_timer_start(timer, -1);
wf_timer_manager_check(manager);
wfp_timer_start(timer, -1);
wfp_timer_manager_check(manager);
wf_timer_dispose(timer);
wf_timer_manager_dispose(manager);
wfp_timer_dispose(timer);
wfp_timer_manager_dispose(manager);
}

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_INTEGRATION_FILE_HPP
#define WF_TEST_INTEGRATION_FILE_HPP
#ifndef WFP_TEST_INTEGRATION_FILE_HPP
#define WFP_TEST_INTEGRATION_FILE_HPP
#include <string>

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_INTEGRATION_PROVIDER
#define WF_TEST_INTEGRATION_PROVIDER
#ifndef WFP_TEST_INTEGRATION_PROVIDER
#define WFP_TEST_INTEGRATION_PROVIDER
namespace webfuse_test
{

View File

@@ -9,7 +9,7 @@
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/server.h"
#define WF_PATH_MAX (100)
#define WFP_PATH_MAX (100)
extern "C"
{
@@ -22,17 +22,17 @@ static void webfuse_test_server_cleanup_mountpoint(
free(path);
}
static struct wf_mountpoint *
static struct wfp_mountpoint *
webfuse_test_server_create_mountpoint(
char const * filesystem,
void * user_data)
{
char const * base_dir = reinterpret_cast<char const*>(user_data);
char path[WF_PATH_MAX];
snprintf(path, WF_PATH_MAX, "%s/%s", base_dir, filesystem);
char path[WFP_PATH_MAX];
snprintf(path, WFP_PATH_MAX, "%s/%s", base_dir, filesystem);
mkdir(path, 0755);
struct wf_mountpoint * mountpoint = wf_mountpoint_create(path);
wf_mountpoint_set_userdata(
struct wfp_mountpoint * mountpoint = wfp_mountpoint_create(path);
wfp_mountpoint_set_userdata(
mountpoint,
reinterpret_cast<void*>(strdup(path)),
&webfuse_test_server_cleanup_mountpoint);
@@ -51,7 +51,7 @@ public:
Private()
: is_shutdown_requested(false)
{
snprintf(base_dir, WF_PATH_MAX, "%s", "/tmp/webfuse_test_integration_XXXXXX");
snprintf(base_dir, WFP_PATH_MAX, "%s", "/tmp/webfuse_test_integration_XXXXXX");
char const * result = mkdtemp(base_dir);
if (NULL == result)
{
@@ -59,19 +59,19 @@ public:
}
config = wf_server_config_create();
wf_server_config_set_port(config, 0);
wf_server_config_set_mountpoint_factory(config,
config = wfp_server_config_create();
wfp_server_config_set_port(config, 0);
wfp_server_config_set_mountpoint_factory(config,
&webfuse_test_server_create_mountpoint,
reinterpret_cast<void*>(base_dir));
wf_server_config_set_keypath(config, "server-key.pem");
wf_server_config_set_certpath(config, "server-cert.pem");
wfp_server_config_set_keypath(config, "server-key.pem");
wfp_server_config_set_certpath(config, "server-cert.pem");
server = wf_server_create(config);
server = wfp_server_create(config);
while (!wf_impl_server_is_operational(server))
while (!wfp_impl_server_is_operational(server))
{
wf_server_service(server);
wfp_server_service(server);
}
thread = std::thread(Run, this);
@@ -83,8 +83,8 @@ public:
RequestShutdown();
thread.join();
rmdir(base_dir);
wf_server_dispose(server);
wf_server_config_dispose(config);
wfp_server_dispose(server);
wfp_server_config_dispose(config);
}
bool IsShutdownRequested()
@@ -95,7 +95,7 @@ public:
std::string GetUrl(void) const
{
int const port = wf_server_get_port(server);
int const port = wfp_server_get_port(server);
std::ostringstream stream;
stream << "wss://localhost:" << port << "/";
return stream.str();
@@ -106,14 +106,14 @@ private:
{
std::lock_guard<std::mutex> lock(shutdown_lock);
is_shutdown_requested = true;
wf_server_interrupt(server);
wfp_server_interrupt(server);
}
static void Run(Server::Private * context)
{
while (!context->IsShutdownRequested())
{
wf_server_service(context->server);
wfp_server_service(context->server);
}
}
@@ -124,9 +124,9 @@ private:
public:
char base_dir[WF_PATH_MAX];
wf_server_config * config;
wf_server * server;
char base_dir[WFP_PATH_MAX];
wfp_server_config * config;
wfp_server * server;
};
Server::Server()

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_INTEGRATION_SERVER_HPP
#define WF_TEST_INTEGRATION_SERVER_HPP
#ifndef WFP_TEST_INTEGRATION_SERVER_HPP
#define WFP_TEST_INTEGRATION_SERVER_HPP
#include <string>

View File

@@ -31,7 +31,7 @@ namespace
, provider(nullptr)
{
json_object_seed(0);
wf_lwslog_disable();
wfp_lwslog_disable();
}
protected:

View File

@@ -11,16 +11,16 @@ using ::webfuse_test::TempDir;
extern "C"
{
wf_mountpoint *
wf_test_integration_lowlevel_create_mountpoint(
wfp_mountpoint *
wfp_test_integration_lowlevel_create_mountpoint(
char const *, void * user_data)
{
auto * tempDir = reinterpret_cast<TempDir*>(user_data);
return wf_mountpoint_create(tempDir->path());
return wfp_mountpoint_create(tempDir->path());
}
void
wf_test_integration_lowlevel_on_connected(
wfp_test_integration_lowlevel_on_connected(
void * user_data)
{
int * state = reinterpret_cast<int*>(user_data);
@@ -28,7 +28,7 @@ wf_test_integration_lowlevel_on_connected(
}
void
wf_test_integration_lowlevel_on_disconnected(
wfp_test_integration_lowlevel_on_disconnected(
void * user_data)
{
int * state = reinterpret_cast<int*>(user_data);
@@ -36,18 +36,18 @@ wf_test_integration_lowlevel_on_disconnected(
}
bool
wf_test_integration_lowlevel_authenticate(
struct wf_credentials const * credentials,
wfp_test_integration_lowlevel_authenticate(
struct wfp_credentials const * credentials,
void * )
{
char const * username = wf_credentials_get(credentials, "username");
char const * password = wf_credentials_get(credentials, "password");
char const * username = wfp_credentials_get(credentials, "username");
char const * password = wfp_credentials_get(credentials, "password");
return ((0 == strcmp(username, "bob")) && (0 == strcmp(password, "secret")));
}
void
wf_test_integration_lowlevel_get_credentials(
wfp_test_integration_lowlevel_get_credentials(
struct wfp_credentials * credentials,
void * )
{
@@ -60,29 +60,29 @@ wf_test_integration_lowlevel_get_credentials(
TEST(integration, lowlevel)
{
TempDir dir("wf_test");
TempDir dir("wfp_test");
wf_server_protocol * server_protocol = wf_server_protocol_create(
&wf_test_integration_lowlevel_create_mountpoint,
wfp_server_protocol * server_protocol = wfp_server_protocol_create(
&wfp_test_integration_lowlevel_create_mountpoint,
reinterpret_cast<void*>(&dir));
ASSERT_NE(nullptr, server_protocol);
wf_server_protocol_add_authenticator(server_protocol, "username",
&wf_test_integration_lowlevel_authenticate, nullptr);
wfp_server_protocol_add_authenticator(server_protocol, "username",
&wfp_test_integration_lowlevel_authenticate, nullptr);
int state = 0;
wfp_client_config * client_config = wfp_client_config_create();
ASSERT_NE(nullptr, client_config);
wfp_client_config_set_userdata(client_config, reinterpret_cast<void*>(&state));
wfp_client_config_set_onconnected(client_config, &wf_test_integration_lowlevel_on_connected);
wfp_client_config_set_ondisconnected(client_config, &wf_test_integration_lowlevel_on_disconnected);
wfp_client_config_enable_authentication(client_config, &wf_test_integration_lowlevel_get_credentials);
wfp_client_config_set_onconnected(client_config, &wfp_test_integration_lowlevel_on_connected);
wfp_client_config_set_ondisconnected(client_config, &wfp_test_integration_lowlevel_on_disconnected);
wfp_client_config_enable_authentication(client_config, &wfp_test_integration_lowlevel_get_credentials);
wfp_client_protocol * client_protocol = wfp_client_protocol_create(client_config);
ASSERT_NE(nullptr, client_protocol);
lws_protocols protocols[3];
memset(protocols, 0, 3 * sizeof(lws_protocols));
wf_server_protocol_init_lws(server_protocol, &protocols[0]);
wfp_server_protocol_init_lws(server_protocol, &protocols[0]);
wfp_client_protocol_init_lws(client_protocol, &protocols[1]);
lws_context_creation_info info;
@@ -108,5 +108,5 @@ TEST(integration, lowlevel)
wfp_client_protocol_dispose(client_protocol);
wfp_client_config_dispose(client_config);
wf_server_protocol_dispose(server_protocol);
wfp_server_protocol_dispose(server_protocol);
}

View File

@@ -34,7 +34,7 @@ class ClientProtocolFixture
public:
explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false)
{
server = new WsServer(WF_PROTOCOL_NAME_ADAPTER_SERVER);
server = new WsServer(WFP_PROTOCOL_NAME_ADAPTER_SERVER);
config = wfp_client_config_create();
client.AttachTo(config, enableAuthentication);

View File

@@ -25,10 +25,10 @@ class AdapterClient::Private
{
public:
Private(
wf_client_callback_fn * callback,
wfp_client_callback_fn * callback,
void * user_data,
std::string const & url)
: client(wf_client_create(callback, user_data))
: client(wfp_client_create(callback, user_data))
, url_(url)
, command(Command::run)
, tempdir("webfuse_adpter_client")
@@ -40,7 +40,7 @@ public:
{
ApplyCommand(Command::shutdown);
thread.join();
wf_client_dispose(client);
wfp_client_dispose(client);
}
void ApplyCommand(Command actual_command)
@@ -50,7 +50,7 @@ public:
command = actual_command;
}
wf_client_interrupt(client);
wfp_client_interrupt(client);
}
std::string GetDir()
@@ -74,19 +74,19 @@ private:
switch (actual_command)
{
case Command::run:
wf_client_service(self->client);
wfp_client_service(self->client);
break;
case Command::connect:
wf_client_connect(self->client, self->url_.c_str());
wfp_client_connect(self->client, self->url_.c_str());
break;
case Command::disconnect:
wf_client_disconnect(self->client);
wfp_client_disconnect(self->client);
break;
case Command::authenticate:
wf_client_authenticate(self->client);
wfp_client_authenticate(self->client);
break;
case Command::add_filesystem:
wf_client_add_filesystem(self->client, self->tempdir.path(), "test");
wfp_client_add_filesystem(self->client, self->tempdir.path(), "test");
break;
case Command::shutdown:
// fall-through
@@ -98,7 +98,7 @@ private:
}
}
wf_client * client;
wfp_client * client;
std::string url_;
Command command;
TempDir tempdir;
@@ -107,7 +107,7 @@ private:
};
AdapterClient::AdapterClient(
wf_client_callback_fn * callback,
wfp_client_callback_fn * callback,
void * user_data,
std::string const & url)
: d(new Private(callback, user_data, url))

View File

@@ -1,5 +1,5 @@
#ifndef WF_UTILS_ADAPTER_CLIENT_HPP
#define WF_UTILS_APAPTER_CLIENT_HPP
#ifndef WFP_UTILS_ADAPTER_CLIENT_HPP
#define WFP_UTILS_APAPTER_CLIENT_HPP
#include "webfuse/adapter/client.h"
#include <string>
@@ -13,7 +13,7 @@ class AdapterClient
AdapterClient& operator=(AdapterClient const &) = delete;
public:
AdapterClient(
wf_client_callback_fn * callback,
wfp_client_callback_fn * callback,
void * user_data,
std::string const & url);
~AdapterClient();

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_FILE_UTILS_HPP
#define WF_TEST_FILE_UTILS_HPP
#ifndef WFP_TEST_FILE_UTILS_HPP
#define WFP_TEST_FILE_UTILS_HPP
#include <string>

View File

@@ -2,9 +2,9 @@
#include <stdlib.h>
#include <string.h>
#define WF_PATH_DEFAULT_CAPACITY (8)
#define WFP_PATH_DEFAULT_CAPACITY (8)
struct wf_path
struct wfp_path
{
char * * elements;
size_t count;
@@ -12,8 +12,8 @@ struct wf_path
};
static void
wf_path_add(
struct wf_path * path,
wfp_path_add(
struct wfp_path * path,
char const * element,
size_t element_size)
{
@@ -40,32 +40,32 @@ wf_path_add(
}
}
struct wf_path *
wf_path_create(
struct wfp_path *
wfp_path_create(
char const * value)
{
struct wf_path * path = malloc(sizeof(struct wf_path));
path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY);
path->capacity = WF_PATH_DEFAULT_CAPACITY;
struct wfp_path * path = malloc(sizeof(struct wfp_path));
path->elements = malloc(sizeof(char*) * WFP_PATH_DEFAULT_CAPACITY);
path->capacity = WFP_PATH_DEFAULT_CAPACITY;
path->count = 0;
char const * remainder = value;
char const * pos = strchr(remainder, '/');
while (NULL != pos)
{
wf_path_add(path, remainder, (pos - remainder));
wfp_path_add(path, remainder, (pos - remainder));
remainder = pos + 1;
pos = strchr(remainder, '/');
}
wf_path_add(path, remainder, strlen(remainder));
wfp_path_add(path, remainder, strlen(remainder));
return path;
}
void
wf_path_dispose(
struct wf_path * path)
wfp_path_dispose(
struct wfp_path * path)
{
for(size_t i = 0; i < path->count; i++)
{
@@ -78,15 +78,15 @@ wf_path_dispose(
}
size_t
wf_path_element_count(
struct wf_path * path)
wfp_path_element_count(
struct wfp_path * path)
{
return path->count;
}
char const *
wf_path_get_element(
struct wf_path * path,
wfp_path_get_element(
struct wfp_path * path,
size_t i)
{
char const * result = NULL;
@@ -99,8 +99,8 @@ wf_path_get_element(
}
char const *
wf_path_get_filename(
struct wf_path * path)
wfp_path_get_filename(
struct wfp_path * path)
{
char const * result = NULL;

View File

@@ -1,5 +1,5 @@
#ifndef WF_PATH_H
#define WF_PATH_H
#ifndef WFP_PATH_H
#define WFP_PATH_H
#ifndef __cplusplus
#include <stddef.h>
@@ -13,28 +13,28 @@ extern "C"
{
#endif
struct wf_path;
struct wfp_path;
extern struct wf_path *
wf_path_create(
extern struct wfp_path *
wfp_path_create(
char const * value);
extern void
wf_path_dispose(
struct wf_path * path);
wfp_path_dispose(
struct wfp_path * path);
extern size_t
wf_path_element_count(
struct wf_path * path);
wfp_path_element_count(
struct wfp_path * path);
extern char const *
wf_path_get_element(
struct wf_path * path,
wfp_path_get_element(
struct wfp_path * path,
size_t i);
extern char const *
wf_path_get_filename(
struct wf_path * path);
wfp_path_get_filename(
struct wfp_path * path);
#ifdef __cplusplus
}

View File

@@ -165,16 +165,16 @@ wfp_static_filesystem_add_dir(
static size_t
wfp_static_filesystem_make_parent(
struct wfp_static_filesystem * filesystem,
struct wf_path * path)
struct wfp_path * path)
{
size_t result = WFP_STATIC_FILSYSTEM_INODE_ROOT;
size_t count = wf_path_element_count(path);
size_t count = wfp_path_element_count(path);
if (0 < count)
{
for(size_t i = 0; i < (count - 1); i++)
{
char const * name = wf_path_get_element(path, i);
char const * name = wfp_path_get_element(path, i);
result = wfp_static_filesystem_add_dir(filesystem, result, name);
}
}
@@ -217,7 +217,7 @@ static void wfp_static_filesystem_lookup(
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
wfp_respond_error(request, WFP_BAD_NOENTRY);
}
}
@@ -238,7 +238,7 @@ static void wfp_static_filesystem_getattr(
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
wfp_respond_error(request, WFP_BAD_NOENTRY);
}
}
@@ -270,7 +270,7 @@ static void wfp_static_filesystem_readdir(
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
wfp_respond_error(request, WFP_BAD_NOENTRY);
}
}
@@ -291,19 +291,19 @@ static void wfp_static_filesystem_open(
}
else
{
wfp_respond_error(request, WF_BAD_ACCESS_DENIED);
wfp_respond_error(request, WFP_BAD_ACCESS_DENIED);
}
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
wfp_respond_error(request, WFP_BAD_NOENTRY);
}
}
static void wfp_static_filesystem_read(
struct wfp_request * request,
ino_t inode,
uint32_t WF_UNUSED_PARAM(handle),
uint32_t WFP_UNUSED_PARAM(handle),
size_t offset,
size_t length,
void * user_data)
@@ -321,7 +321,7 @@ static void wfp_static_filesystem_read(
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
wfp_respond_error(request, WFP_BAD_NOENTRY);
}
}
@@ -373,14 +373,14 @@ wfp_static_filesystem_add(
char const * content,
size_t length)
{
struct wf_path * path_ = wf_path_create(path);
struct wfp_path * path_ = wfp_path_create(path);
if (NULL != path_)
{
size_t parent = wfp_static_filesystem_make_parent(filesystem, path_);
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent;
entry->is_file = true;
entry->name = strdup(wf_path_get_filename(path_));
entry->name = strdup(wfp_path_get_filename(path_));
entry->mode = mode;
entry->size = length;
entry->get_info = &wfp_static_filesystem_entry_get_info;
@@ -390,7 +390,7 @@ wfp_static_filesystem_add(
entry->content = malloc(length);
memcpy(entry->content, content, length);
wf_path_dispose(path_);
wfp_path_dispose(path_);
}
}

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_TEMPDIR_HPP
#define WF_TEST_TEMPDIR_HPP
#ifndef WFP_TEST_TEMPDIR_HPP
#define WFP_TEST_TEMPDIR_HPP
namespace webfuse_test
{

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_TIMEOUT_WATCHER_HPP
#define WF_TEST_TIMEOUT_WATCHER_HPP
#ifndef WFP_TEST_TIMEOUT_WATCHER_HPP
#define WFP_TEST_TIMEOUT_WATCHER_HPP
#include <chrono>
#include <functional>

View File

@@ -1,7 +1,7 @@
#ifndef WF_WRAP_HPP
#define WF_WRAP_HPP
#ifndef WFP_WRAP_HPP
#define WFP_WRAP_HPP
#define WF_WRAP_FUNC0( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME ) \
#define WFP_WRAP_FUNC0( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (); \
RETURN_TYPE __wrap_ ## FUNC_NAME () \
{ \
@@ -15,7 +15,7 @@
} \
}
#define WF_WRAP_FUNC1( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE ) \
#define WFP_WRAP_FUNC1( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1) \
{ \
@@ -29,7 +29,7 @@
} \
}
#define WF_WRAP_FUNC2( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE ) \
#define WFP_WRAP_FUNC2( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2) \
{ \
@@ -43,7 +43,7 @@
} \
}
#define WF_WRAP_FUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \
#define WFP_WRAP_FUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3) \
{ \
@@ -57,7 +57,7 @@
} \
}
#define WF_WRAP_FUNC4( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE ) \
#define WFP_WRAP_FUNC4( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4) \
{ \
@@ -71,7 +71,7 @@
} \
}
#define WF_WRAP_FUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \
#define WFP_WRAP_FUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5) \
{ \
@@ -85,7 +85,7 @@
} \
}
#define WF_WRAP_FUNC6( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE ) \
#define WFP_WRAP_FUNC6( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, ARG6_TYPE arg6) \
{ \
@@ -100,7 +100,7 @@
}
#define WF_WRAP_VFUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \
#define WFP_WRAP_VFUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, va_list); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, va_list args) \
{ \
@@ -114,7 +114,7 @@
} \
}
#define WF_WRAP_VFUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \
#define WFP_WRAP_VFUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, va_list); \
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, va_list args) \
{ \

View File

@@ -63,7 +63,7 @@ private:
extern "C"
{
static int wf_test_utils_ws_server_callback(
static int wfp_test_utils_ws_server_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * user,
@@ -146,12 +146,12 @@ WsServer::Private::Private(std::string const & protocol, int port)
, is_shutdown_requested(false)
, wsi_(nullptr)
{
wf_lwslog_disable();
wfp_lwslog_disable();
IServer * server = this;
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2 );
ws_protocols[0].name = protocol_.c_str();
ws_protocols[0].callback = &wf_test_utils_ws_server_callback;
ws_protocols[0].callback = &wfp_test_utils_ws_server_callback;
ws_protocols[0].per_session_data_size = 0;
ws_protocols[0].user = reinterpret_cast<void*>(server);

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_UTILS_WS_SERVER_HPP
#define WF_TEST_UTILS_WS_SERVER_HPP
#ifndef WFP_TEST_UTILS_WS_SERVER_HPP
#define WFP_TEST_UTILS_WS_SERVER_HPP
#include <jansson.h>
#include <string>

View File

@@ -26,7 +26,7 @@ public:
extern "C"
{
static int wf_test_utils_ws_server_callback(
static int wfp_test_utils_ws_server_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * user,
@@ -150,12 +150,12 @@ WsServer2::Private::Private(
, is_shutdown_requested(false)
, wsi_(nullptr)
{
wf_lwslog_disable();
wfp_lwslog_disable();
IServer * server = this;
memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2 );
ws_protocols[0].name = protocol_.c_str();
ws_protocols[0].callback = &wf_test_utils_ws_server_callback;
ws_protocols[0].callback = &wfp_test_utils_ws_server_callback;
ws_protocols[0].per_session_data_size = 0;
ws_protocols[0].user = reinterpret_cast<void*>(server);

View File

@@ -1,5 +1,5 @@
#ifndef WF_TEST_UTILS_WS_SERVER2_HPP
#define WF_TEST_UTILS_WS_SERVER2_HPP
#ifndef WFP_TEST_UTILS_WS_SERVER2_HPP
#define WFP_TEST_UTILS_WS_SERVER2_HPP
#include <jansson.h>
#include <string>