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)
5  2016, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/test/test-helper.hpp"
22 #include "lib/time/timevalue.hpp"
23 #include "lib/diff/gen-node.hpp"
24 
25 
26 namespace steam {
27 namespace control {
28 namespace test {
29 
30  using lib::time::Time;
31  using lib::time::TimeVar;
33  using lib::time::TimeSpan;
34  using lib::time::Duration;
35  using lib::test::randTime;
36  using lib::diff::Rec;
37 
38 
39 
40 
41 
42  namespace { // functions to be invoked through the command system
43 
44  TimeVar implicitTestState;
45 
46  void
47  operate (Duration dur)
48  {
49  implicitTestState += dur;
50  }
51 
52  Time
53  capture (Duration)
54  {
55  return implicitTestState;
56  }
57 
58  void
59  undoIt (Duration, Time oldVal)
60  {
61  implicitTestState = oldVal;
62  }
63  }
64 
65 
66 
67 
68  /***********************************************************************/
85  class CommandMessageBinding_test : public Test
86  {
87 
88  virtual void
89  run (Arg)
90  {
91  Time five(TimeValue(5));
92  implicitTestState = five;
93 
94  CommandDef ("test.command2")
95  .operation (operate)
96  .captureUndo (capture)
97  .undoOperation (undoIt)
98  ;
99 
100 
101 
102  TimeSpan testSpan (randTime(), randTime());
103  Rec argMsg {testSpan};
104 
105  // bind the command argument from a GenNode message
106  Command ourCmd = Command::get("test.command2");
107  CHECK (not ourCmd.canExec());
108 
109  ourCmd.bindArg (argMsg);
110  CHECK (ourCmd.canExec());
111 
112  // invoke the command
113  ourCmd();
114  CHECK (implicitTestState == five + Duration(testSpan));
115 
116  // undo the effect of the command
117  ourCmd.undo();
118  CHECK (implicitTestState == five);
119  }
120  };
121 
122 
124  LAUNCHER (CommandMessageBinding_test, "unit controller");
125 
126 
127 }}} // 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:232
Definition: run.hpp:40
static Command get(Symbol cmdID)
Access existing command for use.
Definition: command.cpp:120
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Simplistic 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:115
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
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:573
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:141
basic constant internal time value.
Definition: timevalue.hpp:133