include/test/commontesttools.hxx           |   41 ++++++++++++++
 oox/qa/unit/shape.cxx                      |   37 +------------
 sc/qa/unit/subsequent_export_test4.cxx     |   39 ++------------
 sc/qa/unit/subsequent_filters_test3.cxx    |   55 ++-----------------
 sw/qa/extras/autocorrect/autocorrect.cxx   |   14 -----
 sw/qa/extras/globalfilter/globalfilter.cxx |   14 +----
 sw/qa/extras/htmlexport/htmlexport2.cxx    |   29 +---------
 sw/qa/extras/layout/layout6.cxx            |   80 +++++++----------------------
 sw/qa/extras/odfexport/odfexport.cxx       |   26 +--------
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx |   27 +--------
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx |   14 -----
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx |   26 +++------
 sw/qa/extras/ooxmlexport/ooxmlexport23.cxx |   17 +-----
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx  |   14 +----
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx   |   15 +----
 sw/qa/extras/uiwriter/uiwriter11.cxx       |   13 ----
 sw/qa/extras/uiwriter/uiwriter2.cxx        |   17 +-----
 17 files changed, 133 insertions(+), 345 deletions(-)

New commits:
commit 3a9f1198abb192bb6e6b479603983290170f8cd5
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Feb 1 13:53:28 2026 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Feb 1 12:21:11 2026 +0100

    Introduce ScopedConfigValue for easier scoped officecfg manipulation
    
    Helps to reliably restore the correct previous value of a setting:
    in many cases, the old restoration code used hardcoded values, which
    could get out of sync with current defaults. Also, makes the code
    easier to read.
    
    Change-Id: Ia60b4e42192009c16bdbe58c540980c13626d5d8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198479
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/include/test/commontesttools.hxx b/include/test/commontesttools.hxx
new file mode 100644
index 000000000000..dbad46e3f0ee
--- /dev/null
+++ b/include/test/commontesttools.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <comphelper/configuration.hxx>
+
+// RAII-style management of officecfg settings. Sets the setting specified as 
template parameter,
+// to a value passed in constructor. Stores the previous value of the setting, 
and restores it in
+// destructor.
+template <class OfficeCfg> class ScopedConfigValue
+{
+    using ConfigValue_t = decltype(OfficeCfg::get());
+
+public:
+    ScopedConfigValue(const ConfigValue_t& rNewVal)
+        : maOrigValue(OfficeCfg::get())
+    {
+        auto pChanges(comphelper::ConfigurationChanges::create());
+        OfficeCfg::set(rNewVal, pChanges);
+        pChanges->commit();
+    }
+    ScopedConfigValue(const ScopedConfigValue&) = delete;
+    ~ScopedConfigValue()
+    {
+        auto pChanges(comphelper::ConfigurationChanges::create());
+        OfficeCfg::set(maOrigValue, pChanges);
+        pChanges->commit();
+    }
+
+private:
+    ConfigValue_t maOrigValue;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx
index f3bc4ed12832..a6b31e201a69 100644
--- a/oox/qa/unit/shape.cxx
+++ b/oox/qa/unit/shape.cxx
@@ -9,6 +9,7 @@
 
 #include <sal/config.h>
 
+#include <test/commontesttools.hxx>
 #include <test/unoapi_test.hxx>
 
 #include <string_view>
@@ -404,14 +405,8 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf151008VertAnchor)
 CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf151518VertAnchor)
 {
     // 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);
 
     // The document contains SmartArt with shapes with not default text area. 
Without fix the
     // text was shifted up because of wrong values in TextLowerDistance and 
TextUpperDistance.
@@ -443,14 +438,6 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf151518VertAnchor)
         CPPUNIT_ASSERT_EQUAL(aExpected[i].nLowerDistance, nLower);
         CPPUNIT_ASSERT_EQUAL(aExpected[i].nUpperDistance, nUpper);
     }
-
-    if (!bUseGroup)
-    {
-        std::shared_ptr<comphelper::ConfigurationChanges> pChange(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false,
 pChange);
-        pChange->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf54095_SmartArtThemeTextColor)
@@ -460,14 +447,8 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, 
testTdf54095_SmartArtThemeTextColor)
     // Error was, that the theme was not considered and therefore the text was 
