2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/util/json_util.h"
|
2020-07-18 21:16:18 +00:00
|
|
|
#include "webfuse/test_util/json_doc.hpp"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
using webfuse_test::JsonDoc;
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
TEST(jsonrpc_util, get_int)
|
|
|
|
{
|
2020-07-18 21:16:18 +00:00
|
|
|
JsonDoc doc("{\"key\": 23}");
|
|
|
|
int value = wf_impl_json_get_int(doc.root(), "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(23, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_null_object)
|
|
|
|
{
|
|
|
|
int value = wf_impl_json_get_int(nullptr, "key", 42);
|
|
|
|
|
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_not_object)
|
|
|
|
{
|
2020-07-18 21:16:18 +00:00
|
|
|
JsonDoc doc("[]");
|
|
|
|
int value = wf_impl_json_get_int(doc.root(), "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_invalid_key)
|
|
|
|
{
|
2020-07-18 21:16:18 +00:00
|
|
|
JsonDoc doc("{}");
|
|
|
|
int value = wf_impl_json_get_int(doc.root(), "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(jsonrpc_util, failed_to_get_invalid_value_type)
|
|
|
|
{
|
2020-07-18 21:16:18 +00:00
|
|
|
JsonDoc doc("{\"key\": \"42\"}");
|
|
|
|
int value = wf_impl_json_get_int(doc.root(), "key", 42);
|
2019-05-19 12:33:42 +00:00
|
|
|
ASSERT_EQ(42, value);
|
|
|
|
}
|