diff options
Diffstat (limited to 'test/core/model')
-rw-r--r-- | test/core/model/DomainTest.cpp | 72 | ||||
-rw-r--r-- | test/core/model/NodeTest.cpp | 42 |
2 files changed, 53 insertions, 61 deletions
diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index f937842..9cd5bec 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -28,19 +28,14 @@ namespace ousia { namespace model { -void assert_path(std::vector<Rooted<Managed>> &result, size_t idx, - const RttiBase &expected_type, +void assert_path(const ResolutionResult &res, const RttiBase &expected_type, std::vector<std::string> expected_path) { - ASSERT_TRUE(result.size() > idx); - // check class/type - ASSERT_TRUE(result[idx]->isa(expected_type)); - // cast to node - Rooted<Node> n = result[idx].cast<Node>(); - // extract actual path - std::vector<std::string> actual_path = n->path(); - // check path - ASSERT_EQ(expected_path, actual_path); + // Check class/type + ASSERT_TRUE(res.node->isa(expected_type)); + + // Check path + ASSERT_EQ(expected_path, res.node->path()); } TEST(Domain, testDomainResolving) @@ -52,43 +47,38 @@ TEST(Domain, testDomainResolving) // Get the domain. Rooted<Domain> domain = constructBookDomain(mgr, sys, logger); - /* - * Start with the "book" search keyword. This should resolve to the domain - * itself (because it is called "book"), as well as the structure "book" - * node. - */ - std::vector<Rooted<Managed>> res = - domain->resolve(std::vector<std::string>{"book"}); + std::vector<ResolutionResult> res; + + // There is one domain called "book" + res = domain->resolve("book", typeOf<Domain>()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf<Domain>(), {"book"}); - // First we expect the book domain. - assert_path(res, 0, typeOf<Domain>(), {"book"}); - // Then the book structure. - assert_path(res, 1, typeOf<StructuredClass>(), {"book", "book"}); - ASSERT_EQ(2, res.size()); + // There is one domain called "book" + res = domain->resolve("book", typeOf<StructuredClass>()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf<StructuredClass>(), {"book", "book"}); // If we explicitly ask for the "book, book" path, then only the // StructuredClass should be returned. - res = domain->resolve(std::vector<std::string>{"book", "book"}); - assert_path(res, 0, typeOf<StructuredClass>(), {"book", "book"}); - ASSERT_EQ(1, res.size()); + res = domain->resolve(std::vector<std::string>{"book", "book"}, + typeOf<Domain>()); + ASSERT_EQ(0U, res.size()); + + res = domain->resolve(std::vector<std::string>{"book", "book"}, + typeOf<StructuredClass>()); + ASSERT_EQ(1U, res.size()); // If we ask for "section" the result should be unique as well. - res = domain->resolve(std::vector<std::string>{"section"}); - // TODO: Is that the path result we want? - assert_path(res, 0, typeOf<StructuredClass>(), {"book", "section"}); - ASSERT_EQ(1, res.size()); - - // If we ask for the path "book", "book", "" we reference the - // FieldDescriptor of the StructuredClass "book". - res = domain->resolve(std::vector<std::string>{"book", "book", ""}); - assert_path(res, 0, typeOf<FieldDescriptor>(), {"book", "book", ""}); - ASSERT_EQ(1, res.size()); - - // If we ask for "paragraph" it is references two times in the Domain graph, + res = domain->resolve("section", typeOf<StructuredClass>()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf<StructuredClass>(), {"book", "section"}); + + // If we ask for "paragraph" it is referenced two times in the Domain graph, // but should be returned only once. - res = domain->resolve("paragraph"); - assert_path(res, 0, typeOf<StructuredClass>(), {"book", "paragraph"}); - ASSERT_EQ(1, res.size()); + res = domain->resolve("paragraph", typeOf<StructuredClass>()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf<StructuredClass>(), {"book", "paragraph"}); } } } diff --git a/test/core/model/NodeTest.cpp b/test/core/model/NodeTest.cpp index 1c58e2c..334a311 100644 --- a/test/core/model/NodeTest.cpp +++ b/test/core/model/NodeTest.cpp @@ -22,20 +22,15 @@ #include <core/model/Node.hpp> namespace ousia { -namespace dom { class TestNode : public Node { private: std::vector<Owned<Node>> children; protected: - void doResolve(std::vector<Rooted<Managed>> &res, - const std::vector<std::string> &path, Filter filter, - void *filterData, unsigned idx, VisitorSet &visited) override + void continueResolve(ResolutionState &state) override { - for (auto &n : children) { - n->resolve(res, path, filter, filterData, idx, visited, nullptr); - } + continueResolveComposita(children, state); } public: @@ -49,6 +44,11 @@ public: } }; +namespace RttiTypes { +const Rtti<ousia::TestNode> TestNode = + RttiBuilder("TestNode").parent(RttiTypes::Node).composedOf(&TestNode); +} + TEST(Node, isRoot) { Manager mgr; @@ -72,19 +72,21 @@ TEST(Node, simpleResolve) Rooted<TestNode> child1 = root->addChild(new TestNode(mgr, "child1")); Rooted<TestNode> child11 = child1->addChild(new TestNode(mgr, "child11")); - std::vector<Rooted<Managed>> res; - res = root->resolve(std::vector<std::string>{"root", "child1", "child11"}); - ASSERT_EQ(1, res.size()); - ASSERT_TRUE(child11 == *(res.begin())); - - res = root->resolve(std::vector<std::string>{"child1", "child11"}); - ASSERT_EQ(1, res.size()); - ASSERT_TRUE(child11 == *(res.begin())); - - res = root->resolve(std::vector<std::string>{"child11"}); - ASSERT_EQ(1, res.size()); - ASSERT_TRUE(child11 == *(res.begin())); + std::vector<ResolutionResult> res; + res = root->resolve(std::vector<std::string>{"root", "child1", "child11"}, + RttiTypes::TestNode); + ASSERT_EQ(1U, res.size()); + ASSERT_TRUE(child11 == res[0].node); + + res = root->resolve(std::vector<std::string>{"child1", "child11"}, + RttiTypes::TestNode); + ASSERT_EQ(1U, res.size()); + ASSERT_TRUE(child11 == res[0].node); + + res = + root->resolve(std::vector<std::string>{"child11"}, RttiTypes::TestNode); + ASSERT_EQ(1U, res.size()); + ASSERT_TRUE(child11 == res[0].node); } } -} |