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_provider/jsonrpc/test_is_request.cc

75 lines
1.9 KiB
C++
Raw Normal View History

2020-06-16 21:39:45 +00:00
#include "webfuse_provider/impl/jsonrpc/request.h"
#include "webfuse_provider/test_util/json_doc.hpp"
#include <gtest/gtest.h>
using webfuse_test::JsonDoc;
TEST(wfp_jsonrpc_is_request, request_with_object_params)
{
JsonDoc doc("{\"method\": \"method\", \"params\": {}, \"id\": 42}");
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, request_with_array_params)
{
JsonDoc doc("{\"method\": \"method\", \"params\": [], \"id\": 42}");
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, null_request)
{
ASSERT_FALSE(wfp_jsonrpc_is_request(nullptr));
}
TEST(wfp_jsonrpc_is_request, invalid_request)
{
JsonDoc doc("[\"method\", { }, 42]");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, invalid_request_without_id)
{
JsonDoc doc("{\"method\": \"method\", \"params\": { }}");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_id)
{
JsonDoc doc("{\"method\": \"method\", \"params\": { }, \"id\": \"42\"}");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, invalid_request_without_method)
{
JsonDoc doc("{\"params\": { }, \"id\": 42}");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_method)
{
JsonDoc doc("{\"method\": 42, \"params\": {}, \"id\": 42}");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, invalid_request_without_params)
{
JsonDoc doc("{\"method\": \"method\", \"id\": 42}");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_params)
{
JsonDoc doc("{\"method\": \"method\", \"params\": \"params\", \"id\": 42}");
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
}