From 94a60d364203f633370e1b0a77ec5b89428032e3 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 18 Dec 2014 14:49:50 +0100 Subject: Hopefully implemented a working version of the Domain resolve mechanism. --- test/core/model/DomainTest.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/core/model/DomainTest.cpp (limited to 'test/core/model/DomainTest.cpp') diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp new file mode 100644 index 0000000..b1538cf --- /dev/null +++ b/test/core/model/DomainTest.cpp @@ -0,0 +1,67 @@ +/* + 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 + +#include "ModelTestUtils.hpp" + +namespace ousia { +namespace model { + +void assert_path(std::vector> &result, size_t idx, + const std::type_info& expected_type, + std::vector expected_path) +{ + ASSERT_TRUE(result.size() > idx); + // check class/type + ASSERT_EQ(expected_type, typeid(*result[idx])); + // transform to node + Managed *m = &(*result[idx]); + Node *n = dynamic_cast(m); + ASSERT_TRUE(n); + // extract actual path + std::vector actual_path = n->path(); + // check path + ASSERT_EQ(expected_path, actual_path); +} + +TEST(Document, testDomainResolving) +{ + // Construct Manager + Manager mgr{1}; + // Get the domain. + Rooted domain = constructBookDomain(mgr); + + /* + * 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"}); + // First we expect the book domain. + assert_path(res, 0, typeid(Domain), {"book"}); + // Then the book structure. + assert_path(res, 1, typeid(StructuredClass), {"book", "book"}); +} +} +} -- cgit v1.2.3 From 776fbb600da5fb5268e1b803e74fe7f8b0ea2746 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 18 Dec 2014 21:44:17 +0100 Subject: Finished the Domain test for now. Resolving mechanism works as expected (or at least well enough). --- test/core/model/DomainTest.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'test/core/model/DomainTest.cpp') diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index b1538cf..57ec91c 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -28,7 +28,7 @@ namespace ousia { namespace model { void assert_path(std::vector> &result, size_t idx, - const std::type_info& expected_type, + const std::type_info &expected_type, std::vector expected_path) { ASSERT_TRUE(result.size() > idx); @@ -62,6 +62,39 @@ TEST(Document, testDomainResolving) assert_path(res, 0, typeid(Domain), {"book"}); // Then the book structure. assert_path(res, 1, typeid(StructuredClass), {"book", "book"}); + ASSERT_EQ(2, res.size()); + + /* + * 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, typeid(StructuredClass), {"book", "book"}); + ASSERT_EQ(1, 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, typeid(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{"book", "book", ""}); + assert_path(res, 0, typeid(FieldDescriptor), {"book", "book", ""}); + ASSERT_EQ(1, res.size()); + + /* + * If we ask for "paragraph" it is references two times in the Domain graph, + * but should be returned only once. + */ + res = domain->resolve("paragraph"); + assert_path(res, 0, typeid(StructuredClass), {"book", "paragraph"}); + ASSERT_EQ(1, res.size()); } } } -- cgit v1.2.3 From 55d363bea503c0607c80604280c26c235a5d7ee1 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 19 Dec 2014 00:29:02 +0100 Subject: refactored DomainTest somewhat to prevent an unused function warning. --- test/core/model/DomainTest.cpp | 2 +- test/core/model/ModelTestUtils.hpp | 90 ------------------------------------ test/core/model/TestDomain.hpp | 94 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 91 deletions(-) delete mode 100644 test/core/model/ModelTestUtils.hpp create mode 100644 test/core/model/TestDomain.hpp (limited to 'test/core/model/DomainTest.cpp') diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index 57ec91c..f6dff3c 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -22,7 +22,7 @@ #include -#include "ModelTestUtils.hpp" +#include "TestDomain.hpp" namespace ousia { namespace model { diff --git a/test/core/model/ModelTestUtils.hpp b/test/core/model/ModelTestUtils.hpp deleted file mode 100644 index 665e351..0000000 --- a/test/core/model/ModelTestUtils.hpp +++ /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 . -*/ - -#ifndef _MODEL_TEST_UTILS_HPP_ -#define _MODEL_TEST_UTILS_HPP_ - -#include -#include - -namespace ousia { -namespace model { - -/** - * This constructs a somewhat trivial system of standard types. - * - * Currently contained: string - */ -static Rooted constructTypeSystem(Manager &mgr) -{ - Rooted sys{new Typesystem(mgr, "std")}; - Rooted string{new StringType(mgr, sys)}; - sys->addType(string); - - return sys; -} - -/** - * This constructs the "book" domain for test purposes. The structure of the - * domain is fairly and can be seen from the construction itself. - */ -static Rooted constructBookDomain(Manager &mgr) -{ - // Start with the Domain itself. - Rooted domain{new Domain(mgr, "book")}; - // The standard type system. - domain->getTypesystems().push_back(constructTypeSystem(mgr)); - // Set up the cardinalities we'll need. - Cardinality single; - single.merge({1}); - Cardinality any; - any.merge(Range::typeRangeFrom(0)); - - // Set up the "book" node. - Rooted book{ - new StructuredClass(mgr, "book", domain, single)}; - domain->getRootStructures().push_back(book); - // The structure field of it. - Rooted book_field{new FieldDescriptor(mgr, book)}; - book->getFieldDescriptors().push_back(book_field); - - // From there on the "section". - Rooted section{ - new StructuredClass(mgr, "section", domain, any)}; - book_field->getChildren().push_back(section); - // And the field of it. - Rooted section_field{new FieldDescriptor(mgr, section)}; - section->getFieldDescriptors().push_back(section_field); - - // We also add the "paragraph", which is transparent. - Rooted paragraph{new StructuredClass( - mgr, "paragraph", domain, any, {nullptr}, {nullptr}, true)}; - section_field->getChildren().push_back(paragraph); - book_field->getChildren().push_back(paragraph); - // ... and has a primitive field. - Rooted text{new FieldDescriptor( - mgr, paragraph, domain->getTypesystems()[0]->getTypes()[0], "text", - false)}; - - return domain; -} -} -} - -#endif /* _TEST_MANAGED_H_ */ - diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp new file mode 100644 index 0000000..41fcdef --- /dev/null +++ b/test/core/model/TestDomain.hpp @@ -0,0 +1,94 @@ +/* + 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 . +*/ + +#ifndef _MODEL_TEST_DOMAIN_HPP_ +#define _MODEL_TEST_DOMAIN_HPP_ + +#include +#include + +namespace ousia { +namespace model { + +/** + * This constructs a somewhat trivial system of standard types. + * + * Currently contained: string, text (struct wrapper for string) + */ +static Rooted constructTypeSystem(Manager &mgr) +{ + Rooted sys{new Typesystem(mgr, "std")}; + Rooted string{new StringType(mgr, sys)}; + sys->addType(string); + Rooted string_struct{new StructType( + mgr, "text", sys, {{"content", "", false, sys->acquire(string)}})}; + sys->addType(string_struct); + + return sys; +} + +/** + * This constructs the "book" domain for test purposes. The structure of the + * domain is fairly simple and can be seen from the construction itself. + */ +static Rooted constructBookDomain(Manager &mgr) +{ + // Start with the Domain itself. + Rooted domain{new Domain(mgr, "book")}; + // The standard type system. + domain->getTypesystems().push_back(constructTypeSystem(mgr)); + // Set up the cardinalities we'll need. + Cardinality single; + single.merge({1}); + Cardinality any; + any.merge(Range::typeRangeFrom(0)); + + // Set up the "book" node. + Rooted book{ + new StructuredClass(mgr, "book", domain, single)}; + domain->getRootStructures().push_back(book); + // The structure field of it. + Rooted book_field{new FieldDescriptor(mgr, book)}; + book->getFieldDescriptors().push_back(book_field); + + // From there on the "section". + Rooted section{ + new StructuredClass(mgr, "section", domain, any)}; + book_field->getChildren().push_back(section); + // And the field of it. + Rooted section_field{new FieldDescriptor(mgr, section)}; + section->getFieldDescriptors().push_back(section_field); + + // We also add the "paragraph", which is transparent. + Rooted paragraph{new StructuredClass( + mgr, "paragraph", domain, any, {nullptr}, {nullptr}, true)}; + section_field->getChildren().push_back(paragraph); + book_field->getChildren().push_back(paragraph); + // ... and has a primitive field. + Rooted paragraph_field{new FieldDescriptor( + mgr, paragraph, domain->getTypesystems()[0]->getTypes()[1], "text", + false)}; + paragraph->getFieldDescriptors().push_back(paragraph_field); + + return domain; +} +} +} + +#endif /* _TEST_DOMAIN_HPP_ */ + -- cgit v1.2.3