mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: changed directory structure
This commit is contained in:
122
test/webfuse_provider/util/test_base64.cc
Normal file
122
test/webfuse_provider/util/test_base64.cc
Normal file
@@ -0,0 +1,122 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/util/base64.h"
|
||||
|
||||
TEST(Base64, EncodedSize)
|
||||
{
|
||||
ASSERT_EQ(4, wfp_impl_base64_encoded_size(1));
|
||||
ASSERT_EQ(4, wfp_impl_base64_encoded_size(2));
|
||||
ASSERT_EQ(4, wfp_impl_base64_encoded_size(3));
|
||||
|
||||
ASSERT_EQ(8, wfp_impl_base64_encoded_size(4));
|
||||
ASSERT_EQ(8, wfp_impl_base64_encoded_size(5));
|
||||
ASSERT_EQ(8, wfp_impl_base64_encoded_size(6));
|
||||
|
||||
ASSERT_EQ(120, wfp_impl_base64_encoded_size(90));
|
||||
}
|
||||
|
||||
TEST(Base64, Encode)
|
||||
{
|
||||
char buffer[42];
|
||||
|
||||
std::string in = "Hello";
|
||||
size_t length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
|
||||
ASSERT_EQ(8, length);
|
||||
ASSERT_STREQ("SGVsbG8=", buffer);
|
||||
|
||||
in = "Hello\n";
|
||||
length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
|
||||
ASSERT_EQ(8, length);
|
||||
ASSERT_STREQ("SGVsbG8K", buffer);
|
||||
|
||||
in = "Blue";
|
||||
length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42);
|
||||
ASSERT_EQ(8, length);
|
||||
ASSERT_STREQ("Qmx1ZQ==", buffer);
|
||||
}
|
||||
|
||||
TEST(Base64, FailedToEncodeBufferTooSmall)
|
||||
{
|
||||
char buffer[1];
|
||||
|
||||
std::string in = "Hello";
|
||||
size_t length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1);
|
||||
ASSERT_EQ(0, length);
|
||||
}
|
||||
|
||||
TEST(Base64, DecodedSize)
|
||||
{
|
||||
std::string in = "SGVsbG8="; // Hello
|
||||
size_t length = wfp_impl_base64_decoded_size(in.c_str(), in.size());
|
||||
ASSERT_EQ(5, length);
|
||||
|
||||
in = "SGVsbG8K"; // Hello\n
|
||||
length = wfp_impl_base64_decoded_size(in.c_str(), in.size());
|
||||
ASSERT_EQ(6, length);
|
||||
|
||||
in = "Qmx1ZQ=="; // Blue
|
||||
length = wfp_impl_base64_decoded_size(in.c_str(), in.size());
|
||||
ASSERT_EQ(4, length);
|
||||
}
|
||||
|
||||
TEST(Base64, IsValid)
|
||||
{
|
||||
std::string in = "SGVsbG8="; // Hello
|
||||
ASSERT_TRUE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "SGVsbG8K"; // Hello\n
|
||||
ASSERT_TRUE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qmx1ZQ=="; // Blue
|
||||
ASSERT_TRUE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qmx1ZQ=a";
|
||||
ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qmx1ZQ";
|
||||
ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qmx1ZQ=";
|
||||
ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qmx1Z===";
|
||||
ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qmx1ZQ?=";
|
||||
ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
|
||||
in = "Qm?1ZQ==";
|
||||
ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size()));
|
||||
}
|
||||
|
||||
TEST(Base64, Decode)
|
||||
{
|
||||
char buffer[42];
|
||||
|
||||
std::string in = "SGVsbG8="; // Hello
|
||||
size_t length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
|
||||
ASSERT_EQ(5, length);
|
||||
buffer[length] = '\0';
|
||||
ASSERT_STREQ("Hello", buffer);
|
||||
|
||||
in = "SGVsbG8K"; // Hello\n
|
||||
length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
|
||||
ASSERT_EQ(6, length);
|
||||
buffer[length] = '\0';
|
||||
ASSERT_STREQ("Hello\n", buffer);
|
||||
|
||||
in = "Qmx1ZQ=="; // Blue
|
||||
length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42);
|
||||
ASSERT_EQ(4, length);
|
||||
buffer[length] = '\0';
|
||||
ASSERT_STREQ("Blue", buffer);
|
||||
}
|
||||
|
||||
TEST(Base64, FailToDecodeBufferTooSmall)
|
||||
{
|
||||
char buffer[1];
|
||||
|
||||
std::string in = "SGVsbG8="; // Hello
|
||||
size_t length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1);
|
||||
ASSERT_EQ(0, length);
|
||||
}
|
||||
|
||||
29
test/webfuse_provider/util/test_container_of.cc
Normal file
29
test/webfuse_provider/util/test_container_of.cc
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/util/container_of.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct MyStruct
|
||||
{
|
||||
int first;
|
||||
int second;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
TEST(ContainerOf, FirstMember)
|
||||
{
|
||||
MyStruct my_struct = {23, 42};
|
||||
|
||||
int * first = &my_struct.first;
|
||||
ASSERT_EQ(&my_struct, wfp_container_of(first, MyStruct, first));
|
||||
}
|
||||
|
||||
TEST(ContainerOf, SecondMember)
|
||||
{
|
||||
MyStruct my_struct = {23, 42};
|
||||
|
||||
int * second = &my_struct.second;
|
||||
ASSERT_EQ(&my_struct, wfp_container_of(second, MyStruct, second));
|
||||
}
|
||||
22
test/webfuse_provider/util/test_message.cc
Normal file
22
test/webfuse_provider/util/test_message.cc
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
#include "webfuse_provider/impl/message.h"
|
||||
|
||||
TEST(wfp_message, create)
|
||||
{
|
||||
json_t * value = json_object();
|
||||
|
||||
struct wfp_message * message = wfp_message_create(value);
|
||||
ASSERT_NE(nullptr, message);
|
||||
ASSERT_EQ(2, message->length);
|
||||
ASSERT_TRUE(0 == strncmp("{}", message->data, 2));
|
||||
|
||||
wfp_message_dispose(message);
|
||||
json_decref(value);
|
||||
}
|
||||
|
||||
TEST(wfp_message, fail_to_create)
|
||||
{
|
||||
struct wfp_message * message = wfp_message_create(nullptr);
|
||||
ASSERT_EQ(nullptr, message);
|
||||
}
|
||||
52
test/webfuse_provider/util/test_message_queue.cc
Normal file
52
test/webfuse_provider/util/test_message_queue.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/message_queue.h"
|
||||
#include "webfuse_provider/impl/message.h"
|
||||
#include "webfuse_provider/impl/util/slist.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct wfp_slist_item * create_message(char const * content)
|
||||
{
|
||||
json_t * value = json_object();
|
||||
json_object_set_new(value, "content", json_string(content));
|
||||
struct wfp_message * message = wfp_message_create(value);
|
||||
|
||||
json_decref(value);
|
||||
return &message->item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_message_queue, cleanup_empty_list)
|
||||
{
|
||||
struct wfp_slist queue;
|
||||
wfp_slist_init(&queue);
|
||||
|
||||
wfp_message_queue_cleanup(&queue);
|
||||
ASSERT_TRUE(wfp_slist_empty(&queue));
|
||||
}
|
||||
|
||||
TEST(wfp_message_queue, cleanup_one_element)
|
||||
{
|
||||
struct wfp_slist queue;
|
||||
wfp_slist_init(&queue);
|
||||
|
||||
wfp_slist_append(&queue, create_message("Hello"));
|
||||
|
||||
wfp_message_queue_cleanup(&queue);
|
||||
ASSERT_TRUE(wfp_slist_empty(&queue));
|
||||
}
|
||||
|
||||
TEST(wfp_message_queue, cleanup_multiple_element)
|
||||
{
|
||||
struct wfp_slist queue;
|
||||
wfp_slist_init(&queue);
|
||||
|
||||
wfp_slist_append(&queue, create_message("Hello"));
|
||||
wfp_slist_append(&queue, create_message("World"));
|
||||
wfp_slist_append(&queue, create_message("!"));
|
||||
|
||||
wfp_message_queue_cleanup(&queue);
|
||||
ASSERT_TRUE(wfp_slist_empty(&queue));
|
||||
}
|
||||
139
test/webfuse_provider/util/test_slist.cc
Normal file
139
test/webfuse_provider/util/test_slist.cc
Normal file
@@ -0,0 +1,139 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/util/slist.h"
|
||||
|
||||
TEST(wfp_slist, init)
|
||||
{
|
||||
struct wfp_slist list;
|
||||
wfp_slist_init(&list);
|
||||
|
||||
ASSERT_EQ(nullptr, list.head.next);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(&list.head, list.last);
|
||||
ASSERT_TRUE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(nullptr, wfp_slist_first(&list));
|
||||
}
|
||||
|
||||
TEST(wfp_slist, append)
|
||||
{
|
||||
struct wfp_slist list;
|
||||
struct wfp_slist_item item[3];
|
||||
|
||||
wfp_slist_init(&list);
|
||||
ASSERT_TRUE(wfp_slist_empty(&list));
|
||||
|
||||
wfp_slist_append(&list, &item[0]);
|
||||
ASSERT_NE(&list.head, list.last);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
||||
ASSERT_EQ(&item[0], list.head.next);
|
||||
ASSERT_EQ(&item[0], list.last);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(nullptr, item[0].next);
|
||||
|
||||
wfp_slist_append(&list, &item[1]);
|
||||
ASSERT_NE(&list.head, list.last);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
||||
ASSERT_EQ(&item[0], list.head.next);
|
||||
ASSERT_EQ(&item[1], list.last);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(&item[1], item[0].next);
|
||||
ASSERT_EQ(nullptr, item[1].next);
|
||||
|
||||
wfp_slist_append(&list, &item[2]);
|
||||
ASSERT_NE(&list.head, list.last);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
||||
ASSERT_EQ(&item[0], list.head.next);
|
||||
ASSERT_EQ(&item[2], list.last);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(&item[1], item[0].next);
|
||||
ASSERT_EQ(&item[2], item[1].next);
|
||||
ASSERT_EQ(nullptr, item[2].next);
|
||||
}
|
||||
|
||||
TEST(wfp_slist_remove_after, remove_first)
|
||||
{
|
||||
struct wfp_slist list;
|
||||
struct wfp_slist_item item[3];
|
||||
|
||||
wfp_slist_init(&list);
|
||||
wfp_slist_append(&list, &item[0]);
|
||||
wfp_slist_append(&list, &item[1]);
|
||||
wfp_slist_append(&list, &item[2]);
|
||||
|
||||
wfp_slist_item * removed;
|
||||
|
||||
removed = wfp_slist_remove_first(&list);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[0], removed);
|
||||
|
||||
removed = wfp_slist_remove_first(&list);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[1], removed);
|
||||
|
||||
removed = wfp_slist_remove_first(&list);
|
||||
ASSERT_TRUE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[2], removed);
|
||||
|
||||
ASSERT_EQ(nullptr, list.head.next);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(&list.head, list.last);
|
||||
ASSERT_EQ(nullptr, wfp_slist_first(&list));
|
||||
}
|
||||
|
||||
TEST(wfp_slist_remove_after, remove_last)
|
||||
{
|
||||
struct wfp_slist list;
|
||||
struct wfp_slist_item item[3];
|
||||
|
||||
wfp_slist_init(&list);
|
||||
wfp_slist_append(&list, &item[0]);
|
||||
wfp_slist_append(&list, &item[1]);
|
||||
wfp_slist_append(&list, &item[2]);
|
||||
|
||||
wfp_slist_item * removed;
|
||||
|
||||
removed = wfp_slist_remove_after(&list, &item[1]);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[2], removed);
|
||||
|
||||
removed = wfp_slist_remove_after(&list, &item[0]);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[1], removed);
|
||||
|
||||
removed = wfp_slist_remove_after(&list, &list.head);
|
||||
ASSERT_TRUE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[0], removed);
|
||||
|
||||
ASSERT_EQ(nullptr, list.head.next);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(&list.head, list.last);
|
||||
ASSERT_EQ(nullptr, wfp_slist_first(&list));
|
||||
}
|
||||
|
||||
TEST(wfp_slist_remove_after, remove_after)
|
||||
{
|
||||
struct wfp_slist list;
|
||||
struct wfp_slist_item item[3];
|
||||
|
||||
wfp_slist_init(&list);
|
||||
wfp_slist_append(&list, &item[0]);
|
||||
wfp_slist_append(&list, &item[1]);
|
||||
wfp_slist_append(&list, &item[2]);
|
||||
|
||||
wfp_slist_item * removed;
|
||||
|
||||
removed = wfp_slist_remove_after(&list, &item[0]);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[1], removed);
|
||||
|
||||
ASSERT_NE(&list.head, list.last);
|
||||
ASSERT_FALSE(wfp_slist_empty(&list));
|
||||
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
||||
ASSERT_EQ(&item[0], list.head.next);
|
||||
ASSERT_EQ(&item[2], list.last);
|
||||
ASSERT_EQ(nullptr, list.last->next);
|
||||
ASSERT_EQ(&item[2], item[0].next);
|
||||
ASSERT_EQ(nullptr, item[2].next);
|
||||
}
|
||||
30
test/webfuse_provider/util/test_status.cc
Normal file
30
test/webfuse_provider/util/test_status.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/status_intern.h"
|
||||
|
||||
TEST(wfp_status, tostring)
|
||||
{
|
||||
ASSERT_STREQ("Good", wfp_status_tostring(WFP_GOOD));
|
||||
ASSERT_STREQ("Bad", wfp_status_tostring(WFP_BAD));
|
||||
ASSERT_STREQ("Bad (not implemented)", wfp_status_tostring(WFP_BAD_NOTIMPLEMENTED));
|
||||
ASSERT_STREQ("Bad (busy)", wfp_status_tostring(WFP_BAD_BUSY));
|
||||
ASSERT_STREQ("Bad (timeout)", wfp_status_tostring(WFP_BAD_TIMEOUT));
|
||||
ASSERT_STREQ("Bad (format)", wfp_status_tostring(WFP_BAD_FORMAT));
|
||||
ASSERT_STREQ("Bad (no entry)", wfp_status_tostring(WFP_BAD_NOENTRY));
|
||||
ASSERT_STREQ("Bad (access denied)", wfp_status_tostring(WFP_BAD_ACCESS_DENIED));
|
||||
|
||||
ASSERT_STREQ("Bad (unknown)", wfp_status_tostring(-1));
|
||||
}
|
||||
|
||||
TEST(wfp_status, to_rc)
|
||||
{
|
||||
ASSERT_EQ(0, wfp_status_to_rc(WFP_GOOD));
|
||||
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD));
|
||||
ASSERT_EQ(-ENOSYS, wfp_status_to_rc(WFP_BAD_NOTIMPLEMENTED));
|
||||
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD_BUSY));
|
||||
ASSERT_EQ(-ETIMEDOUT, wfp_status_to_rc(WFP_BAD_TIMEOUT));
|
||||
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD_FORMAT));
|
||||
ASSERT_EQ(-ENOENT, wfp_status_to_rc(WFP_BAD_NOENTRY));
|
||||
ASSERT_EQ(-EACCES, wfp_status_to_rc(WFP_BAD_ACCESS_DENIED));
|
||||
|
||||
ASSERT_EQ(-ENOENT, wfp_status_to_rc(-1));
|
||||
}
|
||||
92
test/webfuse_provider/util/test_url.cc
Normal file
92
test/webfuse_provider/util/test_url.cc
Normal file
@@ -0,0 +1,92 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfuse_provider/impl/util/url.h"
|
||||
|
||||
TEST(url, ParseWs)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "ws://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_FALSE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wfp_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParswWss)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "wss://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(443, url.port);
|
||||
ASSERT_TRUE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wfp_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseIPAdress)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "ws://127.0.0.1/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_STREQ("127.0.0.1", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wfp_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParsePort)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "ws://localhost:54321/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(54321, url.port);
|
||||
|
||||
wfp_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseNonEmptyPath)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "ws://localhost/some_path?query");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_STREQ("/some_path?query", url.path);
|
||||
|
||||
wfp_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseUnknownProtocol)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "unknown://localhost/");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
ASSERT_EQ(nullptr, url.host);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseMissingProtocol)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "unknown");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
ASSERT_EQ(nullptr, url.host);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseMissingPath)
|
||||
{
|
||||
struct wfp_url url;
|
||||
bool result = wfp_url_init(&url, "ws://localhost");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
ASSERT_EQ(nullptr, url.host);
|
||||
}
|
||||
|
||||
47
test/webfuse_provider/util/test_util.cc
Normal file
47
test/webfuse_provider/util/test_util.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_provider/impl/util/json_util.h"
|
||||
|
||||
TEST(jsonrpc_util, get_int)
|
||||
{
|
||||
json_t * object = json_object();
|
||||
json_object_set_new(object, "key", json_integer(23));
|
||||
int value = wfp_impl_json_get_int(object, "key", 42);
|
||||
ASSERT_EQ(23, value);
|
||||
|
||||
json_decref(object);
|
||||
}
|
||||
|
||||
TEST(jsonrpc_util, failed_to_get_null_object)
|
||||
{
|
||||
int value = wfp_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 = wfp_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 = wfp_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 = wfp_impl_json_get_int(object, "key", 42);
|
||||
ASSERT_EQ(42, value);
|
||||
|
||||
json_decref(object);
|
||||
}
|
||||
Reference in New Issue
Block a user