From cba02d09ec724def40975240290a30a78d33db8a Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 2 Nov 2014 22:58:55 +0000 Subject: fixed gc sweep rooting detection, added new gc unit test git-svn-id: file:///var/local/svn/basicwriter@92 daaaf23c-2e50-4459-9457-1e69db5a47bf --- test/core/dom/NodeTest.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'test/core') diff --git a/test/core/dom/NodeTest.cpp b/test/core/dom/NodeTest.cpp index fa7b804..3338db6 100644 --- a/test/core/dom/NodeTest.cpp +++ b/test/core/dom/NodeTest.cpp @@ -178,10 +178,7 @@ public: ~TestNode() override { alive = false; } - void addRef(BaseHandle h) - { - refs.push_back(acquire(h)); - } + void addRef(BaseHandle h) { refs.push_back(acquire(h)); } }; TEST(NodeManager, linearDependencies) @@ -251,6 +248,47 @@ TEST(NodeManager, cyclicDependencies) } } +TEST(NodeManager, doubleRooted) +{ + std::array a; + a.fill(false); + + NodeManager mgr(1); + { + TestNode *n1, *n2; + n1 = new TestNode(mgr, a[1]); + n2 = new TestNode(mgr, a[2]); + + { + RootedHandle hr1{new TestNode(mgr, a[0])}; + { + RootedHandle hr2{new TestNode(mgr, a[3])}; + + // All nodes must have set their "alive" flag to true + for (bool v : a) { + ASSERT_TRUE(v); + } + + // Create cyclical dependency between n2 and n1 + n1->addRef(n2); + n2->addRef(n1); + + // Reference n1 and n2 in the rooted nodes + hr1->addRef(n1); + hr2->addRef(n2); + } + + // hr2 is dead, all other nodes are still alive + ASSERT_FALSE(a[3]); + ASSERT_TRUE(a[0] && a[1] && a[2]); + } + + // All nodes are dead + for (bool v : a) { + ASSERT_FALSE(v); + } + } +} } } -- cgit v1.2.3