comphelper/CppunitTest_comphelper_test.mk | 1 comphelper/qa/unit/test_guards.cxx | 57 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
New commits: commit 6ec6d013227e66156e00c1d5ac9d0d2ddd208fae Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Apr 26 13:29:28 2019 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Apr 26 15:33:55 2019 +0200 Add a unit test for comphelper's guards Change-Id: Ia9a9c5694d3982a87b720071b74220d572ef1a78 Reviewed-on: https://gerrit.libreoffice.org/71355 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/comphelper/CppunitTest_comphelper_test.mk b/comphelper/CppunitTest_comphelper_test.mk index 20503e65bd06..8bb335aa24dc 100644 --- a/comphelper/CppunitTest_comphelper_test.mk +++ b/comphelper/CppunitTest_comphelper_test.mk @@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \ comphelper/qa/unit/test_hash \ comphelper/qa/unit/base64_test \ comphelper/qa/unit/types_test \ + comphelper/qa/unit/test_guards \ )) $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test)) diff --git a/comphelper/qa/unit/test_guards.cxx b/comphelper/qa/unit/test_guards.cxx new file mode 100644 index 000000000000..39d8f80e0c68 --- /dev/null +++ b/comphelper/qa/unit/test_guards.cxx @@ -0,0 +1,57 @@ +/* -*- 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 <sal/types.h> +#include <comphelper/flagguard.hxx> +#include <unotest/bootstrapfixturebase.hxx> + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, test_comphelperGuards) +{ + bool bFlag = true; + { + // Test that comphelper::ScopeGuard executes its parameter on destruction + comphelper::ScopeGuard aGuard([&bFlag] { bFlag = false; }); + CPPUNIT_ASSERT(bFlag); + } + CPPUNIT_ASSERT(!bFlag); + + { + // Test that comphelper::FlagGuard properly sets and resets the flag + comphelper::FlagGuard aGuard(bFlag); + CPPUNIT_ASSERT(bFlag); + } + CPPUNIT_ASSERT(!bFlag); + + bFlag = true; + { + // Test that comphelper::FlagGuard properly sets and resets the flag + comphelper::FlagGuard aGuard(bFlag); + CPPUNIT_ASSERT(bFlag); + } + // comphelper::FlagGuard must reset flag to false on destruction unconditionally + CPPUNIT_ASSERT(!bFlag); + + { + // Test that comphelper::FlagRestorationGuard properly sets and resets the flag + comphelper::FlagRestorationGuard aGuard(bFlag, true); + CPPUNIT_ASSERT(bFlag); + } + CPPUNIT_ASSERT(!bFlag); + + bFlag = true; + { + // Test that comphelper::FlagRestorationGuard properly sets and resets the flag + comphelper::FlagRestorationGuard aGuard(bFlag, false); + CPPUNIT_ASSERT(!bFlag); + } + // comphelper::FlagGuard must reset flag to initial state on destruction + CPPUNIT_ASSERT(bFlag); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits