From c6b502d45d2bf916f747411df37df186c4ed4981 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 13 Jan 2015 23:32:48 +0100 Subject: First version of 'pathTo' function enabling users to request a Structure Path from some descriptor to another. --- test/core/model/DomainTest.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/core/model/DomainTest.cpp') diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index 317223d..d22c845 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -80,5 +80,47 @@ TEST(Domain, testDomainResolving) ASSERT_EQ(1U, res.size()); assert_path(res[0], typeOf(), {"book", "paragraph"}); } + +Rooted getClass(const std::string name, Handle dom) +{ + std::vector res = + dom->resolve(name, RttiTypes::StructuredClass); + return res[0].node.cast(); +} + +TEST(Descriptor, pathTo) +{ + // Start with some easy examples from the book domain. + Logger logger; + Manager mgr{1}; + Rooted sys{new SystemTypesystem(mgr)}; + // Get the domain. + Rooted domain = constructBookDomain(mgr, sys, logger); + + // get the book node and the section node. + Rooted book = getClass("book", domain); + Rooted section = getClass("section", domain); + // get the path in between. + std::vector> path = book->pathTo(section); + ASSERT_EQ(1, path.size()); + ASSERT_TRUE(path[0]->isa(RttiTypes::FieldDescriptor)); + + // get the text node. + Rooted text = getClass("text", domain); + // get the path between book and text via paragraph. + path = book->pathTo(text); + ASSERT_EQ(3, path.size()); + ASSERT_TRUE(path[0]->isa(RttiTypes::FieldDescriptor)); + ASSERT_TRUE(path[1]->isa(RttiTypes::StructuredClass)); + ASSERT_EQ("paragraph", path[1]->getName()); + ASSERT_TRUE(path[2]->isa(RttiTypes::FieldDescriptor)); + + // get the subsection node. + Rooted subsection = getClass("subsection", domain); + // try to get the path between book and subsection. + path = book->pathTo(subsection); + // this should be impossible. + ASSERT_EQ(0, path.size()); +} } } -- cgit v1.2.3