2019-04-17 20:51:16 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/util/slist.h"
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2019-04-26 18:50:57 +00:00
|
|
|
TEST(wf_slist, init)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
|
|
|
struct wf_slist list;
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_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-28 17:43:08 +00:00
|
|
|
ASSERT_TRUE(wf_impl_slist_empty(&list));
|
|
|
|
ASSERT_EQ(nullptr, wf_impl_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_slist, append)
|
|
|
|
{
|
|
|
|
struct wf_slist list;
|
|
|
|
struct wf_slist_item item[3];
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&list);
|
|
|
|
ASSERT_TRUE(wf_impl_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_append(&list, &item[0]);
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wf_impl_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-28 17:43:08 +00:00
|
|
|
wf_impl_slist_append(&list, &item[1]);
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wf_impl_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-28 17:43:08 +00:00
|
|
|
wf_impl_slist_append(&list, &item[2]);
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wf_impl_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_slist_remove_after, remove_first)
|
|
|
|
{
|
|
|
|
struct wf_slist list;
|
|
|
|
struct wf_slist_item item[3];
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&list);
|
|
|
|
wf_impl_slist_append(&list, &item[0]);
|
|
|
|
wf_impl_slist_append(&list, &item[1]);
|
|
|
|
wf_impl_slist_append(&list, &item[2]);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
|
|
|
wf_slist_item * removed;
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_first(&list);
|
|
|
|
ASSERT_FALSE(wf_impl_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-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_first(&list);
|
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[1], removed);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_first(&list);
|
|
|
|
ASSERT_TRUE(wf_impl_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-28 17:43:08 +00:00
|
|
|
ASSERT_EQ(nullptr, wf_impl_slist_first(&list));
|
2019-04-17 20:51:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 18:50:57 +00:00
|
|
|
TEST(wf_slist_remove_after, remove_last)
|
2019-04-17 20:51:16 +00:00
|
|
|
{
|
|
|
|
struct wf_slist list;
|
2019-04-26 18:50:57 +00:00
|
|
|
struct wf_slist_item item[3];
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&list);
|
|
|
|
wf_impl_slist_append(&list, &item[0]);
|
|
|
|
wf_impl_slist_append(&list, &item[1]);
|
|
|
|
wf_impl_slist_append(&list, &item[2]);
|
2019-04-17 20:51:16 +00:00
|
|
|
|
2019-04-26 18:50:57 +00:00
|
|
|
wf_slist_item * removed;
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_after(&list, &item[1]);
|
|
|
|
ASSERT_FALSE(wf_impl_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-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_after(&list, &item[0]);
|
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[1], removed);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_after(&list, &list.head);
|
|
|
|
ASSERT_TRUE(wf_impl_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-28 17:43:08 +00:00
|
|
|
ASSERT_EQ(nullptr, wf_impl_slist_first(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wf_slist_remove_after, remove_after)
|
|
|
|
{
|
|
|
|
struct wf_slist list;
|
|
|
|
struct wf_slist_item item[3];
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&list);
|
|
|
|
wf_impl_slist_append(&list, &item[0]);
|
|
|
|
wf_impl_slist_append(&list, &item[1]);
|
|
|
|
wf_impl_slist_append(&list, &item[2]);
|
2019-04-26 18:50:57 +00:00
|
|
|
|
|
|
|
wf_slist_item * removed;
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
removed = wf_impl_slist_remove_after(&list, &item[0]);
|
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
2019-04-26 18:50:57 +00:00
|
|
|
ASSERT_EQ(&item[1], removed);
|
|
|
|
|
|
|
|
ASSERT_NE(&list.head, list.last);
|
2020-06-28 17:43:08 +00:00
|
|
|
ASSERT_FALSE(wf_impl_slist_empty(&list));
|
|
|
|
ASSERT_EQ(&item[0], wf_impl_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
|
|
|
}
|