[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - sw/CppunitTest_sw_core_objectpositioning.mk sw/Module_sw.mk sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 28 08:29:12 UTC 2020


 sw/CppunitTest_sw_core_objectpositioning.mk                        |   73 ++++++++++
 sw/Module_sw.mk                                                    |    1 
 sw/qa/core/objectpositioning/data/overlap-crash.odt                |binary
 sw/qa/core/objectpositioning/objectpositioning.cxx                 |   53 +++++++
 sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx |    9 -
 5 files changed, 134 insertions(+), 2 deletions(-)

New commits:
commit e1dd961e46a016f2641a96d5632757c8db4b1953
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Apr 27 20:48:30 2020 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Tue Apr 28 10:28:41 2020 +0200

    tdf#131729 sw: handle no drawing objects when calculating overlap of objects
    
    Regression from commit d37096f59e7e0286e55008153591a60bab92b9e8
    (Related: tdf#124600 sw anchored object allow overlap: add layout,
    2019-09-19), we assumed that the anchor frame always has draw objects,
    but that may not be the case.
    
    That happens when dragging a to-character anchored object around, before
    the object is added to its anchor.
    
    (cherry picked from commit 4ba1909f12b49f020195b5e767045340717ce6df)
    
    Change-Id: I1271a6e498553838c3851864b7965a1ba28de663
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93002
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/sw/CppunitTest_sw_core_objectpositioning.mk b/sw/CppunitTest_sw_core_objectpositioning.mk
new file mode 100644
index 000000000000..e083c199d74c
--- /dev/null
+++ b/sw/CppunitTest_sw_core_objectpositioning.mk
@@ -0,0 +1,73 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_objectpositioning, \
+    sw/qa/core/objectpositioning/objectpositioning \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_objectpositioning, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    sfx \
+    svxcore \
+    sw \
+    test \
+    unotest \
+    utl \
+    vcl \
+    svt \
+    tl \
+    svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_objectpositioning,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_objectpositioning,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_objectpositioning,\
+	udkapi \
+	offapi \
+	oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_objectpositioning))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_objectpositioning,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_objectpositioning,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_objectpositioning, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_objectpositioning))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 4784dcc64f8b..dc4f303d7a3b 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -109,6 +109,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_uibase_shells \
     CppunitTest_sw_core_frmedt \
     CppunitTest_sw_core_txtnode \
+    CppunitTest_sw_core_objectpositioning \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/objectpositioning/data/overlap-crash.odt b/sw/qa/core/objectpositioning/data/overlap-crash.odt
new file mode 100644
index 000000000000..a756c85dd67b
Binary files /dev/null and b/sw/qa/core/objectpositioning/data/overlap-crash.odt differ
diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx
new file mode 100644
index 000000000000..c73e97567f20
--- /dev/null
+++ b/sw/qa/core/objectpositioning/objectpositioning.cxx
@@ -0,0 +1,53 @@
+/* -*- 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 <comphelper/classids.hxx>
+#include <svtools/embedhlp.hxx>
+#include <svx/svdpage.hxx>
+#include <tools/globname.hxx>
+#include <unotest/bootstrapfixturebase.hxx>
+#include <vcl/gdimtf.hxx>
+
+#include <wrtsh.hxx>
+#include <fmtanchr.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <drawdoc.hxx>
+#include <dcontact.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_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index 89fe27e30558..18c08f8540d9 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -1117,8 +1117,13 @@ void SwToContentAnchoredObjectPosition::CalcOverlap(const SwTextFrame* pAnchorFr
     }
 
     // Get the list of objects.
-    const SwSortedObjs& rSortedObjs = *pAnchorFrameForVertPos->GetDrawObjs();
-    for (const auto& pAnchoredObj : rSortedObjs)
+    auto pSortedObjs = pAnchorFrameForVertPos->GetDrawObjs();
+    if (!pSortedObjs)
+    {
+        return;
+    }
+
+    for (const auto& pAnchoredObj : *pSortedObjs)
     {
         if (pAnchoredObj == &GetAnchoredObj())
         {


More information about the Libreoffice-commits mailing list