remove assert looking for new compatibilityMode DOCX
[LibreOffice.git] / sw / qa / extras / indexing / IndexingExportTest.cxx
blobf52de4a8ab310c1076ef40ac4482d79c30a08a19
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 namespace
18 class IndexingExportTest : public SwModelTestBase
20 public:
21 IndexingExportTest()
22 : SwModelTestBase(u"/sw/qa/extras/indexing/data/"_ustr)
26 void testIndexingExport_Paragraphs();
27 void testIndexingExport_Images();
28 void testIndexingExport_OLE();
29 void testIndexingExport_Shapes();
30 void testIndexingExport_Tables();
31 void testIndexingExport_Sections();
32 void testIndexingExport_Fontwork();
33 void testIndexingExport_Header_Footer();
35 CPPUNIT_TEST_SUITE(IndexingExportTest);
36 CPPUNIT_TEST(testIndexingExport_Paragraphs);
37 CPPUNIT_TEST(testIndexingExport_Images);
38 CPPUNIT_TEST(testIndexingExport_OLE);
39 CPPUNIT_TEST(testIndexingExport_Shapes);
40 CPPUNIT_TEST(testIndexingExport_Tables);
41 CPPUNIT_TEST(testIndexingExport_Sections);
42 CPPUNIT_TEST(testIndexingExport_Fontwork);
43 CPPUNIT_TEST(testIndexingExport_Header_Footer);
44 CPPUNIT_TEST_SUITE_END();
47 void IndexingExportTest::testIndexingExport_Paragraphs()
49 createSwDoc("IndexingExport_VariousParagraphs.odt");
50 SwDoc* pDoc = getSwDoc();
52 SvMemoryStream aMemoryStream;
53 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
54 aIndexingExport.runExport();
55 aMemoryStream.Seek(0);
57 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
58 CPPUNIT_ASSERT(pXmlDoc);
60 assertXPath(pXmlDoc, "/indexing");
61 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", u"Title");
62 assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", u"writer");
63 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", u"Heading 1");
64 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", u"Heading 2");
65 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", u"Paragraph 1");
66 assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", u"Paragraph 2");
67 assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", u"Bullet 1");
68 assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", u"Bullet 2");
69 assertXPathContent(pXmlDoc, "/indexing/paragraph[8]", u"Bullet 3");
70 assertXPathContent(pXmlDoc, "/indexing/paragraph[9]", u"Paragraph 3");
71 assertXPathContent(pXmlDoc, "/indexing/paragraph[10]", u"Paragraph 4");
72 assertXPathContent(pXmlDoc, "/indexing/paragraph[11]", u"List 1");
73 assertXPathContent(pXmlDoc, "/indexing/paragraph[12]", u"List 2");
74 assertXPathContent(pXmlDoc, "/indexing/paragraph[13]", u"List 3");
75 assertXPathContent(pXmlDoc, "/indexing/paragraph[14]", u"Left");
76 assertXPathContent(pXmlDoc, "/indexing/paragraph[15]", u"Center");
77 assertXPathContent(pXmlDoc, "/indexing/paragraph[16]", u"Right");
78 assertXPathContent(pXmlDoc, "/indexing/paragraph[17]", u"Bold Italic Underline Strikeout");
79 assertXPath(pXmlDoc, "/indexing/paragraph[17]", "node_type", u"writer");
82 void IndexingExportTest::testIndexingExport_Images()
84 createSwDoc("IndexingExport_Images.odt");
85 SwDoc* pDoc = getSwDoc();
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", u"Image_NonCaption - Alternative text");
97 assertXPath(pXmlDoc, "/indexing/object[1]", "name", u"Image_NonCaption");
98 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", u"graphic");
99 assertXPath(pXmlDoc, "/indexing/object[2]", "alt", u"Image_InCaption - Alternative text");
100 assertXPath(pXmlDoc, "/indexing/object[2]", "name", u"Image_InCaption");
101 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", u"graphic");
104 void IndexingExportTest::testIndexingExport_OLE()
106 createSwDoc("IndexingExport_OLE.odt");
107 SwDoc* pDoc = getSwDoc();
109 SvMemoryStream aMemoryStream;
110 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
111 aIndexingExport.runExport();
112 aMemoryStream.Seek(0);
114 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
115 CPPUNIT_ASSERT(pXmlDoc);
117 assertXPath(pXmlDoc, "/indexing");
118 assertXPath(pXmlDoc, "/indexing/object[1]", "name", u"Object - Chart");
119 assertXPath(pXmlDoc, "/indexing/object[1]", "alt", u"Alt Text");
120 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", u"ole");
123 void IndexingExportTest::testIndexingExport_Shapes()
125 createSwDoc("IndexingExport_Shapes.odt");
126 SwDoc* pDoc = getSwDoc();
128 SvMemoryStream aMemoryStream;
129 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
130 aIndexingExport.runExport();
131 aMemoryStream.Seek(0);
133 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
134 CPPUNIT_ASSERT(pXmlDoc);
136 assertXPath(pXmlDoc, "/indexing");
137 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", u"Drawing : Just a Diamond");
138 assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", u"writer");
140 assertXPath(pXmlDoc, "/indexing/object[1]", "name", u"Circle");
141 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", u"shape");
142 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", u"This is a circle");
143 assertXPath(pXmlDoc, "/indexing/paragraph[2]", "node_type", u"common");
144 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", u"This is a second paragraph");
145 assertXPath(pXmlDoc, "/indexing/paragraph[3]", "node_type", u"common");
147 assertXPath(pXmlDoc, "/indexing/object[2]", "name", u"Diamond");
148 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", u"shape");
149 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", u"This is a diamond");
150 assertXPath(pXmlDoc, "/indexing/paragraph[4]", "node_type", u"common");
152 assertXPath(pXmlDoc, "/indexing/object[3]", "name", u"Text Frame 1");
153 assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", u"shape");
154 assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", u"This is a TextBox - Para1");
155 assertXPath(pXmlDoc, "/indexing/paragraph[5]", "node_type", u"common");
156 assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", u"Para2");
157 assertXPath(pXmlDoc, "/indexing/paragraph[6]", "node_type", u"common");
158 assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", u"Para3");
159 assertXPath(pXmlDoc, "/indexing/paragraph[7]", "node_type", u"common");
162 void IndexingExportTest::testIndexingExport_Tables()
164 createSwDoc("IndexingExport_Tables.odt");
165 SwDoc* pDoc = getSwDoc();
167 SvMemoryStream aMemoryStream;
168 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
169 aIndexingExport.runExport();
170 aMemoryStream.Seek(0);
172 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
173 CPPUNIT_ASSERT(pXmlDoc);
175 assertXPath(pXmlDoc, "/indexing");
177 assertXPath(pXmlDoc, "/indexing/object[1]", "name", u"Table1");
178 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", u"table");
179 assertXPath(pXmlDoc, "/indexing/object[1]", "index", u"9");
180 // Search paragraph with parent_index = 9
181 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][1]", u"A");
182 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][2]", u"B");
183 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][3]", u"1");
184 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][4]", u"2");
186 assertXPath(pXmlDoc, "/indexing/object[2]", "name", u"Table2");
187 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", u"table");
188 assertXPath(pXmlDoc, "/indexing/object[2]", "index", u"24");
189 // Search paragraph with parent_index = 24
190 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][1]", u"A");
191 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][2]", u"B");
192 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][3]", u"C");
193 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][4]", u"1");
194 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][5]", u"10");
195 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][6]", u"100");
196 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][7]", u"2");
197 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][8]", u"20");
198 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][9]", u"200");
199 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][10]", u"3");
200 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][11]", u"30");
201 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][12]", u"300");
202 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][13]", u"4");
203 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][14]", u"40");
204 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][15]", u"400");
206 assertXPath(pXmlDoc, "/indexing/object[3]", "name", u"WeirdTable");
207 assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", u"table");
208 assertXPath(pXmlDoc, "/indexing/object[3]", "index", u"72");
209 // Search paragraph with parent_index = 72
210 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][1]", u"A1");
211 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][2]", u"B1");
212 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][3]", u"C1");
213 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][4]", u"D1");
214 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][5]", u"A2B2");
215 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][6]", u"C2D2");
216 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][7]", u"A3B3C3D3");
217 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][8]", u"A4-1");
218 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][9]", u"A4-2");
219 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][10]", u"B4-1");
220 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][11]", u"C4-1");
221 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][12]", u"D4-1");
222 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][13]", u"D4-2");
223 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][14]", u"B4-2");
224 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][15]", u"C4-2");
225 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][16]", u"A5B5C5");
226 assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][17]", u"D5");
229 void IndexingExportTest::testIndexingExport_Sections()
231 createSwDoc("IndexingExport_Sections.odt");
232 SwDoc* pDoc = getSwDoc();
234 SvMemoryStream aMemoryStream;
235 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
236 aIndexingExport.runExport();
237 aMemoryStream.Seek(0);
239 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
240 CPPUNIT_ASSERT(pXmlDoc);
242 assertXPath(pXmlDoc, "/indexing");
244 assertXPath(pXmlDoc, "/indexing/object[1]", "name", u"Section1");
245 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", u"section");
246 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", u"This is a paragraph in a Section1");
247 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", u"Section1 - Paragraph 2");
248 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", u"Section1 - Paragraph 3");
250 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", u"This is a paragraph outside sections");
252 assertXPath(pXmlDoc, "/indexing/object[2]", "name", u"Section2");
253 assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", u"section");
254 assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", u"Section2 - Paragraph 1");
255 assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", u"Section2 - Paragraph 2");
257 assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", u"This is a paragraph outside sections");
260 void IndexingExportTest::testIndexingExport_Fontwork()
262 createSwDoc("IndexingExport_Fontwork.odt");
263 SwDoc* pDoc = getSwDoc();
265 SvMemoryStream aMemoryStream;
266 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
267 aIndexingExport.runExport();
268 aMemoryStream.Seek(0);
270 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
271 CPPUNIT_ASSERT(pXmlDoc);
273 assertXPath(pXmlDoc, "/indexing");
275 assertXPath(pXmlDoc, "/indexing/object[1]", "name", u"Gray");
276 assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", u"shape");
278 assertXPath(pXmlDoc, "/indexing/paragraph[1]", "object_name", u"Gray");
279 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", u"Fontwork Text 1");
280 assertXPath(pXmlDoc, "/indexing/paragraph[2]", "object_name", u"Gray");
281 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", u"Fontwork Text 2");
284 void IndexingExportTest::testIndexingExport_Header_Footer()
286 createSwDoc("IndexingExport_Header_Footer.odt");
287 SwDoc* pDoc = getSwDoc();
289 SvMemoryStream aMemoryStream;
290 sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
291 aIndexingExport.runExport();
292 aMemoryStream.Seek(0);
294 xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
295 CPPUNIT_ASSERT(pXmlDoc);
297 assertXPath(pXmlDoc, "/indexing");
299 assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", u"Header Text");
300 assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", u"Footer Text");
301 assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", u"Paragraph 1");
302 assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", u"Paragraph 2");
305 } // end of anonymous namespace
306 CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest);
307 CPPUNIT_PLUGIN_IMPLEMENT();
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */