53 using LERR_(LIFECYCLE);
54 using LERR_(INVALID_COMMAND);
55 using LERR_(DUPLICATE_COMMAND);
56 using LERR_(UNBOUND_ARGUMENTS);
62 const string INVOCATION_ID =
"CommandInstanceManager_test";
67 std::deque<Command> queue_;
81 queue_.emplace_front (move (
cmd));
88 return queue_.end()!= std::find_if (queue_.begin()
122 verify_simpleUsage();
123 verify_extendedUsage();
124 verify_instanceIdentity();
146 CHECK (not iManager.contains (COMMAND_PROTOTYPE));
148 int r1{rand()%1000}, r2{rand()%2000};
149 command1::check_ = 0;
152 CHECK (not iManager.contains (COMMAND_PROTOTYPE));
154 Command com{COMMAND_PROTOTYPE};
156 CHECK (com.canExec());
158 iManager.dispatch (COMMAND_PROTOTYPE);
159 CHECK (not iManager.contains (COMMAND_PROTOTYPE));
165 CHECK (command1::check_ == 0);
167 CHECK (command1::check_ == r1 + r2);
180 Symbol instanceID = iManager.newInstance (COMMAND_PROTOTYPE, INVOCATION_ID);
181 CHECK (iManager.contains (instanceID));
183 Command cmd = iManager.getInstance (instanceID);
185 CHECK (not cmd.canExec());
188 CHECK (cmd.canExec());
190 iManager.dispatch (instanceID);
191 CHECK (fixture.contains (cmd));
192 CHECK (not iManager.contains (instanceID));
193 VERIFY_ERROR (LIFECYCLE, iManager.getInstance (instanceID));
195 command1::check_ = 0;
197 CHECK (command1::check_ == 42);
224 Symbol i1 = iManager.newInstance (COMMAND_PROTOTYPE,
"i1");
225 Symbol i2 = iManager.newInstance (COMMAND_PROTOTYPE,
"i2");
227 Command c11 = iManager.getInstance (i1);
228 Command c12 = iManager.getInstance (i1);
230 CHECK (c11.isValid());
231 CHECK (not c11.canExec());
233 int r1{rand()%100}, r2{rand()%200}, r3{rand()%300};
234 command1::check_ = 0;
237 CHECK (c12.canExec());
238 CHECK (c11.canExec());
240 Command c2 = iManager.getInstance (i2);
245 CHECK (iManager.contains (i1));
246 CHECK (iManager.contains (i2));
247 CHECK (not fixture.contains (c11));
248 CHECK (not fixture.contains (c12));
249 CHECK (not fixture.contains (c2));
251 iManager.dispatch (i1);
252 CHECK (not iManager.contains (i1));
253 CHECK ( iManager.contains (i2));
254 CHECK ( fixture.contains (c11));
255 CHECK ( fixture.contains (c12));
256 CHECK (not fixture.contains (c2));
258 CHECK (command1::check_ == 0);
260 Symbol i11 = iManager.newInstance (COMMAND_PROTOTYPE,
"i1");
262 CHECK ((
const char*)i11 == (
const char*) i1);
265 Command c13 = iManager.getInstance (i1);
268 CHECK (c11.canExec());
269 CHECK (not c13.canExec());
272 CHECK (c13.canExec());
274 CHECK (command1::check_ == 0);
276 CHECK (command1::check_ == 0+r1);
280 CHECK (command1::check_ == 0+r1+r2);
282 CHECK ( iManager.contains (i1));
283 CHECK ( iManager.contains (i2));
284 CHECK ( fixture.contains (c11));
285 CHECK ( fixture.contains (c12));
286 CHECK (not fixture.contains (c2));
288 iManager.dispatch (i2);
289 iManager.dispatch (i11);
290 CHECK (not iManager.contains (i1));
291 CHECK (not iManager.contains (i2));
292 CHECK ( fixture.contains (c11));
293 CHECK ( fixture.contains (c12));
294 CHECK ( fixture.contains (c13));
295 CHECK ( fixture.contains (c2));
303 CHECK (command1::check_ == 0+r1+r2+47+r3+r3);
306 CHECK (command1::check_ == 0);
308 CHECK (command1::check_ == 0+r1+r2);
310 CHECK (command1::check_ == 0);
325 Symbol i1 = iManager.newInstance (COMMAND_PROTOTYPE,
"i1");
326 Symbol i2 = iManager.newInstance (COMMAND_PROTOTYPE,
"i2");
328 VERIFY_ERROR (DUPLICATE_COMMAND, iManager.newInstance (COMMAND_PROTOTYPE,
"i1"));
329 VERIFY_ERROR (DUPLICATE_COMMAND, iManager.newInstance (COMMAND_PROTOTYPE,
"i2"));
331 iManager.bindAndDispatch (i1, {-1});
333 iManager.newInstance (COMMAND_PROTOTYPE,
"i1");
334 VERIFY_ERROR (DUPLICATE_COMMAND, iManager.newInstance (COMMAND_PROTOTYPE,
"i2"));
336 CHECK (iManager.getInstance (i1));
337 CHECK (iManager.getInstance (i2));
355 Symbol instanceID{COMMAND_PROTOTYPE, INVOCATION_ID};
356 VERIFY_ERROR (INVALID_COMMAND, iManager.getInstance (instanceID));
357 VERIFY_ERROR (INVALID_COMMAND, iManager.dispatch (instanceID));
359 Symbol i2 = iManager.newInstance (COMMAND_PROTOTYPE, INVOCATION_ID);
360 CHECK (i2 == instanceID);
361 CHECK (iManager.getInstance (instanceID));
364 Command cmd = iManager.getInstance (instanceID);
366 CHECK (not cmd.canExec());
368 VERIFY_ERROR (UNBOUND_ARGUMENTS, iManager.dispatch (instanceID));
369 VERIFY_ERROR (DUPLICATE_COMMAND, iManager.newInstance (COMMAND_PROTOTYPE, INVOCATION_ID));
370 CHECK (iManager.contains (instanceID));
373 CHECK (cmd.canExec());
374 iManager.dispatch (instanceID);
376 CHECK (not iManager.contains (instanceID));
377 VERIFY_ERROR (LIFECYCLE, iManager.getInstance (instanceID));
378 VERIFY_ERROR (LIFECYCLE, iManager.dispatch (instanceID));
379 CHECK (instanceID == iManager.newInstance (COMMAND_PROTOTYPE, INVOCATION_ID));
391 CHECK (not iManager.contains (COMMAND_PROTOTYPE));
392 Command cmd = iManager.getInstance (COMMAND_PROTOTYPE);
394 CHECK (cmd.isValid());
395 CHECK (not cmd.isAnonymous());
397 CHECK (cmd ==
Command{COMMAND_PROTOTYPE});
400 CHECK (cmd.canExec());
401 CHECK (not fixture.contains(cmd));
403 iManager.dispatch (COMMAND_PROTOTYPE);
404 CHECK (fixture.contains(cmd));
406 command1::check_ = 0;
408 CHECK (command1::check_ == -12);
void verify_extendedUsage()
Conveniently iterable stack and queue containers.
inline string literal This is a marker type to indicate that
Maintain a current command instance for parametrisation.
void verify_simpleUsage()
Service to support forming and invocation of command instances for use by the UI. ...
CommandSetup test_Dummy_command1
test dummy command to add the argument to a global variable
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
static Command get(Symbol cmdID)
Access existing command for use.
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
Token or Atom with distinct identity.
Simple test class runner.
Interface of a service to perform Commands on the session.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Some dummy command functions used for building unit test cases.
Handle object representing a single Command instance to be used by client code.
void bindAndDispatch(Symbol instanceID, Rec const &argSeq)
fire and forget anonymous command instance.
RET bind()
Accept dummy binding (0 Arg)
void verify_instanceIdentity()