From a5ca8ed3b1d3811ed140c202f525c5a0f07fc866 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 12 Jan 2016 02:14:06 +0100 Subject: [PATCH] ...and back to #975 : draft command invocation on UI elements First part is to define the steps (the protocol) at the model element level, which gets a command prepared and invoked. Test fails still, because there is no actual argument binding invoked in the TestNexus --- .../core/proc/control/command-basic-test.cpp | 3 +- tests/gui/abstract-tangible-test.cpp | 69 ++++++++++++++++++- wiki/thinkPad.ichthyo.mm | 51 +++++++++++++- 3 files changed, 119 insertions(+), 4 deletions(-) diff --git a/tests/core/proc/control/command-basic-test.cpp b/tests/core/proc/control/command-basic-test.cpp index 5150bdd9f..5dae1f42a 100644 --- a/tests/core/proc/control/command-basic-test.cpp +++ b/tests/core/proc/control/command-basic-test.cpp @@ -36,6 +36,7 @@ namespace control { namespace test { using lib::P; + using lib::newP; using lib::time::Time; using lib::time::TimeVar; using lib::time::TimeValue; @@ -93,7 +94,7 @@ namespace test { int randVal ((rand() % 10) - 5); Time five(TimeValue(5)); TimeValue randomTime(randVal); - P obj (new TimeVar(five)); + auto obj = newP(five); CommandDef ("test.command1") .operation (operate) diff --git a/tests/gui/abstract-tangible-test.cpp b/tests/gui/abstract-tangible-test.cpp index fd77c778f..7194f145b 100644 --- a/tests/gui/abstract-tangible-test.cpp +++ b/tests/gui/abstract-tangible-test.cpp @@ -51,15 +51,21 @@ #include "test/mock-elm.hpp" #include "test/test-nexus.hpp" #include "lib/idi/entry-id.hpp" +#include "proc/control/command-def.hpp" #include "lib/format-cout.hpp" +#include "lib/symbol.hpp" #include "lib/error.hpp" //#include "lib/util.hpp" +using lib::Symbol; using gui::test::MockElm; using lib::test::EventLog; using lib::idi::EntryID; +using proc::control::Command; +using proc::control::CommandDef; +using gui::interact::InvocationTrail; @@ -69,6 +75,29 @@ namespace test { namespace { // test fixture... + // dummy operation to be invoked through the command system + int dummyState = 0; + + void + operate (int val) + { + dummyState = val; + } + + int + capture (int) + { + return dummyState; + } + + void + undoIt (int, int oldState) + { + dummyState = oldState; + } + + const Symbol DUMMY_CMD_ID{"test.AbstractTangibleTest_dummy_command"}; + }//(End) test fixture @@ -224,10 +253,48 @@ namespace test { } + void invokeCommand () { - UNIMPLEMENTED ("invoke an action, pass arguments"); + EventLog nexusLog = gui::test::Nexus::startNewLog(); + + // Setup test stage: define an command/action "in Proc" + CommandDef (DUMMY_CMD_ID) + .operation (operate) + .captureUndo (capture) + .undoOperation (undoIt); + + // Usually it's the InvocationStateManager's job to + // prepare an "InvocationTrail", which is a prospective + // Command invocation about to happen soon. + InvocationTrail invTrail (Command::get (DUMMY_CMD_ID)); + + // the UI element relevant for this command invocation + MockElm mock("uiElm"); + + int prevState = dummyState; + int concreteParam = 1 +rand() % 100; + + // now the ongoing interaction picks up parameter data + mock.prepareCommand (invTrail, lib::diff::Rec({concreteParam})); + + CHECK (dummyState == prevState); // command was not yet invoked + + // finally the command gets triggered + mock.issueCommand (invTrail); + + CHECK (dummyState == concreteParam); // command was indeed invoked + + + // verify proper binding, including UNDO state capture + Command::get (DUMMY_CMD_ID).undo(); + CHECK (dummyState == prevState); + + + cout << "____Nexus-Log_________________\n" + << util::join(nexusLog, "\n") + << "\n───╼━━━━━━━━━╾────────────────"< - + + + + + + + + +

+ hier geht es darum, eine Regel zu generieren, +

+

+ die dann den zugrundeliegenden Command-Prototyp automatisch mit konkreten Aufrufparametern binden kann, +

+

+ sobald bestimmte Umstände im UI einschlägig werden +

+

+ +

+

+ Das kann ich für die ersten Tests auslassen, und stattdessen einfach +

+

+ den InvocationTrail manuell im Testcode binden +

+ + +
+ +
@@ -452,9 +482,26 @@ - + + + + + + + +

+ gemeint, das Model-Element (Tangible) sollte einen solchen Overload anbieten, +

+

+ der unimttelbar Datenwerte nimmt und sie in einen Argument-Record packt +

+ + +
+ +