1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/test/webfuse/tests/adapter/jsonrpc/test_is_request.cc

113 lines
3.2 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include "webfuse/adapter/impl/jsonrpc/request.h"
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(jsonrpc_is_request, null_request)
{
ASSERT_FALSE(wf_impl_jsonrpc_is_request(nullptr));
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}
TEST(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_impl_jsonrpc_is_request(request));
json_decref(request);
}