From f3b5356bdc51b03f9910ed544b8c17d6f919bc12 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 15 Jan 2021 11:57:50 +0100 Subject: tdf#136861 ODT export: fix writing resolved state for non-ranged comments It was probably not intentional to write the resolved state only in case the annotation has a name. Change-Id: Ia3a6b2320e2288528c43c832211ebfcde492881e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109354 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmloff/CppunitTest_xmloff_text.mk | 1 + xmloff/qa/unit/text.cxx | 48 +++++++++++++++++++++++++++++++++++++++ xmloff/source/text/txtflde.cxx | 23 +++++++++---------- 3 files changed, 60 insertions(+), 12 deletions(-) (limited to 'xmloff') diff --git a/xmloff/CppunitTest_xmloff_text.mk b/xmloff/CppunitTest_xmloff_text.mk index e3259672605b..8e757fd584b2 100644 --- a/xmloff/CppunitTest_xmloff_text.mk +++ b/xmloff/CppunitTest_xmloff_text.mk @@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_text, \ sal \ test \ unotest \ + utl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,xmloff_text)) diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index c8e867401ccd..30646655bf3a 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -10,7 +10,13 @@ #include #include +#include #include +#include +#include + +#include +#include using namespace ::com::sun::star; @@ -52,6 +58,48 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testMailMergeInEditeng) CPPUNIT_ASSERT(getComponent().is()); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentResolved) +{ + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Sequence aCommentProps = comphelper::InitPropertySequence({ + { "Text", uno::makeAny(OUString("comment")) }, + }); + dispatchCommand(getComponent(), ".uno:InsertAnnotation", aCommentProps); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xPortionEnum = xPara->createEnumeration(); + uno::Reference xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xField(xPortion->getPropertyValue("TextField"), + uno::UNO_QUERY); + xField->setPropertyValue("Resolved", uno::makeAny(true)); + + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::makeAny(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + getComponent()->dispose(); + + getComponent() = loadFromDesktop(aTempFile.GetURL()); + xTextDocument.set(getComponent(), uno::UNO_QUERY); + xParaEnumAccess.set(xTextDocument->getText(), uno::UNO_QUERY); + xParaEnum = xParaEnumAccess->createEnumeration(); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + xPortionEnum = xPara->createEnumeration(); + xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); + xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY); + bool bResolved = false; + xField->getPropertyValue("Resolved") >>= bResolved; + // Without the accompanying fix in place, this test would have failed, as the resolved state was + // not saved for non-range comments. + CPPUNIT_ASSERT(bResolved); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index f9c0769ead3e..50d072b6b2a9 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -1752,18 +1752,17 @@ void XMLTextFieldExport::ExportFieldHelper( if (!aName.isEmpty()) { GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, aName); - SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion(); - if (eVersion & SvtSaveOptions::ODFSVER_EXTENDED) - { - bool b = GetBoolProperty("Resolved", rPropSet); - OUString aResolvedText; - OUStringBuffer aResolvedTextBuffer; - ::sax::Converter::convertBool(aResolvedTextBuffer, b); - aResolvedText = aResolvedTextBuffer.makeStringAndClear(); - - GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_RESOLVED, - aResolvedText); - } + } + SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion(); + if (eVersion & SvtSaveOptions::ODFSVER_EXTENDED) + { + bool b = GetBoolProperty("Resolved", rPropSet); + OUString aResolvedText; + OUStringBuffer aResolvedTextBuffer; + ::sax::Converter::convertBool(aResolvedTextBuffer, b); + aResolvedText = aResolvedTextBuffer.makeStringAndClear(); + + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_RESOLVED, aResolvedText); } SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_OFFICE, XML_ANNOTATION, false, true); -- cgit v1.2.3