diff options
-rw-r--r-- | include/o3tl/typed_flags_set.hxx | 12 | ||||
-rw-r--r-- | o3tl/CppunitTest_o3tl_tests.mk | 1 | ||||
-rw-r--r-- | o3tl/qa/test-typed_flags.cxx | 63 |
3 files changed, 68 insertions, 8 deletions
diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx index b9b40d8cba09..1aac62512273 100644 --- a/include/o3tl/typed_flags_set.hxx +++ b/include/o3tl/typed_flags_set.hxx @@ -177,7 +177,7 @@ inline typename o3tl::typed_flags<E>::Self operator |( } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) { +inline E operator &=(E & lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); lhs = lhs & rhs; @@ -185,16 +185,14 @@ inline typename o3tl::typed_flags<E>::Self operator &=(E & lhs, E rhs) { } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator &=( - E & lhs, typename o3tl::typed_flags<E>::Self rhs) -{ +inline E operator &=(E & lhs, typename o3tl::typed_flags<E>::Self rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); lhs = lhs & rhs; return lhs; } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) { +inline E operator |=(E & lhs, E rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(rhs) >= 0); lhs = lhs | rhs; @@ -202,9 +200,7 @@ inline typename o3tl::typed_flags<E>::Self operator |=(E & lhs, E rhs) { } template<typename E> -inline typename o3tl::typed_flags<E>::Self operator |=( - E & lhs, typename o3tl::typed_flags<E>::Self rhs) -{ +inline E operator |=(E & lhs, typename o3tl::typed_flags<E>::Self rhs) { assert(static_cast<O3TL_STD_UNDERLYING_TYPE_E>(lhs) >= 0); lhs = lhs | rhs; return lhs; diff --git a/o3tl/CppunitTest_o3tl_tests.mk b/o3tl/CppunitTest_o3tl_tests.mk index a4d6d715853c..66f2951bf4f6 100644 --- a/o3tl/CppunitTest_o3tl_tests.mk +++ b/o3tl/CppunitTest_o3tl_tests.mk @@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,o3tl_tests,\ o3tl/qa/test-range \ o3tl/qa/test-vector_pool \ o3tl/qa/test-sorted_vector \ + o3tl/qa/test-typed_flags \ )) # vim: set noet sw=4: diff --git a/o3tl/qa/test-typed_flags.cxx b/o3tl/qa/test-typed_flags.cxx new file mode 100644 index 000000000000..de6e080eddd0 --- /dev/null +++ b/o3tl/qa/test-typed_flags.cxx @@ -0,0 +1,63 @@ +/* -*- 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 "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <o3tl/typed_flags_set.hxx> + +using namespace ::o3tl; + + +enum class ConfigurationChangedHint { NONE, ONE, TWO }; + +namespace o3tl +{ + template<> struct typed_flags< ConfigurationChangedHint> : is_typed_flags< ConfigurationChangedHint, 0xFF> {}; +} + +class typed_flags_test : public CppUnit::TestFixture +{ +public: + void testBasics() + { + ConfigurationChangedHint nHint = ConfigurationChangedHint::ONE; + + CPPUNIT_ASSERT( ConfigurationChangedHint::ONE & ConfigurationChangedHint::ONE ); + CPPUNIT_ASSERT( nHint & ConfigurationChangedHint::ONE ); + CPPUNIT_ASSERT( ConfigurationChangedHint::ONE & nHint ); + + CPPUNIT_ASSERT( ConfigurationChangedHint::ONE | ConfigurationChangedHint::ONE ); + CPPUNIT_ASSERT( nHint | ConfigurationChangedHint::ONE ); + CPPUNIT_ASSERT( ConfigurationChangedHint::ONE | nHint ); + + CPPUNIT_ASSERT( ~nHint ); + CPPUNIT_ASSERT( ~ConfigurationChangedHint::ONE ); + + nHint |= ConfigurationChangedHint::ONE; + CPPUNIT_ASSERT( nHint |= ConfigurationChangedHint::ONE ); + + nHint &= ConfigurationChangedHint::ONE; + CPPUNIT_ASSERT( nHint &= ConfigurationChangedHint::ONE ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(typed_flags_test); + CPPUNIT_TEST(testBasics); + CPPUNIT_TEST_SUITE_END(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION(typed_flags_test); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |