44 using LERR_(INVALID_COMMAND);
45 using LERR_(DUPLICATE_COMMAND);
46 using LERR_(UNBOUND_ARGUMENTS);
47 using LERR_(INVALID_ARGUMENTS);
63 int random() {
return randVal = 10 + (rand() % 40); }
80 stringRepresentation();
83 CHECK (0 == command1::check_);
94 .operation (command1::operate)
95 .captureUndo (command1::capture)
96 .undoOperation (command1::undoIt)
101 CHECK (randVal == command1::check_);
104 CHECK ( 0 == command1::check_);
113 .operation (command1::operate)
114 .captureUndo (command1::capture)
115 .undoOperation (command1::undoIt)
120 Command com (
"test.command1.2");
123 CHECK (contains (
string(com),
"test.command1.2"));
124 CHECK (contains (
string(com),
"{def}"));
125 CHECK (!com.canExec());
127 CHECK ( 0 == command1::check_);
131 CHECK ( com.canExec());
132 CHECK (!com.canUndo());
134 CHECK (randVal == command1::check_);
136 CHECK ( 0 == command1::check_);
139 invoke (
"test.command1.2") (1234);
140 CHECK ( 1234 == command1::check_);
143 CHECK ( 0 == command1::check_);
150 Command::remove(
"test.command1.2");
156 def.operation (command1::operate)
157 .captureUndo (command1::capture);
161 def.operation (command1::operate)
162 .captureUndo (command1::capture)
163 .undoOperation (command1::undoIt);
168 CHECK ( Command::defined(
"test.command1.2"));
169 CHECK (!Command::canExec(
"test.command1.2"));
170 CHECK (!Command::canUndo(
"test.command1.2"));
174 CHECK (!com.canExec());
175 CHECK (!com.canUndo());
178 CHECK ( Command::defined(
"test.command1.2"));
179 CHECK ( Command::canExec(
"test.command1.2"));
180 CHECK (!Command::canUndo(
"test.command1.2"));
183 CHECK ( Command::defined(
"test.command1.2"));
184 CHECK ( Command::canExec(
"test.command1.2"));
185 CHECK ( Command::canUndo(
"test.command1.2"));
188 CHECK ( Command::defined(
"test.command1.2"));
189 CHECK ( Command::canExec(
"test.command1.2"));
190 CHECK ( Command::canUndo(
"test.command1.2"));
193 CHECK ( Command::defined(
"test.command1.2"));
194 CHECK (!Command::canExec(
"test.command1.2"));
195 CHECK (!Command::canUndo(
"test.command1.2"));
203 .operation (command1::operate)
204 .captureUndo (command1::capture)
205 .undoOperation (command1::undoIt)
218 CHECK (c1.canExec());
219 CHECK (!c1.canUndo());
223 CHECK (c2.canExec());
224 CHECK (!c2.canUndo());
225 CHECK (c2.isAnonymous());
228 CHECK (!isSameObject(c1, c2));
230 CHECK (0 == command1::check_);
234 CHECK (randVal == command1::check_);
235 CHECK ( c1.canUndo());
236 CHECK (!c2.canUndo());
239 CHECK (randVal + randVal == command1::check_);
240 CHECK (c2.canUndo());
244 CHECK (0 == command1::check_);
246 CHECK (randVal == command1::check_);
250 CHECK (randVal + 23 == command1::check_);
254 CHECK (randVal + 23 + randVal == command1::check_);
256 CHECK (randVal + 23 == command1::check_);
261 CHECK (randVal == command1::check_);
263 CHECK (randVal + 23 == command1::check_);
266 c2.storeDef (
"test.command1.4");
269 CHECK (c4.canExec());
270 CHECK (c4.canUndo());
272 CHECK ( c2.isAnonymous());
277 CHECK (randVal + 2*23 == command1::check_);
279 c4.
bind(
int(-command1::check_));
281 CHECK (0 == command1::check_);
283 CHECK (23 == command1::check_);
285 CHECK (0 == command1::check_);
289 CHECK (c2.canExec());
290 CHECK (c2.canUndo());
291 CHECK (not c4.canExec());
292 CHECK (not c4.canUndo());
299 #define BUILD_NEW_COMMAND_DEF(_ID_) \ 301 .operation (command1::operate) \ 302 .captureUndo (command1::capture) \ 303 .undoOperation (command1::undoIt) 306 VERIFY_ERROR (DUPLICATE_COMMAND, BUILD_NEW_COMMAND_DEF (
"test.command1.1") );
308 VERIFY_ERROR (DUPLICATE_COMMAND, BUILD_NEW_COMMAND_DEF (
"test.command1.2") );
310 VERIFY_ERROR (DUPLICATE_COMMAND, BUILD_NEW_COMMAND_DEF (
"test.command1.3") );
312 VERIFY_ERROR (DUPLICATE_COMMAND, BUILD_NEW_COMMAND_DEF (
"test.command1.4") );
317 stringRepresentation()
327 .operation (command1::operate)
328 .captureUndo (command1::capture)
329 .undoOperation (command1::undoIt);
355 VERIFY_ERROR (INVALID_COMMAND, invoke (
"miracle") (1,2,3));
358 CHECK (!unbelievable);
366 CHECK (!miracle.canExec());
367 CHECK (!miracle.canUndo());
372 CHECK (Command::remove(
"test.command1.1"));
373 CHECK (Command::remove(
"test.command1.2"));
374 CHECK (Command::remove(
"test.command1.3"));
375 CHECK (Command::remove(
"test.command1.4"));
376 CHECK (Command::remove(
"test.command1.5"));
378 CHECK (!Command::remove(
"miracle"));
391 CHECK (c5.isValid());
392 CHECK (c5.canExec());
Some additional helpers and convenience shortcuts to ease command invocation.
Helper class used solely for defining a Command-Object.
static size_t definition_count()
Command newInstance() const
create independent (anonymous) clone copy of this command
#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.
static size_t instance_count()
Command & unbind()
discard any argument data previously bound.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
ExecResult execSync()
invoke using a default "synchronous" execution pattern
Some dummy command functions used for building unit test cases.
Handle object representing a single Command instance to be used by client code.
RET bind()
Accept dummy binding (0 Arg)
Actually defining a command and binding it to execution parameters.
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.