Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
command-queue-test.cpp
Go to the documentation of this file.
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
24namespace steam {
25namespace control{
26namespace 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)
61 .captureUndo (command1::capture)
62 .undoOperation (command1::undoIt)
63 ;
64 CommandDef (COMMAND_3)
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 {
83 }
84
85
86 void
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
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
Token or Atom with distinct identity.
Definition symbol.hpp:120
Helper class used solely for defining a Command-Object.
auto operation(FUN operation_to_define)
Implementation of the Session's command queue.
CommandQueue & feed(Command &&cmd)
Handle object representing a single Command instance to be used by client code.
Definition command.hpp:120
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition command.cpp:200
static bool remove(Symbol cmdID)
Definition command.cpp:241
Actually defining a command and binding it to execution parameters.
Implementation building block of SteamDispatcher to organise commands.
#define LERR_(_NAME_)
Definition error.hpp:45
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
void undoIt(int, int64_t oldVal)
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
size_t size() const
bool empty() const
Marker types to indicate a literal string and a Symbol.
Some dummy command functions used for building unit test cases.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...