41 using std::ostringstream;
42 using std::make_tuple;
50 using lib::test::showSizeof;
53 using LERR_(MISSING_MEMENTO);
70 static int instanceCnt;
72 Tracker (TY init = TY()) : element_(init) { ++instanceCnt; }
73 Tracker (
Tracker const& otr) : element_(otr.element_) { ++instanceCnt; }
82 operator string()
const {
return element_; }
88 return tra1.element_ == tra2.element_;
130 static _Fmt fmt (
"doIt( Time=%s \"%s\" rand=%2d )");
131 cout <<
"invoke operation..." << endl;
132 protocol << fmt % *time % *str % rand;
138 cout <<
"capture state..." << endl;
139 return protocol.str() + *xstr;
145 cout <<
"undo... memento=" << memento << endl;
146 protocol <<
"undoIt(time="<<time<<
")----memento-:"<< *memento;
152 int dummyC (
int u,
int o) {
return u +
rani(o-u+1); }
165 TODO (
"implement serialisation/de-serialisation-Check");
166 cout <<
"would be serialised....." << clo << endl;
175 return 10 +
rani(90);
201 ArgTuples testTuples;
203 Tracker<TimeVar>::instanceCnt = 0;
204 Tracker<string>::instanceCnt = 0;
206 createTuples (testTuples);
207 serialiseArgTuples (testTuples);
210 simulateCmdLifecycle();
213 CHECK (0 == Tracker<TimeVar>::instanceCnt);
214 CHECK (0 == Tracker<string>::instanceCnt);
218 typedef Tracker<TimeVar> TTime;
219 typedef Tracker<string> Tstr;
236 A1* arg1 =
new A1(); tup.
manage (arg1);
237 A2* arg2 =
new A2(); tup.
manage (arg2);
238 A3* arg3 =
new A3(); tup.
manage (arg3);
239 A4* arg4 =
new A4(); tup.
manage (arg4);
240 A5* arg5 =
new A5(); tup.
manage (arg5);
242 CHECK (isnil (*arg1));
243 CHECK (isnil (*arg2));
244 CHECK (isnil (*arg3));
245 CHECK (isnil (*arg4));
246 CHECK (isnil (*arg5));
248 for_each (tup, showIt);
250 arg1->storeTuple (std::tuple<>());
251 arg2->storeTuple (make_tuple (
rani(10)));
252 arg3->storeTuple (make_tuple (
rani(10),
TimeVar(randTime())));
253 arg4->storeTuple (make_tuple (
rani(10),
TimeVar(randTime())));
255 arg5->storeTuple (make_tuple (TTime (randTime()), Tstr(
"glorious"), twoRandomDigits() ));
257 CHECK (!arg5->canUndo());
259 arg5->tie(undoIt, captureState)
261 (TTime(), Tstr(
"destruction"), 11);
263 CHECK (arg5->canUndo());
264 CHECK (*arg5->memento() ==
"destruction");
266 VERIFY_ERROR(MISSING_MEMENTO, arg4->memento().i[3] = 513 );
268 for_each (tup, showIt);
279 for_each (tup, checkSerialisation);
290 typedef void SIG_do(Tracker<TimeVar>, Tracker<string>,
int);
295 CHECK (isnil (args));
296 cout << showSizeof(args) << endl;
300 make_tuple (TTime(randTime()), Tstr(
"Lumiera rocks"), twoRandomDigits() ));
301 CHECK (!isnil (args));
302 cout << args << endl;
304 CHECK (!args.canUndo());
307 MemHolder& memHolder = args.tie(undoIt,captureState);
309 CHECK (!args.canUndo());
311 function<SIG_do> doItFun = doIt;
312 function<SIG_do> undoFun = memHolder.tieUndoFunc();
313 function<SIG_do> captFun = memHolder.tieCaptureFunc();
315 typedef function<void()> OpFun;
326 cout <<
"captured state: " << args.memento() << endl;
328 CHECK (!isnil (*args.memento()));
329 CHECK (args.canUndo());
330 cout << args << endl;
338 Args argsCopy (args);
344 make_tuple (TTime(
TimeValue(123456)), Tstr(
"unbelievable"), twoRandomDigits() ));
345 cout <<
"modified: " << args << endl;
346 cout <<
"copied : " << argsCopy << endl;
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
FunErasure< StoreFunction > CmdFunctor
A neutral container internally holding the functor used to implement the Command. ...
void prepareEmptyMemento()
prepare a (singleton) empty value for the memento.
ostringstream protocol
used to verify the test function calls
int rani(uint bound=_iBOUND())
Singleton holder for NIL or default value objects.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
void createTuples(ArgTuples &tup)
void simulateCmdLifecycle()
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
Managing lifecycle for a collection of objects.
Simple vector based collection of pointers, managing lifecycle of the pointed-to objects.
watching the instance creation of some parameter values
Lumiera's internal time value datatype.
virtual void invoke(CmdFunctor const &)=0
invoke functor using the stored parameter values
void dummyU(int, int, int)
another dummy-UNDO function
Simplistic test class runner.
void serialiseArgTuples(ArgTuples &tup)
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
A collection of frequently used helper functions to support unit testing.
Dummy custom memento datatype.
lib::time::Time randTime()
create a random but not insane Time value between 1s ...
basic constant internal time value.
Binding together state capturing and execution of the undo operation.
Perform operations "for each element" of a collection.
T & manage(T *obj)
take ownership of the given object, adding it at the end of the collection
This is "the" top level CmdClosure implementation.
A passive container record holding the actual command arguments & UNDO state.