2019-05-19 12:33:42 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/message_queue.h"
|
|
|
|
#include "webfuse_provider/impl/message.h"
|
2020-06-21 19:18:43 +00:00
|
|
|
#include "webfuse_provider/impl/util/slist.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist_item * create_message(char const * content)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
|
|
|
json_t * value = json_object();
|
|
|
|
json_object_set_new(value, "content", json_string(content));
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_message * message = wfp_message_create(value);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(value);
|
|
|
|
return &message->item;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_message_queue, cleanup_empty_list)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist queue;
|
|
|
|
wfp_slist_init(&queue);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_message_queue_cleanup(&queue);
|
|
|
|
ASSERT_TRUE(wfp_slist_empty(&queue));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_message_queue, cleanup_one_element)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist queue;
|
|
|
|
wfp_slist_init(&queue);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_append(&queue, create_message("Hello"));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_message_queue_cleanup(&queue);
|
|
|
|
ASSERT_TRUE(wfp_slist_empty(&queue));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_message_queue, cleanup_multiple_element)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist queue;
|
|
|
|
wfp_slist_init(&queue);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_append(&queue, create_message("Hello"));
|
|
|
|
wfp_slist_append(&queue, create_message("World"));
|
|
|
|
wfp_slist_append(&queue, create_message("!"));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_message_queue_cleanup(&queue);
|
|
|
|
ASSERT_TRUE(wfp_slist_empty(&queue));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|