Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
command-clone-builder-test.cpp
Go to the documentation of this file.
1 /*
2  CommandCloneBuilder(Test) - verify building an implementation clone
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"
34 #include "lib/symbol.hpp"
35 #include "lib/util.hpp"
36 #include "lib/p.hpp"
37 
39 
40 
41 namespace proc {
42 namespace control {
43 namespace test {
44 
45  using namespace lib::meta;
46 
48 
49 
50  namespace { // test config...
51  HandlingPattern::ID TEST_HANDLING_PATTERN = HandlingPattern::DUMMY;
52  }
53 
54 
55 
56 
57 
58 
59  /****************************************************************************/
73  class CommandCloneBuilder_test : public Test
74  {
75 
76 
77  virtual void
78  run (Arg)
79  {
81  CHECK (&registry);
82  uint cnt_inst = registry.instance_count();
83 
84  {
85  PCmdImpl source = buildTestImplFrame (registry);
86  PCmdImpl clone = registry.createCloneImpl (*source);
87 
88  verifySeparation (source, clone);
89  }
90 
91  CHECK (cnt_inst == registry.instance_count());
92  }
93 
94 
95 
96  PCmdImpl
98  {
99  // simulate what normally happens within a CommandDef
100  typedef void Sig_oper(int);
101  typedef long Sig_capt(int);
102  typedef void Sig_undo(int,long);
103 
104  function<Sig_oper> o_Fun (command1::operate);
105  function<Sig_capt> c_Fun (command1::capture);
106  function<Sig_undo> u_Fun (command1::undoIt);
107 
108  CHECK (o_Fun && c_Fun && u_Fun);
109  PCmdImpl cmd = registry.newCommandImpl(o_Fun,c_Fun,u_Fun);
110 
111  // make ready for execution
112  bindRandArgument (*cmd);
113  CHECK (cmd->canExec());
114  return cmd;
115  }
116 
117 
119  void
121  {
122  typedef Types<int> ArgType;
123  TypedArguments<Tuple<ArgType>> arg (std::make_tuple (rand() % 10000));
124  cmd.setArguments (arg);
125  CHECK (cmd.canExec());
126  }
127 
128 
134  void
135  verifySeparation (PCmdImpl orig, PCmdImpl copy)
136  {
137  CHECK (orig && copy);
138  CHECK (orig->canExec());
139  CHECK (copy->canExec());
140  CHECK (orig == copy);
141 
142 
143  // prepare for command invocation on implementation level....
144  HandlingPattern const& testExec = HandlingPattern::get(TEST_HANDLING_PATTERN);
145  command1::check_ = 0;
146 
147  bindRandArgument (*orig);
148  CHECK ( orig->canExec());
149  CHECK (!orig->canUndo());
150  testExec.exec (*orig, "Execute original"); // EXEC 1
151  long state_after_exec1 = command1::check_;
152  CHECK (command1::check_ > 0);
153  CHECK (orig->canUndo());
154  CHECK (orig != copy);
155 
156  CHECK (!copy->canUndo());
157  testExec.exec (*copy, "Execute clone"); // EXEC 2
158  CHECK (command1::check_ != state_after_exec1);
159  CHECK (copy->canUndo());
160  CHECK (copy != orig);
161 
162  // invoke UNDO on the clone
163  testExec.undo (*copy, "Undo clone"); // UNDO 2
164  CHECK (command1::check_ == state_after_exec1);
165 
166  // invoke UNDO on original
167  testExec.undo (*orig, "Undo original"); // UNDO 1
168  CHECK (command1::check_ ==0);
169 
170  CHECK (copy != orig);
171  }
172 
173  };
174 
175 
177  LAUNCHER (CommandCloneBuilder_test, "function controller");
178 
179 
180 }}} // namespace proc::control::test
void bindRandArgument(CommandImpl &cmd)
Helper: create random command parameter binding.
int64_t check_
< test command just adding a given value
ExecResult undo(CommandImpl &command, string) const
likewise invoke the configured UNDO operation
PCmdImpl buildTestImplFrame(CommandRegistry &registry)
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
void undoIt(int, int64_t oldVal)
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
Definition: run.hpp:49
Implementation helper to bind Proc-Layer commands with arbitrary argument tuples. ...
Top level of the command implementation.
Managing command definitions and the storage of individual command objects.
Customised refcounting smart pointer.
shared_ptr< CommandImpl > createCloneImpl(CommandImpl const &refObject)
create an allocation for holding a clone of the given CommandImpl data.
Definition: command.cpp:226
ExecResult exec(CommandImpl &command, string) const
main functionality: invoke a command, detect errors.
Metaprogramming with tuples-of-types and the std::tuple record.
bool canExec() const
< state check: sufficiently defined to be invoked
Registry managing command implementation objects (Singleton).
shared_ptr< CommandImpl > newCommandImpl(function< SIG_OPER > &operFunctor, function< SIG_CAPT > &captFunctor, function< SIG_UNDO > &undoFunctor)
set up a new command implementation frame
std::vector< string > & Arg
Definition: run.hpp:54
Proc-Layer Command implementation.
Marker types to indicate a literal string and a Symbol.
lib::P< CommandImpl > PCmdImpl
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
LAUNCHER(ArgumentTupleAccept_test,"unit controller")
Register this test class...
Pre-defined command execution skeletons.
Interface: Operation Skeleton how to invoke or undo a command.
void setArguments(Arguments &args)
static lib::Depend< CommandRegistry > instance
storage for the singleton factory used to access CommandRegistry
Some dummy command functions used for building unit test cases.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63