2 #include "../../../../tests/catch2/catch.hpp"
4 #include <mx/sys/timeUtils.hpp>
6 #define OUTLET_CTRL_TEST_NOINDI
7 #define OUTLET_CTRL_TEST_NOLOG
8 #include "../outletController.hpp"
54 SCENARIO(
"outletController Configuration",
"[outletController]" )
56 GIVEN(
"a config file with 4 channels for 4 outlets")
58 WHEN(
"using outlet keyword, only outlet specified")
60 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel2",
"channel3",
"channel4"},
61 {
"outlet",
"outlet",
"outlet",
"outlet"},
62 {
"0",
"1",
"2",
"3"} );
64 mx::app::appConfigurator config;
65 config.readConfig(
"/tmp/outletController_test.conf");
76 std::vector<size_t> outlets, onOrder, offOrder;
77 std::vector<unsigned> onDelays, offDelays;
89 REQUIRE( offDelays.size() == 0);
100 REQUIRE( onDelays.size() == 0);
102 REQUIRE( offDelays.size() == 0);
111 REQUIRE( offOrder.size() == 0);
113 REQUIRE( onDelays.size() == 0);
115 REQUIRE( offDelays.size() == 0);
124 REQUIRE( offOrder.size() == 0);
126 REQUIRE( onDelays.size() == 0);
128 REQUIRE( offDelays.size() == 0);
132 WHEN(
"using outlet keyword, all specified")
134 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2",
"channel2",
"channel2",
"channel3",
"channel3",
"channel3",
"channel3",
"channel3",
"channel4",
"channel4",
"channel4",
"channel4",
"channel4" },
135 {
"outlet",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlet",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlet",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlet",
"onOrder",
"offOrder",
"onDelays",
"offDelays" },
136 {
"0",
"0",
"0",
"100",
"120",
"1",
"0",
"0",
"105",
"130",
"2",
"0",
"0",
"107",
"132",
"3",
"0",
"0",
"108",
"133"});
138 mx::app::appConfigurator config;
139 config.readConfig(
"/tmp/outletController_test.conf");
150 std::vector<size_t> outlets, onOrder, offOrder;
151 std::vector<unsigned> onDelays, offDelays;
161 REQUIRE( offOrder.size() == 1);
164 REQUIRE( onDelays.size() == 1);
167 REQUIRE( offDelays.size() == 1);
178 REQUIRE( offOrder.size() == 1);
181 REQUIRE( onDelays.size() == 1);
184 REQUIRE( offDelays.size() == 1);
195 REQUIRE( offOrder.size() == 1);
198 REQUIRE( onDelays.size() == 1);
201 REQUIRE( offDelays.size() == 1);
212 REQUIRE( offOrder.size() == 1);
215 REQUIRE( onDelays.size() == 1);
218 REQUIRE( offDelays.size() == 1);
222 WHEN(
"using outlets keyword, only outlet specified")
224 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel2",
"channel3",
"channel4"},
225 {
"outlets",
"outlets",
"outlets",
"outlets"},
226 {
"0",
"1",
"2",
"3"} );
228 mx::app::appConfigurator config;
229 config.readConfig(
"/tmp/outletController_test.conf");
240 std::vector<size_t> outlets, onOrder, offOrder;
241 std::vector<unsigned> onDelays, offDelays;
249 REQUIRE( offOrder.size() == 0);
251 REQUIRE( onDelays.size() == 0);
253 REQUIRE( offDelays.size() == 0);
262 REQUIRE( offOrder.size() == 0);
264 REQUIRE( onDelays.size() == 0);
266 REQUIRE( offDelays.size() == 0);
275 REQUIRE( offOrder.size() == 0);
277 REQUIRE( onDelays.size() == 0);
279 REQUIRE( offDelays.size() == 0);
288 REQUIRE( offOrder.size() == 0);
290 REQUIRE( onDelays.size() == 0);
292 REQUIRE( offDelays.size() == 0);
295 WHEN(
"using outlets keyword, all specified")
297 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2",
"channel2",
"channel2",
"channel3",
"channel3",
"channel3",
"channel3",
"channel3",
"channel4",
"channel4",
"channel4",
"channel4",
"channel4" },
298 {
"outlets",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlets",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlets",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlets",
"onOrder",
"offOrder",
"onDelays",
"offDelays" },
299 {
"0",
"0",
"0",
"100",
"120",
"1",
"0",
"0",
"105",
"130",
"2",
"0",
"0",
"107",
"132",
"3",
"0",
"0",
"108",
"133"});
301 mx::app::appConfigurator config;
302 config.readConfig(
"/tmp/outletController_test.conf");
313 std::vector<size_t> outlets, onOrder, offOrder;
314 std::vector<unsigned> onDelays, offDelays;
324 REQUIRE( offOrder.size() == 1);
327 REQUIRE( onDelays.size() == 1);
330 REQUIRE( offDelays.size() == 1);
341 REQUIRE( offOrder.size() == 1);
344 REQUIRE( onDelays.size() == 1);
347 REQUIRE( offDelays.size() == 1);
358 REQUIRE( offOrder.size() == 1);
361 REQUIRE( onDelays.size() == 1);
364 REQUIRE( offDelays.size() == 1);
375 REQUIRE( offOrder.size() == 1);
378 REQUIRE( onDelays.size() == 1);
381 REQUIRE( offDelays.size() == 1);
386 GIVEN(
"a config file with 2 channels for 4 outlets")
388 WHEN(
"using outlet keyword, only outlet specified")
390 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel2" },
391 {
"outlet",
"outlet" },
394 mx::app::appConfigurator config;
395 config.readConfig(
"/tmp/outletController_test.conf");
406 std::vector<size_t> outlets, onOrder, offOrder;
407 std::vector<unsigned> onDelays, offDelays;
416 REQUIRE( offOrder.size() == 0);
418 REQUIRE( onDelays.size() == 0);
420 REQUIRE( offDelays.size() == 0);
430 REQUIRE( offOrder.size() == 0);
432 REQUIRE( onDelays.size() == 0);
434 REQUIRE( offDelays.size() == 0);
439 WHEN(
"using outlet keyword, all specified")
441 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2",
"channel2",
"channel2" },
442 {
"outlet",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlet",
"onOrder",
"offOrder",
"onDelays",
"offDelays" },
443 {
"0,1",
"0,1",
"1,0",
"0,105",
"0,107",
"2,3",
"1,0",
"0,1",
"0,106",
"0,108" } );
445 mx::app::appConfigurator config;
446 config.readConfig(
"/tmp/outletController_test.conf");
457 std::vector<size_t> outlets, onOrder, offOrder;
458 std::vector<unsigned> onDelays, offDelays;
469 REQUIRE( offOrder.size() == 2);
473 REQUIRE( onDelays.size() == 2);
477 REQUIRE( offDelays.size() == 2);
479 REQUIRE( offDelays[1] == 107 );
491 REQUIRE( offOrder.size() == 2);
495 REQUIRE( onDelays.size() == 2);
499 REQUIRE( offDelays.size() == 2);
501 REQUIRE( offDelays[1] == 108 );
504 WHEN(
"using outlets keyword, only outlet specified")
506 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel2" },
507 {
"outlets",
"outlets" },
510 mx::app::appConfigurator config;
511 config.readConfig(
"/tmp/outletController_test.conf");
522 std::vector<size_t> outlets, onOrder, offOrder;
523 std::vector<unsigned> onDelays, offDelays;
532 REQUIRE( offOrder.size() == 0);
534 REQUIRE( onDelays.size() == 0);
536 REQUIRE( offDelays.size() == 0);
547 REQUIRE( offOrder.size() == 0);
549 REQUIRE( onDelays.size() == 0);
551 REQUIRE( offDelays.size() == 0);
554 WHEN(
"using outlets keyword, all specified")
556 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2",
"channel2",
"channel2" },
557 {
"outlets",
"onOrder",
"offOrder",
"onDelays",
"offDelays",
"outlets",
"onOrder",
"offOrder",
"onDelays",
"offDelays" },
558 {
"0,2",
"0,1",
"1,0",
"0,105",
"0,107",
"1,3",
"1,0",
"0,1",
"0,106",
"0,108" } );
560 mx::app::appConfigurator config;
561 config.readConfig(
"/tmp/outletController_test.conf");
572 std::vector<size_t> outlets, onOrder, offOrder;
573 std::vector<unsigned> onDelays, offDelays;
584 REQUIRE( offOrder.size() == 2);
588 REQUIRE( onDelays.size() == 2);
592 REQUIRE( offDelays.size() == 2);
594 REQUIRE( offDelays[1] == 107 );
606 REQUIRE( offOrder.size() == 2);
610 REQUIRE( onDelays.size() == 2);
614 REQUIRE( offDelays.size() == 2);
616 REQUIRE( offDelays[1] == 108 );
621 SCENARIO(
"outletController Operation",
"[outletController]" )
623 GIVEN(
"a config file with 4 channels for 4 outlets, only outlet specified")
625 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel2",
"channel3",
"channel4"},
626 {
"outlet",
"outlet",
"outlet",
"outlet"},
627 {
"0",
"1",
"2",
"3"} );
629 mx::app::appConfigurator config;
630 config.readConfig(
"/tmp/outletController_test.conf");
636 WHEN(
"test device startup outlet states")
650 WHEN(
"operating a single channel")
772 WHEN(
"operating multiple channels")
902 WHEN(
"outlets intermediate")
971 GIVEN(
"a config file with 2 channels for 4 outlets, only outlet specified")
973 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel2" },
974 {
"outlet",
"outlet" },
977 mx::app::appConfigurator config;
978 config.readConfig(
"/tmp/outletController_test.conf");
984 WHEN(
"test device startup outlet states")
996 WHEN(
"operating a single channel")
1056 WHEN(
"operating two channels")
1087 WHEN(
"outlets intermediate")
1167 GIVEN(
"a config file with 2 channels for 4 outlets, onOrder specified")
1171 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel2",
"channel2" },
1172 {
"outlet",
"onOrder",
"outlet",
"onOrder" },
1173 {
"0,1",
"0,1",
"2,3",
"0,1" } );
1175 mx::app::appConfigurator config;
1176 config.readConfig(
"/tmp/outletController_test.conf");
1182 WHEN(
"test device startup channel states")
1188 WHEN(
"operating a single channel")
1225 GIVEN(
"a config file with 2 channels for 4 outlets, onOrder reversed")
1229 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel2",
"channel2" },
1230 {
"outlet",
"onOrder",
"outlet",
"onOrder" },
1231 {
"0,1",
"1,0",
"2,3",
"1,0" } );
1233 mx::app::appConfigurator config;
1234 config.readConfig(
"/tmp/outletController_test.conf");
1240 WHEN(
"test device startup channel states")
1246 WHEN(
"operating a single channel")
1283 GIVEN(
"a config file with 2 channels for 4 outlets, onOrder and offOrder specified, the same")
1287 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2" },
1288 {
"outlet",
"onOrder",
"offOrder",
"outlet",
"onOrder",
"offOrder" },
1289 {
"0,1",
"0,1",
"0,1",
"2,3",
"0,1" ,
"0,1" } );
1291 mx::app::appConfigurator config;
1292 config.readConfig(
"/tmp/outletController_test.conf");
1298 WHEN(
"test device startup channel states")
1304 WHEN(
"operating a single channel")
1346 GIVEN(
"a config file with 2 channels for 4 outlets, onOrder and offOrder specified, different")
1350 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2" },
1351 {
"outlet",
"onOrder",
"offOrder",
"outlet",
"onOrder",
"offOrder" },
1352 {
"0,1",
"0,1",
"1,0",
"2,3",
"0,1" ,
"1,0" } );
1354 mx::app::appConfigurator config;
1355 config.readConfig(
"/tmp/outletController_test.conf");
1361 WHEN(
"test device startup channel states")
1367 WHEN(
"operating a single channel")
1412 GIVEN(
"a config file with 2 channels for 4 outlets, onOrder and offOrder specified, different, reversed")
1416 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2" },
1417 {
"outlet",
"onOrder",
"offOrder",
"outlet",
"onOrder",
"offOrder" },
1418 {
"0,1",
"1,0",
"0,1",
"2,3",
"1,0" ,
"0,1" } );
1420 mx::app::appConfigurator config;
1421 config.readConfig(
"/tmp/outletController_test.conf");
1427 WHEN(
"test device startup channel states")
1433 WHEN(
"operating a single channel")
1480 SCENARIO(
"outletController Operation with delays",
"[outletController]" )
1482 std::cout <<
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1483 std::cout <<
"[outletController] Testing delays ... \n";
1484 GIVEN(
"a config file with 2 channels for 4 outlets, onDelays specified")
1488 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel2",
"channel2" },
1489 {
"outlet",
"onDelays",
"outlet",
"onDelays" },
1490 {
"0,1",
"0,350",
"2,3",
"0,150" } );
1492 mx::app::appConfigurator config;
1493 config.readConfig(
"/tmp/outletController_test.conf");
1499 WHEN(
"operating a single channel")
1541 GIVEN(
"a config file with 2 channels for 4 outlets, offDelays specified")
1545 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel2",
"channel2" },
1546 {
"outlet",
"offDelays",
"outlet",
"offDelays" },
1547 {
"0,1",
"0,550",
"2,3",
"0,750" } );
1549 mx::app::appConfigurator config;
1550 config.readConfig(
"/tmp/outletController_test.conf");
1556 WHEN(
"operating a single channel")
1599 GIVEN(
"a config file with 2 channels for 4 outlets, onDelays and offDelays specified, off order reversed")
1603 mx::app::writeConfigFile(
"/tmp/outletController_test.conf", {
"channel1",
"channel1",
"channel1",
"channel1",
"channel1",
"channel2",
"channel2",
"channel2",
"channel2",
"channel2" },
1604 {
"outlet",
"onOrder",
"onDelays",
"offOrder",
"offDelays",
"outlet",
"onOrder",
"onDelays",
"offOrder",
"offDelays" },
1605 {
"0,1",
"0,1",
"0,350",
"1,0",
"0,450",
"2,3",
"0,1",
"0,150",
"1,0",
"0,75" } );
1607 mx::app::appConfigurator config;
1608 config.readConfig(
"/tmp/outletController_test.conf");
1614 WHEN(
"operating a single channel")
1658 std::cout <<
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
void nanoSleep(unsigned long nsec)
SCENARIO("outletController Configuration", "[outletController]")
A generic outlet controller.
int outletState(int outletNum)
Get the currently stored outlet state, without updating from device.
std::vector< unsigned > channelOffDelays(const std::string &channel)
Get the vector of outlet off delays for a channel.
int turnChannelOn(const std::string &channel)
Turn a channel on.
int channelState(const std::string &channel)
Get the state of a channel.
int loadConfig(mx::app::appConfigurator &config)
Load the [channel] sections from an application configurator.
size_t numChannels()
Get the number of channels.
std::vector< size_t > channelOnOrder(const std::string &channel)
Get the vector of outlet on orders for a channel.
int setupConfig(mx::app::appConfigurator &config)
Setup an application configurator for an outletController.
int turnChannelOff(const std::string &channel)
Turn a channel off.
std::vector< size_t > channelOutlets(const std::string &channel)
Get the vector of outlet indices for a channel.
int setNumberOfOutlets(int numOuts)
Sets the number of outlets. This should be called by the derived class constructor.
std::vector< unsigned > channelOnDelays(const std::string &channel)
Get the vector of outlet on delays for a channel.
std::vector< size_t > channelOffOrder(const std::string &channel)
Get the vector of outlet off orders for a channel.
std::vector< int > m_outletStates
The current states of each outlet. These MUST be updated by derived classes in the overridden updated...
std::vector< double > m_timestamps
virtual int turnOutletOff(int outletNum)
Turn an outlet off.
virtual int updateOutletState(int outletNum)
Get the state of the outlet from the device.
virtual int turnOutletOn(int outletNum)
Turn an outlet on.