Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
handling-pattern-basics-test.cpp
Go to the documentation of this file.
1/*
2 HandlingPatternBasics(Test) - verify elementary operation of a command handling pattern
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"
26
28
29
30namespace steam {
31namespace control{
32namespace test {
33
34 using std::function;
35
36 namespace { // test fixture...
37
38 string TEST_CMD = "test.command1.handling";
39 HandlingPattern::ID TEST_PATTERN = HandlingPattern::DUMMY;
40
41
43 : public HandlingPattern
44 {
45 mutable
46 lib::test::EventLog log_{"custom command handler"};
47
48
49 /* ==== HandlingPattern - Interface ==== */
50
51 void
53 {
54 log_.call (TEST_CMD, "exec");
55 command.invokeCapture();
56 command.invokeOperation();
57 }
58
59 void
61 {
62 log_.call (TEST_CMD, "undo");
63 command.invokeUndo();
64 }
65
66 bool
67 isValid() const override
68 {
69 return true;
70 }
71
72
73 public:
74 bool
76 {
77 return log_.verifyCall("exec").on(TEST_CMD);
78 }
79
80 bool
82 {
83 return log_.verifyCall("undo").on(TEST_CMD)
84 .afterCall("exec");
85 }
86 };
87
88 }//(End) test fixture
89
91 using HaPatt = HandlingPattern const&;
92
93
94
95
96
97
98 /******************************************************************************/
108 class HandlingPatternBasics_test : public Test
109 {
110
112
113
114 virtual void
115 run (Arg)
116 {
117 seedRand();
119 CHECK (&registry);
120
121 cnt_inst = registry.instance_count();
122
123 {
125 checkExec (pCom);
126 checkUndo (pCom);
127
129 }
130
131 CHECK (cnt_inst == registry.instance_count());
132 }
133
134
142 {
143
144 typedef void Sig_oper(int);
145 typedef long Sig_capt(int);
146 typedef void Sig_undo(int,long);
147
151
153
154 // when the CommandDef is complete, it issues the
155 // allocation call to the registry behind the scenes....
156
158 CHECK (pImpl);
159 CHECK (*pImpl);
160 return pImpl;
161 }
162
163
165 void
167 {
168 CHECK (com);
169 CHECK (not com->canExec());
170
171 using ArgTuple = std::tuple<int>;
172 const int ARGR{1 + rani (1000)};
173 ArgTuple argTup{ARGR};
175 com->setArguments(arg);
176
177 CHECK (com->canExec());
178 CHECK (!com->canUndo());
180
181 HaPatt patt = HandlingPattern::get(TEST_PATTERN);
182 ExecResult res = patt.exec (*com, TEST_CMD);
183
184 CHECK (res);
186 CHECK (com->canUndo());
187 }
188
189
191 void
193 {
194 CHECK (com);
195 CHECK (com->canExec());
196 CHECK (com->canUndo());
197
199
200 HaPatt ePatt = HandlingPattern::get(TEST_PATTERN);
201 ExecResult res = ePatt.undo (*com, TEST_CMD);
202
203 CHECK (res);
204 CHECK (command1::check_ == 0);
205 }
206
207
211 void
213 {
214 CustomHandler specialHandler;
215
216 CHECK (com->canExec());
217 CHECK (not specialHandler.invokedExec());
218
219 specialHandler.exec (*com, TEST_CMD);
220 CHECK ( specialHandler.invokedExec());
221 CHECK (not specialHandler.invokedUndo());
222
223 specialHandler.undo (*com, TEST_CMD);
224 CHECK ( specialHandler.invokedExec());
225 }
226 };
227
228
230 LAUNCHER (HandlingPatternBasics_test, "function controller");
231
232
233}}} // namespace steam::control::test
Implementation helper to bind Steam-Layer commands with arbitrary argument tuples.
Helper to log and verify the occurrence of events.
Steam-Layer Command implementation.
Registry managing command implementation objects (Singleton).
shared_ptr< CommandImpl > newCommandImpl(function< SIG_OPER > &operFunctor, function< SIG_CAPT > &captFunctor, function< SIG_UNDO > &undoFunctor)
set up a new command implementation frame
static lib::Depend< CommandRegistry > instance
storage for the singleton factory used to access CommandRegistry
Result (Status) of command execution.
Interface: Operation Skeleton how to invoke or undo a command.
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
PCommandImpl buildTestCommand(CommandRegistry &registry)
create a command implementation frame usable for tests.
Top level of the command implementation.
Managing command definitions and the storage of individual command objects.
Steam-Layer command frontend.
Support for verifying the occurrence of events from unit tests.
Pre-defined command execution skeletons.
unsigned int uint
Definition integral.hpp:29
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)
int64_t check_
< test command just adding a given value
shared_ptr< CommandImpl > PCommandImpl
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Some dummy command functions used for building unit test cases.