From 75f40e25ca7e5a28cb5cf860715ef4f851641e54 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 2 Jan 2015 23:31:13 +0100 Subject: Moved NodeTest to model folder --- CMakeLists.txt | 2 +- test/core/NodeTest.cpp | 90 -------------------------------------------- test/core/model/NodeTest.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 91 deletions(-) delete mode 100644 test/core/NodeTest.cpp create mode 100644 test/core/model/NodeTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 87ac931..53b8e89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,6 @@ IF(TEST) ADD_EXECUTABLE(ousia_test_core test/core/CodeTokenizerTest test/core/CSSTest - test/core/NodeTest test/core/RangeSetTest test/core/RegistryTest test/core/ResourceLocatorTest @@ -199,6 +198,7 @@ IF(TEST) test/core/managed/VariantObjectTest test/core/model/DomainTest test/core/model/DocumentTest + test/core/model/NodeTest test/core/model/TypesystemTest test/core/parser/ParserStackTest # test/core/script/FunctionTest diff --git a/test/core/NodeTest.cpp b/test/core/NodeTest.cpp deleted file mode 100644 index 1c58e2c..0000000 --- a/test/core/NodeTest.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - 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 . -*/ - -#include - -#include -#include - -namespace ousia { -namespace dom { - -class TestNode : public Node { -private: - std::vector> children; - -protected: - void doResolve(std::vector> &res, - const std::vector &path, Filter filter, - void *filterData, unsigned idx, VisitorSet &visited) override - { - for (auto &n : children) { - n->resolve(res, path, filter, filterData, idx, visited, nullptr); - } - } - -public: - using Node::Node; - - Rooted addChild(Handle node) - { - Owned nd = acquire(node); - children.push_back(nd); - return nd; - } -}; - -TEST(Node, isRoot) -{ - Manager mgr; - Rooted n1{new TestNode(mgr)}; - Rooted n2{new TestNode(mgr)}; - Rooted n3{new TestNode(mgr, n2)}; - ASSERT_TRUE(n1->isRoot()); - ASSERT_TRUE(n2->isRoot()); - ASSERT_FALSE(n3->isRoot()); - - n2->setParent(n1); - ASSERT_TRUE(n1->isRoot()); - ASSERT_FALSE(n2->isRoot()); - ASSERT_FALSE(n3->isRoot()); -} - -TEST(Node, simpleResolve) -{ - Manager mgr; - Rooted root{new TestNode(mgr, "root")}; - Rooted child1 = root->addChild(new TestNode(mgr, "child1")); - Rooted child11 = child1->addChild(new TestNode(mgr, "child11")); - - std::vector> res; - res = root->resolve(std::vector{"root", "child1", "child11"}); - ASSERT_EQ(1, res.size()); - ASSERT_TRUE(child11 == *(res.begin())); - - res = root->resolve(std::vector{"child1", "child11"}); - ASSERT_EQ(1, res.size()); - ASSERT_TRUE(child11 == *(res.begin())); - - res = root->resolve(std::vector{"child11"}); - ASSERT_EQ(1, res.size()); - ASSERT_TRUE(child11 == *(res.begin())); -} - -} -} diff --git a/test/core/model/NodeTest.cpp b/test/core/model/NodeTest.cpp new file mode 100644 index 0000000..1c58e2c --- /dev/null +++ b/test/core/model/NodeTest.cpp @@ -0,0 +1,90 @@ +/* + 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 . +*/ + +#include + +#include +#include + +namespace ousia { +namespace dom { + +class TestNode : public Node { +private: + std::vector> children; + +protected: + void doResolve(std::vector> &res, + const std::vector &path, Filter filter, + void *filterData, unsigned idx, VisitorSet &visited) override + { + for (auto &n : children) { + n->resolve(res, path, filter, filterData, idx, visited, nullptr); + } + } + +public: + using Node::Node; + + Rooted addChild(Handle node) + { + Owned nd = acquire(node); + children.push_back(nd); + return nd; + } +}; + +TEST(Node, isRoot) +{ + Manager mgr; + Rooted n1{new TestNode(mgr)}; + Rooted n2{new TestNode(mgr)}; + Rooted n3{new TestNode(mgr, n2)}; + ASSERT_TRUE(n1->isRoot()); + ASSERT_TRUE(n2->isRoot()); + ASSERT_FALSE(n3->isRoot()); + + n2->setParent(n1); + ASSERT_TRUE(n1->isRoot()); + ASSERT_FALSE(n2->isRoot()); + ASSERT_FALSE(n3->isRoot()); +} + +TEST(Node, simpleResolve) +{ + Manager mgr; + Rooted root{new TestNode(mgr, "root")}; + Rooted child1 = root->addChild(new TestNode(mgr, "child1")); + Rooted child11 = child1->addChild(new TestNode(mgr, "child11")); + + std::vector> res; + res = root->resolve(std::vector{"root", "child1", "child11"}); + ASSERT_EQ(1, res.size()); + ASSERT_TRUE(child11 == *(res.begin())); + + res = root->resolve(std::vector{"child1", "child11"}); + ASSERT_EQ(1, res.size()); + ASSERT_TRUE(child11 == *(res.begin())); + + res = root->resolve(std::vector{"child11"}); + ASSERT_EQ(1, res.size()); + ASSERT_TRUE(child11 == *(res.begin())); +} + +} +} -- cgit v1.2.3