white.
 
     // Make sure it is not loaded as metafile but with single shapes.
-    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);
 
     // get SmartArt
     loadFromFile(u"tdf54095_SmartArtThemeTextColor.docx");
@@ -499,14 +480,6 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, 
testTdf54095_SmartArtThemeTextColor)
     CPPUNIT_ASSERT(xComplexColor.is());
     auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
     CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Dark2, 
aComplexColor.getThemeColorType());
-
-    if (!bUseGroup)
-    {
-        std::shared_ptr<comphelper::ConfigurationChanges> pChange(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false,
 pChange);
-        pChange->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWriterFontwork)
diff --git a/sc/qa/unit/subsequent_export_test4.cxx 
b/sc/qa/unit/subsequent_export_test4.cxx
index d25c5b7332f1..cc3d419d09c4 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -37,6 +37,7 @@
 #include <comphelper/scopeguard.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <formula/grammar.hxx>
+#include <test/commontesttools.hxx>
 #include <tools/fldunit.hxx>
 #include <tools/UnitConversion.hxx>
 #include <svl/numformat.hxx>
@@ -1241,16 +1242,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testTdf142264ManyChartsToXLSX)
 {
     // The cache size for the test should be small enough, to make sure that 
some charts get
     // unloaded in the process, and then loaded on demand properly (default is 
currently 200)
-    comphelper::ScopeGuard g([]() {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(200, 
pBatch);
-        return pBatch->commit();
-    });
-    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-        comphelper::ConfigurationChanges::create());
-    officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(20, 
pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects> 
aCfg(20);
 
     createScDoc("ods/many_charts.ods");
     saveAndReload(TestFilter::XLSX);
@@ -2036,10 +2028,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testChangesAuthorDate)
 {
     createScDoc("ods/change-tracking.ods");
 
-    auto pBatch(comphelper::ConfigurationChanges::create());
     // Remove all personal info
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving>
+        aCfg(true);
 
     save(TestFilter::ODS);
     xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
@@ -2055,20 +2046,15 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testChangesAuthorDate)
                        
"table:tracked-changes/table:cell-content-change[1]/office:change-info/"
                        "dc:date",
                        u"1970-01-01T12:00:00");
-
-    // Reset config change
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false,
 pBatch);
-    pBatch->commit();
 }
 
 CPPUNIT_TEST_FIXTURE(ScExportTest4, testChangesAuthorDateXLSX)
 {
     createScDoc("xlsx/change-tracking.xlsx");
 
-    auto pBatch(comphelper::ConfigurationChanges::create());
     // Remove all personal info
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving>
+        aCfg(true);
 
     save(TestFilter::XLSX);
     xmlDocUniquePtr pXmlDoc = 
parseExport(u"xl/revisions/revisionHeaders.xml"_ustr);
@@ -2076,10 +2062,6 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, 
testChangesAuthorDateXLSX)
 
     assertXPath(pXmlDoc, "/x:headers/x:header[1]", "userName", u"Author1");
     assertXPath(pXmlDoc, "/x:headers/x:header[1]", "dateTime", 
u"1970-01-01T12:00:00.000000000Z");
-
-    // Reset config change
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false,
 pBatch);
-    pBatch->commit();
 }
 
 CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf163554)
@@ -2106,20 +2088,15 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testNotesAuthor)
 {
     createScDoc("xlsx/cell-note.xlsx");
 
-    auto pBatch(comphelper::ConfigurationChanges::create());
     // Remove all personal info
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving>
+        aCfg(true);
 
     save(TestFilter::XLSX);
     xmlDocUniquePtr pXmlDoc = parseExport(u"xl/comments1.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
     assertXPathContent(pXmlDoc, "/x:comments/x:authors/x:author", u"Author1");
-
-    // Reset config change
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false,
 pBatch);
-    pBatch->commit();
 }
 
 CPPUNIT_TEST_FIXTURE(ScExportTest4, testSheetProtections)
diff --git a/sc/qa/unit/subsequent_filters_test3.cxx 
b/sc/qa/unit/subsequent_filters_test3.cxx
index dd6733e8c90a..937b4b69d0f5 100644
--- a/sc/qa/unit/subsequent_filters_test3.cxx
+++ b/sc/qa/unit/subsequent_filters_test3.cxx
@@ -48,6 +48,7 @@
 #include <com/sun/star/text/XTextRange.hpp>
 
 #include <comphelper/scopeguard.hxx>
