summaryrefslogtreecommitdiff
path: root/test/plugins/html/DemoOutputTest.cpp
blob: 5b2758d2911e6a836426bd2bd7e068013dd66ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
    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/html/DemoOutput.hpp>

#include <core/model/Document.hpp>
#include <core/model/Domain.hpp>

#include <core/model/TestAdvanced.hpp>
#include <core/model/TestDomain.hpp>

namespace ousia {
namespace html {

TEST(DemoHTMLTransformer, writeHTML)
{
	// Construct Manager
	TerminalLogger logger{std::cerr, true};
	Manager mgr{1};
	Rooted<model::SystemTypesystem> sys{new model::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);
	// Construct the document.
	Rooted<model::Document> doc = model::constructAdvancedDocument(
	    mgr, logger, bookDom, headingDom, listDom, emDom);
	ASSERT_TRUE(doc != nullptr);

#ifdef MANAGER_GRAPHVIZ_EXPORT
	// dump the manager state
	mgr.exportGraphviz("bookDocument.dot");
#endif

	// we can only do a rough check here.
	DemoHTMLTransformer transformer;
	std::stringstream out;
	transformer.writeHTML(doc, out);
	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<model::SystemTypesystem> sys{new model::SystemTypesystem(mgr)};
	// Get the domains.
	Rooted<model::Domain> bookDom =
	    model::constructBookDomain(mgr, sys, logger);
	Rooted<model::Domain> emDom =
	    model::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")};
	doc->addDomains({bookDom, emDom});
	Rooted<model::StructuredEntity> book =
	    buildRootStructuredEntity(doc, logger, {"book"});
	ASSERT_TRUE(book != nullptr);
	Rooted<model::StructuredEntity> p =
	    buildStructuredEntity(doc, logger, book, {"paragraph"});
	ASSERT_TRUE(p != nullptr);
	Rooted<model::AnnotationEntity::Anchor> em_start =
	    buildAnchor(logger, p, "1");
	ASSERT_TRUE(em_start != nullptr);
	ASSERT_TRUE(addText(logger, doc, p, "bla"));
	Rooted<model::AnnotationEntity::Anchor> strong_start =
	    buildAnchor(logger, p, "2");
	ASSERT_TRUE(strong_start != nullptr);
	ASSERT_TRUE(addText(logger, doc, p, "blub"));
	Rooted<model::AnnotationEntity::Anchor> em_end =
	    buildAnchor(logger, p, "3");
	ASSERT_TRUE(em_end != nullptr);
	ASSERT_TRUE(addText(logger, doc, p, "bla"));
	Rooted<model::AnnotationEntity::Anchor> strong_end =
	    buildAnchor(logger, p, "4");
	ASSERT_TRUE(strong_end != nullptr);
	buildAnnotationEntity(doc, logger, {"emphasized"}, em_start, em_end);
	buildAnnotationEntity(doc, logger, {"strong"}, strong_start, strong_end);

	// Check serialization.
	DemoHTMLTransformer transformer;
	std::stringstream out;
	transformer.writeHTML(doc, out, 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);
}
}
}