From b2e0c8fa63dad727c9e568669ff5a6cb3675d529 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 15 Jan 2016 04:30:43 +0100 Subject: [PATCH] WIP: draft a test to verify the bus side of UI command invocation basically this comes down to provide some convenience fixture within the test::Nexus, which automatically generates and wires mock commands. Not sure if this is even possible to the extent envisioned here --- src/gui/interact/invocation-trail.hpp | 10 +++++ tests/gui/bus-term-test.cpp | 53 ++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/gui/interact/invocation-trail.hpp b/src/gui/interact/invocation-trail.hpp index 649add17f..1d585475c 100644 --- a/src/gui/interact/invocation-trail.hpp +++ b/src/gui/interact/invocation-trail.hpp @@ -80,6 +80,16 @@ namespace interact { string cmdID_; public: + /** + * Build a "command-as-prepared-for-UI". + * @param prototype an _already existing_ command prototype definition within Proc-Layer + * @remarks we deliberately link InvocationTrail to the existence of an actual prototype. + * Invocation trails will be created in advance for various scenarios to invoke commands, + * and are in fact lightweight placeholder handles -- so we do not want placeholders to + * exist somewhere in the system and IDs to be sent over the bus, without the certainty + * of a real invocation site and a matching command operation to exist somewhere else + * within the system. + */ InvocationTrail(proc::control::Command prototype) : cmdID_(prototype.getID()) { } diff --git a/tests/gui/bus-term-test.cpp b/tests/gui/bus-term-test.cpp index 345abef1a..e45196016 100644 --- a/tests/gui/bus-term-test.cpp +++ b/tests/gui/bus-term-test.cpp @@ -28,6 +28,8 @@ #include "lib/idi/entry-id.hpp" #include "lib/diff/gen-node.hpp" #include "lib/format-cout.hpp" +#include "lib/time/timevalue.hpp" +#include "lib/luid.h" //#include "lib/util.hpp" @@ -36,6 +38,9 @@ using lib::idi::EntryID; using lib::idi::BareEntryID; using gui::test::MockElm; using lib::diff::GenNode; +using lib::diff::Rec; +using lib::time::TimeSpan; +using lib::hash::LuidH; //using util::contains; @@ -43,6 +48,9 @@ namespace gui { namespace model{ namespace test { + using proc::control::LUMIERA_ERROR_INVALID_ARGUMENTS; + using proc::control::LUMIERA_ERROR_UNBOUND_ARGUMENTS; + namespace { // test fixture... }//(End) test fixture @@ -166,7 +174,50 @@ namespace test { void commandInvocation () { - UNIMPLEMENTED ("pass a message to invoke an action"); + MARK_TEST_FUN + auto cmd = gui::test::Nexus::prepareMockCmd(); + + MockElm mock("uiElm"); + + // random command arguments... + string text {lib::test::randStr(12)}; + 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) ); + + // proper argument typing is ensured while dispatching the bind message. + VERIFY_ERROR (INVALID_ARGUMENTS, mock.prepareCommand(cmd, Rec({"lalala"})) ); + + // command can't be issued, since it's still unbound + CHECK (not gui::test::Nexus::canInvoke(cmd)); + + + mock.prepareCommand(cmd, Rec({text, clip, luid})); + + CHECK (gui::test::Nexus::canInvoke(cmd)); + CHECK (gui::test::Nexus::wasBound(cmd, text, clip, luid)); + CHECK (not gui::test::Nexus::wasInvoked(cmd)); + CHECK (not gui::test::Nexus::wasInvoked(cmd, text, clip, luid)); + CHECK (not gui::test::Nexus::wasBound(cmd, "lololo")); + + + mock.issueCommand(cmd); + + CHECK (gui::test::Nexus::wasInvoked(cmd)); + CHECK (gui::test::Nexus::wasInvoked(cmd, text, clip, luid)); + CHECK (not gui::test::Nexus::wasInvoked(cmd, " huh ", clip, luid)); + CHECK (not gui::test::Nexus::wasInvoked(cmd, text, clip)); + + // Mock commands are automatically unique + auto cmdX = gui::test::Nexus::prepareMockCmd<>(); + auto cmdY = gui::test::Nexus::prepareMockCmd<>(); + CHECK (cmd.getID() != cmdX.getID()); + CHECK (cmd.getID() != cmdY.getID()); + + CHECK (not gui::test::Nexus::wasInvoked(cmdX)); + CHECK (not gui::test::Nexus::wasInvoked(cmdY)); }