2019-05-19 12:33:42 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/message_queue.h"
|
|
|
|
#include "webfuse/impl/message.h"
|
|
|
|
#include "webfuse/impl/util/slist.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
struct wf_slist_item * create_message(char const * content)
|
|
|
|
{
|
|
|
|
json_t * value = json_object();
|
|
|
|
json_object_set_new(value, "content", json_string(content));
|
2020-06-28 17:43:08 +00:00
|
|
|
struct wf_message * message = wf_impl_message_create(value);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
json_decref(value);
|
|
|
|
return &message->item;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_message_queue, cleanup_empty_list)
|
|
|
|
{
|
|
|
|
struct wf_slist queue;
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&queue);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_message_queue_cleanup(&queue);
|
|
|
|
ASSERT_TRUE(wf_impl_slist_empty(&queue));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_message_queue, cleanup_one_element)
|
|
|
|
{
|
|
|
|
struct wf_slist queue;
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&queue);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_append(&queue, create_message("Hello"));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_message_queue_cleanup(&queue);
|
|
|
|
ASSERT_TRUE(wf_impl_slist_empty(&queue));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_message_queue, cleanup_multiple_element)
|
|
|
|
{
|
|
|
|
struct wf_slist queue;
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&queue);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_append(&queue, create_message("Hello"));
|
|
|
|
wf_impl_slist_append(&queue, create_message("World"));
|
|
|
|
wf_impl_slist_append(&queue, create_message("!"));
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_message_queue_cleanup(&queue);
|
|
|
|
ASSERT_TRUE(wf_impl_slist_empty(&queue));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|