embeddedobj/qa/cppunit/general.cxx | 41 +---- sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx | 13 - sw/qa/core/text/itrform2.cxx | 8 - sw/qa/core/text/text.cxx | 24 +-- sw/qa/extras/layout/layout.cxx | 16 -- sw/qa/extras/layout/layout4.cxx | 38 +--- sw/qa/extras/odfexport/odfexport4.cxx | 120 +++++++-------- sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 19 -- sw/qa/extras/uiwriter/uiwriter7.cxx | 15 - sw/qa/extras/uiwriter/uiwriter9.cxx | 65 +------- sw/qa/extras/unowriter/unowriter.cxx | 13 - sw/qa/inc/swmodeltestbase.hxx | 14 - sw/qa/unit/swmodeltestbase.cxx | 16 -- sw/qa/writerfilter/dmapper/GraphicImport.cxx | 21 -- 14 files changed, 131 insertions(+), 292 deletions(-)
New commits: commit 9d51fa1028783ce51ed07904f0ae3133dac7d8ce Author: Mike Kaganski <[email protected]> AuthorDate: Mon Feb 2 10:36:49 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Feb 2 08:43:17 2026 +0100 Use ScopedConfigValue instead of manual configuration management Use of the RAII method is more robust, including restoration of the correct previous values (in many cases, the restored values are hardcoded, which could get out-of-sync in case of changing defaults). Change-Id: I4f8f5109116c621aae3412171db8bded2b066ffa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198504 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/embeddedobj/qa/cppunit/general.cxx b/embeddedobj/qa/cppunit/general.cxx index 8c128c0ccddb..71b85262ee80 100644 --- a/embeddedobj/qa/cppunit/general.cxx +++ b/embeddedobj/qa/cppunit/general.cxx @@ -8,6 +8,7 @@ */ #include <config_poppler.h> +#include <test/commontesttools.hxx> #include <test/unoapi_test.hxx> #include <com/sun/star/embed/XStorage.hpp> @@ -36,17 +37,8 @@ public: CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfig) { // Explicitly disable Word->Writer mapping for this test. - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(false, pBatch); - pBatch->commit(); - comphelper::ScopeGuard g([]() { - std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(true, - pBatchReset); - pBatchReset->commit(); - }); + ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter> aCfg( + false); loadFromURL(u"private:factory/swriter"_ustr); // Insert a file as an embedded object. @@ -68,17 +60,9 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfig) CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigVsdx) { - // Explicitly disable Word->Writer mapping for this test. - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(false, pBatch); - pBatch->commit(); - comphelper::ScopeGuard g([]() { - std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(true, pBatchReset); - pBatchReset->commit(); - }); + // Explicitly disable Visio->Draw mapping for this test. + ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw> aCfg( + false); loadFromURL(u"private:factory/swriter"_ustr); // Insert a file as an embedded object. @@ -101,17 +85,8 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigVsdx) #if ENABLE_PDFIMPORT CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigPdf) { - // Explicitly disable Word->Writer mapping for this test. - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(false, pBatch); - pBatch->commit(); - comphelper::ScopeGuard g([]() { - std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(true, pBatchReset); - pBatchReset->commit(); - }); + // Explicitly disable PDF->Draw mapping for this test. + ScopedConfigValue<officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw> aCfg(false); loadFromURL(u"private:factory/swriter"_ustr); // Insert a PDF file as an embedded object. diff --git a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx index d8093e57a4e8..d701b7437ce8 100644 --- a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx +++ b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx @@ -17,6 +17,7 @@ #include <comphelper/scopeguard.hxx> #include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> class AccessibilityCheckTest : public SwModelTestBase { @@ -434,16 +435,8 @@ CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testOnlineNodeSplitAppend) CPPUNIT_ASSERT(pWrtShell); // Enable online a11y checker - { - auto pBatch(comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::set(true, pBatch); - pBatch->commit(); - } - comphelper::ScopeGuard g([] { - auto pBatch(comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::set(false, pBatch); - pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck> aCfg( + true); Scheduler::ProcessEventsToIdle(); diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index 7e6452a90ce4..85ed844a6015 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -28,6 +28,7 @@ #include <fldmgr.hxx> #include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> /// Test to assert layout / rendering result of Writer. class SwLayoutWriter : public SwModelTestBase @@ -764,14 +765,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInBody) CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testFlyHiddenParagraph) { // disable Field Names warning dialog - const bool bAsk = officecfg::Office::Common::Misc::QueryShowFieldName::get(); - std::shared_ptr<comphelper::ConfigurationChanges> xChanges; - if (bAsk) - { - xChanges = comphelper::ConfigurationChanges::create(); - officecfg::Office::Common::Misc::QueryShowFieldName::set(false, xChanges); - xChanges->commit(); - } + ScopedConfigValue<officecfg::Office::Common::Misc::QueryShowFieldName> aCfg(false); createSwDoc("fly_hidden_paragraph.fodt"); @@ -819,12 +813,6 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testFlyHiddenParagraph) // so just hardcode it... dispatchCommand(mxComponent, ".uno:Fieldnames", args); Scheduler::ProcessEventsToIdle(); - - if (bAsk) - { - officecfg::Office::Common::Misc::QueryShowFieldName::set(true, xChanges); - xChanges->commit(); - } } CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testFieldHideSection) diff --git a/sw/qa/extras/layout/layout4.cxx b/sw/qa/extras/layout/layout4.cxx index ebe72e405b53..2d5ec972dc5c 100644 --- a/sw/qa/extras/layout/layout4.cxx +++ b/sw/qa/extras/layout/layout4.cxx @@ -31,6 +31,7 @@ #include <frameformats.hxx> #include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> namespace { @@ -48,27 +49,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testHiddenSectionPageDescs) { createSwDoc("hidden-sections-with-pagestyles.odt"); - // disable Field Names warning dialog - const bool bAsk = officecfg::Office::Common::Misc::QueryShowFieldName::get(); - std::shared_ptr<comphelper::ConfigurationChanges> xChanges; - if (bAsk) { - xChanges = comphelper::ConfigurationChanges::create(); - officecfg::Office::Common::Misc::QueryShowFieldName::set(false, xChanges); - xChanges->commit(); - } - - // hide these just so that the height of the section is what is expected; - // otherwise height depends on which tests run previously - uno::Sequence<beans::PropertyValue> argsSH( - comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", uno::Any(false) } })); - dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH); - uno::Sequence<beans::PropertyValue> args( - comphelper::InitPropertySequence({ { "Fieldnames", uno::Any(false) } })); - dispatchCommand(mxComponent, ".uno:Fieldnames", args); - Scheduler::ProcessEventsToIdle(); + // disable Field Names warning dialog + ScopedConfigValue<officecfg::Office::Common::Misc::QueryShowFieldName> aCfg(false); + + // hide these just so that the height of the section is what is expected; + // otherwise height depends on which tests run previously + uno::Sequence<beans::PropertyValue> argsSH( + comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", uno::Any(false) } })); + dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH); + uno::Sequence<beans::PropertyValue> args( + comphelper::InitPropertySequence({ { "Fieldnames", uno::Any(false) } })); + dispatchCommand(mxComponent, ".uno:Fieldnames", args); + Scheduler::ProcessEventsToIdle(); - { xmlDocUniquePtr pXmlDoc = parseLayoutDump(); assertXPath(pXmlDoc, "/root/page", 2); assertXPath(pXmlDoc, "/root/page[1]", "formatName", u"Hotti"); @@ -87,12 +81,6 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testHiddenSectionPageDescs) assertXPath(pXmlDoc, "/root/page[2]", "formatName", u"Folgeseite"); } - if (bAsk) - { - officecfg::Office::Common::Misc::QueryShowFieldName::set(true, xChanges); - xChanges->commit(); - } - // toggle one section hidden and other visible executeMacro( u"vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document"_ustr); diff --git a/sw/qa/extras/odfexport/odfexport4.cxx b/sw/qa/extras/odfexport/odfexport4.cxx index a0f669944328..63a9e25e119d 100644 --- a/sw/qa/extras/odfexport/odfexport4.cxx +++ b/sw/qa/extras/odfexport/odfexport4.cxx @@ -35,9 +35,12 @@ #include <IDocumentLinksAdministration.hxx> #include <sfx2/linkmgr.hxx> #include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> namespace { +using ScriptingCfg = officecfg::Office::Common::Security::Scripting; + class Test : public SwModelTestBase { public: @@ -81,63 +84,60 @@ CPPUNIT_TEST_FIXTURE(Test, tdf150927) CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData) { - // 1. Remove personal info, keep user info - auto pBatch(comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true, pBatch); - officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(true, pBatch); - pBatch->commit(); - - createSwDoc("personalmetadata.odt"); - saveAndReload(TestFilter::ODT); - xmlDocUniquePtr pXmlDoc = parseExport(u"meta.xml"_ustr); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:initial-creator", 1); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:creation-date", 1); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:date", 1); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:creator", 1); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:printed-by", 1); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:print-date", 1); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-cycles", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:template", 0); - pXmlDoc = parseExport(u"settings.xml"_ustr); - assertXPath(pXmlDoc, - "/office:document-settings/office:settings/config:config-item-set[2]/" - "config:config-item[@config:name='PrinterName']", - 0); - assertXPath(pXmlDoc, - "/office:document-settings/office:settings/config:config-item-set[2]/" - "config:config-item[@config:name='PrinterSetup']", - 0); - - // 2. Remove user info too - officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(false, pBatch); - pBatch->commit(); - - createSwDoc("personalmetadata.odt"); - saveAndReload(TestFilter::ODT); - pXmlDoc = parseExport(u"meta.xml"_ustr); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:initial-creator", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:creation-date", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:date", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:creator", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:printed-by", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:print-date", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-cycles", 0); - assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:template", 0); - pXmlDoc = parseExport(u"settings.xml"_ustr); - assertXPath(pXmlDoc, - "/office:document-settings/office:settings/config:config-item-set[2]/" - "config:config-item[@config:name='PrinterName']", - 0); - assertXPath(pXmlDoc, - "/office:document-settings/office:settings/config:config-item-set[2]/" - "config:config-item[@config:name='PrinterSetup']", - 0); + ScopedConfigValue<ScriptingCfg::RemovePersonalInfoOnSaving> aCfg1(true); + { + // 1. Remove personal info, keep user info + ScopedConfigValue<ScriptingCfg::KeepDocUserInfoOnSaving> aCfg2(true); + + createSwDoc("personalmetadata.odt"); + saveAndReload(TestFilter::ODT); + xmlDocUniquePtr pXmlDoc = parseExport(u"meta.xml"_ustr); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:initial-creator", 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:creation-date", 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:date", 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:creator", 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:printed-by", 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:print-date", 1); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-cycles", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:template", 0); + pXmlDoc = parseExport(u"settings.xml"_ustr); + assertXPath(pXmlDoc, + "/office:document-settings/office:settings/config:config-item-set[2]/" + "config:config-item[@config:name='PrinterName']", + 0); + assertXPath(pXmlDoc, + "/office:document-settings/office:settings/config:config-item-set[2]/" + "config:config-item[@config:name='PrinterSetup']", + 0); + } - // Reset config change - officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false, pBatch); - pBatch->commit(); + { + // 2. Remove user info too + ScopedConfigValue<ScriptingCfg::KeepDocUserInfoOnSaving> aCfg2(false); + + createSwDoc("personalmetadata.odt"); + saveAndReload(TestFilter::ODT); + xmlDocUniquePtr pXmlDoc = parseExport(u"meta.xml"_ustr); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:initial-creator", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:creation-date", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:date", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/dc:creator", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:printed-by", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:print-date", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:editing-cycles", 0); + assertXPath(pXmlDoc, "/office:document-meta/office:meta/meta:template", 0); + pXmlDoc = parseExport(u"settings.xml"_ustr); + assertXPath(pXmlDoc, + "/office:document-settings/office:settings/config:config-item-set[2]/" + "config:config-item[@config:name='PrinterName']", + 0); + assertXPath(pXmlDoc, + "/office:document-settings/office:settings/config:config-item-set[2]/" + "config:config-item[@config:name='PrinterSetup']", + 0); + } } CPPUNIT_TEST_FIXTURE(Test, testRemoveOnlyEditTimeMetaData) @@ -150,19 +150,13 @@ CPPUNIT_TEST_FIXTURE(Test, testRemoveOnlyEditTimeMetaData) u"PT21M22S"); // Set config RemoveEditingTimeOnSaving to true - auto pBatch(comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(true, pBatch); - pBatch->commit(); + ScopedConfigValue<ScriptingCfg::RemoveEditingTimeOnSaving> aCfg(true); // 2. Check edit time info is 0 createSwDoc("personalmetadata.odt"); save(TestFilter::ODT); pXmlDoc = parseExport(u"meta.xml"_ustr); assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/meta:editing-duration", u"P0D"); - - // Reset config change - officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(false, pBatch); - pBatch->commit(); } CPPUNIT_TEST_FIXTURE(Test, tdf151100) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index 266105b85de4..69b4b084d3fa 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -31,6 +31,7 @@ #include <o3tl/string_view.hxx> #include <comphelper/scopeguard.hxx> #include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> class Test : public SwModelTestBase { @@ -555,22 +556,10 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf134951_duplicates) CPPUNIT_TEST_FIXTURE(Test, testTdf135773_numberingShading) { - bool bIsExportAsShading = !officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::get(); - auto batch = comphelper::ConfigurationChanges::create(); - - // This function is run at the end of the test - returning the filter options to normal. - comphelper::ScopeGuard g( - [bIsExportAsShading, batch] - { - if (bIsExportAsShading) - { - officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::set(false, batch); - batch->commit(); - } - }); // For these test, ensure exporting CharBackground as w:highlight. - officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::set(true, batch); - batch->commit(); + ScopedConfigValue< + officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting> + aCfg(true); createSwDoc("tdf135774_numberingShading.docx"); save(TestFilter::DOCX); diff --git a/sw/qa/extras/uiwriter/uiwriter7.cxx b/sw/qa/extras/uiwriter/uiwriter7.cxx index 2fe8d2c10dc7..460fe78fc844 100644 --- a/sw/qa/extras/uiwriter/uiwriter7.cxx +++ b/sw/qa/extras/uiwriter/uiwriter7.cxx @@ -72,6 +72,7 @@ #include <rootfrm.hxx> #include <officecfg/Office/Writer.hxx> #include <vcl/idletask.hxx> +#include <test/commontesttools.hxx> namespace { @@ -1849,11 +1850,10 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf151605) createSwDoc("tdf151605.odt"); // disable IncludeHiddenText - std::shared_ptr<comphelper::ConfigurationChanges> batch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText::set(false, batch); - officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(false, batch); - batch->commit(); + ScopedConfigValue<officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText> aCfg1( + false); + ScopedConfigValue<officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection> aCfg2( + false); dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {}); dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); @@ -1866,11 +1866,6 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf151605) CPPUNIT_ASSERT_EQUAL(u"Before"_ustr, getParagraph(1)->getString()); CPPUNIT_ASSERT_EQUAL(u"After"_ustr, getParagraph(2)->getString()); - - // re-enable it - officecfg::Office::Writer::FilterFlags::ASCII::IncludeHiddenText::set(true, batch); - officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(true, batch); - batch->commit(); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf90362) diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index b6ab384433b9..46c500d3c7fa 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -67,6 +67,7 @@ #include <pagefrm.hxx> #include <svx/svdview.hxx> #include <svx/svdmark.hxx> +#include <test/commontesttools.hxx> namespace { @@ -159,14 +160,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testHiddenSectionShape) ->getName()); // prevent the warning dialog which is automatically cancelled - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(false, pBatch); - pBatch->commit(); - comphelper::ScopeGuard _([&] { - officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::set(true, pBatch); - pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection> aCfg( + false); // backspace should delete the hidden section pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1); @@ -995,14 +990,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf165351) CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf151710) { // Turn "Enclose with characters" on temporarily - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters::set(true, pBatch); - pBatch->commit(); - comphelper::ScopeGuard _([&] { - officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters::set(false, pBatch); - pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters> aCfg( + true); createSwDoc(); @@ -1085,14 +1074,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf151710) CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf167132) { // Turn "Enclose with characters" on temporarily - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters::set(true, pBatch); - pBatch->commit(); - comphelper::ScopeGuard _([&] { - officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters::set(false, pBatch); - pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters> aCfg( + true); // Given a document with several paragraphs, and a formula object createSwDoc("text-with-formula.fodt"); @@ -1170,14 +1153,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf167132) CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf167133) { // Turn "Enclose with characters" on temporarily - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters::set(true, pBatch); - pBatch->commit(); - comphelper::ScopeGuard _([&] { - officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters::set(false, pBatch); - pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Writer::FmtAidsAutocomplete::EncloseWithCharacters> aCfg( + true); // Given a document with a single paragraph, having a formula object createSwDoc("text-with-formula-one-paragraph.fodt"); @@ -1233,16 +1210,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159054_disableOutlineNumbering) CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158375_dde_disable) { - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(true, pBatch); - pBatch->commit(); - comphelper::ScopeGuard g([] { - std::shared_ptr<comphelper::ConfigurationChanges> _pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(false, _pBatch); - _pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Common::Security::Scripting::DisableActiveContent> aCfg( + true); createSwDoc(); SwDoc* pDoc = getSwDoc(); @@ -1297,16 +1266,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158375_dde_disable) CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158375_ole_object_disable) { - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(true, pBatch); - pBatch->commit(); - comphelper::ScopeGuard g([] { - std::shared_ptr<comphelper::ConfigurationChanges> _pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Security::Scripting::DisableActiveContent::set(false, _pBatch); - _pBatch->commit(); - }); + ScopedConfigValue<officecfg::Office::Common::Security::Scripting::DisableActiveContent> aCfg( + true); // Enable LOK mode, otherwise OCommonEmbeddedObject::SwitchStateTo_Impl() will throw when it // finds out that the test runs headless. diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index ab6005562dc0..b98f27df3339 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -51,6 +51,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/compbase.hxx> +#include <test/commontesttools.hxx> #include <wrtsh.hxx> #include <ndtxt.hxx> @@ -973,16 +974,8 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testRenderablePagePosition) CPPUNIT_TEST_FIXTURE(SwUnoWriter, testPasteListener) { - comphelper::ScopeGuard g([]() { - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::Cursor::Option::SelectPastedAnchoredObject::set(false, pBatch); - return pBatch->commit(); - }); - std::shared_ptr<comphelper::ConfigurationChanges> pBatch( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Writer::Cursor::Option::SelectPastedAnchoredObject::set(true, pBatch); - pBatch->commit(); + ScopedConfigValue<officecfg::Office::Writer::Cursor::Option::SelectPastedAnchoredObject> aCfg( + true); createSwDoc(); diff --git a/sw/qa/writerfilter/dmapper/GraphicImport.cxx b/sw/qa/writerfilter/dmapper/GraphicImport.cxx index 1bac2878ebda..a29fd6673bb2 100644 --- a/sw/qa/writerfilter/dmapper/GraphicImport.cxx +++ b/sw/qa/writerfilter/dmapper/GraphicImport.cxx @@ -7,6 +7,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <sal/config.h> + +#include <test/commontesttools.hxx> #include <test/unoapixml_test.hxx> #include <com/sun/star/awt/Point.hpp> @@ -383,14 +386,8 @@ CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellOfHraphics) CPPUNIT_TEST_FIXTURE(Test, testTdf149840SmartArtBackground) { // Make sure SmartArt is loaded as group shape - bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); - if (!bUseGroup) - { - std::shared_ptr<comphelper::ConfigurationChanges> pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); - pChange->commit(); - } + ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes> aCfg( + true); loadFromFile(u"tdf149840_SmartArtBackground.docx"); uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); @@ -419,14 +416,6 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf149840SmartArtBackground) // The test would have failed with Expected: 2404x5226, Actual: 2910x5226 CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(2404), aShapeTwoSize.Width, 1); CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(5226), aShapeTwoSize.Height, 1); - - if (!bUseGroup) - { - std::shared_ptr<comphelper::ConfigurationChanges> pChange( - comphelper::ConfigurationChanges::create()); - officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); - pChange->commit(); - } } } commit 6437d0c99f71c9ed0dffdb3dc84639eda2ac404e Author: Mike Kaganski <[email protected]> AuthorDate: Mon Feb 2 10:10:15 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Feb 2 08:43:08 2026 +0100 Drop SwExportFormFieldsGuard, and use ScopedConfigValue instead Change-Id: I1c0582ba9f4851096c9ffd138cd8b36a6822446d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198503 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/qa/core/text/itrform2.cxx b/sw/qa/core/text/itrform2.cxx index b8c9107a8ae3..6a02317ad084 100644 --- a/sw/qa/core/text/itrform2.cxx +++ b/sw/qa/core/text/itrform2.cxx @@ -21,6 +21,8 @@ #include <vcl/pdf/PDFAnnotationSubType.hxx> #include <vcl/pdf/PDFFormFieldType.hxx> #include <vcl/pdf/PDFPageObjectType.hxx> +#include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> #include <IDocumentLayoutAccess.hxx> #include <rootfrm.hxx> @@ -208,7 +210,7 @@ CPPUNIT_TEST_FIXTURE(Test, testCheckedCheckboxContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a checked checkbox content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -244,7 +246,7 @@ CPPUNIT_TEST_FIXTURE(Test, testContentControlPDFFontColor) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a document with a custom orange font color and a content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -277,7 +279,7 @@ CPPUNIT_TEST_FIXTURE(Test, testContentControlPDFDropDownText) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a document with a dropdown: custom default text and 3 items: createSwDoc(); uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 565889bbdda0..75680d8c7ad8 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -29,6 +29,8 @@ #include <comphelper/sequenceashashmap.hxx> #include <editeng/fhgtitem.hxx> #include <editeng/wghtitem.hxx> +#include <officecfg/Office/Common.hxx> +#include <test/commontesttools.hxx> #include <docsh.hxx> #include <unotxdoc.hxx> @@ -220,7 +222,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf159924) CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf159336) { - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); createSwDoc("tdf159336.odt"); save(TestFilter::PDF_WRITER); @@ -1036,7 +1038,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1083,7 +1085,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPlaceholderPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a content control, in placeholder mode: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1111,7 +1113,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a checkbox content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1141,7 +1143,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a dropdown content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1171,7 +1173,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF2) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); createSwDoc("tdf153040.docx"); save(TestFilter::PDF_WRITER); @@ -1196,7 +1198,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDateContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a date content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1229,7 +1231,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDFFont) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a document with a custom 24pt font size and a content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1261,7 +1263,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testComboContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a combo box content control: createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1292,7 +1294,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRichContentControlPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a rich content control, its value set to "xxx<b>yyy</b>": createSwDoc(); SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); @@ -1328,7 +1330,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testPlaceholderFieldPDF) if (!pPDFium) return; - SwExportFormFieldsGuard g; + ScopedConfigValue<officecfg::Office::Common::Filter::PDF::Export::ExportFormFields> aCfg(true); // Given a file with a text-type placeholder field: createSwDoc("placeholder.fodt"); diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx index 11967d327dd5..51c2efafbef4 100644 --- a/sw/qa/inc/swmodeltestbase.hxx +++ b/sw/qa/inc/swmodeltestbase.hxx @@ -47,10 +47,6 @@ #define DECLARE_WW8EXPORT_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, TestFilter::DOC) class SwXTextDocument; -namespace comphelper -{ -class ConfigurationChanges; -} namespace vcl { namespace pdf @@ -59,16 +55,6 @@ class PDFiumDocument; } } -/// Temporarily enables the ExportFormFields setting. -class SWQAHELPER_DLLPUBLIC SwExportFormFieldsGuard -{ - std::shared_ptr<comphelper::ConfigurationChanges> m_pBatch; - bool m_bValue; -public: - SwExportFormFieldsGuard(); - ~SwExportFormFieldsGuard(); -}; - /// Base class for filter tests loading or roundtripping a document, then asserting the document model. class SWQAHELPER_DLLPUBLIC SwModelTestBase : public UnoApiXmlTest { diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index e149687a9cf1..7a1c0d5609ad 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -24,8 +24,6 @@ #include <unotools/ucbstreamhelper.hxx> #include <vcl/scheduler.hxx> #include <comphelper/configuration.hxx> -#include <officecfg/Office/Writer.hxx> -#include <officecfg/Office/Common.hxx> #include <IDocumentLayoutAccess.hxx> #include <docsh.hxx> @@ -485,18 +483,4 @@ void SwModelTestBase::emulateTyping(std::u16string_view rStr) } } -SwExportFormFieldsGuard::SwExportFormFieldsGuard() -{ - m_pBatch = comphelper::ConfigurationChanges::create(); - m_bValue = officecfg::Office::Common::Filter::PDF::Export::ExportFormFields::get(); - officecfg::Office::Common::Filter::PDF::Export::ExportFormFields::set(true, m_pBatch); - m_pBatch->commit(); -} - -SwExportFormFieldsGuard::~SwExportFormFieldsGuard() -{ - officecfg::Office::Common::Filter::PDF::Export::ExportFormFields::set(m_bValue, m_pBatch); - m_pBatch->commit(); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
