summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/ManagedContainersTest.cpp80
-rw-r--r--test/core/ManagedTest.cpp84
-rw-r--r--test/core/TestManaged.hpp62
3 files changed, 144 insertions, 82 deletions
diff --git a/test/core/ManagedContainersTest.cpp b/test/core/ManagedContainersTest.cpp
new file mode 100644
index 0000000..3abbd4d
--- /dev/null
+++ b/test/core/ManagedContainersTest.cpp
@@ -0,0 +1,80 @@
+/*
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <array>
+
+#include <gtest/gtest.h>
+
+#include <core/Managed.hpp>
+#include <core/ManagedContainers.hpp>
+
+#include "TestManaged.hpp"
+
+namespace ousia {
+
+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);
+ }
+}
+
+}
+
diff --git a/test/core/ManagedTest.cpp b/test/core/ManagedTest.cpp
index 1aada5a..a52ba88 100644
--- a/test/core/ManagedTest.cpp
+++ b/test/core/ManagedTest.cpp
@@ -24,6 +24,8 @@
#include <core/Managed.hpp>
+#include "TestManaged.hpp"
+
namespace ousia {
/* Class ObjectDescriptor */
@@ -211,39 +213,6 @@ TEST(Owned, equalsAndAssign)
/* Class Manager */
-class TestManaged : public Managed {
-private:
- bool &alive;
-
- std::vector<Owned<Managed>> refs;
-
-public:
- TestManaged(Manager &mgr, bool &alive) : Managed(mgr), alive(alive)
- {
- //std::cout << "create TestManaged @" << this << std::endl;
- alive = true;
- }
-
- ~TestManaged() override
- {
- //std::cout << "delete TestManaged @" << this << std::endl;
- alive = false;
- }
-
- void addRef(Handle<Managed> h) { refs.push_back(acquire(h)); }
-
- void deleteRef(Handle<Managed> h)
- {
- for (auto it = refs.begin(); it != refs.end();) {
- if (*it == h) {
- it = refs.erase(it);
- } else {
- it++;
- }
- }
- }
-};
-
TEST(Manager, linearDependencies)
{
std::array<bool, 4> a;
@@ -542,54 +511,5 @@ 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);
- }
-}
-
}
diff --git a/test/core/TestManaged.hpp b/test/core/TestManaged.hpp
new file mode 100644
index 0000000..3b93e51
--- /dev/null
+++ b/test/core/TestManaged.hpp
@@ -0,0 +1,62 @@
+/*
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _TEST_MANAGED_H_
+#define _TEST_MANAGED_H_
+
+#include <core/Managed.hpp>
+
+namespace ousia {
+
+class TestManaged : public Managed {
+private:
+ bool &alive;
+
+ std::vector<Owned<Managed>> refs;
+
+public:
+ TestManaged(Manager &mgr, bool &alive) : Managed(mgr), alive(alive)
+ {
+ //std::cout << "create TestManaged @" << this << std::endl;
+ alive = true;
+ }
+
+ ~TestManaged() override
+ {
+ //std::cout << "delete TestManaged @" << this << std::endl;
+ alive = false;
+ }
+
+ void addRef(Handle<Managed> h) { refs.push_back(acquire(h)); }
+
+ void deleteRef(Handle<Managed> h)
+ {
+ for (auto it = refs.begin(); it != refs.end();) {
+ if (*it == h) {
+ it = refs.erase(it);
+ } else {
+ it++;
+ }
+ }
+ }
+};
+
+}
+
+#endif /* _TEST_MANAGED_H_ */
+