Lumiera  0.pre.03
»edityourfreedom«
command-queue-test.cpp
Go to the documentation of this file.
1 /*
2  CommandQueue(Test) - verify functionality of ProcDispatcher queue component
3 
4  Copyright (C) Lumiera.org
5  2016, 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 
23 
24 #include "lib/test/run.hpp"
27 //#include "proc/control/command-registry.hpp"
28 //#include "lib/test/event-log.hpp"
29 #include "lib/symbol.hpp"
30 #include "lib/util.hpp"
31 
33 
34 //#include <cstdlib>
35 
36 
37 namespace proc {
38 namespace control {
39 namespace test {
40 
41 
42 // using std::function;
43 // using std::rand;
44  using lib::Symbol;
45  using util::isnil;
46 
47 
48  namespace { // test fixture...
49 
50  const Symbol COMMAND_1{"test.queue.command1"};
51  const Symbol COMMAND_3{"test.queue.command3"};
52 
53  }//(End) test fixture
54 
55 // typedef shared_ptr<CommandImpl> PCommandImpl;
56 // typedef HandlingPattern const& HaPatt;
57 
58 
59 
60 
61 
62 
63  /******************************************************************************/
73  class CommandQueue_test : public Test
74  {
75 
76  //------------------FIXTURE
77  public:
79  {
80  CommandDef (COMMAND_1)
82  .captureUndo (command1::capture)
83  .undoOperation (command1::undoIt)
84  ;
85  CommandDef (COMMAND_3)
87  .captureUndo (command3::capture)
88  .undoOperation (command3::undoIt)
89  ;
90  }
92  {
93  Command::remove (COMMAND_1);
94  Command::remove (COMMAND_3);
95  }
96  //-------------(End)FIXTURE
97 
98 
99  virtual void
101  {
102  verifyBasics();
104  }
105 
106 
107  void
109  {
110  Command com11 = Command(COMMAND_1).newInstance();
111  Command com12 = Command(COMMAND_1).newInstance();
112 
113  com11.bind(42);
114  com12.bind(47);
115 
116  CommandQueue queue;
117  CHECK (isnil(queue));
118 
119  queue.feed (Command{com11});
120  queue.feed (Command{com12});
121 
122  CHECK (2 == queue.size());
123 
124  Command x = queue.pop();
125  CHECK (1 == queue.size());
126  CHECK (x == com11);
127 
128  queue.clear();
129  CHECK (0 == queue.size());
130  CHECK (queue.empty());
131  }
132 
133 
134  void
136  {
137  Command com11 = Command(COMMAND_1).newInstance();
138  Command com12 = Command(COMMAND_1).newInstance();
139 
140  com11.bind(42);
141  // NOT binding the second command...
142 
143  CommandQueue queue;
144  queue.feed (Command{com11});
145  CHECK (1 == queue.size());
146 
147  VERIFY_ERROR (UNBOUND_ARGUMENTS, queue.feed (Command{com12}));
148  CHECK (1 == queue.size());
149 
150  queue.pop().execSync();
151  VERIFY_ERROR (UNBOUND_ARGUMENTS, com12.execSync());
152  }
153  };
154 
155 
157  LAUNCHER (CommandQueue_test, "unit controller");
158 
159 
160 }}} // namespace proc::control::test
auto operation(FUN operation_to_define)
void undoIt(int, int64_t oldVal)
Definition: run.hpp:49
size_t size() const
Definition: iter-stack.hpp:230
bool empty() const
Definition: iter-stack.hpp:236
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify a statement indeed raises an exception.
Helper class used solely for defining a Command-Object.
Implementation building block of ProcDispatcher to organise commands.
Token or Atom with distinct identity.
Definition: symbol.hpp:116
RET bind()
Accept dummy binding (0 Arg)
std::vector< string > & Arg
Definition: run.hpp:54
LAUNCHER(ArgumentTupleAccept_test, "unit controller")
Register this test class...
Marker types to indicate a literal string and a Symbol.
Simple test class runner.
Implementation of the Session&#39;s command queue.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition: command.cpp:207
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
CommandQueue & feed(Command &&cmd)
Some dummy command functions used for building unit test cases.
Handle object representing a single Command instance to be used by client code.
Definition: command.hpp:125
static bool remove(Symbol cmdID)
Definition: command.cpp:248
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
Actually defining a command and binding it to execution parameters.
ExecResult execSync()
invoke using a default "synchronous" execution pattern
Definition: command.cpp:464