Line data Source code
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 <swmodeltestbase.hxx>
11 :
12 : #include <com/sun/star/awt/XBitmap.hpp>
13 : #include <com/sun/star/graphic/XGraphic.hpp>
14 : #include <com/sun/star/frame/XStorable.hpp>
15 : #include <com/sun/star/drawing/FillStyle.hpp>
16 : #include <com/sun/star/drawing/LineJoint.hpp>
17 : #include <com/sun/star/drawing/LineStyle.hpp>
18 : #include <com/sun/star/drawing/XControlShape.hpp>
19 : #include <com/sun/star/awt/Gradient.hpp>
20 : #include <com/sun/star/style/TabStop.hpp>
21 : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
22 : #include <com/sun/star/text/RelOrientation.hpp>
23 : #include <com/sun/star/text/XTextFrame.hpp>
24 : #include <com/sun/star/text/XTextTable.hpp>
25 : #include <com/sun/star/text/XTextFramesSupplier.hpp>
26 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
27 : #include <com/sun/star/text/XTextSection.hpp>
28 : #include <com/sun/star/style/CaseMap.hpp>
29 : #include <com/sun/star/style/ParagraphAdjust.hpp>
30 : #include <com/sun/star/style/LineSpacing.hpp>
31 : #include <com/sun/star/style/LineSpacingMode.hpp>
32 : #include <com/sun/star/view/XSelectionSupplier.hpp>
33 : #include <com/sun/star/table/BorderLine2.hpp>
34 : #include <com/sun/star/table/ShadowFormat.hpp>
35 : #include <com/sun/star/text/GraphicCrop.hpp>
36 : #include <com/sun/star/text/XPageCursor.hpp>
37 : #include <com/sun/star/awt/FontWeight.hpp>
38 : #include <com/sun/star/awt/FontUnderline.hpp>
39 : #include <com/sun/star/awt/FontSlant.hpp>
40 : #include <com/sun/star/text/WritingMode2.hpp>
41 : #include <com/sun/star/text/WrapTextMode.hpp>
42 : #include <com/sun/star/xml/dom/XDocument.hpp>
43 : #include <com/sun/star/style/BreakType.hpp>
44 : #include <unotools/tempfile.hxx>
45 : #include <comphelper/sequenceashashmap.hxx>
46 : #include <com/sun/star/text/XDocumentIndex.hpp>
47 : #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
48 : #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
49 : #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
50 : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
51 : #include <com/sun/star/drawing/Hatch.hpp>
52 :
53 : #include <string>
54 :
55 208 : class Test : public SwModelTestBase
56 : {
57 : public:
58 208 : Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {}
59 :
60 : protected:
61 : /**
62 : * Blacklist handling
63 : */
64 104 : bool mustTestImportOf(const char* filename) const SAL_OVERRIDE {
65 : // If the testcase is stored in some other format, it's pointless to test.
66 104 : return (OString(filename).endsWith(".docx"));
67 : }
68 : };
69 :
70 28 : DECLARE_OOXMLEXPORT_TEST(testFdo47669, "fdo47669.docx")
71 : {
72 : /*
73 : * Problem: we created imbalance </w:hyperlink> which shouldn't be there,
74 : * resulting in loading error: missing last character of hyperlink text
75 : * and content after it wasn't loaded.
76 : */
77 4 : getParagraph(1, "This is a hyperlink with anchor. Also, this sentence should be seen.");
78 4 : getRun(getParagraph(1), 2, "hyperlink with anchor");
79 4 : CPPUNIT_ASSERT_EQUAL(OUString("http://www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 2), "HyperLinkURL"));
80 4 : }
81 :
82 28 : DECLARE_OOXMLEXPORT_TEST(testN789482, "n789482.docx")
83 : {
84 : // The problem was that w:del was exported before w:hyperlink, resulting in an invalid XML.
85 4 : uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
86 4 : getRun(xParagraph, 1, "Before. ");
87 :
88 4 : CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 2), "RedlineType"));
89 4 : CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(getRun(xParagraph, 2), "IsStart"));
90 :
91 4 : getRun(xParagraph, 3, "www.test.com");
92 4 : CPPUNIT_ASSERT_EQUAL(OUString("http://www.test.com/"), getProperty<OUString>(getRun(xParagraph, 3), "HyperLinkURL"));
93 :
94 4 : CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 4), "RedlineType"));
95 4 : CPPUNIT_ASSERT_EQUAL(sal_False, getProperty<sal_Bool>(getRun(xParagraph, 4), "IsStart"));
96 :
97 4 : getRun(xParagraph, 5, " After.");
98 4 : }
99 :
100 26 : DECLARE_OOXMLEXPORT_TEST(testBnc834035, "bnc834035.odt")
101 : {
102 : // Illustration index had wrong hyperlinks: anchor was using Writer's
103 : // <seqname>!<index>|sequence syntax, not a bookmark name.
104 2 : xmlDocPtr pXmlDoc = parseExport();
105 2 : if (!pXmlDoc)
106 2 : return;
107 : // This was Figure!1|sequence.
108 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p[10]/w:hyperlink", "anchor", "_Toc363553908");
109 : }
110 :
111 26 : DECLARE_OOXMLEXPORT_TEST(testCp1000015, "cp1000015.odt")
112 : {
113 : // Redline and hyperlink end got exported in an incorrect order.
114 2 : getParagraph(1, "Hello.");
115 2 : getParagraph(2, "http://www.google.com/");
116 2 : }
117 :
118 28 : DECLARE_OOXMLEXPORT_TEST(testHyperlineIsEnd, "hyperlink.docx")
119 : {
120 : // Check that the document.xml contents all the tag properly closed.
121 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
122 4 : if (!pXmlDoc)
123 6 : return;
124 : // If document.xml miss any ending tag then parseExport() returns NULL which fail the test case.
125 2 : CPPUNIT_ASSERT(pXmlDoc) ;
126 : // Check hyperlink is properly open.
127 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:hyperlink",1);
128 : }
129 :
130 28 : DECLARE_OOXMLEXPORT_TEST(testFdo69649, "fdo69649.docx")
131 : {
132 : // The DOCX containing the Table of Contents was not exported with correct page nos
133 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
134 4 : if (!pXmlDoc)
135 6 : return;
136 :
137 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[21]/w:hyperlink/w:r[5]/w:t", "15");
138 : }
139 :
140 28 : DECLARE_OOXMLEXPORT_TEST(testFieldFlagO,"TOC_field_f.docx")
141 : {
142 : // This test case is to verify \o flag should come once.
143 4 : xmlDocPtr pXmlDoc = parseExport();
144 4 : if (!pXmlDoc)
145 6 : return;
146 :
147 : // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
148 : // not to insert an empty paragraph before TOC.
149 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " TOC \\z \\f \\o \"1-3\" \\u \\h");
150 : }
151 :
152 28 : DECLARE_OOXMLEXPORT_TEST(testTOCFlag_f, "toc_doc.docx")
153 : {
154 : // Export logic for all TOC field flags was enclosed inside
155 : // if( nsSwTOXElement::TOX_MARK & pTOX->GetCreateType() ) in ww8atr.cxx which gets true for \f,
156 : // this was the reason if there is \f flag present in original doc then only other flags like
157 : // \o \h \n used to come after RoundTrip.
158 : // This test case is to verify even if there is no \f flag in original doc, \h flag is getting
159 : // preserved after RT.
160 4 : xmlDocPtr pXmlDoc = parseExport();
161 4 : if (!pXmlDoc)
162 6 : return;
163 :
164 : // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
165 : // not to insert an empty paragraph before TOC.
166 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " TOC \\z \\o \"1-3\" \\u \\h");
167 : }
168 :
169 28 : DECLARE_OOXMLEXPORT_TEST(testPreserveZfield,"preserve_Z_field_TOC.docx")
170 : {
171 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
172 4 : if (!pXmlDoc)
173 6 : return;
174 :
175 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[2]/w:instrText", " TOC \\z \\f \\o \"1-3\" \\h");
176 : }
177 :
178 28 : DECLARE_OOXMLEXPORT_TEST(testPreserveWfieldTOC, "PreserveWfieldTOC.docx")
179 : {
180 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
181 4 : if (!pXmlDoc)
182 6 : return;
183 :
184 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\z \\w \\f \\o \"1-3\" \\h");
185 : }
186 :
187 28 : DECLARE_OOXMLEXPORT_TEST(testFieldFlagB,"TOC_field_b.docx")
188 : {
189 : // This test case is to verify \b flag.
190 4 : xmlDocPtr pXmlDoc = parseExport();
191 4 : if (!pXmlDoc)
192 6 : return;
193 :
194 : // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
195 : // not to insert an empty paragraph before TOC.
196 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " TOC \\b \"bookmark111\" \\o \"1-9\" \\h");
197 : }
198 :
199 28 : DECLARE_OOXMLEXPORT_TEST(testPreserveXfieldTOC, "PreserveXfieldTOC.docx")
200 : {
201 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
202 4 : if (!pXmlDoc)
203 6 : return;
204 :
205 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\x \\f \\o \"1-3\" \\h");
206 : }
207 :
208 28 : DECLARE_OOXMLEXPORT_TEST(testFDO77715,"FDO77715.docx")
209 : {
210 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
211 4 : if (!pXmlDoc)
212 6 : return;
213 :
214 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText[1]", " TOC \\c ");
215 : }
216 :
217 28 : DECLARE_OOXMLEXPORT_TEST(testTOCFlag_u,"testTOCFlag_u.docx")
218 : {
219 : // DOCX contaning TOC should preserve code field '\u'.
220 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
221 4 : if (!pXmlDoc)
222 6 : return;
223 :
224 : // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
225 : // not to insert an empty paragraph before TOC.
226 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\z \\o \"1-9\" \\u \\h");
227 : }
228 :
229 28 : DECLARE_OOXMLEXPORT_TEST(testfdo73596_RunInStyle,"fdo73596_RunInStyle.docx")
230 : {
231 : // INDEX should be preserved.
232 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
233 4 : if (!pXmlDoc)
234 6 : return;
235 :
236 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText[1]", " INDEX \\e \"");
237 : }
238 :
239 28 : DECLARE_OOXMLEXPORT_TEST(testfdo73596_AlphaSeparator,"fdo73596_AlphaSeparator.docx")
240 : {
241 : // INDEX flag \h "A" should be preserved.
242 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
243 4 : if (!pXmlDoc)
244 6 : return;
245 :
246 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText[1]", " INDEX \\h \"A\" \\e \"");
247 : }
248 :
249 28 : DECLARE_OOXMLEXPORT_TEST(testCaption1, "EquationAsScientificNumbering.docx")
250 : {
251 : // fdo#74431 : This test case is to verify the Captions are coming properly
252 : // earlier it was coming as "SEQ "scientific"\*ROMAN now it is SEQ scientific\* ROMAN"
253 :
254 4 : xmlDocPtr pXmlDoc = parseExport();
255 4 : if (!pXmlDoc)
256 6 : return;
257 :
258 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:instrText", " SEQ scientific \\* ROMAN ");
259 : }
260 :
261 28 : DECLARE_OOXMLEXPORT_TEST(testCaption2, "EquationWithAboveAndBelowCaption.docx")
262 : {
263 : // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
264 : // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
265 4 : xmlDocPtr pXmlDoc = parseExport();
266 4 : if (!pXmlDoc)
267 6 : return;
268 :
269 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[5]/w:r[3]/w:instrText", " SEQ Equation \\* ARABIC ");
270 : }
271 :
272 28 : DECLARE_OOXMLEXPORT_TEST(testCaption3, "FigureAsLabelPicture.docx")
273 : {
274 : // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
275 : // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
276 4 : xmlDocPtr pXmlDoc = parseExport();
277 4 : if (!pXmlDoc)
278 6 : return;
279 :
280 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[3]/w:instrText", " SEQ picture \\* ARABIC ");
281 : }
282 :
283 28 : DECLARE_OOXMLEXPORT_TEST(testCaption4, "TableWithAboveCaptions.docx")
284 : {
285 : // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
286 : // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
287 4 : xmlDocPtr pXmlDoc = parseExport();
288 4 : if (!pXmlDoc)
289 6 : return;
290 :
291 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:instrText", " SEQ Table \\* ARABIC ");
292 : }
293 :
294 28 : DECLARE_OOXMLEXPORT_TEST(testFooterContainHyperlink,"footer-contain-hyperlink.docx")
295 : {
296 : // Problem is that footer1.xml.rels contains the empty
297 : // Target due to which the file get corrupted
298 : // in MS Office 2007.
299 : // Check for footer1.xml.rels file.
300 4 : xmlDocPtr pXmlRels = parseExport("word/_rels/footer1.xml.rels");
301 4 : if (!pXmlRels)
302 6 : return;
303 : // Check the value of Target which is http://www.google.com/.
304 2 : assertXPath(pXmlRels,"/rels:Relationships/rels:Relationship","Target","http://www.google.com/");
305 : }
306 :
307 28 : DECLARE_OOXMLEXPORT_TEST(testAlphabeticalIndex_MultipleColumns,"alphabeticalIndex_MultipleColumns.docx")
308 : {
309 : // Bug :: fdo#73596
310 : /*
311 : * Index with multiple columns was not imported correctly and
312 : * hence not exported correctly...
313 : * The column count is given by the \c switch.
314 : * If the column count is explicitly specified,
315 : * MS Office adds section breaks before and after the Index.
316 : */
317 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
318 4 : if (!pXmlDoc)
319 6 : return;
320 :
321 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText", " INDEX \\c \"4\"\\e \"");
322 :
323 : // check for section breaks after and before the Index Section
324 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:sectPr/w:type","val","continuous");
325 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:sectPr/w:type","val","continuous");
326 : // check for "w:space" attribute for the columns in Section Properties
327 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:sectPr/w:cols/w:col[1]","space","720");
328 : }
329 :
330 28 : DECLARE_OOXMLEXPORT_TEST(testPageref, "testPageref.docx")
331 : {
332 : // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
333 : // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
334 4 : xmlDocPtr pXmlDoc = parseExport();
335 4 : if (!pXmlDoc)
336 6 : return;
337 :
338 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:hyperlink/w:r[3]/w:instrText", "PAGEREF _Toc355095261 \\h");
339 : }
340 :
341 28 : DECLARE_OOXMLEXPORT_TEST(testAlphabeticalIndex_AutoColumn,"alphabeticalIndex_AutoColumn.docx")
342 : {
343 : // Bug :: fdo#73596
344 : /*
345 : * When the columns in Index are 0; i.e not specified by the
346 : * "\c" switch, don't write back '\c "0"' or the section breaks
347 : * before and after the Index Context
348 : */
349 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
350 4 : if (!pXmlDoc)
351 6 : return;
352 :
353 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " INDEX \\e \"");
354 :
355 : // check for section break doestn't appear for any paragraph
356 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:sectPr", 0);
357 : }
358 :
359 28 : DECLARE_OOXMLEXPORT_TEST(testIndexFieldFlagF,"IndexFieldFlagF.docx")
360 : {
361 : // This test case is to verify the Index field flag '\f' with some
362 : // Specific Entry Type (ex. "Syn" in our case).
363 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
364 4 : if (!pXmlDoc)
365 6 : return;
366 : // We check the Index field flag '\f'.
367 2 : assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[4]/w:r[2]/w:instrText[1]", " INDEX \\c \"2\"\\f \"Syn\" \" \\e \"");
368 : }
369 :
370 28 : DECLARE_OOXMLEXPORT_TEST(testBibliography,"FDO75133.docx")
371 : {
372 4 : xmlDocPtr pXmlDoc = parseExport();
373 4 : if (!pXmlDoc)
374 6 : return;
375 :
376 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " BIBLIOGRAPHY ");
377 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartGallery", "val", "Bibliographies");
378 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartUnique", 1);
379 : }
380 :
381 28 : DECLARE_OOXMLEXPORT_TEST(testGenericTextField, "Unsupportedtextfields.docx")
382 : {
383 : // fdo#75158 : This test case is to verify the unsupported textfields are exported properly.
384 :
385 4 : xmlDocPtr pXmlDoc = parseExport();
386 4 : if (!pXmlDoc)
387 6 : return;
388 2 : xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:r[2]/w:instrText");
389 2 : xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
390 2 : xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
391 2 : OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
392 2 : CPPUNIT_ASSERT(contents.match("PRINTDATE \\* MERGEFORMAT"));
393 2 : xmlXPathFreeObject(pXmlObj);
394 : }
395 :
396 28 : DECLARE_OOXMLEXPORT_TEST(test_FieldType, "99_Fields.docx")
397 : {
398 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
399 4 : if (!pXmlDoc)
400 6 : return;
401 : // Checking for three field types (BIBLIOGRAPHY, BIDIOUTLINE, CITATION) in sequence
402 2 : assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[2]/w:r[2]/w:instrText[1]",1);
403 2 : assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[5]/w:r[2]/w:instrText[1]",1);
404 2 : assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p/w:sdt/w:sdtContent/w:r[2]/w:instrText[1]",1);
405 : }
406 :
407 28 : DECLARE_OOXMLEXPORT_TEST(testCitation,"FDO74775.docx")
408 : {
409 4 : xmlDocPtr pXmlDoc = parseExport();
410 4 : if (!pXmlDoc)
411 6 : return;
412 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:sdt/w:sdtContent/w:r[2]/w:instrText", " CITATION Kra06 \\l 1033 ");
413 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:sdt/w:sdtContent/w:r[4]/w:t", "(Kramer & Chen, 2006)");
414 : }
415 :
416 28 : DECLARE_OOXMLEXPORT_TEST(testHyperLinkTagEnded, "fdo76316.docx")
417 : {
418 : /* XML tag <w:hyperlink> was not getting closed when its inside another
419 : * <w:hyperlink> tag.
420 : */
421 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
422 :
423 8 : if (!pXmlDoc) return;
424 :
425 2 : CPPUNIT_ASSERT(pXmlDoc);
426 2 : assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tr[2]/w:tc[1]/w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]/w:tr[7]/w:tc[1]/w:tbl[1]/w:tr[2]/w:tc[6]/w:tbl[1]/w:tr[1]/w:tc[1]/w:p[1]/w:hyperlink[1]/w:hyperlink[1]",1);
427 : }
428 :
429 28 : DECLARE_OOXMLEXPORT_TEST(testFDO76163 , "fdo76163.docx")
430 : {
431 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
432 4 : if (!pXmlDoc)
433 6 : return;
434 : //docx file after RT is getting corrupted.
435 2 : assertXPath ( pXmlDoc, "/w:document/w:body/w:p[2]/w:hyperlink/w:r[11]/w:fldChar", "fldCharType", "end" );
436 : }
437 :
438 28 : DECLARE_OOXMLEXPORT_TEST(testFDO78659, "fdo78659.docx")
439 : {
440 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
441 4 : if (!pXmlDoc)
442 6 : return;
443 :
444 2 : assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tr[1]/w:tc[1]/w:p[1]/w:hyperlink[1]/w:r[3]/w:fldChar[1]", 0);
445 : }
446 :
447 28 : DECLARE_OOXMLEXPORT_TEST(testFDO78654 , "fdo78654.docx")
448 : {
449 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
450 4 : if (!pXmlDoc)
451 6 : return;
452 : // In case of two "Hyperlink" tags in one paragraph and one of them
453 : // contains "PAGEREF" field then field end tag was missing from hyperlink.
454 2 : assertXPath ( pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:hyperlink[3]/w:r[5]/w:fldChar", "fldCharType", "end" );
455 : }
456 :
457 :
458 28 : DECLARE_OOXMLEXPORT_TEST(testfdo78599,"fdo78599.docx")
459 : {
460 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
461 4 : if (!pXmlDoc)
462 6 : return;
463 : //docx file after RT is getting corrupted.
464 2 : assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:fldChar", "fldCharType", "end" );
465 : }
466 :
467 28 : DECLARE_OOXMLEXPORT_TEST(testfdo78886, "fdo78886.docx")
468 : {
469 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
470 4 : if (!pXmlDoc)
471 6 : return;
472 :
473 2 : assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[2]/w:tr[1]/w:tc[1]/w:p[1]/w:hyperlink[1]/w:r[2]/w:fldChar[1]", 0);
474 : }
475 :
476 28 : DECLARE_OOXMLEXPORT_TEST(testFdo78910, "fdo78910.docx")
477 : {
478 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
479 :
480 4 : if (!pXmlDoc)
481 6 : return;
482 :
483 : // This is to ensure that the fld starts and ends inside a hyperlink...
484 2 : assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[1]/w:fldChar", "fldCharType", "begin" );
485 2 : assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[5]/w:fldChar", "fldCharType", "end" );
486 : }
487 :
488 28 : DECLARE_OOXMLEXPORT_TEST(testFDO78590, "FDO78590.docx")
489 : {
490 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
491 :
492 4 : if (!pXmlDoc)
493 6 : return;
494 :
495 : // This is to ensure that the fld starts and ends inside a hyperlink...
496 2 : assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "w", "9851" );
497 2 : assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "h", "1669" );
498 : }
499 :
500 28 : DECLARE_OOXMLEXPORT_TEST(testSdtCitationRun, "sdt-citation-run.docx")
501 : {
502 : // The problem was that the SDT was around the whole paragraph, not only around the citation field.
503 4 : if (xmlDocPtr pXmlDoc = parseExport())
504 : {
505 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:t", "Before sdt.");
506 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:instrText", " CITATION BBC11 \\l 1033 ");
507 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:t", "After sdt.");
508 : }
509 4 : }
510 :
511 28 : DECLARE_OOXMLEXPORT_TEST(testParagraphSdt, "paragraph-sdt.docx")
512 : {
513 : // The problem was that the SDT was around the run only, not the whole paragraph.
514 4 : if (xmlDocPtr pXmlDoc = parseExport())
515 : {
516 : // The path to w:sdt contained a w:p.
517 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:sdt");
518 : }
519 4 : }
520 :
521 28 : DECLARE_OOXMLEXPORT_TEST(testSdt2Run, "sdt-2-para.docx")
522 : {
523 4 : if (xmlDocPtr pXmlDoc = parseExport())
524 : {
525 : // The problem was that <w:sdt> was closed after "first", not after "second", so the second assert failed.
526 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r/w:t", "first");
527 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r/w:t", "second");
528 : // Make sure the third paragraph is still outside <w:sdt>.
529 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r/w:t", "third");
530 : }
531 4 : }
532 :
533 28 : DECLARE_OOXMLEXPORT_TEST(test2Id, "2-id.docx")
534 : {
535 4 : if (xmlDocPtr pXmlDoc = parseExport())
536 : {
537 : // This was 2, but only one w:id is allowed.
538 2 : assertXPath(pXmlDoc, "//w:sdtPr/w:id", 1);
539 : }
540 4 : }
541 :
542 28 : DECLARE_OOXMLEXPORT_TEST(testTableStart2Sdt, "table-start-2-sdt.docx")
543 : {
544 4 : if (xmlDocPtr pXmlDoc = parseExport())
545 : {
546 : // w:docPartGallery should be a child of <w:docPartObj>, make sure it's not a child of w:text.
547 2 : assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text/w:docPartGallery", 0);
548 : }
549 4 : }
550 :
551 28 : DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx")
552 : {
553 4 : if (xmlDocPtr pXmlDoc = parseExport())
554 : {
555 : // Single <w:sdt> was exported as 2 <w:sdt> elements.
556 2 : assertXPath(pXmlDoc, "//w:sdt", 1);
557 : }
558 4 : }
559 :
560 28 : DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx")
561 : {
562 4 : if (xmlDocPtr pXmlDoc = parseExport())
563 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[5]/w:instrText", "ADDIN EN.CITE.DATA");
564 4 : }
565 :
566 28 : DECLARE_OOXMLEXPORT_TEST(testEditTime, "fdo81341.docx")
567 : {
568 : /* Issue was LO was not able to Import and Export EditTime in seconds format.
569 : * It was supporting Time in "HH:MM" format. But if DOCX conatins Time in seconds,
570 : * then LO was not able to display time in "HH:MM:SS" format.
571 : * While exporting LO was writing plian text instead of field entry.
572 : */
573 4 : if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
574 : {
575 : //Ensure that EditTime is written inside w:fldChar in "HH:MM:SS" format.
576 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldCharType", "begin");
577 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:fldChar", "fldCharType", "separate");
578 2 : assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[4]/w:t", "00:00:05");
579 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[5]/w:fldChar", "fldCharType", "end");
580 : }
581 4 : }
582 :
583 28 : DECLARE_OOXMLEXPORT_TEST(testFdo81945, "fdo81945.docx")
584 : {
585 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
586 4 : if (!pXmlDoc)
587 6 : return;
588 :
589 2 : assertXPath(pXmlDoc, "//w:sdt//w:sdt", 0);
590 : }
591 :
592 28 : DECLARE_OOXMLEXPORT_TEST(testfdo82123, "fdo82123.docx")
593 : {
594 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
595 4 : if (!pXmlDoc)
596 6 : return;
597 :
598 : // make sure there is only one run inside first SDT after RT as in the Original file.
599 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:p/w:sdt[1]/w:sdtContent/w:r",1);
600 : }
601 :
602 28 : DECLARE_OOXMLEXPORT_TEST(testSdtBeforeField, "sdt-before-field.docx")
603 : {
604 4 : if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
605 : {
606 : // Make sure the field doesn't sneak inside the SDT: the SDT should contain only a single run (there were 6 ones).
607 2 : assertXPath(pXmlDoc, "//w:sdt/w:sdtContent/w:r", 1);
608 : }
609 4 : }
610 :
611 28 : DECLARE_OOXMLEXPORT_TEST(testfdo81946, "fdo81946.docx")
612 : {
613 4 : xmlDocPtr pXmlDoc = parseExport("word/header1.xml");
614 4 : if (!pXmlDoc)
615 6 : return;
616 : // make sure AlternateContent should not present in sdt
617 2 : assertXPath(pXmlDoc, "/w:hdr[1]/w:p[1]/w:sdt[1]/w:sdtContent[1]/w:r[2]/mc:AlternateContent[1]",0);
618 : }
619 :
620 28 : DECLARE_OOXMLEXPORT_TEST(testfdo82492, "fdo82492.docx")
621 : {
622 4 : xmlDocPtr pXmlDoc = parseExport("word/document.xml");
623 4 : if (!pXmlDoc)
624 6 : return;
625 :
626 : // make sure there is only one run inside first SDT after RT as in the Original file.
627 2 : assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt[1]/w:sdtContent/w:r",1);
628 : }
629 :
630 28 : DECLARE_OOXMLEXPORT_TEST(testSdtHeader, "sdt-header.docx")
631 : {
632 : // Problem was that w:sdt elements in headers were lost on import.
633 4 : if (xmlDocPtr pXmlDoc = parseExport("word/header1.xml"))
634 : // This was 0, w:sdt (and then w:date) was missing.
635 2 : assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date", 1);
636 4 : }
637 :
638 28 : DECLARE_OOXMLEXPORT_TEST(testSdtCompanyMultipara, "sdt-company-multipara.docx")
639 : {
640 4 : if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
641 : {
642 : // This was 3, but multiple paragraphs inside "Company" SDT is now allowed.
643 2 : assertXPath(pXmlDoc, "//w:sdtContent/w:p", 1);
644 : }
645 4 : }
646 :
647 8 : CPPUNIT_PLUGIN_IMPLEMENT();
648 :
649 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|