Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / extras / indexing / IndexingExportTest.cxx
blobfa56aa3c53a07fba53a4d932984e93918974d5d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <swmodeltestbase.hxx>
11 #include <docsh.hxx>
12 #include <unotxdoc.hxx>
14 #include <IndexingExport.hxx>
16 class IndexingExportTest : public SwModelTestBase
18 public:
19 IndexingExportTest()
20 : SwModelTestBase("/sw/qa/extras/indexing/data/")
24 void testIndexingExport_Paragraphs();
25 void testIndexingExport_Images();
26 void testIndexingExport_OLE();
27 void testIndexingExport_Shapes();
28 void testIndexingExport_Tables();
29 void testIndexingExport_Sections();
30 void testIndexingExport_Fontwork();
31 void testIndexingExport_Header_Footer();
33 CPPUNIT_TEST_SUITE(IndexingExportTest);
34 CPPUNIT_TEST(testIndexingExport_Paragraphs);
35 CPPUNIT_TEST(testIndexingExport_Images);
36 CPPUNIT_TEST(testIndexingExport_OLE);
37 CPPUNIT_TEST(testIndexingExport_Shapes);
38 CPPUNIT_TEST(testIndexingExport_Tables);
39 CPPUNIT_TEST(testIndexingExport_Sections);
40 CPPUNIT_TEST(testIndexingExport_Fontwork);
41 CPPUNIT_TEST(testIndexingExport_Header_Footer);
42 CPPUNIT_TEST_SUITE_END();
45 void IndexingExportTest::testIndexingExport_Paragraphs()
47 createSwDoc("IndexingExport_VariousParagraphs.odt");
48 SwDoc* pDoc = getSwDoc();
49 CPPUNIT_ASSERT(pDoc);
51 SvMemoryStream aMemoryStream;
52 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
53 aIndexingExport.runExport();
54 aMemoryStream.Seek(0);
56 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
57 CPPUNIT_ASSERT(pXmlDoc);
59 assertXPath(pXmlDoc, "/indexing");
60 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Title");
61 assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", "writer");
62 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Heading 1");
63 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Heading 2");
64 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 1");
65 assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Paragraph 2");
66 assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Bullet 1");
67 assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Bullet 2");
68 assertXPathContent(pXmlDoc, "/indexing/paragraph[8]", "Bullet 3");
69 assertXPathContent(pXmlDoc, "/indexing/paragraph[9]", "Paragraph 3");
70 assertXPathContent(pXmlDoc, "/indexing/paragraph[10]", "Paragraph 4");
71 assertXPathContent(pXmlDoc, "/indexing/paragraph[11]", "List 1");
72 assertXPathContent(pXmlDoc, "/indexing/paragraph[12]", "List 2");
73 assertXPathContent(pXmlDoc, "/indexing/paragraph[13]", "List 3");
74 assertXPathContent(pXmlDoc, "/indexing/paragraph[14]", "Left");
75 assertXPathContent(pXmlDoc, "/indexing/paragraph[15]", "Center");
76 assertXPathContent(pXmlDoc, "/indexing/paragraph[16]", "Right");
77 assertXPathContent(pXmlDoc, "/indexing/paragraph[17]", "Bold Italic Underline Strikeout");
78 assertXPath(pXmlDoc, "/indexing/paragraph[17]", "node_type", "writer");
81 void IndexingExportTest::testIndexingExport_Images()
83 createSwDoc("IndexingExport_Images.odt");
84 SwDoc* pDoc = getSwDoc();
85 CPPUNIT_ASSERT(pDoc);
87 SvMemoryStream aMemoryStream;
88 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
89 aIndexingExport.runExport();
90 aMemoryStream.Seek(0);
92 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
93 CPPUNIT_ASSERT(pXmlDoc);
95 assertXPath(pXmlDoc, "/indexing");
96 assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Image_NonCaption - Alternative text");
97 assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Image_NonCaption");
98 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "graphic");
99 assertXPath(pXmlDoc, "/indexing/object[2]", "alt", "Image_InCaption - Alternative text");
100 assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Image_InCaption");
101 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "graphic");
104 void IndexingExportTest::testIndexingExport_OLE()
106 createSwDoc("IndexingExport_OLE.odt");
107 SwDoc* pDoc = getSwDoc();
108 CPPUNIT_ASSERT(pDoc);
110 SvMemoryStream aMemoryStream;
111 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
112 aIndexingExport.runExport();
113 aMemoryStream.Seek(0);
115 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
116 CPPUNIT_ASSERT(pXmlDoc);
118 assertXPath(pXmlDoc, "/indexing");
119 assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Object - Chart");
120 assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Alt Text");
121 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "ole");
124 void IndexingExportTest::testIndexingExport_Shapes()
126 createSwDoc("IndexingExport_Shapes.odt");
127 SwDoc* pDoc = getSwDoc();
128 CPPUNIT_ASSERT(pDoc);
130 SvMemoryStream aMemoryStream;
131 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
132 aIndexingExport.runExport();
133 aMemoryStream.Seek(0);
135 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
136 CPPUNIT_ASSERT(pXmlDoc);
138 assertXPath(pXmlDoc, "/indexing");
139 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Drawing : Just a Diamond");
140 assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", "writer");
142 assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Circle");
143 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape");
144 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "This is a circle");
145 assertXPath(pXmlDoc, "/indexing/paragraph[2]", "node_type", "common");
146 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "This is a second paragraph");
147 assertXPath(pXmlDoc, "/indexing/paragraph[3]", "node_type", "common");
149 assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Diamond");
150 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "shape");
151 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a diamond");
152 assertXPath(pXmlDoc, "/indexing/paragraph[4]", "node_type", "common");
154 assertXPath(pXmlDoc, "/indexing/object[3]", "name", "Text Frame 1");
155 assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "shape");
156 assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "This is a TextBox - Para1");
157 assertXPath(pXmlDoc, "/indexing/paragraph[5]", "node_type", "common");
158 assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Para2");
159 assertXPath(pXmlDoc, "/indexing/paragraph[6]", "node_type", "common");
160 assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Para3");
161 assertXPath(pXmlDoc, "/indexing/paragraph[7]", "node_type", "common");
164 void IndexingExportTest::testIndexingExport_Tables()
166 createSwDoc("IndexingExport_Tables.odt");
167 SwDoc* pDoc = getSwDoc();
168 CPPUNIT_ASSERT(pDoc);
170 SvMemoryStream aMemoryStream;
171 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
172 aIndexingExport.runExport();
173 aMemoryStream.Seek(0);
175 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
176 CPPUNIT_ASSERT(pXmlDoc);
178 assertXPath(pXmlDoc, "/indexing");
180 assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Table1");
181 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "table");
182 assertXPath(pXmlDoc, "/indexing/object[1]", "index", "9");
183 // Search paragraph with parent_index = 9
184 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][1]", "A");
185 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][2]", "B");
186 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][3]", "1");
187 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][4]", "2");
189 assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Table2");
190 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "table");
191 assertXPath(pXmlDoc, "/indexing/object[2]", "index", "24");
192 // Search paragraph with parent_index = 24
193 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][1]", "A");
194 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][2]", "B");
195 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][3]", "C");
196 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][4]", "1");
197 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][5]", "10");
198 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][6]", "100");
199 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][7]", "2");
200 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][8]", "20");
201 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][9]", "200");
202 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][10]", "3");
203 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][11]", "30");
204 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][12]", "300");
205 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][13]", "4");
206 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][14]", "40");
207 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][15]", "400");
209 assertXPath(pXmlDoc, "/indexing/object[3]", "name", "WeirdTable");
210 assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "table");
211 assertXPath(pXmlDoc, "/indexing/object[3]", "index", "72");
212 // Search paragraph with parent_index = 72
213 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][1]", "A1");
214 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][2]", "B1");
215 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][3]", "C1");
216 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][4]", "D1");
217 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][5]", "A2B2");
218 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][6]", "C2D2");
219 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][7]", "A3B3C3D3");
220 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][8]", "A4-1");
221 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][9]", "A4-2");
222 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][10]", "B4-1");
223 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][11]", "C4-1");
224 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][12]", "D4-1");
225 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][13]", "D4-2");
226 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][14]", "B4-2");
227 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][15]", "C4-2");
228 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][16]", "A5B5C5");
229 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][17]", "D5");
232 void IndexingExportTest::testIndexingExport_Sections()
234 createSwDoc("IndexingExport_Sections.odt");
235 SwDoc* pDoc = getSwDoc();
236 CPPUNIT_ASSERT(pDoc);
238 SvMemoryStream aMemoryStream;
239 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
240 aIndexingExport.runExport();
241 aMemoryStream.Seek(0);
243 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
244 CPPUNIT_ASSERT(pXmlDoc);
246 assertXPath(pXmlDoc, "/indexing");
248 assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Section1");
249 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "section");
250 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "This is a paragraph in a Section1");
251 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Section1 - Paragraph 2");
252 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Section1 - Paragraph 3");
254 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a paragraph outside sections");
256 assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Section2");
257 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "section");
258 assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Section2 - Paragraph 1");
259 assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Section2 - Paragraph 2");
261 assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "This is a paragraph outside sections");
264 void IndexingExportTest::testIndexingExport_Fontwork()
266 createSwDoc("IndexingExport_Fontwork.odt");
267 SwDoc* pDoc = getSwDoc();
268 CPPUNIT_ASSERT(pDoc);
270 SvMemoryStream aMemoryStream;
271 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
272 aIndexingExport.runExport();
273 aMemoryStream.Seek(0);
275 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
276 CPPUNIT_ASSERT(pXmlDoc);
278 assertXPath(pXmlDoc, "/indexing");
280 assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Gray");
281 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape");
283 assertXPath(pXmlDoc, "/indexing/paragraph[1]", "object_name", "Gray");
284 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Fontwork Text 1");
285 assertXPath(pXmlDoc, "/indexing/paragraph[2]", "object_name", "Gray");
286 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Fontwork Text 2");
289 void IndexingExportTest::testIndexingExport_Header_Footer()
291 createSwDoc("IndexingExport_Header_Footer.odt");
292 SwDoc* pDoc = getSwDoc();
293 CPPUNIT_ASSERT(pDoc);
295 SvMemoryStream aMemoryStream;
296 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
297 aIndexingExport.runExport();
298 aMemoryStream.Seek(0);
300 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
301 CPPUNIT_ASSERT(pXmlDoc);
303 assertXPath(pXmlDoc, "/indexing");
305 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Header Text");
306 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Footer Text");
307 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Paragraph 1");
308 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 2");
311 CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest);
312 CPPUNIT_PLUGIN_IMPLEMENT();
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */