2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/jsonrpc/response_intern.h"
|
2020-07-11 22:39:55 +00:00
|
|
|
#include "webfuse_provider/impl/jsonrpc/error.h"
|
|
|
|
#include "webfuse_provider/impl/json/parser.h"
|
2019-02-13 19:49:05 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
#include <gtest/gtest.h>
|
2019-01-27 02:45:03 +00:00
|
|
|
|
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
TEST(response_parser, fail_no_object)
|
2019-01-27 02:45:03 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "[]";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_jsonrpc_response response;
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
2019-01-27 02:45:03 +00:00
|
|
|
|
2020-02-28 22:17:41 +00:00
|
|
|
ASSERT_NE(nullptr, response.error);
|
2019-01-27 02:45:03 +00:00
|
|
|
ASSERT_EQ(-1, response.id);
|
2019-01-30 20:53:57 +00:00
|
|
|
ASSERT_EQ(nullptr, response.result);
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_jsonrpc_response_cleanup(&response);
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(response_error, fail_empty_object)
|
|
|
|
{
|
|
|
|
char text[] = "{}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
|
|
|
struct wfp_jsonrpc_response response;
|
|
|
|
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
2019-01-27 02:45:03 +00:00
|
|
|
|
2020-02-28 22:17:41 +00:00
|
|
|
ASSERT_NE(nullptr, response.error);
|
2019-01-27 02:45:03 +00:00
|
|
|
ASSERT_EQ(-1, response.id);
|
2019-01-30 20:53:57 +00:00
|
|
|
ASSERT_EQ(nullptr, response.result);
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_jsonrpc_response_cleanup(&response);
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(response_error, fail_no_data)
|
|
|
|
{
|
|
|
|
char text[] = "{\"id\":42}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
|
|
|
struct wfp_jsonrpc_response response;
|
|
|
|
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
2019-01-27 02:45:03 +00:00
|
|
|
|
2020-02-28 22:17:41 +00:00
|
|
|
ASSERT_NE(nullptr, response.error);
|
2019-01-27 02:45:03 +00:00
|
|
|
ASSERT_EQ(42, response.id);
|
2019-01-30 20:53:57 +00:00
|
|
|
ASSERT_EQ(nullptr, response.result);
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_jsonrpc_response_cleanup(&response);
|
2020-07-11 22:39:55 +00:00
|
|
|
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);
|
|
|
|
struct wfp_jsonrpc_response response;
|
|
|
|
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
2019-01-27 02:45:03 +00:00
|
|
|
|
2020-02-28 22:17:41 +00:00
|
|
|
ASSERT_NE(nullptr, response.error);
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_EQ(42, response.error->code);
|
2019-01-27 02:45:03 +00:00
|
|
|
ASSERT_EQ(42, response.id);
|
2019-01-30 20:53:57 +00:00
|
|
|
ASSERT_EQ(nullptr, response.result);
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_jsonrpc_response_cleanup(&response);
|
2020-07-11 22:39:55 +00:00
|
|
|
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);
|
|
|
|
struct wfp_jsonrpc_response response;
|
|
|
|
wfp_jsonrpc_response_init(&response, wfp_impl_json_root(doc));
|
2019-01-27 02:45:03 +00:00
|
|
|
|
2020-03-01 16:44:12 +00:00
|
|
|
ASSERT_EQ(nullptr, response.error);
|
2019-01-27 02:45:03 +00:00
|
|
|
ASSERT_EQ(42, response.id);
|
2019-01-30 20:53:57 +00:00
|
|
|
ASSERT_NE(nullptr, response.result);
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_jsonrpc_response_cleanup(&response);
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-01-27 02:45:03 +00:00
|
|
|
}
|