diff options
-rw-r--r-- | src/plugins/html/DemoOutput.cpp | 36 | ||||
-rw-r--r-- | src/plugins/html/DemoOutput.hpp | 10 | ||||
-rw-r--r-- | test/core/model/DocumentTest.cpp | 2 | ||||
-rw-r--r-- | test/core/model/DomainTest.cpp | 8 | ||||
-rw-r--r-- | test/core/model/TestAdvanced.hpp | 2 | ||||
-rw-r--r-- | test/core/model/TestDocument.hpp | 2 | ||||
-rw-r--r-- | test/core/model/TestDocumentBuilder.hpp | 2 | ||||
-rw-r--r-- | test/core/model/TestDomain.hpp | 3 | ||||
-rw-r--r-- | test/core/model/TypesystemTest.cpp | 87 | ||||
-rw-r--r-- | test/plugins/html/DemoOutputTest.cpp | 44 |
10 files changed, 88 insertions, 108 deletions
diff --git a/src/plugins/html/DemoOutput.cpp b/src/plugins/html/DemoOutput.cpp index a3d1b84..503c104 100644 --- a/src/plugins/html/DemoOutput.cpp +++ b/src/plugins/html/DemoOutput.cpp @@ -27,7 +27,7 @@ namespace ousia { namespace html { -void DemoHTMLTransformer::writeHTML(Handle<model::Document> doc, +void DemoHTMLTransformer::writeHTML(Handle<Document> doc, std::ostream &out, bool pretty) { Manager &mgr = doc->getManager(); @@ -66,7 +66,7 @@ void DemoHTMLTransformer::writeHTML(Handle<model::Document> doc, } // extract the book root node. - Rooted<model::StructuredEntity> root = doc->getRoot(); + Rooted<StructuredEntity> root = doc->getRoot(); if (root->getDescriptor()->getName() != "book") { throw OusiaException("The given documents root is no book node!"); } @@ -98,7 +98,7 @@ SectionType getSectionType(const std::string &name) } Rooted<xml::Element> DemoHTMLTransformer::transformSection( - Handle<xml::Element> parent, Handle<model::StructuredEntity> section, + Handle<xml::Element> parent, Handle<StructuredEntity> section, AnnoMap &startMap, AnnoMap &endMap) { Manager &mgr = section->getManager(); @@ -115,8 +115,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection( // check if we have a heading. if (section->hasField("heading") && section->getField("heading").size() > 0) { - Handle<model::StructuredEntity> heading = - section->getField("heading")[0].cast<model::StructuredEntity>(); + Handle<StructuredEntity> heading = + section->getField("heading")[0].cast<StructuredEntity>(); std::string headingclass; switch (type) { case SectionType::BOOK: @@ -149,7 +149,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection( if (!n->isa(RttiTypes::StructuredEntity)) { continue; } - Handle<model::StructuredEntity> s = n.cast<model::StructuredEntity>(); + Handle<StructuredEntity> s = n.cast<StructuredEntity>(); /* * Strictly speaking this is the wrong mechanism, because we would have * to make an "isa" call here because we can not rely on our knowledge @@ -174,7 +174,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection( } Rooted<xml::Element> DemoHTMLTransformer::transformList( - Handle<xml::Element> parent, Handle<model::StructuredEntity> list, + Handle<xml::Element> parent, Handle<StructuredEntity> list, AnnoMap &startMap, AnnoMap &endMap) { Manager &mgr = list->getManager(); @@ -183,8 +183,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformList( Rooted<xml::Element> l{new xml::Element{mgr, parent, listclass}}; // iterate through list items. for (auto &it : list->getField()) { - Handle<model::StructuredEntity> item = - it.cast<model::StructuredEntity>(); + Handle<StructuredEntity> item = + it.cast<StructuredEntity>(); std::string itDescrName = item->getDescriptor()->getName(); if (itDescrName == "item") { // create the list item. @@ -203,10 +203,10 @@ Rooted<xml::Element> DemoHTMLTransformer::transformList( return l; } -typedef std::stack<Rooted<model::AnnotationEntity>> AnnoStack; +typedef std::stack<Rooted<AnnotationEntity>> AnnoStack; static Rooted<xml::Element> openAnnotation( - Manager &mgr, AnnoStack &opened, Handle<model::AnnotationEntity> entity, + Manager &mgr, AnnoStack &opened, Handle<AnnotationEntity> entity, Handle<xml::Element> current) { // we push the newly opened entity on top of the stack. @@ -225,7 +225,7 @@ static Rooted<xml::Element> openAnnotation( } Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( - Handle<xml::Element> parent, Handle<model::StructuredEntity> par, + Handle<xml::Element> parent, Handle<StructuredEntity> par, AnnoMap &startMap, AnnoMap &endMap) { Manager &mgr = par->getManager(); @@ -234,8 +234,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( // check if we have a heading. if (par->hasField("heading") && par->getField("heading").size() > 0) { - Handle<model::StructuredEntity> heading = - par->getField("heading")[0].cast<model::StructuredEntity>(); + Handle<StructuredEntity> heading = + par->getField("heading")[0].cast<StructuredEntity>(); // put the heading in a strong xml::Element. Rooted<xml::Element> strong{new xml::Element{mgr, p, "strong"}}; p->addChild(strong); @@ -281,7 +281,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( * be re-opened. */ AnnoStack tmp; - Rooted<model::AnnotationEntity> closed = opened.top(); + Rooted<AnnotationEntity> closed = opened.top(); current = current->getParent(); opened.pop(); while (closed->getEnd()->getName() != n->getName()) { @@ -313,12 +313,12 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph( if (!n->isa(RttiTypes::StructuredEntity)) { continue; } - Handle<model::StructuredEntity> t = n.cast<model::StructuredEntity>(); + Handle<StructuredEntity> t = n.cast<StructuredEntity>(); std::string childDescriptorName = t->getDescriptor()->getName(); if (childDescriptorName == "text") { - Handle<model::DocumentPrimitive> primitive = - t->getField()[0].cast<model::DocumentPrimitive>(); + Handle<DocumentPrimitive> primitive = + t->getField()[0].cast<DocumentPrimitive>(); if (primitive.isNull()) { throw OusiaException("Text field is not primitive!"); } diff --git a/src/plugins/html/DemoOutput.hpp b/src/plugins/html/DemoOutput.hpp index b755aac..67b7494 100644 --- a/src/plugins/html/DemoOutput.hpp +++ b/src/plugins/html/DemoOutput.hpp @@ -39,7 +39,7 @@ namespace ousia { namespace html { -typedef std::map<std::string, Rooted<model::AnnotationEntity>> AnnoMap; +typedef std::map<std::string, Rooted<AnnotationEntity>> AnnoMap; class DemoHTMLTransformer { private: @@ -50,14 +50,14 @@ private: * called recursively. */ Rooted<xml::Element> transformSection(Handle<xml::Element> parent, - Handle<model::StructuredEntity> sec, + Handle<StructuredEntity> sec, AnnoMap &startMap, AnnoMap &endMap); /** * This transforms a list entity, namely ul and ol to an XHTML element. * For each item, the transformParagraph function is called. */ Rooted<xml::Element> transformList(Handle<xml::Element> parent, - Handle<model::StructuredEntity> list, + Handle<StructuredEntity> list, AnnoMap &startMap, AnnoMap &endMap); /** * This transforms a paragraph-like entity, namely heading, item and @@ -65,7 +65,7 @@ private: * contained. For anchor handling we require the AnnoMaps. */ Rooted<xml::Element> transformParagraph(Handle<xml::Element> parent, - Handle<model::StructuredEntity> par, + Handle<StructuredEntity> par, AnnoMap &startMap, AnnoMap &endMap); public: @@ -89,7 +89,7 @@ public: * @param pretty is a flag that manipulates whether newlines and tabs are * used. */ - void writeHTML(Handle<model::Document> doc, std::ostream &out, + void writeHTML(Handle<Document> doc, std::ostream &out, bool pretty = true); }; } diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index e07deb8..a09068d 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -29,7 +29,6 @@ #include "TestDomain.hpp" namespace ousia { -namespace model { TEST(Document, construct) { @@ -308,4 +307,3 @@ TEST(Document, validate) } } } -} diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index c00b122..fc71f91 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -27,7 +27,6 @@ #include "TestDomain.hpp" namespace ousia { -namespace model { void assert_path(const ResolutionResult &res, const Rtti &expected_type, std::vector<std::string> expected_path) @@ -335,8 +334,7 @@ TEST(Domain, validate) ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); // add a subclass for our base class. - Rooted<StructuredClass> sub{ - new StructuredClass(mgr, "sub", domain)}; + Rooted<StructuredClass> sub{new StructuredClass(mgr, "sub", domain)}; // this should be valid in itself. ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); @@ -355,8 +353,7 @@ TEST(Domain, validate) ASSERT_TRUE(domain->validate(logger)); ASSERT_EQ(base, sub->getSuperclass()); // add a non-primitive field to the child class. - Rooted<FieldDescriptor> sub_field{ - new FieldDescriptor(mgr, sub)}; + Rooted<FieldDescriptor> sub_field{new FieldDescriptor(mgr, sub)}; // this should be valid ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); @@ -383,4 +380,3 @@ TEST(Domain, validate) } } } -} diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index f8585d1..6111170 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -26,7 +26,6 @@ #include "TestDocumentBuilder.hpp" namespace ousia { -namespace model { static Rooted<StructuredClass> resolveDescriptor(Handle<Domain> domain, const std::string &className) @@ -316,6 +315,5 @@ static Rooted<Document> constructAdvancedDocument(Manager &mgr, Logger &logger, return doc; } } -} #endif /* _TEST_DOCUMENT_HPP_ */ diff --git a/test/core/model/TestDocument.hpp b/test/core/model/TestDocument.hpp index 2397fe6..243672b 100644 --- a/test/core/model/TestDocument.hpp +++ b/test/core/model/TestDocument.hpp @@ -26,7 +26,6 @@ #include "TestDocumentBuilder.hpp" namespace ousia { -namespace model { /** * This constructs a fairly simple test document for the "book" domain. The @@ -88,7 +87,6 @@ static Rooted<Document> constructBookDocument(Manager &mgr, Logger &logger, return doc; } } -} #endif /* _TEST_DOCUMENT_HPP_ */ diff --git a/test/core/model/TestDocumentBuilder.hpp b/test/core/model/TestDocumentBuilder.hpp index 63d60eb..149b88e 100644 --- a/test/core/model/TestDocumentBuilder.hpp +++ b/test/core/model/TestDocumentBuilder.hpp @@ -27,7 +27,6 @@ #include <core/model/Typesystem.hpp> namespace ousia { -namespace model { typedef std::vector<std::string> Path; @@ -215,5 +214,4 @@ Rooted<AnnotationEntity> buildAnnotationEntity( return anno; } } -} #endif diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index f6b8805..35f1ce1 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -23,8 +23,6 @@ #include <core/model/Typesystem.hpp> namespace ousia { -namespace model { - /** * This constructs the "book" domain for test purposes. The structure of the * domain is fairly simple and can be seen from the construction itself. @@ -91,6 +89,5 @@ static Rooted<Domain> constructBookDomain(Manager &mgr, return domain; } } -} #endif /* _TEST_DOMAIN_HPP_ */ diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp index 4d1d2c9..7d05f56 100644 --- a/test/core/model/TypesystemTest.cpp +++ b/test/core/model/TypesystemTest.cpp @@ -25,10 +25,9 @@ #include <core/model/Typesystem.hpp> namespace ousia { -namespace model { static TerminalLogger logger(std::cerr, true); -//static ConcreteLogger logger; +// static ConcreteLogger logger; /* Class StringType */ @@ -519,28 +518,28 @@ TEST(StructType, creationWithParent) Manager mgr{1}; Rooted<StructType> structType = createStructType(mgr, logger); { - Rooted<StructType> structWithParentType = - createStructTypeWithParent(structType, mgr, logger); + Rooted<StructType> structWithParentType = + createStructTypeWithParent(structType, mgr, logger); - Variant val = structWithParentType->create(); - ASSERT_TRUE(val.isArray()); - ASSERT_EQ(7U, val.asArray().size()); + Variant val = structWithParentType->create(); + ASSERT_TRUE(val.isArray()); + ASSERT_EQ(7U, val.asArray().size()); - const auto &arr = val.asArray(); - ASSERT_TRUE(arr[0].isString()); - ASSERT_TRUE(arr[1].isString()); - ASSERT_TRUE(arr[2].isInt()); - ASSERT_TRUE(arr[3].isInt()); - ASSERT_TRUE(arr[4].isString()); - ASSERT_TRUE(arr[5].isInt()); - ASSERT_TRUE(arr[6].isArray()); + const auto &arr = val.asArray(); + ASSERT_TRUE(arr[0].isString()); + ASSERT_TRUE(arr[1].isString()); + ASSERT_TRUE(arr[2].isInt()); + ASSERT_TRUE(arr[3].isInt()); + ASSERT_TRUE(arr[4].isString()); + ASSERT_TRUE(arr[5].isInt()); + ASSERT_TRUE(arr[6].isArray()); - ASSERT_EQ("attr1default", arr[0].asString()); - ASSERT_EQ("", arr[1].asString()); - ASSERT_EQ(3, arr[2].asInt()); - ASSERT_EQ(0, arr[3].asInt()); - ASSERT_EQ("value1", arr[4].asString()); - ASSERT_EQ(42, arr[5].asInt()); + ASSERT_EQ("attr1default", arr[0].asString()); + ASSERT_EQ("", arr[1].asString()); + ASSERT_EQ(3, arr[2].asInt()); + ASSERT_EQ(0, arr[3].asInt()); + ASSERT_EQ("value1", arr[4].asString()); + ASSERT_EQ(42, arr[5].asInt()); } } @@ -566,13 +565,13 @@ TEST(StructType, createValidated) { logger.reset(); Rooted<StructType> structType{StructType::createValidated( - mgr, "struct", nullptr, nullptr, - NodeVector<Attribute>{ - new Attribute{mgr, "d", stringType, "attr1default"}, - new Attribute{mgr, "b", stringType}, - new Attribute{mgr, "c", intType, 3}, - new Attribute{mgr, "a", intType}}, - logger)}; + mgr, "struct", nullptr, nullptr, + NodeVector<Attribute>{ + new Attribute{mgr, "d", stringType, "attr1default"}, + new Attribute{mgr, "b", stringType}, + new Attribute{mgr, "c", intType, 3}, + new Attribute{mgr, "a", intType}}, + logger)}; ASSERT_TRUE(structType->validate(logger)); ASSERT_EQ(Severity::DEBUG, logger.getMaxEncounteredSeverity()); } @@ -580,13 +579,13 @@ TEST(StructType, createValidated) { logger.reset(); Rooted<StructType> structType{StructType::createValidated( - mgr, "struct", nullptr, nullptr, - NodeVector<Attribute>{ - new Attribute{mgr, "d", stringType, "attr1default"}, - new Attribute{mgr, "b", stringType}, - new Attribute{mgr, "a", intType, 3}, - new Attribute{mgr, "a", intType}}, - logger)}; + mgr, "struct", nullptr, nullptr, + NodeVector<Attribute>{ + new Attribute{mgr, "d", stringType, "attr1default"}, + new Attribute{mgr, "b", stringType}, + new Attribute{mgr, "a", intType, 3}, + new Attribute{mgr, "a", intType}}, + logger)}; ASSERT_FALSE(structType->validate(logger)); ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity()); } @@ -594,13 +593,13 @@ TEST(StructType, createValidated) { logger.reset(); Rooted<StructType> structType{StructType::createValidated( - mgr, "struct", nullptr, nullptr, - NodeVector<Attribute>{ - new Attribute{mgr, "d", stringType, "attr1default"}, - new Attribute{mgr, "b", stringType}, - new Attribute{mgr, "a", intType, 3}, - new Attribute{mgr, "a a", intType}}, - logger)}; + mgr, "struct", nullptr, nullptr, + NodeVector<Attribute>{ + new Attribute{mgr, "d", stringType, "attr1default"}, + new Attribute{mgr, "b", stringType}, + new Attribute{mgr, "a", intType, 3}, + new Attribute{mgr, "a a", intType}}, + logger)}; ASSERT_FALSE(structType->validate(logger)); ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity()); } @@ -704,7 +703,6 @@ TEST(StructType, build) ASSERT_EQ(5, arr[3].asInt()); } - // All mandatory attributes given as array { Variant var{{"v1", 2, 3, 4}}; @@ -923,7 +921,4 @@ TEST(SystemTypesystem, rtti) ASSERT_FALSE(typesystem->composedOf(RttiTypes::Typesystem)); ASSERT_FALSE(typesystem->composedOf(RttiTypes::SystemTypesystem)); } - - -} } diff --git a/test/plugins/html/DemoOutputTest.cpp b/test/plugins/html/DemoOutputTest.cpp index 11e5fa6..094b5fd 100644 --- a/test/plugins/html/DemoOutputTest.cpp +++ b/test/plugins/html/DemoOutputTest.cpp @@ -39,18 +39,18 @@ TEST(DemoHTMLTransformer, writeHTML) // Construct Manager TerminalLogger logger{std::cerr, true}; Manager mgr{1}; - Rooted<model::SystemTypesystem> sys{new model::SystemTypesystem(mgr)}; + Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; // Get the domains. - Rooted<model::Domain> bookDom = - model::constructBookDomain(mgr, sys, logger); - Rooted<model::Domain> headingDom = - model::constructHeadingDomain(mgr, sys, bookDom, logger); - Rooted<model::Domain> listDom = - model::constructListDomain(mgr, sys, bookDom, logger); - Rooted<model::Domain> emDom = - model::constructEmphasisDomain(mgr, sys, logger); + Rooted<Domain> bookDom = + constructBookDomain(mgr, sys, logger); + Rooted<Domain> headingDom = + constructHeadingDomain(mgr, sys, bookDom, logger); + Rooted<Domain> listDom = + constructListDomain(mgr, sys, bookDom, logger); + Rooted<Domain> emDom = + constructEmphasisDomain(mgr, sys, logger); // Construct the document. - Rooted<model::Document> doc = model::constructAdvancedDocument( + Rooted<Document> doc = constructAdvancedDocument( mgr, logger, bookDom, headingDom, listDom, emDom); ASSERT_TRUE(doc != nullptr); @@ -77,29 +77,29 @@ TEST(DemoHTMLTransformer, AnnotationProcessing) // Construct Manager TerminalLogger logger{std::cerr, true}; Manager mgr{1}; - Rooted<model::SystemTypesystem> sys{new model::SystemTypesystem(mgr)}; + Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; // Get the domains. - Rooted<model::Domain> bookDom = - model::constructBookDomain(mgr, sys, logger); - Rooted<model::Domain> emDom = - model::constructEmphasisDomain(mgr, sys, logger); + Rooted<Domain> bookDom = + constructBookDomain(mgr, sys, logger); + Rooted<Domain> emDom = + constructEmphasisDomain(mgr, sys, logger); // Construct a document only containing overlapping annotations. // it has the form: <em>bla<strong>blub</em>bla</strong> - Rooted<model::Document> doc{new model::Document(mgr, "annotations.oxd")}; + Rooted<Document> doc{new Document(mgr, "annotations.oxd")}; doc->addDomains({bookDom, emDom}); - Rooted<model::StructuredEntity> book = + Rooted<StructuredEntity> book = buildRootStructuredEntity(doc, logger, {"book"}); ASSERT_TRUE(book != nullptr); - Rooted<model::StructuredEntity> p = + Rooted<StructuredEntity> p = buildStructuredEntity(doc, logger, book, {"paragraph"}); ASSERT_TRUE(p != nullptr); - Rooted<model::Anchor> em_start{new model::Anchor(mgr, "1", p)}; + Rooted<Anchor> em_start{new Anchor(mgr, "1", p)}; ASSERT_TRUE(addText(logger, doc, p, "bla")); - Rooted<model::Anchor> strong_start{new model::Anchor(mgr, "2", p)}; + Rooted<Anchor> strong_start{new Anchor(mgr, "2", p)}; ASSERT_TRUE(addText(logger, doc, p, "blub")); - Rooted<model::Anchor> em_end{new model::Anchor(mgr, "3", p)}; + Rooted<Anchor> em_end{new Anchor(mgr, "3", p)}; ASSERT_TRUE(addText(logger, doc, p, "bla")); - Rooted<model::Anchor> strong_end{new model::Anchor(mgr, "4", p)}; + Rooted<Anchor> strong_end{new Anchor(mgr, "4", p)}; buildAnnotationEntity(doc, logger, {"emphasized"}, em_start, em_end); buildAnnotationEntity(doc, logger, {"strong"}, strong_start, strong_end); |