13 #include <gtest/gtest.h> 14 #include "../../include/ecl/utilities/flags.hpp" 52 Flags<Setting> operator|(Setting flagOne, Setting flagTwo) {
return Flags<Setting>(flagOne) | flagTwo; }
64 typedef Flags<Setting> Settings;
75 void configure(Settings s)
77 if ( ( s.testFlag(Gold) && s_.testFlag(Dark) ) ||
78 ( s_.testFlag(Gold) && s.testFlag(Dark) ) ||
79 ( s.testFlag(Gold) && s.testFlag(Dark) ) )
82 std::cout <<
"This combination is not permitted." << std::endl;
89 Settings settings() {
return s_; }
101 using namespace ecl::utilities::tests;
107 TEST(Flags, initialisation) {
110 settings = Fast | Red;
113 std::cout <<
"Fast & Red: " << settings << std::endl;
115 EXPECT_EQ(Fast|Red,settings);
118 TEST(Flags, Operators) {
120 settings = Fast | Red;
123 std::cout <<
"Fast: " << settings << std::endl;
128 std::cout <<
"Fast & Gold: " << settings << std::endl;
130 EXPECT_EQ(FastGold,settings);
135 settings = Fast | Gold;
136 EXPECT_EQ(settings.testFlag(Gold),
true);
137 EXPECT_EQ(settings.testFlag(Red),
false);
138 EXPECT_EQ(settings.testFlag(FastGold),
true);
140 EXPECT_EQ(settings.testFlag(Nada),
true);
143 if ( settings.testFlag(Gold) ) {
144 std::cout <<
"Gold Set" << std::endl;
146 std::cout <<
"Gold Not Set" << std::endl;
148 if ( settings.testFlag(Red) ) {
149 std::cout <<
"Red Set" << std::endl;
151 std::cout <<
"Red Not Set" << std::endl;
153 if ( settings.testFlag(FastGold) ) {
154 std::cout <<
"Fast & Gold Set" << std::endl;
156 std::cout <<
"Fast & Gold Not Set" << std::endl;
160 TEST(Flags, combinations) {
162 a.configure(Gold|Dark);
163 EXPECT_EQ(0,a.settings());
165 EXPECT_EQ(Gold,a.settings());
172 int main(
int argc,
char **argv) {
173 testing::InitGoogleTest(&argc,argv);
174 return RUN_ALL_TESTS();
Embedded control libraries.
TEST(TypeTests, fundamentals)
int main(int argc, char **argv)