include/vcl/transfer.hxx | 4 + sw/CppunitTest_sw_core_attr.mk | 75 +++++++++++++++++++++++++++++++++++++ sw/Module_sw.mk | 1 sw/qa/core/attr/attr.cxx | 53 ++++++++++++++++++++++++++ sw/qa/core/attr/data/attr-set.docx |binary sw/source/core/attr/swatrset.cxx | 3 - 6 files changed, 134 insertions(+), 2 deletions(-)
New commits: commit ac151fafd06c92cf9482b5696380346206542f87 Author: Miklos Vajna <[email protected]> AuthorDate: Wed Mar 30 11:20:12 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Thu Mar 31 16:39:06 2022 +0200 sw: fix crash in SwAttrSet::CopyToModify() Regression from commit 938a4d6624a78f3e272b3c4c07f314cb0c6db723 (tdf#128375 sw: fix copying RES_PARATR_LIST_AUTOFMT to different SwDoc, 2019-11-01), the problem is that we may get an autofmt pool item which is set, but its style handle is empty. Assume that this is the same case as having no autofmt at all. (cherry picked from commit ddfafd9b67e6e61c144b29ac73bbafb413ddf03b) Conflicts: sw/Module_sw.mk sw/source/core/attr/swatrset.cxx [ Help backporting by also picking a single hunk from commit 1ad26c9fc237e00247f18fcc8ccc778fba88d1fd (loplugin:referencecasting add check for new rtl::Reference operator, 2021-02-11) as well. ] Change-Id: I87494fd04687d31201b4ec712cb0fb1ec7362b46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132313 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/vcl/transfer.hxx b/include/vcl/transfer.hxx index 2ec7c340b69f..8a2092559691 100644 --- a/include/vcl/transfer.hxx +++ b/include/vcl/transfer.hxx @@ -176,7 +176,7 @@ protected: const css::uno::Reference< css::datatransfer::clipboard::XClipboard >& getOwnClipboard() const { return mxClipboard; } -private: +public: // XTransferable virtual css::uno::Any SAL_CALL getTransferData( const css::datatransfer::DataFlavor& rFlavor ) override; @@ -188,6 +188,8 @@ private: const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override; virtual sal_Bool SAL_CALL isComplex() override; +private: + // XEventListener virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; diff --git a/sw/CppunitTest_sw_core_attr.mk b/sw/CppunitTest_sw_core_attr.mk new file mode 100644 index 000000000000..7ca0060290e3 --- /dev/null +++ b/sw/CppunitTest_sw_core_attr.mk @@ -0,0 +1,75 @@ +# -*- 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_attr)) + +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_attr)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_attr, \ + sw/qa/core/attr/attr \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sw_core_attr, \ + comphelper \ + cppu \ + cppuhelper \ + editeng \ + sal \ + sfx \ + svl \ + svx \ + svxcore \ + sw \ + swqahelper \ + test \ + unotest \ + utl \ + vcl \ + tl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sw_core_attr,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sw_core_attr,\ + -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_attr,\ + udkapi \ + offapi \ + oovbaapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sw_core_attr)) +$(eval $(call gb_CppunitTest_use_vcl,sw_core_attr)) + +$(eval $(call gb_CppunitTest_use_rdb,sw_core_attr,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_attr,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_core_attr)) + +$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_attr, \ + modules/swriter \ +)) + +$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_attr)) + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index cddc7cdc4f14..72e5112fe403 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -128,6 +128,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_uibase_uiview \ CppunitTest_sw_core_draw \ CppunitTest_sw_core_edit \ + CppunitTest_sw_core_attr \ )) ifneq ($(DISABLE_GUI),TRUE) diff --git a/sw/qa/core/attr/attr.cxx b/sw/qa/core/attr/attr.cxx new file mode 100644 index 000000000000..0df9d9ef0451 --- /dev/null +++ b/sw/qa/core/attr/attr.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 <docsh.hxx> +#include <swdtflvr.hxx> +#include <swmodule.hxx> + +namespace +{ +constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/attr/data/"; + +/// Covers sw/source/core/attr/ fixes. +class Test : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(Test, testSwAttrSet) +{ + // Given a document with track changes and the whole document is selected: + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "attr-set.docx"); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:Cut", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + rtl::Reference<SwTransferable> xTransferable(new SwTransferable(*pWrtShell)); + SwModule* pMod = SW_MOD(); + SwTransferable* pOldTransferable = pMod->m_pXSelection; + pMod->m_pXSelection = xTransferable.get(); + + // When getting the plain text version of the selection: + datatransfer::DataFlavor aFlavor; + aFlavor.MimeType = "text/plain;charset=utf-16"; + aFlavor.DataType = cppu::UnoType<OUString>::get(); + uno::Any aData = xTransferable->getTransferData(aFlavor); + + // Then make sure we get data without crashing: + CPPUNIT_ASSERT(aData.hasValue()); + pMod->m_pXSelection = pOldTransferable; +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/attr/data/attr-set.docx b/sw/qa/core/attr/data/attr-set.docx new file mode 100644 index 000000000000..0cb8508aa2a4 Binary files /dev/null and b/sw/qa/core/attr/data/attr-set.docx differ diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx index 0fe141ef5834..4b9f8eddded8 100644 --- a/sw/source/core/attr/swatrset.cxx +++ b/sw/source/core/attr/swatrset.cxx @@ -399,7 +399,8 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const } if (pSrcDoc != pDstDoc && - SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem)) + SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem) && + static_cast<SwFormatAutoFormat const&>(*pItem).GetStyleHandle()) { SfxItemSet const& rAutoStyle(*static_cast<SwFormatAutoFormat const&>(*pItem).GetStyleHandle()); std::shared_ptr<SfxItemSet> const pNewSet(
