Commands: complete the test case

verify the commands where indeed defined as given by the lambda
This commit is contained in:
Fischlurch 2017-03-31 03:27:26 +02:00
parent 27c2f843da
commit b303bcebc0
3 changed files with 23 additions and 9 deletions

View file

@ -44,7 +44,7 @@
** @see command-def.hpp
** @see command.hpp
** @see command-accessor.hpp
** @see TODO_CommandSetup_test
** @see CommandSetup_test
**
*/

View file

@ -70,9 +70,7 @@ namespace test {
void
do_something_pointless (CommandDef&)
{
cout << "before-->" << testString << endl;
testString = "Ichthyostega wuz here";
cout << "after--->" << testString << endl;
}
@ -98,8 +96,8 @@ namespace test {
/***********************************************************************//**
* @test cover the behaviour of the CommandSetup helper for inserting
* actual command definitions into the Session.
* @test cover the behaviour of the CommandSetup helper intended for
* inserting actual command definitions into the Session.
*
* @see cmd.hpp
* @see session-cmd.cpp actual usage example
@ -141,7 +139,7 @@ namespace test {
CHECK (def_empty != CommandSetup("to pee or not to pee"));
//////////// does not compile -- copy assignment prohibited...
// def_empty = def_1;
// def_empty = CommandSetup{"to peel whatever"};
// add actual definition closures...
@ -198,6 +196,22 @@ namespace test {
// but the other two entries did indeed define commands
CHECK (Command::defined("test.CommandSetup.def_1"));
CHECK (Command::defined("test.CommandSetup.def_2"));
// ...and they defined the commands as specified
Command com1{"test.CommandSetup.def_1"};
Command com2{"test.CommandSetup.def_2"};
com1.bind (string{"^(\\w+)"}, string{"No $1"});
com2.bind (uint(42));
com1();
CHECK (testString == "No Ichthyostega wuz here");
com2();
CHECK (testString == "No Ichthyostega wuz here 42 times.");
com1.undo();
CHECK (testString == "Ichthyostega wuz here");
}

View file

@ -1605,13 +1605,13 @@ When a command has been executed (and maybe undone), it's best to leave it alone
State predicates are accessible through the Command (frontend); additionally there are static query functions in class {{{Command}}}
</pre>
</div>
<div title="CommandSetup" creator="Ichthyostega" modifier="Ichthyostega" created="201703180038" modified="201703180047" tags="SessionLogic spec draft impl" changecount="4">
<div title="CommandSetup" creator="Ichthyostega" modifier="Ichthyostega" created="201703180038" modified="201703302055" tags="SessionLogic spec draft impl" changecount="6">
<pre>//Helper facility to ease the creation of actual command definitions.//
A [[Proc-Layer command|CommandHandling]] is a functor, which can be parametrised with actual arguments. It needs to be [defined](command-def.hpp) beforehand, which means to establish an unique name and to supply three functions, one for the actual command operation, one to capture state and one to [[UNDO]] the effect of the command invocation.
A [[Proc-Layer command|CommandHandling]] is a functor, which can be parametrised with actual arguments. It needs to be [[defined|CommandDefinition]] beforehand, which means to establish an unique name and to supply three functions, one for the actual command operation, one to capture state and one to [[UNDO]] the effect of the command invocation.
The helper class {{{CommandSetup}}} allows to create series of such definitions with minimal effort. Since any access and mutation from the UI into the Session data must be performed by invoking such commands, a huge amount of individual command definitions need to be written eventually. These are organised into a series of implementation translation units with location {{{poc/cmd/*-cmd.cpp}}}.
Each of these files is specialised to defining a set of thematically related command, supplying the code for the actual command scripts. Each definition is introduced by a single line with the macro {{{COMMAND_DEFINITION(name)}}}, followed by a code block, which actually ends up as the body of a lambda function, and receives the bare [[CommandDef|CommandDefinition]] as single argument with name {{{cmd}}}. The {{{name}}} argument of the macro ends up both stringified as the value of the command-~ID, and as an identifier holding a new {{{CommandSetup}}} instance. It is assumed that a header with //corresponding declarations// (the header {{{cmd.hpp}}}) is included by all UI elements actually to use, handle and invoke commands towards the SessionSubsystem
Each of these files is specialised to defining a set of thematically related commands, supplying the code for the actual command scripts. Each definition is introduced by a single line with the macro {{{COMMAND_DEFINITION(name)}}}, followed by a code block, which actually ends up as the body of a lambda function, and receives the bare [[CommandDef|CommandDefinition]] as single argument with name {{{cmd}}}. The {{{name}}} argument of the macro ends up both stringified as the value of the command-ID, and as an identifier holding a new {{{CommandSetup}}} instance. It is assumed that a header with //corresponding declarations// (the header {{{cmd.hpp}}}) is included by all UI elements actually to use, handle and invoke commands towards the SessionSubsystem
</pre>
</div>
<div title="CommandUsage" modifier="Ichthyostega" created="200907212338" modified="201701090011" tags="SessionLogic draft operational" changecount="8">