summaryrefslogtreecommitdiff
path: root/sw/qa/extras/indexing/IndexingExportTest.cxx
blob: 9d40d887f30dfa5a626cfa0ad469ac91f8259c61 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <memory>
#include <string_view>
#include <swmodeltestbase.hxx>
#include <docsh.hxx>
#include <unotxdoc.hxx>

#include <IndexingExport.hxx>

namespace
{
constexpr OUStringLiteral DATA_DIRECTORY = u"sw/qa/extras/indexing/data/";
}

class IndexingExportTest : public SwModelTestBase
{
private:
    SwDoc* createDoc(const char* pName = nullptr);

public:
    void testIndexingExport_Paragraphs();
    void testIndexingExport_Images();
    void testIndexingExport_OLE();
    void testIndexingExport_Shapes();
    void testIndexingExport_Tables();
    void testIndexingExport_Sections();
    void testIndexingExport_Fontwork();
    void testIndexingExport_Header_Footer();

    CPPUNIT_TEST_SUITE(IndexingExportTest);
    CPPUNIT_TEST(testIndexingExport_Paragraphs);
    CPPUNIT_TEST(testIndexingExport_Images);
    CPPUNIT_TEST(testIndexingExport_OLE);
    CPPUNIT_TEST(testIndexingExport_Shapes);
    CPPUNIT_TEST(testIndexingExport_Tables);
    CPPUNIT_TEST(testIndexingExport_Sections);
    CPPUNIT_TEST(testIndexingExport_Fontwork);
    CPPUNIT_TEST(testIndexingExport_Header_Footer);
    CPPUNIT_TEST_SUITE_END();
};

SwDoc* IndexingExportTest::createDoc(const char* pName)
{
    if (!pName)
        loadURL("private:factory/swriter", nullptr);
    else
        load(DATA_DIRECTORY, pName);

    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
    CPPUNIT_ASSERT(pTextDoc);
    return pTextDoc->GetDocShell()->GetDoc();
}

void IndexingExportTest::testIndexingExport_Paragraphs()
{
    SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Title");
    assertXPath(pXmlDoc, "/indexing/paragraph[1]", "type", "1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Heading 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Heading 2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Paragraph 2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Bullet 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Bullet 2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[8]", "Bullet 3");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[9]", "Paragraph 3");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[10]", "Paragraph 4");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[11]", "List 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[12]", "List 2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[13]", "List 3");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[14]", "Left");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[15]", "Center");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[16]", "Right");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[17]", "Bold Italic Underline Strikeout");
}

void IndexingExportTest::testIndexingExport_Images()
{
    SwDoc* pDoc = createDoc("IndexingExport_Images.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");
    assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Image_NonCaption - Alternative text");
    assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Image_NonCaption");
    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "graphic");
    assertXPath(pXmlDoc, "/indexing/object[2]", "alt", "Image_InCaption - Alternative text");
    assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Image_InCaption");
    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "graphic");
}

void IndexingExportTest::testIndexingExport_OLE()
{
    SwDoc* pDoc = createDoc("IndexingExport_OLE.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");
    assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Object - Chart");
    assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Alt Text");
    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "ole");
}

void IndexingExportTest::testIndexingExport_Shapes()
{
    SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Drawing : Just a Diamond");

    assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Circle");
    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "shape");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "This is a circle");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "This is a second paragraph");

    assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Diamond");
    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "shape");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a diamond");

    assertXPath(pXmlDoc, "/indexing/object[3]", "name", "Text Frame 1");
    assertXPath(pXmlDoc, "/indexing/object[3]", "type", "shape");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "This is a TextBox - Para1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Para2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Para3");
}

void IndexingExportTest::testIndexingExport_Tables()
{
    SwDoc* pDoc = createDoc("IndexingExport_Tables.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");

    assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Table1");
    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "table");
    assertXPath(pXmlDoc, "/indexing/object[1]", "index", "9");
    // Search paragraph with parent = 9
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][1]", "A");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][2]", "B");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][3]", "1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][4]", "2");

    assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Table2");
    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "table");
    assertXPath(pXmlDoc, "/indexing/object[2]", "index", "24");
    // Search paragraph with parent = 24
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][1]", "A");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][2]", "B");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][3]", "C");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][4]", "1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][5]", "10");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][6]", "100");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][7]", "2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][8]", "20");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][9]", "200");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][10]", "3");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][11]", "30");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][12]", "300");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][13]", "4");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][14]", "40");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][15]", "400");

    assertXPath(pXmlDoc, "/indexing/object[3]", "name", "WeirdTable");
    assertXPath(pXmlDoc, "/indexing/object[3]", "type", "table");
    assertXPath(pXmlDoc, "/indexing/object[3]", "index", "72");
    // Search paragraph with parent = 72
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][1]", "A1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][2]", "B1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][3]", "C1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][4]", "D1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][5]", "A2B2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][6]", "C2D2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][7]", "A3B3C3D3");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][8]", "A4-1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][9]", "A4-2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][10]", "B4-1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][11]", "C4-1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][12]", "D4-1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][13]", "D4-2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][14]", "B4-2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][15]", "C4-2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][16]", "A5B5C5");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][17]", "D5");
}

void IndexingExportTest::testIndexingExport_Sections()
{
    SwDoc* pDoc = createDoc("IndexingExport_Sections.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");

    assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Section1");
    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "section");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "This is a paragraph in a Section1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Section1 - Paragraph 2");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Section1 - Paragraph 3");

    assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a paragraph outside sections");

    assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Section2");
    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "section");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Section2 - Paragraph 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Section2 - Paragraph 2");

    assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "This is a paragraph outside sections");
}

void IndexingExportTest::testIndexingExport_Fontwork()
{
    SwDoc* pDoc = createDoc("IndexingExport_Fontwork.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");

    assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Gray");
    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "shape");

    assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Fontwork Text 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Fontwork Text 2");
}

void IndexingExportTest::testIndexingExport_Header_Footer()
{
    SwDoc* pDoc = createDoc("IndexingExport_Header_Footer.odt");
    CPPUNIT_ASSERT(pDoc);

    SvMemoryStream aMemoryStream;
    sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
    aIndexingExport.runExport();
    aMemoryStream.Seek(0);

    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
    CPPUNIT_ASSERT(pXmlDoc);

    assertXPath(pXmlDoc, "/indexing");

    assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Header Text");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Footer Text");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Paragraph 1");
    assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 2");
}

CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */