/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class Test : public SwModelTestBase { public: Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {} protected: void verifyComboBoxExport(bool aComboBoxAsDropDown); }; DECLARE_OOXMLEXPORT_TEST(testRelorientation, "relorientation.docx") { uno::Reference xShape = getShape(1); // This was text::RelOrientation::FRAME, when handling relativeFrom=page, align=right CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty(xShape, "HoriOrientRelation")); uno::Reference xGroup(xShape, uno::UNO_QUERY); // This resulted in lang::IndexOutOfBoundsException, as nested groupshapes weren't handled. uno::Reference xShapeDescriptor(xGroup->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GroupShape"), xShapeDescriptor->getShapeType()); // 'actual child size' = 'group ext' * 'child ext' / 'chExt from group', see section 'chExt' in // [MS-OI29500]. Here for width from file 3108960 * 4896 / 4911 = 3099464 EMU. That corresponds to // width 8.61cm and 325px in UI in Word and rounds down to 8609 Hmm. Considering scaling of the // parent group to the anchor extent (* 3118485 / 3108960) we get a display width of 3108960 EMU // = 8636Hmm. FIXME: Expected value is as in LO 7.2. Reason for difference is yet unknown. if (isExported()) { uno::Reference xYear(xGroup->getByIndex(1), uno::UNO_QUERY); // This was 2, due to incorrect handling of parent transformations inside DML groupshapes. CPPUNIT_ASSERT_EQUAL(sal_Int32(8662), xYear->getSize().Width); } } CPPUNIT_TEST_FIXTURE(Test, testBezier) { loadAndReload("bezier.odt"); CPPUNIT_ASSERT_EQUAL(1, getPages()); // Check that no shape got lost: a bezier, a line and a text shape. CPPUNIT_ASSERT_EQUAL(3, getShapes()); } DECLARE_OOXMLEXPORT_TEST(testGroupshapeTextbox, "groupshape-textbox.docx") { uno::Reference xGroup(getShape(1), uno::UNO_QUERY); uno::Reference xShape(xGroup->getByIndex(0), uno::UNO_QUERY); // The VML export lost text on textboxes inside groupshapes. // The DML export does not, make sure it stays that way. CPPUNIT_ASSERT_EQUAL(OUString("first"), xShape->getString()); // This was 16, i.e. inheriting doc default char height didn't work. CPPUNIT_ASSERT_EQUAL(11.f, getProperty(getParagraphOfText(1, xShape->getText()), "CharHeight")); } DECLARE_OOXMLEXPORT_TEST(testGroupshapePicture, "groupshape-picture.docx") { // Picture in the groupshape got lost, groupshape had only one child. uno::Reference xGroup(getShape(1), uno::UNO_QUERY); uno::Reference xShapeDescriptor(xGroup->getByIndex(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GraphicObjectShape"), xShapeDescriptor->getShapeType()); } DECLARE_OOXMLEXPORT_TEST(testAutofit, "autofit.docx") { CPPUNIT_ASSERT_EQUAL(true, getProperty(getShape(1), "TextAutoGrowHeight")); CPPUNIT_ASSERT_EQUAL(false, getProperty(getShape(2), "TextAutoGrowHeight")); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesDeletedParagraphMark) { loadAndSave("testTrackChangesDeletedParagraphMark.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:del"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesInsertedParagraphMark) { loadAndSave("testTrackChangesInsertedParagraphMark.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:ins"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesDeletedTableRow) { loadAndSave("testTrackChangesDeletedTableRow.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:trPr/w:del"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesInsertedTableRow) { loadAndSave("testTrackChangesInsertedTableRow.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:trPr/w:ins"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesDeletedTableCell) { loadAndSave("testTrackChangesDeletedTableCell.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc/w:tcPr/w:cellDel"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesInsertedTableCell) { loadAndSave("testTrackChangesInsertedTableCell.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc/w:tcPr/w:cellIns"_ostr); } DECLARE_OOXMLEXPORT_TEST(testTextBoxPictureFill, "textbox_picturefill.docx") { uno::Reference xFrame(getShape(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, getProperty(xFrame, "FillStyle")); auto xBitmap = getProperty>(xFrame, "FillBitmap"); CPPUNIT_ASSERT(xBitmap.is()); uno::Reference xGraphic(xBitmap, uno::UNO_QUERY); CPPUNIT_ASSERT(xGraphic.is()); Graphic aGraphic(xGraphic); CPPUNIT_ASSERT(!aGraphic.IsNone()); CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0L); CPPUNIT_ASSERT_EQUAL(tools::Long(447), aGraphic.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(528), aGraphic.GetSizePixel().Height()); } CPPUNIT_TEST_FIXTURE(Test, testFDO73034) { loadAndSave("FDO73034.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:u"_ostr, "val"_ostr).match("single")); } CPPUNIT_TEST_FIXTURE(Test, testFDO71834) { loadAndSave("fdo71834.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tr[2]/w:tc[1]/w:tcPr[1]/w:tcW[1]"_ostr,"type"_ostr, "dxa"); } CPPUNIT_TEST_FIXTURE(Test, testTrackChangesParagraphProperties) { loadAndSave("testTrackChangesParagraphProperties.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPathChildren(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:pPrChange"_ostr, 0); } CPPUNIT_TEST_FIXTURE(Test, testMsoSpt180) { loadAndReload("mso-spt180.docx"); uno::Reference xGroup(getShape(1), uno::UNO_QUERY); const uno::Sequence aProps = getProperty< uno::Sequence >(xGroup->getByIndex(0), "CustomShapeGeometry"); OUString aType; for (beans::PropertyValue const & prop : aProps) if (prop.Name == "Type") aType = prop.Value.get(); // This was exported as borderCallout90, which is an invalid drawingML preset shape string. CPPUNIT_ASSERT_EQUAL(OUString("ooxml-borderCallout1"), aType); } CPPUNIT_TEST_FIXTURE(Test, testFdo73550) { loadAndSave("fdo73550.docx"); xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml"); // This was wrap="none". assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:pPr/w:rPr/w:rFonts"_ostr); } DECLARE_OOXMLEXPORT_TEST(testPageRelSize, "pagerelsize.docx") { // First shape: width is relative from page, but not height. uno::Reference xShape = getShape(1); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty(xShape, "RelativeWidthRelation")); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty(xShape, "RelativeHeightRelation")); // Second shape: height is relative from page, but not height. xShape = getShape(2); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty(xShape, "RelativeHeightRelation")); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty(xShape, "RelativeWidthRelation")); } DECLARE_OOXMLEXPORT_TEST(testRelSizeRound, "rel-size-round.docx") { // This was 9: 9.8 was imported as 9 instead of being rounded to 10. CPPUNIT_ASSERT_EQUAL(sal_Int16(10), getProperty(getShape(1), "RelativeHeight")); } DECLARE_OOXMLEXPORT_TEST(testTestTitlePage, "testTitlePage.docx") { // this has 2 pages in Word CPPUNIT_ASSERT_EQUAL(OUString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), parseDump("/root/page[2]/footer/txt/text()"_ostr)); } DECLARE_OOXMLEXPORT_TEST(testTableRowDataDisplayedTwice, "table-row-data-displayed-twice.docx") { // fdo#73534: There was a problem for some documents during export.Invalid sectPr getting added // because of wrong condition in code. // This was the reason for increasing number of pages after RT CPPUNIT_ASSERT_EQUAL(2, getPages()); } CPPUNIT_TEST_FIXTURE(Test, testFdo73556) { loadAndSave("fdo73556.docx"); /* * The file contains a table with 3 columns * the gridcols are as follows: {1210, 1331, 1210} * whereas the individual cells have {1210, 400, 1210} * The table column separators were taken from the Grid, while * the table width was calculated as 2820 from cells instead * of 3751 from the Grid. */ xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol"_ostr, 3); sal_Int32 tableWidth = 0; tableWidth += getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[1]"_ostr, "w"_ostr).toInt32(); tableWidth += getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]"_ostr, "w"_ostr).toInt32(); tableWidth += getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[3]"_ostr, "w"_ostr).toInt32(); CPPUNIT_ASSERT_EQUAL(sal_Int32(3751), tableWidth); } CPPUNIT_TEST_FIXTURE(Test, testSegFaultWhileSave) { loadAndSave("test_segfault_while_save.docx"); // fdo#74499 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); CPPUNIT_ASSERT_EQUAL(static_cast(6137), getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]"_ostr, "w"_ostr).toInt32()); } CPPUNIT_TEST_FIXTURE(Test, fdo69656) { loadAndSave("Table_cell_auto_width_fdo69656.docx"); // Changed the UT to check "dxa" instead of "auto" // For this particular issue file few cells have width type "auto" // LO supports VARIABLE and FIXED width type. // If type is VARIABLE LO calculates width as percent of PageSize // Else if the width is fixed it uses the width value. // After changes for fdo76741 the fixed width is exported as "dxa" for DOCX // Check for the width type of table and its cells. xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblW"_ostr,"type"_ostr,"dxa"); } CPPUNIT_TEST_FIXTURE(Test, testFdo76741) { loadAndSave("fdo76741.docx"); // There are two issue related to table in the saved(exported) file // - the table alignment in saved file is "left" instead of "center" // - the table width type in properties is "auto" instead of "dxa" xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "//w:jc"_ostr, "val"_ostr, "center"); assertXPath(pXmlDoc, "//w:tblW"_ostr, "w"_ostr, "10081"); assertXPath(pXmlDoc, "//w:tblW"_ostr, "type"_ostr, "dxa"); } CPPUNIT_TEST_FIXTURE(Test, testFdo73541) { loadAndSave("fdo73541.docx"); // fdo#73541: The mirrored margins were not imported and mapped correctly in Page Layout // Hence tag was not exported back in settings.xml xmlDocUniquePtr pXmlDoc = parseExport("word/settings.xml"); assertXPath(pXmlDoc, "/w:settings/w:mirrorMargins"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testFdo106029) { loadAndSave("fdo106029.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/settings.xml"); assertXPath(pXmlDoc, "/w:settings/w:compat/w:doNotExpandShiftReturn"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testTdf146515) { loadAndSave("tdf146515.odt"); xmlDocUniquePtr pXmlDoc = parseExport("word/settings.xml"); assertXPath(pXmlDoc, "/w:settings/w:compat/w:usePrinterMetrics"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testFDO74106) { loadAndSave("FDO74106.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/numbering.xml"); assertXPath(pXmlDoc, "/w:numbering/w:abstractNum[1]/w:lvl[1]/w:numFmt"_ostr, "val"_ostr,"hebrew1"); } CPPUNIT_TEST_FIXTURE(Test, testFDO74215) { loadAndSave("FDO74215.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/numbering.xml"); // tdf#106849 NumPicBullet xShape should not be resized. // This is dependent on the running system: see MSWordExportBase::BulletDefinitions // FIXME: the size of a bullet is defined by GraphicSize property // (stored in SvxNumberFormat::aGraphicSize) so use that for the size // (properly convert from 100mm to pt (1 inch is 72 pt, 1 pt is 20 twips). // On 96 DPI "width:11.25pt;height:11.25pt"; on 120 DPI "width:9pt;height:9pt" const OUString sStyle = getXPath(pXmlDoc, "/w:numbering/w:numPicBullet[2]/w:pict/v:shape"_ostr, "style"_ostr); { OUString sWidth = sStyle.getToken(0, ';'); CPPUNIT_ASSERT(sWidth.startsWith("width:", &sWidth)); CPPUNIT_ASSERT(sWidth.endsWith("pt", &sWidth)); const double fWidth = sWidth.toDouble(); const double fXScaleFactor = 96.0 / Application::GetDefaultDevice()->GetDPIX(); // note: used to fail on Mac with 14.7945205479452 vs. 14.8 // note: used to fail on another Mac with 12.1348314606742 vs 12.15 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.25 * fXScaleFactor, fWidth, 0.1); } { OUString sHeight = sStyle.getToken(1, ';'); CPPUNIT_ASSERT(sHeight.startsWith("height:", &sHeight)); CPPUNIT_ASSERT(sHeight.endsWith("pt", &sHeight)); const double fHeight = sHeight.toDouble(); const double fYScaleFactor = 96.0 / Application::GetDefaultDevice()->GetDPIY(); CPPUNIT_ASSERT_DOUBLES_EQUAL(11.25 * fYScaleFactor, fHeight, 0.1); } } DECLARE_OOXMLEXPORT_TEST(testColumnBreak_ColumnCountIsZero,"fdo74153.docx") { /* fdo73545: Column Break with Column_count = 0 was not getting preserved. * The was missing after roundtrip */ if (isExported()) { xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[1]/w:br"_ostr,"type"_ostr,"column"); } //tdf76349 match Word's behavior of treating breaks in single columns as page breaks. CPPUNIT_ASSERT_EQUAL(2, getPages()); } DECLARE_OOXMLEXPORT_TEST(testTdf90697_complexBreaksHeaders,"tdf90697_complexBreaksHeaders.docx") { // This is a complex document using many types of section breaks and re-defined headers. // Paragraphs 44-47 were in two columns uno::Reference xTextSection = getProperty< uno::Reference >(getParagraph(45), "TextSection"); CPPUNIT_ASSERT(xTextSection.is()); uno::Reference xTextColumns = getProperty< uno::Reference >(xTextSection, "TextColumns"); CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount()); // after that, the section break should switch things back to one column. xTextSection = getProperty< uno::Reference >(getParagraph(50), "TextSection"); CPPUNIT_ASSERT(xTextSection.is()); xTextColumns = getProperty< uno::Reference >(xTextSection, "TextColumns"); CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextColumns->getColumnCount()); } CPPUNIT_TEST_FIXTURE(Test, testIndentation) { loadAndSave("test_indentation.docx"); // fdo#74141 :There was a problem that in style.xml and document.xml in tag "right" & "left" margin // attributes gets added(w:right=0 & w:left=0) if these attributes are not set in original document. // This test is to verify does not contain w:right attribute. xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:ind"_ostr, "end"_ostr); } CPPUNIT_TEST_FIXTURE(Test, testChartInFooter) { loadAndSave("chart-in-footer.docx"); // fdo#73872: document contains chart in footer. // The problem was that footer1.xml.rels files for footer1.xml // files were missing from docx file after roundtrip. xmlDocUniquePtr pXmlDoc = parseExport("word/_rels/footer2.xml.rels"); // Check footer2.xml.rels contains in doc after roundtrip. // Check Id = rId1 in footer2.xml.rels assertXPath(pXmlDoc,"/rels:Relationships/rels:Relationship"_ostr,"Id"_ostr,"rId1"); assertXPath(pXmlDoc, "/rels:Relationships/rels:Relationship[@Id='rId1']"_ostr, "Type"_ostr, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"); xmlDocUniquePtr pXmlDocCT = parseExport("[Content_Types].xml"); assertXPath(pXmlDocCT, "/ContentType:Types/ContentType:Override[@PartName='/word/charts/chart1.xml']"_ostr, "ContentType"_ostr, "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"); // check the content too xmlDocUniquePtr pXmlDocFooter2 = parseExport("word/footer2.xml"); assertXPath(pXmlDocFooter2, "/w:ftr/w:p[1]/w:r/w:drawing/wp:inline/a:graphic/a:graphicData"_ostr, "uri"_ostr, "http://schemas.openxmlformats.org/drawingml/2006/chart"); assertXPath(pXmlDocFooter2, "/w:ftr/w:p[1]/w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart"_ostr, "id"_ostr, "rId1"); CPPUNIT_ASSERT_EQUAL(1, getShapes()); } CPPUNIT_TEST_FIXTURE(Test, testNestedTextFrames) { loadAndReload("nested-text-frames.odt"); CPPUNIT_ASSERT_EQUAL(3, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); // First problem was LO crashed during export (crash test) // Second problem was LO made file corruption, writing out nested text boxes, which can't be handled by Word. // Test that all three exported text boxes are anchored to the same paragraph and not each other. uno::Reference xTextContent(getShape(1), uno::UNO_QUERY); uno::Reference xRange = xTextContent->getAnchor(); uno::Reference xText = xRange->getText(); CPPUNIT_ASSERT_EQUAL(OUString("Anchor point"), xText->getString()); xTextContent.set(getShape(2), uno::UNO_QUERY); xRange = xTextContent->getAnchor(); xText = xRange->getText(); CPPUNIT_ASSERT_EQUAL(OUString("Anchor point"), xText->getString()); xTextContent.set(getShape(3), uno::UNO_QUERY); xRange = xTextContent->getAnchor(); xText = xRange->getText(); CPPUNIT_ASSERT_EQUAL(OUString("Anchor point"), xText->getString()); } DECLARE_OOXMLEXPORT_TEST(testFloatingTablePosition, "floating-table-position.docx") { // Position of shape was wrong, because some conversion was missing. uno::Reference xShape(getShape(1), uno::UNO_QUERY); // This was 3295. CPPUNIT_ASSERT_EQUAL(sal_Int32(5964), getProperty(xShape, "HoriOrientPosition")); // This was 4611. CPPUNIT_ASSERT_EQUAL(sal_Int32(8133), getProperty(xShape, "VertOrientPosition")); } CPPUNIT_TEST_FIXTURE(Test, testAbi11739) { loadAndSave("abi11739.docx"); // Validation test: order of elements were wrong. xmlDocUniquePtr pXmlDoc = parseExport("word/styles.xml"); // Order was: uiPriority, link, basedOn. CPPUNIT_ASSERT(getXPathPosition(pXmlDoc, "/w:styles/w:style[3]"_ostr, "basedOn") < getXPathPosition(pXmlDoc, "/w:styles/w:style[3]"_ostr, "link")); CPPUNIT_ASSERT(getXPathPosition(pXmlDoc, "/w:styles/w:style[3]"_ostr, "link") < getXPathPosition(pXmlDoc, "/w:styles/w:style[3]"_ostr, "uiPriority")); // Order was: qFormat, unhideWhenUsed. CPPUNIT_ASSERT(getXPathPosition(pXmlDoc, "/w:styles/w:style[11]"_ostr, "unhideWhenUsed") < getXPathPosition(pXmlDoc, "/w:styles/w:style[11]"_ostr, "qFormat")); } DECLARE_OOXMLEXPORT_TEST(testEmbeddedXlsx, "embedded-xlsx.docx") { // check there are two objects and they are FrameShapes CPPUNIT_ASSERT_EQUAL(2, getShapes()); CPPUNIT_ASSERT_EQUAL(OUString("FrameShape"), getShape(1)->getShapeType()); CPPUNIT_ASSERT_EQUAL(OUString("FrameShape"), getShape(2)->getShapeType()); // check the objects are present in the exported document.xml if (!isExported()) return; xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml"); assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/w:object"_ostr, 2); // finally check the embedded files are present in the zipped document uno::Reference xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); const uno::Sequence names = xNameAccess->getElementNames(); int nSheetFiles = 0; int nImageFiles = 0; for (OUString const & n : names) { if(n.startsWith("word/embeddings/oleObject")) nSheetFiles++; if(n.startsWith("word/media/image")) nImageFiles++; } CPPUNIT_ASSERT_EQUAL(2, nSheetFiles); CPPUNIT_ASSERT_EQUAL(2, nImageFiles); } CPPUNIT_TEST_FIXTURE(Test, testNumberedLists_StartingWithZero) { loadAndSave("FDO74105.docx"); /* Issue : Numbered lists Starting with value '0' is not preserved after RT. * In numbering.xml, an XML tag is optional. If not mentioned, * the Numbered list should start from 0. * Problem was LO was writing for all levels 0-8 with default value "1". */ xmlDocUniquePtr pXmlDoc = parseExport("word/numbering.xml"); // Check that we do _not_ export w:start for . assertXPath(pXmlDoc, "w:numbering/w:abstractNum[1]/w:lvl[1]/w:start"_ostr, 0); } CPPUNIT_TEST_FIXTURE(Test, testPageBreak) { loadAndReload("fdo74566.docx"); /* Break to next page was written into wrong paragraph as . * LO was not preserving Page Break as . * Now after fix , LO writes Page Break as the new paragraph and also * preserves the xml tag . */ xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); uno::Reference xParagraph2 = getParagraph(2); uno::Reference xParagraph4 = getParagraph(4); getRun(xParagraph2, 1, "First Page Second Line"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:br"_ostr,"type"_ostr,"page"); getRun(xParagraph4, 1, "Second Page First line after Page Break"); } CPPUNIT_TEST_FIXTURE(Test, testOleObject) { loadAndSave("test_ole_object.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object/v:shape/v:imagedata"_ostr, "o:title"_ostr); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject"_ostr, "DrawAspect"_ostr, "Content"); // TODO: ProgID="Package" - what is this? Zip with 10k extra header? // check the rels too xmlDocUniquePtr pXmlDocRels = parseExport("word/_rels/document.xml.rels"); assertXPath(pXmlDocRels, "/rels:Relationships/rels:Relationship[@Target='embeddings/oleObject1.bin']"_ostr, "Type"_ostr, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"); // check the media type too xmlDocUniquePtr pXmlDocCT = parseExport("[Content_Types].xml"); assertXPath(pXmlDocCT, "/ContentType:Types/ContentType:Override[@PartName='/word/embeddings/oleObject1.bin']"_ostr, "ContentType"_ostr, "application/vnd.openxmlformats-officedocument.oleObject"); } CPPUNIT_TEST_FIXTURE(Test, testFdo74792) { loadAndSave("fdo74792.docx"); /* * fdo#74792 : The images associated with smart-art data[i].xml * were not preserved on exporting to DOCX format * Added support to grabbag the rels, with associated images. */ xmlDocUniquePtr pXmlDoc = parseExport("word/diagrams/_rels/data1.xml.rels"); assertXPath(pXmlDoc,"/rels:Relationships/rels:Relationship"_ostr, 4); uno::Reference xNameAccess = packages::zip::ZipFileAccess::createWithURL( comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); //check that images are also saved uno::Reference xInputStream(xNameAccess->getByName( "word/media/OOXDiagramDataRels1_0.jpeg" /*added anchor id to form a unique name*/ ), uno::UNO_QUERY); CPPUNIT_ASSERT( xInputStream.is() ); } CPPUNIT_TEST_FIXTURE(Test, testFdo77718) { loadAndSave("fdo77718.docx"); //in case of multiple smart arts the names for images were getting //repeated and thereby causing a data loss as the binary stream was //getting over written. This test case ensures that unique names are //given for images in different smart arts. xmlDocUniquePtr pXmlDataRels1 = parseExport("word/diagrams/_rels/data1.xml.rels"); xmlDocUniquePtr pXmlDataRels2 = parseExport("word/diagrams/_rels/data2.xml.rels"); //ensure that the rels file is present. assertXPath(pXmlDataRels1,"/rels:Relationships/rels:Relationship"_ostr, 4); assertXPath(pXmlDataRels2,"/rels:Relationships/rels:Relationship"_ostr, 4); uno::Reference xNameAccess = packages::zip::ZipFileAccess::createWithURL( comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); //check that images are also saved uno::Reference xInputStream1(xNameAccess->getByName( "word/media/OOXDiagramDataRels1_0.jpeg" /*added anchor id to form a unique name*/ ), uno::UNO_QUERY); CPPUNIT_ASSERT( xInputStream1.is() ); //check that images are saved for other smart-arts as well. uno::Reference xInputStream2(xNameAccess->getByName( "word/media/OOXDiagramDataRels2_0.jpeg" /*added anchor id to form a unique name*/ ), uno::UNO_QUERY); CPPUNIT_ASSERT( xInputStream2.is() ); } CPPUNIT_TEST_FIXTURE(Test, testTableCurruption) { loadAndSave("tableCurrupt.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/header2.xml"); CPPUNIT_ASSERT(pXmlDoc) ; assertXPath(pXmlDoc, "/w:hdr/w:tbl[1]/w:tr[1]/w:tc[1]"_ostr,1); // tdf#116549: header paragraph should not have a bottom border. uno::Reference xStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY); CPPUNIT_ASSERT(xStyle.is()); uno::Reference xHeaderText = getProperty>(xStyle, "HeaderTextFirst"); CPPUNIT_ASSERT(xHeaderText.is()); auto xParagraph = getParagraphOfText(1, xHeaderText); CPPUNIT_ASSERT(xParagraph.is()); table::BorderLine2 aHeaderBottomBorder = getProperty(xParagraph, "BottomBorder"); CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), aHeaderBottomBorder.LineWidth); } CPPUNIT_TEST_FIXTURE(Test, testDateControl) { loadAndSave("date-control.docx"); // check XML xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date"_ostr, "fullDate"_ostr, "2014-03-05T00:00:00Z"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat"_ostr, "val"_ostr, "dddd, dd' de 'MMMM' de 'yyyy"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:lid"_ostr, "val"_ostr, "es-ES"); assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t"_ostr, u"mi\u00E9rcoles, 05 de marzo de 2014"_ustr); } CPPUNIT_TEST_FIXTURE(Test, test_Tdf115030) { loadAndSave("tdf115030.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); sal_Unicode aDot = {0x02D9}; sal_Unicode aDobleDot = {0x00A8}; assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/m:oMath[1]/m:acc/m:accPr/m:chr"_ostr, "val"_ostr, OUString(aDot)); assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/m:oMath[2]/m:acc/m:accPr/m:chr"_ostr, "val"_ostr, OUString(aDobleDot)); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/m:oMathPara/m:oMath[1]/m:acc/m:accPr/m:chr"_ostr, "val"_ostr, OUString(aDot)); } CPPUNIT_TEST_FIXTURE(Test, test_OpeningBrace) { loadAndSave("2120112713_OpenBrace.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); // Checking for OpeningBrace tag assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/m:oMath[1]/m:d[1]/m:dPr[1]/m:begChr[1]"_ostr,"val"_ostr,""); } CPPUNIT_TEST_FIXTURE(Test, test_Tdf132305) { loadAndSave("tdf132305.docx"); xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/m:oMath[1]/m:bar/m:barPr/m:pos"_ostr,"val"_ostr,"top"); } // Checks that all runs of the field have text properties. // Old behaviour: only first run has text properties of the field // // There are several runs are used in fields: // // //