summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-17 18:32:36 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-17 18:32:36 +0100
commit2662f67a6c3cf74bbefff26abeac2c67ee02a57c (patch)
treeddc112172dab509cdb19522203c3c9caf792c11d /test
parent26d2236c89017d5f9f31b90ec02600744aa5ad0f (diff)
parentadbf7bdcd62b7f8d264028260624175d504e13ed (diff)
Merge branch 'master' of somweyr.de:ousia
Diffstat (limited to 'test')
-rw-r--r--test/core/model/TestAdvanced.hpp12
-rw-r--r--test/plugins/xml/XmlOutputTest.cpp111
2 files changed, 118 insertions, 5 deletions
diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp
index 8e81554..71379d2 100644
--- a/test/core/model/TestAdvanced.hpp
+++ b/test/core/model/TestAdvanced.hpp
@@ -65,8 +65,10 @@ static Rooted<Domain> constructHeadingDomain(Manager &mgr,
"paragraph"};
for (auto &s : secclasses) {
Rooted<StructuredClass> desc = resolveDescriptor(bookDomain, s);
- Rooted<FieldDescriptor> heading_field = desc->createFieldDescriptor(
- logger, FieldDescriptor::FieldType::SUBTREE, "heading", true).first;
+ Rooted<FieldDescriptor> heading_field =
+ desc->createFieldDescriptor(logger,
+ FieldDescriptor::FieldType::SUBTREE,
+ "heading", true).first;
heading_field->addChild(heading);
}
return domain;
@@ -139,7 +141,7 @@ static bool addHeading(Logger &logger, Handle<Document> doc,
{
// Add the heading.
Rooted<StructuredEntity> heading = buildStructuredEntity(
- doc, logger, parent, {"heading"}, "heading", {}, "");
+ doc, logger, parent, {"heading"}, "heading", Variant::mapType{}, "");
if (heading.isNull()) {
return false;
}
@@ -193,7 +195,7 @@ static Rooted<Document> constructAdvancedDocument(Manager &mgr, Logger &logger,
// Add the heading.
{
Rooted<StructuredEntity> heading = buildStructuredEntity(
- doc, logger, book, {"heading"}, "heading", {}, "");
+ doc, logger, book, {"heading"}, "heading", Variant::mapType{}, "");
if (heading.isNull()) {
return {nullptr};
}
@@ -311,4 +313,4 @@ static Rooted<Document> constructAdvancedDocument(Manager &mgr, Logger &logger,
}
}
-#endif /* _TEST_DOCUMENT_HPP_ */
+#endif /* _TEST_DOCUMENT_HPP_ */ \ No newline at end of file
diff --git a/test/plugins/xml/XmlOutputTest.cpp b/test/plugins/xml/XmlOutputTest.cpp
new file mode 100644
index 0000000..403078d
--- /dev/null
+++ b/test/plugins/xml/XmlOutputTest.cpp
@@ -0,0 +1,111 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+#include <sstream>
+
+#include <plugins/xml/XmlOutput.hpp>
+
+#include <core/common/Rtti.hpp>
+#include <core/frontend/TerminalLogger.hpp>
+#include <core/model/Document.hpp>
+#include <core/model/Domain.hpp>
+
+#include <core/model/TestAdvanced.hpp>
+#include <core/model/TestDomain.hpp>
+
+namespace ousia {
+namespace xml {
+
+TEST(DemoHTMLTransformer, writeHTML)
+{
+ // Construct Manager
+ TerminalLogger logger{std::cerr, true};
+ Manager mgr{1};
+ Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)};
+ // Get the domains.
+ 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<Document> doc = constructAdvancedDocument(
+ mgr, logger, bookDom, headingDom, listDom, emDom);
+ ASSERT_TRUE(doc != nullptr);
+
+ // we can only do a rough check here.
+ ResourceManager dummy;
+ XmlTransformer transformer;
+ std::stringstream out;
+ transformer.writeXml(doc, out, logger, dummy, true);
+ 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);
+}
+
+TEST(DemoHTMLTransformer, AnnotationProcessing)
+{
+ // Construct Manager
+ TerminalLogger logger{std::cerr, true};
+ Manager mgr{1};
+ Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)};
+ // Get the domains.
+ 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<Document> doc{new Document(mgr, "annotations.oxd")};
+ doc->referenceDomains({bookDom, emDom});
+ Rooted<StructuredEntity> book =
+ buildRootStructuredEntity(doc, logger, {"book"});
+ ASSERT_TRUE(book != nullptr);
+ Rooted<StructuredEntity> p =
+ buildStructuredEntity(doc, logger, book, {"paragraph"});
+ ASSERT_TRUE(p != nullptr);
+ Rooted<Anchor> em_start{new Anchor(mgr, p)};
+ ASSERT_TRUE(addText(logger, doc, p, "bla"));
+ Rooted<Anchor> strong_start{new Anchor(mgr, p)};
+ ASSERT_TRUE(addText(logger, doc, p, "blub"));
+ Rooted<Anchor> em_end{new Anchor(mgr, p)};
+ ASSERT_TRUE(addText(logger, doc, p, "bla"));
+ Rooted<Anchor> strong_end{new Anchor(mgr, p)};
+ buildAnnotationEntity(doc, logger, {"emphasized"}, em_start, em_end);
+ buildAnnotationEntity(doc, logger, {"strong"}, strong_start, strong_end);
+
+ // Check serialization.
+ ResourceManager dummy;
+ XmlTransformer transformer;
+ std::stringstream out;
+ transformer.writeXml(doc, out, logger, dummy, false);
+ const std::string res = out.str();
+ // In HTML the overlapping structure must be serialized as follows:
+ ASSERT_TRUE(
+ res.find(
+ "<a:start:emphasized/><book:text>bla</book:text><a:start:strong/"
+ "><book:text>blub</book:text><a:end:emphasized/"
+ "><book:text>bla</book:text><a:end:strong/>") != std::string::npos);
+}
+}
+} \ No newline at end of file