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
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2009-06-28 15:27:27 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
|
|
|
|
#include "proc/control/command-argument-holder.hpp"
|
2009-07-11 20:06:35 +02:00
|
|
|
#include "lib/scoped-ptrvect.hpp"
|
2011-05-16 08:38:27 +02:00
|
|
|
#include "lib/time/diagnostics.hpp"
|
2009-10-02 23:49:15 +02:00
|
|
|
#include "lib/meta/tuple.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
|
|
|
|
2009-07-11 20:06:35 +02:00
|
|
|
#include <boost/format.hpp>
|
2009-09-21 03:15:06 +02:00
|
|
|
#include <tr1/functional>
|
2009-06-28 15:27:27 +02:00
|
|
|
#include <iostream>
|
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>
|
|
|
|
|
|
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-07-20 07:03:18 +02:00
|
|
|
using boost::format;
|
2009-06-28 15:27:27 +02:00
|
|
|
using std::string;
|
2009-07-11 20:06:35 +02:00
|
|
|
using std::ostream;
|
2009-07-13 01:16:30 +02:00
|
|
|
using std::ostringstream;
|
2009-07-20 07:03:18 +02:00
|
|
|
using std::rand;
|
2009-06-28 15:27:27 +02:00
|
|
|
using std::cout;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace proc {
|
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;
|
2009-10-02 23:49:15 +02:00
|
|
|
using namespace lumiera::typelist;
|
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; }
|
2011-12-02 17:50:44 +01:00
|
|
|
|
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 ostream&
|
|
|
|
|
operator<< (ostream& out, const Tracker& tra)
|
|
|
|
|
{
|
|
|
|
|
return out << tra.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
|
|
|
|
|
{
|
|
|
|
|
int i[5];
|
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)
|
|
|
|
|
{
|
|
|
|
|
return i1.i == i2.i;
|
|
|
|
|
}
|
|
|
|
|
};
|
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
|
|
|
{
|
|
|
|
|
static format 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) { }
|
|
|
|
|
int dummyC (int u,int o) { return u + rand() % (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()
|
|
|
|
|
{
|
|
|
|
|
return 10 + rand() % 90;
|
|
|
|
|
}
|
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
|
|
|
|
2009-06-28 15:27:27 +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
|
|
|
*
|
2009-06-29 06:33:42 +02:00
|
|
|
* @see control::CommandArgumentHolder
|
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
|
|
|
{
|
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 19:13:25 +02:00
|
|
|
checkArgumentComparison ();
|
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)
|
|
|
|
|
{
|
2011-05-16 08:38:27 +02:00
|
|
|
typedef ArgumentHolder<void(), bool> A1;
|
|
|
|
|
typedef ArgumentHolder<void(int), void*> A2;
|
|
|
|
|
typedef ArgumentHolder<void(int,TimeVar), int> A3;
|
|
|
|
|
typedef ArgumentHolder<void(int,TimeVar), Sint5> A4;
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-07-19 08:32:49 +02:00
|
|
|
typedef ArgumentHolder<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
|
|
|
|
2009-10-02 23:49:15 +02:00
|
|
|
arg1->storeTuple (tuple::makeNullTuple());
|
|
|
|
|
arg2->storeTuple (tuple::make (rand() % 10));
|
2011-05-16 08:38:27 +02:00
|
|
|
arg3->storeTuple (tuple::make (rand() % 10, TimeVar(randTime())));
|
|
|
|
|
arg4->storeTuple (tuple::make (rand() % 10, TimeVar(randTime())));
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2011-11-27 02:15:11 +01:00
|
|
|
arg5->storeTuple (tuple::make (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
|
|
|
|
2009-07-19 08:32:49 +02:00
|
|
|
VERIFY_ERROR(MISSING_MEMENTO, arg4->memento().i[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-11 20:06:35 +02:00
|
|
|
/** @test verify the comparison operators */
|
|
|
|
|
void
|
|
|
|
|
checkArgumentComparison ()
|
|
|
|
|
{
|
2009-07-20 05:09:46 +02:00
|
|
|
ArgumentHolder<void(int,int), int> one, two;
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (one == two); // empty, identically typed argument holders -->equal
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-07-20 05:09:46 +02:00
|
|
|
one.tie(dummyU,dummyC)
|
|
|
|
|
.tieCaptureFunc()(1,9);
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (one != two); // now one contains captured UNDO state
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-07-20 05:09:46 +02:00
|
|
|
two.tie(dummyU,dummyC)
|
|
|
|
|
.tieCaptureFunc()(1,9);
|
|
|
|
|
two.memento() = one.memento(); // put the same UNDO state in both
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (one == two); // ...makes them equal again
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-10-02 23:49:15 +02:00
|
|
|
one.storeTuple (tuple::make (1,2));
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (one != two); // verify argument tuple comparison
|
|
|
|
|
CHECK (two != one);
|
|
|
|
|
CHECK (!isnil (one));
|
|
|
|
|
CHECK ( isnil (two));
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-10-02 23:49:15 +02:00
|
|
|
two.storeTuple (tuple::make (3,4));
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (!isnil (two));
|
|
|
|
|
CHECK (one != two);
|
|
|
|
|
CHECK (two != one);
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-10-02 23:49:15 +02:00
|
|
|
one.storeTuple (tuple::make (1,4));
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (!isnil (one));
|
|
|
|
|
CHECK (one != two);
|
|
|
|
|
CHECK (two != one);
|
2011-12-02 17:50:44 +01:00
|
|
|
|
2009-10-02 23:49:15 +02:00
|
|
|
one.storeTuple (tuple::make (3,4));
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (!isnil (one));
|
|
|
|
|
CHECK (one == two);
|
|
|
|
|
CHECK (two == one);
|
2009-07-20 05:09:46 +02:00
|
|
|
two.memento() = 12345;
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (!isnil (two));
|
|
|
|
|
CHECK (one != two);
|
|
|
|
|
CHECK (two != one);
|
2009-07-11 20:06:35 +02:00
|
|
|
}
|
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);
|
2009-07-20 07:03:18 +02:00
|
|
|
typedef ArgumentHolder<SIG_do, Tracker<string> > Args;
|
|
|
|
|
typedef MementoTie<SIG_do, Tracker<string> > MemHolder;
|
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 (
|
2011-11-27 02:15:11 +01:00
|
|
|
tuple::make (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...
|
2009-09-21 03:15:06 +02:00
|
|
|
OpFun bound_doItFun = std::tr1::bind (&CmdClosure::invoke, args, CmdFunctor(doItFun));
|
|
|
|
|
OpFun bound_undoFun = std::tr1::bind (&CmdClosure::invoke, args, CmdFunctor(undoFun));
|
|
|
|
|
OpFun bound_captFun = std::tr1::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 (
|
2011-11-27 02:15:11 +01:00
|
|
|
tuple::make (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
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace proc::control::test
|