From 93c065174e1aa306ee724dd523ef6b2254c1d388 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 17 Dec 2014 17:11:51 +0100 Subject: Some (slight) changes to existing structures and first attempts on a test to construct a test comain and a test document out of thin air. I am, indeed, an alchemist. --- test/core/model/ModelTestUtils.hpp | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 test/core/model/ModelTestUtils.hpp (limited to 'test/core/model/ModelTestUtils.hpp') diff --git a/test/core/model/ModelTestUtils.hpp b/test/core/model/ModelTestUtils.hpp new file mode 100644 index 0000000..665e351 --- /dev/null +++ b/test/core/model/ModelTestUtils.hpp @@ -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 . +*/ + +#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_ */ + -- cgit v1.2.3