Kaydet (Commit) 6ec6d013 authored tarafından Mike Kaganski's avatar Mike Kaganski

Add a unit test for comphelper's guards

Change-Id: Ia9a9c5694d3982a87b720071b74220d572ef1a78
Reviewed-on: https://gerrit.libreoffice.org/71355
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst fb2f2e66
......@@ -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))
......
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment