Lumiera  0.pre.03
»edit your freedom«
command-queue-test.cpp
1 /*
2  CommandQueue(Test) - verify functionality of SteamDispatcher 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 "lib/symbol.hpp"
28 #include "lib/util.hpp"
29 
31 
32 
33 namespace steam {
34 namespace control{
35 namespace test {
36 
37  using lib::Symbol;
38  using util::isnil;
39  using LERR_(UNBOUND_ARGUMENTS);
40 
41 
42  namespace { // test fixture...
43 
44  const Symbol COMMAND_1{"test.queue.command1"};
45  const Symbol COMMAND_3{"test.queue.command3"};
46 
47  }//(End) test fixture
48 
49 
50 
51 
52  /******************************************************************************/
61  class CommandQueue_test : public Test
62  {
63 
64  //------------------FIXTURE
65  public:
67  {
68  CommandDef (COMMAND_1)
69  .operation (command1::operate)
70  .captureUndo (command1::capture)
71  .undoOperation (command1::undoIt)
72  ;
73  CommandDef (COMMAND_3)
74  .operation (command3::operate)
75  .captureUndo (command3::capture)
76  .undoOperation (command3::undoIt)
77  ;
78  }
80  {
81  Command::remove (COMMAND_1);
82  Command::remove (COMMAND_3);
83  }
84  //-------------(End)FIXTURE
85 
86 
87  virtual void
88  run (Arg)
89  {
90  verifyBasics();
91  verifyExecutabilityCheck();
92  }
93 
94 
95  void
96  verifyBasics()
97  {
98  Command com11 = Command(COMMAND_1).newInstance();
99  Command com12 = Command(COMMAND_1).newInstance();
100 
101  com11.bind(42);
102  com12.bind(47);
103 
104  CommandQueue queue;
105  CHECK (isnil(queue));
106 
107  queue.feed (Command{com11});
108  queue.feed (Command{com12});
109 
110  CHECK (2 == queue.size());
111 
112  Command x = queue.pop();
113  CHECK (1 == queue.size());
114  CHECK (x == com11);
115 
116  queue.clear();
117  CHECK (0 == queue.size());
118  CHECK (queue.empty());
119  }
120 
121 
122  void
123  verifyExecutabilityCheck()
124  {
125  Command com11 = Command(COMMAND_1).newInstance();
126  Command com12 = Command(COMMAND_1).newInstance();
127 
128  com11.bind(42);
129  // NOT binding the second command...
130 
131  CommandQueue queue;
132  queue.feed (Command{com11});
133  CHECK (1 == queue.size());
134 
135  VERIFY_ERROR (UNBOUND_ARGUMENTS, queue.feed (Command{com12}));
136  CHECK (1 == queue.size());
137 
138  queue.pop().execSync();
139  VERIFY_ERROR (UNBOUND_ARGUMENTS, com12.execSync());
140  }
141  };
142 
143 
145  LAUNCHER (CommandQueue_test, "unit controller");
146 
147 
148 }}} // namespace steam::control::test
Helper class used solely for defining a Command-Object.
Definition: run.hpp:49
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition: command.cpp:209
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Steam-Layer implementation namespace root.
Implementation building block of SteamDispatcher to organise commands.
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Marker types to indicate a literal string and a Symbol.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Implementation of the Session&#39;s command queue.
ExecResult execSync()
invoke using a default "synchronous" execution pattern
Definition: command.cpp:459
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:124
RET bind()
Accept dummy binding (0 Arg)
Actually defining a command and binding it to execution parameters.