return *this;
}
- /**
- * Verifies whether any bit in the flags is set.
- *
- * @return True if any flag bit is set; false otherwise.
- */
- bool isSet() const { return _flags; }
-
/**
* Verifies whether any bit matching the given mask is set.
*
*/
bool isSet(Type mask) const { return (_flags & mask); }
- /**
- * Verifies whether all bits in the flags are set.
- *
- * @return True if all flag bits are set; false otherwise.
- */
- bool allSet() const { return !(~_flags); }
-
/**
* Verifies whether no bits matching the given mask are set.
*
*/
bool allSet(Type mask) const { return (_flags & mask) == mask; }
- /**
- * Verifies whether no bits in the flags are set.
- *
- * @return True if all flag bits are cleared; false otherwise.
- */
- bool noneSet() const { return _flags == 0; }
-
/**
* Verifies whether no bits matching the given mask are set.
*
ASSERT_EQ(uint32_t(flags_a), uint32_t(flags_b));
}
-/** Test isSet for any bit set. */
-TEST(FlagsTest, IsSetAny)
-{
- const uint32_t value = (1 << 3);
- const Flags<uint32_t> flags_a;
- const Flags<uint32_t> flags_b(value);
- ASSERT_FALSE(flags_a.isSet());
- ASSERT_TRUE(flags_b.isSet());
-}
-
/** Test isSet for multiple bits set. */
TEST(FlagsTest, IsSetValue)
{
ASSERT_FALSE(flags.isSet(value_c));
}
-/** Test if all bits are set with allSet. */
-TEST(FlagsTest, AllSet)
-{
- const uint32_t value_b = (1 << 5) | (1 << 6);
- const uint32_t value_c = std::numeric_limits<uint32_t>::max();
- const Flags<uint32_t> flags_a;
- const Flags<uint32_t> flags_b(value_b);
- const Flags<uint32_t> flags_c(value_c);
- ASSERT_FALSE(flags_a.allSet());
- ASSERT_FALSE(flags_b.allSet());
- ASSERT_TRUE(flags_c.allSet());
-}
-
/** Test allSet comparing against another flag. */
TEST(FlagsTest, AllSetMatch)
{
ASSERT_FALSE(flags.allSet(value_b));
}
-/** Test if no bits are set with noneSet. */
-TEST(FlagsTest, NoneSet)
-{
- const uint32_t value_b = (1 << 5) | (1 << 6);
- const Flags<uint32_t> flags_a;
- const Flags<uint32_t> flags_b(value_b);
- ASSERT_TRUE(flags_a.noneSet());
- ASSERT_FALSE(flags_b.noneSet());
-}
-
/** Test noneSet comparing against another flag. */
TEST(FlagsTest, NoneSetMatch)
{
const uint32_t value = (1 << 5) | (1 << 6);
Flags<uint32_t> flags(value);
flags.clear();
- ASSERT_TRUE(flags.noneSet());
+ ASSERT_EQ(0, uint32_t(flags));
}
/** Test clearing specific bits. */