blob: f560fe67e40447ad157adf9b2d4124eda0268a8d [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#include "aos/util/options.h"
Brian Silverman7faaec72014-05-26 16:25:38 -07002
3#include "gtest/gtest.h"
4
Stephan Pleinesf63bde82024-01-13 15:59:33 -08005namespace aos::testing {
Brian Silverman7faaec72014-05-26 16:25:38 -07006
7class OptionsTest : public ::testing::Test {
8 public:
9 static constexpr Options<OptionsTest>::Option kOne{1}, kTwo{2}, kThree{4},
10 kFour{8};
11};
12
13constexpr Options<OptionsTest>::Option OptionsTest::kOne, OptionsTest::kTwo,
14 OptionsTest::kThree, OptionsTest::kFour;
15
16TEST_F(OptionsTest, Basic) {
17 const Options<OptionsTest> one_three = kOne | kThree;
18 EXPECT_TRUE(one_three & kOne);
19 EXPECT_FALSE(one_three & kTwo);
20 EXPECT_TRUE(one_three & kThree);
21}
22
23TEST_F(OptionsTest, NoOthersSet) {
24 const Options<OptionsTest> one_three = kOne | kThree;
25 EXPECT_TRUE(one_three.NoOthersSet(one_three));
26 EXPECT_TRUE(one_three.NoOthersSet(kOne | kTwo | kThree));
27 EXPECT_TRUE(one_three.NoOthersSet(kOne | kThree | kFour));
28 EXPECT_TRUE(one_three.NoOthersSet(kOne | kTwo | kThree | kFour));
29 EXPECT_FALSE(one_three.NoOthersSet(kOne));
30 EXPECT_FALSE(one_three.NoOthersSet(kThree));
31 EXPECT_FALSE(one_three.NoOthersSet(kTwo | kFour));
32}
33
34TEST_F(OptionsTest, ExactlyOneSet) {
35 const Options<OptionsTest> one_three = kOne | kThree;
36 EXPECT_TRUE(one_three.ExactlyOneSet(kOne | kTwo));
37 EXPECT_FALSE(one_three.ExactlyOneSet(one_three));
38 EXPECT_TRUE(one_three.ExactlyOneSet(kTwo | kThree | kFour));
39 EXPECT_FALSE(one_three.ExactlyOneSet(kOne | kTwo | kThree | kFour));
40}
41
42TEST_F(OptionsTest, AllSet) {
43 const Options<OptionsTest> one_three = kOne | kThree;
44 EXPECT_TRUE(one_three.AllSet(one_three));
45 EXPECT_TRUE(one_three.AllSet(kOne));
46 EXPECT_FALSE(one_three.AllSet(kTwo));
47 EXPECT_TRUE(one_three.AllSet(kThree));
48 EXPECT_FALSE(one_three.AllSet(kFour));
49 EXPECT_FALSE(one_three.AllSet(kOne | kTwo | kFour));
50 EXPECT_FALSE(one_three.AllSet(kTwo | kThree | kFour));
51 EXPECT_FALSE(one_three.AllSet(kOne | kTwo | kThree | kFour));
52}
53
Stephan Pleinesf63bde82024-01-13 15:59:33 -080054} // namespace aos::testing