[Libreoffice-commits] core.git: sw/CppunitTest_sw_updateall_object_replacements.mk sw/Module_sw.mk sw/qa

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 28 18:27:39 UTC 2020


 sw/CppunitTest_sw_updateall_object_replacements.mk |   74 ++++++++++++++++
 sw/Module_sw.mk                                    |    1 
 sw/qa/core/data/updateall-objectreplacements.odt   |binary
 sw/qa/core/updateall_objectreplacements.cxx        |   92 +++++++++++++++++++++
 4 files changed, 167 insertions(+)

New commits:
commit 3f291bb285335efbc2f21a08bdcb23d92911940c
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue Aug 25 13:48:32 2020 +0300
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Aug 28 20:26:54 2020 +0200

    Add unit test for c123bfff501229f398a1b679fc7434b82d53685c
    
    Change-Id: Ic616ec9f39b65f8e8ec840a48e3b5801b31cf5da
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101530
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/CppunitTest_sw_updateall_object_replacements.mk b/sw/CppunitTest_sw_updateall_object_replacements.mk
new file mode 100644
index 000000000000..a8aa95e73258
--- /dev/null
+++ b/sw/CppunitTest_sw_updateall_object_replacements.mk
@@ -0,0 +1,74 @@
+# -*- 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 \
+    swqahelper \
+    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/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 0df68e21a6f7..21930dc487b4 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -120,6 +120,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_core_unocore \
     CppunitTest_sw_core_crsr \
     CppunitTest_sw_core_undo \
+    CppunitTest_sw_updateall_object_replacements \
 ))
 
 ifneq ($(DISABLE_GUI),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