mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 00:49:08 +00:00
feat(list): implement copy constructor
This commit is contained in:
parent
48a2315122
commit
f46c0c2c4c
2 changed files with 59 additions and 2 deletions
|
|
@ -5,11 +5,29 @@ struct TestListNode : TSLinkedNode<TestListNode> {
|
|||
uint32_t index = 0;
|
||||
};
|
||||
|
||||
struct TestExplicitListNode {
|
||||
uint32_t index = 0;
|
||||
TSLink<TestExplicitListNode> m_explicitLink;
|
||||
};
|
||||
|
||||
TEST_CASE("TSList", "[list]") {
|
||||
SECTION("constructs correctly") {
|
||||
STORM_LIST(TestListNode) list;
|
||||
REQUIRE(list.Head() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("constructs copy correctly") {
|
||||
STORM_LIST(TestListNode) list;
|
||||
auto node = new TestListNode();
|
||||
list.LinkToHead(node);
|
||||
|
||||
STORM_LIST(TestListNode) listCopy(list);
|
||||
|
||||
// List copy constructor does not transfer ownership of nodes. It merely copies the link
|
||||
// offset from the source list and initializes the list terminator.
|
||||
REQUIRE(list.Head() == node);
|
||||
REQUIRE(listCopy.Head() == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("TSList::Head", "[list]") {
|
||||
|
|
@ -135,3 +153,24 @@ TEST_CASE("TSList::Tail", "[list]") {
|
|||
REQUIRE(list.Tail() == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("TSExplicitList", "[list]") {
|
||||
SECTION("constructs correctly") {
|
||||
STORM_EXPLICIT_LIST(TestExplicitListNode, m_explicitLink) list;
|
||||
REQUIRE(list.Head() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("constructs copy correctly") {
|
||||
STORM_EXPLICIT_LIST(TestExplicitListNode, m_explicitLink) list;
|
||||
auto node = new TestExplicitListNode();
|
||||
list.LinkToHead(node);
|
||||
|
||||
STORM_EXPLICIT_LIST(TestExplicitListNode, m_explicitLink) listCopy(list);
|
||||
|
||||
// Explicit list copy constructor does not transfer ownership of nodes. It merely calls
|
||||
// the copy constructor on the list base class, which only copies the link offset from
|
||||
// the source list and initializes the list terminator.
|
||||
REQUIRE(list.Head() == node);
|
||||
REQUIRE(listCopy.Head() == nullptr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue