John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #include "aos/util/options.h" |
Brian Silverman | 7faaec7 | 2014-05-26 16:25:38 -0700 | [diff] [blame] | 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | namespace aos { |
| 6 | namespace testing { |
| 7 | |
| 8 | class OptionsTest : public ::testing::Test { |
| 9 | public: |
| 10 | static constexpr Options<OptionsTest>::Option kOne{1}, kTwo{2}, kThree{4}, |
| 11 | kFour{8}; |
| 12 | }; |
| 13 | |
| 14 | constexpr Options<OptionsTest>::Option OptionsTest::kOne, OptionsTest::kTwo, |
| 15 | OptionsTest::kThree, OptionsTest::kFour; |
| 16 | |
| 17 | TEST_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 | |
| 24 | TEST_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 | |
| 35 | TEST_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 | |
| 43 | TEST_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 |