/* -*- 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/.
*/
CPPUNIT_TEST_FIXTURE(Test, testRelorientation)
{ auto verify = [this](bool bIsExport = false) {
uno::Reference<drawing::XShape> xShape = getShape(1); // This was text::RelOrientation::FRAME, when handling relativeFrom=page, align=right
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xShape, u"HoriOrientRelation"_ustr));
uno::Reference<drawing::XShapes> xGroup(xShape, uno::UNO_QUERY); // This resulted in lang::IndexOutOfBoundsException, as nested groupshapes weren't handled.
uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor(xGroup->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"com.sun.star.drawing.GroupShape"_ustr, 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 (bIsExport)
{
uno::Reference<drawing::XShape> 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<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> 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(u"first"_ustr, xShape->getString()); // This was 16, i.e. inheriting doc default char height didn't work.
CPPUNIT_ASSERT_EQUAL(11.f, getProperty<float>(getParagraphOfText(1, xShape->getText()), u"CharHeight"_ustr));
}
DECLARE_OOXMLEXPORT_TEST(testGroupshapePicture, "groupshape-picture.docx")
{ // Picture in the groupshape got lost, groupshape had only one child.
uno::Reference<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY);
uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor(xGroup->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"com.sun.star.drawing.GraphicObjectShape"_ustr, xShapeDescriptor->getShapeType());
}
CPPUNIT_TEST_FIXTURE(Test, testMsoSpt180)
{
loadAndReload("mso-spt180.docx");
uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY); const uno::Sequence<beans::PropertyValue> aProps = getProperty< uno::Sequence<beans::PropertyValue> >(xGroup->getByIndex(0), u"CustomShapeGeometry"_ustr);
OUString aType; for (beans::PropertyValue const & prop : aProps) if (prop.Name == "Type")
aType = prop.Value.get<OUString>(); // This was exported as borderCallout90, which is an invalid drawingML preset shape string.
CPPUNIT_ASSERT_EQUAL(u"ooxml-borderCallout1"_ustr, aType);
}
CPPUNIT_TEST_FIXTURE(Test, testFdo73550)
{
loadAndSave("fdo73550.docx");
xmlDocUniquePtr pXmlDocument = parseExport(u"word/document.xml"_ustr); // This was wrap="none".
assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:pPr/w:rPr/w:rFonts");
}
DECLARE_OOXMLEXPORT_TEST(testPageRelSize, "pagerelsize.docx")
{ // First shape: width is relative from page, but not height.
uno::Reference<drawing::XShape> xShape = getShape(1);
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xShape, u"RelativeWidthRelation"_ustr));
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xShape, u"RelativeHeightRelation"_ustr));
// Second shape: height is relative from page, but not height.
xShape = getShape(2);
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xShape, u"RelativeHeightRelation"_ustr));
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xShape, u"RelativeWidthRelation"_ustr));
}
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<sal_Int16>(getShape(1), u"RelativeHeight"_ustr));
}
DECLARE_OOXMLEXPORT_TEST(testTestTitlePage, "testTitlePage.docx")
{ // this has 2 pages in Word
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPathContent(pXmlDoc, "/root/page[2]/footer/txt/text()", u"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
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(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol", 3);
sal_Int32 tableWidth = 0;
tableWidth += getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[1]", "w").toInt32();
tableWidth += getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]", "w").toInt32();
tableWidth += getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[3]", "w").toInt32();
CPPUNIT_ASSERT_EQUAL(sal_Int32(3751), tableWidth);
}
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(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblW","type",u"dxa");
}
// 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"
CPPUNIT_TEST_FIXTURE(Test, testFdo73541)
{
loadAndSave("fdo73541.docx"); // fdo#73541: The mirrored margins were not imported and mapped correctly in Page Layout // Hence <w:mirrorMargins /> tag was not exported back in settings.xml
xmlDocUniquePtr pXmlDoc = parseExport(u"word/settings.xml"_ustr);
assertXPath(pXmlDoc, "/w:settings/w:mirrorMargins");
}
CPPUNIT_TEST_FIXTURE(Test, testFDO74215)
{
loadAndSave("FDO74215.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/numbering.xml"_ustr); // 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", "style");
{
OUString sWidth = sStyle.getToken(0, ';');
CPPUNIT_ASSERT(sWidth.startsWith("width:", &sWidth));
CPPUNIT_ASSERT(sWidth.endsWith("pt", &sWidth)); constdouble fWidth = sWidth.toDouble(); constdouble 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)); constdouble fHeight = sHeight.toDouble(); constdouble fYScaleFactor = 96.0 / Application::GetDefaultDevice()->GetDPIY();
CPPUNIT_ASSERT_DOUBLES_EQUAL(11.25 * fYScaleFactor, fHeight, 0.1);
}
}
CPPUNIT_TEST_FIXTURE(Test, testColumnBreak_ColumnCountIsZero)
{ /* fdo73545: Column Break with Column_count = 0 was not getting preserved. * The <w:br w:type="column" /> was missing after roundtrip
*/
loadAndSave("fdo74153.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[1]/w:br", "type", u"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<beans::XPropertySet> xTextSection = getProperty< uno::Reference<beans::XPropertySet> >(getParagraph(45), u"TextSection"_ustr);
CPPUNIT_ASSERT(xTextSection.is());
uno::Reference<text::XTextColumns> xTextColumns = getProperty< uno::Reference<text::XTextColumns> >(xTextSection, u"TextColumns"_ustr);
CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount());
// after that, the section break should switch things back to one column.
xTextSection = getProperty< uno::Reference<beans::XPropertySet> >(getParagraph(50), u"TextSection"_ustr);
CPPUNIT_ASSERT(xTextSection.is());
xTextColumns = getProperty< uno::Reference<text::XTextColumns> >(xTextSection, u"TextColumns"_ustr);
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 <w:ind> 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 <w:ind> does not contain w:right attribute.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:ind", "end");
}
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(u"word/_rels/footer2.xml.rels"_ustr);
// Check footer2.xml.rels contains in doc after roundtrip. // Check Id = rId1 in footer2.xml.rels
assertXPath(pXmlDoc,"/rels:Relationships/rels:Relationship","Id",u"rId1");
assertXPath(pXmlDoc, "/rels:Relationships/rels:Relationship[@Id='rId1']", "Type",
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart");
// check the content too
xmlDocUniquePtr pXmlDocFooter2 = parseExport(u"word/footer2.xml"_ustr);
assertXPath(pXmlDocFooter2, "/w:ftr/w:p[1]/w:r/w:drawing/wp:inline/a:graphic/a:graphicData", "uri",
u"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", "id",
u"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<text::XTextContent> xTextContent(getShape(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xRange = xTextContent->getAnchor();
uno::Reference<text::XText> xText = xRange->getText();
CPPUNIT_ASSERT_EQUAL(u"Anchor point"_ustr, xText->getString());
DECLARE_OOXMLEXPORT_TEST(testFloatingTablePosition, "floating-table-position.docx")
{ // Position of shape was wrong, because some conversion was missing.
uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); // This was 3295.
CPPUNIT_ASSERT_EQUAL(sal_Int32(5964), getProperty<sal_Int32>(xShape, u"HoriOrientPosition"_ustr)); // This was 4611.
CPPUNIT_ASSERT_EQUAL(sal_Int32(8133), getProperty<sal_Int32>(xShape, u"VertOrientPosition"_ustr));
}
CPPUNIT_TEST_FIXTURE(Test, testAbi11739)
{
loadAndSave("abi11739.docx"); // Validation test: order of elements were wrong.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/styles.xml"_ustr); // Order was: uiPriority, link, basedOn.
CPPUNIT_ASSERT(getXPathPosition(pXmlDoc, "/w:styles/w:style[3]", "basedOn") < getXPathPosition(pXmlDoc, "/w:styles/w:style[3]", "link"));
CPPUNIT_ASSERT(getXPathPosition(pXmlDoc, "/w:styles/w:style[3]", "link") < getXPathPosition(pXmlDoc, "/w:styles/w:style[3]", "uiPriority")); // Order was: qFormat, unhideWhenUsed.
CPPUNIT_ASSERT(getXPathPosition(pXmlDoc, "/w:styles/w:style[11]", "unhideWhenUsed") < getXPathPosition(pXmlDoc, "/w:styles/w:style[11]", "qFormat"));
}
CPPUNIT_TEST_FIXTURE(Test, testEmbeddedXlsx)
{ auto verify = [this]() { // check there are two objects and they are FrameShapes
CPPUNIT_ASSERT_EQUAL(2, getShapes());
CPPUNIT_ASSERT_EQUAL(u"FrameShape"_ustr, getShape(1)->getShapeType());
CPPUNIT_ASSERT_EQUAL(u"FrameShape"_ustr, getShape(2)->getShapeType());
};
// check the objects are present in the exported document.xml
xmlDocUniquePtr pXmlDocument = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/w:object", 2);
// finally check the embedded files are present in the zipped document
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); const uno::Sequence<OUString> 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 <w:start> is optional. If not mentioned, * the Numbered list should start from 0. * Problem was LO was writing <w:start> for all levels 0-8 with default value "1".
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/numbering.xml"_ustr);
// Check that we do _not_ export w:start for <w:lvl w:ilvl="0">.
assertXPath(pXmlDoc, "w:numbering/w:abstractNum[1]/w:lvl[1]/w:start", 0);
}
CPPUNIT_TEST_FIXTURE(Test, testPageBreak)
{
loadAndReload("fdo74566.docx"); /* Break to next page was written into wrong paragraph as <w:pageBreakBefore />. * LO was not preserving Page Break as <w:br w:type="page" />. * Now after fix , LO writes Page Break as the new paragraph and also * preserves the xml tag <w:br>.
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
getRun(xParagraph2, 1, u"First Page Second Line"_ustr);
assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r[2]/w:br","type",u"page");
getRun(xParagraph4, 1, u"Second Page First line after Page Break"_ustr);
}
assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object/v:shape/v:imagedata", "o:title");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject", "DrawAspect",
u"Content"); // TODO: ProgID="Package" - what is this? Zip with 10k extra header?
// check the rels too
xmlDocUniquePtr pXmlDocRels = parseExport(u"word/_rels/document.xml.rels"_ustr);
assertXPath(pXmlDocRels, "/rels:Relationships/rels:Relationship[@Target='embeddings/oleObject1.bin']", "Type",
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"); // check the media type too
xmlDocUniquePtr pXmlDocCT = parseExport(u"[Content_Types].xml"_ustr);
assertXPath(pXmlDocCT, "/ContentType:Types/ContentType:Override[@PartName='/word/embeddings/oleObject1.bin']", "ContentType",
u"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(u"word/diagrams/_rels/data1.xml.rels"_ustr);
assertXPath(pXmlDoc,"/rels:Relationships/rels:Relationship", 4);
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(
comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL());
//check that images are also saved
uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName( u"word/media/OOXDiagramDataRels1_0.jpeg"_ustr /*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(u"word/diagrams/_rels/data1.xml.rels"_ustr);
xmlDocUniquePtr pXmlDataRels2 = parseExport(u"word/diagrams/_rels/data2.xml.rels"_ustr);
//ensure that the rels file is present.
assertXPath(pXmlDataRels1,"/rels:Relationships/rels:Relationship", 4);
assertXPath(pXmlDataRels2,"/rels:Relationships/rels:Relationship", 4);
//check that images are also saved
uno::Reference<io::XInputStream> xInputStream1(xNameAccess->getByName( u"word/media/OOXDiagramDataRels1_0.jpeg"_ustr /*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<io::XInputStream> xInputStream2(xNameAccess->getByName( u"word/media/OOXDiagramDataRels2_0.jpeg"_ustr /*added anchor id to form a unique name*/ ), uno::UNO_QUERY);
CPPUNIT_ASSERT( xInputStream2.is() );
}
// 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: // <w:r> // <w:rPr> // <!-- properties written with DocxAttributeOutput::StartRunProperties() / DocxAttributeOutput::EndRunProperties(). // </w:rPr> // <w:fldChar w:fldCharType="begin" /> // </w:r> // <w:r> // <w:rPr> // <!-- properties written with DocxAttributeOutput::DoWriteFieldRunProperties() // </w:rPr> // <w:instrText>TIME \@"HH:mm:ss"</w:instrText> // </w:r> // <w:r> // <w:rPr> // <!-- properties written with DocxAttributeOutput::DoWriteFieldRunProperties() // </w:rPr> // <w:fldChar w:fldCharType="separate" /> // </w:r> // <w:r> // <w:rPr> // <!-- properties written with DocxAttributeOutput::DoWriteFieldRunProperties() // </w:rPr> // <w:t>14:01:13</w:t> // </w:r> // <w:r> // <w:rPr> // <!-- properties written with DocxAttributeOutput::DoWriteFieldRunProperties() // </w:rPr> // <w:fldChar w:fldCharType="end" /> // </w:r> // See, tdf#38778
CPPUNIT_TEST_FIXTURE(Test, testTdf38778)
{
loadAndSave("tdf38778_properties_in_run_for_field.doc");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
// tdf#127862: page fill color (in this case white) was lost
uno::Reference<beans::XPropertySet> xStyle(getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT(drawing::FillStyle_NONE != getProperty<drawing::FillStyle>(xStyle, u"FillStyle"_ustr));
}
CPPUNIT_TEST_FIXTURE(Test, testParagraphWithComments)
{
loadAndSave("paragraphWithComments.docx"); /* Comment id's were getting overwritten for annotation mark(s), which was causing a mismatch in the relationship for comment id's in document.xml and comment.xml
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
xmlDocUniquePtr pXmlComm = parseExport(u"word/comments.xml"_ustr);
CPPUNIT_TEST_FIXTURE(Test, testTdf104707_urlComment)
{
loadAndReload("tdf104707_urlComment.odt");
CPPUNIT_ASSERT_EQUAL(1, getPages());
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); auto aField1 = xFields->nextElement(); // the comment/annotation/postit text auto xText = getProperty< uno::Reference<text::XText> >(aField1, u"TextRange"_ustr); // the hyperlink within the comment text auto xURLField = getProperty< uno::Reference<text::XTextField> >(xText, u"TextField"_ustr); auto aURL = getProperty< OUString >(xURLField, u"URL"_ustr);
CPPUNIT_ASSERT_EQUAL(u"https://bugs.documentfoundation.org/show_bug.cgi?id=104707"_ustr, aURL);
}
CPPUNIT_TEST_FIXTURE(Test, testOLEObjectinHeader)
{
loadAndSave("2129393649.docx"); // fdo#76015 : Document contains oleobject in header xml. // Problem was relationship entry for oleobject from header was // exported into document.xml.rels file because of this rels file // for headers were missing from document/word/rels.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/_rels/header2.xml.rels"_ustr);
// check the media type too
assertXPath(pXmlDocCT, "/ContentType:Types/ContentType:Override[@PartName='/word/embeddings/oleObject1.bin']", "ContentType",
u"application/vnd.openxmlformats-officedocument.oleObject");
#if 0 // Currently LibreOffice exports custom geometry for this up arrow, not preset shape. // When LibreOffice can export preset shape with correct modifiers, then this test can be re-enabled.
CPPUNIT_TEST_FIXTURE(Test, testFileWithInvalidImageLink)
{
loadAndSave("FileWithInvalidImageLink.docx"); /* In case if the original file has an image whose link is invalid, then the RT file used to result in corruption since the exported image would be an empty image.
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
// check the rels too
xmlDocUniquePtr pXmlDocRels = parseExport(u"word/charts/_rels/chart1.xml.rels"_ustr);
assertXPath(pXmlDocRels, "/rels:Relationships/rels:Relationship[@Target='../embeddings/Microsoft_Excel_Macro-Enabled_Worksheet1.xlsm']", "Type",
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"); // check the content too
xmlDocUniquePtr pXmlDocChart1 = parseExport(u"word/charts/chart1.xml"_ustr);
assertXPath(pXmlDocChart1, "/c:chartSpace/c:externalData", "id",
u"rId1");
}
CPPUNIT_TEST_FIXTURE(Test, test76108)
{
loadAndSave("test76108.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); //docx file after RT is getting corrupted.
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[1]/w:fldChar[1]", "fldCharType", u"begin");
}
CPPUNIT_TEST_FIXTURE(Test, testTCTagMisMatch)
{
loadAndSave("TCTagMisMatch.docx"); // TCTagMisMatch.docx : This document contains an empty table with borders. // there was a TC tag mismatch which resulted into a crash.
CPPUNIT_TEST_FIXTURE(Test, testFDO78292)
{
loadAndSave("FDO78292.docx"); //text node is a leaf node, it should not have any children
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc,"/w:document/w:body/w:p[14]/w:sdt[3]/w:sdtPr[1]/w:text/w14:checked",0);
}
// check the content too
xmlDocUniquePtr pXmlDocContent = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDocContent, "/w:document/w:body/w:p/w:r/w:object/o:OLEObject", "ProgID",
u"Excel.Chart.8");
}
CPPUNIT_TEST_FIXTURE(Test, testTdf83227)
{
loadAndReload("tdf83227.docx"); // Bug document contains a rotated image, which is handled as a draw shape (not as a Writer image) on export.
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL());
CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName(u"word/media/image1.png"_ustr))); // This was also true, image was written twice.
CPPUNIT_ASSERT_EQUAL(false, bool(xNameAccess->hasByName(u"word/media/image2.png"_ustr)));
}
CPPUNIT_TEST_FIXTURE(Test, testTdf103001)
{
loadAndReload("tdf103001.docx"); // The same image is featured in the header and in the body text, make sure // the header relation is still written, even when caching is enabled.
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); // This failed: header reused the RelId of the body text, even if RelIds // are local to their stream.
CPPUNIT_ASSERT(xNameAccess->hasByName(u"word/_rels/header2.xml.rels"_ustr));
}
CPPUNIT_TEST_FIXTURE(Test, testTdf92521)
{
loadAndSave("tdf92521.odt");
CPPUNIT_ASSERT_EQUAL(2, getPages());
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // There should be a section break that's in the middle of the document: right after the table.
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:sectPr", 1);
}
DECLARE_OOXMLEXPORT_TEST(testTdf102466, "tdf102466.docx")
{ // the problem was: file is truncated: the first page is missing. // More precisely, the table in the first page was clipped.
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
sal_Int32 nFlyPrtHeight = getXPath(pXmlDoc, "(/root/page[1]//anchored/fly)[1]/infos/prtBounds", "height").toInt32();
sal_Int32 nTableHeight = getXPath(pXmlDoc, "(/root/page[1]//anchored/fly)[1]/tab/infos/bounds", "height").toInt32();
CPPUNIT_ASSERT_MESSAGE("The table is clipped in a fly frame.", nFlyPrtHeight >= nTableHeight);
}
// check how much pages we have: it should match the Word layout result
CPPUNIT_ASSERT_EQUAL(11, getPages());
// check content of the first page
{
uno::Reference<beans::XPropertySet> xFrame(getShapeByName(u"Marco1"), uno::UNO_QUERY);
// no border
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xFrame, u"LineWidth"_ustr));
}
// Make sure we have 19 tables created
{
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
CPPUNIT_ASSERT(xTables->getCount() >= sal_Int32(19)); // TODO
// check the text inside first cell of the first table
uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xCell(xTable->getCellByName(u"A1"_ustr), uno::UNO_QUERY);
const OUString aActualText = xCell->getString();
CPPUNIT_ASSERT(aActualText.indexOf("Requerimientos del Cliente") > 0);
}
}
CPPUNIT_TEST_FIXTURE(Test, testTdf99090_pgbrkAfterTable)
{
loadAndSave("tdf99090_pgbrkAfterTable.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // There should be a regular page break that's in the middle of the document: right after the table.
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:br", 1);
}
DECLARE_OOXMLEXPORT_TEST(testTdf64372_continuousBreaks,"tdf64372_continuousBreaks.docx")
{ //There are no page breaks, so everything should be on the first page.
CPPUNIT_ASSERT_EQUAL(1, getPages());
}
DECLARE_OOXMLEXPORT_TEST(testTdf92724_continuousBreaksComplex,"tdf92724_continuousBreaksComplex.docx")
{ //There are 2 page breaks, so there should be 3 pages.
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
DECLARE_OOXMLEXPORT_TEST(testTdf90697_continuousBreaksComplex2,"tdf92724_continuousBreaksComplex2.docx")
{ // Continuous section breaks with new headers/footers should not immediately switch to a new page style.
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
xCursor->jumpToLastPage();
sal_Int16 nPages = xCursor->getPage(); while( nPages > 0 )
{
OUString sPageStyleName = getProperty<OUString>( xCursor, u"PageStyleName"_ustr );
uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles(u"PageStyles"_ustr)->getByName(sPageStyleName), u"HeaderText"_ustr); // Specific case to avoid. Testing separately (even though redundant). // The first header (defined on page 3) ONLY is shown IF the section happens to start on a new page (which it doesn't in this document).
CPPUNIT_ASSERT( xHeaderText->getString() != "Third section - First page header. No follow defined" ); // Same test stated differently: Pages 4 and 5 OUGHT to use "Second section header", but currently don't. Page 6 does. if( nPages <= 3 )
CPPUNIT_ASSERT_EQUAL( u"First section header"_ustr, xHeaderText->getString() ); else
CPPUNIT_ASSERT( xHeaderText->getString() == "First section header" || xHeaderText->getString() == "Second section header" );
#if HAVE_MORE_FONTS
DECLARE_OOXMLEXPORT_TEST(testTdf81345_045Original, "tdf81345.docx")
{ //Header wasn't replaced and columns were missing because no new style was created.
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
// tdf89297 Styles were being added before their base/parent/inherited-from style existed, and so were using default settings.
uno::Reference<container::XNameAccess> xParaStyles(getStyles(u"ParagraphStyles"_ustr));
uno::Reference<beans::XPropertySet> xStyle(xParaStyles->getByName(u"Pull quote"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(6736947), getProperty<sal_Int32>(xStyle, u"CharColor"_ustr));
} #endif
// the exported positions were wrong due to some missing shifting in the export code
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblpPr", "tblpX", u"3494");
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblpPr", "tblpY", u"4611");
} #if 0 // FIXME:
CPPUNIT_TEST_FIXTURE(Test, testUnderlineGroupShapeText)
{
loadAndSave("tdf123351_UnderlineGroupSapeText.docx"); // tdf#123351: Check if correct underline is used.
xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml");
// TODO: Import of "words". // This must fail when import of "words" is implemented. This is a temporary solution, we read "words" as "single".
assertXPath(pXmlDocument, "/w:document/w:body/w:p[32]/w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor" "/a:graphic/a:graphicData/wpg:wgp/wps:wsp[2]/wps:txbx/w:txbxContent/w:p/w:r/w:rPr/w:u", "val", "single");
} #endif
CPPUNIT_TEST_FIXTURE(Test, testUnderlineColorGroupedShapes)
{
loadAndSave("tdf132491_UnderlineColorGroupedShapes.docx"); // tdf#132491 : Check if correct color is used for underline.
xmlDocUniquePtr pXmlDocument = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor" "/a:graphic/a:graphicData/wpg:wgp/wps:wsp[1]/wps:txbx/w:txbxContent/w:p/w:r/w:rPr/w:u", "color", u"FF0000");
assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor" "/a:graphic/a:graphicData/wpg:wgp/wps:wsp[2]/wps:txbx/w:txbxContent/w:p/w:r/w:rPr/w:u", "color", u"00B050");
assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor" "/a:graphic/a:graphicData/wpg:wgp/wps:wsp[3]/wps:txbx/w:txbxContent/w:p/w:r/w:rPr/w:u", "color");
}
CPPUNIT_TEST_FIXTURE(Test, testRelativeAnchorWidthFromRightMargin)
{
loadAndSave("tdf133670_testRelativeAnchorWidthFromRightMargin.docx"); // tdf#133670 The width was set relative from right margin, but this was handled relative from page width.
xmlDocUniquePtr pXmlDoc = parseLayoutDump(); auto nWidth = getXPath(pXmlDoc, "//anchored/SwAnchoredDrawObject/bounds", "width").toInt32();
CPPUNIT_ASSERT_DOUBLES_EQUAL(2408, nWidth, 1);
}
CPPUNIT_TEST_FIXTURE(Test, testAutoFitForLegacyShapes)
{
loadAndSave("tdf112312_AutoFitForLegacyShapes.odt"); // tdf#112312: check if noAutoFit is used instead of spAutoFit even if the TextAutoGrowHeight is set
xmlDocUniquePtr pXmlDocument = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:bodyPr/a:noAutofit");
assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:bodyPr", "a:spAutofit");
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.23Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.