Skip to content

Commit 5e726b2

Browse files
[tests] entity add test for signalDeregistration.
1 parent 157f5e6 commit 5e726b2

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/entity.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "dynamic-graph/factory.h"
1414
#include "dynamic-graph/pool.h"
1515
#include <dynamic-graph/real-time-logger.h>
16+
#include <dynamic-graph/signal-ptr.h>
17+
#include <dynamic-graph/signal-time-dependent.h>
1618

1719
#define BOOST_TEST_MODULE entity
1820

@@ -26,15 +28,42 @@ namespace dynamicgraph
2628
class CustomEntity : public Entity
2729
{
2830
public:
31+
dynamicgraph::SignalPtr<double, int> m_sigdSIN;
32+
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
33+
2934
static const std::string CLASS_NAME;
3035
virtual const std::string& getClassName () const
3136
{
3237
return CLASS_NAME;
3338
}
3439
CustomEntity (const std::string n)
3540
: Entity (n)
41+
,m_sigdSIN(NULL,"CustomEntity("+name+")::input(double)::in_double")
42+
,m_sigdTimeDepSOUT(boost::bind(&CustomEntity::update,this,_1,_2),
43+
m_sigdSIN,
44+
"CustomEntity("+name+")::input(double)::out_double")
45+
46+
{
47+
}
48+
49+
void addSignal()
50+
{
51+
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT);
52+
}
53+
54+
void rmValidSignal()
55+
{
56+
signalDeregistration("in_double");
57+
signalDeregistration("out_double");
58+
}
59+
60+
double & update(double &res, const int &inTime)
3661
{
62+
const double &aDouble = m_sigdSIN(inTime);
63+
res = aDouble;
64+
return res;
3765
}
66+
3867
};
3968
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity");
4069
}
@@ -83,6 +112,23 @@ BOOST_AUTO_TEST_CASE (signal)
83112
BOOST_CHECK_EQUAL (exception.getCode (),
84113
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL);
85114
}
115+
// deregistration
116+
try
117+
{
118+
dynamicgraph::CustomEntity * customEntity =
119+
dynamic_cast<dynamicgraph::CustomEntity *>(&entity);
120+
customEntity->addSignal();
121+
// Removing signals is working the first time
122+
customEntity->rmValidSignal();
123+
// Removing signals generates an exception the second time.
124+
customEntity->rmValidSignal();
125+
BOOST_ERROR ("Should never happen.");
126+
}
127+
catch (const dynamicgraph::ExceptionFactory& exception)
128+
{
129+
BOOST_CHECK_EQUAL (exception.getCode (),
130+
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL);
131+
}
86132
}
87133

88134
BOOST_AUTO_TEST_CASE (displaySignalList)

0 commit comments

Comments
 (0)