summaryrefslogtreecommitdiff
path: root/test/core/ManagedTest.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-11-16 01:41:54 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-11-16 01:41:54 +0100
commitadf0b5eaef95484a8d3b8ad1e6e6765018658bdc (patch)
treed39d900c02ca57387b70f7b9bf26b622ec936574 /test/core/ManagedTest.cpp
parent2910a2e310b04dfa1983cc9b9af7dc1f5d045c99 (diff)
added ManagedContainer and ManagedVector templates which allow automatic acquiring of a Managed objects stored within that container owned by another Managed object
Diffstat (limited to 'test/core/ManagedTest.cpp')
-rw-r--r--test/core/ManagedTest.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/core/ManagedTest.cpp b/test/core/ManagedTest.cpp
index 3085a74..1aada5a 100644
--- a/test/core/ManagedTest.cpp
+++ b/test/core/ManagedTest.cpp
@@ -542,5 +542,54 @@ TEST(Manager, hiddenRootedGraph)
}
}
+TEST(ManagedVector, managedVector)
+{
+ // TODO: This test is highly incomplete
+
+ constexpr int nElem = 16;
+ std::array<bool, nElem> a;
+
+ Manager mgr(1);
+ {
+ Rooted<Managed> root{new Managed{mgr}};
+
+ std::vector<TestManaged*> elems;
+ for (int i = 0; i < nElem; i++) {
+ elems.push_back(new TestManaged{mgr, a[i]});
+ }
+
+ for (bool v : a) {
+ ASSERT_TRUE(v);
+ }
+
+ ManagedVector<TestManaged> v(root, elems);
+
+ // Remove the last element from the list. It should be garbage collected.
+ v.pop_back();
+ ASSERT_FALSE(a[nElem - 1]);
+
+ // Insert a new element into the list.
+ v.push_back(new TestManaged{mgr, a[nElem - 1]});
+ ASSERT_TRUE(a[nElem - 1]);
+
+ // Erase element 10
+ {
+ auto it = v.find(elems[10]);
+ ASSERT_TRUE(it != v.end());
+ v.erase(it);
+ ASSERT_FALSE(a[10]);
+ }
+
+ // Erase element 3 - 5
+ v.erase(v.find(elems[3]), v.find(elems[5]));
+ ASSERT_FALSE(a[3] || a[4]);
+ ASSERT_TRUE(a[5]);
+ }
+
+ for (bool v : a) {
+ ASSERT_FALSE(v);
+ }
+}
+
}