Lumiera  0.pre.03
»edit your freedom«
command-message-binding-test.cpp
Go to the documentation of this file.
1 /*
2  CommandMessageBinding(Test) - verify argument binding via GenNode-Message, with immutable types
3 
4  Copyright (C) Lumiera.org
5  2016, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
31 #include "lib/time/timevalue.hpp"
32 #include "lib/diff/gen-node.hpp"
33 
34 
35 namespace steam {
36 namespace control {
37 namespace test {
38 
39  using lib::time::Time;
40  using lib::time::TimeVar;
42  using lib::time::TimeSpan;
43  using lib::time::Duration;
44  using lib::test::randTime;
45  using lib::diff::Rec;
46 
47 
48 
49 
50 
51  namespace { // functions to be invoked through the command system
52 
53  TimeVar implicitTestState;
54 
55  void
56  operate (Duration dur)
57  {
58  implicitTestState += dur;
59  }
60 
61  Time
62  capture (Duration)
63  {
64  return implicitTestState;
65  }
66 
67  void
68  undoIt (Duration, Time oldVal)
69  {
70  implicitTestState = oldVal;
71  }
72  }
73 
74 
75 
76 
77  /***********************************************************************/
94  class CommandMessageBinding_test : public Test
95  {
96 
97  virtual void
98  run (Arg)
99  {
100  Time five(TimeValue(5));
101  implicitTestState = five;
102 
103  CommandDef ("test.command2")
104  .operation (operate)
105  .captureUndo (capture)
106  .undoOperation (undoIt)
107  ;
108 
109 
110 
111  TimeSpan testSpan (randTime(), randTime());
112  Rec argMsg {testSpan};
113 
114  // bind the command argument from a GenNode message
115  Command ourCmd = Command::get("test.command2");
116  CHECK (not ourCmd.canExec());
117 
118  ourCmd.bindArg (argMsg);
119  CHECK (ourCmd.canExec());
120 
121  // invoke the command
122  ourCmd();
123  CHECK (implicitTestState == five + Duration(testSpan));
124 
125  // undo the effect of the command
126  ourCmd.undo();
127  CHECK (implicitTestState == five);
128  }
129  };
130 
131 
133  LAUNCHER (CommandMessageBinding_test, "unit controller");
134 
135 
136 }}} // namespace steam::control::test
Helper class used solely for defining a Command-Object.
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
Definition: run.hpp:49
static Command get(Symbol cmdID)
Access existing command for use.
Definition: command.cpp:129
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Simple test class runner.
Generic building block for tree shaped (meta)data structures.
A collection of frequently used helper functions to support unit testing.
Handle object representing a single Command instance to be used by client code.
Definition: command.hpp:124
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
lib::time::Time randTime()
create a random but not insane Time value between 1s ...
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
Actually defining a command and binding it to execution parameters.
a family of time value like entities and their relationships.
object-like record of data.
Definition: record.hpp:150
basic constant internal time value.
Definition: timevalue.hpp:142