Lumiera  0.pre.03
»edit your freedom«
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)
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"
25 #include "lib/symbol.hpp"
26 #include "lib/util.hpp"
27 #include "lib/p.hpp"
28 
30 
31 
32 namespace steam {
33 namespace control {
34 namespace test {
35 
36  using namespace lib::meta;
37 
38  typedef lib::P<CommandImpl> PCmdImpl;
39 
40 
41  namespace { // test config...
42  HandlingPattern::ID TEST_HANDLING_PATTERN = HandlingPattern::DUMMY;
43  }
44 
45 
46 
47 
48 
49 
50  /****************************************************************************/
64  class CommandCloneBuilder_test : public Test
65  {
66 
67 
68  virtual void
69  run (Arg)
70  {
71  seedRand();
73  CHECK (&registry);
74  uint cnt_inst = registry.instance_count();
75 
76  {
77  PCmdImpl source = buildTestImplFrame (registry);
78  PCmdImpl clone = registry.createCloneImpl (*source);
79 
80  verifySeparation (source, clone);
81  }
82 
83  CHECK (cnt_inst == registry.instance_count());
84  }
85 
86 
87 
88  PCmdImpl
89  buildTestImplFrame (CommandRegistry& registry)
90  {
91  // simulate what normally happens within a CommandDef
92  typedef void Sig_oper(int);
93  typedef long Sig_capt(int);
94  typedef void Sig_undo(int,long);
95 
96  function<Sig_oper> o_Fun (command1::operate);
97  function<Sig_capt> c_Fun (command1::capture);
98  function<Sig_undo> u_Fun (command1::undoIt);
99 
100  CHECK (o_Fun && c_Fun && u_Fun);
101  PCmdImpl cmd = registry.newCommandImpl(o_Fun,c_Fun,u_Fun);
102 
103  // make ready for execution
104  bindRandArgument (*cmd);
105  CHECK (cmd->canExec());
106  return cmd;
107  }
108 
109 
111  void
113  {
114  typedef Types<int> ArgType;
115  TypedArguments<Tuple<ArgType>> arg (std::make_tuple (rani (10000)));
116  cmd.setArguments (arg);
117  CHECK (cmd.canExec());
118  }
119 
120 
126  void
127  verifySeparation (PCmdImpl orig, PCmdImpl copy)
128  {
129  CHECK (orig && copy);
130  CHECK (orig->canExec());
131  CHECK (copy->canExec());
132 
133 
134  // prepare for command invocation on implementation level....
135  HandlingPattern const& testExec = HandlingPattern::get(TEST_HANDLING_PATTERN);
136  command1::check_ = 0;
137 
138  bindRandArgument (*orig);
139  CHECK ( orig->canExec());
140  CHECK (!orig->canUndo());
141  testExec.exec (*orig, "Execute original"); // EXEC 1
142  long state_after_exec1 = command1::check_;
143  CHECK (command1::check_ > 0);
144  CHECK (orig->canUndo());
145 
146  CHECK (!copy->canUndo());
147  testExec.exec (*copy, "Execute clone"); // EXEC 2
148  CHECK (command1::check_ != state_after_exec1);
149  CHECK (copy->canUndo());
150 
151  // invoke UNDO on the clone
152  testExec.undo (*copy, "Undo clone"); // UNDO 2
153  CHECK (command1::check_ == state_after_exec1);
154 
155  // invoke UNDO on original
156  testExec.undo (*orig, "Undo original"); // UNDO 1
157  CHECK (command1::check_ ==0);
158  }
159 
160  };
161 
162 
164  LAUNCHER (CommandCloneBuilder_test, "function controller");
165 
166 
167 }}} // namespace steam::control::test
Definition: run.hpp:40
Implementation helper to bind Steam-Layer commands with arbitrary argument tuples.
shared_ptr< CommandImpl > newCommandImpl(function< SIG_OPER > &operFunctor, function< SIG_CAPT > &captFunctor, function< SIG_UNDO > &undoFunctor)
set up a new command implementation frame
bool canExec() const
< state check: sufficiently defined to be invoked
Top level of the command implementation.
Managing command definitions and the storage of individual command objects.
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
Customised refcounting smart pointer.
Registry managing command implementation objects (Singleton).
Steam-Layer implementation namespace root.
Metaprogramming with tuples-of-types and the std::tuple record.
Marker types to indicate a literal string and a Symbol.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void bindRandArgument(CommandImpl &cmd)
Helper: create random command parameter binding.
Pre-defined command execution skeletons.
Some dummy command functions used for building unit test cases.
shared_ptr< CommandImpl > createCloneImpl(CommandImpl const &refObject)
create an allocation for holding a clone of the given CommandImpl data.
Definition: command.cpp:219
Steam-Layer Command implementation.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
Interface: Operation Skeleton how to invoke or undo a command.
static lib::Depend< CommandRegistry > instance
storage for the singleton factory used to access CommandRegistry