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)
5  2016, 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 
14 
15 #include "lib/test/run.hpp"
18 #include "lib/symbol.hpp"
19 #include "lib/util.hpp"
20 
22 
23 
24 namespace steam {
25 namespace control{
26 namespace test {
27 
28  using lib::Symbol;
29  using util::isnil;
30  using LERR_(UNBOUND_ARGUMENTS);
31 
32 
33  namespace { // test fixture...
34 
35  const Symbol COMMAND_1{"test.queue.command1"};
36  const Symbol COMMAND_3{"test.queue.command3"};
37 
38  }//(End) test fixture
39 
40 
41 
42 
43  /******************************************************************************/
52  class CommandQueue_test : public Test
53  {
54 
55  //------------------FIXTURE
56  public:
58  {
59  CommandDef (COMMAND_1)
60  .operation (command1::operate)
61  .captureUndo (command1::capture)
62  .undoOperation (command1::undoIt)
63  ;
64  CommandDef (COMMAND_3)
65  .operation (command3::operate)
66  .captureUndo (command3::capture)
67  .undoOperation (command3::undoIt)
68  ;
69  }
71  {
72  Command::remove (COMMAND_1);
73  Command::remove (COMMAND_3);
74  }
75  //-------------(End)FIXTURE
76 
77 
78  virtual void
79  run (Arg)
80  {
81  verifyBasics();
82  verifyExecutabilityCheck();
83  }
84 
85 
86  void
87  verifyBasics()
88  {
89  Command com11 = Command(COMMAND_1).newInstance();
90  Command com12 = Command(COMMAND_1).newInstance();
91 
92  com11.bind(42);
93  com12.bind(47);
94 
95  CommandQueue queue;
96  CHECK (isnil(queue));
97 
98  queue.feed (Command{com11});
99  queue.feed (Command{com12});
100 
101  CHECK (2 == queue.size());
102 
103  Command x = queue.pop();
104  CHECK (1 == queue.size());
105  CHECK (x == com11);
106 
107  queue.clear();
108  CHECK (0 == queue.size());
109  CHECK (queue.empty());
110  }
111 
112 
113  void
114  verifyExecutabilityCheck()
115  {
116  Command com11 = Command(COMMAND_1).newInstance();
117  Command com12 = Command(COMMAND_1).newInstance();
118 
119  com11.bind(42);
120  // NOT binding the second command...
121 
122  CommandQueue queue;
123  queue.feed (Command{com11});
124  CHECK (1 == queue.size());
125 
126  VERIFY_ERROR (UNBOUND_ARGUMENTS, queue.feed (Command{com12}));
127  CHECK (1 == queue.size());
128 
129  queue.pop().execSync();
130  VERIFY_ERROR (UNBOUND_ARGUMENTS, com12.execSync());
131  }
132  };
133 
134 
136  LAUNCHER (CommandQueue_test, "unit controller");
137 
138 
139 }}} // namespace steam::control::test
Helper class used solely for defining a Command-Object.
Definition: run.hpp:40
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition: command.cpp:200
#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:117
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...
Implementation of the Session&#39;s command queue.
ExecResult execSync()
invoke using a default "synchronous" execution pattern
Definition: command.cpp:450
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:115
RET bind()
Accept dummy binding (0 Arg)
Actually defining a command and binding it to execution parameters.