src/base/flags.test.cc
/**
 * Test replacing a masked selection of bits. This means that bits of the
 * original value that match the mask will be replaced by the bits of
 * the new value that match the mask.
 */
Test replacing a masked selection of bits. This means that bits of the
original value that match the mask will be replaced by the bits of
the new value that match the mask.
Test replacing a masked selection of bits . This means that bits of the original value that match the mask will be replaced by the bits of the new value that match the mask .
TEST(FlagsTest, ReplaceOverlapping)
{
    const uint32_t value_a = (1 << 4) | (1 << 5) | (1 << 6);
    const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
    const uint32_t mask = (1 << 4) | (1 << 5) | (1 << 9) | (1 << 10);
    const uint32_t result = (1 << 5) | (1 << 6) | (1 << 9);
    Flags<uint32_t> flags(value_a);
    flags.replace(value_b, mask);
    ASSERT_EQ(result, uint32_t(flags));
}
TEST ( FlagsTest , ReplaceOverlapping ) { const uint32_t value_a = ( 1 << 4 ) | ( 1 << 5 ) | ( 1 << 6 ) ; const uint32_t value_b = ( 1 << 3 ) | ( 1 << 5 ) | ( 1 << 9 ) ; const uint32_t mask = ( 1 << 4 ) | ( 1 << 5 ) | ( 1 << 9 ) | ( 1 << 10 ) ; const uint32_t result = ( 1 << 5 ) | ( 1 << 6 ) | ( 1 << 9 ) ; Flags < uint32_t > flags ( value_a ) ; flags . replace ( value_b , mask ) ; ASSERT_EQ ( result , uint32_t ( flags ) ) ; }
Test replacing a masked selection of bits.
Test replacing a masked selection of bits .
// (1 << 4) is set in value_a, but is not set in value_b, so it is cleared // (1 << 5) is set in both values, so it remains set // (1 << 9) is not set in value_a, but it is in value_b, so it is set // (1 << 10) is not set in both values, so it remains not set