29 #include <gtest/gtest.h>
37 TEST(FlagsTest, ConstructorZero)
40 ASSERT_EQ(uint32_t(0), uint32_t(flags));
44 TEST(FlagsTest, ConstructorSingle)
46 const uint32_t value = (1 << 3);
48 ASSERT_EQ(value, uint32_t(flags));
52 TEST(FlagsTest, ConstructorMulti)
54 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
56 ASSERT_EQ(value, uint32_t(flags));
60 TEST(FlagsTest, TypeAssignment)
62 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
65 ASSERT_EQ(value, uint32_t(flags));
72 TEST(FlagsTest, TypeAssignmentOverwrite)
74 const uint32_t init_value = (1 << 5) | (1 << 6) ;
75 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
78 ASSERT_EQ(value, uint32_t(flags));
82 TEST(FlagsTest, FlagsAssignment)
84 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
88 ASSERT_EQ(uint32_t(flags_a), uint32_t(flags_b));
92 TEST(FlagsTest, FlagsAssignmentOverwrite)
94 const uint32_t init_value = (1 << 5) | (1 << 6);
95 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
99 ASSERT_EQ(uint32_t(flags_a), uint32_t(flags_b));
105 const uint32_t value_a = (1 << 3);
106 const uint32_t value_b = (1 << 5);
108 ASSERT_TRUE(flags.
isSet(value_a));
109 ASSERT_FALSE(flags.
isSet(value_a << 1));
110 ASSERT_TRUE(flags.
isSet(value_b));
116 const uint32_t value_a = (1 << 5) | (1 << 6);
117 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
118 const uint32_t value_c = (1 << 4) | (1 << 8);
120 ASSERT_TRUE(flags.
isSet(value_b));
121 ASSERT_FALSE(flags.
isSet(value_c));
127 const uint32_t value_a = (1 << 5) | (1 << 6);
128 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
130 ASSERT_TRUE(flags.
allSet(value_a));
131 ASSERT_FALSE(flags.
allSet(value_b));
137 const uint32_t value_a = (1 << 5) | (1 << 6);
138 const uint32_t value_b = (1 << 3) | (1 << 6);
139 const uint32_t value_c = (1 << 3) | (1 << 4) | (1 << 9);
141 ASSERT_FALSE(flags.
noneSet(value_a));
142 ASSERT_FALSE(flags.
noneSet(value_b));
143 ASSERT_TRUE(flags.
noneSet(value_c));
149 const uint32_t value = (1 << 5) | (1 << 6);
152 ASSERT_EQ(0, uint32_t(flags));
158 const uint32_t value_a = (1 << 5) | (1 << 6);
159 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
161 flags.
clear(value_b);
162 ASSERT_FALSE(flags.
isSet(value_a & value_b));
163 ASSERT_TRUE(flags.
isSet(value_a ^ (value_a & value_b)));
167 TEST(FlagsTest, SetOverlapping)
169 const uint32_t value_a = (1 << 5) | (1 << 6);
170 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
173 ASSERT_EQ(value_a | value_b, uint32_t(flags));
180 TEST(FlagsTest, ConditionalSet)
182 const uint32_t value_a = (1 << 5) | (1 << 6);
183 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
186 flags_true.
set(value_b,
true);
187 ASSERT_EQ(value_a | value_b, uint32_t(flags_true));
190 flags_false.
set(value_b,
false);
191 ASSERT_EQ(value_a & ~value_b, uint32_t(flags_false));
199 TEST(FlagsTest, ReplaceOverlapping)
201 const uint32_t value_a = (1 << 4) | (1 << 5) | (1 << 6);
202 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
203 const uint32_t
mask = (1 << 4) | (1 << 5) | (1 << 9) | (1 << 10);
208 const uint32_t result = (1 << 5) | (1 << 6) | (1 << 9);
211 ASSERT_EQ(result, uint32_t(flags));