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 | |
Stephan Pleines | b117767 | 2024-05-27 17:48:32 -0700 | [diff] [blame] | 3 | #include <memory> |
| 4 | |
Brian Silverman | 7faaec7 | 2014-05-26 16:25:38 -0700 | [diff] [blame] | 5 | #include "gtest/gtest.h" |
| 6 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 7 | namespace aos::testing { |
Brian Silverman | 7faaec7 | 2014-05-26 16:25:38 -0700 | [diff] [blame] | 8 | |
| 9 | class OptionsTest : public ::testing::Test { |
| 10 | public: |
| 11 | static constexpr Options<OptionsTest>::Option kOne{1}, kTwo{2}, kThree{4}, |
| 12 | kFour{8}; |
| 13 | }; |
| 14 | |
| 15 | constexpr Options<OptionsTest>::Option OptionsTest::kOne, OptionsTest::kTwo, |
| 16 | OptionsTest::kThree, OptionsTest::kFour; |
| 17 | |
| 18 | TEST_F(OptionsTest, Basic) { |
| 19 | const Options<OptionsTest> one_three = kOne | kThree; |
| 20 | EXPECT_TRUE(one_three & kOne); |
| 21 | EXPECT_FALSE(one_three & kTwo); |
| 22 | EXPECT_TRUE(one_three & kThree); |
| 23 | } |
| 24 | |
| 25 | TEST_F(OptionsTest, NoOthersSet) { |
| 26 | const Options<OptionsTest> one_three = kOne | kThree; |
| 27 | EXPECT_TRUE(one_three.NoOthersSet(one_three)); |
| 28 | EXPECT_TRUE(one_three.NoOthersSet(kOne | kTwo | kThree)); |
| 29 | EXPECT_TRUE(one_three.NoOthersSet(kOne | kThree | kFour)); |
| 30 | EXPECT_TRUE(one_three.NoOthersSet(kOne | kTwo | kThree | kFour)); |
| 31 | EXPECT_FALSE(one_three.NoOthersSet(kOne)); |
| 32 | EXPECT_FALSE(one_three.NoOthersSet(kThree)); |
| 33 | EXPECT_FALSE(one_three.NoOthersSet(kTwo | kFour)); |
| 34 | } |
| 35 | |
| 36 | TEST_F(OptionsTest, ExactlyOneSet) { |
| 37 | const Options<OptionsTest> one_three = kOne | kThree; |
| 38 | EXPECT_TRUE(one_three.ExactlyOneSet(kOne | kTwo)); |
| 39 | EXPECT_FALSE(one_three.ExactlyOneSet(one_three)); |
| 40 | EXPECT_TRUE(one_three.ExactlyOneSet(kTwo | kThree | kFour)); |
| 41 | EXPECT_FALSE(one_three.ExactlyOneSet(kOne | kTwo | kThree | kFour)); |
| 42 | } |
| 43 | |
| 44 | TEST_F(OptionsTest, AllSet) { |
| 45 | const Options<OptionsTest> one_three = kOne | kThree; |
| 46 | EXPECT_TRUE(one_three.AllSet(one_three)); |
| 47 | EXPECT_TRUE(one_three.AllSet(kOne)); |
| 48 | EXPECT_FALSE(one_three.AllSet(kTwo)); |
| 49 | EXPECT_TRUE(one_three.AllSet(kThree)); |
| 50 | EXPECT_FALSE(one_three.AllSet(kFour)); |
| 51 | EXPECT_FALSE(one_three.AllSet(kOne | kTwo | kFour)); |
| 52 | EXPECT_FALSE(one_three.AllSet(kTwo | kThree | kFour)); |
| 53 | EXPECT_FALSE(one_three.AllSet(kOne | kTwo | kThree | kFour)); |
| 54 | } |
| 55 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 56 | } // namespace aos::testing |