From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 243 +++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx (limited to 'sw/qa/extras/ooxmlexport/ooxmlexport15.cxx') diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx new file mode 100644 index 000000000..1fd8ad4a7 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -0,0 +1,243 @@ +/* -*- 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 + +char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/"; + +class Test : public SwModelTestBase +{ +public: + Test() : SwModelTestBase(DATA_DIRECTORY, "Office Open XML Text") {} + +protected: + /** + * Blacklist handling + */ + bool mustTestImportOf(const char* filename) const override { + // If the testcase is stored in some other format, it's pointless to test. + return OString(filename).endsWith(".docx"); + } +}; + +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf123621, "tdf123621.docx") +{ + xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml"); + if (!pXmlDocument) + return; + + assertXPathContent(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor" + "/wp:positionV/wp:posOffset", "1080135"); +} + + +DECLARE_OOXMLEXPORT_TEST(testTdf133334_followPgStyle, "tdf133334_followPgStyle.odt") +{ + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + +DECLARE_OOXMLEXPORT_TEST(testTdf133370_columnBreak, "tdf133370_columnBreak.odt") +{ + // Since non-DOCX formats ignores column breaks in non-column situtations, don't export to docx. + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + +DECLARE_OOXMLEXPORT_TEST(testTdf131801, "tdf131801.docx") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + xmlDocUniquePtr pDump = parseLayoutDump(); + // "1." is red + CPPUNIT_ASSERT_EQUAL(OUString("1."), getXPath(pDump, "//page[1]/body/txt[1]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[1]/Special/SwFont", "color")); + // "2." is red + CPPUNIT_ASSERT_EQUAL(OUString("2."), getXPath(pDump, "//page[1]/body/txt[2]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[2]/Special/SwFont", "color")); + // "3." is black + CPPUNIT_ASSERT_EQUAL(OUString("3."), getXPath(pDump, "//page[1]/body/txt[3]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[3]/Special/SwFont", "color")); + // "4." is black + CPPUNIT_ASSERT_EQUAL(OUString("4."), getXPath(pDump, "//page[1]/body/txt[4]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[4]/Special/SwFont", "color")); + // "5." is red + CPPUNIT_ASSERT_EQUAL(OUString("5."), getXPath(pDump, "//page[1]/body/txt[5]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[5]/Special/SwFont", "color")); + // "6." is red + CPPUNIT_ASSERT_EQUAL(OUString("6."), getXPath(pDump, "//page[1]/body/txt[6]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[6]/Special/SwFont", "color")); + // "7." is black + CPPUNIT_ASSERT_EQUAL(OUString("7."), getXPath(pDump, "//page[1]/body/txt[7]/Special", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[7]/Special/SwFont", "color")); + // "8." is black + CPPUNIT_ASSERT_EQUAL(OUString("8."), getXPath(pDump, "//page[1]/body/txt[8]/Special[1]", "rText")); + CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[8]/Special[1]/SwFont", "color")); + + xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml"); + if (!pXmlDocument) + return; + + assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:rStyle", + "val", "Emphasis"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:pPr/w:rPr/w:rStyle", + "val", "Emphasis"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[3]/w:pPr/w:rPr/w:rStyle", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[4]/w:pPr/w:rPr/w:rStyle", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:pPr/w:rPr/w:rStyle", + "val", "Emphasis"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:pPr/w:rPr/w:sz", + "val", "32"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[6]/w:pPr/w:rPr/w:rStyle", + "val", "Emphasis"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[6]/w:pPr/w:rPr/w:sz", + "val", "32"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[7]/w:pPr/w:rPr/w:rStyle", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:p[8]/w:pPr/w:rPr/w:rStyle", 0); +} + +DECLARE_OOXMLEXPORT_TEST(testTdf135973, "tdf135973.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + { + uno::Reference xPara(getParagraph(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty(xPara, "ListLabelString")); + } + { + uno::Reference xPara(getParagraph(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2."), getProperty(xPara, "ListLabelString")); + } + { + uno::Reference xPara(getParagraph(5), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty(xPara, "ListLabelString")); + } + { + uno::Reference xPara(getParagraph(6), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2."), getProperty(xPara, "ListLabelString")); + } +} + +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf136441_commentInFootnote, "tdf136441_commentInFootnote.odt") +{ + // failed to load without error if footnote contained a comment. + // (MS Word's UI doesn't allow adding comments to a footnote.) +} + +DECLARE_OOXMLEXPORT_TEST(testTdf134063, "tdf134063.docx") +{ + CPPUNIT_ASSERT_EQUAL(2, getPages()); + + xmlDocUniquePtr pDump = parseLayoutDump(); + + // There are three tabs with default width + CPPUNIT_ASSERT_EQUAL(sal_Int32(720), getXPath(pDump, "//page[1]/body/txt[1]/Text[1]", "nWidth").toInt32()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(720), getXPath(pDump, "//page[1]/body/txt[1]/Text[2]", "nWidth").toInt32()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(720), getXPath(pDump, "//page[1]/body/txt[1]/Text[3]", "nWidth").toInt32()); +} + +DECLARE_OOXMLEXPORT_TEST(testTdf135665, "tdf135665.docx") +{ + uno::Reference xOLEProps1(getShape(1), uno::UNO_QUERY_THROW); + uno::Reference xOLEProps2(getShape(2), uno::UNO_QUERY_THROW); + bool bSurroundContour1 = false; + bool bSurroundContour2 = false; + xOLEProps1->getPropertyValue("SurroundContour") >>= bSurroundContour1; + xOLEProps2->getPropertyValue("SurroundContour") >>= bSurroundContour2; + + CPPUNIT_ASSERT_EQUAL_MESSAGE("OLE tight wrap setting not imported correctly", true, bSurroundContour1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("OLE tight wrap setting not imported correctly", false, bSurroundContour2); +} + +DECLARE_OOXMLEXPORT_TEST(testAtPageShapeRelOrientation, "rotated_shape.fodt") +{ + // invalid combination of at-page anchor and horizontal-rel="paragraph" + // caused relativeFrom="column" instead of relativeFrom="page" + + xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml"); + if (!pXmlDocument) + return; + + assertXPathContent(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor" + "/wp:positionH/wp:posOffset", "-480060"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor" + "/wp:positionH", "relativeFrom", "page"); + assertXPathContent(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor" + "/wp:positionV/wp:posOffset", "8147685"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor" + "/wp:positionV", "relativeFrom", "page"); + + // same for sw + assertXPathContent(pXmlDocument, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor" + "/wp:positionH/wp:posOffset", "720090"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor" + "/wp:positionH", "relativeFrom", "page"); + assertXPathContent(pXmlDocument, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor" + "/wp:positionV/wp:posOffset", "1080135"); + assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor" + "/wp:positionV", "relativeFrom", "page"); + + // now test text rotation -> VML writing direction + assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Fallback/w:pict/v:shape/v:textbox", "style", "mso-layout-flow-alt:bottom-to-top"); + // text wrap -> VML + assertXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Fallback/w:pict/v:shape/w10:wrap", "type", "none"); + // vertical alignment -> VML + OUString const style = getXPath(pXmlDocument, "/w:document/w:body/w:p/w:r/mc:AlternateContent[1]/mc:Fallback/w:pict/v:shape", "style"); + CPPUNIT_ASSERT(style.indexOf("v-text-anchor:middle") != -1); +} + +DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromBottomMarginHasFooter, + "tdf133070_testRelativeAnchorHeightFromBottomMarginHasFooter.docx") +{ + // TODO: fix export too + if (mbExported) + return; + // tdf#133070 The height was set relative to page print area bottom, + // but this was handled relative to page height. + // Note: page print area bottom = margin + footer height. + // In this case the footer exists. + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + const sal_Int32 nAnchoredHeight + = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height").toInt32(); + CPPUNIT_ASSERT_EQUAL(static_cast(1147), nAnchoredHeight); +} + +DECLARE_OOXMLEXPORT_TEST(TestTdf132483, "tdf132483.docx") +{ + uno::Reference xOLEProps(getShape(1), uno::UNO_QUERY_THROW); + sal_Int16 nVRelPos = -1; + sal_Int16 nHRelPos = -1; + xOLEProps->getPropertyValue("VertOrientRelation") >>= nVRelPos; + xOLEProps->getPropertyValue("HoriOrientRelation") >>= nHRelPos; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The OLE is shifted vertically", + text::RelOrientation::PAGE_FRAME , nVRelPos); + CPPUNIT_ASSERT_EQUAL_MESSAGE("The OLE is shifted horizontally", + text::RelOrientation::PAGE_FRAME , nHRelPos); +} + +DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromBottomMarginNoFooter, + "tdf133070_testRelativeAnchorHeightFromBottomMarginNoFooter.docx") +{ + // TODO: fix export too + if (mbExported) + return; + // tdf#133070 The height was set relative to page print area bottom, + // but this was handled relative to page height. + // Note: page print area bottom = margin + footer height. + // In this case the footer does not exist, so OpenDocument and OOXML margins are the same. + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + const sal_Int32 nAnchoredHeight + = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height").toInt32(); + CPPUNIT_ASSERT_EQUAL(static_cast(1147), nAnchoredHeight); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3