mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
07e32757f8
* removes unnecessary code * adds test of wf_status * adds tests of wf_message * adds tests of wf_message_queue * changed branch of coverage badge to display correct results * moves core tests into separate subdirectory * increases coverage of timer test * moves adapter specific tests into separate directory * moves provider specific tests into separate directory * adds tests of jsonrpc utilities * adds tests of jsonrpc request * adds test of jsonrpc response * adds tests of jsonrpc server * adds tests of jsonrpc proxy * adds integration test (found some issues) * disables problematic tests * fixes resource leak: pending timer after cleanup proxy * fixes order of cleanup to prevent processing pending requests after filesystem shut down * fixes some memcheck and helgrind errors: initialization of lws_log; setup of client and server * disabled a test * fixes error in msleep utility * fixes deadlock at IntegrationTest using valgrind * removes unit test code from coverage report * adds some integration tests * makes badge show coverage of master * fixes some coding style issues * fixes eary trigger of is_connected (provider) * fixes read error in 32 bit environments\n\ninode is always 64 bit, but variadic wf_impl_jsonrpc_proxy_invoke expects int
103 lines
2.6 KiB
C++
103 lines
2.6 KiB
C++
#include <gtest/gtest.h>
|
|
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
struct Context
|
|
{
|
|
json_t * response;
|
|
};
|
|
|
|
bool jsonrpc_send(
|
|
json_t * request,
|
|
void * user_data)
|
|
{
|
|
Context * context = reinterpret_cast<Context*>(user_data);
|
|
context->response = request;
|
|
json_incref(request);
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
TEST(jsonrpc_request, create_dispose)
|
|
{
|
|
Context context{nullptr};
|
|
void * user_data = reinterpret_cast<void*>(&context);
|
|
|
|
struct wf_impl_jsonrpc_request * request =
|
|
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
|
|
|
ASSERT_NE(nullptr, request);
|
|
ASSERT_EQ(user_data, wf_impl_jsonrpc_request_get_userdata(request));
|
|
|
|
wf_impl_jsonrpc_request_dispose(request);
|
|
}
|
|
|
|
TEST(jsonrpc_request, respond)
|
|
{
|
|
Context context{nullptr};
|
|
void * user_data = reinterpret_cast<void*>(&context);
|
|
|
|
struct wf_impl_jsonrpc_request * request =
|
|
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
|
|
|
wf_impl_jsonrpc_respond(request, json_string("okay"));
|
|
|
|
ASSERT_NE(nullptr, context.response);
|
|
|
|
|
|
json_t * response = reinterpret_cast<json_t*>(context.response);
|
|
ASSERT_TRUE(json_is_object(response));
|
|
|
|
json_t * id = json_object_get(response, "id");
|
|
ASSERT_TRUE(json_is_integer(id));
|
|
ASSERT_EQ(42, json_integer_value(id));
|
|
|
|
json_t * result = json_object_get(response, "result");
|
|
ASSERT_TRUE(json_is_string(result));
|
|
ASSERT_STREQ("okay", json_string_value(result));
|
|
|
|
ASSERT_EQ(nullptr, json_object_get(response, "error"));
|
|
|
|
json_decref(response);
|
|
}
|
|
|
|
TEST(jsonrpc_request, respond_error)
|
|
{
|
|
Context context{nullptr};
|
|
void * user_data = reinterpret_cast<void*>(&context);
|
|
|
|
struct wf_impl_jsonrpc_request * request =
|
|
wf_impl_jsonrpc_request_create(42, &jsonrpc_send, user_data);
|
|
|
|
wf_impl_jsonrpc_respond_error(request, WF_BAD);
|
|
|
|
ASSERT_NE(nullptr, context.response);
|
|
|
|
|
|
json_t * response = reinterpret_cast<json_t*>(context.response);
|
|
ASSERT_TRUE(json_is_object(response));
|
|
|
|
json_t * id = json_object_get(response, "id");
|
|
ASSERT_TRUE(json_is_integer(id));
|
|
ASSERT_EQ(42, json_integer_value(id));
|
|
|
|
ASSERT_EQ(nullptr, json_object_get(response, "result"));
|
|
|
|
json_t * err = json_object_get(response, "error");
|
|
ASSERT_TRUE(json_is_object(err));
|
|
|
|
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));
|
|
|
|
json_t * err_message = json_object_get(err, "message");
|
|
ASSERT_TRUE(json_is_string(err_message));
|
|
ASSERT_STREQ("Bad", json_string_value(err_message));
|
|
|
|
json_decref(response);
|
|
}
|