1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <memory>
11 #include <swmodeltestbase.hxx>
12 
13 #include <test/htmltesttools.hxx>
14 
15 class XHtmlExportTest : public SwModelTestBase, public HtmlTestTools
16 {
17 public:
XHtmlExportTest()18     XHtmlExportTest()
19         : SwModelTestBase("/sw/qa/extras/odfexport/data/", "XHTML Writer File")
20     {
21     }
22 
23 private:
preTest(const char *)24     virtual std::unique_ptr<Resetter> preTest(const char*) override
25     {
26         setFilterOptions("UTF8");
27         return nullptr;
28     }
29 };
30 
31 #define DECLARE_HTMLEXPORT_TEST(TestName, filename)                                                \
32     DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, XHtmlExportTest)
33 
34 DECLARE_HTMLEXPORT_TEST(testImageEmbedding, "image-mimetype.odt")
35 {
36     htmlDocUniquePtr pDoc = parseHtml(maTempFile);
37     CPPUNIT_ASSERT(pDoc);
38 
39     assertXPath(pDoc, "/html/body", 1);
40     assertXPath(pDoc, "/html/body/div[1]/div[1]/img", 1);
41     OUString aValue = getXPath(pDoc, "/html/body/div[1]/div[1]/img", "src");
42     CPPUNIT_ASSERT(aValue.startsWith("data:image/svg+xml;base64"));
43 }
44 
45 DECLARE_HTMLEXPORT_TEST(testTdf131812, "tdf131812.odt")
46 {
47     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
48     CPPUNIT_ASSERT(pStream);
49     sal_uInt64 nLength = pStream->TellEnd();
50     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
51     CPPUNIT_ASSERT(
52         aStream.indexOf(".P1 { font-size:12pt; font-family:\'Liberation Serif\'; "
53                         "writing-mode:horizontal-tb; direction:rtl; text-align:right ! important;}")
54         != -1);
55 }
56 
57 DECLARE_HTMLEXPORT_TEST(testTdf118637, "tdf118637.odt")
58 {
59     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
60     CPPUNIT_ASSERT(pStream);
61     sal_uInt64 nLength = pStream->TellEnd();
62     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
63     CPPUNIT_ASSERT(
64         aStream.indexOf(
65             "<div style=\"display:inline; position:relative; left:0cm;\">The formula  </div>")
66         != -1);
67     CPPUNIT_ASSERT(
68         aStream.indexOf(
69             "<div style=\"display:inline; position:relative; left:0cm;\">should be inline.</div>")
70         != -1);
71 }
72 
73 DECLARE_HTMLEXPORT_TEST(testTdf142483, "tdf142483.odt")
74 {
75     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
76     CPPUNIT_ASSERT(pStream);
77     sal_uInt64 nLength = pStream->TellEnd();
78     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
79     CPPUNIT_ASSERT(
80         aStream.indexOf("padding:0.0382in; border-left-width:thin; border-left-style:solid; "
81                         "border-left-color:#000000; border-right-style:none; "
82                         "border-top-width:thin; border-top-style:solid; border-top-color:#000000; "
83                         "border-bottom-width:thin; border-bottom-style:solid; "
84                         "border-bottom-color:#000000;")
85         != -1);
86     CPPUNIT_ASSERT(
87         aStream.indexOf("padding:0.0382in; border-left-width:thin; border-left-style:solid; "
88                         "border-left-color:#000000; border-right-style:none; "
89                         "border-top-style:none; border-bottom-width:thin; "
90                         "border-bottom-style:solid; border-bottom-color:#000000;")
91         != -1);
92     CPPUNIT_ASSERT(
93         aStream.indexOf("border-top-width:thin; border-top-style:solid; border-top-color:#000000; "
94                         "border-left-width:thin; border-left-style:solid; "
95                         "border-left-color:#000000; border-bottom-width:thin; "
96                         "border-bottom-style:solid; border-bottom-color:#000000; "
97                         "border-right-width:thin; border-right-style:solid; "
98                         "border-right-color:#000000; padding:0.0382in;")
99         != -1);
100     CPPUNIT_ASSERT(
101         aStream.indexOf("padding:0.0382in; border-left-width:thin; border-left-style:solid; "
102                         "border-left-color:#000000; border-right-width:thin; "
103                         "border-right-style:solid; border-right-color:#000000; "
104                         "border-top-style:none; border-bottom-width:thin; "
105                         "border-bottom-style:solid; border-bottom-color:#000000;")
106         != -1);
107 }
108 
109 DECLARE_HTMLEXPORT_TEST(testTdf107696, "tdf107696.odt")
110 {
111     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
112     CPPUNIT_ASSERT(pStream);
113     sal_uInt64 nLength = pStream->TellEnd();
114     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
115     //tdf#111492
116     CPPUNIT_ASSERT(aStream.indexOf("span.heading_numbering { margin-right: 0.8rem; }* { margin:0;}")
117                    != -1);
118     CPPUNIT_ASSERT(
119         aStream.indexOf("<h2 class=\"Heading_20_2\"><a "
120                         "id=\"a__Level_2_without_number\"><span/></a>Level 2 without number</h2>")
121         != -1);
122     CPPUNIT_ASSERT(
123         aStream.indexOf("<h2 class=\"Heading_20_2\"><a id=\"a_3_1_Level_2__number_3_1\"><span "
124                         "class=\"heading_numbering\">3.1</span></a>Level <span "
125                         "class=\"T2\">2</span>, <span class=\"T1\">number 3.1</span></h2>")
126         != -1);
127     CPPUNIT_ASSERT(
128         aStream.indexOf("<h2 class=\"Heading_20_2\"><a id=\"a_3_2_Level_2__number_3_2\"><span "
129                         "class=\"heading_numbering\">3.2</span></a>Level 2, <span "
130                         "class=\"T1\">number 3.2</span></h2>")
131         != -1);
132 }
133 
134 DECLARE_HTMLEXPORT_TEST(testTdf66305, "tdf66305.odt")
135 {
136     SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
137     CPPUNIT_ASSERT(pStream);
138     sal_uInt64 nLength = pStream->TellEnd();
139     OString aStream(read_uInt8s_ToOString(*pStream, nLength));
140     CPPUNIT_ASSERT(
141         aStream.indexOf("<p class=\"P6\"><a href=\"#__RefHeading__82004_486970805\" "
142                         "class=\"Internet_20_link\">Introduction</a></p><p class=\"P7\"> </p>")
143         != -1);
144 }
145 
146 CPPUNIT_PLUGIN_IMPLEMENT();
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
149