From 6dd18a83a1f2c89c5bca435090c80d72cb8716e3 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 17 Dec 2014 11:44:36 +0100 Subject: First draft of Cardinality. There are still semantic improvements to be made, though. --- test/core/model/DocumentTest.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/core/model/DocumentTest.cpp (limited to 'test/core/model/DocumentTest.cpp') diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp new file mode 100644 index 0000000..36e7c02 --- /dev/null +++ b/test/core/model/DocumentTest.cpp @@ -0,0 +1,32 @@ +/* + 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 + +namespace ousia { +namespace model { +TEST(Document, testDocumentConstruction) +{ + // Start by constructing the domain. + //TODO: IMPLEMENT + ASSERT_TRUE(true); +} +} +} -- cgit v1.2.3 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. --- src/core/managed/ManagedContainer.hpp | 11 ++++ src/core/model/Document.hpp | 8 ++- src/core/model/Domain.hpp | 41 +++++++++----- src/core/model/Typesystem.hpp | 2 + test/core/managed/ManagedContainerTest.cpp | 41 ++++++++++---- test/core/model/DocumentTest.cpp | 12 +++- test/core/model/ModelTestUtils.hpp | 90 ++++++++++++++++++++++++++++++ 7 files changed, 176 insertions(+), 29 deletions(-) create mode 100644 test/core/model/ModelTestUtils.hpp (limited to 'test/core/model/DocumentTest.cpp') diff --git a/src/core/managed/ManagedContainer.hpp b/src/core/managed/ManagedContainer.hpp index 19bff3f..6bf1915 100644 --- a/src/core/managed/ManagedContainer.hpp +++ b/src/core/managed/ManagedContainer.hpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "Manager.hpp" @@ -496,6 +497,16 @@ public: } Base::c.pop_back(); } + + Rooted operator[](int i) const { + for (const_iterator it = Base::cbegin(); it != Base::cend(); it++) { + if (i == 0) { + return Rooted(*it); + } + i--; + } + throw std::out_of_range(std::to_string(i) + " is out of range!"); + } }; /** diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 3114480..a31e52f 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -26,9 +26,11 @@ * * A Document, from top to bottom, consists of "Document" instance, * which "owns" the structural root node of the in-document graph. This might - * for example be a "book" node, if the respective document implements the - * "book" domain. That root node in turn has structure nodes as children as well - * as annotations that refer to the content of that structure node. + * for example be a "book" node of the "book" domain. That root node in turn has + * structure nodes as children, which in turn may have children. This + * constitutes a Structure Tree. Additionally annotations may be attached to + * Structure Nodes, effectively resulting in a Document Graph instead of a + * Document Tree (other references may introduce cycles as well). * * Consider this simplified XML representation of a document (TODO: Use * non-simplified XML as soon as possible): diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 9ae8871..e348136 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -91,8 +91,9 @@ namespace ousia { namespace model { -class StructuredClass; class Descriptor; +class StructuredClass; +class Domain; /** * As mentioned in the description above a FieldDescriptor specifies the @@ -147,17 +148,18 @@ public: * set to "PRIMITIVE". * * @param mgr is the global Manager instance. - * @param name is the name of this field. * @param parent is a handle of the Descriptor node that has this * FieldDescriptor. * @param primitiveType is a handle to some Type in some Typesystem of which * one instance is allowed to fill this field. + * @param name is the name of this field. * @param optional should be set to 'false' is this field needs to be * filled in order for an instance of the parent * Descriptor to be valid. */ - FieldDescriptor(Manager &mgr, std::string name, Handle parent, - Handle primitiveType, bool optional) + FieldDescriptor(Manager &mgr, Handle parent, + Handle primitiveType, std::string name = "", + bool optional = false) : Node(mgr, std::move(name), parent), children(this), fieldType(FieldType::PRIMITIVE), @@ -171,18 +173,19 @@ public: * children here. * * @param mgr is the global Manager instance. - * @param name is the name of this field. * @param parent is a handle of the Descriptor node that has this * FieldDescriptor. * @param fieldType is the FieldType of this FieldDescriptor, either * TREE for the main or default structure or SUBTREE * for supporting structures. + * @param name is the name of this field. * @param optional should be set to 'false' is this field needs to be * filled in order for an instance of the parent * Descriptor to be valid. */ - FieldDescriptor(Manager &mgr, std::string name, Handle parent, - FieldType fieldType, bool optional) + FieldDescriptor(Manager &mgr, Handle parent, + FieldType fieldType = FieldType::TREE, + std::string name = "", bool optional = false) : Node(mgr, std::move(name), parent), children(this), fieldType(fieldType), @@ -239,10 +242,10 @@ private: ManagedVector fieldDescriptors; public: - Descriptor(Manager &mgr, std::string name, Handle parent, + Descriptor(Manager &mgr, std::string name, Handle domain, // TODO: What would be a wise default value for attributes? Handle attributesDescriptor) - : Node(mgr, std::move(name), parent), + : Node(mgr, std::move(name), domain), attributesDescriptor(acquire(attributesDescriptor)), fieldDescriptors(this) { @@ -351,12 +354,13 @@ private: public: const bool transparent; - StructuredClass(Manager &mgr, std::string name, Handle parent, - Handle attributesDescriptor, + StructuredClass(Manager &mgr, std::string name, Handle domain, const Cardinality &cardinality, + Handle attributesDescriptor = {nullptr}, // TODO: What would be a wise default value for isa? - Handle isa, bool transparent) - : Descriptor(mgr, std::move(name), parent, attributesDescriptor), + Handle isa = {nullptr}, + bool transparent = false) + : Descriptor(mgr, std::move(name), domain, attributesDescriptor), cardinality(cardinality), isa(acquire(isa)), parents(this), @@ -393,13 +397,15 @@ class Domain : public Node { private: ManagedVector rootStructures; ManagedVector annotationClasses; + ManagedVector typesystems; public: Domain(Manager &mgr, std::string name) // TODO: Can a domain have a parent? : Node(mgr, std::move(name), nullptr), rootStructures(this), - annotationClasses(this) + annotationClasses(this), + typesystems(this) { } @@ -423,6 +429,13 @@ public: { return annotationClasses; } + + ManagedVector &getTypesystems() { return typesystems; } + + const ManagedVector &getTypesystems() const + { + return typesystems; + } }; } } diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index 347adb8..90154ce 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -372,6 +372,8 @@ public: * TODO: DOC */ void addType(Handle type) { types.push_back(type); } + + const NodeVector &getTypes() const { return types; } }; } } diff --git a/test/core/managed/ManagedContainerTest.cpp b/test/core/managed/ManagedContainerTest.cpp index c34541a..7ff819f 100644 --- a/test/core/managed/ManagedContainerTest.cpp +++ b/test/core/managed/ManagedContainerTest.cpp @@ -38,7 +38,7 @@ TEST(ManagedVector, managedVector) { Rooted root{new Managed{mgr}}; - std::vector elems; + std::vector elems; for (int i = 0; i < nElem; i++) { elems.push_back(new TestManaged{mgr, a[i]}); } @@ -49,7 +49,8 @@ TEST(ManagedVector, managedVector) ManagedVector v(root, elems.begin(), elems.end()); - // Remove the last element from the list. It should be garbage collected. + // Remove the last element from the list. It should be garbage + // collected. v.pop_back(); ASSERT_FALSE(a[nElem - 1]); @@ -85,7 +86,6 @@ TEST(ManagedVector, managedVector) } } - TEST(ManagedVector, moveAssignment) { constexpr int nElem = 16; @@ -220,16 +220,39 @@ TEST(ManagedVector, moveWithNewOwner) } } -class TestManagedWithContainer : public Managed { +TEST(ManagedVector, accessOperator) +{ + Manager mgr{1}; + Rooted root{new Managed{mgr}}; + ManagedVector instance{root}; + Rooted elem{new Managed{mgr}}; + instance.push_back(elem); + + ASSERT_EQ(elem, instance[0]); + + // Test out of bounds. + bool caught = false; + try { + instance[1]; + } + catch (std::out_of_range ex) { + caught = true; + } + ASSERT_TRUE(caught); + + instance.push_back(elem); + ASSERT_EQ(elem, instance[1]); +} +class TestManagedWithContainer : public Managed { public: ManagedVector elems; - TestManagedWithContainer(Manager &mgr) : Managed(mgr), elems(this) {}; - + TestManagedWithContainer(Manager &mgr) : Managed(mgr), elems(this){}; }; -TEST(ManagedVector, embedded) { +TEST(ManagedVector, embedded) +{ // Note: This test depends on the correct deletion order -- otherwise // valgrind shows an error bool a; @@ -248,7 +271,6 @@ TEST(ManagedVector, embedded) { ASSERT_FALSE(a); } - TEST(ManagedMap, managedMap) { // TODO: This test is highly incomplete @@ -260,7 +282,7 @@ TEST(ManagedMap, managedMap) { Rooted root{new Managed{mgr}}; - std::map elems; + std::map elems; for (int i = 0; i < nElem; i++) { elems.insert(std::make_pair(i, new TestManaged{mgr, a[i]})); } @@ -298,6 +320,5 @@ TEST(ManagedMap, managedMap) ASSERT_FALSE(v); } } - } diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index 36e7c02..dd883a4 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -20,12 +20,20 @@ #include +#include "ModelTestUtils.hpp" + namespace ousia { namespace model { + + TEST(Document, testDocumentConstruction) { - // Start by constructing the domain. - //TODO: IMPLEMENT + // Construct Manager + Manager mgr{1}; + // Get the domain. + Rooted domain = constructBookDomain(mgr); + + // TODO: IMPLEMENT ASSERT_TRUE(true); } } 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 From 23e593eb69f6d0beb197f33ae31b479c60d9316f Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 19 Dec 2014 00:29:55 +0100 Subject: added convenience function for document construction and tested them. --- src/core/model/Document.cpp | 104 ++++++++++++++++++++++++++++++++++++++- src/core/model/Document.hpp | 100 +++++++++++++++++++++++++++++++++++-- test/core/model/DocumentTest.cpp | 12 +++-- test/core/model/TestDocument.hpp | 67 +++++++++++++++++++++++++ 4 files changed, 275 insertions(+), 8 deletions(-) create mode 100644 test/core/model/TestDocument.hpp (limited to 'test/core/model/DocumentTest.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 31b22e3..709981b 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -58,7 +58,7 @@ int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName) } void DocumentEntity::getField(ManagedVector &res, - const std::string &fieldName) + const std::string &fieldName) { int f = getFieldDescriptorIndex(fieldName); if (f < 0) { @@ -85,6 +85,108 @@ ManagedVector &DocumentEntity::getField( "The given FieldDescriptor is not specified in the Descriptor of this " "node."); } + +static Rooted resolveDescriptor( + std::vector> domains, const std::string &className) +{ + // iterate over all domains. + for (auto &d : domains) { + // use the actual resolve method. + std::vector> resolved = d->resolve(className); + // if we don't find anything, continue. + if (resolved.size() == 0) { + continue; + } + // Otherwise take the first valid result. + for (auto &r : resolved) { + Managed *m = &(*r); + StructuredClass *c = dynamic_cast(m); + if (c != nullptr) { + return Rooted(c); + } + } + } + return {nullptr}; +} + +Rooted StructuredEntity::buildRootEntity( + Handle document, std::vector> domains, + const std::string &className, Variant attributes, std::string name) +{ + // If the parent is not set, we can not build the entity. + if (document == nullptr) { + return {nullptr}; + } + // If we can not find the correct descriptor, we can not build the entity + // either. + Rooted descriptor = resolveDescriptor(domains, className); + if (descriptor == nullptr) { + return {nullptr}; + } + // Then construct the StructuredEntity itself. + Rooted root{ + new StructuredEntity(document->getManager(), document, descriptor, + attributes, std::move(name))}; + // append it to the document. + document->setRoot(root); + // and return it. + return root; +} + +Rooted StructuredEntity::buildEntity( + Handle parent, std::vector> domains, + const std::string &className, const std::string &fieldName, + Variant attributes, std::string name) +{ + // If the parent is not set, we can not build the entity. + if (parent == nullptr) { + return {nullptr}; + } + // If we can not find the correct descriptor, we can not build the entity + // either. + Rooted descriptor = resolveDescriptor(domains, className); + if (descriptor == nullptr) { + return {nullptr}; + } + // Then construct the StructuredEntity itself. + Rooted entity{new StructuredEntity( + parent->getManager(), parent, descriptor, attributes, std::move(name))}; + // if the field does not exist, return null handle as well. + if (!parent->hasField(fieldName)) { + return {nullptr}; + } + // append the new entity to the right field. + ManagedVector field{parent}; + parent->getField(field, fieldName); + field.push_back(entity); + + // and return it. + return entity; +} + +Rooted DocumentPrimitive::buildEntity( + Handle parent, Variant content, + const std::string &fieldName) +{ + // If the parent is not set, we can not build the entity. + if (parent == nullptr) { + return {nullptr}; + } + // Then construct the StructuredEntity itself. + Rooted entity{ + new DocumentPrimitive(parent->getManager(), parent, content)}; + // if the field does not exist, return null handle as well. + if (!parent->hasField(fieldName)) { + return {nullptr}; + } + // append the new entity to the right field. + ManagedVector field{parent}; + parent->getField(field, fieldName); + field.push_back(entity); + + // and return it. + return entity; +} } } diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index a31e52f..15a4599 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -80,6 +80,7 @@ namespace model { class StructuredEntity; class AnnotationEntity; +class Document; /** * A DocumentEntity is the common superclass for StructuredEntities and @@ -110,8 +111,11 @@ public: { // TODO: Validation at construction time? // insert empty vectors for each field. - for (size_t f = 0; f < descriptor->getFieldDescriptors().size(); f++) { - fields.push_back(ManagedVector(this)); + if (!descriptor.isNull()) { + for (size_t f = 0; f < descriptor->getFieldDescriptors().size(); + f++) { + fields.push_back(ManagedVector(this)); + } } } @@ -202,6 +206,57 @@ public: } ManagedVector &getAnnotations() { return annotations; } + + /** + * This builds the root StructuredEntity for the given document. It + * automatically appends the newly build entity to the given document. + * + * @param document is the document this entity shall be build for. The + * resulting entity will automatically be appended to that + * document. Also the manager of that document will be + * used to register the new node. + * @param domains are the domains that are used to find the + * StructuredClass for the new node. The domains will be + * searched in the given order. + * @param className is the name of the StructuredClass. + * @param attributes are the attributes of the new node in terms of a Struct + * variant (empty per default). + * @param name is the name of this StructuredEntity (empty per + * default). + * @return the newly created StructuredEntity or a nullptr if some + * input handle was empty or the given domains did not + * contain a StructuredClass with the given name. + */ + static Rooted buildRootEntity( + Handle document, std::vector> domains, + const std::string &className, Variant attributes = Variant(), + std::string name = ""); + + /** + * This builds a StructuredEntity as child of the given DocumentEntity. It + * automatically appends the newly build entity to its parent. + * + * @param parent is the parent DocumentEntity. The newly constructed + * StructuredEntity will automatically be appended to it. + * @param domains are the domains that are used to find the + * StructuredClass for the new node. The domains will be + * searched in the given order. + * @param className is the name of the StructuredClass. + * @param fieldName is the name of the field where the newly constructed + * StructuredEntity shall be appended. + * @param attributes are the attributes of the new node in terms of a Struct + * variant (empty per default). + * @param name is the name of this StructuredEntity (empty per + * default). + * + * @return the newly created StructuredEntity or a nullptr if some + * input handle was empty or the given domains did not + * contain a StructuredClass with the given name. + */ + static Rooted buildEntity( + Handle parent, std::vector> domains, + const std::string &className, const std::string &fieldName = "", + Variant attributes = Variant(), std::string name = ""); }; /** @@ -211,7 +266,7 @@ public: */ class DocumentPrimitive : public StructuredEntity { public: - DocumentPrimitive(Manager &mgr, Handle parent, + DocumentPrimitive(Manager &mgr, Handle parent, Variant content) : StructuredEntity(mgr, parent, nullptr, std::move(content)) { @@ -220,6 +275,25 @@ public: Variant getContent() const { return getAttributes(); } // TODO: Override such methods like "getField" to disable them? + + /** + * This builds a DocumentPrimitive as child of the given DocumentEntity. It + * automatically appends the newly build entity to its parent. + * + * @param parent is the parent DocumentEntity. The newly constructed + * DocumentPrimitive will automatically be appended to it. + * @param content is the primitive content of the new node in terms of a + * Struct variant. + * @param fieldName is the name of the field where the newly constructed + * StructuredEntity shall be appended. + * + * @return the newly created StructuredEntity or a nullptr if some + * input handle was empty or the given domains did not + * contain a StructuredClass with the given name. + */ + static Rooted buildEntity( + Handle parent, + Variant content, const std::string &fieldName = ""); }; /** @@ -284,6 +358,26 @@ public: Rooted getEnd() { return end; } }; + +/** + * A Document is mainly a wrapper for the Root structure node of the Document + * Graph. + */ +class Document : public Node { +private: + Owned root; + +public: + Document(Manager &mgr, std::string name) + // TODO: Can a document have a parent? + : Node(mgr, std::move(name), nullptr) + { + } + + void setRoot(Handle root) { root = acquire(root); }; + + Rooted getRoot() const { return root; } +}; } } diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index dd883a4..26553dd 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -19,8 +19,10 @@ #include #include +#include -#include "ModelTestUtils.hpp" +#include "TestDocument.hpp" +#include "TestDomain.hpp" namespace ousia { namespace model { @@ -32,9 +34,11 @@ TEST(Document, testDocumentConstruction) Manager mgr{1}; // Get the domain. Rooted domain = constructBookDomain(mgr); - - // TODO: IMPLEMENT - ASSERT_TRUE(true); + // Construct the document. + Rooted doc = constructBookDocument(mgr, domain); + + // If that works we are happy already. + ASSERT_FALSE(doc.isNull()); } } } diff --git a/test/core/model/TestDocument.hpp b/test/core/model/TestDocument.hpp new file mode 100644 index 0000000..c99bdd3 --- /dev/null +++ b/test/core/model/TestDocument.hpp @@ -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 . +*/ + +#ifndef _MODEL_TEST_DOCUMENT_HPP_ +#define _MODEL_TEST_DOCUMENT_HPP_ + +#include +#include +#include + +namespace ousia { +namespace model { + +/** + * This constructs a fairly simple test document for the "book" domain. The + * structure of the document can be seen in the Code below. + */ +static Rooted constructBookDocument(Manager &mgr, + Rooted bookDomain) +{ + // Start with the (empty) document. + Rooted doc{new Document(mgr, "myDoc.oxd")}; + + // Add the root. + Rooted root = + StructuredEntity::buildRootEntity(doc, {bookDomain}, "book"); + if (root.isNull()) { + return {nullptr}; + } + + // Add a paragraph. + Rooted foreword = + StructuredEntity::buildEntity(root, {bookDomain}, "paragraph"); + if (foreword.isNull()) { + return {nullptr}; + } + // Add its text. + Variant text{std::map{ + {"content", Variant("Some introductory text")}}}; + Rooted text_primitive = + DocumentPrimitive::buildEntity(foreword, text, "text"); + // Add a section. + Rooted section = + StructuredEntity::buildEntity(root, {bookDomain}, "section"); + + return doc; +} +} +} + +#endif /* _TEST_DOCUMENT_HPP_ */ + -- cgit v1.2.3