+#include <test/commontesttools.hxx>
 #include <unotools/syslocaleoptions.hxx>
 #include "helper/qahelper.hxx"
 #include <officecfg/Office/Common.hxx>
@@ -1474,14 +1475,8 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testTdf83671_SmartArt_import)
     // Error was, that the background shape had size zero and the diagram 
shapes where missing.
 
     // 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);
 
     // Get document and shape
     createScDoc("xlsx/tdf83671_SmartArt_import.xlsx");
@@ -1500,14 +1495,6 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testTdf83671_SmartArt_import)
     tools::Rectangle aBackground = pChildren->GetObj(0)->GetLogicRect();
     CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6000), aBackground.getOpenWidth(), 
10);
     CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4200), aBackground.getOpenHeight(), 
10);
-
-    if (!bUseGroup)
-    {
-        std::shared_ptr<comphelper::ConfigurationChanges> pChange(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false,
 pChange);
-        pChange->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf83671_SmartArt_import2)
@@ -1517,14 +1504,8 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testTdf83671_SmartArt_import2)
     // had size 100x100 Hmm and position 0|0.
 
     // Make sure SmartArt is loaded with converting to metafile
-    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(false,
 pChange);
-        pChange->commit();
-    }
+    
ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes>
 aCfg(
+        false);
 
     // Get document and shape
     createScDoc("xlsx/tdf83671_SmartArt_import.xlsx");
@@ -1544,14 +1525,6 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testTdf83671_SmartArt_import2)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6000), aBackground.getOpenWidth(), 
10);
     CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4200), aBackground.getOpenHeight(), 
10);
     CPPUNIT_ASSERT_EQUAL(Point(1164, 1270), aBackground.GetPos());
-
-    if (bUseGroup)
-    {
-        std::shared_ptr<comphelper::ConfigurationChanges> pChange(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true,
 pChange);
-        pChange->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf151818_SmartArtFontColor)
@@ -1561,14 +1534,8 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testTdf151818_SmartArtFontColor)
     // Error was, that the theme was not considered and therefore the text was 
white.
 
     // Make sure it is not loaded as metafile but with single shapes.
-    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);
 
     // Get document and shape in SmartArt object
     createScDoc("xlsx/tdf151818_SmartartThemeFontColor.xlsx");
@@ -1597,14 +1564,6 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, 
testTdf151818_SmartArtFontColor)
     // Without fix the color scheme was "lt1" (1) but should be "dk2" (2).
     CPPUNIT_ASSERT_EQUAL(sal_Int16(2),
                          
xPortion->getPropertyValue(u"CharColorTheme"_ustr).get<sal_Int16>());
-
-    if (!bUseGroup)
-    {
-        std::shared_ptr<comphelper::ConfigurationChanges> pChange(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false,
 pChange);
-        pChange->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf137216_HideCol)
diff --git a/sw/qa/extras/autocorrect/autocorrect.cxx 
b/sw/qa/extras/autocorrect/autocorrect.cxx
index 203dcd979ec6..2668f7661140 100644
--- a/sw/qa/extras/autocorrect/autocorrect.cxx
+++ b/sw/qa/extras/autocorrect/autocorrect.cxx
@@ -15,6 +15,7 @@
 #include <ndtxt.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <swacorr.hxx>
+#include <test/commontesttools.hxx>
 #include <unotools/syslocaleoptions.hxx>
 #include <unotxdoc.hxx>
 #include <wrtsh.hxx>
@@ -339,18 +340,7 @@ CPPUNIT_TEST_FIXTURE(SwAutoCorrectTest, testFieldMark)
 
 CPPUNIT_TEST_FIXTURE(SwAutoCorrectTest, testUnderlineWeight)
 {
-    Resetter resetter([]() {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::AutoCorrect::ChangeUnderlineWeight::set(false, 
pBatch);
-        
officecfg::Office::Common::AutoCorrect::ChangeUnderlineWeight::set(false, 
pBatch);
-        return pBatch->commit();
-    });
-    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-        comphelper::ConfigurationChanges::create());
-    officecfg::Office::Common::AutoCorrect::ChangeUnderlineWeight::set(true, 
pBatch);
-    officecfg::Office::Common::AutoCorrect::ChangeUnderlineWeight::set(true, 
pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::AutoCorrect::ChangeUnderlineWeight>
 aCfg(true);
 
     createSwDoc(); // Default lang is en-US
 
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx 
b/sw/qa/extras/globalfilter/globalfilter.cxx
index 16e150b51217..e7f132ea20a0 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -41,6 +41,7 @@
 #include <IDocumentMarkAccess.hxx>
 #include <IMark.hxx>
 #include <com/sun/star/awt/FontWeight.hpp>
+#include <test/commontesttools.hxx>
 #include <unotools/saveopt.hxx>
 
 namespace
@@ -849,16 +850,9 @@ void Test::testSkipImages()
 void Test::testNestedFieldmark()
 {
     // experimental config setting
-    Resetter resetter(
-        [] () {
-            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-                    comphelper::ConfigurationChanges::create());
-            
officecfg::Office::Common::Filter::Microsoft::Import::ForceImportWWFieldsAsGenericFields::set(false,
 pBatch);
-            return pBatch->commit();
-        });
-    std::shared_ptr<comphelper::ConfigurationChanges> 
pBatch(comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Filter::Microsoft::Import::ForceImportWWFieldsAsGenericFields::set(true,
 pBatch);
-    pBatch->commit();
+    ScopedConfigValue<
+        
officecfg::Office::Common::Filter::Microsoft::Import::ForceImportWWFieldsAsGenericFields>
+        aCfg(true);
 
     auto verify = [this](OUString const& rTestName) {
         SwDoc* pDoc = getSwDoc();
diff --git a/sw/qa/extras/htmlexport/htmlexport2.cxx 
b/sw/qa/extras/htmlexport/htmlexport2.cxx
index 1952fba15b30..bf40f5a176ac 100644
--- a/sw/qa/extras/htmlexport/htmlexport2.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport2.cxx
@@ -22,6 +22,7 @@
 #include <vcl/graphicfilter.hxx>
 #include <vcl/dibtools.hxx>
 #include <editeng/brushitem.hxx>
+#include <test/commontesttools.hxx>
 
 #include <wrtsh.hxx>
 #include <ndtxt.hxx>
@@ -1325,19 +1326,9 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testHTML_161979)
 
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqIF_exportAbsoluteURLs_ownRelative)
 {
-    auto pBatch(comphelper::ConfigurationChanges::create());
-    Resetter resetter([
-        bInternetPreviousValue = 
officecfg::Office::Common::Save::URL::Internet::get(),
-        bFileSystemPreviousValue = 
officecfg::Office::Common::Save::URL::FileSystem::get(), pBatch
-    ]() {
-        
officecfg::Office::Common::Save::URL::Internet::set(bInternetPreviousValue, 
pBatch);
-        
officecfg::Office::Common::Save::URL::FileSystem::set(bFileSystemPreviousValue, 
pBatch);
-        return pBatch->commit();
-    });
     // Set saving absolute URLs
-    officecfg::Office::Common::Save::URL::Internet::set(false, pBatch);
-    officecfg::Office::Common::Save::URL::FileSystem::set(false, pBatch);
-    pBatch->commit();
+    ScopedConfigValue<officecfg::Office::Common::Save::URL::Internet> 
aCfg1(false);
+    ScopedConfigValue<officecfg::Office::Common::Save::URL::FileSystem> 
aCfg2(false);
 
     createSwDoc("URLs.odt");
     // Export to ReqIF, using absolute URLs
@@ -1446,19 +1437,9 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqIF_exportRelativeURLs)
 
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testHTML_exportAbsoluteURLs_ownRelative)
 {
-    auto pBatch(comphelper::ConfigurationChanges::create());
-    Resetter resetter([
-        bInternetPreviousValue = 
officecfg::Office::Common::Save::URL::Internet::get(),
-        bFileSystemPreviousValue = 
officecfg::Office::Common::Save::URL::FileSystem::get(), pBatch
-    ]() {
-        
officecfg::Office::Common::Save::URL::Internet::set(bInternetPreviousValue, 
pBatch);
-        
officecfg::Office::Common::Save::URL::FileSystem::set(bFileSystemPreviousValue, 
pBatch);
-        return pBatch->commit();
-    });
     // Set saving absolute URLs
-    officecfg::Office::Common::Save::URL::Internet::set(false, pBatch);
-    officecfg::Office::Common::Save::URL::FileSystem::set(false, pBatch);
-    pBatch->commit();
+    ScopedConfigValue<officecfg::Office::Common::Save::URL::Internet> 
aCfg1(false);
+    ScopedConfigValue<officecfg::Office::Common::Save::URL::FileSystem> 
aCfg2(false);
 
     createSwDoc("URLs.odt");
     // Export to HTML, using absolute URLs
diff --git a/sw/qa/extras/layout/layout6.cxx b/sw/qa/extras/layout/layout6.cxx
index 0bca86f1d7f0..f8b68d65ac50 100644
--- a/sw/qa/extras/layout/layout6.cxx
+++ b/sw/qa/extras/layout/layout6.cxx
@@ -20,6 +20,7 @@
 #include <editeng/postitem.hxx>
 #include <editeng/unolingu.hxx>
 #include <comphelper/sequence.hxx>
+#include <test/commontesttools.hxx>
 
 #include <anchoredobject.hxx>
 #include <fmtfsize.hxx>
@@ -618,14 +619,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, 
testKeepWithNextPlusFlyFollowTextFlow)
     }
 
     // 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);
 
     dispatchCommand(mxComponent, u".uno:Fieldnames"_ustr, {});
 
@@ -657,12 +651,6 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, 
testKeepWithNextPlusFlyFollowTextFlow)
         assertXPath(pXmlDoc, "/root/page[1]/body/txt[3]/infos/bounds", 
"height", u"276");
         assertXPath(pXmlDoc, "/root/page", 1);
     }
-
-    if (bAsk)
-    {
-        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
-        xChanges->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf122607)
@@ -1559,36 +1547,24 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, 
testHiddenParagraphFollowFrame)
         dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
     });
 
-    // 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();
-    }
-    uno::Sequence<beans::PropertyValue> argsSH(
-        comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
-    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);
+
+        uno::Sequence<beans::PropertyValue> argsSH(
+            comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
+        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]/body/txt", 2);
         assertXPath(pXmlDoc, "/root/page[2]/body/txt", 2);
     }
 
-    if (bAsk)
-    {
-        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
-        xChanges->commit();
-    }
-
     dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", {});
 
     {
@@ -1620,34 +1596,22 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, 
testHiddenParagraphFlys)
         dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
     });
 
-    // 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();
-    }
-    uno::Sequence<beans::PropertyValue> argsSH(
-        comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
-    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);
+
+        uno::Sequence<beans::PropertyValue> argsSH(
+            comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
+        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/body/txt[3]/anchored/fly/infos/bounds", "height", u"724");
     }
 
-    if (bAsk)
-    {
-        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
-        xChanges->commit();
-    }
-
     dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", {});
 
     {
diff --git a/sw/qa/extras/odfexport/odfexport.cxx 
b/sw/qa/extras/odfexport/odfexport.cxx
index 196984dadded..59d5dd657819 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -51,6 +51,7 @@
 #include <svl/PasswordHelper.hxx>
 #include <comphelper/scopeguard.hxx>
 #include <docmodel/uno/UnoGradientTools.hxx>
+#include <test/commontesttools.hxx>
 #include <vcl/image.hxx>
 
 #include <docufld.hxx> // for SwHiddenTextField::ParseIfFieldDefinition() 
method call
@@ -67,16 +68,7 @@ public:
 
 CPPUNIT_TEST_FIXTURE(Test, testMathObjectFlatExport)
 {
-    comphelper::ScopeGuard g([]() {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        officecfg::Office::Common::Cache::Writer::OLE_Objects::set(20, pBatch);
-        return pBatch->commit();
-    });
-    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-        comphelper::ConfigurationChanges::create());
-    officecfg::Office::Common::Cache::Writer::OLE_Objects::set(1, pBatch);
-    pBatch->commit();
+    ScopedConfigValue<officecfg::Office::Common::Cache::Writer::OLE_Objects> 
aCfg(1);
     createSwDoc("2_MathType3.docx");
     saveAndReload(TestFilter::FODT); // doesn't happen with ODF package
 
@@ -915,17 +907,9 @@ DECLARE_ODFEXPORT_TEST(testTdf115815, "tdf115815.odt")
 
 CPPUNIT_TEST_FIXTURE(Test, testFdo58949)
 {
-    comphelper::ScopeGuard g([]() {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(true, 
pBatch);
-        pBatch->commit();
-    });
-
-    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-        comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(false,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath>
 aCfg(
+        false);
+
     createSwDoc("fdo58949.docx");
     saveAndReload(TestFilter::ODT);
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 42b9e5f35189..35ca217fdf1f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -34,6 +34,7 @@
 #include <comphelper/sequenceashashmap.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <oox/drawingml/drawingmltypes.hxx>
+#include <test/commontesttools.hxx>
 
 #include <unotxdoc.hxx>
 
@@ -65,17 +66,8 @@ DECLARE_OOXMLEXPORT_TEST(testWPGtextboxes, 
"testWPGtextboxes.docx")
 CPPUNIT_TEST_FIXTURE(Test, testSmartart)
 {
     // experimental config setting
-    bool bOrigSet = 
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get();
-    Resetter resetter(
-        [bOrigSet] () {
-            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-                    comphelper::ConfigurationChanges::create());
-            
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(bOrigSet,
 pBatch);
-            return pBatch->commit();
-        });
-    std::shared_ptr<comphelper::ConfigurationChanges> 
pBatch(comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes>
 aCfg(
+        true);
 
     auto verify = [this]() {
         CPPUNIT_ASSERT_EQUAL(1, getShapes());
@@ -605,17 +597,8 @@ DECLARE_OOXMLEXPORT_TEST(testStrict, "strict.docx")
 CPPUNIT_TEST_FIXTURE(Test, testSmartartStrict)
 {
     // experimental config setting
-    bool bOrigSet = 
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get();
-    Resetter resetter(
-        [bOrigSet] () {
-            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-                    comphelper::ConfigurationChanges::create());
-            
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(bOrigSet,
 pBatch);
-            return pBatch->commit();
-        });
-    std::shared_ptr<comphelper::ConfigurationChanges> 
pBatch(comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes>
 aCfg(
+        true);
 
     auto verify = [this]() {
         uno::Reference<container::XIndexAccess> xGroup(getShape(1), 
uno::UNO_QUERY);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 0471d49e16f6..8018edddf3d8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -32,6 +32,7 @@
 #include <officecfg/Office/Common.hxx>
 #include <o3tl/string_view.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <test/commontesttools.hxx>
 
 #include <unotxdoc.hxx>
 #include <docsh.hxx>
@@ -531,18 +532,7 @@ DECLARE_OOXMLEXPORT_TEST(testParaListRightIndent, 
"testParaListRightIndent.docx"
 CPPUNIT_TEST_FIXTURE(Test, testDontAddNewStyles)
 {
     // Given a document that lacks builtin styles, and addition of them is 
disabled:
-    {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        officecfg::Office::Common::Load::DisableBuiltinStyles::set(true, 
pBatch);
-        pBatch->commit();
-    }
-    comphelper::ScopeGuard g([] {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        officecfg::Office::Common::Load::DisableBuiltinStyles::set(false, 
pBatch);
-        pBatch->commit();
-    });
+    ScopedConfigValue<officecfg::Office::Common::Load::DisableBuiltinStyles> 
aCfg(true);
 
     // When saving that document:
     createSwDoc("dont-add-new-styles.docx");
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 97c0a3d06242..bfee6ba34487 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -26,6 +26,7 @@
 #include <comphelper/configuration.hxx>
 #include <comphelper/sequenceashashmap.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <test/commontesttools.hxx>
 
 #include <pam.hxx>
 #include <unotxdoc.hxx>
@@ -783,9 +784,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf160814_commentOrder)
 CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
 {
     // 1. Remove all personal info
-    auto pBatch(comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving>
+        aCfg1(true);
+
     createSwDoc("personalmetadata.docx");
     save(TestFilter::DOCX);
 
@@ -801,8 +802,9 @@ CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
     assertXPath(pCoreDoc, "/cp:coreProperties/cp:revision", 0);
 
     // 2. Remove personal information, keep user information
-    
officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving>
+        aCfg2(true);
+
     createSwDoc("personalmetadata.docx");
     save(TestFilter::DOCX);
 
@@ -816,11 +818,6 @@ CPPUNIT_TEST_FIXTURE(Test, testPersonalMetaData)
     assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastModifiedBy", 1);
     assertXPath(pCoreDoc, "/cp:coreProperties/cp:lastPrinted", 1);
     assertXPath(pCoreDoc, "/cp:coreProperties/cp:revision", 0);
-
-    // Reset config change
-    
officecfg::Office::Common::Security::Scripting::RemovePersonalInfoOnSaving::set(false,
 pBatch);
-    
officecfg::Office::Common::Security::Scripting::KeepDocUserInfoOnSaving::set(false,
 pBatch);
-    pBatch->commit();
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf169072_illegalDates)
@@ -846,19 +843,14 @@ CPPUNIT_TEST_FIXTURE(Test, testRemoveOnlyEditTimeMetaData)
     assertXPath(pAppDoc, 
"/extended-properties:Properties/extended-properties:TotalTime", 1);
 
     // Set config RemoveEditingTimeOnSaving to true
-    auto pBatch(comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving>
+        aCfg(true);
 
     // 2. Check edit time info is removed
     createSwDoc("personalmetadata.docx");
     save(TestFilter::DOCX);
     pAppDoc = parseExport(u"docProps/app.xml"_ustr);
     assertXPath(pAppDoc, 
"/extended-properties:Properties/extended-properties:TotalTime", 0);
-
-    // Reset config change
-    
officecfg::Office::Common::Security::Scripting::RemoveEditingTimeOnSaving::set(false,
 pBatch);
-    pBatch->commit();
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf126533_noPageBitmap, 
"tdf126533_noPageBitmap.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport23.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport23.cxx
index 226417add22e..15d789dd05a8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport23.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport23.cxx
@@ -21,6 +21,7 @@
 
 #include <comphelper/sequenceashashmap.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <test/commontesttools.hxx>
 
 using namespace com::sun::star;
 
@@ -39,12 +40,9 @@ CPPUNIT_TEST_FIXTURE(Test, testHighlightEdit_numbering)
     createSwDoc("tdf135774_numberingCRProps.docx");
 
     // This only affects when saving as w:highlight - which is not the default 
since 7.0.
-    bool bWasExportToShade = 
!officecfg::Office::Common::Filter::Microsoft::Export::
-                                 CharBackgroundToHighlighting::get();
-    auto batch = comphelper::ConfigurationChanges::create();
-    
officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::set(true,
-                                                                               
             batch);
-    batch->commit();
+    ScopedConfigValue<
+        
officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting>
+        aCfg(true);
 
     //Simulate a user editing the char background color of the paragraph 2 
marker (CR)
     uno::Reference<beans::XPropertySet> properties(getParagraph(2), 
uno::UNO_QUERY);
@@ -84,13 +82,6 @@ CPPUNIT_TEST_FIXTURE(Test, testHighlightEdit_numbering)
                 
"//w:style[@w:styleId='CustomParaStyleHighlightGreen']/w:rPr/w:highlight", 
"val",
                 u"green");
     // Visually, the last bullet point's text should be green-highlighted (but 
the bullet point itself shouldn't)
-
-    if (bWasExportToShade)
-    {
-        
officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::set(
-            false, batch);
-        batch->commit();
-    }
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf132766)
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 99594137150a..6540e8a523b9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -27,6 +27,7 @@
 #include <officecfg/Office/Writer.hxx>
 #include <vcl/svapp.hxx>
 #include <comphelper/scopeguard.hxx>
+#include <test/commontesttools.hxx>
 
 class Test : public SwModelTestBase
 {
@@ -880,17 +881,8 @@ CPPUNIT_TEST_FIXTURE(Test, 
tdf134043_ImportComboBoxAsDropDown_true)
 
 CPPUNIT_TEST_FIXTURE(Test, tdf134043_ImportComboBoxAsDropDown_false)
 {
-    std::shared_ptr<comphelper::ConfigurationChanges> batch(
-        comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::set(false,
 batch);
-    batch->commit();
-    comphelper::ScopeGuard g(
-        [batch]
-        {
-            
officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::set(true,
-                                                                               
            batch);
-            batch->commit();
-        });
+    
ScopedConfigValue<officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown>
+        aCfg(false);
 
     createSwDoc("combobox-control.docx");
     verifyComboBoxExport(false);
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index c31961af4cb0..f299a5e1ac4d 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -67,6 +67,7 @@
 #include <comphelper/sequenceashashmap.hxx>
 #include <vcl/TypeSerializer.hxx>
 #include <comphelper/scopeguard.hxx>
+#include <test/commontesttools.hxx>
 
 namespace
 {
@@ -1380,17 +1381,9 @@ CPPUNIT_TEST_FIXTURE(Test, testFdo87488)
     // The shape on the right (index 0, CustomShape within a
     // GroupShape) is rotated 90 degrees clockwise and contains text
     // rotated 90 degrees anticlockwise.
-    bool bOrigSet = 
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get();
-    Resetter resetter(
-        [bOrigSet] () {
-            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-                    comphelper::ConfigurationChanges::create());
-            
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(bOrigSet,
 pBatch);
-            return pBatch->commit();
-        });
-    std::shared_ptr<comphelper::ConfigurationChanges> 
pBatch(comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes>
 aCfg(
+        true);
+
     createSwDoc("fdo87488.docx");
     uno::Reference<container::XIndexAccess> group(getShape(1), uno::UNO_QUERY);
     {
diff --git a/sw/qa/extras/uiwriter/uiwriter11.cxx 
b/sw/qa/extras/uiwriter/uiwriter11.cxx
index c5a22b87ed93..4b36bd432a1a 100644
--- a/sw/qa/extras/uiwriter/uiwriter11.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter11.cxx
@@ -10,6 +10,7 @@
 #include <swmodeltestbase.hxx>
 
 #include <officecfg/Office/Writer.hxx>
+#include <test/commontesttools.hxx>
 #include <vcl/pdf/PDFPageObjectType.hxx>
 #include <vcl/scheduler.hxx>
 
@@ -481,17 +482,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest11, testTdf163194)
     // export doesn't change the annotation sizes in the document.
 
     // Annotation size depends on DisplayWidthFactor. Set it to a fixed value 
for testing.
-    comphelper::ScopeGuard
-        aReset([oldValue = 
officecfg::Office::Writer::Notes::DisplayWidthFactor::get()]() {
-            auto pChanges(comphelper::ConfigurationChanges::create());
-            
officecfg::Office::Writer::Notes::DisplayWidthFactor::set(oldValue, pChanges);
-            pChanges->commit();
-        });
-    {
-        auto pChanges(comphelper::ConfigurationChanges::create());
-        officecfg::Office::Writer::Notes::DisplayWidthFactor::set(4.0, 
pChanges);
-        pChanges->commit();
-    }
+    ScopedConfigValue<officecfg::Office::Writer::Notes::DisplayWidthFactor> 
aCfg(4.0);
 
     createSwDoc("tdf163194-two-comments.fodt");
 
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 731251c7f7c7..01252ff8666e 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -22,6 +22,7 @@
 #include <sfx2/dispatch.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <svx/svxids.hrc>
+#include <test/commontesttools.hxx>
 #include <view.hxx>
 #include <ndtxt.hxx>
 #include <wrtsh.hxx>
@@ -389,18 +390,10 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf137318)
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf136704)
 {
-    Resetter resetter([]() {
-        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-            comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Writer::AutoFunction::Format::ByInput::ReplaceStyle::set(false,
 pBatch);
-        
officecfg::Office::Writer::AutoFunction::Format::Option::ReplaceStyle::set(false,
 pBatch);
-        return pBatch->commit();
-    });
-    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
-        comphelper::ConfigurationChanges::create());
-    
officecfg::Office::Writer::AutoFunction::Format::ByInput::ReplaceStyle::set(true,
 pBatch);
-    
officecfg::Office::Writer::AutoFunction::Format::Option::ReplaceStyle::set(true,
 pBatch);
-    pBatch->commit();
+    
ScopedConfigValue<officecfg::Office::Writer::AutoFunction::Format::ByInput::ReplaceStyle>
 aCfg1(
+        true);
+    
ScopedConfigValue<officecfg::Office::Writer::AutoFunction::Format::Option::ReplaceStyle>
 aCfg2(
+        true);
 
     createSwDoc();
     SwWrtShell* const pWrtShell = getSwDocShell()->GetWrtShell();

Reply via email to