Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / extras / ooxmlexport / ooxmlfieldexport.cxx
blobc0578ad31a164e4fc2abfecfb829e4aaab17ac6f
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>
12 #include <com/sun/star/text/XDocumentIndex.hpp>
13 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
14 #include <com/sun/star/text/XTextField.hpp>
15 #include <com/sun/star/text/XTextTable.hpp>
17 #include <xmloff/odffields.hxx>
18 #include <o3tl/string_view.hxx>
20 #include <IDocumentMarkAccess.hxx>
21 #include <IMark.hxx>
22 #include <docsh.hxx>
23 #include <unotxdoc.hxx>
25 class Test : public SwModelTestBase
27 public:
28 Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {}
31 DECLARE_OOXMLEXPORT_TEST(testFdo47669, "fdo47669.docx")
34 * Problem: we created imbalance </w:hyperlink> which shouldn't be there,
35 * resulting in loading error: missing last character of hyperlink text
36 * and content after it wasn't loaded.
38 getParagraph(1, "This is a hyperlink with anchor. Also, this sentence should be seen.");
39 getRun(getParagraph(1), 2, "hyperlink with anchor");
40 CPPUNIT_ASSERT_EQUAL(OUString("http://www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 2), "HyperLinkURL"));
43 DECLARE_OOXMLEXPORT_TEST(testN789482, "n789482.docx")
45 // The problem was that w:del was exported before w:hyperlink, resulting in an invalid XML.
46 uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
47 getRun(xParagraph, 1, "Before. ");
49 CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 2), "RedlineType"));
50 CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(getRun(xParagraph, 2), "IsStart"));
52 getRun(xParagraph, 3, "www.test.com");
53 CPPUNIT_ASSERT_EQUAL(OUString("http://www.test.com/"), getProperty<OUString>(getRun(xParagraph, 3), "HyperLinkURL"));
55 CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 4), "RedlineType"));
56 CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getRun(xParagraph, 4), "IsStart"));
58 getRun(xParagraph, 5, " After.");
61 CPPUNIT_TEST_FIXTURE(Test, testBnc834035)
63 loadAndReload("bnc834035.odt");
64 CPPUNIT_ASSERT_EQUAL(2, getShapes());
65 CPPUNIT_ASSERT_EQUAL(3, getPages());
66 // Illustration index had wrong hyperlinks: anchor was using Writer's
67 // <seqname>!<index>|sequence syntax, not a bookmark name.
68 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
69 // This was Figure!1|sequence.
70 assertXPath(pXmlDoc, "/w:document/w:body/w:p[10]/w:hyperlink", "anchor", "_Toc363553908");
73 CPPUNIT_TEST_FIXTURE(Test, testCp1000015)
75 loadAndReload("cp1000015.odt");
76 CPPUNIT_ASSERT_EQUAL(1, getPages());
77 // Redline and hyperlink end got exported in an incorrect order.
78 getParagraph(1, "Hello.");
79 getParagraph(2, "http://www.google.com/");
82 CPPUNIT_TEST_FIXTURE(Test, testHyperlineIsEnd)
84 loadAndReload("hyperlink.docx");
85 // Check that the document.xml contents all the tag properly closed.
86 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
87 // If document.xml miss any ending tag then parseExport() returns NULL which fail the test case.
88 CPPUNIT_ASSERT(pXmlDoc) ;
89 // Check hyperlink is properly open.
90 assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:hyperlink",1);
93 CPPUNIT_TEST_FIXTURE(Test, testFdo69649)
95 loadAndReload("fdo69649.docx");
96 // The DOCX containing the Table of Contents was not exported with correct page nos
97 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
99 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[21]/w:hyperlink/w:r[5]/w:t", "15");
102 CPPUNIT_TEST_FIXTURE(Test, testFieldFlagO)
104 loadAndReload("TOC_field_f.docx");
105 // This test case is to verify \o flag should come once.
106 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
108 // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
109 // not to insert an empty paragraph before TOC.
110 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[2]/w:instrText", " TOC \\z \\f \\o \"1-3\" \\u \\h");
113 CPPUNIT_TEST_FIXTURE(Test, testTOCFlag_f)
115 loadAndReload("toc_doc.docx");
116 // Export logic for all TOC field flags was enclosed inside
117 // if( SwTOXElement::Mark & pTOX->GetCreateType() ) in ww8atr.cxx which gets true for \f,
118 // this was the reason if there is \f flag present in original doc then only other flags like
119 // \o \h \n used to come after RoundTrip.
120 // This test case is to verify even if there is no \f flag in original doc, \h flag is getting
121 // preserved after RT.
122 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
124 // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
125 // not to insert an empty paragraph before TOC.
126 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[2]/w:instrText", " TOC \\z \\o \"1-3\" \\u \\h");
129 CPPUNIT_TEST_FIXTURE(Test, testPreserveZfield)
131 loadAndReload("preserve_Z_field_TOC.docx");
132 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
134 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");
137 CPPUNIT_TEST_FIXTURE(Test, testPreserveWfieldTOC)
139 loadAndReload("PreserveWfieldTOC.docx");
140 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
142 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");
145 CPPUNIT_TEST_FIXTURE(Test, testFieldFlagB)
147 loadAndReload("TOC_field_b.docx");
148 // This test case is to verify \b flag.
149 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
151 // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
152 // not to insert an empty paragraph before TOC.
153 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[2]/w:instrText", " TOC \\b \"bookmark111\" \\o \"1-9\" \\h");
156 CPPUNIT_TEST_FIXTURE(Test, testPreserveXfieldTOC)
158 loadAndReload("PreserveXfieldTOC.docx");
159 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
161 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\x \\f \\o \"1-3\" \\h");
164 CPPUNIT_TEST_FIXTURE(Test, testFDO77715)
166 loadAndReload("FDO77715.docx");
167 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
169 // tdf#153090 check that para style is preserved
170 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText[1]", " TOC \\c \\h \\t \"Block Header\" ");
172 uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY);
173 uno::Reference<container::XIndexAccess> xIndexes = xIndexSupplier->getDocumentIndexes();
174 uno::Reference<text::XDocumentIndex> xTOC(xIndexes->getByIndex(0), uno::UNO_QUERY);
175 CPPUNIT_ASSERT_EQUAL(OUString("Block Header"), getProperty<OUString>(xTOC, "CreateFromParagraphStyle"));
176 // tdf#153090 check that update uses the style
177 xTOC->update();
178 OUString const tocContent(xTOC->getAnchor()->getString());
179 CPPUNIT_ASSERT(tocContent.startsWith("National Infrastructure Bank Aff/Neg Index"));
182 CPPUNIT_TEST_FIXTURE(Test, testTOCFlag_u)
184 loadAndReload("testTOCFlag_u.docx");
185 // DOCX containing TOC should preserve code field '\u'.
186 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
188 // FIXME "p[2]" will have to be "p[1]", once the TOC import code is fixed
189 // not to insert an empty paragraph before TOC.
190 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " TOC \\z \\o \"1-9\" \\u \\h");
193 CPPUNIT_TEST_FIXTURE(Test, testfdo73596_RunInStyle)
195 loadAndReload("fdo73596_RunInStyle.docx");
196 // INDEX should be preserved.
197 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
199 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText[1]", " INDEX \\e \"");
202 CPPUNIT_TEST_FIXTURE(Test, testfdo73596_AlphaSeparator)
204 loadAndReload("fdo73596_AlphaSeparator.docx");
205 // INDEX flag \h "A" should be preserved.
206 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
208 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText[1]", " INDEX \\h \"A\" \\e \"");
211 CPPUNIT_TEST_FIXTURE(Test, testCaption1)
213 loadAndReload("EquationAsScientificNumbering.docx");
214 // fdo#74431 : This test case is to verify the Captions are coming properly
215 // earlier it was coming as "SEQ "scientific"\*ROMAN now it is SEQ scientific\* ROMAN"
217 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
219 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:instrText", " SEQ scientific \\* ROMAN ");
222 CPPUNIT_TEST_FIXTURE(Test, testCaption2)
224 loadAndReload("EquationWithAboveAndBelowCaption.docx");
225 // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
226 // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
227 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
229 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[5]/w:r[3]/w:instrText", " SEQ Equation \\* ARABIC ");
232 CPPUNIT_TEST_FIXTURE(Test, testCaption3)
234 loadAndReload("FigureAsLabelPicture.docx");
235 // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
236 // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
237 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
239 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[3]/w:instrText", " SEQ picture \\* ARABIC ");
242 CPPUNIT_TEST_FIXTURE(Test, testCaption4)
244 loadAndReload("TableWithAboveCaptions.docx");
245 // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
246 // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
247 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
249 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:instrText", " SEQ Table \\* ARABIC ");
252 CPPUNIT_TEST_FIXTURE(Test, testFooterContainHyperlink)
254 loadAndReload("footer-contain-hyperlink.docx");
255 // Problem is that footer1.xml.rels contains the empty
256 // Target due to which the file get corrupted
257 // in MS Office 2007.
258 // Check for footer1.xml.rels file.
259 xmlDocUniquePtr pXmlRels = parseExport("word/_rels/footer1.xml.rels");
260 // Check the value of Target which is http://www.google.com/.
261 assertXPath(pXmlRels,"/rels:Relationships/rels:Relationship","Target","http://www.google.com/");
264 CPPUNIT_TEST_FIXTURE(Test, testAlphabeticalIndex_MultipleColumns)
266 loadAndReload("alphabeticalIndex_MultipleColumns.docx");
267 // Bug :: fdo#73596
269 * Index with multiple columns was not imported correctly and
270 * hence not exported correctly...
271 * The column count is given by the \c switch.
272 * If the column count is explicitly specified,
273 * MS Office adds section breaks before and after the Index.
275 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
277 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText", " INDEX \\c \"4\"\\e \"");
279 // check for section breaks after and before the Index Section
280 assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:sectPr/w:type","val","continuous");
281 assertXPath(pXmlDoc, "/w:document/w:body/w:p[8]/w:pPr/w:sectPr/w:type","val","continuous");
282 // check for "w:space" attribute for the columns in Section Properties
283 assertXPath(pXmlDoc, "/w:document/w:body/w:p[8]/w:pPr/w:sectPr/w:cols","space","720");
286 CPPUNIT_TEST_FIXTURE(Test, testPageref)
288 loadAndReload("testPageref.docx");
289 // fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
290 // This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
291 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
293 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:hyperlink/w:r[3]/w:instrText", "PAGEREF _Toc355095261 \\h");
296 CPPUNIT_TEST_FIXTURE(Test, testAlphabeticalIndex_AutoColumn)
298 loadAndReload("alphabeticalIndex_AutoColumn.docx");
299 // Bug :: fdo#73596
301 * When the columns in Index are 0; i.e not specified by the
302 * "\c" switch, don't write back '\c "0"' or the section breaks
303 * before and after the Index Context
305 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
307 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText", " INDEX \\e \"");
309 // check for section break doesn't appear for any paragraph
310 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:sectPr", 0);
313 CPPUNIT_TEST_FIXTURE(Test, testIndexFieldFlagF)
315 loadAndReload("IndexFieldFlagF.docx");
316 // This test case is to verify the Index field flag '\f' with some
317 // Specific Entry Type (ex. "Syn" in our case).
318 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
319 // We check the Index field flag '\f'.
320 // Note: no syntax error any more (extra quotation mark between "Syn" and \e)
321 assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[4]/w:r[2]/w:instrText[1]", " INDEX \\c \"2\"\\f \"Syn\"\\e \"");
322 // XE entries lost their \f "Syn" before
323 assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[17]/w:r[21]/w:instrText[1]", " XE \"formatting\" \\f \"Syn\" ");
324 assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[17]/w:r[29]/w:instrText[1]", " XE \"choosing:aaaa\" \\f \"Syn\" ");
327 CPPUNIT_TEST_FIXTURE(Test, testBibliography)
329 loadAndReload("FDO75133.docx");
330 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
332 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r[2]/w:instrText", " BIBLIOGRAPHY ");
333 assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartGallery", "val", "Bibliographies");
334 assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartUnique", 1);
337 CPPUNIT_TEST_FIXTURE(Test, testGenericTextField)
339 loadAndReload("Unsupportedtextfields.docx");
340 // fdo#75158 : This test case is to verify the unsupported textfields are exported properly.
342 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
343 xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:r[2]/w:instrText");
344 xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
345 xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
346 OUString contents = OUString::createFromAscii(reinterpret_cast<char*>((pXmlNode->children[0]).content));
347 CPPUNIT_ASSERT(contents.match(" PRINTDATE "));
348 xmlXPathFreeObject(pXmlObj);
351 CPPUNIT_TEST_FIXTURE(Test, test_FieldType)
353 loadAndReload("99_Fields.docx");
354 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
355 // Checking for three field types (BIBLIOGRAPHY, BIDIOUTLINE, CITATION) in sequence
356 assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:instrText");
357 assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:instrText");
358 assertXPath(pXmlDoc, "/w:document/w:body/w:p[4]/w:sdt/w:sdtContent/w:r[2]/w:instrText");
361 CPPUNIT_TEST_FIXTURE(Test, testCitation)
363 loadAndReload("FDO74775.docx");
364 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
365 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:sdt/w:sdtContent/w:r[2]/w:instrText", " CITATION Kra06 \\l 1033 ");
366 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:sdt/w:sdtContent/w:r[4]/w:t", "(Kramer & Chen, 2006)");
369 CPPUNIT_TEST_FIXTURE(Test, testHyperLinkTagEnded)
371 loadAndReload("fdo76316.docx");
372 /* XML tag <w:hyperlink> was not getting closed when its inside another
373 * <w:hyperlink> tag.
375 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
377 CPPUNIT_ASSERT(pXmlDoc);
378 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);
381 CPPUNIT_TEST_FIXTURE(Test, testFDO76163 )
383 loadAndReload("fdo76163.docx");
384 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
385 //docx file after RT is getting corrupted.
386 assertXPath ( pXmlDoc, "/w:document/w:body/w:p[2]/w:hyperlink/w:r[10]/w:fldChar", "fldCharType", "end" );
389 CPPUNIT_TEST_FIXTURE(Test, testFDO78659)
391 loadAndReload("fdo78659.docx");
392 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
394 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);
397 CPPUNIT_TEST_FIXTURE(Test, testFDO78654 )
399 loadAndReload("fdo78654.docx");
400 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
401 // In case of two "Hyperlink" tags in one paragraph and one of them
402 // contains "PAGEREF" field then field end tag was missing from hyperlink.
403 assertXPath ( pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:hyperlink[3]/w:r[5]/w:fldChar", "fldCharType", "end" );
407 CPPUNIT_TEST_FIXTURE(Test, testfdo78599)
409 loadAndReload("fdo78599.docx");
410 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
411 //docx file after RT is getting corrupted.
412 assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:fldChar", "fldCharType", "end" );
414 // Check for automatic hyphenation
415 xmlDocUniquePtr pSettingsXml = parseExport("word/settings.xml");
416 // This failed as w:settings had no w:autoHyphenation child.
417 assertXPath(pSettingsXml, "/w:settings/w:autoHyphenation");
420 CPPUNIT_TEST_FIXTURE(Test, testfdo78886)
422 loadAndReload("fdo78886.docx");
423 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
425 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);
428 CPPUNIT_TEST_FIXTURE(Test, testFdo78910)
430 loadAndReload("fdo78910.docx");
431 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
433 // This is to ensure that the fld starts and ends inside a hyperlink...
434 assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[1]/w:fldChar", "fldCharType", "begin" );
435 assertXPath ( pXmlDoc, "//w:hyperlink[2]/w:r[5]/w:fldChar", "fldCharType", "end" );
438 // FIXME: During this test a pure VML shape get converted to DML and crash at verifying.
439 // CPPUNIT_TEST_FIXTURE(Test, testFDO78590)
440 // {
441 // loadAndReload("FDO78590.docx");
442 // xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
444 // // This is to ensure that the fld starts and ends inside a hyperlink...
445 // assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "w", "9851" );
446 // assertXPath ( pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "h", "1669" );
447 // }
449 CPPUNIT_TEST_FIXTURE(Test, testSdtCitationRun)
451 loadAndReload("sdt-citation-run.docx");
452 // The problem was that the SDT was around the whole paragraph, not only around the citation field.
453 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
454 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:t", "Before sdt.");
455 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:instrText", " CITATION BBC11 \\l 1033 ");
456 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:t", "After sdt.");
459 CPPUNIT_TEST_FIXTURE(Test, testParagraphSdt)
461 loadAndReload("paragraph-sdt.docx");
462 // The problem was that the SDT was around the run only, not the whole paragraph.
463 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
464 // The path to w:sdt contained a w:p.
465 assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p/w:sdt");
468 CPPUNIT_TEST_FIXTURE(Test, testSdt2Run)
470 loadAndReload("sdt-2-para.docx");
471 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
472 // The problem was that <w:sdt> was closed after "first", not after "second", so the second assert failed.
473 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r/w:t", "first");
474 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r/w:t", "second");
475 // Make sure the third paragraph is still outside <w:sdt>.
476 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r/w:t", "third");
479 CPPUNIT_TEST_FIXTURE(Test, test2Id)
481 loadAndReload("2-id.docx");
482 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
483 // This was 2, but only one w:id is allowed.
484 assertXPath(pXmlDoc, "//w:sdtPr/w:id", 1);
487 CPPUNIT_TEST_FIXTURE(Test, testTableStart2Sdt)
489 loadAndReload("table-start-2-sdt.docx");
490 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
491 // w:docPartGallery should be a child of <w:docPartObj>, make sure it's not a child of w:text.
492 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text/w:docPartGallery", 0);
495 DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx")
497 if (isExported())
499 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
500 // Single <w:sdt> was exported as 2 <w:sdt> elements.
501 assertXPath(pXmlDoc, "//w:sdt", 1);
502 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
503 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
504 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
505 uno::Reference<table::XCell> xCell = xTable->getCellByName("A1");
506 uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY);
507 uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration();
508 uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(),
509 uno::UNO_QUERY);
510 uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration();
511 uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY);
512 OUString aPortionType;
513 xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType;
514 CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType);
515 uno::Reference<text::XTextContent> xContentControl;
516 xTextPortion->getPropertyValue("ContentControl") >>= xContentControl;
517 uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
518 bool bDate{};
519 xContentControlProps->getPropertyValue("Date") >>= bDate;
520 CPPUNIT_ASSERT(bDate);
521 uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY);
522 uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration();
523 uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY);
524 CPPUNIT_ASSERT_EQUAL(OUString("4/26/2012"), xTextPortionRange->getString());
526 else
528 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
529 CPPUNIT_ASSERT(pTextDoc);
530 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
531 IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
532 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount());
534 ::sw::mark::IDateFieldmark* pFieldmark
535 = dynamic_cast<::sw::mark::IDateFieldmark*>(*pMarkAccess->getAllMarksBegin());
536 CPPUNIT_ASSERT(pFieldmark);
537 CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
538 CPPUNIT_ASSERT_EQUAL(OUString("4/26/2012"), pFieldmark->GetContent());
542 CPPUNIT_TEST_FIXTURE(Test, testFdo81492)
544 loadAndReload("fdo81492.docx");
545 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
546 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[6]/w:instrText", "ADDIN EN.CITE.DATA");
549 CPPUNIT_TEST_FIXTURE(Test, testEditTime)
551 loadAndReload("fdo81341.docx");
552 /* Issue was LO was not able to Import and Export EditTime in seconds format.
553 * It was supporting Time in "HH:MM" format. But if DOCX contains Time in seconds,
554 * then LO was not able to display time in "HH:MM:SS" format.
555 * While exporting LO was writing plain text instead of field entry.
557 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
558 //Ensure that EditTime is written inside w:fldChar in "HH:MM:SS" format.
559 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldCharType", "begin");
560 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[3]/w:fldChar", "fldCharType", "separate");
561 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[4]/w:t", "00:05");
562 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[5]/w:fldChar", "fldCharType", "end");
565 CPPUNIT_TEST_FIXTURE(Test, testFlyFieldmark)
567 loadAndReload("fly_fieldmark.fodt");
568 // the problem was that the flys were written after the field start
569 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
570 // run 1 contains 2 shapes, one was at-page, one was at-char
571 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/mc:AlternateContent", 2);
572 // run 2 contains the field start
573 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[2]/w:fldChar", "fldCharType", "begin");
574 // run 3 contains the field instruction text
575 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:instrText", " FORMTEXT ");
578 CPPUNIT_TEST_FIXTURE(Test, testFdo81945)
580 loadAndReload("fdo81945.docx");
581 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
583 assertXPath(pXmlDoc, "//w:sdt//w:sdt", 0);
586 CPPUNIT_TEST_FIXTURE(Test, testfdo82123)
588 loadAndReload("fdo82123.docx");
589 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
591 // make sure there is only one run inside first SDT after RT as in the Original file.
592 assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:p/w:sdt[1]/w:sdtContent/w:r/w:t", 1);
593 assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:p/w:r/w:drawing", 1);
596 CPPUNIT_TEST_FIXTURE(Test, testSdtBeforeField)
598 loadAndReload("sdt-before-field.docx");
599 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
600 // Make sure the field doesn't sneak inside the SDT: the SDT should contain only a single run (there were 6 ones).
601 assertXPath(pXmlDoc, "//w:p/w:sdt/w:sdtContent/w:r/w:t", 1);
602 assertXPath(pXmlDoc, "//w:p/w:r/w:fldChar", 3);
605 CPPUNIT_TEST_FIXTURE(Test, testfdo81946)
607 loadAndReload("fdo81946.docx");
608 xmlDocUniquePtr pXmlDoc = parseExport("word/header1.xml");
609 // make sure AlternateContent should not present in sdt
610 assertXPath(pXmlDoc, "/w:hdr[1]/w:p[1]/w:sdt[1]/w:sdtContent[1]/w:r[2]/mc:AlternateContent[1]",0);
613 CPPUNIT_TEST_FIXTURE(Test, testfdo82492)
615 loadAndReload("fdo82492.docx");
616 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
618 // make sure there is only one run inside first SDT after RT as in the Original file.
619 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt[1]/w:sdtContent/w:r/w:t", 1);
620 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent", 1);
623 CPPUNIT_TEST_FIXTURE(Test, testSdtHeader)
625 loadAndReload("sdt-header.docx");
626 // Problem was that w:sdt elements in headers were lost on import.
627 xmlDocUniquePtr pXmlDoc = parseExport("word/header2.xml");
628 // This was 0, w:sdt (and then w:date) was missing.
629 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date", 1);
632 CPPUNIT_TEST_FIXTURE(Test, testSdtCompanyMultipara)
634 loadAndReload("sdt-company-multipara.docx");
635 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
636 // Here is just a simple text node, so there should be either one or zero paragraph
637 // (in this case sdt element is inside paragraph)
638 assertXPath(pXmlDoc, "//w:sdtContent/w:p", 0);
639 assertXPath(pXmlDoc, "//w:sdtContent/w:r", 1);
642 DECLARE_OOXMLEXPORT_TEST(testFixedDateFields, "fixed-date-field.docx")
644 uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
645 uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
646 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
647 uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY);
649 // Check fixed property was imported and date value was parsed correctly
650 CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, "IsFixed"));
651 css::util::DateTime date = getProperty<css::util::DateTime>(xField, "DateTimeValue");
652 CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), date.Day);
653 CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), date.Month);
654 CPPUNIT_ASSERT_EQUAL(sal_Int16(2014), date.Year);
656 if (isExported())
658 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
659 // Previously, fixed fields were exported as static text ("Date (fixed)")
660 // Check they are now exported correctly as fldChar with fldLock attribute
661 assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldLock", "true");
665 CPPUNIT_TEST_FIXTURE(Test, testToxmarkHyperlink)
667 loadAndReload("toxmarkhyperlink.fodt");
668 // test that export doesn't assert with overlapping fields / hyperlink attr
671 CPPUNIT_TEST_FIXTURE(Test, testOO34469)
673 loadAndReload("ooo34469-1.odt");
674 CPPUNIT_ASSERT_EQUAL(1, getPages());
675 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
676 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink[1]", "anchor", "2.9.2.Creating_New_files|outline");
679 CPPUNIT_TEST_FIXTURE(Test, testOO39845)
681 loadAndReload("ooo39845-7.odt");
682 CPPUNIT_ASSERT_EQUAL(1, getPages());
683 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
684 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink[1]", "anchor", "Figure4|graphic");
687 DECLARE_OOXMLEXPORT_TEST( testTdf85161, "tdf85161.docx" )
689 CPPUNIT_ASSERT_EQUAL(OUString("Symbol"), getProperty<OUString>(getRun(getParagraph(1), 1), "CharFontName"));
690 CPPUNIT_ASSERT_EQUAL(OUString(u'\x5e'),getParagraph(1)->getString());
693 CPPUNIT_TEST_FIXTURE(Test, testTdf66401)
695 loadAndReload("tdf66401.docx");
696 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
697 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:rPr/w:rFonts", 1);
698 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:rPr/w:rFonts", "ascii", "Arial Black");
699 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[3]/w:rPr/w:sz", "val", "24");
700 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[9]/w:rPr/w:rFonts", 1);
701 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[9]/w:rPr/w:rFonts", "ascii", "Arial Black");
702 assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[9]/w:rPr/w:sz", "val", "24");
705 DECLARE_OOXMLEXPORT_TEST( testDateFieldInShape, "date_field_in_shape.docx" )
707 // This was crashed on export.
708 if (isExported())
710 uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY);
711 uno::Reference<text::XText> xShapeText = xShape->getText();
712 uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraphOfText(1, xShapeText), 1), uno::UNO_QUERY);
713 OUString aPortionType;
714 xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType;
715 CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType);
716 uno::Reference<text::XTextContent> xContentControl;
717 xTextPortion->getPropertyValue("ContentControl") >>= xContentControl;
718 uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
719 bool bDate{};
720 xContentControlProps->getPropertyValue("Date") >>= bDate;
721 CPPUNIT_ASSERT(bDate);
722 uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY);
723 uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration();
724 uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY);
725 CPPUNIT_ASSERT_EQUAL(OUString("Click here to enter a date."), xTextPortionRange->getString());
727 else
729 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
730 CPPUNIT_ASSERT(pTextDoc);
731 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
732 IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
733 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount());
735 ::sw::mark::IDateFieldmark* pFieldmark
736 = dynamic_cast<::sw::mark::IDateFieldmark*>(*pMarkAccess->getAllMarksBegin());
737 CPPUNIT_ASSERT(pFieldmark);
738 CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
739 CPPUNIT_ASSERT_EQUAL(OUString("Click here to enter a date."), pFieldmark->GetContent());
743 DECLARE_OOXMLEXPORT_TEST( testDateFieldAtEndOfParagraph, "date_field_at_end_of_paragraph.docx" )
745 // Additional line end was added by import and it was crashed on export
746 if (isExported())
748 uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraph(2), 1), uno::UNO_QUERY);
749 OUString aPortionType;
750 xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType;
751 CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType);
752 uno::Reference<text::XTextContent> xContentControl;
753 xTextPortion->getPropertyValue("ContentControl") >>= xContentControl;
754 uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
755 bool bDate{};
756 xContentControlProps->getPropertyValue("Date") >>= bDate;
757 CPPUNIT_ASSERT(bDate);
758 uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY);
759 uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration();
760 uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY);
761 CPPUNIT_ASSERT_EQUAL(OUString("Click here to enter a date."), xTextPortionRange->getString());
763 else
765 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
766 CPPUNIT_ASSERT(pTextDoc);
767 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
768 IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
769 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount());
771 ::sw::mark::IDateFieldmark* pFieldmark
772 = dynamic_cast<::sw::mark::IDateFieldmark*>(*pMarkAccess->getAllMarksBegin());
773 CPPUNIT_ASSERT(pFieldmark);
774 CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
775 CPPUNIT_ASSERT_EQUAL(OUString("Click here to enter a date."), pFieldmark->GetContent());
779 CPPUNIT_TEST_FIXTURE(Test, testDropDownFieldEntryLimit)
781 loadAndReload("tdf126792.odt" );
782 CPPUNIT_ASSERT_EQUAL(1, getPages());
783 // In MSO, there is a limit of 25 for the items in a drop-down form field.
784 // So we truncate the list of items to not exceed this limit.
786 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
787 CPPUNIT_ASSERT(pTextDoc);
788 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
789 IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
790 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
792 ::sw::mark::IFieldmark* pFieldmark
793 = dynamic_cast<::sw::mark::IFieldmark*>(*pMarkAccess->getAllMarksBegin());
794 CPPUNIT_ASSERT(pFieldmark);
795 CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDROPDOWN), pFieldmark->GetFieldname());
797 const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
798 auto pListEntries = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
799 CPPUNIT_ASSERT(bool(pListEntries != pParameters->end()));
800 css::uno::Sequence<OUString> vListEntries;
801 pListEntries->second >>= vListEntries;
802 if (!isExported())
803 CPPUNIT_ASSERT_EQUAL(sal_Int32(26), vListEntries.getLength());
804 else
805 CPPUNIT_ASSERT_EQUAL(sal_Int32(25), vListEntries.getLength());
808 CPPUNIT_TEST_FIXTURE(Test, testTdf132185)
810 loadAndReload("tdf132185.docx");
811 xmlDocUniquePtr pXmlDoc = parseExport("word/footer1.xml");
812 // Since the default (without xml:space attribute) is to ignore leading and trailing spaces,
813 // " PAGE \\* roman " will get imported as "PAGE \\* roman". This is also valid, and must be
814 // treated accordingly. "roman" was ignored before the fix, exporting only " PAGE ".
815 assertXPathContent(pXmlDoc, "/w:ftr/w:p/w:r[2]/w:instrText", " PAGE \\* roman ");
818 CPPUNIT_TEST_FIXTURE(Test, testConditionalText)
820 loadAndReload("conditional-text.fodt");
821 // Load a document which has a conditional text field in it.
822 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
823 std::u16string_view aExpected(u" IF 1 < 2 \"True\" \"- 'False' -\"");
825 // Without the accompanying fix in place, this test would have failed with:
826 // - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0
827 // - In <...>, XPath '/w:document/w:body/w:p/w:r[2]/w:instrText' not found
828 // i.e. the field was lost on export.
829 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText", OUString(aExpected));
832 CPPUNIT_TEST_FIXTURE(Test, testConditionalText2)
834 loadAndReload("tdf114537_conditional-text2.doc");
835 // Load a document which has a conditional text field in it.
836 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
837 std::u16string_view aExpected(u" IF 1 = 1 \"test1\" \"test2\"");
838 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText", OUString(aExpected));
840 getParagraph(1, "test1");
843 CPPUNIT_TEST_FIXTURE(Test, testConditionalText3)
845 loadAndReload("tdf125038_conditionalText3.docx");
846 // It is unclear what the purpose of all the conditional IF statements is,
847 // but the end result should not produce any output.
848 // Previously, the fields were being displayed as text
849 // instead of as building blocks for the IF field condition.
850 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getParagraph(1)->getString().indexOf('2'));
853 DECLARE_OOXMLEXPORT_TEST(testTdf142464_ampm, "tdf142464_ampm.docx")
855 css::uno::Reference<css::text::XTextFieldsSupplier> xTextFieldsSupplier(
856 mxComponent, css::uno::UNO_QUERY_THROW);
857 auto xFieldsAccess(xTextFieldsSupplier->getTextFields());
858 auto xFields(xFieldsAccess->createEnumeration());
859 css::uno::Reference<css::text::XTextField> xField(xFields->nextElement(),
860 css::uno::UNO_QUERY_THROW);
862 // Without the fix in place, this would have failed with:
863 // - Expected: 12:32 PM
864 // - Actual : 12:32 a12/p12
865 CPPUNIT_ASSERT_EQUAL(OUString("12:32 PM"), xField->getPresentation(false));
867 if (isExported())
869 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
870 // Without the fix in place, this would have failed with:
871 // - Expected: DATE \@"H:mm\ AM/PM"
872 // - Actual : DATE \@"H:mm' a'M'/p'M"
873 // i.e., the AM/PM would be treated as literal 'a' and 'p' followed by a month code
874 assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText",
875 " DATE \\@\"H:mm\\ AM/PM\" ");
879 DECLARE_OOXMLEXPORT_TEST( testSdtDatePicker, "test_sdt_datepicker.docx" )
881 // Check that roundtrip for date picker field does not lose essential data
882 if (!isExported())
883 return; // initial import, no further checks
884 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
886 // Placeholder is here
887 OUString sDocPart = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:placeholder/w:docPart", "val");
888 CPPUNIT_ASSERT_EQUAL(OUString("DefaultPlaceholder_-1854013437"), sDocPart);
890 // Ensure that we have data binding stuff
891 OUString sDBprefix = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "prefixMappings");
892 CPPUNIT_ASSERT_EQUAL(OUString("xmlns:ns0='http://schemas.microsoft.com/vsto/samples' "), sDBprefix);
894 OUString sDBxpath = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "xpath");
895 CPPUNIT_ASSERT_EQUAL(OUString("/ns0:employees[1]/ns0:employee[1]/ns0:hireDate[1]"), sDBxpath);
897 OUString sDBstoreid = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "storeItemID");
898 CPPUNIT_ASSERT_EQUAL(OUString("{241A8A02-7FFD-488D-8827-63FBE74E8BC9}"), sDBstoreid);
900 OUString sColor = getXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w15:color", "val");
901 CPPUNIT_ASSERT_EQUAL(OUString("008000"), sColor);
904 CPPUNIT_TEST_FIXTURE(Test, testContentControlGrabBag)
906 // Given a document with a <w:sdt> tag:
907 createSwDoc("content-control-grab-bag.docx");
909 // When exporting that document back to DOCX:
910 // Then make sure that completes without an assertion failure, which would mean not-well-formed
911 // output was produced:
912 save("Office Open XML Text");
915 CPPUNIT_TEST_FIXTURE(Test, testContentControlShape)
917 // Given a document with a <w:sdt> tag:
918 createSwDoc("content-control-shape.docx");
920 // When exporting that document back to DOCX:
921 // Then make sure that completes without an assertion failure, which would mean not-well-formed
922 // output was produced, since the <w:sdt> was conditional but the </w:sdt> was unconditional:
923 save("Office Open XML Text");
926 CPPUNIT_TEST_FIXTURE(Test, testTdf104823)
928 // Test how we can roundtrip sdt plain text with databindings support
929 createSwDoc("tdf104823.docx");
931 // First paragraph: content from core properties
932 uno::Reference<text::XTextRange> xParagraph1 = getParagraph(1);
933 auto xContentControl1 = getProperty<uno::Reference<text::XText>>(getRun(xParagraph1, 2), "ContentControl");
934 // Check field value (it should be value from data source) and set new
935 CPPUNIT_ASSERT_EQUAL(OUString("True Core Property Value"), xContentControl1->getString());
936 xContentControl1->setString("New Core Property Value");
938 // Third paragraph: content from custom properties
939 uno::Reference<text::XTextRange> xParagraph3 = getParagraph(3);
940 auto xContentControl3 = getProperty<uno::Reference<text::XText>>(getRun(xParagraph3, 2), "ContentControl");
941 // Check field value (it should be value from data source) and set new
942 CPPUNIT_ASSERT_EQUAL(OUString("True Custom XML Value"), xContentControl3->getString());
943 xContentControl3->setString("New Custom XML Value");
945 // Second paragraph: content from extended properties
946 uno::Reference<text::XTextRange> xParagraph2 = getParagraph(2);
947 auto xContentControl2 = getProperty<uno::Reference<text::XText>>(getRun(xParagraph2, 2), "ContentControl");
948 // Check field value (it should be value from data source) and set new
949 CPPUNIT_ASSERT_EQUAL(OUString("True Extended Property Value"), xContentControl2->getString());
950 xContentControl2->setString("New Extended Property Value");
952 // Save and check saved data
953 save("Office Open XML Text");
954 xmlDocUniquePtr pXmlCustomPropsDoc = parseExport("customXml/item1.xml");
955 CPPUNIT_ASSERT(pXmlCustomPropsDoc);
956 // FIXME: strange it won't run simple /employees/employee/name xpath query. Does not like namespaces?
957 assertXPathContent(pXmlCustomPropsDoc, "//*/*[local-name()='name']", "New Custom XML Value");
959 xmlDocUniquePtr pXmlAppPropsDoc = parseExport("docProps/app.xml");
960 CPPUNIT_ASSERT(pXmlAppPropsDoc);
961 // TODO: extended properties are not written yet
962 assertXPathContent(pXmlAppPropsDoc, "//*/*[local-name()='Company']", "True Extended Property Value");
964 xmlDocUniquePtr pXmlCorePropsDoc = parseExport("docProps/core.xml");
965 CPPUNIT_ASSERT(pXmlCorePropsDoc);
966 // TODO: core properties are not written yet
967 assertXPathContent(pXmlCorePropsDoc, "/cp:coreProperties/dc:creator", "True Core Property Value");
970 CPPUNIT_PLUGIN_IMPLEMENT();
972 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */