2019-05-19 12:33:42 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/jsonrpc/request.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, request_with_object_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, request_with_array_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_TRUE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, null_request)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(nullptr));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request_without_id)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
json_t * request = json_object();
|
|
|
|
json_object_set_new(request, "method", json_string("method"));
|
|
|
|
json_object_set_new(request, "params", json_object());
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_id)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
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"));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request_without_method)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
json_t * request = json_object();
|
|
|
|
json_object_set_new(request, "params", json_object());
|
|
|
|
json_object_set_new(request, "id", json_integer(42));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_method)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request_without_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
json_t * request = json_object();
|
|
|
|
json_object_set_new(request, "method", json_string("method"));
|
|
|
|
json_object_set_new(request, "id", json_integer(42));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|
|
|
|
|
2020-03-01 15:55:58 +00:00
|
|
|
TEST(wf_jsonrpc_is_request, invalid_request_due_to_invalid_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_jsonrpc_is_request(request));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(request);
|
|
|
|
}
|