1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <swmodeltestbase.hxx>
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>
55 class Test
: public SwModelTestBase
58 Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {}
64 bool mustTestImportOf(const char* filename
) const SAL_OVERRIDE
{
65 const char* aBlacklist
[] = {
69 "test_GIF_ImageCrop.docx",
70 "test_PNG_ImageCrop.docx"
72 std::vector
<const char*> vBlacklist(aBlacklist
, aBlacklist
+ SAL_N_ELEMENTS(aBlacklist
));
74 // If the testcase is stored in some other format, it's pointless to test.
75 return (OString(filename
).endsWith(".docx") && std::find(vBlacklist
.begin(), vBlacklist
.end(), filename
) == vBlacklist
.end());
79 DECLARE_OOXMLEXPORT_TEST(testRelorientation
, "relorientation.docx")
81 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
82 // This was text::RelOrientation::FRAME, when handling relativeFrom=page, align=right
83 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_RIGHT
, getProperty
<sal_Int16
>(xShape
, "HoriOrientRelation"));
85 uno::Reference
<drawing::XShapes
> xGroup(xShape
, uno::UNO_QUERY
);
86 // This resulted in lang::IndexOutOfBoundsException, as nested groupshapes weren't handled.
87 uno::Reference
<drawing::XShapeDescriptor
> xShapeDescriptor(xGroup
->getByIndex(0), uno::UNO_QUERY
);
88 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GroupShape"), xShapeDescriptor
->getShapeType());
90 // Right after import we get a rounding error: 8662 vs 8664.
93 uno::Reference
<drawing::XShape
> xYear(xGroup
->getByIndex(1), uno::UNO_QUERY
);
94 // This was 2, due to incorrect handling of parent transformations inside DML groupshapes.
95 CPPUNIT_ASSERT_EQUAL(sal_Int32(8664), xYear
->getSize().Width
);
99 DECLARE_OOXMLEXPORT_TEST(testBezier
, "bezier.odt")
101 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
102 uno::Reference
<container::XIndexAccess
> xDraws(xDrawPageSupplier
->getDrawPage(), uno::UNO_QUERY
);
103 // Check that no shape got lost: a bezier, a line and a text shape.
104 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDraws
->getCount());
107 DECLARE_OOXMLEXPORT_TEST(testGroupshapeTextbox
, "groupshape-textbox.docx")
109 uno::Reference
<drawing::XShapes
> xGroup(getShape(1), uno::UNO_QUERY
);
110 uno::Reference
<text::XTextRange
> xShape(xGroup
->getByIndex(0), uno::UNO_QUERY
);
111 // The VML export lost text on textboxes inside groupshapes.
112 // The DML export does not, make sure it stays that way.
113 CPPUNIT_ASSERT_EQUAL(OUString("first"), xShape
->getString());
114 // This was 16, i.e. inheriting doc default char height didn't work.
115 CPPUNIT_ASSERT_EQUAL(11.f
, getProperty
<float>(xShape
, "CharHeight"));
118 DECLARE_OOXMLEXPORT_TEST(testGroupshapePicture
, "groupshape-picture.docx")
120 // Picture in the groupshape got lost, groupshape had only one child.
121 uno::Reference
<drawing::XShapes
> xGroup(getShape(1), uno::UNO_QUERY
);
122 uno::Reference
<drawing::XShapeDescriptor
> xShapeDescriptor(xGroup
->getByIndex(1), uno::UNO_QUERY
);
123 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GraphicObjectShape"), xShapeDescriptor
->getShapeType());
126 DECLARE_OOXMLEXPORT_TEST(testAutofit
, "autofit.docx")
128 CPPUNIT_ASSERT_EQUAL(true, bool(getProperty
<sal_Bool
>(getShape(1), "TextAutoGrowHeight")));
129 CPPUNIT_ASSERT_EQUAL(false, bool(getProperty
<sal_Bool
>(getShape(2), "TextAutoGrowHeight")));
132 DECLARE_OOXMLEXPORT_TEST(testTrackChangesDeletedParagraphMark
, "testTrackChangesDeletedParagraphMark.docx")
134 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
137 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:del");
140 DECLARE_OOXMLEXPORT_TEST(testTrackChangesInsertedParagraphMark
, "testTrackChangesInsertedParagraphMark.docx")
142 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
145 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:ins");
148 DECLARE_OOXMLEXPORT_TEST(testTrackChangesDeletedTableRow
, "testTrackChangesDeletedTableRow.docx")
150 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
153 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[2]/w:trPr/w:del");
156 DECLARE_OOXMLEXPORT_TEST(testTrackChangesInsertedTableRow
, "testTrackChangesInsertedTableRow.docx")
158 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
161 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[2]/w:trPr/w:ins");
164 DECLARE_OOXMLEXPORT_TEST(testTrackChangesDeletedTableCell
, "testTrackChangesDeletedTableCell.docx")
166 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
169 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[3]/w:tc/w:tcPr/w:cellDel");
172 DECLARE_OOXMLEXPORT_TEST(testTrackChangesInsertedTableCell
, "testTrackChangesInsertedTableCell.docx")
174 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
177 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[3]/w:tc/w:tcPr/w:cellIns");
180 DECLARE_OOXMLEXPORT_TEST(testTextBoxPictureFill
, "textbox_picturefill.docx")
182 uno::Reference
<beans::XPropertySet
> xFrame(getShape(1), uno::UNO_QUERY
);
183 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP
, getProperty
<drawing::FillStyle
>(xFrame
, "FillStyle"));
184 CPPUNIT_ASSERT(!(getProperty
<OUString
>(xFrame
,"FillBitmapURL")).isEmpty());
187 DECLARE_OOXMLEXPORT_TEST(testFDO73034
, "FDO73034.docx")
189 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
192 CPPUNIT_ASSERT(getXPath(pXmlDoc
, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:u", "val").match("single"));
195 DECLARE_OOXMLEXPORT_TEST(testFDO71834
, "fdo71834.docx")
197 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
200 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl[1]/w:tr[2]/w:tc[1]/w:tcPr[1]/w:tcW[1]","type", "dxa");
203 DECLARE_OOXMLEXPORT_TEST(testTrackChangesParagraphProperties
, "testTrackChangesParagraphProperties.docx")
205 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
208 assertXPathChildren(pXmlDoc
, "/w:document/w:body/w:p[1]/w:pPr/w:pPrChange", 0);
211 DECLARE_OOXMLEXPORT_TEST(testMsoSpt180
, "mso-spt180.docx")
216 uno::Reference
<container::XIndexAccess
> xGroup(getShape(1), uno::UNO_QUERY
);
217 uno::Sequence
<beans::PropertyValue
> aProps
= getProperty
< uno::Sequence
<beans::PropertyValue
> >(xGroup
->getByIndex(0), "CustomShapeGeometry");
219 for (int i
= 0; i
< aProps
.getLength(); ++i
)
220 if (aProps
[i
].Name
== "Type")
221 aType
= aProps
[i
].Value
.get
<OUString
>();
222 // This was exported as borderCallout90, which is an invalid drawingML preset shape string.
223 CPPUNIT_ASSERT_EQUAL(OUString("ooxml-borderCallout1"), aType
);
226 DECLARE_OOXMLEXPORT_TEST(testFdo73550
, "fdo73550.docx")
228 xmlDocPtr pXmlDocument
= parseExport("word/document.xml");
231 // This was wrap="none".
232 assertXPath(pXmlDocument
, "/w:document/w:body/w:p[2]/w:pPr/w:rPr/w:rFonts");
235 DECLARE_OOXMLEXPORT_TEST(testPageRelSize
, "pagerelsize.docx")
237 // First shape: width is relative from page, but not height.
238 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
239 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME
, getProperty
<sal_Int16
>(xShape
, "RelativeWidthRelation"));
240 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME
, getProperty
<sal_Int16
>(xShape
, "RelativeHeightRelation"));
242 // Second shape: height is relative from page, but not height.
243 xShape
= getShape(2);
244 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME
, getProperty
<sal_Int16
>(xShape
, "RelativeHeightRelation"));
245 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME
, getProperty
<sal_Int16
>(xShape
, "RelativeWidthRelation"));
248 DECLARE_OOXMLEXPORT_TEST(testRelSizeRound
, "rel-size-round.docx")
250 // This was 9: 9.8 was imported as 9 instead of being rounded to 10.
251 CPPUNIT_ASSERT_EQUAL(sal_Int16(10), getProperty
<sal_Int16
>(getShape(1), "RelativeHeight"));
254 DECLARE_OOXMLEXPORT_TEST(testTestTitlePage
, "testTitlePage.docx")
256 CPPUNIT_ASSERT_EQUAL(OUString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), parseDump("/root/page[2]/footer/txt/text()"));
259 DECLARE_OOXMLEXPORT_TEST(testTableRowDataDisplayedTwice
,"table-row-data-displayed-twice.docx")
261 // fdo#73534: There was a problem for some documents during export.Invalid sectPr getting added
262 // because of wrong condition in code.
263 // This was the reason for increasing number of pages after RT
264 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
265 uno::Reference
<text::XTextViewCursorSupplier
> xTextViewCursorSupplier(xModel
->getCurrentController(), uno::UNO_QUERY
);
266 uno::Reference
<text::XPageCursor
> xCursor(xTextViewCursorSupplier
->getViewCursor(), uno::UNO_QUERY
);
267 xCursor
->jumpToLastPage();
268 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor
->getPage());
271 DECLARE_OOXMLEXPORT_TEST(testFdo73556
,"fdo73556.docx")
274 * The file contains a table with 3 columns
275 * the girdcols are as follows: {1210, 1331, 1210}
276 * whereas the individual cells have {1210, 400, 1210}
277 * The table column separators were taken from the Grid, while
278 * the table width was calculated as 2820 from cells instead
279 * of 3751 from the Grid.
281 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
284 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol", 3);
285 sal_Int32 tableWidth
= 0;
286 tableWidth
+= getXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[1]", "w").toInt32();
287 tableWidth
+= getXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]", "w").toInt32();
288 tableWidth
+= getXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[3]", "w").toInt32();
289 CPPUNIT_ASSERT_EQUAL(sal_Int32(3751), tableWidth
);
292 DECLARE_OOXMLEXPORT_TEST(testSegFaultWhileSave
, "test_segfault_while_save.docx")
295 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
298 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(6137), getXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]", "w").toInt32());
301 DECLARE_OOXMLEXPORT_TEST(fdo69656
, "Table_cell_auto_width_fdo69656.docx")
303 // Changed the UT to check "dxa" instead of "auto"
304 // For this particular issue file few cells have width type "auto"
305 // LO supports VARIABLE and FIXED width type.
306 // If type is VARIABLE LO calculates width as percent of PageSize
307 // Else if the width is fixed it uses the width value.
308 // After changes for fdo76741 the fixed width is exported as "dxa" for DOCX
310 // Check for the width type of table and its cells.
311 xmlDocPtr pXmlDoc
= parseExport();
314 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tblPr/w:tblW","type","dxa");
317 DECLARE_OOXMLEXPORT_TEST(testFdo76741
, "fdo76741.docx")
320 // There are two issue related to table in the saved(exported) file
321 // - the table alignment in saved file is "left" instead of "center"
322 // - the table width type in properties is "auto" instead of "dxa"
324 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
328 assertXPath(pXmlDoc
, "//w:jc", "val", "center");
329 assertXPath(pXmlDoc
, "//w:tblW", "w", "10081");
330 assertXPath(pXmlDoc
, "//w:tblW", "type", "dxa");
333 DECLARE_OOXMLEXPORT_TEST(testFdo73541
,"fdo73541.docx")
335 // fdo#73541: The mirrored margins were not imported and mapped correctly in Page Layout
336 // Hence <w:mirrorMargins /> tag was not exported back in settings.xml
337 xmlDocPtr pXmlDoc
= parseExport("word/settings.xml");
340 assertXPath(pXmlDoc
, "/w:settings/w:mirrorMargins");
343 DECLARE_OOXMLEXPORT_TEST(testFDO74106
, "FDO74106.docx")
345 xmlDocPtr pXmlDoc
= parseExport("word/numbering.xml");
348 assertXPath(pXmlDoc
, "/w:numbering/w:abstractNum[1]/w:lvl[1]/w:numFmt", "val","hebrew1");
351 DECLARE_OOXMLEXPORT_TEST(testFDO74215
, "FDO74215.docx")
353 xmlDocPtr pXmlDoc
= parseExport("word/numbering.xml");
356 assertXPath(pXmlDoc
, "/w:numbering/w:numPicBullet[2]/w:pict/v:shape", "style", "width:7.9pt;height:7.9pt");
359 DECLARE_OOXMLEXPORT_TEST(testColumnBreak_ColumnCountIsZero
,"fdo74153.docx")
361 /* fdo73545: Column Break with Column_count = 0 was not getting preserved.
362 * The <w:br w:type="column" /> was missing after roundtrip
364 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
367 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[3]/w:r[1]/w:br","type","column");
370 DECLARE_OOXMLEXPORT_TEST(testIndentation
, "test_indentation.docx")
372 // fdo#74141 :There was a problem that in style.xml and document.xml in <w:ind> tag "right" & "left" margin
373 // attributes gets added(w:right=0 & w:left=0) if these attributes are not set in original document.
374 // This test is to verify <w:ind> does not contain w:right attribute.
375 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
378 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:pPr/w:ind", "end", "");
381 DECLARE_OOXMLEXPORT_TEST(testChartInFooter
, "chart-in-footer.docx")
383 // fdo#73872: document contains chart in footer.
384 // The problem was that footer1.xml.rels files for footer1.xml
385 // files were missing from docx file after roundtrip.
386 xmlDocPtr pXmlDoc
= parseExport("word/_rels/footer1.xml.rels");
390 // Check footer1.xml.rels contains in doc after roundtrip.
391 // Check Id = rId1 in footer1.xml.rels
392 assertXPath(pXmlDoc
,"/rels:Relationships/rels:Relationship","Id","rId1");
394 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
395 if (xDrawPageSupplier
.is())
397 // If xDrawPage->getCount()==1, then document conatins one shape.
398 uno::Reference
<container::XIndexAccess
> xDrawPage(xDrawPageSupplier
->getDrawPage(), uno::UNO_QUERY
);
399 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDrawPage
->getCount()); // One shape in the doc
403 DECLARE_OOXMLEXPORT_TEST(testNestedTextFrames
, "nested-text-frames.odt")
405 // First problem was LO crashed during export (crash test)
407 // Second problem was LO made file corruption, writing out nested text boxes, which can't be handled by Word.
408 // Test that all three exported text boxes are anchored to the same paragraph and not each other.
409 uno::Reference
<text::XTextContent
> xTextContent(getShape(1), uno::UNO_QUERY
);
410 uno::Reference
<text::XTextRange
> xRange(xTextContent
->getAnchor(), uno::UNO_QUERY
);
411 uno::Reference
<text::XText
> xText(xRange
->getText(), uno::UNO_QUERY
);
412 CPPUNIT_ASSERT_EQUAL(OUString("Anchor point"), xText
->getString());
414 xTextContent
.set(getShape(2), uno::UNO_QUERY
);
415 xRange
.set(xTextContent
->getAnchor(), uno::UNO_QUERY
);
416 xText
.set(xRange
->getText(), uno::UNO_QUERY
);
417 CPPUNIT_ASSERT_EQUAL(OUString("Anchor point"), xText
->getString());
419 xTextContent
.set(getShape(3), uno::UNO_QUERY
);
420 xRange
.set(xTextContent
->getAnchor(), uno::UNO_QUERY
);
421 xText
.set(xRange
->getText(), uno::UNO_QUERY
);
422 CPPUNIT_ASSERT_EQUAL(OUString("Anchor point"), xText
->getString());
425 DECLARE_OOXMLEXPORT_TEST(testFloatingTablePosition
, "floating-table-position.docx")
427 // Position of shape was wrong, because some conversion was missing.
428 uno::Reference
<beans::XPropertySet
> xShape(getShape(1), uno::UNO_QUERY
);
430 CPPUNIT_ASSERT_EQUAL(sal_Int32(5964), getProperty
<sal_Int32
>(xShape
, "HoriOrientPosition"));
432 CPPUNIT_ASSERT_EQUAL(sal_Int32(8133), getProperty
<sal_Int32
>(xShape
, "VertOrientPosition"));
435 DECLARE_OOXMLEXPORT_TEST(testAbi11739
, "abi11739.docx")
437 // Validation test: order of elements were wrong.
438 xmlDocPtr pXmlDoc
= parseExport("word/styles.xml");
441 // Order was: uiPriority, link, basedOn.
442 CPPUNIT_ASSERT(getXPathPosition(pXmlDoc
, "/w:styles/w:style[3]", "basedOn") < getXPathPosition(pXmlDoc
, "/w:styles/w:style[3]", "link"));
443 CPPUNIT_ASSERT(getXPathPosition(pXmlDoc
, "/w:styles/w:style[3]", "link") < getXPathPosition(pXmlDoc
, "/w:styles/w:style[3]", "uiPriority"));
444 // Order was: qFormat, unhideWhenUsed.
445 CPPUNIT_ASSERT(getXPathPosition(pXmlDoc
, "/w:styles/w:style[11]", "unhideWhenUsed") < getXPathPosition(pXmlDoc
, "/w:styles/w:style[11]", "qFormat"));
448 DECLARE_OOXMLEXPORT_TEST(testEmbeddedXlsx
, "embedded-xlsx.docx")
450 // check there are two objects and they are FrameShapes
451 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
452 uno::Reference
<container::XIndexAccess
> xDraws(xDrawPageSupplier
->getDrawPage(), uno::UNO_QUERY
);
453 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDraws
->getCount());
454 CPPUNIT_ASSERT_EQUAL(OUString("FrameShape"), getShape(1)->getShapeType());
455 CPPUNIT_ASSERT_EQUAL(OUString("FrameShape"), getShape(2)->getShapeType());
457 // check the objects are present in the exported document.xml
458 xmlDocPtr pXmlDocument
= parseExport("word/document.xml");
461 assertXPath(pXmlDocument
, "/w:document/w:body/w:p/w:r/w:object", 2);
463 // finally check the embedded files are present in the zipped document
464 uno::Reference
<packages::zip::XZipFileAccess2
> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory
), maTempFile
.GetURL());
465 uno::Sequence
<OUString
> names
= xNameAccess
->getElementNames();
468 for (int i
=0; i
<names
.getLength(); i
++)
470 if(names
[i
].startsWith("word/embeddings/oleObject"))
472 if(names
[i
].startsWith("word/media/image"))
475 CPPUNIT_ASSERT_EQUAL(2, nSheetFiles
);
476 CPPUNIT_ASSERT_EQUAL(2, nImageFiles
);
479 DECLARE_OOXMLEXPORT_TEST(testNumberedLists_StartingWithZero
, "FDO74105.docx")
481 /* Issue : Numbered lists Starting with value '0' is not preserved after RT.
482 * In numbering.xml, an XML tag <w:start> is optional. If not mentioned,
483 * the Numbered list should start from 0.
484 * Problem was LO was writing <w:start> for all levels 0-8 with default value "1".
486 xmlDocPtr pXmlDoc
= parseExport("word/numbering.xml");
490 // Check that we do _not_ export w:start for <w:lvl w:ilvl="0">.
491 assertXPath(pXmlDoc
, "w:numbering/w:abstractNum[1]/w:lvl[1]/w:start", 0);
494 DECLARE_OOXMLEXPORT_TEST(testPageBreak
,"fdo74566.docx")
496 /* Break to next page was written into wrong paragraph as <w:pageBreakBefore />.
497 * LO was not preserving Page Break as <w:br w:type="page" />.
498 * Now after fix , LO writes Page Break as the new paragraph and also
499 * preserves the xml tag <w:br>.
501 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
505 uno::Reference
<text::XTextRange
> xParagraph2
= getParagraph(2);
506 uno::Reference
<text::XTextRange
> xParagraph4
= getParagraph(4);
508 getRun(xParagraph2
, 1, "First Page Second Line");
509 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[3]/w:r[2]/w:br","type","page");
510 getRun(xParagraph4
, 1, "Second Page First line after Page Break");
513 DECLARE_OOXMLEXPORT_TEST(testOleObject
, "test_ole_object.docx")
515 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
519 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[2]/w:r/w:object/v:shape/v:imagedata", "o:title", "");
522 DECLARE_OOXMLEXPORT_TEST(testFdo74792
, "fdo74792.docx")
525 * fdo#74792 : The images associated with smart-art data[i].xml
526 * were not preserved on exporting to DOCX format
527 * Added support to grabbag the rels, with associated images.
529 xmlDocPtr pXmlDoc
= parseExport("word/diagrams/_rels/data1.xml.rels");
532 assertXPath(pXmlDoc
,"/rels:Relationships/rels:Relationship", 4);
533 uno::Reference
<packages::zip::XZipFileAccess2
> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(
534 comphelper::getComponentContext(m_xSFactory
), maTempFile
.GetURL());
536 //check that images are also saved
537 OUString
sImageFile( "word/media/OOXDiagramDataRels1_0.jpeg" ); //added anchor id to form a uniqe name
538 uno::Reference
<io::XInputStream
> xInputStream(xNameAccess
->getByName( sImageFile
), uno::UNO_QUERY
);
539 CPPUNIT_ASSERT( xInputStream
.is() );
542 DECLARE_OOXMLEXPORT_TEST(testFdo77718
, "fdo77718.docx")
544 //in case of multiple smart arts the names for images were getting
545 //repeated and thereby causing a data loss as the binary stream was
546 //getting over written. This test case ensures that unique names are
547 //given for images in different smart arts.
548 xmlDocPtr pXmlDataRels1
= parseExport("word/diagrams/_rels/data1.xml.rels");
552 xmlDocPtr pXmlDataRels2
= parseExport("word/diagrams/_rels/data2.xml.rels");
556 //ensure that the rels file is present.
557 assertXPath(pXmlDataRels1
,"/rels:Relationships/rels:Relationship", 4);
558 assertXPath(pXmlDataRels2
,"/rels:Relationships/rels:Relationship", 4);
560 uno::Reference
<packages::zip::XZipFileAccess2
> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(
561 comphelper::getComponentContext(m_xSFactory
), maTempFile
.GetURL());
563 //check that images are also saved
564 OUString
sImageFile1( "word/media/OOXDiagramDataRels1_0.jpeg" ); //added anchor id to form a uniqe name
565 uno::Reference
<io::XInputStream
> xInputStream1(xNameAccess
->getByName( sImageFile1
), uno::UNO_QUERY
);
566 CPPUNIT_ASSERT( xInputStream1
.is() );
568 //check that images are saved for other smart-arts as well.
569 OUString
sImageFile2( "word/media/OOXDiagramDataRels2_0.jpeg" ); //added anchor id to form a uniqe name
570 uno::Reference
<io::XInputStream
> xInputStream2(xNameAccess
->getByName( sImageFile2
), uno::UNO_QUERY
);
571 CPPUNIT_ASSERT( xInputStream2
.is() );
574 DECLARE_OOXMLEXPORT_TEST(testTableCurruption
, "tableCurrupt.docx")
576 xmlDocPtr pXmlDoc
= parseExport("word/header2.xml");
579 CPPUNIT_ASSERT(pXmlDoc
) ;
580 assertXPath(pXmlDoc
, "/w:hdr/w:tbl[1]/w:tr[1]/w:tc[1]",1);
583 DECLARE_OOXMLEXPORT_TEST(testDateControl
, "date-control.docx")
586 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
589 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date", "fullDate", "2014-03-05T00:00:00Z");
590 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dddd, dd' de 'MMMM' de 'yyyy");
591 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:lid", "val", "es-ES");
592 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", OUString::fromUtf8("mi\xC3\xA9rcoles, 05 de marzo de 2014"));
594 // check imported control
595 uno::Reference
<drawing::XControlShape
> xControl(getShape(1), uno::UNO_QUERY
);
596 util::Date aDate
= getProperty
<util::Date
>(xControl
->getControl(), "Date");
597 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), sal_Int32(aDate
.Day
));
598 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), sal_Int32(aDate
.Month
));
599 CPPUNIT_ASSERT_EQUAL(sal_Int32(2014), sal_Int32(aDate
.Year
));
602 DECLARE_OOXMLEXPORT_TEST(test_OpeningBrace
, "2120112713_OpenBrace.docx")
604 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
607 // Checking for OpeningBrace tag
608 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[1]/m:oMath[1]/m:d[1]/m:dPr[1]/m:begChr[1]","val","");
611 DECLARE_OOXMLEXPORT_TEST(testFDO76312
, "FDO76312.docx")
613 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
617 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl[1]/w:tr[1]/w:tc[1]");
620 DECLARE_OOXMLEXPORT_TEST(testComboBoxControl
, "combobox-control.docx")
623 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
626 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]", "value", "manolo");
627 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dropDownList/w:listItem[2]", "value", "pepito");
628 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", "Manolo");
630 // check imported control
631 uno::Reference
<drawing::XControlShape
> xControl(getShape(1), uno::UNO_QUERY
);
633 CPPUNIT_ASSERT_EQUAL(OUString("Manolo"), getProperty
<OUString
>(xControl
->getControl(), "Text"));
635 uno::Sequence
<OUString
> aItems
= getProperty
< uno::Sequence
<OUString
> >(xControl
->getControl(), "StringItemList");
636 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), sal_Int32(aItems
.getLength()));
637 CPPUNIT_ASSERT_EQUAL(OUString("manolo"), aItems
[0]);
638 CPPUNIT_ASSERT_EQUAL(OUString("pepito"), aItems
[1]);
641 DECLARE_OOXMLEXPORT_TEST(testCheckBoxControl
, "checkbox-control.docx")
644 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
647 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w14:checkbox/w14:checked", "val", "1");
648 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w14:checkbox/w14:checkedState", "val", "2612");
649 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w14:checkbox/w14:uncheckedState", "val", "2610");
651 // TODO: import control and add a check here
654 DECLARE_OOXMLEXPORT_TEST(testParagraphWithComments
, "paragraphWithComments.docx")
656 /* Comment id's were getting overwritten for annotation mark(s),
657 which was causing a mismatch in the relationship for comment id's
658 in document.xml and comment.xml
660 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
661 xmlDocPtr pXmlComm
= parseExport("word/comments.xml");
665 sal_Int32 idInDocXml
= 0;
666 sal_Int32 idInCommentXml
= -1; //intentionally assigning -1 so that it differs from idInDocXml
667 //and also because getXpath does not assert.
668 idInDocXml
= getXPath(pXmlDoc
,"/w:document/w:body/w:p[3]/w:commentRangeEnd[1]","id").toInt32();
669 idInCommentXml
= getXPath(pXmlComm
,"/w:comments/w:comment[1]","id").toInt32();
670 CPPUNIT_ASSERT_EQUAL( idInDocXml
, idInCommentXml
);
673 DECLARE_OOXMLEXPORT_TEST(testOLEObjectinHeader
, "2129393649.docx")
675 // fdo#76015 : Document contains oleobject in header xml.
676 // Problem was relationship entry for oleobject from header was
677 // exported into document.xml.rels file because of this rels file
678 // for headers were missing from document/word/rels.
679 xmlDocPtr pXmlDoc
= parseExport("word/_rels/header1.xml.rels");
683 assertXPath(pXmlDoc
,"/rels:Relationships/rels:Relationship[1]","Id","rId1");
686 DECLARE_OOXMLEXPORT_TEST(test_ClosingBrace
, "2120112713.docx")
688 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
691 // Checking for ClosingBrace tag
692 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[1]/m:oMath[1]/m:d[2]/m:dPr[1]/m:endChr[1]","val","");
695 DECLARE_OOXMLEXPORT_TEST(testlvlPicBulletId
, "lvlPicBulletId.docx")
697 xmlDocPtr pXmlDoc
= parseExport("word/numbering.xml");
700 assertXPath(pXmlDoc
, "/w:numbering[1]/w:abstractNum[1]/w:lvl[1]/w:lvlPicBulletId[1]", 0);
703 DECLARE_OOXMLEXPORT_TEST(testSdtContent
, "SdtContent.docx")
705 xmlDocPtr pXmlDoc
= parseExport("word/header1.xml");
708 assertXPath(pXmlDoc
, "/w:hdr[1]/w:sdt[1]/w:sdtContent[1]/w:p[1]/w:del[1]");
712 // Currently LibreOffice exports custom geometry for this up arrow, not preset shape.
713 // When LibreOffice can export preset shape with correct modifiers, then this test can be re-enabled.
715 DECLARE_OOXMLEXPORT_TEST(testFdo76016
, "fdo76016.docx")
718 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
721 assertXPath(pXmlDoc
, "//a:graphic/a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", "name", "adj1");
722 assertXPath(pXmlDoc
, "//a:graphic/a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", "name", "adj2");
726 DECLARE_OOXMLEXPORT_TEST(testFileWithInvalidImageLink
, "FileWithInvalidImageLink.docx")
728 /* In case if the original file has an image whose link is
729 invalid, then the RT file used to result in corruption
730 since the exported image would be an empty image.
732 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
736 assertXPath(pXmlDoc
, "/w:document/w:body/w:p[2]/w:r[2]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/pic:pic[1]/pic:blipFill[1]/a:blip[1]", "embed", "");
739 DECLARE_OOXMLEXPORT_TEST(testContentTypeDOCX
, "fdo80410.docx")
741 xmlDocPtr pXmlDoc
= parseExport("[Content_Types].xml");
743 if (!pXmlDoc
) // only test the export, not initial import
747 "/ContentType:Types/ContentType:Override[@PartName='/word/embeddings/oleObject1.docx']",
749 "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
752 DECLARE_OOXMLEXPORT_TEST(testContentTypeXLSM
, "fdo76098.docx")
754 xmlDocPtr pXmlDoc
= parseExport("[Content_Types].xml");
759 assertXPath(pXmlDoc
, "/ContentType:Types/ContentType:Override[@PartName='/word/embeddings/Microsoft_Excel_Macro-Enabled_Worksheet1.xlsm']", "ContentType", "application/vnd.ms-excel.sheet.macroEnabled.12");
762 DECLARE_OOXMLEXPORT_TEST(test76108
, "test76108.docx")
764 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
765 if (!pXmlDoc
) return;
766 //docx file after RT is getting corrupted.
767 assertXPath(pXmlDoc
, "/w:document[1]/w:body[1]/w:p[1]/w:r[1]/w:fldChar[1]", "fldCharType", "begin");
770 DECLARE_OOXMLEXPORT_TEST(testTCTagMisMatch
, "TCTagMisMatch.docx")
772 // TCTagMisMatch.docx : This document contains a empty table with borders.
773 // there was a TC tag mismatch which resulted into a crash.
775 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
778 assertXPath(pXmlDoc
,"/w:document[1]/w:body[1]/w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]/w:tr[1]/w:tc[1]",0);
779 assertXPath(pXmlDoc
,"/w:document[1]/w:body[1]/w:tbl[1]/w:tr[1]/w:tc[1]", 1);
782 DECLARE_OOXMLEXPORT_TEST(testFDO78292
, "FDO78292.docx")
784 //text node is a leaf node, it should not have any children
785 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
788 assertXPath(pXmlDoc
,"/w:document/w:body/w:p[14]/w:sdt[3]/w:sdtPr[1]/w:text/w14:checked",0);
791 DECLARE_OOXMLEXPORT_TEST(testSimpleSdts
, "simple-sdts.docx")
793 xmlDocPtr pXmlDoc
= parseExport("word/document.xml");
798 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w:text", 1);
799 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w:id", 3);
800 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w:picture", 1);
801 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w:group", 1);
802 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:citation", 1);
806 DECLARE_OOXMLEXPORT_TEST(testTdf83227
, "tdf83227.docx")
808 // Bug document contains a rotated image, which is handled as a draw shape (not as a Writer image) on export.
812 uno::Reference
<packages::zip::XZipFileAccess2
> xNameAccess
= packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory
), maTempFile
.GetURL());
813 CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess
->hasByName("word/media/image1.png")));
814 // This was also true, image was written twice.
815 CPPUNIT_ASSERT_EQUAL(false, bool(xNameAccess
->hasByName("word/media/image2.png")));
818 DECLARE_OOXMLEXPORT_TEST(testTdf92521
, "tdf92521.odt")
820 if (xmlDocPtr pXmlDoc
= parseExport("word/document.xml"))
821 // There should be a section break that's in the middle of the document: right after the table.
822 assertXPath(pXmlDoc
, "/w:document/w:body/w:p/w:pPr/w:sectPr", 1);
825 CPPUNIT_PLUGIN_IMPLEMENT();
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */