[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - 4 commits - sfx2/source sw/CppunitTest_sw_uibase_uiview.mk sw/Module_sw.mk sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Nov 19 16:56:23 UTC 2020
sfx2/source/view/sfxbasecontroller.cxx | 12 -
sw/CppunitTest_sw_uibase_uiview.mk | 73 +++++++
sw/Module_sw.mk | 1
sw/qa/uibase/uiview/data/update-replacement-nosetting.odt |binary
sw/qa/uibase/uiview/data/updateall-objectreplacements.odt |binary
sw/qa/uibase/uiview/uiview.cxx | 137 ++++++++++++++
sw/source/uibase/uiview/view.cxx | 8
7 files changed, 225 insertions(+), 6 deletions(-)
New commits:
commit d121a9959adb9bc2e3781ae24b3f36763cd6f0c8
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Nov 18 17:55:13 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Nov 19 17:55:45 2020 +0100
sw replacement image creation: fix this when an ODT's settings.xml is invalid
This builds on top of commit c123bfff501229f398a1b679fc7434b82d53685c
(Bin overly eager early return that stops replacement image creation,
2020-08-20), and handles a similar case, when
SwView::ReadUserDataSequence() is not called at all.
The result is the same: no shell is selected on the command dispatcher
stack, so .uno:UpdateAll is ignored and the replacement images are not
created.
(cherry picked from commit 693f12ad57912c2356a197d9a794e6108ce79ef2)
Conflicts:
sfx2/source/view/sfxbasecontroller.cxx
sw/source/uibase/uiview/view.cxx
Change-Id: If8b74424b0ad88e63129fd8f7efd09f85e300895
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx
index b7947d3dc648..12f44335230c 100644
--- a/sfx2/source/view/sfxbasecontroller.cxx
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -1384,12 +1384,18 @@ void SfxBaseController::ConnectSfxFrame_Impl( const ConnectSfxFrame i_eConnect )
break;
}
}
- if ( nViewDataIndex < nCount )
+ if (nViewDataIndex < nCount || !xViewData.is())
{
Sequence< PropertyValue > aViewData;
- OSL_VERIFY( xViewData->getByIndex( nViewDataIndex ) >>= aViewData );
- if ( aViewData.getLength() > 0 )
+ if (xViewData.is())
+ {
+ OSL_VERIFY(xViewData->getByIndex(nViewDataIndex) >>= aViewData);
+ }
+ if (aViewData.getLength() > 0 || !xViewData.is())
+ {
+ // Tolerate empty xViewData, ReadUserDataSequence() has side effects.
m_pData->m_pViewShell->ReadUserDataSequence( aViewData );
+ }
}
}
catch (const Exception&)
diff --git a/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt
new file mode 100644
index 000000000000..055c3d1a2c2a
Binary files /dev/null and b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt differ
diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 8827cea10752..72900f9db54b 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -12,6 +12,7 @@
#include <unotools/mediadescriptor.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/file.hxx>
+#include <comphelper/propertyvalue.hxx>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -87,6 +88,50 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateAllObjectReplacements)
CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components_1"));
}
+namespace
+{
+void dispatchCommand(const uno::Reference<lang::XComponent>& xComponent,
+ const OUString& rCommand,
+ const uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+ uno::Reference<frame::XController> xController
+ = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
+ CPPUNIT_ASSERT(xController.is());
+ uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFrame.is());
+
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
+ CPPUNIT_ASSERT(xDispatchHelper.is());
+
+ xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
+}
+}
+
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
+{
+ // Load a copy of the document in hidden mode.
+ OUString aSourceURL
+ = m_directories.getURLFromSrc(DATA_DIRECTORY) + "update-replacement-nosetting.odt";
+ CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::copy(aSourceURL, maTempFile.GetURL()));
+ mxComponent = loadFromDesktop(maTempFile.GetURL(), "com.sun.star.text.TextDocument",
+ { comphelper::makePropertyValue("Hidden", true) });
+
+ // Update "everything" (including object replacements) and save it.
+ dispatchCommand(mxComponent, ".uno:UpdateAll", {});
+ uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
+ xStorable->storeSelf({});
+
+ // Check the contents of the updated copy.
+ uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
+ = packages::zip::ZipFileAccess::createWithURL(xContext, maTempFile.GetURL());
+
+ // Without the accompanying fix in place, this test would have failed, because the embedded
+ // object replacement image was not generated.
+ CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index c6cbd9319be8..d806b3758153 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1242,7 +1242,6 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
return;
bool bIsOwnDocument = lcl_IsOwnDocument( *this );
sal_Int32 nLength = rSequence.getLength();
- if (nLength)
{
SET_CURR_SHELL(m_pWrtShell);
const beans::PropertyValue *pValue = rSequence.getConstArray();
commit 0a9012e5375a84de8065947d8a8a75dd53976cfc
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Sep 8 20:55:32 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Nov 19 14:03:59 2020 +0100
sw: rename CppunitTest_sw_updateall_object_replacements to sw_uibase_uiview
All these new test suites are named in a way, so that in case the fix is
in sw/source/foo/bar/, then the matching test suite is sw_foo_bar.
Rename to this schema, so next time a bug is fixed in that directory, we
don't need to add a new suite.
(cherry picked from commit 0be6168c5a7b1493a22222dc0967b5e8a0153386)
Conflicts:
sw/CppunitTest_sw_updateall_object_replacements.mk
sw/Module_sw.mk
Change-Id: I968711754cb587cc2f97fff6431be416b477728f
diff --git a/sw/CppunitTest_sw_uibase_uiview.mk b/sw/CppunitTest_sw_uibase_uiview.mk
new file mode 100644
index 000000000000..d1b4141c3952
--- /dev/null
+++ b/sw/CppunitTest_sw_uibase_uiview.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_uibase_uiview))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_uibase_uiview))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_uibase_uiview, \
+ sw/qa/uibase/uiview/uiview \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_uibase_uiview, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sfx \
+ svxcore \
+ sw \
+ test \
+ unotest \
+ utl \
+ vcl \
+ svt \
+ tl \
+ svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_uibase_uiview,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_uibase_uiview,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/extras/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_uibase_uiview,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_uibase_uiview))
+$(eval $(call gb_CppunitTest_use_vcl,sw_uibase_uiview))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_uibase_uiview,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_uibase_uiview,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_uibase_uiview))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_uibase_uiview, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_uibase_uiview))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/CppunitTest_sw_updateall_object_replacements.mk b/sw/CppunitTest_sw_updateall_object_replacements.mk
deleted file mode 100644
index ce4682dd6ef3..000000000000
--- a/sw/CppunitTest_sw_updateall_object_replacements.mk
+++ /dev/null
@@ -1,73 +0,0 @@
-# -*- 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_updateall_object_replacements))
-
-$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_updateall_object_replacements))
-
-$(eval $(call gb_CppunitTest_add_exception_objects,sw_updateall_object_replacements, \
- sw/qa/core/updateall_objectreplacements \
-))
-
-$(eval $(call gb_CppunitTest_use_libraries,sw_updateall_object_replacements, \
- comphelper \
- cppu \
- cppuhelper \
- sal \
- sfx \
- svxcore \
- sw \
- test \
- unotest \
- utl \
- vcl \
- svt \
- tl \
- svl \
-))
-
-$(eval $(call gb_CppunitTest_use_externals,sw_updateall_object_replacements,\
- boost_headers \
- libxml2 \
-))
-
-$(eval $(call gb_CppunitTest_set_include,sw_updateall_object_replacements,\
- -I$(SRCDIR)/sw/inc \
- -I$(SRCDIR)/sw/source/core/inc \
- -I$(SRCDIR)/sw/source/uibase/inc \
- -I$(SRCDIR)/sw/qa/extras/inc \
- $$(INCLUDE) \
-))
-
-$(eval $(call gb_CppunitTest_use_api,sw_updateall_object_replacements,\
- udkapi \
- offapi \
- oovbaapi \
-))
-
-$(eval $(call gb_CppunitTest_use_ure,sw_updateall_object_replacements))
-$(eval $(call gb_CppunitTest_use_vcl,sw_updateall_object_replacements))
-
-$(eval $(call gb_CppunitTest_use_rdb,sw_updateall_object_replacements,services))
-
-$(eval $(call gb_CppunitTest_use_custom_headers,sw_updateall_object_replacements,\
- officecfg/registry \
-))
-
-$(eval $(call gb_CppunitTest_use_configuration,sw_updateall_object_replacements))
-
-$(eval $(call gb_CppunitTest_use_uiconfigs,sw_updateall_object_replacements, \
- modules/swriter \
-))
-
-$(eval $(call gb_CppunitTest_use_more_fonts,sw_updateall_object_replacements))
-
-# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index b5f2ca3155ca..8427e77f98f5 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -80,7 +80,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_globalfilter \
CppunitTest_sw_unowriter \
CppunitTest_sw_uibase_shells \
- CppunitTest_sw_updateall_object_replacements \
+ CppunitTest_sw_uibase_uiview \
))
ifneq ($(ENABLE_HEADLESS),TRUE)
diff --git a/sw/qa/core/data/updateall-objectreplacements.odt b/sw/qa/uibase/uiview/data/updateall-objectreplacements.odt
similarity index 100%
rename from sw/qa/core/data/updateall-objectreplacements.odt
rename to sw/qa/uibase/uiview/data/updateall-objectreplacements.odt
diff --git a/sw/qa/core/updateall_objectreplacements.cxx b/sw/qa/uibase/uiview/uiview.cxx
similarity index 93%
rename from sw/qa/core/updateall_objectreplacements.cxx
rename to sw/qa/uibase/uiview/uiview.cxx
index 92997d498e59..8827cea10752 100644
--- a/sw/qa/core/updateall_objectreplacements.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -23,14 +23,14 @@
#include <wrtsh.hxx>
#include <swdtflvr.hxx>
-char const DATA_DIRECTORY[] = "/sw/qa/core/data/";
+char const DATA_DIRECTORY[] = "/sw/qa/uibase/uiview/data/";
-/// Covers sw/source/core/undo/ fixes.
-class SwCoreUpdateAllObjectReplacementsTest : public SwModelTestBase
+/// Covers sw/source/uibase/uiview/ fixes.
+class SwUibaseUiviewTest : public SwModelTestBase
{
};
-CPPUNIT_TEST_FIXTURE(SwCoreUpdateAllObjectReplacementsTest, testDoIt)
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateAllObjectReplacements)
{
// Make a temporary copy of the test document
utl::TempFile tmp;
commit 3e4ce34fd971a1ace938a1d3bd24cbd2cdc0842a
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Fri Aug 28 12:00:11 2020 +0300
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Nov 19 12:31:20 2020 +0100
Fix ooo38104-1.sxw crash after c123bfff501229f398a1b679fc7434b82d53685c
Unlike the c123bf commit, this commit does not cause the crash that
was caught by the crash-testing system.
(The crash could be reproduced by:
wget -O ooo38104-1.sxw https://bz.apache.org/ooo/attachment.cgi?id=19889
./instdir/program/soffice.bin --headless --convert-to docx ./ooo38104-1.sxw
)
In this commit, I reinstate the "early return" in
SwView::ReadUserDataSequence() that I dropped in the c123bf commit,
but instead move the SelectShell() call earlier, so that it will be
executed before the potential early return.
The problem that we try to fix here is the one that the fresh
CppunitTest_sw_updateall_object_replacements checks, so to reproduce
that problem, revert both this commit and c123bf, and then run that
unit test.
(cherry picked from commit 6e0bb3fc4e89ddb85ddf40889b11a0c0bd4ab607)
Conflicts:
sw/source/uibase/uiview/view.cxx
Change-Id: I6c728b75a2f172b75fbf2ad00c019c32aecc19f8
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 89cb4d9335fa..c6cbd9319be8 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1341,10 +1341,14 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
// delegate further
GetViewImpl()->GetUNOObject_Impl()->getViewSettings()->setPropertyValue("ShowOnlineLayout", uno::Any(bBrowseMode));
}
+
+ SelectShell();
+
if (bGotVisibleBottom)
{
Point aCursorPos( nX, nY );
-
+ const long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
+ if (nBottom <= (m_pWrtShell->GetDocSize().Height()+nAdd) )
{
m_pWrtShell->EnableSmooth( false );
const tools::Rectangle aVis( nLeft, nTop, nRight, nBottom );
@@ -1401,7 +1405,6 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
// reset flag value
m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
}
- SelectShell();
// Set ViewLayoutSettings
const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
commit 051a2c1d5622629ce4c180015282ba0370d6e03b
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue Aug 25 13:48:32 2020 +0300
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Nov 19 12:29:19 2020 +0100
Add unit test for c123bfff501229f398a1b679fc7434b82d53685c
(cherry picked from commit 3f291bb285335efbc2f21a08bdcb23d92911940c)
Conflicts:
sw/Module_sw.mk
Change-Id: Ic616ec9f39b65f8e8ec840a48e3b5801b31cf5da
diff --git a/sw/CppunitTest_sw_updateall_object_replacements.mk b/sw/CppunitTest_sw_updateall_object_replacements.mk
new file mode 100644
index 000000000000..ce4682dd6ef3
--- /dev/null
+++ b/sw/CppunitTest_sw_updateall_object_replacements.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_updateall_object_replacements))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_updateall_object_replacements))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_updateall_object_replacements, \
+ sw/qa/core/updateall_objectreplacements \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_updateall_object_replacements, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sfx \
+ svxcore \
+ sw \
+ test \
+ unotest \
+ utl \
+ vcl \
+ svt \
+ tl \
+ svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_updateall_object_replacements,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_updateall_object_replacements,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/extras/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_updateall_object_replacements,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_updateall_object_replacements))
+$(eval $(call gb_CppunitTest_use_vcl,sw_updateall_object_replacements))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_updateall_object_replacements,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_updateall_object_replacements,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_updateall_object_replacements))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_updateall_object_replacements, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_updateall_object_replacements))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 6a017917725d..b5f2ca3155ca 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_globalfilter \
CppunitTest_sw_unowriter \
CppunitTest_sw_uibase_shells \
+ CppunitTest_sw_updateall_object_replacements \
))
ifneq ($(ENABLE_HEADLESS),TRUE)
diff --git a/sw/qa/core/data/updateall-objectreplacements.odt b/sw/qa/core/data/updateall-objectreplacements.odt
new file mode 100644
index 000000000000..35decf73f895
Binary files /dev/null and b/sw/qa/core/data/updateall-objectreplacements.odt differ
diff --git a/sw/qa/core/updateall_objectreplacements.cxx b/sw/qa/core/updateall_objectreplacements.cxx
new file mode 100644
index 000000000000..92997d498e59
--- /dev/null
+++ b/sw/qa/core/updateall_objectreplacements.cxx
@@ -0,0 +1,92 @@
+/* -*- 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 <comphelper/processfactory.hxx>
+#include <osl/file.hxx>
+
+#include <com/sun/star/frame/DispatchHelper.hpp>
+#include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
+
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <swdtflvr.hxx>
+
+char const DATA_DIRECTORY[] = "/sw/qa/core/data/";
+
+/// Covers sw/source/core/undo/ fixes.
+class SwCoreUpdateAllObjectReplacementsTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreUpdateAllObjectReplacementsTest, testDoIt)
+{
+ // Make a temporary copy of the test document
+ utl::TempFile tmp;
+ tmp.EnableKillingFile();
+ OUString sTempCopy = tmp.GetURL();
+ CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None,
+ osl::File::copy(m_directories.getURLFromSrc(DATA_DIRECTORY)
+ + "updateall-objectreplacements.odt",
+ sTempCopy));
+
+ /* BASIC code that exhibits the problem:
+
+ desktop = CreateUnoService("com.sun.star.frame.Desktop")
+ Dim props(0) as new com.sun.star.beans.PropertyValue
+ props(0).Name = "Hidden"
+ props(0).Value = true
+ component = desktop.loadComponentFromURL("file://.../test.odt", "_default", 0, props)
+ Wait 1000 ' workaround
+ dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
+ frame = component.CurrentController.Frame
+ dispatcher.executeDispatch(frame, ".uno:UpdateAll", "", 0, Array())
+ component.storeSelf(Array())
+ component.dispose()
+ */
+
+ uno::Reference<lang::XMultiServiceFactory> xFactory(comphelper::getProcessServiceFactory());
+
+ // Load the copy
+ uno::Reference<uno::XInterface> xInterface
+ = xFactory->createInstance("com.sun.star.frame.Desktop");
+ uno::Reference<frame::XComponentLoader> xComponentLoader(xInterface, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aLoadArgs(1);
+ aLoadArgs[0].Name = "Hidden";
+ aLoadArgs[0].Value <<= true;
+ mxComponent = xComponentLoader->loadComponentFromURL(sTempCopy, "_default", 0, aLoadArgs);
+
+ // Perform the .uno:UpdateAll call and save
+ xInterface = xFactory->createInstance("com.sun.star.frame.DispatchHelper");
+ uno::Reference<frame::XDispatchHelper> xDispatchHelper(xInterface, uno::UNO_QUERY);
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ uno::Reference<frame::XDispatchProvider> xDispatchProvider(
+ xModel->getCurrentController()->getFrame(), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aNoArgs;
+ xDispatchHelper->executeDispatch(xDispatchProvider, ".uno:UpdateAll", OUString(), 0, aNoArgs);
+ uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
+ xStorable->storeSelf(aNoArgs);
+
+ // Check the contents of the updated copy and verify that ObjectReplacements are there
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
+ = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(xFactory),
+ sTempCopy);
+
+ CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components"));
+ CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components_1"));
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list