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) Lumiera.org
5  2009, 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"
30 #include "lib/time/timevalue.hpp"
31 #include "lib/p.hpp"
32 
33 #include <cstdlib>
34 
35 using std::rand;
36 
37 
38 namespace steam {
39 namespace control {
40 namespace test {
41 
42  using lib::P;
43  using lib::makeP;
44  using lib::time::Time;
45  using lib::time::TimeVar;
47  using lib::time::Offset;
48 
49 
50 
51 
52 
53  namespace { // functions to be invoked through the command system
54 
55  void
56  operate (P<TimeVar> dummyObj, int randVal)
57  {
58  *dummyObj += TimeValue(randVal);
59  }
60 
61  Offset
62  capture (P<TimeVar> dummyObj, int)
63  {
64  return Offset{*dummyObj};
65  }
66 
67  void
68  undoIt (P<TimeVar> dummyObj, int, Offset oldVal)
69  {
70  *dummyObj = oldVal;
71  }
72 
73  }
74 
75 
76 
77  /***********************************************************************/
93  class CommandBasic_test : public Test
94  {
95 
96  virtual void
97  run (Arg)
98  {
99  int randVal ((rand() % 10) - 5);
100  Time five(TimeValue(5));
101  TimeValue randomTime(randVal);
102  auto obj = makeP<TimeVar>(five);
103 
104  CommandDef ("test.command1")
105  .operation (operate)
106  .captureUndo (capture)
107  .undoOperation (undoIt)
108  .bind (obj, randVal)
109  ;
110 
111 
112  Command ourCmd = Command::get("test.command1");
113 
114  // invoke the command
115  CHECK (*obj == five);
116  ourCmd();
117  CHECK (*obj == five + randomTime);
118 
119  // undo the effect of the command
120  ourCmd.undo();
121  CHECK (*obj == five);
122  }
123  };
124 
125 
127  LAUNCHER (CommandBasic_test, "unit controller");
128 
129 
130 }}} // 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
Customised refcounting smart pointer.
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Simple test class runner.
Offset measures a distance in time.
Definition: timevalue.hpp:367
Handle object representing a single Command instance to be used by client code.
Definition: command.hpp:124
P< X > makeP(ARGS &&... ctorArgs)
Helper to create and manage by lib::P.
Definition: p.hpp:144
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
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:142