diff options
Diffstat (limited to 'test/core/model')
-rw-r--r-- | test/core/model/TestAdvanced.hpp | 28 | ||||
-rw-r--r-- | test/core/model/TestDocument.hpp | 11 | ||||
-rw-r--r-- | test/core/model/TestDocumentBuilder.hpp | 90 |
3 files changed, 14 insertions, 115 deletions
diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index 15a4042..f8585d1 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -115,11 +115,9 @@ static Rooted<Domain> constructEmphasisDomain(Manager &mgr, // set up domain node. Rooted<Domain> domain{new Domain(mgr, sys, "emphasis")}; // create AnnotationClasses - Rooted<AnnotationClass> em{ - new AnnotationClass(mgr, "emphasized", domain)}; + Rooted<AnnotationClass> em{new AnnotationClass(mgr, "emphasized", domain)}; - Rooted<AnnotationClass> strong{ - new AnnotationClass(mgr, "strong", domain)}; + Rooted<AnnotationClass> strong{new AnnotationClass(mgr, "strong", domain)}; return domain; } @@ -135,12 +133,8 @@ static bool addText(Logger &logger, Handle<Document> doc, } // And the primitive content Variant content_var{content.c_str()}; - Rooted<DocumentPrimitive> primitive = - buildPrimitiveEntity(logger, text, content_var, "content"); - if (primitive.isNull()) { - return false; - } - + Rooted<DocumentPrimitive> primitive{new DocumentPrimitive( + parent->getManager(), text, content_var, "content")}; return true; } @@ -167,19 +161,12 @@ static bool addAnnotation(Logger &logger, Handle<Document> doc, Handle<StructuredEntity> parent, const std::string &text, const std::string &annoClass) { - Rooted<AnnotationEntity::Anchor> start = - buildAnchor(logger, parent, std::to_string(annoIdx++)); - if (start.isNull()) { - return false; - } + Manager& mgr = parent->getManager(); + Rooted<Anchor> start{new Anchor(mgr, std::to_string(annoIdx++), parent)}; if (!addText(logger, doc, parent, text)) { return false; } - Rooted<AnnotationEntity::Anchor> end = - buildAnchor(logger, parent, std::to_string(annoIdx++)); - if (end.isNull()) { - return false; - } + Rooted<Anchor> end{new Anchor(mgr, std::to_string(annoIdx++), parent)}; Rooted<AnnotationEntity> anno = buildAnnotationEntity(doc, logger, {annoClass}, start, end); if (anno.isNull()) { @@ -191,7 +178,6 @@ static bool addAnnotation(Logger &logger, Handle<Document> doc, /** * This constructs a more advanced book document using not only the book * domain but also headings, emphasis and lists. - * TODO: insert emphasis and lists. */ static Rooted<Document> constructAdvancedDocument(Manager &mgr, Logger &logger, Handle<Domain> bookDom, diff --git a/test/core/model/TestDocument.hpp b/test/core/model/TestDocument.hpp index eaec42c..2397fe6 100644 --- a/test/core/model/TestDocument.hpp +++ b/test/core/model/TestDocument.hpp @@ -60,11 +60,8 @@ static Rooted<Document> constructBookDocument(Manager &mgr, Logger &logger, } // And its primitive content Variant text{"Some introductory text"}; - Rooted<DocumentPrimitive> foreword_primitive = - buildPrimitiveEntity(logger, foreword_text, text, "content"); - if (foreword_primitive.isNull()) { - return {nullptr}; - } + Rooted<DocumentPrimitive> foreword_primitive{ + new DocumentPrimitive(mgr, foreword_text, text, "content")}; // Add a section. Rooted<StructuredEntity> section = buildStructuredEntity(doc, logger, root, {"section"}); @@ -82,8 +79,8 @@ static Rooted<Document> constructBookDocument(Manager &mgr, Logger &logger, } // And its primitive content text = Variant{"Some actual text"}; - Rooted<DocumentPrimitive> main_primitive = - buildPrimitiveEntity(logger, main_text, text, "content"); + Rooted<DocumentPrimitive> main_primitive{ + new DocumentPrimitive(mgr, main_text, text, "content")}; if (main_primitive.isNull()) { return {nullptr}; } diff --git a/test/core/model/TestDocumentBuilder.hpp b/test/core/model/TestDocumentBuilder.hpp index ae7b3fd..dc0479d 100644 --- a/test/core/model/TestDocumentBuilder.hpp +++ b/test/core/model/TestDocumentBuilder.hpp @@ -107,8 +107,6 @@ Rooted<StructuredEntity> buildRootStructuredEntity(Handle<Document> document, Rooted<StructuredEntity> root{new StructuredEntity( document->getManager(), document, descriptor.cast<StructuredClass>(), attributes, std::move(name))}; - // append it to the document. - document->setRoot(root); // and return it. return root; } @@ -162,95 +160,13 @@ Rooted<StructuredEntity> buildStructuredEntity( // Then construct the StructuredEntity itself. Rooted<StructuredEntity> entity{new StructuredEntity( parent->getManager(), parent, descriptor.cast<StructuredClass>(), - attributes, std::move(name))}; - // if the field does not exist, return null handle as well. - if (!parent->hasField(fieldName)) { - logger.error(std::string("The parent has no field of the name ") + - fieldName + "!"); - return {nullptr}; - } - parent->addStructureNode(entity, fieldName); + attributes, fieldName, std::move(name))}; // and return it. return entity; } /** - * This builds a DocumentPrimitive as child of the given DocumentEntity. It - * automatically appends the newly build entity to its parent. - * - * @param logger is the current logger. - * @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 DocumentPrimitive or a nullptr if some - * input handle was empty. - */ -Rooted<DocumentPrimitive> buildPrimitiveEntity( - Logger &logger, Handle<StructuredEntity> parent, Variant content = {}, - const std::string &fieldName = "") -{ - // If the input handles are not set, we can not build the entity. - if (parent == nullptr) { - logger.error("The input parent handle was null!"); - return {nullptr}; - } - // Then construct the StructuredEntity itself. - Rooted<DocumentPrimitive> entity{ - new DocumentPrimitive(parent->getManager(), parent, content)}; - // if the field does not exist, return null handle as well. - if (!parent->hasField(fieldName)) { - logger.error(std::string("The parent has no field of the name ") + - fieldName + "!"); - return {nullptr}; - } - parent->addStructureNode(entity, fieldName); - // and return it. - return entity; -} - -/** - * This builds an Anchor as child of the given DocumentEntity. It - * automatically appends the newly build Anchor to its parent. - * - * @param logger is the current logger. - * @param parent is the parent DocumentEntity. The newly constructed - * Anchor will automatically be appended to it. - * @param id is the id of this Anchor. - * @param fieldName is the name of the field where the newly constructed - * Anchor shall be appended. - * - * @return the newly created Anchor or a nullptr if some - * input handle was empty. - */ -Rooted<AnnotationEntity::Anchor> buildAnchor(Logger &logger, - Handle<StructuredEntity> parent, - std::string id, - const std::string &fieldName = "") -{ - // If the parent is not set, we can not build the anchor. - if (parent == nullptr) { - logger.error("The input parent handle was null!"); - return {nullptr}; - } - // Then construct the Anchor itself - Rooted<AnnotationEntity::Anchor> anchor{ - new AnnotationEntity::Anchor(parent->getManager(), id, parent)}; - // append the new entity to the right field. - if (!parent->hasField(fieldName)) { - logger.error(std::string("The parent has no field of the name ") + - fieldName + "!"); - return {nullptr}; - } - parent->addStructureNode(anchor, fieldName); - // and return it. - return anchor; -} -/** * This builds an AnnotationEntity as child of the given Document. It * automatically appends the newly build entity to its parent. * @@ -271,8 +187,8 @@ Rooted<AnnotationEntity::Anchor> buildAnchor(Logger &logger, */ Rooted<AnnotationEntity> buildAnnotationEntity( Handle<Document> document, Logger &logger, const Path &path, - Handle<AnnotationEntity::Anchor> start, - Handle<AnnotationEntity::Anchor> end, Variant attributes = {}, + Handle<Anchor> start, + Handle<Anchor> end, Variant attributes = {}, std::string name = "") { // If the input handles are not set, we can not build the entity. |