sw/CppunitTest_sw_core_undo.mk             |   73 +++++++++++++++++++++++++++++
 sw/Module_sw.mk                            |    1 
 sw/qa/core/undo/data/textbox-cut-save.docx |binary
 sw/qa/core/undo/undo.cxx                   |   55 +++++++++++++++++++++
 sw/source/core/undo/undobj1.cxx            |   13 +++++
 5 files changed, 142 insertions(+)

New commits:
commit 949b42bb9fc32d0fcb99941a705ddfc8cae0b233
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Aug 17 21:06:32 2020 +0200
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Wed Aug 19 11:32:11 2020 +0200

    tdf#135016 DOCX export: fix unexpected error on save with undo/redo
    
    Regression from commit d379d18666aa42031359ca8eb34b0021960347ae (oox:
    import WPS shape with text as shape with textbox, 2014-06-18), then
    problem was that when undo restored text deleted by cut, we ended up
    with an SwXShape that had no frame format.
    
    Fix the problem by deleting the cached old UNO wrapper after changing
    the association between a textbox's shape and text frame.
    
    An alternative would be to handle errors better when the TextBox UNO
    property is not of type bool, but that would still lead to silent data
    loss, so don't fix the problem that way.
    
    (cherry picked from commit b784ee4feb554987eff1c7fdaff640abb340504d)
    
    Change-Id: Id45ad292befc746e7c49a3b827c91efd069d29df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100911
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>

diff --git a/sw/CppunitTest_sw_core_undo.mk b/sw/CppunitTest_sw_core_undo.mk
new file mode 100644
index 000000000000..6c74de3fa04c
--- /dev/null
+++ b/sw/CppunitTest_sw_core_undo.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_undo))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_undo, \
+    sw/qa/core/undo/undo \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_undo, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    sfx \
+    svxcore \
+    sw \
+    test \
+    unotest \
+    utl \
+    vcl \
+    svt \
+    tl \
+    svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_undo,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_undo,\
+    -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_undo,\
+       udkapi \
+       offapi \
+       oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_undo))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_undo,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_undo,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_undo))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_undo, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_undo))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 1dd4f34cc61f..e2fd9b5ed75a 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -118,6 +118,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_core_objectpositioning \
     CppunitTest_sw_core_unocore \
     CppunitTest_sw_core_crsr \
+    CppunitTest_sw_core_undo \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/undo/data/textbox-cut-save.docx 
b/sw/qa/core/undo/data/textbox-cut-save.docx
new file mode 100644
index 000000000000..a1a350d08aac
Binary files /dev/null and b/sw/qa/core/undo/data/textbox-cut-save.docx differ
diff --git a/sw/qa/core/undo/undo.cxx b/sw/qa/core/undo/undo.cxx
new file mode 100644
index 000000000000..aeacffc78e9b
--- /dev/null
+++ b/sw/qa/core/undo/undo.cxx
@@ -0,0 +1,55 @@
+/* -*- 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 <unotools/mediadescriptor.hxx>
+
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <swdtflvr.hxx>
+
+char const DATA_DIRECTORY[] = "/sw/qa/core/undo/data/";
+
+/// Covers sw/source/core/undo/ fixes.
+class SwCoreUndoTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreUndoTest, testTextboxCutSave)
+{
+    // Load the document and select all.
+    load(DATA_DIRECTORY, "textbox-cut-save.docx");
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwDocShell* pDocShell = pTextDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    pWrtShell->SelAll();
+
+    // Cut.
+    rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
+    pTransfer->Cut();
+
+    // Undo.
+    pWrtShell->Undo();
+
+    // Save.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // void sax_fastparser::FastSaxSerializer::endDocument(): Assertion 
`mbMarkStackEmpty && maMarkStack.empty()' failed.
+    // i.e. failed to save because we tried to write not-well-formed XML.
+    xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx
index 51ba206af391..0596531d7031 100644
--- a/sw/source/core/undo/undobj1.cxx
+++ b/sw/source/core/undo/undobj1.cxx
@@ -37,6 +37,7 @@
 #include <ndtxt.hxx>
 #include <ndole.hxx>
 #include <frameformats.hxx>
+#include <svx/svdobj.hxx>
 
 SwUndoFlyBase::SwUndoFlyBase( SwFrameFormat* pFormat, SwUndoId nUndoId )
     : SwUndo(nUndoId, pFormat->GetDoc())
@@ -117,6 +118,18 @@ void SwUndoFlyBase::InsFly(::sw::UndoRedoContext & 
rContext, bool bShowSelFrame)
         // recklessly assume that this thing will live longer than the
         // SwUndoFlyBase - not sure what could be done if that isn't the 
case...
         
m_pFrameFormat->GetOtherTextBoxFormat()->SetOtherTextBoxFormat(m_pFrameFormat);
+
+        if (m_pFrameFormat->GetOtherTextBoxFormat()->Which() == RES_DRAWFRMFMT)
+        {
+            SdrObject* pSdrObject = 
m_pFrameFormat->GetOtherTextBoxFormat()->FindSdrObject();
+            if (pSdrObject)
+            {
+                // Make sure the old UNO wrapper is no longer cached after 
changing the shape +
+                // textframe pair. Otherwise we would have a wrapper which 
doesn't know about its
+                // textframe, even if it's there.
+                pSdrObject->setUnoShape(nullptr);
+            }
+        }
     }
 
     m_pFrameFormat->MakeFrames();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to