TEST(AtomicIntrusiveLinkedList, ReverseSweep) { TestIntrusiveObject a(1), b(2), c(3); TestIntrusiveObject::List list; list.insertHead(&a); list.insertHead(&b); list.insertHead(&c); size_t next_expected_id = 3; list.reverseSweep([&](TestIntrusiveObject* obj) { auto const expected = next_expected_id--; EXPECT_EQ(expected, obj->id()); }); EXPECT_TRUE(list.empty()); // Test that we can still insert list.insertHead(&a); EXPECT_FALSE(list.empty()); list.reverseSweep([](TestIntrusiveObject*) {}); }
TEST(AtomicIntrusiveLinkedList, Basic) { TestIntrusiveObject a(1), b(2), c(3); TestIntrusiveObject::List list; EXPECT_TRUE(list.empty()); { EXPECT_TRUE(list.insertHead(&a)); EXPECT_FALSE(list.insertHead(&b)); EXPECT_FALSE(list.empty()); size_t id = 0; list.sweep([&](TestIntrusiveObject* obj) mutable { ++id; EXPECT_EQ(id, obj->id()); }); EXPECT_TRUE(list.empty()); } // Try re-inserting the same item (b) and a new item (c) { EXPECT_TRUE(list.insertHead(&b)); EXPECT_FALSE(list.insertHead(&c)); EXPECT_FALSE(list.empty()); size_t id = 1; list.sweep([&](TestIntrusiveObject* obj) mutable { ++id; EXPECT_EQ(id, obj->id()); }); EXPECT_TRUE(list.empty()); } TestIntrusiveObject::List movedList = std::move(list); }