Skip to content
Snippets Groups Projects
Commit e7614beb authored by Olivier Stasse's avatar Olivier Stasse
Browse files

[tests] Improve test on pool

Testing and checking output of writeGraph.
parent 00b2d6ce
No related branches found
No related tags found
No related merge requests found
Pipeline #3111 failed
......@@ -19,6 +19,8 @@
#include <dynamic-graph/factory.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#define BOOST_TEST_MODULE pool
......@@ -31,9 +33,18 @@ struct MyEntity : public dynamicgraph::Entity
{
static const std::string CLASS_NAME;
dynamicgraph::SignalPtr<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
MyEntity (const std::string& name)
: Entity (name)
{}
,m_sigdSIN(NULL,"MyEntity("+name+")::input(double)::in_double")
,m_sigdTimeDepSOUT(boost::bind(&MyEntity::update,this,_1,_2),
m_sigdSIN,
"MyEntity("+name+")::input(double)::out_double")
{
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT);
}
virtual void display (std::ostream& os) const
{
......@@ -44,6 +55,14 @@ struct MyEntity : public dynamicgraph::Entity
{
return CLASS_NAME;
}
double & update(double &res, const int &inTime)
{
const double &aDouble = m_sigdSIN(inTime);
res = aDouble;
return res;
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (MyEntity, "MyEntity");
......@@ -80,7 +99,41 @@ BOOST_AUTO_TEST_CASE (pool_display)
// Testing the completion list of pool storage
dg::PoolStorage::getInstance()->writeCompletionList
(output);
BOOST_CHECK (output.is_equal ("print\nsignals\nsignalDep\n"));
BOOST_CHECK (output.is_equal ("MyEntityInst.in_double\nMyEntityInst.out_double\nprint\nsignals\nsignalDep\n"));
// Checking the graph generated by the pool
dg::PoolStorage::getInstance()->writeGraph("output.dot");
std::fstream the_debug_file;
the_debug_file.open("output.dot");
std::ostringstream oss_output_wgph;
oss_output_wgph << the_debug_file.rdbuf();
the_debug_file.close();
/* Use a predefined output */
std::string str_to_test="/* This graph has been automatically generated.\n"
" 2019 Month: 2 Day: 28 Time: 11:28 */\n"
"digraph \"output\" { graph [ label=\"output\" bgcolor = white rankdir=LR ]\n"
"\t node [ fontcolor = black, color = black, fillcolor = gold1, style=filled, shape=box ] ; \n"
"\tsubgraph cluster_Entities { \n"
"\t} \n"
"\"MyEntityInst\" [ label = \"MyEntityInst\" ,\n"
" fontcolor = black, color = black, fillcolor=cyan, style=filled, shape=box ]\n"
"}\n";
/* Check the two substring (remove the date) */
std::string s_output_wgph = oss_output_wgph.str();
std::string s_crmk="*/";
std::size_t find_s_output_wgph = s_output_wgph.find(s_crmk);
std::string sub_s_output_wgph =s_output_wgph.substr(find_s_output_wgph, s_output_wgph.length());
std::size_t find_str_to_test = str_to_test.find(s_crmk);
std::string sub_str_to_test =str_to_test.substr(find_str_to_test, str_to_test.length());
bool two_sub_string_identical;
two_sub_string_identical=sub_str_to_test==sub_s_output_wgph;
BOOST_CHECK(two_sub_string_identical);
// Deregister the entity.
dg::PoolStorage::getInstance()->deregisterEntity
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment