Kaydet (Commit) 2cd11285 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Stephan Bergmann

fixes and tests for o3tl::typed_flags

create test suite for typed_flags template.
fix the operator&= and operator|= definitions
Signed-off-by: 's avatarStephan Bergmann <sbergman@redhat.com>
Conflicts:
	include/o3tl/typed_flags_set.hxx

Change-Id: I1df9ae197889af98a2fd76ff2bc07756c7b14ced
üst a1a83ceb
......@@ -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;
......
......@@ -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:
/* -*- 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: */
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