2019-05-19 12:33:42 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/jsonrpc/response.h"
|
2020-07-11 22:39:55 +00:00
|
|
|
#include "webfuse_provider/impl/json/parser.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, valid_result)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"result\": {}, \"id\": 42}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, valid_result_string)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"result\": \"also valid\", \"id\": 42}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, valid_error)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"error\": { }, \"id\": 42}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_TRUE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, invalid_null)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_response(nullptr));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, invalid_message)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "[{ }, 42]";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, invalid_missing_id)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"result\": { } }";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, invalid_id_wrong_type)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"result\": { }, \"id\": \"42\"}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, invalid_missing_result_and_error)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"id\": \"42\"}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_response, invalid_error_wrong_type)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-11 22:39:55 +00:00
|
|
|
char text[] = "{\"error\": [], \"id\": \"42\"}";
|
|
|
|
wfp_json_doc * doc = wfp_impl_json_parse(text);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_response(wfp_impl_json_root(doc)));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-11 22:39:55 +00:00
|
|
|
wfp_impl_json_dispose(doc);
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|