2019-05-19 12:33:42 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-21 19:18:43 +00:00
|
|
|
#include "webfuse_provider/impl/util/json_util.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
TEST(jsonrpc_util, get_int)
|
|
|
|
{
|
|
|
|
json_t * object = json_object();
|
|
|
|
json_object_set_new(object, "key", json_integer(23));
|
2020-06-16 21:57:41 +00:00
|
|
|
int value = wfp_impl_json_get_int(object, "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(23, value);
|
|
|
|
|
|
|
|
json_decref(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_null_object)
|
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
int value = wfp_impl_json_get_int(nullptr, "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_not_object)
|
|
|
|
{
|
|
|
|
json_t * object = json_array();
|
2020-06-16 21:57:41 +00:00
|
|
|
int value = wfp_impl_json_get_int(nullptr, "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
|
|
|
|
json_decref(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_invalid_key)
|
|
|
|
{
|
|
|
|
json_t * object = json_object();
|
2020-06-16 21:57:41 +00:00
|
|
|
int value = wfp_impl_json_get_int(object, "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
|
|
|
|
json_decref(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_invalid_value_type)
|
|
|
|
{
|
|
|
|
json_t * object = json_object();
|
|
|
|
json_object_set_new(object, "key", json_string("42"));
|
2020-06-16 21:57:41 +00:00
|
|
|
int value = wfp_impl_json_get_int(object, "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
|
|
|
|
json_decref(object);
|
2020-06-21 19:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, get_status_good_if_no_error)
|
|
|
|
{
|
|
|
|
json_t * error = nullptr;
|
|
|
|
wfp_status status = wfp_impl_jsonrpc_get_status(error);
|
|
|
|
ASSERT_EQ(WFP_GOOD, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, get_status)
|
|
|
|
{
|
|
|
|
json_t * error = json_object();
|
|
|
|
json_object_set_new(error, "code", json_integer(WFP_BAD_BUSY));
|
|
|
|
wfp_status status = wfp_impl_jsonrpc_get_status(error);
|
|
|
|
ASSERT_EQ(WFP_BAD_BUSY, status);
|
|
|
|
json_decref(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, get_status_bad_format)
|
|
|
|
{
|
|
|
|
json_t * error = json_array();
|
|
|
|
json_array_append_new(error, json_integer(WFP_BAD_BUSY));
|
|
|
|
wfp_status status = wfp_impl_jsonrpc_get_status(error);
|
|
|
|
ASSERT_EQ(WFP_BAD_FORMAT, status);
|
|
|
|
json_decref(error);
|
|
|
|
}
|