Lumiera  0.pre.03
»edit your freedom«
command-basic-test.cpp
Go to the documentation of this file.
1 /*
2  CommandBasic(Test) - checking simple SteamDispatcher command definition and execution
3 
4  Copyright (C)
5  2009, 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"
21 #include "lib/time/timevalue.hpp"
22 #include "lib/p.hpp"
23 
24 
25 namespace steam {
26 namespace control {
27 namespace test {
28 
29  using lib::P;
30  using lib::makeP;
31  using lib::time::Time;
32  using lib::time::TimeVar;
34  using lib::time::Offset;
35 
36 
37 
38 
39 
40  namespace { // functions to be invoked through the command system
41 
42  void
43  operate (P<TimeVar> dummyObj, int randVal)
44  {
45  *dummyObj += TimeValue(randVal);
46  }
47 
48  Offset
49  capture (P<TimeVar> dummyObj, int)
50  {
51  return Offset{*dummyObj};
52  }
53 
54  void
55  undoIt (P<TimeVar> dummyObj, int, Offset oldVal)
56  {
57  *dummyObj = oldVal;
58  }
59 
60  }
61 
62 
63 
64  /***********************************************************************/
80  class CommandBasic_test : public Test
81  {
82 
83  virtual void
84  run (Arg)
85  {
86  seedRand();
87  int randVal{rani(10) - 5};
88  Time five(TimeValue(5));
89  TimeValue randomTime(randVal);
90  auto obj = makeP<TimeVar>(five);
91 
92  CommandDef ("test.command1")
93  .operation (operate)
94  .captureUndo (capture)
95  .undoOperation (undoIt)
96  .bind (obj, randVal)
97  ;
98 
99 
100  Command ourCmd = Command::get("test.command1");
101 
102  // invoke the command
103  CHECK (*obj == five);
104  ourCmd();
105  CHECK (*obj == five + randomTime);
106 
107  // undo the effect of the command
108  ourCmd.undo();
109  CHECK (*obj == five);
110  }
111  };
112 
113 
115  LAUNCHER (CommandBasic_test, "unit controller");
116 
117 
118 }}} // 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
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
static Command get(Symbol cmdID)
Access existing command for use.
Definition: command.cpp:120
Customised refcounting smart pointer.
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Simplistic test class runner.
Offset measures a distance in time.
Definition: timevalue.hpp:358
Handle object representing a single Command instance to be used by client code.
Definition: command.hpp:115
P< X > makeP(ARGS &&... ctorArgs)
Helper to create and manage by lib::P.
Definition: p.hpp:135
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
Actually defining a command and binding it to execution parameters.
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133