Looper: extend test coverage

This commit is contained in:
Fischlurch 2016-12-16 20:38:00 +01:00
parent 30254da95f
commit 8ee08905b3
2 changed files with 133 additions and 0 deletions

View file

@ -110,6 +110,12 @@ namespace control {
shutdown_ = true;
}
void
enableProcessing(bool yes =true)
{
disabled_ = not yes;
}
/** state fusion to control (timed) wait */
bool
requireAction()

View file

@ -91,6 +91,8 @@ namespace test {
verifyBasics();
verifyShutdown();
verifyWakeupActivity();
verifyShutdown_stops_processing();
verifyDisabling_stops_processing();
}
@ -152,6 +154,131 @@ namespace test {
CHECK ( looper.isIdle());
CHECK (looper.shallLoop());
}
void
verifyShutdown_stops_processing()
{
Setup setup;
Looper looper = setup.install();
CHECK (not looper.isDying());
CHECK (looper.shallLoop());
CHECK (not looper.requireAction());
CHECK (not looper.isWorking());
CHECK ( looper.isIdle());
setup.has_commands_in_queue = true;
CHECK ( looper.requireAction());
CHECK ( looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
looper.triggerShutdown();
CHECK ( looper.requireAction());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK (not looper.shallLoop());
CHECK ( looper.isDying());
setup.has_commands_in_queue = false;
CHECK ( looper.requireAction());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK (not looper.shallLoop());
CHECK ( looper.isDying());
setup.has_commands_in_queue = true;
CHECK ( looper.requireAction());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK (not looper.shallLoop());
CHECK ( looper.isDying());
}
void
verifyDisabling_stops_processing()
{
Setup setup;
Looper looper = setup.install();
CHECK (not looper.requireAction());
CHECK (not looper.isDisabled());
CHECK (not looper.isWorking());
CHECK ( looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
setup.has_commands_in_queue = true; // normal operation: pending commands will be processed
CHECK ( looper.requireAction()); // ..causes wake-up
CHECK (not looper.isDisabled());
CHECK ( looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
looper.enableProcessing(false); // disable processing
CHECK (not looper.requireAction());
CHECK ( looper.isDisabled());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
setup.has_commands_in_queue = false; // while disabled, state of the command queue has no effect
CHECK (not looper.requireAction());
CHECK ( looper.isDisabled());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
setup.has_commands_in_queue = true;
CHECK (not looper.requireAction());
CHECK ( looper.isDisabled());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
looper.enableProcessing(); // resume normal operation
CHECK ( looper.requireAction());
CHECK (not looper.isDisabled());
CHECK ( looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
looper.enableProcessing(false); // disable again
CHECK (not looper.requireAction());
CHECK ( looper.isDisabled());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK ( looper.shallLoop());
CHECK (not looper.isDying());
looper.triggerShutdown(); // wake-up for shutdown even from disabled state
CHECK ( looper.requireAction());
CHECK ( looper.isDisabled());
CHECK (not looper.isWorking());
CHECK (not looper.isIdle());
CHECK (not looper.shallLoop());
CHECK ( looper.isDying());
}
};