blob: 536b319d15cca96976dfd118a47381f4c42dc9c2 [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#include "aos/util/options.h"
Brian Silverman7faaec72014-05-26 16:25:38 -07002
Stephan Pleinesb1177672024-05-27 17:48:32 -07003#include <memory>
4
Brian Silverman7faaec72014-05-26 16:25:38 -07005#include "gtest/gtest.h"
6
Stephan Pleinesf63bde82024-01-13 15:59:33 -08007namespace aos::testing {
Brian Silverman7faaec72014-05-26 16:25:38 -07008
9class OptionsTest : public ::testing::Test {
10 public:
11 static constexpr Options<OptionsTest>::Option kOne{1}, kTwo{2}, kThree{4},
12 kFour{8};
13};
14
15constexpr Options<OptionsTest>::Option OptionsTest::kOne, OptionsTest::kTwo,
16 OptionsTest::kThree, OptionsTest::kFour;
17
18TEST_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
25TEST_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
36TEST_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
44TEST_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 Pleinesf63bde82024-01-13 15:59:33 -080056} // namespace aos::testing