blob: ee228cb58cae65e1dc0168ebbc7edb187d018ca3 [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
5namespace aos {
6namespace testing {
7
8class OptionsTest : public ::testing::Test {
9 public:
10 static constexpr Options<OptionsTest>::Option kOne{1}, kTwo{2}, kThree{4},
11 kFour{8};
12};
13
14constexpr Options<OptionsTest>::Option OptionsTest::kOne, OptionsTest::kTwo,
15 OptionsTest::kThree, OptionsTest::kFour;
16
17TEST_F(OptionsTest, Basic) {
18 const Options<OptionsTest> one_three = kOne | kThree;
19 EXPECT_TRUE(one_three & kOne);
20 EXPECT_FALSE(one_three & kTwo);
21 EXPECT_TRUE(one_three & kThree);
22}
23
24TEST_F(OptionsTest, NoOthersSet) {
25 const Options<OptionsTest> one_three = kOne | kThree;
26 EXPECT_TRUE(one_three.NoOthersSet(one_three));
27 EXPECT_TRUE(one_three.NoOthersSet(kOne | kTwo | kThree));
28 EXPECT_TRUE(one_three.NoOthersSet(kOne | kThree | kFour));
29 EXPECT_TRUE(one_three.NoOthersSet(kOne | kTwo | kThree | kFour));
30 EXPECT_FALSE(one_three.NoOthersSet(kOne));
31 EXPECT_FALSE(one_three.NoOthersSet(kThree));
32 EXPECT_FALSE(one_three.NoOthersSet(kTwo | kFour));
33}
34
35TEST_F(OptionsTest, ExactlyOneSet) {
36 const Options<OptionsTest> one_three = kOne | kThree;
37 EXPECT_TRUE(one_three.ExactlyOneSet(kOne | kTwo));
38 EXPECT_FALSE(one_three.ExactlyOneSet(one_three));
39 EXPECT_TRUE(one_three.ExactlyOneSet(kTwo | kThree | kFour));
40 EXPECT_FALSE(one_three.ExactlyOneSet(kOne | kTwo | kThree | kFour));
41}
42
43TEST_F(OptionsTest, AllSet) {
44 const Options<OptionsTest> one_three = kOne | kThree;
45 EXPECT_TRUE(one_three.AllSet(one_three));
46 EXPECT_TRUE(one_three.AllSet(kOne));
47 EXPECT_FALSE(one_three.AllSet(kTwo));
48 EXPECT_TRUE(one_three.AllSet(kThree));
49 EXPECT_FALSE(one_three.AllSet(kFour));
50 EXPECT_FALSE(one_three.AllSet(kOne | kTwo | kFour));
51 EXPECT_FALSE(one_three.AllSet(kTwo | kThree | kFour));
52 EXPECT_FALSE(one_three.AllSet(kOne | kTwo | kThree | kFour));
53}
54
55} // namespace testing
56} // namespace aos