2009-06-28 15:27:27 +02:00
|
|
|
|
/*
|
|
|
|
|
|
CommandArgument(Test) - checking storage of specifically typed command arguments
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file command-argument-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref CommandArgument_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/control/command-storage-holder.hpp"
|
2009-07-11 20:06:35 +02:00
|
|
|
|
#include "lib/scoped-ptrvect.hpp"
|
2013-09-01 17:36:05 +02:00
|
|
|
|
#include "lib/format-string.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2009-12-29 04:39:27 +01:00
|
|
|
|
#include "lib/util-foreach.hpp"
|
2009-07-11 20:06:35 +02:00
|
|
|
|
#include "lib/util.hpp"
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
|
#include <functional>
|
2009-07-13 01:16:30 +02:00
|
|
|
|
#include <sstream>
|
2009-07-19 08:32:49 +02:00
|
|
|
|
#include <cstdlib>
|
2009-06-28 15:27:27 +02:00
|
|
|
|
#include <string>
|
2016-01-17 23:55:41 +01:00
|
|
|
|
#include <tuple>
|
2025-04-15 23:40:14 +02:00
|
|
|
|
#include <array>
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
2013-09-01 17:36:05 +02:00
|
|
|
|
using util::_Fmt;
|
2009-07-11 20:06:35 +02:00
|
|
|
|
using util::isnil;
|
2009-07-18 19:36:32 +02:00
|
|
|
|
using util::for_each;
|
2011-05-16 08:38:27 +02:00
|
|
|
|
using lib::time::Time;
|
|
|
|
|
|
using lib::time::TimeVar;
|
|
|
|
|
|
using lib::time::TimeValue;
|
2009-06-28 15:27:27 +02:00
|
|
|
|
using std::string;
|
2009-07-13 01:16:30 +02:00
|
|
|
|
using std::ostringstream;
|
2016-01-17 23:55:41 +01:00
|
|
|
|
using std::make_tuple;
|
2009-07-20 07:03:18 +02:00
|
|
|
|
using std::rand;
|
2009-06-28 15:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2009-06-28 15:27:27 +02:00
|
|
|
|
namespace control {
|
|
|
|
|
|
namespace test {
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
using lib::test::showSizeof;
|
2009-07-13 01:16:30 +02:00
|
|
|
|
using lib::test::randTime;
|
2011-12-03 02:56:50 +01:00
|
|
|
|
using namespace lib::meta;
|
2024-03-16 02:04:47 +01:00
|
|
|
|
using LERR_(MISSING_MEMENTO);
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
namespace { // test helpers
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-13 01:16:30 +02:00
|
|
|
|
ostringstream protocol; ///< used to verify the test function calls
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
/**
|
2009-07-20 07:03:18 +02:00
|
|
|
|
* watching the instance creation
|
2010-12-10 02:55:40 +01:00
|
|
|
|
* of some parameter values
|
2009-07-20 07:03:18 +02:00
|
|
|
|
*/
|
2009-07-11 20:06:35 +02:00
|
|
|
|
template<typename TY>
|
|
|
|
|
|
struct Tracker
|
|
|
|
|
|
{
|
|
|
|
|
|
TY element_;
|
|
|
|
|
|
static int instanceCnt;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-19 08:32:49 +02:00
|
|
|
|
Tracker (TY init = TY()) : element_(init) { ++instanceCnt; }
|
|
|
|
|
|
Tracker (Tracker const& otr) : element_(otr.element_) { ++instanceCnt; }
|
|
|
|
|
|
~Tracker() { --instanceCnt; }
|
2025-04-15 18:32:52 +02:00
|
|
|
|
|
|
|
|
|
|
Tracker& operator= (Tracker const&) = default;
|
|
|
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
|
TY&
|
|
|
|
|
|
operator* ()
|
|
|
|
|
|
{
|
|
|
|
|
|
return element_;
|
|
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
|
operator string() const { return element_; }
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
|
friend bool
|
|
|
|
|
|
operator== (Tracker const& tra1, Tracker const& tra2)
|
|
|
|
|
|
{
|
|
|
|
|
|
return tra1.element_ == tra2.element_;
|
|
|
|
|
|
}
|
2009-07-11 20:06:35 +02:00
|
|
|
|
};
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
template<typename TY>
|
|
|
|
|
|
int Tracker<TY>::instanceCnt (0);
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
|
/** Dummy custom memento datatype
|
|
|
|
|
|
* @note memento needs to be equality comparable
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct Sint5
|
|
|
|
|
|
{
|
2025-04-15 23:40:14 +02:00
|
|
|
|
std::array<int,5> i5i;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-10-05 04:29:06 +02:00
|
|
|
|
friend bool
|
|
|
|
|
|
operator== (Sint5 const& i1, Sint5 const& i2)
|
|
|
|
|
|
{
|
2025-04-15 23:40:14 +02:00
|
|
|
|
return i1.i5i == i2.i5i;
|
2009-10-05 04:29:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
/* === functions to implement test-"operation" & UNDO === */
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
void
|
2011-05-16 08:38:27 +02:00
|
|
|
|
doIt (Tracker<TimeVar> time, Tracker<string> str, int rand)
|
2009-07-11 20:06:35 +02:00
|
|
|
|
{
|
2013-09-01 17:36:05 +02:00
|
|
|
|
static _Fmt fmt ("doIt( Time=%s \"%s\" rand=%2d )");
|
2009-07-20 07:03:18 +02:00
|
|
|
|
cout << "invoke operation..." << endl;
|
2009-07-11 20:06:35 +02:00
|
|
|
|
protocol << fmt % *time % *str % rand;
|
|
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
Tracker<string>
|
2011-05-16 08:38:27 +02:00
|
|
|
|
captureState (Tracker<TimeVar>, Tracker<string> xstr, int)
|
2009-07-11 20:06:35 +02:00
|
|
|
|
{
|
2009-07-20 07:03:18 +02:00
|
|
|
|
cout << "capture state..." << endl;
|
2009-07-19 08:32:49 +02:00
|
|
|
|
return protocol.str() + *xstr;
|
2009-07-11 20:06:35 +02:00
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
void
|
2011-05-16 08:38:27 +02:00
|
|
|
|
undoIt (Tracker<TimeVar> time, Tracker<string>, int, Tracker<string> memento)
|
2009-07-11 20:06:35 +02:00
|
|
|
|
{
|
2009-07-20 07:03:18 +02:00
|
|
|
|
cout << "undo... memento=" << memento << endl;
|
|
|
|
|
|
protocol << "undoIt(time="<<time<<")----memento-:"<< *memento;
|
2009-07-11 20:06:35 +02:00
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
/// another dummy-UNDO function
|
2009-07-20 05:09:46 +02:00
|
|
|
|
void dummyU (int,int,int) { }
|
2024-11-13 02:23:23 +01:00
|
|
|
|
int dummyC (int u,int o) { return u + rani(o-u+1); }
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
void
|
|
|
|
|
|
showIt (CmdClosure& clo)
|
|
|
|
|
|
{
|
|
|
|
|
|
cout << clo << endl;
|
|
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
void
|
|
|
|
|
|
checkSerialisation (CmdClosure& clo)
|
|
|
|
|
|
{
|
|
|
|
|
|
TODO ("implement serialisation/de-serialisation-Check");
|
2009-07-19 08:32:49 +02:00
|
|
|
|
cout << "would be serialised....." << clo << endl;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
// serialise, then de-serialise into a new instance and compare both
|
|
|
|
|
|
}
|
2011-11-27 02:15:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
twoRandomDigits()
|
|
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
return 10 + rani(90);
|
2011-11-27 02:15:11 +01:00
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
} // test-helper implementation
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
typedef lib::ScopedPtrVect<CmdClosure> ArgTuples;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/***********************************************************************//**
|
2009-07-11 20:06:35 +02:00
|
|
|
|
* @test Check storage handling of the command parameters and state memento.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
*
|
2016-02-06 16:29:06 +01:00
|
|
|
|
* @see control::CommandStorageHolder
|
2009-06-28 15:27:27 +02:00
|
|
|
|
* @see command-basic-test.hpp
|
|
|
|
|
|
*/
|
|
|
|
|
|
class CommandArgument_test : public Test
|
|
|
|
|
|
{
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
virtual void
|
2010-12-10 02:55:40 +01:00
|
|
|
|
run (Arg)
|
2009-06-28 15:27:27 +02:00
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
2009-07-11 20:06:35 +02:00
|
|
|
|
ArgTuples testTuples;
|
2011-05-16 08:38:27 +02:00
|
|
|
|
Tracker<TimeVar>::instanceCnt = 0;
|
2009-07-11 20:06:35 +02:00
|
|
|
|
Tracker<string>::instanceCnt = 0;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-18 19:36:32 +02:00
|
|
|
|
createTuples (testTuples);
|
2009-07-19 08:32:49 +02:00
|
|
|
|
serialiseArgTuples (testTuples);
|
|
|
|
|
|
testTuples.clear();
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
simulateCmdLifecycle();
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
// verify all dtors properly called...
|
2011-05-16 08:38:27 +02:00
|
|
|
|
CHECK (0 == Tracker<TimeVar>::instanceCnt);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (0 == Tracker<string>::instanceCnt);
|
2009-07-11 20:06:35 +02:00
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2011-05-16 08:38:27 +02:00
|
|
|
|
typedef Tracker<TimeVar> TTime;
|
2009-07-19 08:32:49 +02:00
|
|
|
|
typedef Tracker<string> Tstr;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
/** @test create various argument tuples and re-access their contents */
|
|
|
|
|
|
void
|
|
|
|
|
|
createTuples (ArgTuples& tup)
|
|
|
|
|
|
{
|
2016-02-06 16:29:06 +01:00
|
|
|
|
typedef StorageHolder<void(), bool> A1;
|
|
|
|
|
|
typedef StorageHolder<void(int), void*> A2;
|
|
|
|
|
|
typedef StorageHolder<void(int,TimeVar), int> A3;
|
|
|
|
|
|
typedef StorageHolder<void(int,TimeVar), Sint5> A4;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2016-02-06 16:29:06 +01:00
|
|
|
|
typedef StorageHolder<void(TTime,Tstr,int), Tstr> A5;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2009-07-18 19:36:32 +02:00
|
|
|
|
A1* arg1 = new A1(); tup.manage (arg1);
|
|
|
|
|
|
A2* arg2 = new A2(); tup.manage (arg2);
|
|
|
|
|
|
A3* arg3 = new A3(); tup.manage (arg3);
|
|
|
|
|
|
A4* arg4 = new A4(); tup.manage (arg4);
|
|
|
|
|
|
A5* arg5 = new A5(); tup.manage (arg5);
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (isnil (*arg1));
|
|
|
|
|
|
CHECK (isnil (*arg2));
|
|
|
|
|
|
CHECK (isnil (*arg3));
|
|
|
|
|
|
CHECK (isnil (*arg4));
|
|
|
|
|
|
CHECK (isnil (*arg5));
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
for_each (tup, showIt);
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2016-01-17 23:55:41 +01:00
|
|
|
|
arg1->storeTuple (std::tuple<>());
|
2024-11-13 02:23:23 +01:00
|
|
|
|
arg2->storeTuple (make_tuple (rani(10)));
|
|
|
|
|
|
arg3->storeTuple (make_tuple (rani(10), TimeVar(randTime())));
|
|
|
|
|
|
arg4->storeTuple (make_tuple (rani(10), TimeVar(randTime())));
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2016-01-17 23:55:41 +01:00
|
|
|
|
arg5->storeTuple (make_tuple (TTime (randTime()), Tstr("glorious"), twoRandomDigits() ));
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!arg5->canUndo());
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-19 08:32:49 +02:00
|
|
|
|
arg5->tie(undoIt, captureState)
|
|
|
|
|
|
.tieCaptureFunc() // bind capturing function to memento storage,
|
2009-07-20 07:03:18 +02:00
|
|
|
|
(TTime(), Tstr("destruction"), 11); // then invoke the bound capturing mechanism
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (arg5->canUndo());
|
|
|
|
|
|
CHECK (*arg5->memento() == "destruction");
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2025-04-15 23:40:14 +02:00
|
|
|
|
VERIFY_ERROR(MISSING_MEMENTO, arg4->memento().i5i[3] = 513 );
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-18 19:36:32 +02:00
|
|
|
|
for_each (tup, showIt);
|
2009-07-11 20:06:35 +02:00
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
/** @test serialise and de-serialise each tuple and check validity
|
|
|
|
|
|
* @todo unimplemented, waiting on Serialiser
|
|
|
|
|
|
*/
|
2010-12-10 02:55:40 +01:00
|
|
|
|
void
|
2009-07-11 20:06:35 +02:00
|
|
|
|
serialiseArgTuples (ArgTuples& tup)
|
|
|
|
|
|
{
|
|
|
|
|
|
for_each (tup, checkSerialisation);
|
|
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
/** @test simulate a complete command lifecycle with regards to the
|
|
|
|
|
|
* storage handling of the command parameters and state memento.
|
2009-07-11 20:06:35 +02:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
simulateCmdLifecycle()
|
|
|
|
|
|
{
|
2011-05-16 08:38:27 +02:00
|
|
|
|
typedef void SIG_do(Tracker<TimeVar>, Tracker<string>, int);
|
2016-02-06 16:29:06 +01:00
|
|
|
|
using Args = StorageHolder<SIG_do, Tracker<string>>;
|
|
|
|
|
|
using MemHolder = MementoTie<SIG_do, Tracker<string>>;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
Args args;
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (isnil (args));
|
2009-07-11 20:06:35 +02:00
|
|
|
|
cout << showSizeof(args) << endl;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
// store a set of parameter values, later to be used on invocation
|
2009-10-02 23:49:15 +02:00
|
|
|
|
args.storeTuple (
|
2016-01-17 23:55:41 +01:00
|
|
|
|
make_tuple (TTime(randTime()), Tstr("Lumiera rocks"), twoRandomDigits() ));
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!isnil (args));
|
2009-07-11 20:06:35 +02:00
|
|
|
|
cout << args << endl;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!args.canUndo());
|
2009-07-20 07:03:18 +02:00
|
|
|
|
VERIFY_ERROR(MISSING_MEMENTO, args.memento() );
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
MemHolder& memHolder = args.tie(undoIt,captureState);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!memHolder); // no stored memento....
|
|
|
|
|
|
CHECK (!args.canUndo());
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
function<SIG_do> doItFun = doIt;
|
|
|
|
|
|
function<SIG_do> undoFun = memHolder.tieUndoFunc();
|
|
|
|
|
|
function<SIG_do> captFun = memHolder.tieCaptureFunc();
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-20 07:03:18 +02:00
|
|
|
|
typedef function<void()> OpFun;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
// now close all the functions with the stored parameter values...
|
2014-04-03 22:42:48 +02:00
|
|
|
|
OpFun bound_doItFun = std::bind (&CmdClosure::invoke, args, CmdFunctor(doItFun));
|
|
|
|
|
|
OpFun bound_undoFun = std::bind (&CmdClosure::invoke, args, CmdFunctor(undoFun));
|
|
|
|
|
|
OpFun bound_captFun = std::bind (&CmdClosure::invoke, args, CmdFunctor(captFun));
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
protocol.seekp(0);
|
|
|
|
|
|
protocol << "START...";
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
bound_captFun();
|
|
|
|
|
|
cout << "captured state: " << args.memento() << endl;
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (memHolder);
|
|
|
|
|
|
CHECK (!isnil (*args.memento()));
|
|
|
|
|
|
CHECK (args.canUndo());
|
2009-07-20 07:03:18 +02:00
|
|
|
|
cout << args << endl;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
bound_doItFun();
|
|
|
|
|
|
cout << protocol.str() << endl;
|
|
|
|
|
|
bound_undoFun();
|
|
|
|
|
|
cout << protocol.str() << endl;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-12 18:55:33 +02:00
|
|
|
|
// Commands can serve as prototype to be copied....
|
2009-07-11 20:06:35 +02:00
|
|
|
|
Args argsCopy (args);
|
|
|
|
|
|
bound_captFun();
|
|
|
|
|
|
protocol.seekp(0);
|
|
|
|
|
|
protocol << "RESET...";
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-10-02 23:49:15 +02:00
|
|
|
|
args.storeTuple (
|
2016-01-17 23:55:41 +01:00
|
|
|
|
make_tuple (TTime(TimeValue(123456)), Tstr("unbelievable"), twoRandomDigits() ));
|
2009-07-20 07:03:18 +02:00
|
|
|
|
cout << "modified: " << args << endl;
|
|
|
|
|
|
cout << "copied : " << argsCopy << endl; // holds still the old params & memento
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
|
bound_undoFun();
|
|
|
|
|
|
cout << protocol.str() << endl;
|
2009-06-28 15:27:27 +02:00
|
|
|
|
}
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
};
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (CommandArgument_test, "unit controller");
|
2011-12-02 17:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::control::test
|