From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sw/qa/filter/ww8/data/negative-page-border.doc | Bin 0 -> 22528 bytes sw/qa/filter/ww8/ww8.cxx | 116 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 sw/qa/filter/ww8/data/negative-page-border.doc create mode 100644 sw/qa/filter/ww8/ww8.cxx (limited to 'sw/qa/filter/ww8') diff --git a/sw/qa/filter/ww8/data/negative-page-border.doc b/sw/qa/filter/ww8/data/negative-page-border.doc new file mode 100644 index 000000000..6ea5e9030 Binary files /dev/null and b/sw/qa/filter/ww8/data/negative-page-border.doc differ diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx new file mode 100644 index 000000000..9268a9943 --- /dev/null +++ b/sw/qa/filter/ww8/ww8.cxx @@ -0,0 +1,116 @@ +/* -*- 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 + +namespace +{ +constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/filter/ww8/data/"; + +/** + * Covers sw/source/filter/ww8/ fixes. + * + * Note that these tests are meant to be simple: either load a file and assert some result or build + * a document model with code, export and assert that result. + * + * Keep using the various sw_import/export suites for multiple filter calls inside a single + * test. + */ +class Test : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorderDocImport) +{ + // Given a document with a border distance that is larger than the margin, when loading that + // document: + createSwDoc(DATA_DIRECTORY, "negative-page-border.doc"); + + // Then make sure we map that to a negative border distance (move border from the edge of body + // frame towards the center of the page, not towards the edge of the page): + uno::Reference xStyleFamily = getStyles("PageStyles"); + uno::Reference xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY); + auto nTopMargin = xStyle->getPropertyValue("TopMargin").get(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 501 + // - Actual : 342 + // i.e. the border properties influenced the margin, which was 284 twips in the sprmSDyaTop + // SPRM. + CPPUNIT_ASSERT_EQUAL(static_cast(501), nTopMargin); + auto aTopBorder = xStyle->getPropertyValue("TopBorder").get(); + CPPUNIT_ASSERT_EQUAL(static_cast(159), aTopBorder.LineWidth); + auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get(); + CPPUNIT_ASSERT_EQUAL(static_cast(-646), nTopBorderDistance); +} + +CPPUNIT_TEST_FIXTURE(Test, testDocxHyperlinkShape) +{ + // Given a document with a hyperlink at char positions 0 -> 6 and a shape with text anchored at + // char position 6: + mxComponent = loadFromDesktop("private:factory/swriter"); + uno::Reference xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "beforeafter", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->goRight(/*nCount=*/6, /*bExpand=*/true); + uno::Reference xCursorProps(xCursor, uno::UNO_QUERY); + xCursorProps->setPropertyValue("HyperLinkURL", uno::Any(OUString("http://www.example.com/"))); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->goRight(/*nCount=*/6, /*bExpand=*/false); + uno::Reference xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference xShape( + xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY); + xShape->setSize(awt::Size(5000, 5000)); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + xShapeProps->setPropertyValue("AnchorType", uno::Any(text::TextContentAnchorType_AT_CHARACTER)); + uno::Reference xShapeContent(xShape, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xShapeContent, /*bAbsorb=*/false); + xShapeProps->setPropertyValue("TextBox", uno::Any(true)); + + // When saving this document to DOCX, then make sure we don't crash on export (due to an + // assertion failure for not-well-formed XML output): + save("Office Open XML Text", maTempFile); +} + +CPPUNIT_TEST_FIXTURE(Test, testDocxContentControlDropdownEmptyDisplayText) +{ + // Given a document with a dropdown content control, the only list item has no display text + // (only a value): + mxComponent = loadFromDesktop("private:factory/swriter"); + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc()); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // When saving to DOCX: + save("Office Open XML Text", maTempFile); + mbExported = true; + + // Then make sure that no display text attribute is written: + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + CPPUNIT_ASSERT(pXmlDoc); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//w:sdt/w:sdtPr/w:dropDownList/w:listItem' unexpected 'displayText' attribute + // i.e. we wrote an empty attribute instead of omitting it. + assertXPathNoAttribute(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem", "displayText"); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3