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/adapter/jsonrpc/test_is_response.cc

95 lines
2.3 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
#include "webfuse/adapter/impl/jsonrpc/response.h"
TEST(jsonrpc_is_response, valid_result)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, valid_result_string)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_string("also valid"));
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, valid_error)
{
json_t * message = json_object();
json_object_set_new(message, "error", json_object());
json_object_set_new(message, "id", json_integer(42));
ASSERT_TRUE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, invalid_null)
{
ASSERT_FALSE(wf_impl_jsonrpc_is_response(nullptr));
}
TEST(jsonrpc_is_response, invalid_message)
{
json_t * message = json_array();
json_array_append_new(message, json_object());
json_array_append_new(message, json_integer(42));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, invalid_missing_id)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, invalid_id_wrong_type)
{
json_t * message = json_object();
json_object_set_new(message, "result", json_object());
json_object_set_new(message, "id", json_string("42"));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, invalid_missing_result_and_error)
{
json_t * message = json_object();
json_object_set_new(message, "id", json_integer(42));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}
TEST(jsonrpc_is_response, invalid_error_wrong_type)
{
json_t * message = json_object();
json_object_set_new(message, "error", json_array());
json_object_set_new(message, "id", json_integer(42));
ASSERT_FALSE(wf_impl_jsonrpc_is_response(message));
json_decref(message);
}