2019-05-19 12:33:42 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/jsonrpc/request.h"
|
|
|
|
#include "webfuse_provider/status.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Context
|
|
|
|
{
|
|
|
|
json_t * response;
|
|
|
|
};
|
|
|
|
|
2020-07-10 19:41:10 +00:00
|
|
|
void jsonrpc_send(
|
2019-05-19 12:33:42 +00:00
|
|
|
json_t * request,
|
|
|
|
void * user_data)
|
|
|
|
{
|
|
|
|
Context * context = reinterpret_cast<Context*>(user_data);
|
|
|
|
context->response = request;
|
|
|
|
json_incref(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_request, is_request_object_params)
|
2020-03-22 12:36:03 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_TRUE(wfp_jsonrpc_is_request(request));
|
2020-03-22 12:36:03 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_request, is_request_fail_missing_params)
|
2020-03-22 12:36:03 +00:00
|
|
|
{
|
|
|
|
json_t * request = json_object();
|
|
|
|
json_object_set_new(request, "method", json_string("some_method"));
|
|
|
|
json_object_set_new(request, "id", json_integer(42));
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
|
2020-03-22 12:36:03 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_request, is_request_fail_params_wrong_type)
|
2020-03-22 12:36:03 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(request));
|
2020-03-22 12:36:03 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|