summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt51
-rw-r--r--test/plugins/xml/XmlOutputTest.cpp111
2 files changed, 142 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5b310a2..15e2f32 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -319,16 +319,6 @@ IF(TEST)
ousia_core
)
- ADD_EXECUTABLE(ousia_test_filesystem
- test/plugins/filesystem/FileLocatorTest
- )
-
- TARGET_LINK_LIBRARIES(ousia_test_filesystem
- ${GTEST_LIBRARIES}
- ousia_core
- ousia_filesystem
- )
-
# ADD_EXECUTABLE(ousia_test_css
# test/plugins/css/Tokenizer
# test/plugins/css/CodeTokenizerTest
@@ -341,6 +331,16 @@ IF(TEST)
# ousia_css
# )
+ ADD_EXECUTABLE(ousia_test_filesystem
+ test/plugins/filesystem/FileLocatorTest
+ )
+
+ TARGET_LINK_LIBRARIES(ousia_test_filesystem
+ ${GTEST_LIBRARIES}
+ ousia_core
+ ousia_filesystem
+ )
+
ADD_EXECUTABLE(ousia_test_html
test/plugins/html/DemoOutputTest
)
@@ -351,6 +351,16 @@ IF(TEST)
ousia_html
)
+# ADD_EXECUTABLE(ousia_test_mozjs
+# test/plugins/mozjs/MozJsScriptEngineTest
+# )
+
+# TARGET_LINK_LIBRARIES(ousia_test_mozjs
+# ${GTEST_LIBRARIES}
+# ousia_core
+# ousia_mozjs
+# )
+
ADD_EXECUTABLE(ousia_test_osml
test/formats/osml/OsmlParserTest
test/formats/osml/OsmlStreamParserTest
@@ -375,24 +385,25 @@ IF(TEST)
ousia_filesystem
)
-# ADD_EXECUTABLE(ousia_test_mozjs
-# test/plugins/mozjs/MozJsScriptEngineTest
-# )
+ ADD_EXECUTABLE(ousia_test_xml
+ test/plugins/xml/XmlOutputTest
+ )
-# TARGET_LINK_LIBRARIES(ousia_test_mozjs
-# ${GTEST_LIBRARIES}
-# ousia_core
-# ousia_mozjs
-# )
+ TARGET_LINK_LIBRARIES(ousia_test_xml
+ ${GTEST_LIBRARIES}
+ ousia_core
+ ousia_xml
+ )
# Register the unit tests
ADD_TEST(ousia_test_core ousia_test_core)
- ADD_TEST(ousia_test_filesystem ousia_test_filesystem)
# ADD_TEST(ousia_test_css ousia_test_css)
+ ADD_TEST(ousia_test_filesystem ousia_test_filesystem)
ADD_TEST(ousia_test_html ousia_test_html)
+# ADD_TEST(ousia_test_mozjs ousia_test_mozjs)
ADD_TEST(ousia_test_osml ousia_test_osml)
ADD_TEST(ousia_test_osxml ousia_test_osxml)
-# ADD_TEST(ousia_test_mozjs ousia_test_mozjs)
+ ADD_TEST(ousia_test_xml ousia_test_xml)
ENDIF()
################################################################################
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