From 0605eed698443dc18c48340084507c90e97a9333 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 9 Jan 2015 01:09:07 +0100 Subject: Adapted code to new resolve function --- test/core/model/DomainTest.cpp | 72 ++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 41 deletions(-) (limited to 'test') 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> &result, size_t idx, - const RttiBase &expected_type, +void assert_path(const ResolutionResult &res, const RttiBase &expected_type, std::vector expected_path) { - ASSERT_TRUE(result.size() > idx); - // check class/type - ASSERT_TRUE(result[idx]->isa(expected_type)); - // cast to node - Rooted n = result[idx].cast(); - // extract actual path - std::vector 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 = 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> res = - domain->resolve(std::vector{"book"}); + std::vector res; + + // There is one domain called "book" + res = domain->resolve("book", typeOf()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf(), {"book"}); - // First we expect the book domain. - assert_path(res, 0, typeOf(), {"book"}); - // Then the book structure. - assert_path(res, 1, typeOf(), {"book", "book"}); - ASSERT_EQ(2, res.size()); + // There is one domain called "book" + res = domain->resolve("book", typeOf()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf(), {"book", "book"}); // If we explicitly ask for the "book, book" path, then only the // StructuredClass should be returned. - res = domain->resolve(std::vector{"book", "book"}); - assert_path(res, 0, typeOf(), {"book", "book"}); - ASSERT_EQ(1, res.size()); + res = domain->resolve(std::vector{"book", "book"}, + typeOf()); + ASSERT_EQ(0U, res.size()); + + res = domain->resolve(std::vector{"book", "book"}, + typeOf()); + ASSERT_EQ(1U, res.size()); // If we ask for "section" the result should be unique as well. - res = domain->resolve(std::vector{"section"}); - // TODO: Is that the path result we want? - assert_path(res, 0, typeOf(), {"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{"book", "book", ""}); - assert_path(res, 0, typeOf(), {"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()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf(), {"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(), {"book", "paragraph"}); - ASSERT_EQ(1, res.size()); + res = domain->resolve("paragraph", typeOf()); + ASSERT_EQ(1U, res.size()); + assert_path(res[0], typeOf(), {"book", "paragraph"}); } } } -- cgit v1.2.3