mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: simlify usage of wfp_json_doc in unit tests
This commit is contained in:
@@ -1,26 +1,22 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/request.h"
|
||||
#include "webfuse_provider/impl/json/parser.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)
|
||||
{
|
||||
char text[] = "{\"method\": \"method\", \"params\": {}, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"method\", \"params\": {}, \"id\": 42}");
|
||||
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, request_with_array_params)
|
||||
{
|
||||
char text[] = "{\"method\": \"method\", \"params\": [], \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"method\", \"params\": [], \"id\": 42}");
|
||||
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, null_request)
|
||||
@@ -30,70 +26,49 @@ TEST(wfp_jsonrpc_is_request, null_request)
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request)
|
||||
{
|
||||
char text[] = "[\"method\", { }, 42]";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("[\"method\", { }, 42]");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request_without_id)
|
||||
{
|
||||
char text[] = "{\"method\": \"method\", \"params\": { }}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"method\", \"params\": { }}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_id)
|
||||
{
|
||||
char text[] = "{\"method\": \"method\", \"params\": { }, \"id\": \"42\"}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"method\", \"params\": { }, \"id\": \"42\"}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request_without_method)
|
||||
{
|
||||
char text[] = "{\"params\": { }, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"params\": { }, \"id\": 42}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_method)
|
||||
{
|
||||
char text[] = "{\"method\": 42, \"params\": {}, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": 42, \"params\": {}, \"id\": 42}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request_without_params)
|
||||
{
|
||||
char text[] = "{\"method\": \"method\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"method\", \"id\": 42}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_params)
|
||||
{
|
||||
char text[] = "{\"method\": \"method\", \"params\": \"params\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"method\", \"params\": \"params\", \"id\": 42}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
@@ -1,35 +1,28 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/jsonrpc/response.h"
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
#include "webfuse_provider/test_util/json_doc.hpp"
|
||||
|
||||
using webfuse_test::JsonDoc;
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, valid_result)
|
||||
{
|
||||
char text[] = "{\"result\": {}, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": {}, \"id\": 42}");
|
||||
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, valid_result_string)
|
||||
{
|
||||
char text[] = "{\"result\": \"also valid\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": \"also valid\", \"id\": 42}");
|
||||
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, valid_error)
|
||||
{
|
||||
char text[] = "{\"error\": { }, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\": { }, \"id\": 42}");
|
||||
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, invalid_null)
|
||||
@@ -39,51 +32,36 @@ TEST(wfp_jsonrpc_is_response, invalid_null)
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, invalid_message)
|
||||
{
|
||||
char text[] = "[{ }, 42]";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("[{ }, 42]");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, invalid_missing_id)
|
||||
{
|
||||
char text[] = "{\"result\": { } }";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": { } }");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, invalid_id_wrong_type)
|
||||
{
|
||||
char text[] = "{\"result\": { }, \"id\": \"42\"}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": { }, \"id\": \"42\"}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, invalid_missing_result_and_error)
|
||||
{
|
||||
char text[] = "{\"id\": \"42\"}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"id\": \"42\"}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_is_response, invalid_error_wrong_type)
|
||||
{
|
||||
char text[] = "{\"error\": [], \"id\": \"42\"}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\": [], \"id\": \"42\"}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_response(doc.root()));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/error.h"
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
#include "webfuse_provider/status.h"
|
||||
#include "webfuse_provider/impl/timer/manager.h"
|
||||
|
||||
#include "webfuse_provider/jsonrpc/mock_timer.hpp"
|
||||
#include "webfuse_provider/test_util/json_doc.hpp"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using wfp_jsonrpc_test::MockTimer;
|
||||
using webfuse_test::JsonDoc;
|
||||
using testing::Return;
|
||||
using testing::_;
|
||||
using testing::DoAll;
|
||||
@@ -188,11 +189,8 @@ TEST(wfp_jsonrpc_proxy, on_result)
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
|
||||
char response_text[] = "{\"result\": \"okay\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(response_text);
|
||||
|
||||
wfp_jsonrpc_proxy_onresult(proxy, wfp_impl_json_root(doc));
|
||||
wfp_impl_json_dispose(doc);
|
||||
JsonDoc doc("{\"result\": \"okay\", \"id\": 42}");
|
||||
wfp_jsonrpc_proxy_onresult(proxy, doc.root());
|
||||
|
||||
ASSERT_TRUE(finished_context.is_called);
|
||||
ASSERT_EQ(nullptr, finished_context.error);
|
||||
@@ -216,11 +214,8 @@ TEST(wfp_jsonrpc_proxy, on_result_reject_response_with_unknown_id)
|
||||
|
||||
ASSERT_TRUE(send_context.is_called);
|
||||
|
||||
char response_text[] = "{\"result\": \"okay\", \"id\": 1234}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(response_text);
|
||||
|
||||
wfp_jsonrpc_proxy_onresult(proxy, wfp_impl_json_root(doc));
|
||||
wfp_impl_json_dispose(doc);
|
||||
JsonDoc doc("{\"result\": \"okay\", \"id\": 1234}");
|
||||
wfp_jsonrpc_proxy_onresult(proxy, doc.root());
|
||||
|
||||
ASSERT_FALSE(finished_context.is_called);
|
||||
|
||||
@@ -340,11 +335,8 @@ TEST(wfp_jsonrpc_proxy, on_result_swallow_if_no_request_pending)
|
||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
||||
|
||||
char response_text[] = "{\"result\": \"okay\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(response_text);
|
||||
|
||||
wfp_jsonrpc_proxy_onresult(proxy, wfp_impl_json_root(doc));
|
||||
wfp_impl_json_dispose(doc);
|
||||
JsonDoc doc("{\"result\": \"okay\", \"id\": 42}");
|
||||
wfp_jsonrpc_proxy_onresult(proxy, doc.root());
|
||||
|
||||
wfp_jsonrpc_proxy_dispose(proxy);
|
||||
wfp_timer_manager_dispose(timer_manager);
|
||||
|
||||
@@ -1,33 +1,26 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/request.h"
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
#include "webfuse_provider/test_util/json_doc.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::JsonDoc;
|
||||
|
||||
TEST(wfp_jsonrpc_request, is_request_object_params)
|
||||
{
|
||||
char text[] = "{\"method\": \"some_method\", \"params\": { }, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"some_method\", \"params\": { }, \"id\": 42}");
|
||||
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_request, is_request_fail_missing_params)
|
||||
{
|
||||
char text[] = "{\"method\": \"some_method\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"some_method\", \"id\": 42}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
TEST(wfp_jsonrpc_request, is_request_fail_params_wrong_type)
|
||||
{
|
||||
char text[] = "{\"method\": \"some_method\", \"params\": \"invalid_params\", \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"method\": \"some_method\", \"params\": \"invalid_params\", \"id\": 42}");
|
||||
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(wfp_impl_json_root(doc)));
|
||||
|
||||
wfp_impl_json_dispose(doc);
|
||||
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/jsonrpc/response_intern.h"
|
||||
#include "webfuse_provider/status.h"
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
#include "webfuse_provider/test_util/json_doc.hpp"
|
||||
#include "webfuse_provider/impl/json/node.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/error.h"
|
||||
|
||||
using webfuse_test::JsonDoc;
|
||||
|
||||
TEST(wfp_json_response, init_result)
|
||||
{
|
||||
char text[] = "{\"result\": 47, \"id\": 11}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": 47, \"id\": 11}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response,doc.root());
|
||||
|
||||
ASSERT_EQ(nullptr, response.error);
|
||||
ASSERT_TRUE(wfp_impl_json_is_int(response.result));
|
||||
@@ -19,16 +20,14 @@ TEST(wfp_json_response, init_result)
|
||||
ASSERT_EQ(11, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_error)
|
||||
{
|
||||
char text[] = "{\"error\": {\"code\": 42, \"message\": \"Don't Panic!\"}, \"id\": 23}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\": {\"code\": 42, \"message\": \"Don't Panic!\"}, \"id\": 23}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(42, response.error->code);
|
||||
ASSERT_STREQ("Don't Panic!", response.error->message);
|
||||
@@ -36,101 +35,88 @@ TEST(wfp_json_response, init_error)
|
||||
ASSERT_EQ(23, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_fail_missing_result_and_error)
|
||||
{
|
||||
char text[] = "{\"id\": 12}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"id\": 12}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(12, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_fail_missing_id)
|
||||
{
|
||||
char text[] = "{\"result\": 47}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": 47}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_fail_wrong_id_type)
|
||||
{
|
||||
char text[] = "{\"result\": 47, \"id\": \"42\"}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": 47, \"id\": \"42\"}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_fail_error_missing_code)
|
||||
{
|
||||
char text[] = "{\"error\": {\"message\": \"Don't Panic!\"}, \"id\": 23}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\": {\"message\": \"Don't Panic!\"}, \"id\": 23}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(WFP_BAD_FORMAT,response.error->code);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(23, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_fail_error_wrong_code_type)
|
||||
{
|
||||
char text[] = "{\"error\": {\"code\": \"42\", \"message\": \"Don't Panic!\"}, \"id\": 23}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\": {\"code\": \"42\", \"message\": \"Don't Panic!\"}, \"id\": 23}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(23, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(wfp_json_response, init_fail_error_wrong_type)
|
||||
{
|
||||
char text[] = "{\"error\": \"invalid error type\", \"id\": 23}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\": \"invalid error type\", \"id\": 23}");
|
||||
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(WFP_BAD_FORMAT, response.error->code);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
ASSERT_EQ(23, response.id);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
@@ -1,61 +1,55 @@
|
||||
#include "webfuse_provider/impl/jsonrpc/response_intern.h"
|
||||
#include "webfuse_provider/impl/jsonrpc/error.h"
|
||||
#include "webfuse_provider/impl/json/parser.h"
|
||||
#include "webfuse_provider/test_util/json_doc.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::JsonDoc;
|
||||
|
||||
TEST(response_parser, fail_no_object)
|
||||
{
|
||||
char text[] = "[]";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("[]");
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(response_error, fail_empty_object)
|
||||
{
|
||||
char text[] = "{}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{}");
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(response_error, fail_no_data)
|
||||
{
|
||||
char text[] = "{\"id\":42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"id\":42}");
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(response_error, fail_with_custom_error_code)
|
||||
{
|
||||
char text[] = "{\"error\":{\"code\": 42}, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"error\":{\"code\": 42}, \"id\": 42}");
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_NE(nullptr, response.error);
|
||||
ASSERT_EQ(42, response.error->code);
|
||||
@@ -63,20 +57,17 @@ TEST(response_error, fail_with_custom_error_code)
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
TEST(response_parser, fail_invalid_response)
|
||||
{
|
||||
char text[] = "{\"result\": true, \"id\": 42}";
|
||||
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
||||
JsonDoc doc("{\"result\": true, \"id\": 42}");
|
||||
struct wfp_jsonrpc_response response;
|
||||
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
||||
wfp_jsonrpc_response_init(&response, doc.root());
|
||||
|
||||
ASSERT_EQ(nullptr, response.error);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
|
||||
wfp_jsonrpc_response_cleanup(&response);
|
||||
wfp_impl_json_dispose(doc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user