From 86c41d73592cdeb3d57dd489fb843521be25feeb Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 27 Apr 2019 17:11:18 +0200 Subject: [PATCH] adds tests of jsonrpc utilities --- CMakeLists.txt | 1 + test/adapter/jsonrpc/test_util.cc | 47 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/adapter/jsonrpc/test_util.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index fb49146..34c9d3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,6 +307,7 @@ add_executable(alltests test/adapter/test_credentials.cc test/adapter/test_authenticator.cc test/adapter/test_authenticators.cc + test/adapter/jsonrpc/test_util.cc test/adapter/test_fuse_req.cc test/provider/test_url.cc test/provider/test_static_filesystem.cc diff --git a/test/adapter/jsonrpc/test_util.cc b/test/adapter/jsonrpc/test_util.cc new file mode 100644 index 0000000..562b7c4 --- /dev/null +++ b/test/adapter/jsonrpc/test_util.cc @@ -0,0 +1,47 @@ +#include +#include "webfuse/adapter/impl/jsonrpc/util.h" + +TEST(jsonrpc_util, get_int) +{ + json_t * object = json_object(); + json_object_set_new(object, "key", json_integer(23)); + int value = wf_impl_json_get_int(object, "key", 42); + ASSERT_EQ(23, value); + + json_decref(object); +} + +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) +{ + json_t * object = json_array(); + int value = wf_impl_json_get_int(nullptr, "key", 42); + ASSERT_EQ(42, value); + + json_decref(object); +} + +TEST(jsonrpc_util, failed_to_get_invalid_key) +{ + json_t * object = json_object(); + int value = wf_impl_json_get_int(object, "key", 42); + 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")); + int value = wf_impl_json_get_int(object, "key", 42); + ASSERT_EQ(42, value); + + json_decref(object); +} \ No newline at end of file