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 - 5 files changed, 131 insertions(+), 1 deletion(-)
New commits: commit ddfafd9b67e6e61c144b29ac73bbafb413ddf03b Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Mar 30 11:20:12 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Mar 30 14:09:30 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. Change-Id: I87494fd04687d31201b4ec712cb0fb1ec7362b46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132301 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins 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 ee4e0798a5b9..84a718feb766 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -145,6 +145,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_core_edit \ CppunitTest_sw_uibase_fldui \ CppunitTest_sw_core_view \ + 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 606ae209fc53..a825cb9941a2 100644 --- a/sw/source/core/attr/swatrset.cxx +++ b/sw/source/core/attr/swatrset.cxx @@ -364,7 +364,8 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const const SwFormatAutoFormat* pAutoFormatItem; if (pSrcDoc != pDstDoc && - (pAutoFormatItem = GetItemIfSet(RES_PARATR_LIST_AUTOFMT, false))) + (pAutoFormatItem = GetItemIfSet(RES_PARATR_LIST_AUTOFMT, false)) && + pAutoFormatItem->GetStyleHandle()) { SfxItemSet const& rAutoStyle(*pAutoFormatItem->GetStyleHandle()); std::shared_ptr<SfxItemSet> const pNewSet(