From 99217593bf3c3b6e9c38f5b3c4fc3374e77c69d5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 2 Mar 2021 18:13:55 +0100 Subject: [PATCH] test/util/TestIntrusiveList: add AutoUnlink test --- test/util/TestIntrusiveList.cxx | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/util/TestIntrusiveList.cxx b/test/util/TestIntrusiveList.cxx index 3cbafa0b9..e8c144e11 100644 --- a/test/util/TestIntrusiveList.cxx +++ b/test/util/TestIntrusiveList.cxx @@ -132,3 +132,47 @@ TEST(IntrusiveList, SafeLink) ASSERT_FALSE(a.is_linked()); } + +TEST(IntrusiveList, AutoUnlink) +{ + struct Item final : AutoUnlinkIntrusiveListHook {}; + + Item a; + ASSERT_FALSE(a.is_linked()); + + IntrusiveList list; + + Item b; + ASSERT_FALSE(b.is_linked()); + + { + Item c; + + list.push_back(a); + list.push_back(b); + list.push_back(c); + + ASSERT_TRUE(a.is_linked()); + ASSERT_TRUE(b.is_linked()); + ASSERT_TRUE(c.is_linked()); + + auto i = list.begin(); + ASSERT_EQ(&*i, &a); + ++i; + ASSERT_EQ(&*i, &b); + ++i; + ASSERT_EQ(&*i, &c); + ++i; + ASSERT_EQ(i, list.end()); + } + + auto i = list.begin(); + ASSERT_EQ(&*i, &a); + ++i; + ASSERT_EQ(&*i, &b); + ++i; + ASSERT_EQ(i, list.end()); + + ASSERT_TRUE(a.is_linked()); + ASSERT_TRUE(b.is_linked()); +}