From 1dc9642ec41767f2f9293c65a0954910aba22a13 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 22 Jan 2016 19:44:17 +0100 Subject: [PATCH] draft implementation of diagnostic command handler --- src/proc/control/command.cpp | 2 +- tests/gui/bus-term-test.cpp | 5 +- tests/gui/test/test-nexus.cpp | 106 +++++++++++++++++++++++++++++++++- tests/gui/test/test-nexus.hpp | 4 ++ 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/src/proc/control/command.cpp b/src/proc/control/command.cpp index d42e3b8ea..f3605c40e 100644 --- a/src/proc/control/command.cpp +++ b/src/proc/control/command.cpp @@ -116,7 +116,7 @@ namespace control { * @throw error::Invalid if command not * registered or incompletely defined. */ - Command + Command Command::get (Symbol cmdID) { Command cmd = CommandRegistry::instance().queryIndex (cmdID); diff --git a/tests/gui/bus-term-test.cpp b/tests/gui/bus-term-test.cpp index 976dfe7f8..1d55d63ca 100644 --- a/tests/gui/bus-term-test.cpp +++ b/tests/gui/bus-term-test.cpp @@ -186,14 +186,13 @@ namespace test { TimeSpan clip (Time(1,2,3), lib::test::randTime()); LuidH luid; + // we cannot invoke commands prior to binding arguments + VERIFY_ERROR (UNBOUND_ARGUMENTS, mock.issueCommand(cmd) ); ////////////////////////////////////////////////////////////////////////////////////////////////////TODO WIP - mock.issueCommand(cmd); cout << "____Nexus-Log_________________\n" << util::join(gui::test::Nexus::getLog(), "\n") << "\n───╼━━━━━━━━━╾────────────────"< idStringBuffer; ////////////////////////////////TICKET #158 replace by symbol table @@ -88,6 +92,9 @@ namespace test{ idStringBuffer.emplace_back (std::forward (idString)); return Symbol (idStringBuffer.back().c_str()); } + ////////////////////////(End)symbol-table hack + + namespace { // internal details @@ -422,6 +429,103 @@ namespace test{ } + namespace { // install a diagnostic dummy-command-handler + + class SimulatedCommandHandler + : public Variant::Predicate + , public HandlingPattern + { + mutable EventLog log_; + Command command_; + + + + /* ==== HandlingPattern - Interface ==== */ + + void + performExec (CommandImpl& command) const override + { + log_.call ("TestNexus", "exec"); + command.invokeCapture(); + command.invokeOperation(); + } + + void + performUndo (CommandImpl& command) const override + { + log_.call ("TestNexus", "undo"); + command.invokeUndo(); + } + + bool + isValid() const override + { + return true; + } + + + /* ==== CommandHandler ==== */ + + bool + handle (Rec const& argBinding) override + { + log_.event("TestNexus", "bound command arguments "+string(argBinding)); + } + + bool + handle (int const&) override + { + log_.event("TestNexus", "trigger "+string(command_)); + return command_.exec (*this); + } + + + + static Command + retrieveCommand (GenNode const& cmdMsg) + { + Symbol cmdID {cmdMsg.idi.getSym().c_str()}; + return Command::get (cmdID); + } + + public: + SimulatedCommandHandler (GenNode const& cmdMsg) + : log_(Nexus::getLog()) + , command_(retrieveCommand(cmdMsg)) + { + log_.event("TestNexus", "HANDLING Command-Message for "+string(command_)); + + if (not cmdMsg.data.accept (*this)) + log_.warn(_Fmt("FAILED to handle command-message %s in test-mode") % cmdMsg); + } + + bool + invokedExec() + { + return log_.verifyCall("exec").on(this); + } + + bool + invokedUndo() + { + return log_.verifyCall("undo").on(this) + .afterCall("exec"); + } + }; + + }//(End)diagnostic dummy-command-handler + + void + Nexus::prepareDiagnosticCommandHandler() + { + testNexus().installCommandHandler( + [](GenNode const& cmdMsg) + { + SimulatedCommandHandler{cmdMsg}; + }); + } + + bool Nexus::canInvoke(Cmd cmd) diff --git a/tests/gui/test/test-nexus.hpp b/tests/gui/test/test-nexus.hpp index 89aed1ef8..6a8e99a95 100644 --- a/tests/gui/test/test-nexus.hpp +++ b/tests/gui/test/test-nexus.hpp @@ -109,6 +109,9 @@ namespace test{ template static bool wasInvoked (Cmd, ARGS const& ...args); + + private: + static void prepareDiagnosticCommandHandler(); }; @@ -117,6 +120,7 @@ namespace test{ inline interact::InvocationTrail Nexus::prepareMockCmd() { + prepareDiagnosticCommandHandler(); return Cmd {PlaceholderCommand::fabricateNewInstance(getLog())}; }