summaryrefslogtreecommitdiffstats
path: root/sw/qa/core/objectpositioning/objectpositioning.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /sw/qa/core/objectpositioning/objectpositioning.cxx
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/qa/core/objectpositioning/objectpositioning.cxx')
-rw-r--r--sw/qa/core/objectpositioning/objectpositioning.cxx75
1 files changed, 75 insertions, 0 deletions
diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx
new file mode 100644
index 000000000..d0431764b
--- /dev/null
+++ b/sw/qa/core/objectpositioning/objectpositioning.cxx
@@ -0,0 +1,75 @@
+/* -*- 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/VertOrientation.hpp>
+
+#include <wrtsh.hxx>
+
+static char const DATA_DIRECTORY[] = "/sw/qa/core/objectpositioning/data/";
+
+/// Covers sw/source/core/objectpositioning/ fixes.
+class SwCoreObjectpositioningTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testOverlapCrash)
+{
+ // Load a document with 2 images.
+ load(DATA_DIRECTORY, "overlap-crash.odt");
+
+ // Change their anchor type to to-char.
+ uno::Reference<beans::XPropertySet> xShape1(getShape(1), uno::UNO_QUERY);
+ xShape1->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+ uno::Reference<beans::XPropertySet> xShape2(getShape(1), uno::UNO_QUERY);
+ xShape2->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+
+ // Insert a new paragraph at the start.
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDocShell* pDocShell = pTextDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ // Without the accompanying fix in place, this test would have crashed.
+ pWrtShell->SplitNode();
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testVertPosFromBottom)
+{
+ // Create a document, insert a shape and position it 1cm above the bottom of the body area.
+ mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+ uno::Reference<css::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(10000, 10000));
+ uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+ xShapeProps->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+ xShapeProps->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::NONE));
+ xShapeProps->setPropertyValue("VertOrientRelation",
+ uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM));
+ xShapeProps->setPropertyValue("VertOrientPosition",
+ uno::makeAny(static_cast<sal_Int32>(-11000)));
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ xDrawPageSupplier->getDrawPage()->add(xShape);
+
+ // Verify that the distance between the body and anchored object bottom is indeed around 1cm.
+ xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+ sal_Int32 nBodyBottom = getXPath(pXmlDoc, "//body/infos/bounds", "bottom").toInt32();
+ sal_Int32 nAnchoredBottom
+ = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "bottom").toInt32();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 564
+ // - Actual : 9035
+ // i.e. the vertical position was from-top, not from-bottom.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(564), nBodyBottom - nAnchoredBottom);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */