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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 30 10:56:09 UTC 2020


 sw/CppunitTest_sw_core_unocore.mk     |   77 ++++++++++++++++++++++++++++
 sw/Module_sw.mk                       |    1 
 sw/qa/core/unocore/data/tdf119081.odt |binary
 sw/qa/core/unocore/unocore.cxx        |   91 ++++++++++++++++++++++++++++++++++
 sw/source/core/unocore/unotext.cxx    |    3 -
 5 files changed, 170 insertions(+), 2 deletions(-)

New commits:
commit 7fffa25b37006aea218d8fa709f148168efee053
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Jun 22 21:04:47 2020 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Tue Jun 30 12:55:36 2020 +0200

    tdf#119081 sw: fix RTF paste into outer table cell
    
    Regression from commit ed654c4aa7f9f10fcb16127349009bc0c38b12e8 (Revert
    "fdo#43869 use the old rtf importer for paste", 2012-11-30), the direct
    problem is that SwXText::insertTextPortion() is now used by
    writerfilter, so in case it's not as good as the internal API used by
    the old RTF filter, we have a problem.
    
    This function calls SwXCell::CreateCursor(), which calls
    SwXCell::createTextCursor(), which uses Move() to go to the first
    content node in the cell, but that means we end up at the inner cell's
    XText for an outer cell.
    
    So later when we want to go to the end of the outer cell, we can't, as
    that would be a different XText and we throw an exception.
    
    Fix the problem by instead using createTextCursorByRange(), which
    immediately positions the cursor at the insert position, so the XText
    will be correct.
    
    FWIW, the ODF import at SwXMLImport::setTextInsertMode() also uses
    createTextCursorByRange() to handle this situation.
    
    (cherry picked from commit e0d0274c2b806f5148b413926ec2e58c75ce04a1)
    
    Conflicts:
            sw/Module_sw.mk
    
    Change-Id: I1db13b860bc60771d98c2b4099be73f4bf41c375
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96937
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/sw/CppunitTest_sw_core_unocore.mk b/sw/CppunitTest_sw_core_unocore.mk
new file mode 100644
index 000000000000..6ff38dfc1890
--- /dev/null
+++ b/sw/CppunitTest_sw_core_unocore.mk
@@ -0,0 +1,77 @@
+# -*- 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_unocore))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_unocore))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_unocore, \
+    sw/qa/core/unocore/unocore \
+))
+
+# note: this links msword only for the reason to have an order dependency,
+# because "make sw.check" will not see the dependency through services.rdb
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_unocore, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    msword \
+    sal \
+    sfx \
+    svl \
+    svt \
+    svxcore \
+    sw \
+    test \
+    unotest \
+    vcl \
+    tl \
+    tk \
+    utl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_unocore,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_unocore,\
+    -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_unocore,\
+	udkapi \
+	offapi \
+	oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_unocore))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_unocore))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_unocore,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_unocore))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_unocore, \
+    modules/swriter \
+))
+
+$(call gb_CppunitTest_get_target,sw_core_unocore): \
+    $(call gb_Library_get_target,textconv_dict)
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_unocore))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index fcd3f0c2d572..f8d59d1e7848 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -112,6 +112,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_core_txtnode \
     CppunitTest_sw_core_objectpositioning \
     CppunitTest_sw_core_layout \
+    CppunitTest_sw_core_unocore \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/unocore/data/tdf119081.odt b/sw/qa/core/unocore/data/tdf119081.odt
new file mode 100644
index 000000000000..a9b479dd59df
Binary files /dev/null and b/sw/qa/core/unocore/data/tdf119081.odt differ
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
new file mode 100644
index 000000000000..d8d72ecf369f
--- /dev/null
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -0,0 +1,91 @@
+/* -*- 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/awt/FontSlant.hpp>
+#include <com/sun/star/table/XCellRange.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
+#include <com/sun/star/text/AutoTextContainer.hpp>
+#include <com/sun/star/text/VertOrientation.hpp>
+#include <com/sun/star/text/XAutoTextGroup.hpp>
+#include <com/sun/star/text/XTextPortionAppend.hpp>
+#include <com/sun/star/text/XTextContentAppend.hpp>
+#include <com/sun/star/text/XTextRangeCompare.hpp>
+#include <com/sun/star/text/XTextAppend.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/URIs.hpp>
+#include <com/sun/star/awt/XDevice.hpp>
+#include <com/sun/star/awt/XToolkit.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/style/LineSpacing.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+
+#include <comphelper/propertyvalue.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <vcl/graphicfilter.hxx>
+
+#include <wrtsh.hxx>
+#include <ndtxt.hxx>
+#include <swdtflvr.hxx>
+#include <view.hxx>
+#include <PostItMgr.hxx>
+#include <postithelper.hxx>
+#include <AnnotationWin.hxx>
+#include <flyfrm.hxx>
+#include <fmtanchr.hxx>
+#include <unotextrange.hxx>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+char const DATA_DIRECTORY[] = "/sw/qa/core/unocore/data/";
+}
+
+/// Covers sw/source/core/unocore/ fixes.
+class SwCoreUnocoreTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081)
+{
+    // Load a doc with a nested table in it.
+    load(DATA_DIRECTORY, "tdf119081.odt");
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDocShell* pDocShell = pTextDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+
+    // Enter outer A1.
+    pWrtShell->Down(/*bSelect=*/false, /*nCount=*/3);
+    // Enter inner A1.
+    pWrtShell->Right(CRSR_SKIP_CELLS, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false,
+                     /*bVisual=*/true);
+    // Enter outer B1.
+    pWrtShell->Down(/*bSelect=*/false, /*nCount=*/2);
+
+    SwDoc* pDoc = pDocShell->GetDoc();
+    SwPaM& rCursor = pWrtShell->GetCurrentShellCursor();
+    uno::Reference<text::XTextRange> xInsertPosition
+        = SwXTextRange::CreateXTextRange(*pDoc, *rCursor.GetPoint(), nullptr);
+    uno::Reference<text::XTextAppend> xTextAppend(xInsertPosition->getText(), uno::UNO_QUERY);
+    // Without the accompanying fix in place, this test would have failed with:
+    // An uncaught exception of type com.sun.star.uno.RuntimeException
+    xTextAppend->insertTextPortion("x", {}, xInsertPosition);
+
+    // Verify that the string is indeed inserted.
+    pWrtShell->Left(CRSR_SKIP_CELLS, /*bSelect=*/true, /*nCount=*/1, /*bBasicCall=*/false,
+                    /*bVisual=*/true);
+    CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 8bdc6d575e73..3887a11191d7 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1339,8 +1339,7 @@ SwXText::insertTextPortion(
         throw  uno::RuntimeException();
     }
     uno::Reference< text::XTextRange > xRet;
-    const uno::Reference< text::XTextCursor > xTextCursor = CreateCursor();
-    xTextCursor->gotoRange(xInsertPosition, false);
+    const uno::Reference<text::XTextCursor> xTextCursor = createTextCursorByRange(xInsertPosition);
 
     const uno::Reference< lang::XUnoTunnel > xRangeTunnel(
             xTextCursor, uno::UNO_QUERY_THROW );


More information about the Libreoffice-commits mailing list