API
 
Loading...
Searching...
No Matches
outletController_test.cpp
Go to the documentation of this file.
1//#define CATCH_CONFIG_MAIN
2#include "../../../../tests/catch2/catch.hpp"
3
4#include <mx/sys/timeUtils.hpp>
5
6#define OUTLET_CTRL_TEST_NOINDI
7//#define OUTLET_CTRL_TEST_NOLOG
8#include "../../MagAOXApp.hpp"
9#include "../outletController.hpp"
10
11using namespace MagAOX::app;
12
13/** \defgroup outletController_tests libXWC::app::dev::outletController Unit Tests
14 * \ingroup app_dev_unit_tests
15*/
17{
18
19struct outletControllerTest : public MagAOXApp<false>, dev::outletController<outletControllerTest>
20{
21 std::vector<double> m_timestamps;
22
24 : MagAOX::app::MagAOXApp<false>( "", false )
25 {
27 m_timestamps.resize(4,0);
32 }
33
36
37 int setupConfig( mx::app::appConfigurator & config)
38 {
40 }
41
42 int loadConfig( mx::app::appConfigurator & config)
43 {
45 }
46
48 {
49 return 0;
50 }
51
53 {
54 return 0;
55 }
56
58 {
59 return 0;
60 }
61
63 {
65 }
66
68 {
70 mx::sys::nanoSleep(1);
71 m_timestamps[outletNum] = mx::sys::get_curr_time();
72
73 return 0;
74 }
75
77 {
79 mx::sys::nanoSleep(1);
80 m_timestamps[outletNum] = mx::sys::get_curr_time();
81
82 return 0;
83 }
84
85};
86
87/// outletController Configuration
88/**
89 * \ingroup outletController_tests
90 */
91SCENARIO( "outletController Configuration", "[outletController]" )
92{
93 GIVEN("a config file with 4 channels for 4 outlets")
94 {
95 WHEN("using outlet keyword, only outlet specified")
96 {
97 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel2", "channel3", "channel4"},
98 {"outlet", "outlet", "outlet", "outlet"},
99 {"0", "1", "2", "3"} );
100
101 mx::app::appConfigurator config;
102 config.readConfig("/tmp/outletController_test.conf");
103
105 int rv;
106 rv = pdt.setupConfig(config);
107 REQUIRE( rv == 0);
108
109 rv = pdt.loadConfig(config);
110 REQUIRE( rv == 0);
111 REQUIRE( pdt.numChannels() == 4);
112
113 std::vector<size_t> outlets, onOrder, offOrder;
114 std::vector<unsigned> onDelays, offDelays;
115 outlets = pdt.channelOutlets("channel1");
116 REQUIRE( outlets.size() == 1);
117 REQUIRE( outlets[0] == 0 );
118
119 onOrder = pdt.channelOnOrder("channel1");
120 REQUIRE( onOrder.size() == 0);
121 offOrder = pdt.channelOffOrder("channel1");
122 REQUIRE( offOrder.size() == 0);
123 onDelays = pdt.channelOnDelays("channel1");
124 REQUIRE( onDelays.size() == 0);
125 offDelays = pdt.channelOffDelays("channel1");
126 REQUIRE( offDelays.size() == 0);
127
128 outlets = pdt.channelOutlets("channel2");
129 REQUIRE( outlets.size() == 1);
130 REQUIRE( outlets[0] == 1 );
131
132 onOrder = pdt.channelOnOrder("channel2");
133 REQUIRE( onOrder.size() == 0);
134 offOrder = pdt.channelOffOrder("channel2");
135 REQUIRE( offOrder.size() == 0);
136 onDelays = pdt.channelOnDelays("channel2");
137 REQUIRE( onDelays.size() == 0);
138 offDelays = pdt.channelOffDelays("channel2");
139 REQUIRE( offDelays.size() == 0);
140
141 outlets = pdt.channelOutlets("channel3");
142 REQUIRE( outlets.size() == 1);
143 REQUIRE( outlets[0] == 2 );
144
145 onOrder = pdt.channelOnOrder("channel3");
146 REQUIRE( onOrder.size() == 0);
147 offOrder = pdt.channelOffOrder("channel3");
148 REQUIRE( offOrder.size() == 0);
149 onDelays = pdt.channelOnDelays("channel3");
150 REQUIRE( onDelays.size() == 0);
151 offDelays = pdt.channelOffDelays("channel3");
152 REQUIRE( offDelays.size() == 0);
153
154 outlets = pdt.channelOutlets("channel4");
155 REQUIRE( outlets.size() == 1);
156 REQUIRE( outlets[0] == 3 );
157
158 onOrder = pdt.channelOnOrder("channel4");
159 REQUIRE( onOrder.size() == 0);
160 offOrder = pdt.channelOffOrder("channel4");
161 REQUIRE( offOrder.size() == 0);
162 onDelays = pdt.channelOnDelays("channel4");
163 REQUIRE( onDelays.size() == 0);
164 offDelays = pdt.channelOffDelays("channel4");
165 REQUIRE( offDelays.size() == 0);
166
167 }
168
169 WHEN("using outlet keyword, all specified")
170 {
171 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" },
172 {"outlet", "onOrder", "offOrder", "onDelays", "offDelays", "outlet", "onOrder", "offOrder", "onDelays", "offDelays", "outlet", "onOrder", "offOrder", "onDelays", "offDelays", "outlet", "onOrder", "offOrder", "onDelays", "offDelays" },
173 {"0", "0", "0", "100", "120", "1", "0", "0", "105", "130", "2", "0", "0", "107", "132", "3", "0", "0", "108", "133"});
174
175 mx::app::appConfigurator config;
176 config.readConfig("/tmp/outletController_test.conf");
177
179 int rv;
180 rv = pdt.setupConfig(config);
181 REQUIRE( rv == 0);
182
183 rv = pdt.loadConfig(config);
184 REQUIRE( rv == 0);
185 REQUIRE( pdt.numChannels() == 4);
186
187 std::vector<size_t> outlets, onOrder, offOrder;
188 std::vector<unsigned> onDelays, offDelays;
189
190 outlets = pdt.channelOutlets("channel1");
191 REQUIRE( outlets.size() == 1);
192 REQUIRE( outlets[0] == 0 );
193
194 onOrder = pdt.channelOnOrder("channel1");
195 REQUIRE( onOrder.size() == 1);
196 REQUIRE( onOrder[0] == 0);
197 offOrder = pdt.channelOffOrder("channel1");
198 REQUIRE( offOrder.size() == 1);
199 REQUIRE( offOrder[0] == 0);
200 onDelays = pdt.channelOnDelays("channel1");
201 REQUIRE( onDelays.size() == 1);
202 REQUIRE( onDelays[0] == 100);
203 offDelays = pdt.channelOffDelays("channel1");
204 REQUIRE( offDelays.size() == 1);
205 REQUIRE( offDelays[0] == 120);
206
207 outlets = pdt.channelOutlets("channel2");
208 REQUIRE( outlets.size() == 1);
209 REQUIRE( outlets[0] == 1 );
210
211 onOrder = pdt.channelOnOrder("channel2");
212 REQUIRE( onOrder.size() == 1);
213 REQUIRE( onOrder[0] == 0);
214 offOrder = pdt.channelOffOrder("channel2");
215 REQUIRE( offOrder.size() == 1);
216 REQUIRE( offOrder[0] == 0);
217 onDelays = pdt.channelOnDelays("channel2");
218 REQUIRE( onDelays.size() == 1);
219 REQUIRE( onDelays[0] == 105);
220 offDelays = pdt.channelOffDelays("channel2");
221 REQUIRE( offDelays.size() == 1);
222 REQUIRE( offDelays[0] == 130);
223
224 outlets = pdt.channelOutlets("channel3");
225 REQUIRE( outlets.size() == 1);
226 REQUIRE( outlets[0] == 2 );
227
228 onOrder = pdt.channelOnOrder("channel3");
229 REQUIRE( onOrder.size() == 1);
230 REQUIRE( onOrder[0] == 0);
231 offOrder = pdt.channelOffOrder("channel3");
232 REQUIRE( offOrder.size() == 1);
233 REQUIRE( offOrder[0] == 0);
234 onDelays = pdt.channelOnDelays("channel3");
235 REQUIRE( onDelays.size() == 1);
236 REQUIRE( onDelays[0] == 107);
237 offDelays = pdt.channelOffDelays("channel3");
238 REQUIRE( offDelays.size() == 1);
239 REQUIRE( offDelays[0] == 132);
240
241 outlets = pdt.channelOutlets("channel4");
242 REQUIRE( outlets.size() == 1);
243 REQUIRE( outlets[0] == 3 );
244
245 onOrder = pdt.channelOnOrder("channel4");
246 REQUIRE( onOrder.size() == 1);
247 REQUIRE( onOrder[0] == 0);
248 offOrder = pdt.channelOffOrder("channel4");
249 REQUIRE( offOrder.size() == 1);
250 REQUIRE( offOrder[0] == 0);
251 onDelays = pdt.channelOnDelays("channel4");
252 REQUIRE( onDelays.size() == 1);
253 REQUIRE( onDelays[0] == 108);
254 offDelays = pdt.channelOffDelays("channel4");
255 REQUIRE( offDelays.size() == 1);
256 REQUIRE( offDelays[0] == 133);
257 }
258
259 WHEN("using outlets keyword, only outlet specified")
260 {
261 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel2", "channel3", "channel4"},
262 {"outlets", "outlets", "outlets", "outlets"},
263 {"0", "1", "2", "3"} );
264
265 mx::app::appConfigurator config;
266 config.readConfig("/tmp/outletController_test.conf");
267
269 int rv;
270 rv = pdt.setupConfig(config);
271 REQUIRE( rv == 0);
272
273 rv = pdt.loadConfig(config);
274 REQUIRE( rv == 0);
275 REQUIRE( pdt.numChannels() == 4);
276
277 std::vector<size_t> outlets, onOrder, offOrder;
278 std::vector<unsigned> onDelays, offDelays;
279 outlets = pdt.channelOutlets("channel1");
280 REQUIRE( outlets.size() == 1);
281 REQUIRE( outlets[0] == 0 );
282
283 onOrder = pdt.channelOnOrder("channel1");
284 REQUIRE( onOrder.size() == 0);
285 offOrder = pdt.channelOffOrder("channel1");
286 REQUIRE( offOrder.size() == 0);
287 onDelays = pdt.channelOnDelays("channel1");
288 REQUIRE( onDelays.size() == 0);
289 offDelays = pdt.channelOffDelays("channel1");
290 REQUIRE( offDelays.size() == 0);
291
292 outlets = pdt.channelOutlets("channel2");
293 REQUIRE( outlets.size() == 1);
294 REQUIRE( outlets[0] == 1 );
295
296 onOrder = pdt.channelOnOrder("channel2");
297 REQUIRE( onOrder.size() == 0);
298 offOrder = pdt.channelOffOrder("channel2");
299 REQUIRE( offOrder.size() == 0);
300 onDelays = pdt.channelOnDelays("channel2");
301 REQUIRE( onDelays.size() == 0);
302 offDelays = pdt.channelOffDelays("channel2");
303 REQUIRE( offDelays.size() == 0);
304
305 outlets = pdt.channelOutlets("channel3");
306 REQUIRE( outlets.size() == 1);
307 REQUIRE( outlets[0] == 2 );
308
309 onOrder = pdt.channelOnOrder("channel3");
310 REQUIRE( onOrder.size() == 0);
311 offOrder = pdt.channelOffOrder("channel3");
312 REQUIRE( offOrder.size() == 0);
313 onDelays = pdt.channelOnDelays("channel3");
314 REQUIRE( onDelays.size() == 0);
315 offDelays = pdt.channelOffDelays("channel3");
316 REQUIRE( offDelays.size() == 0);
317
318 outlets = pdt.channelOutlets("channel4");
319 REQUIRE( outlets.size() == 1);
320 REQUIRE( outlets[0] == 3 );
321
322 onOrder = pdt.channelOnOrder("channel4");
323 REQUIRE( onOrder.size() == 0);
324 offOrder = pdt.channelOffOrder("channel4");
325 REQUIRE( offOrder.size() == 0);
326 onDelays = pdt.channelOnDelays("channel4");
327 REQUIRE( onDelays.size() == 0);
328 offDelays = pdt.channelOffDelays("channel4");
329 REQUIRE( offDelays.size() == 0);
330 }
331
332 WHEN("using outlets keyword, all specified")
333 {
334 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" },
335 {"outlets", "onOrder", "offOrder", "onDelays", "offDelays", "outlets", "onOrder", "offOrder", "onDelays", "offDelays", "outlets", "onOrder", "offOrder", "onDelays", "offDelays", "outlets", "onOrder", "offOrder", "onDelays", "offDelays" },
336 {"0", "0", "0", "100", "120", "1", "0", "0", "105", "130", "2", "0", "0", "107", "132", "3", "0", "0", "108", "133"});
337
338 mx::app::appConfigurator config;
339 config.readConfig("/tmp/outletController_test.conf");
340
342 int rv;
343 rv = pdt.setupConfig(config);
344 REQUIRE( rv == 0);
345
346 rv = pdt.loadConfig(config);
347 REQUIRE( rv == 0);
348 REQUIRE( pdt.numChannels() == 4);
349
350 std::vector<size_t> outlets, onOrder, offOrder;
351 std::vector<unsigned> onDelays, offDelays;
352
353 outlets = pdt.channelOutlets("channel1");
354 REQUIRE( outlets.size() == 1);
355 REQUIRE( outlets[0] == 0 );
356
357 onOrder = pdt.channelOnOrder("channel1");
358 REQUIRE( onOrder.size() == 1);
359 REQUIRE( onOrder[0] == 0);
360 offOrder = pdt.channelOffOrder("channel1");
361 REQUIRE( offOrder.size() == 1);
362 REQUIRE( offOrder[0] == 0);
363 onDelays = pdt.channelOnDelays("channel1");
364 REQUIRE( onDelays.size() == 1);
365 REQUIRE( onDelays[0] == 100);
366 offDelays = pdt.channelOffDelays("channel1");
367 REQUIRE( offDelays.size() == 1);
368 REQUIRE( offDelays[0] == 120);
369
370 outlets = pdt.channelOutlets("channel2");
371 REQUIRE( outlets.size() == 1);
372 REQUIRE( outlets[0] == 1 );
373
374 onOrder = pdt.channelOnOrder("channel2");
375 REQUIRE( onOrder.size() == 1);
376 REQUIRE( onOrder[0] == 0);
377 offOrder = pdt.channelOffOrder("channel2");
378 REQUIRE( offOrder.size() == 1);
379 REQUIRE( offOrder[0] == 0);
380 onDelays = pdt.channelOnDelays("channel2");
381 REQUIRE( onDelays.size() == 1);
382 REQUIRE( onDelays[0] == 105);
383 offDelays = pdt.channelOffDelays("channel2");
384 REQUIRE( offDelays.size() == 1);
385 REQUIRE( offDelays[0] == 130);
386
387 outlets = pdt.channelOutlets("channel3");
388 REQUIRE( outlets.size() == 1);
389 REQUIRE( outlets[0] == 2 );
390
391 onOrder = pdt.channelOnOrder("channel3");
392 REQUIRE( onOrder.size() == 1);
393 REQUIRE( onOrder[0] == 0);
394 offOrder = pdt.channelOffOrder("channel3");
395 REQUIRE( offOrder.size() == 1);
396 REQUIRE( offOrder[0] == 0);
397 onDelays = pdt.channelOnDelays("channel3");
398 REQUIRE( onDelays.size() == 1);
399 REQUIRE( onDelays[0] == 107);
400 offDelays = pdt.channelOffDelays("channel3");
401 REQUIRE( offDelays.size() == 1);
402 REQUIRE( offDelays[0] == 132);
403
404 outlets = pdt.channelOutlets("channel4");
405 REQUIRE( outlets.size() == 1);
406 REQUIRE( outlets[0] == 3 );
407
408 onOrder = pdt.channelOnOrder("channel4");
409 REQUIRE( onOrder.size() == 1);
410 REQUIRE( onOrder[0] == 0);
411 offOrder = pdt.channelOffOrder("channel4");
412 REQUIRE( offOrder.size() == 1);
413 REQUIRE( offOrder[0] == 0);
414 onDelays = pdt.channelOnDelays("channel4");
415 REQUIRE( onDelays.size() == 1);
416 REQUIRE( onDelays[0] == 108);
417 offDelays = pdt.channelOffDelays("channel4");
418 REQUIRE( offDelays.size() == 1);
419 REQUIRE( offDelays[0] == 133);
420 }
421 }
422
423 GIVEN("a config file with 2 channels for 4 outlets")
424 {
425 WHEN("using outlet keyword, only outlet specified")
426 {
427 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel2" },
428 {"outlet", "outlet" },
429 {"0,1", "2,3" } );
430
431 mx::app::appConfigurator config;
432 config.readConfig("/tmp/outletController_test.conf");
433
435 int rv;
436 rv = pdt.setupConfig(config);
437 REQUIRE( rv == 0);
438
439 rv = pdt.loadConfig(config);
440 REQUIRE( rv == 0);
441 REQUIRE( pdt.numChannels() == 2);
442
443 std::vector<size_t> outlets, onOrder, offOrder;
444 std::vector<unsigned> onDelays, offDelays;
445 outlets = pdt.channelOutlets("channel1");
446 REQUIRE( outlets.size() == 2);
447 REQUIRE( outlets[0] == 0 );
448 REQUIRE( outlets[1] == 1 );
449
450 onOrder = pdt.channelOnOrder("channel1");
451 REQUIRE( onOrder.size() == 0);
452 offOrder = pdt.channelOffOrder("channel1");
453 REQUIRE( offOrder.size() == 0);
454 onDelays = pdt.channelOnDelays("channel1");
455 REQUIRE( onDelays.size() == 0);
456 offDelays = pdt.channelOffDelays("channel1");
457 REQUIRE( offDelays.size() == 0);
458
459 outlets = pdt.channelOutlets("channel2");
460 REQUIRE( outlets.size() == 2);
461 REQUIRE( outlets[0] == 2 );
462 REQUIRE( outlets[1] == 3 );
463
464 onOrder = pdt.channelOnOrder("channel2");
465 REQUIRE( onOrder.size() == 0);
466 offOrder = pdt.channelOffOrder("channel2");
467 REQUIRE( offOrder.size() == 0);
468 onDelays = pdt.channelOnDelays("channel2");
469 REQUIRE( onDelays.size() == 0);
470 offDelays = pdt.channelOffDelays("channel2");
471 REQUIRE( offDelays.size() == 0);
472
473
474 }
475
476 WHEN("using outlet keyword, all specified")
477 {
478 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1","channel1", "channel1", "channel1", "channel1", "channel2", "channel2", "channel2", "channel2", "channel2" },
479 {"outlet", "onOrder", "offOrder", "onDelays", "offDelays", "outlet", "onOrder", "offOrder", "onDelays", "offDelays" },
480 {"0,1", "0,1", "1,0", "0,105", "0,107", "2,3", "1,0", "0,1", "0,106", "0,108" } );
481
482 mx::app::appConfigurator config;
483 config.readConfig("/tmp/outletController_test.conf");
484
486 int rv;
487 rv = pdt.setupConfig(config);
488 REQUIRE( rv == 0);
489
490 rv = pdt.loadConfig(config);
491 REQUIRE( rv == 0);
492 REQUIRE( pdt.numChannels() == 2);
493
494 std::vector<size_t> outlets, onOrder, offOrder;
495 std::vector<unsigned> onDelays, offDelays;
496 outlets = pdt.channelOutlets("channel1");
497 REQUIRE( outlets.size() == 2);
498 REQUIRE( outlets[0] == 0 );
499 REQUIRE( outlets[1] == 1 );
500
501 onOrder = pdt.channelOnOrder("channel1");
502 REQUIRE( onOrder.size() == 2);
503 REQUIRE( onOrder[0] == 0 );
504 REQUIRE( onOrder[1] == 1 );
505 offOrder = pdt.channelOffOrder("channel1");
506 REQUIRE( offOrder.size() == 2);
507 REQUIRE( offOrder[0] == 1 );
508 REQUIRE( offOrder[1] == 0 );
509 onDelays = pdt.channelOnDelays("channel1");
510 REQUIRE( onDelays.size() == 2);
511 REQUIRE( onDelays[0] == 0 );
512 REQUIRE( onDelays[1] == 105 );
513 offDelays = pdt.channelOffDelays("channel1");
514 REQUIRE( offDelays.size() == 2);
515 REQUIRE( offDelays[0] == 0 );
516 REQUIRE( offDelays[1] == 107 );
517
518 outlets = pdt.channelOutlets("channel2");
519 REQUIRE( outlets.size() == 2);
520 REQUIRE( outlets[0] == 2 );
521 REQUIRE( outlets[1] == 3 );
522
523 onOrder = pdt.channelOnOrder("channel2");
524 REQUIRE( onOrder.size() == 2);
525 REQUIRE( onOrder[0] == 1 );
526 REQUIRE( onOrder[1] == 0 );
527 offOrder = pdt.channelOffOrder("channel2");
528 REQUIRE( offOrder.size() == 2);
529 REQUIRE( offOrder[0] == 0 );
530 REQUIRE( offOrder[1] == 1 );
531 onDelays = pdt.channelOnDelays("channel2");
532 REQUIRE( onDelays.size() == 2);
533 REQUIRE( onDelays[0] == 0 );
534 REQUIRE( onDelays[1] == 106 );
535 offDelays = pdt.channelOffDelays("channel2");
536 REQUIRE( offDelays.size() == 2);
537 REQUIRE( offDelays[0] == 0 );
538 REQUIRE( offDelays[1] == 108 );
539 }
540
541 WHEN("using outlets keyword, only outlet specified")
542 {
543 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel2" },
544 {"outlets", "outlets" },
545 {"0,1", "2,3" } );
546
547 mx::app::appConfigurator config;
548 config.readConfig("/tmp/outletController_test.conf");
549
551 int rv;
552 rv = pdt.setupConfig(config);
553 REQUIRE( rv == 0);
554
555 rv = pdt.loadConfig(config);
556 REQUIRE( rv == 0);
557 REQUIRE( pdt.numChannels() == 2);
558
559 std::vector<size_t> outlets, onOrder, offOrder;
560 std::vector<unsigned> onDelays, offDelays;
561 outlets = pdt.channelOutlets("channel1");
562 REQUIRE( outlets.size() == 2);
563 REQUIRE( outlets[0] == 0 );
564 REQUIRE( outlets[1] == 1 );
565
566 onOrder = pdt.channelOnOrder("channel1");
567 REQUIRE( onOrder.size() == 0);
568 offOrder = pdt.channelOffOrder("channel1");
569 REQUIRE( offOrder.size() == 0);
570 onDelays = pdt.channelOnDelays("channel1");
571 REQUIRE( onDelays.size() == 0);
572 offDelays = pdt.channelOffDelays("channel1");
573 REQUIRE( offDelays.size() == 0);
574
575
576 outlets = pdt.channelOutlets("channel2");
577 REQUIRE( outlets.size() == 2);
578 REQUIRE( outlets[0] == 2 );
579 REQUIRE( outlets[1] == 3 );
580
581 onOrder = pdt.channelOnOrder("channel2");
582 REQUIRE( onOrder.size() == 0);
583 offOrder = pdt.channelOffOrder("channel2");
584 REQUIRE( offOrder.size() == 0);
585 onDelays = pdt.channelOnDelays("channel2");
586 REQUIRE( onDelays.size() == 0);
587 offDelays = pdt.channelOffDelays("channel2");
588 REQUIRE( offDelays.size() == 0);
589 }
590
591 WHEN("using outlets keyword, all specified")
592 {
593 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1","channel1", "channel1", "channel1", "channel1", "channel2", "channel2", "channel2", "channel2", "channel2" },
594 {"outlets", "onOrder", "offOrder", "onDelays", "offDelays", "outlets", "onOrder", "offOrder", "onDelays", "offDelays" },
595 {"0,2", "0,1", "1,0", "0,105", "0,107", "1,3", "1,0", "0,1", "0,106", "0,108" } );
596
597 mx::app::appConfigurator config;
598 config.readConfig("/tmp/outletController_test.conf");
599
601 int rv;
602 rv = pdt.setupConfig(config);
603 REQUIRE( rv == 0);
604
605 rv = pdt.loadConfig(config);
606 REQUIRE( rv == 0);
607 REQUIRE( pdt.numChannels() == 2);
608
609 std::vector<size_t> outlets, onOrder, offOrder;
610 std::vector<unsigned> onDelays, offDelays;
611 outlets = pdt.channelOutlets("channel1");
612 REQUIRE( outlets.size() == 2);
613 REQUIRE( outlets[0] == 0 );
614 REQUIRE( outlets[1] == 2 );
615
616 onOrder = pdt.channelOnOrder("channel1");
617 REQUIRE( onOrder.size() == 2);
618 REQUIRE( onOrder[0] == 0 );
619 REQUIRE( onOrder[1] == 1 );
620 offOrder = pdt.channelOffOrder("channel1");
621 REQUIRE( offOrder.size() == 2);
622 REQUIRE( offOrder[0] == 1 );
623 REQUIRE( offOrder[1] == 0 );
624 onDelays = pdt.channelOnDelays("channel1");
625 REQUIRE( onDelays.size() == 2);
626 REQUIRE( onDelays[0] == 0 );
627 REQUIRE( onDelays[1] == 105 );
628 offDelays = pdt.channelOffDelays("channel1");
629 REQUIRE( offDelays.size() == 2);
630 REQUIRE( offDelays[0] == 0 );
631 REQUIRE( offDelays[1] == 107 );
632
633 outlets = pdt.channelOutlets("channel2");
634 REQUIRE( outlets.size() == 2);
635 REQUIRE( outlets[0] == 1 );
636 REQUIRE( outlets[1] == 3 );
637
638 onOrder = pdt.channelOnOrder("channel2");
639 REQUIRE( onOrder.size() == 2);
640 REQUIRE( onOrder[0] == 1 );
641 REQUIRE( onOrder[1] == 0 );
642 offOrder = pdt.channelOffOrder("channel2");
643 REQUIRE( offOrder.size() == 2);
644 REQUIRE( offOrder[0] == 0 );
645 REQUIRE( offOrder[1] == 1 );
646 onDelays = pdt.channelOnDelays("channel2");
647 REQUIRE( onDelays.size() == 2);
648 REQUIRE( onDelays[0] == 0 );
649 REQUIRE( onDelays[1] == 106 );
650 offDelays = pdt.channelOffDelays("channel2");
651 REQUIRE( offDelays.size() == 2);
652 REQUIRE( offDelays[0] == 0 );
653 REQUIRE( offDelays[1] == 108 );
654 }
655 }
656}
657
658/// outletController Operation
659/**
660 * \ingroup outletController_tests
661 */
662SCENARIO( "outletController Operation", "[outletController]" )
663{
664 GIVEN("a config file with 4 channels for 4 outlets, only outlet specified")
665 {
666 mx::app::writeConfigFile( "/tmp/outletController_test.conf",
667 {"channel1", "channel2", "channel3", "channel4"},
668 {"outlet", "outlet", "outlet", "outlet"},
669 {"0", "1", "2", "3"} );
670
671 mx::app::appConfigurator config;
672 config.readConfig("/tmp/outletController_test.conf");
673
675 pdt.setupConfig(config);
676 pdt.loadConfig(config);
677
678 WHEN("test device startup outlet states")
679 {
680 //Verify outlet startup state
681 REQUIRE( pdt.outletState(0) == 0 );
682 REQUIRE( pdt.outletState(1) == 0 );
683 REQUIRE( pdt.outletState(2) == 0 );
684 REQUIRE( pdt.outletState(3) == 0 );
685
686 //Verify channel state at startup
687 REQUIRE( pdt.channelState("channel1") == 0 );
688 REQUIRE( pdt.channelState("channel2") == 0 );
689 REQUIRE( pdt.channelState("channel3") == 0 );
690 REQUIRE( pdt.channelState("channel4") == 0 );
691 }
692
693 WHEN("operating a single channel")
694 {
695 //Turn on channel1
696 pdt.turnChannelOn("channel1");
697
698 //Verify outlet state
699 REQUIRE( pdt.outletState(0) == 2 );
700 REQUIRE( pdt.outletState(1) == 0 );
701 REQUIRE( pdt.outletState(2) == 0 );
702 REQUIRE( pdt.outletState(3) == 0 );
703
704 //Verify channel state
705 REQUIRE( pdt.channelState("channel1") == 2 );
706 REQUIRE( pdt.channelState("channel2") == 0 );
707 REQUIRE( pdt.channelState("channel3") == 0 );
708 REQUIRE( pdt.channelState("channel4") == 0 );
709
710 //Turn off channel1
711 pdt.turnChannelOff("channel1");
712
713 //Verify outlet state
714 REQUIRE( pdt.outletState(0) == 0 );
715 REQUIRE( pdt.outletState(1) == 0 );
716 REQUIRE( pdt.outletState(2) == 0 );
717 REQUIRE( pdt.outletState(3) == 0 );
718
719 //Verify channel state
720 REQUIRE( pdt.channelState("channel1") == 0 );
721 REQUIRE( pdt.channelState("channel2") == 0 );
722 REQUIRE( pdt.channelState("channel3") == 0 );
723 REQUIRE( pdt.channelState("channel4") == 0 );
724
725 //Turn on channel2
726 pdt.turnChannelOn("channel2");
727
728 //Verify outlet state
729 REQUIRE( pdt.outletState(0) == 0 );
730 REQUIRE( pdt.outletState(1) == 2 );
731 REQUIRE( pdt.outletState(2) == 0 );
732 REQUIRE( pdt.outletState(3) == 0 );
733
734 //Verify channel state
735 REQUIRE( pdt.channelState("channel1") == 0 );
736 REQUIRE( pdt.channelState("channel2") == 2 );
737 REQUIRE( pdt.channelState("channel3") == 0 );
738 REQUIRE( pdt.channelState("channel4") == 0 );
739
740 //Turn off channel2
741 pdt.turnChannelOff("channel2");
742
743 //Verify outlet state
744 REQUIRE( pdt.outletState(0) == 0 );
745 REQUIRE( pdt.outletState(1) == 0 );
746 REQUIRE( pdt.outletState(2) == 0 );
747 REQUIRE( pdt.outletState(3) == 0 );
748
749 //Verify channel state
750 REQUIRE( pdt.channelState("channel1") == 0 );
751 REQUIRE( pdt.channelState("channel2") == 0 );
752 REQUIRE( pdt.channelState("channel3") == 0 );
753 REQUIRE( pdt.channelState("channel4") == 0 );
754
755 //Turn on channel3
756 pdt.turnChannelOn("channel3");
757
758 //Verify outlet state
759 REQUIRE( pdt.outletState(0) == 0 );
760 REQUIRE( pdt.outletState(1) == 0 );
761 REQUIRE( pdt.outletState(2) == 2 );
762 REQUIRE( pdt.outletState(3) == 0 );
763
764 //Verify channel state
765 REQUIRE( pdt.channelState("channel1") == 0 );
766 REQUIRE( pdt.channelState("channel2") == 0 );
767 REQUIRE( pdt.channelState("channel3") == 2 );
768 REQUIRE( pdt.channelState("channel4") == 0 );
769
770 //Turn off channel3
771 pdt.turnChannelOff("channel3");
772
773 //Verify outlet state
774 REQUIRE( pdt.outletState(0) == 0 );
775 REQUIRE( pdt.outletState(1) == 0 );
776 REQUIRE( pdt.outletState(2) == 0 );
777 REQUIRE( pdt.outletState(3) == 0 );
778
779 //Verify channel state
780 REQUIRE( pdt.channelState("channel1") == 0 );
781 REQUIRE( pdt.channelState("channel2") == 0 );
782 REQUIRE( pdt.channelState("channel3") == 0 );
783 REQUIRE( pdt.channelState("channel4") == 0 );
784
785 //Turn on channel4
786 pdt.turnChannelOn("channel4");
787
788 //Verify outlet state
789 REQUIRE( pdt.outletState(0) == 0 );
790 REQUIRE( pdt.outletState(1) == 0 );
791 REQUIRE( pdt.outletState(2) == 0 );
792 REQUIRE( pdt.outletState(3) == 2 );
793
794 //Verify channel state
795 REQUIRE( pdt.channelState("channel1") == 0 );
796 REQUIRE( pdt.channelState("channel2") == 0 );
797 REQUIRE( pdt.channelState("channel3") == 0 );
798 REQUIRE( pdt.channelState("channel4") == 2 );
799
800 //Turn off channel4
801 pdt.turnChannelOff("channel4");
802
803 //Verify outlet startup state
804 REQUIRE( pdt.outletState(0) == 0 );
805 REQUIRE( pdt.outletState(1) == 0 );
806 REQUIRE( pdt.outletState(2) == 0 );
807 REQUIRE( pdt.outletState(3) == 0 );
808
809 //Verify channel state at startup
810 REQUIRE( pdt.channelState("channel1") == 0 );
811 REQUIRE( pdt.channelState("channel2") == 0 );
812 REQUIRE( pdt.channelState("channel3") == 0 );
813 REQUIRE( pdt.channelState("channel4") == 0 );
814 }
815
816 WHEN("operating multiple channels")
817 {
818 //Turn on channel1&2
819 pdt.turnChannelOn("channel1");
820 pdt.turnChannelOn("channel2");
821
822 //Verify outlet state
823 REQUIRE( pdt.outletState(0) == 2 );
824 REQUIRE( pdt.outletState(1) == 2 );
825 REQUIRE( pdt.outletState(2) == 0 );
826 REQUIRE( pdt.outletState(3) == 0 );
827
828 //Verify channel state
829 REQUIRE( pdt.channelState("channel1") == 2 );
830 REQUIRE( pdt.channelState("channel2") == 2 );
831 REQUIRE( pdt.channelState("channel3") == 0 );
832 REQUIRE( pdt.channelState("channel4") == 0 );
833
834 //Turn off channel1&2
835 pdt.turnChannelOff("channel1");
836 pdt.turnChannelOff("channel2");
837
838 //Verify outlet state
839 REQUIRE( pdt.outletState(0) == 0 );
840 REQUIRE( pdt.outletState(1) == 0 );
841 REQUIRE( pdt.outletState(2) == 0 );
842 REQUIRE( pdt.outletState(3) == 0 );
843
844 //Verify channel state
845 REQUIRE( pdt.channelState("channel1") == 0 );
846 REQUIRE( pdt.channelState("channel2") == 0 );
847 REQUIRE( pdt.channelState("channel3") == 0 );
848 REQUIRE( pdt.channelState("channel4") == 0 );
849
850 //Turn on channel3&4
851 pdt.turnChannelOn("channel3");
852 pdt.turnChannelOn("channel4");
853
854 //Verify outlet state
855 REQUIRE( pdt.outletState(0) == 0 );
856 REQUIRE( pdt.outletState(1) == 0 );
857 REQUIRE( pdt.outletState(2) == 2 );
858 REQUIRE( pdt.outletState(3) == 2 );
859
860 //Verify channel state
861 REQUIRE( pdt.channelState("channel1") == 0 );
862 REQUIRE( pdt.channelState("channel2") == 0 );
863 REQUIRE( pdt.channelState("channel3") == 2 );
864 REQUIRE( pdt.channelState("channel4") == 2 );
865
866 //Turn off channel3&4
867 pdt.turnChannelOff("channel3");
868 pdt.turnChannelOff("channel4");
869
870 //Verify outlet state
871 REQUIRE( pdt.outletState(0) == 0 );
872 REQUIRE( pdt.outletState(1) == 0 );
873 REQUIRE( pdt.outletState(2) == 0 );
874 REQUIRE( pdt.outletState(3) == 0 );
875
876 //Verify channel state
877 REQUIRE( pdt.channelState("channel1") == 0 );
878 REQUIRE( pdt.channelState("channel2") == 0 );
879 REQUIRE( pdt.channelState("channel3") == 0 );
880 REQUIRE( pdt.channelState("channel4") == 0 );
881
882 //Turn on channel1&3
883 pdt.turnChannelOn("channel1");
884 pdt.turnChannelOn("channel3");
885
886 //Verify outlet state
887 REQUIRE( pdt.m_outletStates[0] == 2);
888 REQUIRE( pdt.outletState(0) == 2 );
889 REQUIRE( pdt.outletState(1) == 0 );
890 REQUIRE( pdt.outletState(2) == 2 );
891 REQUIRE( pdt.outletState(3) == 0 );
892
893 //Verify channel state
894 REQUIRE( pdt.channelState("channel1") == 2 );
895 REQUIRE( pdt.channelState("channel2") == 0 );
896 REQUIRE( pdt.channelState("channel3") == 2 );
897 REQUIRE( pdt.channelState("channel4") == 0 );
898
899 //Turn off channel1&3
900 pdt.turnChannelOff("channel1");
901 pdt.turnChannelOff("channel3");
902
903 //Verify outlet state
904 REQUIRE( pdt.outletState(0) == 0 );
905 REQUIRE( pdt.outletState(1) == 0 );
906 REQUIRE( pdt.outletState(2) == 0 );
907 REQUIRE( pdt.outletState(3) == 0 );
908
909 //Verify channel state
910 REQUIRE( pdt.channelState("channel1") == 0 );
911 REQUIRE( pdt.channelState("channel2") == 0 );
912 REQUIRE( pdt.channelState("channel3") == 0 );
913 REQUIRE( pdt.channelState("channel4") == 0 );
914
915 //Turn on channel2&4
916 pdt.turnChannelOn("channel2");
917 pdt.turnChannelOn("channel4");
918
919 //Verify outlet state
920 REQUIRE( pdt.outletState(0) == 0 );
921 REQUIRE( pdt.outletState(1) == 2 );
922 REQUIRE( pdt.outletState(2) == 0 );
923 REQUIRE( pdt.outletState(3) == 2 );
924
925 //Verify channel state
926 REQUIRE( pdt.channelState("channel1") == 0 );
927 REQUIRE( pdt.channelState("channel2") == 2 );
928 REQUIRE( pdt.channelState("channel3") == 0 );
929 REQUIRE( pdt.channelState("channel4") == 2 );
930
931 //Turn off channel2&4
932 pdt.turnChannelOff("channel2");
933 pdt.turnChannelOff("channel4");
934
935 //Verify outlet startup state
936 REQUIRE( pdt.outletState(0) == 0 );
937 REQUIRE( pdt.outletState(1) == 0 );
938 REQUIRE( pdt.outletState(2) == 0 );
939 REQUIRE( pdt.outletState(3) == 0 );
940
941 //Verify channel state at startup
942 REQUIRE( pdt.channelState("channel1") == 0 );
943 REQUIRE( pdt.channelState("channel2") == 0 );
944 REQUIRE( pdt.channelState("channel3") == 0 );
945 REQUIRE( pdt.channelState("channel4") == 0 );
946 }
947
948 WHEN("outlets intermediate")
949 {
950 pdt.m_outletStates[0] = 1;
951
952 //Verify outlet state
953 REQUIRE( pdt.outletState(0) == 1 );
954 REQUIRE( pdt.outletState(1) == 0 );
955 REQUIRE( pdt.outletState(2) == 0 );
956 REQUIRE( pdt.outletState(3) == 0 );
957
958 //Verify channel state
959 REQUIRE( pdt.channelState("channel1") == 1 );
960 REQUIRE( pdt.channelState("channel2") == 0 );
961 REQUIRE( pdt.channelState("channel3") == 0 );
962 REQUIRE( pdt.channelState("channel4") == 0 );
963
964 pdt.m_outletStates[0] = 0;
965
966 pdt.m_outletStates[1] = 1;
967
968 //Verify outlet state
969 REQUIRE( pdt.outletState(0) == 0 );
970 REQUIRE( pdt.outletState(1) == 1 );
971 REQUIRE( pdt.outletState(2) == 0 );
972 REQUIRE( pdt.outletState(3) == 0 );
973
974 //Verify channel state
975 REQUIRE( pdt.channelState("channel1") == 0 );
976 REQUIRE( pdt.channelState("channel2") == 1 );
977 REQUIRE( pdt.channelState("channel3") == 0 );
978 REQUIRE( pdt.channelState("channel4") == 0 );
979
980 pdt.m_outletStates[1] = 0;
981
982 pdt.m_outletStates[2] = 1;
983
984 //Verify outlet state
985 REQUIRE( pdt.outletState(0) == 0 );
986 REQUIRE( pdt.outletState(1) == 0 );
987 REQUIRE( pdt.outletState(2) == 1 );
988 REQUIRE( pdt.outletState(3) == 0 );
989
990 //Verify channel state
991 REQUIRE( pdt.channelState("channel1") == 0 );
992 REQUIRE( pdt.channelState("channel2") == 0 );
993 REQUIRE( pdt.channelState("channel3") == 1 );
994 REQUIRE( pdt.channelState("channel4") == 0 );
995
996 pdt.m_outletStates[2] = 0;
997
998 pdt.m_outletStates[3] = 1;
999
1000 //Verify outlet state
1001 REQUIRE( pdt.outletState(0) == 0 );
1002 REQUIRE( pdt.outletState(1) == 0 );
1003 REQUIRE( pdt.outletState(2) == 0 );
1004 REQUIRE( pdt.outletState(3) == 1 );
1005
1006 //Verify channel state
1007 REQUIRE( pdt.channelState("channel1") == 0 );
1008 REQUIRE( pdt.channelState("channel2") == 0 );
1009 REQUIRE( pdt.channelState("channel3") == 0 );
1010 REQUIRE( pdt.channelState("channel4") == 1 );
1011
1012 pdt.m_outletStates[3] = 0;
1013 }
1014
1015 }
1016
1017 GIVEN("a config file with 2 channels for 4 outlets, only outlet specified")
1018 {
1019 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel2" },
1020 {"outlet", "outlet" },
1021 {"0,1", "2,3" } );
1022
1023 mx::app::appConfigurator config;
1024 config.readConfig("/tmp/outletController_test.conf");
1025
1027 pdt.setupConfig(config);
1028 pdt.loadConfig(config);
1029
1030 WHEN("test device startup outlet states")
1031 {
1032 //Verify outlet startup state
1033 REQUIRE( pdt.outletState(0) == 0 );
1034 REQUIRE( pdt.outletState(1) == 0 );
1035 REQUIRE( pdt.outletState(2) == 0 );
1036 REQUIRE( pdt.outletState(3) == 0 );
1037
1038 //Verify channel state at startup
1039 REQUIRE( pdt.channelState("channel1") == 0 );
1040 REQUIRE( pdt.channelState("channel2") == 0 );
1041 }
1042 WHEN("operating a single channel")
1043 {
1044 //Turn on channel1
1045 pdt.turnChannelOn("channel1");
1046
1047 //Verify outlet state
1048 REQUIRE( pdt.outletState(0) == 2 );
1049 REQUIRE( pdt.outletState(1) == 2 );
1050 REQUIRE( pdt.outletState(2) == 0 );
1051 REQUIRE( pdt.outletState(3) == 0 );
1052
1053 //verify outlet order
1054 REQUIRE( pdt.m_timestamps[1] > pdt.m_timestamps[0]);
1055
1056 //Verify channel state
1057 REQUIRE( pdt.channelState("channel1") == 2 );
1058 REQUIRE( pdt.channelState("channel2") == 0 );
1059
1060 //Turn off channel1
1061 pdt.turnChannelOff("channel1");
1062
1063 //Verify outlet state
1064 REQUIRE( pdt.outletState(0) == 0 );
1065 REQUIRE( pdt.outletState(1) == 0 );
1066 REQUIRE( pdt.outletState(2) == 0 );
1067 REQUIRE( pdt.outletState(3) == 0 );
1068
1069 //Verify channel state
1070 REQUIRE( pdt.channelState("channel1") == 0 );
1071 REQUIRE( pdt.channelState("channel2") == 0 );
1072
1073 //Turn on channel2
1074 pdt.turnChannelOn("channel2");
1075
1076 //Verify outlet state
1077 REQUIRE( pdt.outletState(0) == 0 );
1078 REQUIRE( pdt.outletState(1) == 0 );
1079 REQUIRE( pdt.outletState(2) == 2 );
1080 REQUIRE( pdt.outletState(3) == 2 );
1081
1082 //verify outlet order
1083 REQUIRE( pdt.m_timestamps[3] > pdt.m_timestamps[2]);
1084
1085 //Verify channel state
1086 REQUIRE( pdt.channelState("channel1") == 0 );
1087 REQUIRE( pdt.channelState("channel2") == 2 );
1088
1089 //Turn off channel2
1090 pdt.turnChannelOff("channel2");
1091
1092 //Verify outlet state
1093 REQUIRE( pdt.outletState(0) == 0 );
1094 REQUIRE( pdt.outletState(1) == 0 );
1095 REQUIRE( pdt.outletState(2) == 0 );
1096 REQUIRE( pdt.outletState(3) == 0 );
1097
1098 //Verify channel state
1099 REQUIRE( pdt.channelState("channel1") == 0 );
1100 REQUIRE( pdt.channelState("channel2") == 0 );
1101 }
1102 WHEN("operating two channels")
1103 {
1104 //Turn on channels
1105 pdt.turnChannelOn("channel1");
1106 pdt.turnChannelOn("channel2");
1107
1108 //Verify outlet state
1109 REQUIRE( pdt.outletState(0) == 2 );
1110 REQUIRE( pdt.outletState(1) == 2 );
1111 REQUIRE( pdt.outletState(2) == 2 );
1112 REQUIRE( pdt.outletState(3) == 2 );
1113
1114 //Verify channel state
1115 REQUIRE( pdt.channelState("channel1") == 2 );
1116 REQUIRE( pdt.channelState("channel2") == 2 );
1117
1118 //Turn off channel1&2
1119 pdt.turnChannelOff("channel1");
1120 pdt.turnChannelOff("channel2");
1121
1122 //Verify outlet state
1123 REQUIRE( pdt.outletState(0) == 0 );
1124 REQUIRE( pdt.outletState(1) == 0 );
1125 REQUIRE( pdt.outletState(2) == 0 );
1126 REQUIRE( pdt.outletState(3) == 0 );
1127
1128 //Verify channel state
1129 REQUIRE( pdt.channelState("channel1") == 0 );
1130 REQUIRE( pdt.channelState("channel2") == 0 );
1131
1132 }
1133 WHEN("outlets intermediate")
1134 {
1135 pdt.m_outletStates[0] = 2;
1136
1137 //Verify outlet state
1138 REQUIRE( pdt.outletState(0) == 2 );
1139 REQUIRE( pdt.outletState(1) == 0 );
1140 REQUIRE( pdt.outletState(2) == 0 );
1141 REQUIRE( pdt.outletState(3) == 0 );
1142
1143 REQUIRE( pdt.channelState("channel1") == 1);
1144 REQUIRE( pdt.channelState("channel2") == 0);
1145
1146 pdt.turnChannelOn("channel2");
1147
1148 //Verify outlet state
1149 REQUIRE( pdt.outletState(0) == 2 );
1150 REQUIRE( pdt.outletState(1) == 0 );
1151 REQUIRE( pdt.outletState(2) == 2 );
1152 REQUIRE( pdt.outletState(3) == 2 );
1153
1154 REQUIRE( pdt.channelState("channel1") == 1);
1155 REQUIRE( pdt.channelState("channel2") == 2);
1156
1157 pdt.m_outletStates[0] = 0;
1158
1159 REQUIRE( pdt.channelState("channel1") == 0);
1160 REQUIRE( pdt.channelState("channel2") == 2);
1161
1162 pdt.turnChannelOff("channel2");
1163
1164 //Verify outlet state
1165 REQUIRE( pdt.outletState(0) == 0 );
1166 REQUIRE( pdt.outletState(1) == 0 );
1167 REQUIRE( pdt.outletState(2) == 0 );
1168 REQUIRE( pdt.outletState(3) == 0 );
1169
1170 REQUIRE( pdt.channelState("channel1") == 0);
1171 REQUIRE( pdt.channelState("channel2") == 0);
1172
1173
1174 pdt.m_outletStates[2] = 1;
1175
1176 //Verify outlet state
1177 REQUIRE( pdt.outletState(0) == 0 );
1178 REQUIRE( pdt.outletState(1) == 0 );
1179 REQUIRE( pdt.outletState(2) == 1 );
1180 REQUIRE( pdt.outletState(3) == 0 );
1181
1182 REQUIRE( pdt.channelState("channel1") == 0);
1183 REQUIRE( pdt.channelState("channel2") == 1);
1184
1185 pdt.turnChannelOn("channel1");
1186
1187 //Verify outlet state
1188 REQUIRE( pdt.outletState(0) == 2 );
1189 REQUIRE( pdt.outletState(1) == 2 );
1190 REQUIRE( pdt.outletState(2) == 1 );
1191 REQUIRE( pdt.outletState(3) == 0 );
1192
1193 REQUIRE( pdt.channelState("channel1") == 2);
1194 REQUIRE( pdt.channelState("channel2") == 1);
1195
1196 pdt.m_outletStates[2] = 0;
1197
1198 REQUIRE( pdt.channelState("channel1") == 2);
1199 REQUIRE( pdt.channelState("channel2") == 0);
1200
1201 pdt.turnChannelOff("channel1");
1202
1203 //Verify outlet state
1204 REQUIRE( pdt.outletState(0) == 0 );
1205 REQUIRE( pdt.outletState(1) == 0 );
1206 REQUIRE( pdt.outletState(2) == 0 );
1207 REQUIRE( pdt.outletState(3) == 0 );
1208
1209 REQUIRE( pdt.channelState("channel1") == 0);
1210 REQUIRE( pdt.channelState("channel2") == 0);
1211 }
1212 }
1213 GIVEN("a config file with 2 channels for 4 outlets, onOrder specified")
1214 {
1215 //Here we are just testing order, so we don't need to verify outlet state anymore
1216
1217 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel2", "channel2" },
1218 {"outlet", "onOrder", "outlet", "onOrder" },
1219 {"0,1", "0,1", "2,3", "0,1" } );
1220
1221 mx::app::appConfigurator config;
1222 config.readConfig("/tmp/outletController_test.conf");
1223
1225 pdt.setupConfig(config);
1226 pdt.loadConfig(config);
1227
1228 WHEN("test device startup channel states")
1229 {
1230 //Verify channel state at startup
1231 REQUIRE( pdt.channelState("channel1") == 0 );
1232 REQUIRE( pdt.channelState("channel2") == 0 );
1233 }
1234 WHEN("operating a single channel")
1235 {
1236 //Turn on channel1
1237 pdt.turnChannelOn("channel1");
1238
1239 //verify outlet order
1240 REQUIRE( pdt.m_timestamps[1] > pdt.m_timestamps[0]);
1241
1242 //Verify channel state
1243 REQUIRE( pdt.channelState("channel1") == 2 );
1244 REQUIRE( pdt.channelState("channel2") == 0 );
1245
1246 //Turn off channel1
1247 pdt.turnChannelOff("channel1");
1248
1249 //Verify channel state
1250 REQUIRE( pdt.channelState("channel1") == 0 );
1251 REQUIRE( pdt.channelState("channel2") == 0 );
1252
1253 //Turn on channel2
1254 pdt.turnChannelOn("channel2");
1255
1256 //verify outlet order
1257 REQUIRE( pdt.m_timestamps[3] > pdt.m_timestamps[2]);
1258
1259 //Verify channel state
1260 REQUIRE( pdt.channelState("channel1") == 0 );
1261 REQUIRE( pdt.channelState("channel2") == 2 );
1262
1263 //Turn off channel2
1264 pdt.turnChannelOff("channel2");
1265
1266 //Verify channel state
1267 REQUIRE( pdt.channelState("channel1") == 0 );
1268 REQUIRE( pdt.channelState("channel2") == 0 );
1269 }
1270 }
1271 GIVEN("a config file with 2 channels for 4 outlets, onOrder reversed")
1272 {
1273 //Here we are just testing order, so we don't need to verify outlet state anymore
1274
1275 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel2", "channel2" },
1276 {"outlet", "onOrder", "outlet", "onOrder" },
1277 {"0,1", "1,0", "2,3", "1,0" } );
1278
1279 mx::app::appConfigurator config;
1280 config.readConfig("/tmp/outletController_test.conf");
1281
1283 pdt.setupConfig(config);
1284 pdt.loadConfig(config);
1285
1286 WHEN("test device startup channel states")
1287 {
1288 //Verify channel state at startup
1289 REQUIRE( pdt.channelState("channel1") == 0 );
1290 REQUIRE( pdt.channelState("channel2") == 0 );
1291 }
1292 WHEN("operating a single channel")
1293 {
1294 //Turn on channel1
1295 pdt.turnChannelOn("channel1");
1296
1297 //verify outlet order
1298 REQUIRE( pdt.m_timestamps[0] > pdt.m_timestamps[1]);
1299
1300 //Verify channel state
1301 REQUIRE( pdt.channelState("channel1") == 2 );
1302 REQUIRE( pdt.channelState("channel2") == 0 );
1303
1304 //Turn off channel1
1305 pdt.turnChannelOff("channel1");
1306
1307 //Verify channel state
1308 REQUIRE( pdt.channelState("channel1") == 0 );
1309 REQUIRE( pdt.channelState("channel2") == 0 );
1310
1311 //Turn on channel2
1312 pdt.turnChannelOn("channel2");
1313
1314 //verify outlet order
1315 REQUIRE( pdt.m_timestamps[2] > pdt.m_timestamps[3]);
1316
1317 //Verify channel state
1318 REQUIRE( pdt.channelState("channel1") == 0 );
1319 REQUIRE( pdt.channelState("channel2") == 2 );
1320
1321 //Turn off channel2
1322 pdt.turnChannelOff("channel2");
1323
1324 //Verify channel state
1325 REQUIRE( pdt.channelState("channel1") == 0 );
1326 REQUIRE( pdt.channelState("channel2") == 0 );
1327 }
1328 }
1329 GIVEN("a config file with 2 channels for 4 outlets, onOrder and offOrder specified, the same")
1330 {
1331 //Here we are just testing order, so we don't need to verify outlet state anymore
1332
1333 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel1", "channel2", "channel2", "channel2" },
1334 {"outlet", "onOrder", "offOrder", "outlet", "onOrder", "offOrder" },
1335 {"0,1", "0,1", "0,1", "2,3", "0,1" , "0,1" } );
1336
1337 mx::app::appConfigurator config;
1338 config.readConfig("/tmp/outletController_test.conf");
1339
1341 pdt.setupConfig(config);
1342 pdt.loadConfig(config);
1343
1344 WHEN("test device startup channel states")
1345 {
1346 //Verify channel state at startup
1347 REQUIRE( pdt.channelState("channel1") == 0 );
1348 REQUIRE( pdt.channelState("channel2") == 0 );
1349 }
1350 WHEN("operating a single channel")
1351 {
1352 //Turn on channel1
1353 pdt.turnChannelOn("channel1");
1354
1355 //verify outlet order
1356 REQUIRE( pdt.m_timestamps[1] > pdt.m_timestamps[0]);
1357
1358 //Verify channel state
1359 REQUIRE( pdt.channelState("channel1") == 2 );
1360 REQUIRE( pdt.channelState("channel2") == 0 );
1361
1362 //Turn off channel1
1363 pdt.turnChannelOff("channel1");
1364
1365 //verify outlet order
1366 REQUIRE( pdt.m_timestamps[1] > pdt.m_timestamps[0]);
1367
1368 //Verify channel state
1369 REQUIRE( pdt.channelState("channel1") == 0 );
1370 REQUIRE( pdt.channelState("channel2") == 0 );
1371
1372 //Turn on channel2
1373 pdt.turnChannelOn("channel2");
1374
1375 //verify outlet order
1376 REQUIRE( pdt.m_timestamps[3] > pdt.m_timestamps[2]);
1377
1378 //Verify channel state
1379 REQUIRE( pdt.channelState("channel1") == 0 );
1380 REQUIRE( pdt.channelState("channel2") == 2 );
1381
1382 //Turn off channel2
1383 pdt.turnChannelOff("channel2");
1384
1385 REQUIRE( pdt.m_timestamps[3] >= pdt.m_timestamps[2]);
1386
1387 //Verify channel state
1388 REQUIRE( pdt.channelState("channel1") == 0 );
1389 REQUIRE( pdt.channelState("channel2") == 0 );
1390 }
1391 }
1392 GIVEN("a config file with 2 channels for 4 outlets, onOrder and offOrder specified, different")
1393 {
1394 //Here we are just testing order, so we don't need to verify outlet state anymore
1395
1396 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel1", "channel2", "channel2", "channel2" },
1397 {"outlet", "onOrder", "offOrder", "outlet", "onOrder", "offOrder" },
1398 {"0,1", "0,1", "1,0", "2,3", "0,1" , "1,0" } );
1399
1400 mx::app::appConfigurator config;
1401 config.readConfig("/tmp/outletController_test.conf");
1402
1404 pdt.setupConfig(config);
1405 pdt.loadConfig(config);
1406
1407 WHEN("test device startup channel states")
1408 {
1409 //Verify channel state at startup
1410 REQUIRE( pdt.channelState("channel1") == 0 );
1411 REQUIRE( pdt.channelState("channel2") == 0 );
1412 }
1413 WHEN("operating a single channel")
1414 {
1415 //Turn on channel1
1416 pdt.turnChannelOn("channel1");
1417
1418 //verify outlet order
1419 REQUIRE( pdt.m_timestamps[1] > pdt.m_timestamps[0]);
1420
1421 //Verify channel state
1422 REQUIRE( pdt.channelState("channel1") == 2 );
1423 REQUIRE( pdt.channelState("channel2") == 0 );
1424
1425
1426 //Turn off channel1
1427 pdt.turnChannelOff("channel1");
1428
1429 //verify outlet order
1430 REQUIRE( pdt.m_timestamps[0] > pdt.m_timestamps[1]);
1431
1432 //Verify channel state
1433 REQUIRE( pdt.channelState("channel1") == 0 );
1434 REQUIRE( pdt.channelState("channel2") == 0 );
1435
1436 //Turn on channel2
1437 pdt.turnChannelOn("channel2");
1438
1439
1440 //verify outlet order
1441 REQUIRE( pdt.m_timestamps[3] > pdt.m_timestamps[2]);
1442
1443 //Verify channel state
1444 REQUIRE( pdt.channelState("channel1") == 0 );
1445 REQUIRE( pdt.channelState("channel2") == 2 );
1446
1447 //Turn off channel2
1448 pdt.turnChannelOff("channel2");
1449
1450 //verify outlet order
1451 REQUIRE( pdt.m_timestamps[2] > pdt.m_timestamps[3]);
1452
1453 //Verify channel state
1454 REQUIRE( pdt.channelState("channel1") == 0 );
1455 REQUIRE( pdt.channelState("channel2") == 0 );
1456 }
1457 }
1458 GIVEN("a config file with 2 channels for 4 outlets, onOrder and offOrder specified, different, reversed")
1459 {
1460 //Here we are just testing order, so we don't need to verify outlet state anymore
1461
1462 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel1", "channel2", "channel2", "channel2" },
1463 {"outlet", "onOrder", "offOrder", "outlet", "onOrder", "offOrder" },
1464 {"0,1", "1,0", "0,1", "2,3", "1,0" , "0,1" } );
1465
1466 mx::app::appConfigurator config;
1467 config.readConfig("/tmp/outletController_test.conf");
1468
1470 pdt.setupConfig(config);
1471 pdt.loadConfig(config);
1472
1473 WHEN("test device startup channel states")
1474 {
1475 //Verify channel state at startup
1476 REQUIRE( pdt.channelState("channel1") == 0 );
1477 REQUIRE( pdt.channelState("channel2") == 0 );
1478 }
1479 WHEN("operating a single channel")
1480 {
1481 //Turn on channel1
1482 pdt.turnChannelOn("channel1");
1483
1484 //verify outlet order
1485 REQUIRE( pdt.m_timestamps[0] > pdt.m_timestamps[1]);
1486
1487 //Verify channel state
1488 REQUIRE( pdt.channelState("channel1") == 2 );
1489 REQUIRE( pdt.channelState("channel2") == 0 );
1490
1491
1492 //Turn off channel1
1493 pdt.turnChannelOff("channel1");
1494
1495 //verify outlet order
1496 REQUIRE( pdt.m_timestamps[1] > pdt.m_timestamps[0]);
1497
1498 //Verify channel state
1499 REQUIRE( pdt.channelState("channel1") == 0 );
1500 REQUIRE( pdt.channelState("channel2") == 0 );
1501
1502 //Turn on channel2
1503 pdt.turnChannelOn("channel2");
1504
1505
1506 //verify outlet order
1507 REQUIRE( pdt.m_timestamps[2] > pdt.m_timestamps[3]);
1508
1509 //Verify channel state
1510 REQUIRE( pdt.channelState("channel1") == 0 );
1511 REQUIRE( pdt.channelState("channel2") == 2 );
1512
1513 //Turn off channel2
1514 pdt.turnChannelOff("channel2");
1515
1516 //verify outlet order
1517 REQUIRE( pdt.m_timestamps[3] > pdt.m_timestamps[2]);
1518
1519 //Verify channel state
1520 REQUIRE( pdt.channelState("channel1") == 0 );
1521 REQUIRE( pdt.channelState("channel2") == 0 );
1522 }
1523 }
1524}
1525
1526SCENARIO( "outletController Operation with delays", "[outletController]" )
1527{
1528 std::cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1529 std::cout << "[outletController] Testing delays ... \n";
1530 GIVEN("a config file with 2 channels for 4 outlets, onDelays specified")
1531 {
1532 //Here we are just testing delays, so we don't need to verify outlet state anymore
1533
1534 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel2", "channel2" },
1535 {"outlet", "onDelays", "outlet", "onDelays" },
1536 {"0,1", "0,350", "2,3", "0,150" } );
1537
1538 mx::app::appConfigurator config;
1539 config.readConfig("/tmp/outletController_test.conf");
1540
1542 pdt.setupConfig(config);
1543 pdt.loadConfig(config);
1544
1545 WHEN("operating a single channel")
1546 {
1547 //Turn on channel1
1548 pdt.turnChannelOn("channel1");
1549
1550 //verify outlet delay
1551 REQUIRE( pdt.m_timestamps[1] >= Approx(pdt.m_timestamps[0]+0.350));
1552 std::cout << "Ch1 On Delay was " << (pdt.m_timestamps[1] - pdt.m_timestamps[0])*1000 << " msec, expected 350.\n";
1553
1554 //Verify channel state
1555 REQUIRE( pdt.channelState("channel1") == 2 );
1556 REQUIRE( pdt.channelState("channel2") == 0 );
1557
1558 //Turn off channel1
1559 pdt.turnChannelOff("channel1");
1560 std::cout << "Ch1 Off Delay was " << (pdt.m_timestamps[1] - pdt.m_timestamps[0])*1000 << " msec, expected ~0.\n";
1561
1562 //Verify channel state
1563 REQUIRE( pdt.channelState("channel1") == 0 );
1564 REQUIRE( pdt.channelState("channel2") == 0 );
1565
1566 //Turn on channel2
1567 pdt.turnChannelOn("channel2");
1568
1569
1570 //verify outlet delay
1571 REQUIRE( pdt.m_timestamps[3] >= Approx(pdt.m_timestamps[2]+0.150));
1572 std::cout << "Ch2 On Delay was " << (pdt.m_timestamps[3] - pdt.m_timestamps[2])*1000 << " msec, expected 150.\n";
1573
1574 //Verify channel state
1575 REQUIRE( pdt.channelState("channel1") == 0 );
1576 REQUIRE( pdt.channelState("channel2") == 2 );
1577
1578 //Turn off channel2
1579 pdt.turnChannelOff("channel2");
1580 std::cout << "Ch2 Off Delay was " << (pdt.m_timestamps[3] - pdt.m_timestamps[2])*1000 << " msec, expected ~0.\n";
1581
1582 //Verify channel state
1583 REQUIRE( pdt.channelState("channel1") == 0 );
1584 REQUIRE( pdt.channelState("channel2") == 0 );
1585 }
1586 }
1587 GIVEN("a config file with 2 channels for 4 outlets, offDelays specified")
1588 {
1589 //Here we are just testing delays, so we don't need to verify outlet state anymore
1590
1591 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel2", "channel2" },
1592 {"outlet", "offDelays", "outlet", "offDelays" },
1593 {"0,1", "0,550", "2,3", "0,750" } );
1594
1595 mx::app::appConfigurator config;
1596 config.readConfig("/tmp/outletController_test.conf");
1597
1599 pdt.setupConfig(config);
1600 pdt.loadConfig(config);
1601
1602 WHEN("operating a single channel")
1603 {
1604 //Turn on channel1
1605 pdt.turnChannelOn("channel1");
1606
1607 std::cout << "Ch1 On Delay was " << (pdt.m_timestamps[1] - pdt.m_timestamps[0])*1000 << " msec, expected ~0.\n";
1608
1609 //Verify channel state
1610 REQUIRE( pdt.channelState("channel1") == 2 );
1611 REQUIRE( pdt.channelState("channel2") == 0 );
1612
1613 //Turn off channel1
1614 pdt.turnChannelOff("channel1");
1615
1616 REQUIRE( pdt.m_timestamps[1] >= Approx(pdt.m_timestamps[0]+0.550));
1617 std::cout << "Ch1 Off Delay was " << (pdt.m_timestamps[1] - pdt.m_timestamps[0])*1000 << " msec, expected 550.\n";
1618
1619
1620 //Verify channel state
1621 REQUIRE( pdt.channelState("channel1") == 0 );
1622 REQUIRE( pdt.channelState("channel2") == 0 );
1623
1624 //Turn on channel2
1625 pdt.turnChannelOn("channel2");
1626
1627
1628 //verify outlet delay
1629 std::cout << "Ch1 On Delay was " << (pdt.m_timestamps[3] - pdt.m_timestamps[2])*1000 << " msec, expected ~0.\n";
1630
1631 //Verify channel state
1632 REQUIRE( pdt.channelState("channel1") == 0 );
1633 REQUIRE( pdt.channelState("channel2") == 2 );
1634
1635 //Turn off channel2
1636 pdt.turnChannelOff("channel2");
1637 REQUIRE( pdt.m_timestamps[3] >= Approx(pdt.m_timestamps[2]+0.750));
1638 std::cout << "Ch1 On Delay was " << (pdt.m_timestamps[3] - pdt.m_timestamps[2])*1000 << " msec, expected 750.\n";
1639
1640 //Verify channel state
1641 REQUIRE( pdt.channelState("channel1") == 0 );
1642 REQUIRE( pdt.channelState("channel2") == 0 );
1643 }
1644 }
1645 GIVEN("a config file with 2 channels for 4 outlets, onDelays and offDelays specified, off order reversed")
1646 {
1647 //Here we are just testing delays, so we don't need to verify outlet state anymore
1648
1649 mx::app::writeConfigFile( "/tmp/outletController_test.conf", {"channel1", "channel1", "channel1", "channel1", "channel1", "channel2", "channel2", "channel2", "channel2", "channel2" },
1650 {"outlet", "onOrder", "onDelays", "offOrder", "offDelays", "outlet", "onOrder", "onDelays", "offOrder", "offDelays" },
1651 {"0,1", "0,1", "0,350", "1,0", "0,450", "2,3", "0,1", "0,150", "1,0", "0,75" } );
1652
1653 mx::app::appConfigurator config;
1654 config.readConfig("/tmp/outletController_test.conf");
1655
1657 pdt.setupConfig(config);
1658 pdt.loadConfig(config);
1659
1660 WHEN("operating a single channel")
1661 {
1662 //Turn on channel1
1663 pdt.turnChannelOn("channel1");
1664
1665 //verify outlet delay
1666 REQUIRE( pdt.m_timestamps[1] >= Approx(pdt.m_timestamps[0]+0.350));
1667 std::cout << "Ch1 On Delay was " << (pdt.m_timestamps[1] - pdt.m_timestamps[0])*1000 << " msec, expected 350.\n";
1668
1669 //Verify channel state
1670 REQUIRE( pdt.channelState("channel1") == 2 );
1671 REQUIRE( pdt.channelState("channel2") == 0 );
1672
1673 //Turn off channel1
1674 pdt.turnChannelOff("channel1");
1675 REQUIRE( pdt.m_timestamps[0] >= Approx(pdt.m_timestamps[1]+0.450));
1676 std::cout << "Ch1 Off Delay was " << (pdt.m_timestamps[0] - pdt.m_timestamps[1])*1000 << " msec, expected 450.\n";
1677
1678 //Verify channel state
1679 REQUIRE( pdt.channelState("channel1") == 0 );
1680 REQUIRE( pdt.channelState("channel2") == 0 );
1681
1682 //Turn on channel2
1683 pdt.turnChannelOn("channel2");
1684
1685
1686 //verify outlet delay
1687 REQUIRE( pdt.m_timestamps[3] >= Approx(pdt.m_timestamps[2]+0.150));
1688 std::cout << "Ch2 On Delay was " << (pdt.m_timestamps[3] - pdt.m_timestamps[2])*1000 << " msec, expected 150.\n";
1689
1690 //Verify channel state
1691 REQUIRE( pdt.channelState("channel1") == 0 );
1692 REQUIRE( pdt.channelState("channel2") == 2 );
1693
1694 //Turn off channel2
1695 pdt.turnChannelOff("channel2");
1696 REQUIRE( pdt.m_timestamps[2] >= Approx(pdt.m_timestamps[3]+0.075));
1697 std::cout << "Ch2 Off Delay was " << (pdt.m_timestamps[2] - pdt.m_timestamps[3])*1000 << " msec, expected 75.\n";
1698
1699 //Verify channel state
1700 REQUIRE( pdt.channelState("channel1") == 0 );
1701 REQUIRE( pdt.channelState("channel2") == 0 );
1702 }
1703 }
1704 std::cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1705}
1706
1707} //namespace outletController_tests
The base-class for XWCTk applications.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
SCENARIO("outletController Configuration", "[outletController]")
outletController Configuration
Definition dm.hpp:19
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.
int loadConfig(mx::app::appConfigurator &config)
int setupConfig(mx::app::appConfigurator &config)
int appLogic()
This is where derived applications implement their main FSM logic.
int appShutdown()
Any tasks to perform after main loop exit go here.
int appStartup()
Any tasks to perform prior to the main event loop go here.