summaryrefslogtreecommitdiffstats
path: root/sw/qa/filter/ww8/ww8.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa/filter/ww8/ww8.cxx')
-rw-r--r--sw/qa/filter/ww8/ww8.cxx116
1 files changed, 116 insertions, 0 deletions
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 <swmodeltestbase.hxx>
+
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <docsh.hxx>
+#include <formatcontentcontrol.hxx>
+#include <unotxdoc.hxx>
+#include <wrtsh.hxx>
+
+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_<format>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<container::XNameAccess> xStyleFamily = getStyles("PageStyles");
+ uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
+ auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
+ // 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<sal_Int32>(501), nTopMargin);
+ auto aTopBorder = xStyle->getPropertyValue("TopBorder").get<table::BorderLine2>();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(159), aTopBorder.LineWidth);
+ auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get<sal_Int32>();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-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<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+ xText->insertString(xCursor, "beforeafter", /*bAbsorb=*/false);
+ xCursor->gotoStart(/*bExpand=*/false);
+ xCursor->goRight(/*nCount=*/6, /*bExpand=*/true);
+ uno::Reference<beans::XPropertySet> 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<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XShape> xShape(
+ xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
+ xShape->setSize(awt::Size(5000, 5000));
+ uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+ xShapeProps->setPropertyValue("AnchorType", uno::Any(text::TextContentAnchorType_AT_CHARACTER));
+ uno::Reference<text::XTextContent> 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<SwXTextDocument*>(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: */