Commit 5e726b24 authored by Olivier Stasse's avatar Olivier Stasse
Browse files

[tests] entity add test for signalDeregistration.

parent 157f5e62
......@@ -13,6 +13,8 @@
#include "dynamic-graph/factory.h"
#include "dynamic-graph/pool.h"
#include <dynamic-graph/real-time-logger.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#define BOOST_TEST_MODULE entity
......@@ -26,6 +28,9 @@ namespace dynamicgraph
class CustomEntity : public Entity
{
public:
dynamicgraph::SignalPtr<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
static const std::string CLASS_NAME;
virtual const std::string& getClassName () const
{
......@@ -33,8 +38,32 @@ namespace dynamicgraph
}
CustomEntity (const std::string n)
: Entity (n)
,m_sigdSIN(NULL,"CustomEntity("+name+")::input(double)::in_double")
,m_sigdTimeDepSOUT(boost::bind(&CustomEntity::update,this,_1,_2),
m_sigdSIN,
"CustomEntity("+name+")::input(double)::out_double")
{
}
void addSignal()
{
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT);
}
void rmValidSignal()
{
signalDeregistration("in_double");
signalDeregistration("out_double");
}
double & update(double &res, const int &inTime)
{
const double &aDouble = m_sigdSIN(inTime);
res = aDouble;
return res;
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity");
}
......@@ -83,6 +112,23 @@ BOOST_AUTO_TEST_CASE (signal)
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL);
}
// deregistration
try
{
dynamicgraph::CustomEntity * customEntity =
dynamic_cast<dynamicgraph::CustomEntity *>(&entity);
customEntity->addSignal();
// Removing signals is working the first time
customEntity->rmValidSignal();
// Removing signals generates an exception the second time.
customEntity->rmValidSignal();
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL);
}
}
BOOST_AUTO_TEST_CASE (displaySignalList)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment