From aab65460f567fd42e92bdf1ec77b181e7a80eb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Sun, 17 Aug 2025 12:07:27 +0200 Subject: [PATCH] comphelper: Update FlagRestorationGuard test with additional cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So we test all possibilities. Change-Id: If2f4712b0bac41d11d845c21a3917ed3fb0b41d8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189816 Reviewed-by: Tomaž Vajngerl Tested-by: Jenkins --- comphelper/qa/unit/test_guards.cxx | 43 +++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/comphelper/qa/unit/test_guards.cxx b/comphelper/qa/unit/test_guards.cxx index 83034a2dcc6a..48a1f2cd0992 100644 --- a/comphelper/qa/unit/test_guards.cxx +++ b/comphelper/qa/unit/test_guards.cxx @@ -50,15 +50,46 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testFlagRestorationGuard) { // Test that comphelper::FlagRestorationGuard properly sets and resets the flag - // initial value "true", change to "false", out-of-scope change to "true" - - bool bFlag = true; { - comphelper::FlagRestorationGuard aGuard(bFlag, false); + // initial value "true", change to "false", out-of-scope change to "true" + bool bFlag = true; + { + comphelper::FlagRestorationGuard aGuard(bFlag, false); + CPPUNIT_ASSERT(!bFlag); + } + // comphelper::FlagRestorationGuard must reset flag to initial state on destruction + CPPUNIT_ASSERT(bFlag); + } + + { + // initial value "false", change to "true", out-of-scope change to "false" + bool bFlag = false; + { + comphelper::FlagRestorationGuard aGuard(bFlag, true); + CPPUNIT_ASSERT(bFlag); + } CPPUNIT_ASSERT(!bFlag); } - // comphelper::FlagRestorationGuard must reset flag to initial state on destruction - CPPUNIT_ASSERT(bFlag); + + { + // initial value "false", change to "false", out-of-scope change to "false" + bool bFlag = false; + { + comphelper::FlagRestorationGuard aGuard(bFlag, false); + CPPUNIT_ASSERT(!bFlag); + } + CPPUNIT_ASSERT(!bFlag); + } + + { + // initial value "true", change to "true", out-of-scope change to "true" + bool bFlag = true; + { + comphelper::FlagRestorationGuard aGuard(bFlag, true); + CPPUNIT_ASSERT(bFlag); + } + CPPUNIT_ASSERT(bFlag); + } } CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testValueRestorationGuard)