summaryrefslogtreecommitdiff
path: root/test/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-13 12:33:07 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-13 12:33:07 +0100
commit467d8d52ffda8b5d520ee0eb1e42125bdb533ff4 (patch)
tree76f306a1222991c495b0a560240430f72b3977e5 /test/core
parent6d63ba16c66be029c757989f06e308dea9237721 (diff)
started to refactor Managed package
Diffstat (limited to 'test/core')
-rw-r--r--test/core/managed/ManagedContainerTest.cpp (renamed from test/core/ManagedContainersTest.cpp)4
-rw-r--r--test/core/managed/ManagedTest.cpp22
-rw-r--r--test/core/managed/ManagerTest.cpp (renamed from test/core/ManagedTest.cpp)139
-rw-r--r--test/core/managed/TestManaged.hpp (renamed from test/core/TestManaged.hpp)2
4 files changed, 113 insertions, 54 deletions
diff --git a/test/core/ManagedContainersTest.cpp b/test/core/managed/ManagedContainerTest.cpp
index 3abbd4d..db72295 100644
--- a/test/core/ManagedContainersTest.cpp
+++ b/test/core/managed/ManagedContainerTest.cpp
@@ -20,8 +20,8 @@
#include <gtest/gtest.h>
-#include <core/Managed.hpp>
-#include <core/ManagedContainers.hpp>
+#include <core/managed/Managed.hpp>
+#include <core/managed/ManagedContainer.hpp>
#include "TestManaged.hpp"
diff --git a/test/core/managed/ManagedTest.cpp b/test/core/managed/ManagedTest.cpp
new file mode 100644
index 0000000..e8a24f2
--- /dev/null
+++ b/test/core/managed/ManagedTest.cpp
@@ -0,0 +1,22 @@
+/*
+ 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/>.
+*/
+
+namespace ousia {
+
+}
+
diff --git a/test/core/ManagedTest.cpp b/test/core/managed/ManagerTest.cpp
index ab60f04..da42f0a 100644
--- a/test/core/ManagedTest.cpp
+++ b/test/core/managed/ManagerTest.cpp
@@ -22,7 +22,7 @@
#include <gtest/gtest.h>
-#include <core/Managed.hpp>
+#include <core/managed/Managed.hpp>
#include "TestManaged.hpp"
@@ -30,128 +30,171 @@ namespace ousia {
/* Class ObjectDescriptor */
+class TestObjectDescriptor : public Manager::ObjectDescriptor {
+public:
+ int refInCount() const
+ {
+ int res = 0;
+ for (const auto &e : refIn) {
+ res += e.second;
+ }
+ return res + rootRefCount;
+ }
+
+ int refOutCount() const
+ {
+ int res = 0;
+ for (const auto &e : refOut) {
+ res += e.second;
+ }
+ return res;
+ }
+
+ int refInCount(Managed *o) const
+ {
+ if (o == nullptr) {
+ return rootRefCount;
+ }
+
+ const auto it = refIn.find(o);
+ if (it != refIn.cend()) {
+ return it->second;
+ }
+ return 0;
+ }
+
+ int refOutCount(Managed *o) const
+ {
+ const auto it = refOut.find(o);
+ if (it != refOut.cend()) {
+ return it->second;
+ }
+ return 0;
+ }
+};
+
TEST(ObjectDescriptor, degree)
{
// Do not use actual Managed in this test -- we don't want to test their
// behaviour
- ObjectDescriptor nd;
+ TestObjectDescriptor nd;
Managed *n1 = reinterpret_cast<Managed *>(intptr_t{0x10});
Managed *n2 = reinterpret_cast<Managed *>(intptr_t{0x20});
// Input degree
- ASSERT_EQ(0, nd.refIn.size());
+ ASSERT_EQ(0U, nd.refIn.size());
ASSERT_EQ(0, nd.refInCount(n1));
- nd.incrDegree(RefDir::IN, n1);
+ nd.incrDegree(Manager::RefDir::IN, n1);
ASSERT_EQ(1, nd.refInCount());
ASSERT_EQ(1, nd.refInCount(n1));
ASSERT_EQ(0, nd.refInCount(n2));
- ASSERT_EQ(1, nd.refIn.size());
+ ASSERT_EQ(1U, nd.refIn.size());
- nd.incrDegree(RefDir::IN, n1);
+ nd.incrDegree(Manager::RefDir::IN, n1);
ASSERT_EQ(2, nd.refInCount());
ASSERT_EQ(2, nd.refInCount(n1));
ASSERT_EQ(0, nd.refInCount(n2));
- ASSERT_EQ(1, nd.refIn.size());
+ ASSERT_EQ(1U, nd.refIn.size());
- nd.incrDegree(RefDir::IN, n2);
+ nd.incrDegree(Manager::RefDir::IN, n2);
ASSERT_EQ(3, nd.refInCount());
ASSERT_EQ(2, nd.refInCount(n1));
ASSERT_EQ(1, nd.refInCount(n2));
- ASSERT_EQ(2, nd.refIn.size());
+ ASSERT_EQ(2U, nd.refIn.size());
- nd.incrDegree(RefDir::IN, nullptr);
+ nd.incrDegree(Manager::RefDir::IN, nullptr);
ASSERT_EQ(4, nd.refInCount());
ASSERT_EQ(2, nd.refInCount(n1));
ASSERT_EQ(1, nd.refInCount(n2));
- ASSERT_EQ(2, nd.refIn.size());
+ ASSERT_EQ(2U, nd.refIn.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::IN, n1));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::IN, n1));
ASSERT_EQ(3, nd.refInCount());
ASSERT_EQ(1, nd.refInCount(n1));
ASSERT_EQ(1, nd.refInCount(n2));
- ASSERT_EQ(2, nd.refIn.size());
+ ASSERT_EQ(2U, nd.refIn.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::IN, n1));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::IN, n1));
ASSERT_EQ(2, nd.refInCount());
ASSERT_EQ(0, nd.refInCount(n1));
ASSERT_EQ(1, nd.refInCount(n2));
- ASSERT_EQ(1, nd.refIn.size());
+ ASSERT_EQ(1U, nd.refIn.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::IN, n2));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::IN, n2));
ASSERT_EQ(1, nd.refInCount());
ASSERT_EQ(0, nd.refInCount(n1));
ASSERT_EQ(0, nd.refInCount(n2));
- ASSERT_EQ(0, nd.refIn.size());
+ ASSERT_EQ(0U, nd.refIn.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::IN, nullptr));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::IN, nullptr));
ASSERT_EQ(0, nd.refInCount());
ASSERT_EQ(0, nd.refInCount(n1));
ASSERT_EQ(0, nd.refInCount(n2));
- ASSERT_EQ(0, nd.refIn.size());
+ ASSERT_EQ(0U, nd.refIn.size());
// Output degree
- ASSERT_EQ(0, nd.refOut.size());
+ ASSERT_EQ(0U, nd.refOut.size());
ASSERT_EQ(0, nd.refOutCount(n1));
- nd.incrDegree(RefDir::OUT, n1);
+ nd.incrDegree(Manager::RefDir::OUT, n1);
ASSERT_EQ(1, nd.refOutCount());
ASSERT_EQ(1, nd.refOutCount(n1));
ASSERT_EQ(0, nd.refOutCount(n2));
- ASSERT_EQ(1, nd.refOut.size());
+ ASSERT_EQ(1U, nd.refOut.size());
- nd.incrDegree(RefDir::OUT, n1);
+ nd.incrDegree(Manager::RefDir::OUT, n1);
ASSERT_EQ(2, nd.refOutCount());
ASSERT_EQ(2, nd.refOutCount(n1));
ASSERT_EQ(0, nd.refOutCount(n2));
- ASSERT_EQ(1, nd.refOut.size());
+ ASSERT_EQ(1U, nd.refOut.size());
- nd.incrDegree(RefDir::OUT, n2);
+ nd.incrDegree(Manager::RefDir::OUT, n2);
ASSERT_EQ(3, nd.refOutCount());
ASSERT_EQ(2, nd.refOutCount(n1));
ASSERT_EQ(1, nd.refOutCount(n2));
- ASSERT_EQ(2, nd.refOut.size());
+ ASSERT_EQ(2U, nd.refOut.size());
- nd.incrDegree(RefDir::OUT, nullptr);
+ nd.incrDegree(Manager::RefDir::OUT, nullptr);
ASSERT_EQ(3, nd.refOutCount());
ASSERT_EQ(2, nd.refOutCount(n1));
ASSERT_EQ(1, nd.refOutCount(n2));
- ASSERT_EQ(2, nd.refOut.size());
+ ASSERT_EQ(2U, nd.refOut.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::OUT, n1));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::OUT, n1));
ASSERT_EQ(2, nd.refOutCount());
ASSERT_EQ(1, nd.refOutCount(n1));
ASSERT_EQ(1, nd.refOutCount(n2));
- ASSERT_EQ(2, nd.refOut.size());
+ ASSERT_EQ(2U, nd.refOut.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::OUT, n1));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::OUT, n1));
ASSERT_EQ(1, nd.refOutCount());
ASSERT_EQ(0, nd.refOutCount(n1));
ASSERT_EQ(1, nd.refOutCount(n2));
- ASSERT_EQ(1, nd.refOut.size());
+ ASSERT_EQ(1U, nd.refOut.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::OUT, n2));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::OUT, n2));
ASSERT_EQ(0, nd.refOutCount());
ASSERT_EQ(0, nd.refOutCount(n1));
ASSERT_EQ(0, nd.refOutCount(n2));
- ASSERT_EQ(0, nd.refOut.size());
+ ASSERT_EQ(0U, nd.refOut.size());
- ASSERT_TRUE(nd.decrDegree(RefDir::OUT, nullptr));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::OUT, nullptr));
ASSERT_EQ(0, nd.refOutCount());
ASSERT_EQ(0, nd.refOutCount(n1));
ASSERT_EQ(0, nd.refOutCount(n2));
- ASSERT_EQ(0, nd.refOut.size());
+ ASSERT_EQ(0U, nd.refOut.size());
}
TEST(ObjectDescriptor, rootRefCount)
{
- ObjectDescriptor nd;
+ TestObjectDescriptor nd;
ASSERT_EQ(0, nd.rootRefCount);
- nd.incrDegree(RefDir::IN, nullptr);
+ nd.incrDegree(Manager::RefDir::IN, nullptr);
ASSERT_EQ(1, nd.rootRefCount);
- nd.incrDegree(RefDir::OUT, nullptr);
+ nd.incrDegree(Manager::RefDir::OUT, nullptr);
ASSERT_EQ(2, nd.rootRefCount);
ASSERT_EQ(2, nd.refInCount(nullptr));
@@ -159,13 +202,13 @@ TEST(ObjectDescriptor, rootRefCount)
ASSERT_EQ(0, nd.refOutCount(nullptr));
ASSERT_EQ(0, nd.refOutCount());
- ASSERT_TRUE(nd.decrDegree(RefDir::OUT, nullptr));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::OUT, nullptr));
ASSERT_EQ(1, nd.rootRefCount);
- ASSERT_TRUE(nd.decrDegree(RefDir::IN, nullptr));
+ ASSERT_TRUE(nd.decrDegree(Manager::RefDir::IN, nullptr));
ASSERT_EQ(0, nd.rootRefCount);
- ASSERT_FALSE(nd.decrDegree(RefDir::IN, nullptr));
+ ASSERT_FALSE(nd.decrDegree(Manager::RefDir::IN, nullptr));
ASSERT_EQ(0, nd.rootRefCount);
}
@@ -436,7 +479,7 @@ TEST(Manager, disconnectDoubleRootedSubgraph)
}
Rooted<TestManaged> createFullyConnectedGraph(Manager &mgr, int nElem,
- bool alive[])
+ bool alive[])
{
std::vector<Rooted<TestManaged>> nodes;
@@ -474,18 +517,13 @@ TEST(Manager, fullyConnectedGraph)
}
class HidingTestManaged : public TestManaged {
-
private:
Rooted<Managed> hidden;
public:
+ HidingTestManaged(Manager &mgr, bool &alive) : TestManaged(mgr, alive){};
- HidingTestManaged(Manager &mgr, bool &alive) : TestManaged(mgr, alive) {};
-
- void setHiddenRef(Handle<Managed> t) {
- hidden = t;
- }
-
+ void setHiddenRef(Handle<Managed> t) { hidden = t; }
};
TEST(Manager, hiddenRootedGraph)
@@ -510,6 +548,5 @@ TEST(Manager, hiddenRootedGraph)
ASSERT_FALSE(v);
}
}
-
}
diff --git a/test/core/TestManaged.hpp b/test/core/managed/TestManaged.hpp
index 3b93e51..ed51c3b 100644
--- a/test/core/TestManaged.hpp
+++ b/test/core/managed/TestManaged.hpp
@@ -19,7 +19,7 @@
#ifndef _TEST_MANAGED_H_
#define _TEST_MANAGED_H_
-#include <core/Managed.hpp>
+#include <core/managed/Managed.hpp>
namespace ousia {