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

[tests] debug-trace.cpp: detect robustly trace output.

pool.cpp: test exception catching.
parent 203eaebc
No related branches found
No related tags found
No related merge requests found
......@@ -68,3 +68,4 @@ DYNAMIC_GRAPH_TEST(signal-time-dependent)
DYNAMIC_GRAPH_TEST(value)
DYNAMIC_GRAPH_TEST(signal-ptr)
DYNAMIC_GRAPH_TEST(real-time-logger)
DYNAMIC_GRAPH_TEST(debug-trace)
/* Copyright 2019, LAAS-CNRS
*
* Olivier Stasse
*
* See LICENSE file
*
*/
#include <sstream>
#include <iostream>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
#include "dynamic-graph/factory.h"
#include "dynamic-graph/pool.h"
#define VP_DEBUG 1
#define VP_DEBUG_MODE 50
#define VP_TEMPLATE_DEBUG_MODE 50
#include <dynamic-graph/debug.h>
#define BOOST_TEST_MODULE debug-trace
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
namespace dynamicgraph
{
class CustomEntity : public Entity
{
public:
static const std::string CLASS_NAME;
virtual const std::string& getClassName () const
{
return CLASS_NAME;
}
CustomEntity (const std::string n)
: Entity (n)
{
dynamicgraph::dgDEBUGFLOW.openFile("/tmp/dynamic-graph-traces.txt");
}
~CustomEntity()
{
dynamicgraph::dgDEBUGFLOW.closeFile("/tmp/dynamic-graph-traces.txt");
}
void testDebugTrace()
{
/// Test debugging information when entering the code.
dgDEBUGIN(5);
/// Intermediate test.
dgDEBUGINOUT(5);
dgDEBUG(5) << "Here is a test" << std::endl;
/// Test debugging information when going out of the code.
dgDEBUGOUT(5);
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity");
}
BOOST_AUTO_TEST_CASE(testDebugTrace)
{
BOOST_CHECK_EQUAL (dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
dynamicgraph::CustomEntity& entity = *(dynamic_cast<dynamicgraph::CustomEntity *>(
dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
"my-entity")));
entity.testDebugTrace();
/// Copy the debug file into the oss_debug_file
output_test_stream output;
std::fstream the_debug_file;
the_debug_file.open(dynamicgraph::DebugTrace::DEBUG_FILENAME_DEFAULT,
std::ios::in );
// Extract the filename and this source file from the output
std::string astr;
std::ostringstream oss_debug_file;
while(std::getline(the_debug_file,astr))
{
std::size_t found=astr.find(":");
std::string asubstr = astr.substr(found+1,astr.length());
found = asubstr.find(":");
std::string asubstr2 = asubstr.substr(found+1,astr.length());
oss_debug_file << asubstr2;
}
the_debug_file.close();
// Compare with the strings put inside this source file
std::string str_to_test = "# In {"
"# In/Out { }"
"Here is a test"
"# Out }";
bool two_sub_string_identical;
// Make comparisons.
std::cout << str_to_test << std::endl;
std::cout << oss_debug_file.str() << std::endl;
two_sub_string_identical = str_to_test == oss_debug_file.str();
BOOST_CHECK(two_sub_string_identical);
}
/* Copyright 2019, LAAS-CNRS
*
* Olivier Stasse
*
* See LICENSE file
*
*/
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/tracer.h>
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
{
os << "Hello! My name is " << getName () << " !" << std::endl;
}
virtual const std::string& getClassName () const
{
return CLASS_NAME;
}
double & update(double &res, const int &inTime)
{
const double &aDouble = m_sigdSIN(inTime);
res = aDouble;
return res;
}
};
BOOST_AUTO_TEST_CASE(test_tracer)
{
// Creates a tracer.
dynamicgraph::Entity& entity =
*dynamicgraph::FactoryStorage::getInstance()->newEntity("Tracer",
"my-tracer");
}
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