summaryrefslogtreecommitdiff
path: root/test/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-11-02 22:58:55 +0000
committerandreas <andreas@daaaf23c-2e50-4459-9457-1e69db5a47bf>2014-11-02 22:58:55 +0000
commitcba02d09ec724def40975240290a30a78d33db8a (patch)
tree01d1b61e6fd7d2ce3c05be08d9c91d3f182baa26 /test/core
parenta0de8d148f79af1ef96626e9aa561f9360d77045 (diff)
fixed gc sweep rooting detection, added new gc unit test
git-svn-id: file:///var/local/svn/basicwriter@92 daaaf23c-2e50-4459-9457-1e69db5a47bf
Diffstat (limited to 'test/core')
-rw-r--r--test/core/dom/NodeTest.cpp46
1 files changed, 42 insertions, 4 deletions
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<Node> h)
- {
- refs.push_back(acquire(h));
- }
+ void addRef(BaseHandle<Node> h) { refs.push_back(acquire(h)); }
};
TEST(NodeManager, linearDependencies)
@@ -251,6 +248,47 @@ TEST(NodeManager, cyclicDependencies)
}
}
+TEST(NodeManager, doubleRooted)
+{
+ std::array<bool, 4> a;
+ a.fill(false);
+
+ NodeManager mgr(1);
+ {
+ TestNode *n1, *n2;
+ n1 = new TestNode(mgr, a[1]);
+ n2 = new TestNode(mgr, a[2]);
+
+ {
+ RootedHandle<TestNode> hr1{new TestNode(mgr, a[0])};
+ {
+ RootedHandle<TestNode> 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);
+ }
+ }
+}
}
}