/* -*- 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/.
*/
class Test : public SwModelTestBase
{ public:
Test() : SwModelTestBase(u"/sw/qa/extras/ooxmlexport/data/"_ustr, u"Office Open XML Text"_ustr) {}
};
CPPUNIT_TEST_FIXTURE(Test, testFDO76248)
{
loadAndSave("FDO76248.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // In two cases the a:graphicData elements had no children, which is invalid.
assertXPath(pXmlDoc, "//a:graphicData[not(*)]", 0);
}
DECLARE_OOXMLEXPORT_TEST(testTscp, "tscp.docx")
{
uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, u"urn:bails"_ustr);
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(mxComponent, uno::UNO_QUERY);
uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType); // This failed, no graphs had the urn:bails type.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aGraphNames.getLength());
uno::Reference<rdf::XURI> xGraphName = aGraphNames[0];
uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
// No RDF statement on the first paragraph.
uno::Reference<rdf::XResource> xParagraph(getParagraph(1), uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xParagraph, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(xStatements->hasMoreElements()));
// No RDF statement on the third paragraph.
xParagraph.set(getParagraph(3), uno::UNO_QUERY);
xStatements = xGraph->getStatements(xParagraph, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(xStatements->hasMoreElements()));
}
CPPUNIT_TEST_FIXTURE(Test, testfdo76589 )
{
loadAndSave("fdo76589.docx"); /* Numbered list was not preserve after RT. * In numbering.xml, when NumberingType is "decimal" and level is zero, * w:val of w:lvlText was empty. * It should be <w:lvlText w:val="%1" />
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/numbering.xml"_ustr);
CPPUNIT_TEST_FIXTURE(Test, testDecimalNumberingNoLeveltext)
{
loadAndSave("decimal-numbering-no-leveltext.docx"); // This was "%1", not empty: we turned a kind-of-none numbering into a decimal one.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/numbering.xml"_ustr);
assertXPath(pXmlDoc, "/w:numbering/w:abstractNum[1]/w:lvl[1]/w:lvlText","val",u"");
}
CPPUNIT_TEST_FIXTURE(Test, testNoDuplicateAttributeExport)
{
loadAndSave("duplicate-east-asia.odt");
CPPUNIT_ASSERT_EQUAL(1, getShapes());
CPPUNIT_ASSERT_EQUAL(1, getPages()); // File asserting while saving in LO.
parseExport(u"word/document.xml"_ustr);
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79008)
{
loadAndReload("fdo79008.docx"); /* File crashing while saving in LO. * Check if document.xml file is created after fix
*/
parseExport(u"word/document.xml"_ustr);
// tdf#134951: there is only one comment
xmlDocUniquePtr pXmlSettings = parseExport(u"word/comments.xml"_ustr);
assertXPath(pXmlSettings, "/w:comments/w:comment", 1);
// Read-only is set, but it is not enforced, so it should be off...
CPPUNIT_ASSERT(!getSwDocShell()->IsSecurityOptOpenReadOnly());
}
CPPUNIT_TEST_FIXTURE(Test, testTdf120852_readOnlyProtection)
{
createSwDoc("tdf120852_readOnlyProtection.docx"); // Read-only is set, so Enforcement must enable it.
CPPUNIT_ASSERT(getSwDocShell()->IsSecurityOptOpenReadOnly());
CPPUNIT_TEST_FIXTURE(Test, testTdf120852_readOnlyUnProtected)
{ auto verify = [this](bool bIsExport = false) { // Readonly is not enforced, just a suggestion, // so when a section is protected, the document should enable forms protection.
CPPUNIT_ASSERT(!getSwDocShell()->IsSecurityOptOpenReadOnly());
uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY_THROW); const sal_Int32 nLastSection = xSections->getCount() - 1;
uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(nLastSection), uno::UNO_QUERY_THROW); if ( !bIsExport )
{
CPPUNIT_ASSERT_MESSAGE("Section is not protected", !getProperty<bool>(xSect, u"IsProtected"_ustr)); // Enable section protection. The round-trip should have forms protection enabled.
xSect->setPropertyValue(u"IsProtected"_ustr, uno::Any(true));
} else
{
CPPUNIT_ASSERT_MESSAGE("Section is protected", getProperty<bool>(xSect, u"IsProtected"_ustr));
xmlDocUniquePtr pXmlSettings = parseExport(u"word/settings.xml"_ustr);
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", u"forms");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", u"true");
}
};
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "xpath", u"/ns1:coreProperties[1]/ns0:creator[1]");
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "storeItemID",u"{6C3C8BC8-F283-45AE-878A-BAB7291924A1}"); // FIXME: the next property doesn't match, though it's correct in theory. A bug in assertXPath? // assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:dataBinding", "prefixMappings", // "xmlns:ns0='http://purl.org/dc/elements/1.1/' xmlns:ns1='http://schemas.openxmlformats.org/package/2006/metadata/core-properties'");
}
CPPUNIT_TEST_FIXTURE(Test, testFDO76586)
{
loadAndSave("fdo76586.docx"); /* * In the test file gridCol had only one value for entire table width * while there are two cells in a table row. * So the table was not imported with the correct cell widths
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
// there is only one table in the test file
assertXPath(pXmlDoc, "//w:tblGrid/w:gridCol[1]", "w", u"1601");
assertXPath(pXmlDoc, "//w:tblGrid/w:gridCol[2]", "w", u"7844");
}
CPPUNIT_TEST_FIXTURE(Test, testFDO77890 )
{
loadAndSave("fdo77890.docx"); /* Ensure that the page break is preserved i.e it should not be converted to a section break, in case if the different first page is set for the pages in the document. For additional comments please refer to https://www.libreoffice.org/bugzilla/show_bug.cgi?id=77890#c2
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r[2]/w:br", "type", u"page");
}
CPPUNIT_TEST_FIXTURE(Test, testNumberedList)
{
loadAndReload("NumberedList.docx"); //fdo74150:In document.xml, for pStyle = "NumberedList1", iLvl and numId was not preserved
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p[1]/w:pPr[1]/w:pStyle", "val", u"NumberedList1");
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p[1]/w:pPr[1]/w:numPr/w:ilvl","val", u"0");
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p[1]/w:pPr[1]/w:numPr/w:numId","val", u"0");
DECLARE_OOXMLEXPORT_TEST(testFDO77117, "fdo77117.docx")
{
uno::Reference<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xShape(xGroup->getByIndex(0), uno::UNO_QUERY); // This checks textbox textrun size of font which is in group shape.
CPPUNIT_ASSERT_EQUAL(11.f, getProperty<float>(xShape, u"CharHeight"_ustr));
}
//make sure not to write empty attributes which requires enumeration
assertXPathNoAttribute(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tblPr[1]/w:tblpPr[1]", "tblpYSpec");
}
// Check tdf#161202 - this document has all kinds of tables inside hidden sections. // The page count must be 13, but for unclear reason, it is 12 in some tests on Linux // (maybe the layout hasn't finished?). // Without the fix, it was 52.
CPPUNIT_ASSERT_LESSEQUAL(13, getPages());
}
// Problem :If the table preferred width is in percent, then after RT it changes to 0 & width type changes // to 'auto' instead of 'pct'.
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tblPr[1]/w:tblW[1]", "w", u"3000");
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:tbl[1]/w:tblPr[1]/w:tblW[1]", "type",u"pct");
}
CPPUNIT_TEST_FIXTURE(Test, testFieldRotation)
{
loadAndReload("field-rotated.fodt");
uno::Reference<text::XTextRange> const xRun(getRun(uno::Reference<text::XTextRange>(getParagraphOrTable(1), uno::UNO_QUERY), 1));
uno::Reference<text::XTextField> const xField(getProperty<uno::Reference<text::XTextField>>(xRun, u"TextField"_ustr));
CPPUNIT_ASSERT(xField.is());
CPPUNIT_ASSERT_EQUAL(u"DocInformation:Title"_ustr, xField->getPresentation(true));
CPPUNIT_ASSERT_EQUAL(u"Rotationeering"_ustr, xField->getPresentation(false)); // problem was that the rotation wasn't applied to all runs of the field
CPPUNIT_ASSERT_EQUAL(sal_Int16(900), getProperty<sal_Int16>(xRun, u"CharRotation"_ustr));
}
CPPUNIT_TEST_FIXTURE(Test, testPageBreakInFirstPara)
{
loadAndReload("fdo77727.docx"); /* Break to next page was not exported if it is in first paragraph of the section. * Now after fix , LO writes Next Page Break and also preserves <w:br> tag.
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[2]/w:br[1]", 1);
assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[1]/w:t[1]", u"Tab and line break");
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[5]/w:br[1]", 1);
assertXPathContent(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[6]/w:t[1]", u"New line");
}
CPPUNIT_TEST_FIXTURE(Test, testFdo78651)
{
loadAndSave("fdo78651.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // ensure that there are only two tables
assertXPath(pXmlDoc, "//w:tbl", 2);
}
// Ensure that Section Break is getting written inside second paragraph
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[2]/w:pPr[1]/w:sectPr[1]",1);
// Ensure that no dummy paragraph gets created inside second paragraph for Section Break
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[2]/w:p[1]/w:pPr[1]/w:sectPr[1]",0);
}
CPPUNIT_TEST_FIXTURE(Test, testfdo76934)
{
loadAndSave("fdo76934.docx"); /* Issue was, AutoSpacing property if present inside styles.xml, LO was not able to * preserve it.
*/
// Ensure that after fix LO is preserving AutoSpacing property in styles.xml
assertXPath ( pXmlDoc, "/w:styles[1]/w:style[@w:styleId='Title']/w:pPr[1]/w:spacing[1]", "beforeAutospacing", u"1" );
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79540)
{
loadAndSave("fdo79540.docx"); /* Issue was, <w:drawing> was getting written inside <w:drawing>. * So postpone the writing of Inner Drawing tag. * MS Office does not allow nesting of drawing tags.
*/
// Ensure that two separate w:drawing tags are written and they are not nested.
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing", 1);
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing", 1);
}
// The text in the separator footnote should not be added to the footnotes
CPPUNIT_ASSERT_EQUAL(u" Microsoft Office."_ustr, xFootnoteText->getString());
// Ensure that paragraph markers are not lost.
xFootnoteText.set(xFootnotes->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Number of paragraphs in second footnote", 2, getParagraphs(xFootnoteText) );
// tdf#136706: Two useless page styles were created for each of the four footnotes.
CPPUNIT_ASSERT( !getStyles(u"PageStyles"_ustr)->hasByName(u"Converted8"_ustr) );
CPPUNIT_ASSERT( !getStyles(u"PageStyles"_ustr)->hasByName(u"Converted1"_ustr) );
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79668)
{
loadAndReload("fdo79668.docx"); // fdo#79668: Document was Crashing on DebugUtil build while Saving // because of repeated attribute value in same element.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // w:pPr's w:shd attributes were getting added to w:pPrChange/w:pPr's w:shd hence checking // w:fill for both shd elements
assertXPath ( pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:shd", "fill", u"FFFFFF" );
assertXPath ( pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:pPrChange/w:pPr/w:shd", "fill", u"FFFFFF" );
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79822)
{
loadAndSave("fdo79822.docx"); /* File getting crash while saving in LO. * The Docx contain smartart and the file was created in ms word 2007
*/
parseExport(u"word/document.xml"_ustr);
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79968_sldx)
{
loadAndSave("fdo79968.docx"); // This UT for DOCX embedded with powerpoint slide
xmlDocUniquePtr pXmlDoc = parseExport(u"[Content_Types].xml"_ustr);
// check the rels too
xmlDocUniquePtr pXmlDocRels = parseExport(u"word/_rels/document.xml.rels"_ustr);
assertXPath(pXmlDocRels, "/rels:Relationships/rels:Relationship[@Target='embeddings/oleObject1.sldx']", "Type",
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"); // check the content too
xmlDocUniquePtr pXmlDocContent = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDocContent, "/w:document/w:body/w:p[1]/w:r/w:object/o:OLEObject", "ProgID",
u"PowerPoint.Slide.12");
}
CPPUNIT_TEST_FIXTURE(Test, testLostFooterStyle)
{ // Given a document with many numberings and a Footer para style:
loadAndSave("lost-footer-style.docx");
// When saving that to DOCX and checking the Footer style:
xmlDocUniquePtr pXmlDoc = parseExport(u"word/styles.xml"_ustr); // Without the accompanying fix in place, this test would have failed, the Footer style was // lost on export due to the many ListLabel char styles.
OUString aType = getXPath(pXmlDoc, "/w:styles/w:style[@w:styleId='Footer']", "type");
// Then make sure we have a Footer para style:
CPPUNIT_ASSERT_EQUAL(u"paragraph"_ustr, aType);
}
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.