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
|
|
|
|
2020-07-10 19:17:31 +00:00
|
|
|
#include <libwebsockets.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
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
|
|
|
{
|
2020-07-10 19:17:31 +00:00
|
|
|
size_t length = strlen(content);
|
|
|
|
char * raw_data = reinterpret_cast<char*>(malloc(LWS_PRE + length));
|
|
|
|
char * data = raw_data + LWS_PRE;
|
|
|
|
|
|
|
|
memcpy(data, content, length);
|
|
|
|
struct wfp_message * message = wfp_message_create(data, length);
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|