2019-04-17 20:51:16 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-21 19:18:43 +00:00
|
|
|
#include "webfuse_provider/impl/util/slist.h"
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_slist, init)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist list;
|
|
|
|
wfp_slist_init(&list);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(nullptr, list.head.next);
|
|
|
|
ASSERT_EQ(nullptr, list.last->next);
|
|
|
|
ASSERT_EQ(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_TRUE(wfp_slist_empty(&list));
|
|
|
|
ASSERT_EQ(nullptr, wfp_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_slist, append)
|
2019-04-26 18:50:57 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist list;
|
|
|
|
struct wfp_slist_item item[3];
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_init(&list);
|
|
|
|
ASSERT_TRUE(wfp_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_append(&list, &item[0]);
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
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);
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_append(&list, &item[1]);
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
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);
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_append(&list, &item[2]);
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_slist_remove_after, remove_first)
|
2019-04-26 18:50:57 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist list;
|
|
|
|
struct wfp_slist_item item[3];
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_init(&list);
|
|
|
|
wfp_slist_append(&list, &item[0]);
|
|
|
|
wfp_slist_append(&list, &item[1]);
|
|
|
|
wfp_slist_append(&list, &item[2]);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_item * removed;
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_first(&list);
|
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
2019-04-17 20:51:16 +00:00
|
|
|
ASSERT_EQ(&item[0], removed);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_first(&list);
|
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[1], removed);
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_first(&list);
|
|
|
|
ASSERT_TRUE(wfp_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[2], removed);
|
|
|
|
|
|
|
|
ASSERT_EQ(nullptr, list.head.next);
|
|
|
|
ASSERT_EQ(nullptr, list.last->next);
|
|
|
|
ASSERT_EQ(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_EQ(nullptr, wfp_slist_first(&list));
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_slist_remove_after, remove_last)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist list;
|
|
|
|
struct wfp_slist_item item[3];
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_init(&list);
|
|
|
|
wfp_slist_append(&list, &item[0]);
|
|
|
|
wfp_slist_append(&list, &item[1]);
|
|
|
|
wfp_slist_append(&list, &item[2]);
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_item * removed;
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_after(&list, &item[1]);
|
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
2019-04-17 20:51:16 +00:00
|
|
|
ASSERT_EQ(&item[2], removed);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_after(&list, &item[0]);
|
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[1], removed);
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_after(&list, &list.head);
|
|
|
|
ASSERT_TRUE(wfp_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[0], removed);
|
|
|
|
|
|
|
|
ASSERT_EQ(nullptr, list.head.next);
|
|
|
|
ASSERT_EQ(nullptr, list.last->next);
|
|
|
|
ASSERT_EQ(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_EQ(nullptr, wfp_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_slist_remove_after, remove_after)
|
2019-04-26 18:50:57 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_slist list;
|
|
|
|
struct wfp_slist_item item[3];
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_init(&list);
|
|
|
|
wfp_slist_append(&list, &item[0]);
|
|
|
|
wfp_slist_append(&list, &item[1]);
|
|
|
|
wfp_slist_append(&list, &item[2]);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_slist_item * removed;
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
removed = wfp_slist_remove_after(&list, &item[0]);
|
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[1], removed);
|
|
|
|
|
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wfp_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
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);
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|