From 2d5ef968a87dea1664e41e86fcfb6c8c6b395585 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 13 Jan 2017 06:13:22 +0100 Subject: [PATCH] CommandFramework: fill in a simplified function(integration) test Start the ProcDispatcher and schedule a command into the session loop thread --- tests/core/proc/control/command-use2-test.cpp | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/core/proc/control/command-use2-test.cpp b/tests/core/proc/control/command-use2-test.cpp index a63092b53..7f82cd23c 100644 --- a/tests/core/proc/control/command-use2-test.cpp +++ b/tests/core/proc/control/command-use2-test.cpp @@ -32,6 +32,12 @@ #include "proc/control/test-dummy-commands.hpp" +extern "C" { +#include "common/interfaceregistry.h" +} +#include "proc/control/proc-dispatcher.hpp" +#include "include/session-command-facade.h" + #include #include #include @@ -201,10 +207,55 @@ namespace test { + /** @test simplified integration test of command dispatch + * - performs the minimal actions necessary to start the session loop thread + * - then issues a test command, which will be queued and dispatched + * by the ProcDispatcher. Like in the real application, the command + * executions happens in the dedicated session loop thread, and thus + * we have to wait a moment, after which execution can be verified. + * - finally the ProcDispatcher is signalled to shut down. + * @see SessionCommandFunction_test for much more in-depth coverage of this aspect + */ void check_DispatcherInvocation() { - UNIMPLEMENTED("start the dispatcher and enqueue a rigged special command"); /////////////////////////////TICKET #209 + CHECK (not ProcDispatcher::instance().isRunning()); + lumiera_interfaceregistry_init(); + lumiera::throwOnError(); +#define __DELAY__ usleep(10000); + + bool thread_has_ended{false}; + ProcDispatcher::instance().start ([&] (string*) { thread_has_ended = true; }); + + CHECK (ProcDispatcher::instance().isRunning()); + CHECK (not thread_has_ended); + + //----Session-Loop-Thread-is-running------------------------ + + string cmdID {"test.command2"}; + string prevExecLog = command2::check_.str(); + + // previous test cases prepared the arguments + // so that we can just trigger command execution. + // In the real application, this call is issued + // from CoreService when receiving a command + // invocation message over the UI-Bus + SessionCommand::facade().invoke(cmdID); + + __DELAY__ // wait a moment for the other thread to dispatch the command... + CHECK (prevExecLog != command2::check_.str()); + + //----Session-Loop-Thread-is-running------------------------ + + // shut down the ProcDispatcher... + CHECK (ProcDispatcher::instance().isRunning()); + ProcDispatcher::instance().requestStop(); + + __DELAY__ // wait a moment for the other thread to terminate... + CHECK (not ProcDispatcher::instance().isRunning()); + CHECK (thread_has_ended); + + lumiera_interfaceregistry_destroy(); } };