diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/model/DocumentTest.cpp | 8 | ||||
-rw-r--r-- | test/core/model/TestAdvanced.hpp | 25 | ||||
-rw-r--r-- | test/plugins/html/DemoOutputTest.cpp | 52 |
3 files changed, 69 insertions, 16 deletions
diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index 8ae9475..135ba19 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -249,7 +249,8 @@ TEST(Document, construct) TEST(Document, validate) { // Let's start with a trivial ontology and a trivial document. - TerminalLogger logger{std::cerr, true}; +// TerminalLogger logger{std::cerr, true}; + Logger logger; Manager mgr{1}; Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; Rooted<Ontology> ontology{new Ontology(mgr, sys, "trivial")}; @@ -403,7 +404,7 @@ TEST(Document, validate) new AnnotationClass(mgr, "anno", ontology)}; { /* - * Create a valid document in itself. + * Create a document with anchors. */ Rooted<Document> doc{new Document(mgr, "myDoc.oxd")}; doc->referenceOntology(ontology); @@ -416,7 +417,8 @@ TEST(Document, validate) new DocumentPrimitive(mgr, child, {2}, "int")}; Rooted<Anchor> end{new Anchor(mgr, root)}; ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); - ASSERT_TRUE(doc->validate(logger)); + // This should be invalid due to disconnected Anchors + ASSERT_FALSE(doc->validate(logger)); // then add an AnnotationEntity without Anchors. Rooted<AnnotationEntity> anno = buildAnnotationEntity(doc, logger, {"anno"}, nullptr, nullptr); diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index c92effa..58eb965 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -45,9 +45,9 @@ static Rooted<StructuredClass> resolveDescriptor(Handle<Ontology> ontology, * This constructs the "heading" ontology given the book ontology. */ static Rooted<Ontology> constructHeadingOntology(Manager &mgr, - Handle<SystemTypesystem> sys, - Handle<Ontology> bookOntology, - Logger &logger) + Handle<SystemTypesystem> sys, + Handle<Ontology> bookOntology, + Logger &logger) { // set up ontology node. Rooted<Ontology> ontology{new Ontology(mgr, sys, "headings")}; @@ -78,9 +78,9 @@ static Rooted<Ontology> constructHeadingOntology(Manager &mgr, * This constructs the "list" ontology given the book ontology. */ static Rooted<Ontology> constructListOntology(Manager &mgr, - Handle<SystemTypesystem> sys, - Handle<Ontology> bookOntology, - Logger &logger) + Handle<SystemTypesystem> sys, + Handle<Ontology> bookOntology, + Logger &logger) { // set up ontology node. Rooted<Ontology> ontology{new Ontology(mgr, sys, "list")}; @@ -97,7 +97,8 @@ static Rooted<Ontology> constructListOntology(Manager &mgr, for (auto &listType : listTypes) { Rooted<StructuredClass> list{new StructuredClass( mgr, listType, ontology, Cardinality::any(), p, false)}; - Rooted<FieldDescriptor> list_field{new FieldDescriptor(mgr, list)}; + Rooted<FieldDescriptor> list_field = + list->createFieldDescriptor(logger).first; list_field->addChild(item); } return ontology; @@ -107,15 +108,17 @@ static Rooted<Ontology> constructListOntology(Manager &mgr, * This constructs the "emphasis" ontology. */ static Rooted<Ontology> constructEmphasisOntology(Manager &mgr, - Handle<SystemTypesystem> sys, - Logger &logger) + Handle<SystemTypesystem> sys, + Logger &logger) { // set up ontology node. Rooted<Ontology> ontology{new Ontology(mgr, sys, "emphasis")}; // create AnnotationClasses - Rooted<AnnotationClass> em{new AnnotationClass(mgr, "emphasized", ontology)}; + Rooted<AnnotationClass> em{ + new AnnotationClass(mgr, "emphasized", ontology)}; - Rooted<AnnotationClass> strong{new AnnotationClass(mgr, "strong", ontology)}; + Rooted<AnnotationClass> strong{ + new AnnotationClass(mgr, "strong", ontology)}; return ontology; } diff --git a/test/plugins/html/DemoOutputTest.cpp b/test/plugins/html/DemoOutputTest.cpp index debb667..1c54a14 100644 --- a/test/plugins/html/DemoOutputTest.cpp +++ b/test/plugins/html/DemoOutputTest.cpp @@ -24,10 +24,13 @@ #include <plugins/html/DemoOutput.hpp> #include <core/common/Rtti.hpp> +#include <plugins/filesystem/FileLocator.hpp> #include <core/frontend/TerminalLogger.hpp> #include <core/model/Document.hpp> #include <core/model/Ontology.hpp> +#include <formats/osxml/OsxmlParser.hpp> +#include <core/StandaloneEnvironment.hpp> #include <core/model/TestAdvanced.hpp> #include <core/model/TestOntology.hpp> @@ -59,7 +62,7 @@ TEST(DemoHTMLTransformer, writeHTML) // we can only do a rough check here. DemoHTMLTransformer transformer; std::stringstream out; - transformer.writeHTML(doc, out); + transformer.writeHTML(doc, out, logger); const std::string res = out.str(); ASSERT_FALSE(res == ""); ASSERT_TRUE(res.find("Was ist Aufklärung?") != std::string::npos); @@ -106,12 +109,57 @@ TEST(DemoHTMLTransformer, AnnotationProcessing) // Check serialization. DemoHTMLTransformer transformer; std::stringstream out; - transformer.writeHTML(doc, out, false); + transformer.writeHTML(doc, out, logger, false); const std::string res = out.str(); // In HTML the overlapping structure must be serialized as follows: ASSERT_TRUE( res.find("<em>bla<strong>blub</strong></em><strong>bla</strong>") != std::string::npos); } + +struct XmlStandaloneEnvironment : public StandaloneEnvironment { + OsxmlParser parser; + FileLocator fileLocator; + + XmlStandaloneEnvironment(ConcreteLogger &logger) + : StandaloneEnvironment(logger) + { + fileLocator.addDefaultSearchPaths(); + fileLocator.addUnittestSearchPath("osxmlparser"); + + registry.registerDefaultExtensions(); + registry.registerParser({"text/vnd.ousia.osml+xml"}, + {&RttiTypes::Node}, &parser); + registry.registerResourceLocator(&fileLocator); + } +}; + +TEST(DemoHTMLTransformer, pipelineTest) +{ + // Construct Manager + TerminalLogger logger{std::cerr, true}; + XmlStandaloneEnvironment env(logger); + Rooted<Node> book_document_node = + env.parse("complex_book.osxml", "", "", RttiSet{&RttiTypes::Document}); + ASSERT_FALSE(logger.hasError()); + ASSERT_FALSE(book_document_node == nullptr); + ASSERT_TRUE(book_document_node->isa(&RttiTypes::Document)); + Rooted<Document> doc = book_document_node.cast<Document>(); + ASSERT_TRUE(doc->validate(logger)); + ASSERT_FALSE(logger.hasError()); + + // we can only do a rough check here. + DemoHTMLTransformer transformer; + std::stringstream out; + transformer.writeHTML(doc, out, logger); + const std::string res = out.str(); + ASSERT_FALSE(res == ""); + ASSERT_TRUE(res.find("Was ist Aufklärung?") != std::string::npos); + ASSERT_TRUE(res.find( + "Aufklärung ist der Ausgang des Menschen aus seiner " + "selbstverschuldeten Unmündigkeit") != std::string::npos); + ASSERT_TRUE(res.find("Sapere aude!") != std::string::npos); +} + } } |