29 #include <gtest/gtest.h>
39 TEST(FlagsTest, ConstructorZero)
42 ASSERT_EQ(uint32_t(0), uint32_t(flags));
46 TEST(FlagsTest, ConstructorSingle)
48 const uint32_t value = (1 << 3);
50 ASSERT_EQ(value, uint32_t(flags));
54 TEST(FlagsTest, ConstructorMulti)
56 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
58 ASSERT_EQ(value, uint32_t(flags));
62 TEST(FlagsTest, TypeAssignment)
64 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
67 ASSERT_EQ(value, uint32_t(flags));
74 TEST(FlagsTest, TypeAssignmentOverwrite)
76 const uint32_t init_value = (1 << 5) | (1 << 6) ;
77 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
80 ASSERT_EQ(value, uint32_t(flags));
84 TEST(FlagsTest, FlagsAssignment)
86 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
90 ASSERT_EQ(uint32_t(flags_a), uint32_t(flags_b));
94 TEST(FlagsTest, FlagsAssignmentOverwrite)
96 const uint32_t init_value = (1 << 5) | (1 << 6);
97 const uint32_t value = (1 << 3) | (1 << 5) | (1 << 9);
101 ASSERT_EQ(uint32_t(flags_a), uint32_t(flags_b));
107 const uint32_t value_a = (1 << 3);
108 const uint32_t value_b = (1 << 5);
110 ASSERT_TRUE(flags.
isSet(value_a));
111 ASSERT_FALSE(flags.
isSet(value_a << 1));
112 ASSERT_TRUE(flags.
isSet(value_b));
118 const uint32_t value_a = (1 << 5) | (1 << 6);
119 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
120 const uint32_t value_c = (1 << 4) | (1 << 8);
122 ASSERT_TRUE(flags.
isSet(value_b));
123 ASSERT_FALSE(flags.
isSet(value_c));
129 const uint32_t value_a = (1 << 5) | (1 << 6);
130 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
132 ASSERT_TRUE(flags.
allSet(value_a));
133 ASSERT_FALSE(flags.
allSet(value_b));
139 const uint32_t value_a = (1 << 5) | (1 << 6);
140 const uint32_t value_b = (1 << 3) | (1 << 6);
141 const uint32_t value_c = (1 << 3) | (1 << 4) | (1 << 9);
143 ASSERT_FALSE(flags.
noneSet(value_a));
144 ASSERT_FALSE(flags.
noneSet(value_b));
145 ASSERT_TRUE(flags.
noneSet(value_c));
151 const uint32_t value = (1 << 5) | (1 << 6);
154 ASSERT_EQ(0, uint32_t(flags));
160 const uint32_t value_a = (1 << 5) | (1 << 6);
161 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
163 flags.
clear(value_b);
164 ASSERT_FALSE(flags.
isSet(value_a & value_b));
165 ASSERT_TRUE(flags.
isSet(value_a ^ (value_a & value_b)));
169 TEST(FlagsTest, SetOverlapping)
171 const uint32_t value_a = (1 << 5) | (1 << 6);
172 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
175 ASSERT_EQ(value_a | value_b, uint32_t(flags));
182 TEST(FlagsTest, ConditionalSet)
184 const uint32_t value_a = (1 << 5) | (1 << 6);
185 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
188 flags_true.
set(value_b,
true);
189 ASSERT_EQ(value_a | value_b, uint32_t(flags_true));
192 flags_false.
set(value_b,
false);
193 ASSERT_EQ(value_a & ~value_b, uint32_t(flags_false));
201 TEST(FlagsTest, ReplaceOverlapping)
203 const uint32_t value_a = (1 << 4) | (1 << 5) | (1 << 6);
204 const uint32_t value_b = (1 << 3) | (1 << 5) | (1 << 9);
205 const uint32_t
mask = (1 << 4) | (1 << 5) | (1 << 9) | (1 << 10);
210 const uint32_t result = (1 << 5) | (1 << 6) | (1 << 9);
213 ASSERT_EQ(result, uint32_t(flags));