...
 
Commits (36)
...@@ -23,7 +23,7 @@ notifications: ...@@ -23,7 +23,7 @@ notifications:
branches: branches:
only: only:
- master - master
- debian - devel
script: ./travis_custom/build_custom script: ./travis_custom/build_custom
after_success: ./.travis/run after_success after_success: ./.travis/run after_success
after_failure: ./.travis/run after_failure after_failure: ./.travis/run after_failure
......
...@@ -96,7 +96,6 @@ SET(${PROJECT_NAME}_SOURCES ...@@ -96,7 +96,6 @@ SET(${PROJECT_NAME}_SOURCES
SET(${PROJECT_NAME}_HEADERS SET(${PROJECT_NAME}_HEADERS
include/dynamic-graph/fwd.hh include/dynamic-graph/fwd.hh
include/dynamic-graph/null-ptr.hh
include/dynamic-graph/debug.h include/dynamic-graph/debug.h
include/dynamic-graph/real-time-logger.h include/dynamic-graph/real-time-logger.h
......
dynamic-graph dynamic-graph
============= =============
[![Building Status](https://travis-ci.org/stack-of-tasks/dynamic-graph.svg?branch=master)](https://travis-ci.org/stack-of-tasks/dynamic-graph) [![Building status](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph/badges/master/pipeline.svg)](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph/commits/master)
[![Pipeline status](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph/badges/master/pipeline.svg)](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph/commits/master)
[![Coverage report](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph/badges/master/coverage.svg?job=doc-coverage)](http://projects.laas.fr/stack-of-tasks/doc/stack-of-tasks/dynamic-graph/master/coverage/) [![Coverage report](https://gepgitlab.laas.fr/stack-of-tasks/dynamic-graph/badges/master/coverage.svg?job=doc-coverage)](http://projects.laas.fr/stack-of-tasks/doc/stack-of-tasks/dynamic-graph/master/coverage/)
[![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)
This software provides an efficient way to modelize a C++ data-flow. This software provides an efficient way to modelize a C++ data-flow.
...@@ -42,10 +42,7 @@ located in the `$prefix/share/doc/dynamic-graph` directoy where ...@@ -42,10 +42,7 @@ located in the `$prefix/share/doc/dynamic-graph` directoy where
Getting Help Getting Help
------------ ------------
Support is provided through: Support is provided through issues on the github interface.
* the HPP mailing-list: hpp@laas.fr
* the following HipChat room: http://www.hipchat.com/gh4wQrZeV
How can I install dynamic-graph? How can I install dynamic-graph?
-------------------------------- --------------------------------
...@@ -57,13 +54,9 @@ have to be available on your machine. ...@@ -57,13 +54,9 @@ have to be available on your machine.
- Libraries: - Libraries:
- [Boost][] (>= 1.40) - [Boost][] (>= 1.40)
Its detection is controlled by the `BOOST_ROOT` variable, see next section - Doxygen
for more information. - Eigen3
- [Lapack][] library - pthread
Use the generic purpose `CMAKE_CXX_FLAGS` and `CMAKE_EXE_LINKER_FLAGS`
to insert the flags required for the compiler to find your Lapack library
if it is installed in a non-standard directory.
- [jrl-mal][] library
- System tools: - System tools:
- [CMake][] (>=2.6) - [CMake][] (>=2.6)
- [pkg-config][] - [pkg-config][]
...@@ -143,15 +136,12 @@ This package authors are credited in the [AUTHORS](AUTHORS) file. ...@@ -143,15 +136,12 @@ This package authors are credited in the [AUTHORS](AUTHORS) file.
Available Packages Available Packages
------------------ ------------------
* RobotPkg (Release 2.5.3r1): * RobotPkg :
http://robotpkg.openrobots.org/robotpkg/motion/dynamic-graph/index.html http://robotpkg.openrobots.org/robotpkg/motion/dynamic-graph/index.html
[doxygen-documentation]: http://stack-of-tasks.github.io/dynamic-graph/doxygen/HEAD/ [doxygen-documentation]: http://stack-of-tasks.github.io/dynamic-graph/doxygen/HEAD/
[jrl-mathtools]: https://github.com/jrl-umi3218/jrl-mathtools
[jrl-mal]: https://github.com/jrl-umi3218/jrl-mal
[git-submodules]: http://git-scm.com/book/en/Git-Tools-Submodules [git-submodules]: http://git-scm.com/book/en/Git-Tools-Submodules
[Boost]: http://www.boost.org/ [Boost]: http://www.boost.org/
...@@ -159,7 +149,6 @@ Available Packages ...@@ -159,7 +149,6 @@ Available Packages
[Doxygen]: http://www.stack.nl/~dimitri/doxygen/ [Doxygen]: http://www.stack.nl/~dimitri/doxygen/
[Eigen]: http://eigen.tuxfamily.org/ [Eigen]: http://eigen.tuxfamily.org/
[Git]: http://git-scm.com/ [Git]: http://git-scm.com/
[Lapack]: http://www.netlib.org/lapack/
[Libtool]: https://www.gnu.org/software/libtool/ [Libtool]: https://www.gnu.org/software/libtool/
[RobotPkg]: http://robotpkg.openrobots.org/ [RobotPkg]: http://robotpkg.openrobots.org/
[log4cxx]: https://logging.apache.org/log4cxx/ [log4cxx]: https://logging.apache.org/log4cxx/
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#ifndef DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP #ifndef DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
#define DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP #define DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
#include "dynamic-graph/command-setter.h"
#include "dynamic-graph/linear-algebra.h" #include "dynamic-graph/linear-algebra.h"
#include "dynamic-graph/command-setter.h" #include "dynamic-graph/command-setter.h"
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp> #include <boost/numeric/conversion/cast.hpp>
#pragma GCC diagnostic push
#pragma GCC system_header
#include <Eigen/Geometry> #include <Eigen/Geometry>
#pragma GCC diagnostic pop
#include <dynamic-graph/exception-signal.h> #include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/linear-algebra.h> #include <dynamic-graph/linear-algebra.h>
......
...@@ -6,8 +6,11 @@ ...@@ -6,8 +6,11 @@
#ifndef DYNAMIC_GRAPH_LINEAR_ALGEBRA_H #ifndef DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
#define DYNAMIC_GRAPH_LINEAR_ALGEBRA_H #define DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
#pragma GCC diagnostic push
#pragma GCC system_header
#include <Eigen/Core> #include <Eigen/Core>
#include <Eigen/Geometry> #include <Eigen/Geometry>
#pragma GCC diagnostic pop
namespace dynamicgraph { namespace dynamicgraph {
typedef Eigen::MatrixXd Matrix; typedef Eigen::MatrixXd Matrix;
......
// Copyright 2010, Thomas Moulard, JRL, CNRS/AIST
//
#ifndef DYNAMIC_GRAPH_NULL_PTR_HH
#define DYNAMIC_GRAPH_NULL_PTR_HH
namespace dynamicgraph {
/// \cond
const class {
public:
template <class T> operator T *() const { return 0; }
template <class C, class T> operator T C::*() const { return 0; }
private:
void operator&() const;
} nullptr = {};
/// \endcond
} // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_NULL_PTR_HH
...@@ -20,6 +20,11 @@ namespace dynamicgraph { ...@@ -20,6 +20,11 @@ namespace dynamicgraph {
/// In that sense, when plugged into, it acts as a "pointer" to the /// In that sense, when plugged into, it acts as a "pointer" to the
/// input signal, hence the name. Operator -> is also overloaded and /// input signal, hence the name. Operator -> is also overloaded and
/// can be used to access the pointed signal. /// can be used to access the pointed signal.
///
/// If the signal provided as a parameter of the plug operation
/// cannot be casted in type T, but is compatible then the class
/// holds a reference to an abstract object.
///
template <class T, class Time> template <class T, class Time>
class SignalPtr : public virtual Signal<T, Time> { class SignalPtr : public virtual Signal<T, Time> {
public: public:
......
...@@ -107,6 +107,8 @@ public: ...@@ -107,6 +107,8 @@ public:
} }
public: public:
/// checkCompatibility is used to get the object contained in the
/// signal. This used to verify if a dynamic cast is possible or not.
virtual void checkCompatibility() { throw Tcopy; } virtual void checkCompatibility() { throw Tcopy; }
private: private:
......
...@@ -113,21 +113,6 @@ bool TimeDependency<Time>::needUpdate(const Time &t1) const { ...@@ -113,21 +113,6 @@ bool TimeDependency<Time>::needUpdate(const Time &t1) const {
template <class Time> template <class Time>
std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os) const { std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os) const {
std::string LeaderLocalName;
std::string LeaderNodeName;
leader.ExtractNodeAndLocalNames(LeaderLocalName, LeaderNodeName);
if (dependencies.size() != 0) {
const typename Dependencies::const_iterator itend = dependencies.end();
for (typename Dependencies::const_iterator it = dependencies.begin();
it != itend; ++it) {
std::string itLocalName, itNodeName;
(*it)->ExtractNodeAndLocalNames(itLocalName, itNodeName);
os << "\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\""
<< std::endl
<< " [ headlabel = \"" << LeaderLocalName << "\" , taillabel = \""
<< itLocalName << "\" ]" << std::endl;
}
}
return os; return os;
} }
...@@ -159,7 +144,7 @@ TimeDependency<Time>::displayDependencies(std::ostream &os, const int depth, ...@@ -159,7 +144,7 @@ TimeDependency<Time>::displayDependencies(std::ostream &os, const int depth,
std::string ajout = "|"; std::string ajout = "|";
std::string ajout2 = "|"; std::string ajout2 = "|";
typename Dependencies::const_iterator it2 = it; typename Dependencies::const_iterator it2 = it;
it2++; ++it2;
if (it2 == dependencies.end()) { if (it2 == dependencies.end()) {
ajout = "`"; ajout = "`";
ajout2 = " "; ajout2 = " ";
......
...@@ -72,22 +72,22 @@ struct RealTimeLogger::thread { ...@@ -72,22 +72,22 @@ struct RealTimeLogger::thread {
bool changedThreadParams; bool changedThreadParams;
boost::thread t_; boost::thread t_;
thread(RealTimeLogger *logger) explicit thread(RealTimeLogger *logger)
: requestShutdown_(false), threadPolicy_(SCHED_OTHER), threadPriority_(0), : requestShutdown_(false), threadPolicy_(SCHED_OTHER), threadPriority_(0),
changedThreadParams(true), t_(&thread::spin, this, logger) {} changedThreadParams(true), t_(&thread::spin, this, logger) {}
void setThreadPolicy(int policy) { // void setThreadPolicy(int policy) {
threadPolicy_ = policy; // threadPolicy_ = policy;
changedThreadParams = true; // changedThreadParams = true;
} // }
void setPriority(int priority) { // void setPriority(int priority) {
threadPriority_ = priority; // threadPriority_ = priority;
changedThreadParams = true; // changedThreadParams = true;
} // }
int getThreadPolicy() { return threadPolicy_; } // int getThreadPolicy() { return threadPolicy_; }
int getThreadPriority() { return threadPriority_; } // int getThreadPriority() { return threadPriority_; }
void changeThreadParams() { void changeThreadParams() {
int threadPolicy; int threadPolicy;
......
...@@ -46,7 +46,7 @@ Entity::Entity(const string &name__) : name(name__) { ...@@ -46,7 +46,7 @@ Entity::Entity(const string &name__) : name(name__) {
Entity::~Entity() { Entity::~Entity() {
dgDEBUG(25) << "# In (" << name << " { " << endl; dgDEBUG(25) << "# In (" << name << " { " << endl;
for (std::map<const std::string, Command *>::iterator it = commandMap.begin(); for (std::map<const std::string, Command *>::iterator it = commandMap.begin();
it != commandMap.end(); it++) { it != commandMap.end(); ++it) {
delete it->second; delete it->second;
} }
dgDEBUGOUT(25); dgDEBUGOUT(25);
......
...@@ -83,7 +83,7 @@ std::vector<std::string> SignalCaster::listTypenames() const { ...@@ -83,7 +83,7 @@ std::vector<std::string> SignalCaster::listTypenames() const {
std::vector<std::string> typeList; std::vector<std::string> typeList;
for (std::map<std::string, cast_functions_type>::const_iterator iter = for (std::map<std::string, cast_functions_type>::const_iterator iter =
functions_.begin(); functions_.begin();
iter != functions_.end(); iter++) iter != functions_.end(); ++iter)
typeList.push_back(iter->first); typeList.push_back(iter->first);
return typeList; return typeList;
} }
......
...@@ -317,7 +317,7 @@ void TracerRealTime::display(std::ostream &os) const { ...@@ -317,7 +317,7 @@ void TracerRealTime::display(std::ostream &os) const {
os.precision(PRECISION); os.precision(PRECISION);
} }
os << endl; os << endl;
iterFile++; ++iterFile;
} }
} }
......
...@@ -59,9 +59,12 @@ DYNAMIC_GRAPH_TEST(real-time-logger) ...@@ -59,9 +59,12 @@ DYNAMIC_GRAPH_TEST(real-time-logger)
DYNAMIC_GRAPH_TEST(debug-trace) DYNAMIC_GRAPH_TEST(debug-trace)
DYNAMIC_GRAPH_TEST(debug-tracer) DYNAMIC_GRAPH_TEST(debug-tracer)
TARGET_LINK_LIBRARIES(debug-tracer tracer) TARGET_LINK_LIBRARIES(debug-tracer tracer)
DYNAMIC_GRAPH_TEST(debug-real-time-tracer)
TARGET_LINK_LIBRARIES(debug-real-time-tracer tracer-real-time tracer)
DYNAMIC_GRAPH_TEST(debug-logger) DYNAMIC_GRAPH_TEST(debug-logger)
DYNAMIC_GRAPH_TEST(debug-logger-winit) DYNAMIC_GRAPH_TEST(debug-logger-winit)
DYNAMIC_GRAPH_TEST(signal-all) DYNAMIC_GRAPH_TEST(signal-all)
DYNAMIC_GRAPH_TEST(command-test) DYNAMIC_GRAPH_TEST(command-test)
DYNAMIC_GRAPH_TEST(test-mt) DYNAMIC_GRAPH_TEST(test-mt)
TARGET_LINK_LIBRARIES(test-mt tracer) TARGET_LINK_LIBRARIES(test-mt tracer)
DYNAMIC_GRAPH_TEST(exceptions)
...@@ -37,7 +37,7 @@ public: ...@@ -37,7 +37,7 @@ public:
bool test_four_args_; bool test_four_args_;
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) { explicit CustomEntity(const std::string &n) : Entity(n) {
test_zero_arg_ = false; test_zero_arg_ = false;
test_one_arg_ = false; test_one_arg_ = false;
test_two_args_ = false; test_two_args_ = false;
...@@ -62,6 +62,16 @@ public: ...@@ -62,6 +62,16 @@ public:
makeCommandVoid4( makeCommandVoid4(
*this, &CustomEntity::four_args, *this, &CustomEntity::four_args,
docCommandVoid4("four args", "int", "int", "int", "int"))); docCommandVoid4("four args", "int", "int", "int", "int")));
/// Generating an exception by adding a command which already exist
bool res = false;
std::string e_1_arg("1_arg");
try {
addCommand(e_1_arg, getNewStyleCommand(e_1_arg));
} catch (dynamicgraph::ExceptionFactory &aef) {
res = (aef.getCode() == dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
}
BOOST_CHECK(res);
} }
~CustomEntity() {} ~CustomEntity() {}
...@@ -84,10 +94,11 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity"); ...@@ -84,10 +94,11 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
} // namespace dynamicgraph } // namespace dynamicgraph
BOOST_AUTO_TEST_CASE(command_test) { BOOST_AUTO_TEST_CASE(command_test) {
dynamicgraph::CustomEntity &entity = dynamicgraph::CustomEntity *ptr_entity =
*(dynamic_cast<dynamicgraph::CustomEntity *>( (dynamic_cast<dynamicgraph::CustomEntity *>(
dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
"my-entity"))); "my-entity")));
dynamicgraph::CustomEntity &entity = *ptr_entity;
std::map<const std::string, Command *> aCommandMap = std::map<const std::string, Command *> aCommandMap =
entity.getNewStyleCommandMap(); entity.getNewStyleCommandMap();
...@@ -116,10 +127,55 @@ BOOST_AUTO_TEST_CASE(command_test) { ...@@ -116,10 +127,55 @@ BOOST_AUTO_TEST_CASE(command_test) {
values.push_back(aValue); values.push_back(aValue);
it_map->second->setParameterValues(values); it_map->second->setParameterValues(values);
it_map->second->execute(); it_map->second->execute();
it_map->second->owner();
it_map->second->getDocstring();
} }
BOOST_CHECK(entity.test_one_arg_); BOOST_CHECK(entity.test_one_arg_);
BOOST_CHECK(entity.test_two_args_); BOOST_CHECK(entity.test_two_args_);
BOOST_CHECK(entity.test_three_args_); BOOST_CHECK(entity.test_three_args_);
BOOST_CHECK(entity.test_four_args_); BOOST_CHECK(entity.test_four_args_);
std::vector<Value> values_two;
values_two.push_back(aValue);
/// Wrong number of arguments
bool res = false;
it_map = aCommandMap.find(std::string("2_args"));
try {
it_map->second->setParameterValues(values_two);
} catch (const dynamicgraph::ExceptionAbstract &aea) {
res = (aea.getCode() == dynamicgraph::ExceptionAbstract::ABSTRACT);
}
BOOST_CHECK(res);
double snd_arg_db = 10.0;
Value aValue2(snd_arg_db);
values_two.push_back(aValue2);
/// Wrong types of arguments
res = false;
it_map = aCommandMap.find(std::string("2_args"));
try {
it_map->second->setParameterValues(values_two);
} catch (const dynamicgraph::ExceptionAbstract &aea) {
res = (aea.getCode() == dynamicgraph::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
/// Try to find the command 1_arg
res = false;
entity.getNewStyleCommand(vec_fname[0]);
BOOST_CHECK(true);
/// Generate an exception by searching a command with an empty name.w
std::string empty("");
try {
entity.getNewStyleCommand(empty);
} catch (dynamicgraph::ExceptionFactory &aef) {
res = (aef.getCode() == dynamicgraph::ExceptionFactory::UNREFERED_FUNCTION);
}
BOOST_CHECK(res);
/// delete the entity.
delete ptr_entity;
} }
...@@ -19,7 +19,7 @@ struct CustomEntity : public dynamicgraph::Entity { ...@@ -19,7 +19,7 @@ struct CustomEntity : public dynamicgraph::Entity {
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {} explicit CustomEntity(const std::string &n) : Entity(n) {}
virtual ~CustomEntity() {} virtual ~CustomEntity() {}
......
...@@ -32,7 +32,7 @@ class CustomEntity : public Entity { ...@@ -32,7 +32,7 @@ class CustomEntity : public Entity {
public: public:
static const std::string CLASS_NAME; static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) { explicit CustomEntity(const std::string &n) : Entity(n) {
logger_.setTimeSample(0.001); logger_.setTimeSample(0.001);
logger_.setStreamPrintPeriod(0.005); logger_.setStreamPrintPeriod(0.005);
logger_.setVerbosity(VERBOSITY_ALL); logger_.setVerbosity(VERBOSITY_ALL);
...@@ -62,10 +62,7 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity"); ...@@ -62,10 +62,7 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
} // namespace dynamicgraph } // namespace dynamicgraph
BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) { BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) {
std::ofstream of;
dynamicgraph::RealTimeLogger::instance(); dynamicgraph::RealTimeLogger::instance();
// of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
// dgADD_OSTREAM_TO_RTLOG (of);
BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
......
...@@ -28,7 +28,7 @@ class CustomEntity : public Entity { ...@@ -28,7 +28,7 @@ class CustomEntity : public Entity {
public: public:
static const std::string CLASS_NAME; static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) { explicit CustomEntity(const std::string &n) : Entity(n) {
logger_.setTimeSample(0.001); logger_.setTimeSample(0.001);
logger_.setStreamPrintPeriod(0.005); logger_.setStreamPrintPeriod(0.005);
logger_.setVerbosity(VERBOSITY_ALL); logger_.setVerbosity(VERBOSITY_ALL);
...@@ -59,6 +59,7 @@ public: ...@@ -59,6 +59,7 @@ public:
vq[1] = 2.0; vq[1] = 2.0;
vq[2] = 3.0; vq[2] = 3.0;
sendMsg("Value to display: " + toString(vq)); sendMsg("Value to display: " + toString(vq));
sendMsg("Value to display: " + toString(vq, 3, 10));
Eigen::Matrix<double, 3, 3> an_eig_m; Eigen::Matrix<double, 3, 3> an_eig_m;
an_eig_m.Ones(); an_eig_m.Ones();
sendMsg("Value to display: " + toString(an_eig_m)); sendMsg("Value to display: " + toString(an_eig_m));
......
/* Copyright 2019, LAAS-CNRS
*
* Olivier Stasse
*
*/
#include <iostream>
#include <dynamic-graph/command.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/tracer-real-time.h>
#define BOOST_TEST_MODULE debug - tracer
#include <boost/test/output_test_stream.hpp>
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
namespace dynamicgraph {
struct MyEntity : public dynamicgraph::Entity {
static const std::string CLASS_NAME;
dynamicgraph::Signal<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT;
explicit MyEntity(const std::string &name)
: Entity(name),
m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
m_sigdSIN,
"MyEntity(" + name + ")::input(double)::out_double"),
m_sigdTwoTimeDepSOUT(
boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN,
"MyEntity(" + name + ")::input(double)::out2double")
{
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigdTwoTimeDepSOUT);
}
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;
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity, "MyEntity");
} // namespace dynamicgraph
BOOST_AUTO_TEST_CASE(test_tracer) {
using namespace dynamicgraph;
// Creates a tracer.
TracerRealTime &atracer = *dynamic_cast<TracerRealTime *>(
FactoryStorage::getInstance()->newEntity("TracerRealTime", "my-tracer"));
Entity &entity =
*FactoryStorage::getInstance()->newEntity("MyEntity", "my-entity");
std::string rootdir("/tmp");
std::string basename("my-tracer");
std::string suffix(".dat");
/// Test openfiles
atracer.openFiles(rootdir, basename, suffix);
/// Add trace by name
atracer.addSignalToTraceByName("my-entity.out_double", "output");
/// Add trace by name
SignalBase<int> &aSignal = entity.getSignal("out2double");
Signal<double, int> &aSignalInt =
*(dynamic_cast<Signal<double, int> *>(&entity.getSignal("in_double")));
aSignalInt.setConstant(1.5);
atracer.start();
atracer.trace();
std::string emptybuf_cmd_str("empty");
command::Command *acmd = atracer.getNewStyleCommand(emptybuf_cmd_str);
acmd->execute();
for (int i = 0; i < 1000; i++) {
aSignal.setTime(i);
aSignalInt.setTime(i);
atracer.recordTrigger(i, i);
}
output_test_stream output;
atracer.display(output);
atracer.stop();
atracer.clearSignalToTrace();
atracer.closeFiles();
acmd->execute();
atracer.record();
BOOST_CHECK(output.is_equal(
"TracerRealTime my-tracer [mode=play] : \n"
" - Dep list: \n"
" -> MyEntity(my-entity)::input(double)::out_double (in output)"
" [0Mo/1Mo] \n"));
}
...@@ -28,7 +28,7 @@ class CustomEntity : public Entity { ...@@ -28,7 +28,7 @@ class CustomEntity : public Entity {
public: public:
static const std::string CLASS_NAME; static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) { explicit CustomEntity(const std::string &n) : Entity(n) {
dynamicgraph::dgDEBUGFLOW.openFile("/tmp/dynamic-graph-traces.txt"); dynamicgraph::dgDEBUGFLOW.openFile("/tmp/dynamic-graph-traces.txt");
} }
~CustomEntity() { ~CustomEntity() {
...@@ -53,10 +53,13 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity"); ...@@ -53,10 +53,13 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
BOOST_AUTO_TEST_CASE(testDebugTrace) { BOOST_AUTO_TEST_CASE(testDebugTrace) {
BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
dynamicgraph::CustomEntity &entity = dynamicgraph::CustomEntity *ptr_entity =
*(dynamic_cast<dynamicgraph::CustomEntity *>( (dynamic_cast<dynamicgraph::CustomEntity *>(
dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
"my-entity"))); "my-entity")));
dynamicgraph::CustomEntity &entity = *ptr_entity;
entity.testDebugTrace(); entity.testDebugTrace();
/// Copy the debug file into the oss_debug_file /// Copy the debug file into the oss_debug_file
...@@ -89,4 +92,6 @@ BOOST_AUTO_TEST_CASE(testDebugTrace) { ...@@ -89,4 +92,6 @@ BOOST_AUTO_TEST_CASE(testDebugTrace) {
two_sub_string_identical = str_to_test == oss_debug_file.str(); two_sub_string_identical = str_to_test == oss_debug_file.str();
BOOST_CHECK(two_sub_string_identical); BOOST_CHECK(two_sub_string_identical);
delete ptr_entity;
} }
...@@ -27,7 +27,7 @@ struct MyEntity : public dynamicgraph::Entity { ...@@ -27,7 +27,7 @@ struct MyEntity : public dynamicgraph::Entity {
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT; dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT; dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT;
MyEntity(const std::string &name) explicit MyEntity(const std::string &name)
: Entity(name), : Entity(name),
m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"), m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2), m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "dynamic-graph/factory.h" #include "dynamic-graph/factory.h"
#include "dynamic-graph/pool.h" #include "dynamic-graph/pool.h"
#include <dynamic-graph/command-direct-getter.h>
#include <dynamic-graph/command-direct-setter.h>
#include <dynamic-graph/entity.h> #include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h> #include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/real-time-logger.h> #include <dynamic-graph/real-time-logger.h>
...@@ -24,21 +26,33 @@ using boost::test_tools::output_test_stream; ...@@ -24,21 +26,33 @@ using boost::test_tools::output_test_stream;
namespace dynamicgraph { namespace dynamicgraph {
class CustomEntity : public Entity { class CustomEntity : public Entity {
public: public:
dynamicgraph::SignalPtr<double, int> m_sigdSIN; dynamicgraph::SignalPtr<double, int> m_sigdSIN, m_sigdSIN2;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT; dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
static const std::string CLASS_NAME; static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) explicit CustomEntity(const std::string &n)
: Entity(n), : Entity(n),
m_sigdSIN(NULL, "CustomEntity(" + name + ")::input(double)::in_double"), m_sigdSIN(NULL, "CustomEntity(" + name + ")::input(double)::in_double"),
m_sigdSIN2(NULL,
"CustomEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT( m_sigdTimeDepSOUT(
boost::bind(&CustomEntity::update, this, _1, _2), m_sigdSIN, boost::bind(&CustomEntity::update, this, _1, _2), m_sigdSIN,
"CustomEntity(" + name + ")::input(double)::out_double") "CustomEntity(" + name + ")::input(double)::out_double"),
m_value(0.0) {}
{}
~CustomEntity() { entityDeregistration(); }
void addSignal() { signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT); }
void addSignal() {
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT);
/// Try a second time to generate an exception
try {
signalRegistration(m_sigdSIN2 << m_sigdTimeDepSOUT);
} catch (ExceptionFactory &aef) {
BOOST_CHECK_EQUAL(aef.getCode(),
dynamicgraph::ExceptionFactory::SIGNAL_CONFLICT);
}
}
void rmValidSignal() { void rmValidSignal() {
signalDeregistration("in_double"); signalDeregistration("in_double");
...@@ -50,21 +64,47 @@ public: ...@@ -50,21 +64,47 @@ public:
res = aDouble; res = aDouble;
return res; return res;
} }
public:
double m_value;
}; };
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity"); DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
} // namespace dynamicgraph } // namespace dynamicgraph
BOOST_AUTO_TEST_CASE(constructor) { BOOST_AUTO_TEST_CASE(constructor) {
BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); namespace dg = dynamicgraph;
namespace dgc = dynamicgraph::command;
dynamicgraph::Entity &entity = BOOST_CHECK_EQUAL(dg::CustomEntity::CLASS_NAME, "CustomEntity");
*dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
"my-entity"); dg::Entity &entity = *dg::FactoryStorage::getInstance()->newEntity(
"CustomEntity", "my-entity");
BOOST_CHECK_EQUAL(entity.getName(), "my-entity"); BOOST_CHECK_EQUAL(entity.getName(), "my-entity");
BOOST_CHECK_EQUAL(entity.getClassName(), BOOST_CHECK_EQUAL(entity.getClassName(), dg::CustomEntity::CLASS_NAME);
dynamicgraph::CustomEntity::CLASS_NAME);
dg::CustomEntity entity2("");
// Test Commands
dgc::DirectGetter<dg::CustomEntity, double> a_direct_getter(
entity2, &entity2.m_value,
dgc::docDirectGetter("Get value m_value", "double"));
dgc::DirectSetter<dg::CustomEntity, double> a_direct_setter(
entity2, &entity2.m_value,
dgc::docDirectSetter("Set value m_value", "double"));
dgc::Value aValue(2.0);
std::vector<dgc::Value> values;
values.push_back(aValue);
a_direct_setter.setParameterValues(values);
a_direct_setter.execute();
a_direct_getter.execute();
output_test_stream output;
output << entity2.m_value;
output << entity2;
dynamicgraph::CustomEntity entity2(""); entity.getDocString();
} }
BOOST_AUTO_TEST_CASE(signal) { BOOST_AUTO_TEST_CASE(signal) {
...@@ -94,6 +134,12 @@ BOOST_AUTO_TEST_CASE(signal) { ...@@ -94,6 +134,12 @@ BOOST_AUTO_TEST_CASE(signal) {
dynamicgraph::CustomEntity *customEntity = dynamicgraph::CustomEntity *customEntity =
dynamic_cast<dynamicgraph::CustomEntity *>(&entity); dynamic_cast<dynamicgraph::CustomEntity *>(&entity);
customEntity->addSignal(); customEntity->addSignal();
std::string signame("CustomEntity(my-entity)::input(double)::in_double");
customEntity->Entity::hasSignal(signame);
output_test_stream output;
customEntity->Entity::displaySignalList(output);
dynamicgraph::Entity::SignalMap asigmap = customEntity->getSignalMap();
output << customEntity;
// Removing signals is working the first time // Removing signals is working the first time
customEntity->rmValidSignal(); customEntity->rmValidSignal();
// Removing signals generates an exception the second time. // Removing signals generates an exception the second time.
......
// Copyright 2020 Olivier Stasse
// LAAS, CNRS
#include <dynamic-graph/exception-abstract.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/exception-traces.h>
#include <sstream>
#include <boost/test/output_test_stream.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_suite.hpp>
using boost::test_tools::output_test_stream;
using namespace dynamicgraph;
BOOST_AUTO_TEST_CASE(exception_abstract) {
std::string msg_aea("Test exception abstract");
ExceptionAbstract aEA(10, msg_aea);
const char *aC = aEA.getMessage();
output_test_stream output;
output << aC;
BOOST_CHECK(output.is_equal("Test exception abstract"));
output << aEA;
BOOST_CHECK(
output.is_equal("AbstractError [#10]: Test exception abstract\n"));
std::string msg_aet("Test exception abstract");
ExceptionTraces aET(ExceptionTraces::GENERIC, msg_aet);
output << aET;
}
...@@ -18,7 +18,7 @@ class CustomEntity : public Entity { ...@@ -18,7 +18,7 @@ class CustomEntity : public Entity {
public: public:
static const std::string CLASS_NAME; static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; } virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {} explicit CustomEntity(const std::string &n) : Entity(n) {}
}; };
const std::string CustomEntity::CLASS_NAME = "CustomEntity"; const std::string CustomEntity::CLASS_NAME = "CustomEntity";
} // namespace dynamicgraph } // namespace dynamicgraph
......
...@@ -23,7 +23,7 @@ struct MyEntity : public dynamicgraph::Entity { ...@@ -23,7 +23,7 @@ struct MyEntity : public dynamicgraph::Entity {
dynamicgraph::SignalPtr<double, int> m_sigdSIN; dynamicgraph::SignalPtr<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT; dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
MyEntity(const std::string &name) explicit MyEntity(const std::string &name)
: Entity(name), : Entity(name),
m_sigdSIN(NULL, "MyEntity(" + name + ")::input(double)::in_double"), m_sigdSIN(NULL, "MyEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2), m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
......
...@@ -45,9 +45,97 @@ BOOST_AUTO_TEST_CASE(test_array) { ...@@ -45,9 +45,97 @@ BOOST_AUTO_TEST_CASE(test_array) {
} }
BOOST_AUTO_TEST_CASE(test_base) { BOOST_AUTO_TEST_CASE(test_base) {
SignalBase<int> sigA("testA");
SignalBase<int> sigB("test"); SignalBase<int> sigB("test");
sigB.setReady(); sigB.setReady();
BOOST_CHECK_EQUAL(true, sigB.getReady()); BOOST_CHECK_EQUAL(true, sigB.getReady());
// Does nothing, just check that the interface
// still exist at the abstract level.
sigB.setPeriodTime(1);
sigB.getPeriodTime();
sigB.addDependency(sigA);
sigB.removeDependency(sigA);
sigB.clearDependencies();
BOOST_CHECK_EQUAL(true, sigB.needUpdate(10));
output_test_stream output;
sigB.writeGraph(output);
BOOST_CHECK(output.is_equal(""));
/// Verify plug operations
bool res = false;
try {
sigB.plug(&sigA);
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
res = false;
try {
sigB.unplug();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
res = false;
try {
sigB.setConstantDefault();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
res = false;
try {
/// Check signal compatibility.
sigB.checkCompatibility();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
/// Verify set command value
/// set
std::istringstream iss("empty");
res = false;
try {
sigB.set(iss);
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// get a value
res = false;
std::ostringstream oss;
try {
sigB.get(oss);
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Trigger revaluation of the signal
res = false;
try {
sigB.recompute(100);
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Trace the signal
res = false;
try {
sigB.trace(oss);
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Display the signal
sigB.display(output);
BOOST_CHECK(output.is_equal("Sig:test"));
} }
BOOST_AUTO_TEST_CASE(test_cast_helper) { BOOST_AUTO_TEST_CASE(test_cast_helper) {
...@@ -60,7 +148,7 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) { ...@@ -60,7 +148,7 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
std::istringstream iss_fail; std::istringstream iss_fail;
iss.str("test"); iss.str("test");
defaultCR.cast(iss_fail); defaultCR.cast(iss_fail);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
// Take int, not string // Take int, not string
} }
} }
\ No newline at end of file
#pragma GCC diagnostic push
#pragma GCC system_header
#include <Eigen/Dense>
#pragma GCC diagnostic pop
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <Eigen/Dense> #include "signal-cast-register-test.h"
#include <dynamic-graph/debug.h> #include <dynamic-graph/debug.h>
#include <dynamic-graph/eigen-io.h> #include <dynamic-graph/eigen-io.h>
#include <dynamic-graph/entity.h> #include <dynamic-graph/entity.h>
...@@ -172,7 +171,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) { ...@@ -172,7 +171,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try { try {
std::istringstream ss("test"); std::istringstream ss("test");
myVectorSignal.set(ss); myVectorSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[0] != \"[\""; std::cout << "Test passed : ss[0] != \"[\"";
} }
...@@ -180,7 +179,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) { ...@@ -180,7 +179,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try { try {
std::istringstream ss("[test"); std::istringstream ss("[test");
myVectorSignal.set(ss); myVectorSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[1] != %i"; std::cout << "Test passed : ss[1] != %i";
} }
...@@ -188,7 +187,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) { ...@@ -188,7 +187,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try { try {
std::istringstream ss("[5["); std::istringstream ss("[5[");
myVectorSignal.set(ss); myVectorSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[2] != \"]\""; std::cout << "Test passed : ss[2] != \"]\"";
} }
...@@ -196,7 +195,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) { ...@@ -196,7 +195,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try { try {
std::istringstream ss("[5]test"); std::istringstream ss("[5]test");
myVectorSignal.set(ss); myVectorSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[3] != \"(\""; std::cout << "Test passed : ss[3] != \"(\"";
} }
...@@ -204,7 +203,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) { ...@@ -204,7 +203,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try { try {
std::istringstream ss("[5](1, "); std::istringstream ss("[5](1, ");
myVectorSignal.set(ss); myVectorSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
BOOST_ERROR("Can't happened"); BOOST_ERROR("Can't happened");
} }
...@@ -212,7 +211,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) { ...@@ -212,7 +211,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try { try {
std::istringstream ss("[5](1,2,3,4,5]"); std::istringstream ss("[5](1,2,3,4,5]");
myVectorSignal.set(ss); myVectorSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[-1] != \")\""; std::cout << "Test passed : ss[-1] != \")\"";
} }
} }
...@@ -233,7 +232,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -233,7 +232,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("test"); std::istringstream ss("test");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[0] != \"[\""; std::cout << "Test passed : ss[0] != \"[\"";
} }
...@@ -241,7 +240,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -241,7 +240,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[test"); std::istringstream ss("[test");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[1] != %i"; std::cout << "Test passed : ss[1] != %i";
} }
...@@ -249,7 +248,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -249,7 +248,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5["); std::istringstream ss("[5[");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[2] != \",\""; std::cout << "Test passed : ss[2] != \",\"";
} }
...@@ -257,7 +256,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -257,7 +256,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,c"); std::istringstream ss("[5,c");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[3] != %i"; std::cout << "Test passed : ss[3] != %i";
} }
...@@ -265,7 +264,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -265,7 +264,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,3["); std::istringstream ss("[5,3[");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[4] != \"]\""; std::cout << "Test passed : ss[4] != \"]\"";
} }
...@@ -273,7 +272,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -273,7 +272,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,3]test"); std::istringstream ss("[5,3]test");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \"(\""; std::cout << "Test passed : ss[5] != \"(\"";
} }
...@@ -281,7 +280,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -281,7 +280,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,3](test"); std::istringstream ss("[5,3](test");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[6] != \"(\""; std::cout << "Test passed : ss[6] != \"(\"";
} }
...@@ -289,7 +288,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -289,7 +288,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,3]((1,"); std::istringstream ss("[5,3]((1,");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
BOOST_ERROR("Can't happened"); BOOST_ERROR("Can't happened");
} }
...@@ -297,7 +296,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -297,7 +296,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,3]((1,2,3]"); std::istringstream ss("[5,3]((1,2,3]");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << ("ss[6+n] != \")\""); std::cout << ("ss[6+n] != \")\"");
} }
...@@ -305,7 +304,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -305,7 +304,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,1]((1)(2)(3["); std::istringstream ss("[5,1]((1)(2)(3[");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\""; std::cout << "Test passed : ss[5] != \")\"";
} }
...@@ -313,7 +312,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -313,7 +312,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[5,1]((1)(2)(3)["); std::istringstream ss("[5,1]((1)(2)(3)[");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\""; std::cout << "Test passed : ss[5] != \")\"";
} }
...@@ -321,7 +320,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) { ...@@ -321,7 +320,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try { try {
std::istringstream ss("[3,1]((1)(2),(3)["); std::istringstream ss("[3,1]((1)(2),(3)[");
myMatrixSignal.set(ss); myMatrixSignal.set(ss);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\" and ignore \",\""; std::cout << "Test passed : ss[5] != \")\" and ignore \",\"";
} }
......
...@@ -3,12 +3,15 @@ ...@@ -3,12 +3,15 @@
#include <string> #include <string>
#include <boost/foreach.hpp>
#include <dynamic-graph/debug.h> #include <dynamic-graph/debug.h>
#include <dynamic-graph/entity.h> #include <dynamic-graph/entity.h>
#include <dynamic-graph/factory.h> #include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h> #include <dynamic-graph/pool.h>
#include <dynamic-graph/signal-base.h> #include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-ptr.h> #include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h> #include <dynamic-graph/signal.h>
#include <iostream> #include <iostream>
...@@ -17,21 +20,128 @@ ...@@ -17,21 +20,128 @@
#include <boost/test/unit_test_suite.hpp> #include <boost/test/unit_test_suite.hpp>
#include <string> #include <string>
using boost::test_tools::output_test_stream;
typedef dynamicgraph::SignalTimeDependent<double, int> sigDouble_t;
typedef dynamicgraph::SignalTimeDependent<std::string, int> sigString_t;
using namespace dynamicgraph; using namespace dynamicgraph;
using std::cout; using std::cout;
BOOST_AUTO_TEST_CASE(normal_test) { template <class T> class DummyClass {
Signal<double, int> sig("sig"); public:
SignalPtr<double, int> sigPtrA(NULL, "sigPtrA"), sigPtrB(NULL, "sigPtrB"); std::string proname;
std::list<sigDouble_t *> inputsig;
std::list<sigString_t *> inputsigV;
explicit DummyClass(const std::string &n)
: proname(n), res(), call(), timedata() {}
T &fun(T &res, int t) {
++call;
timedata = t;
BOOST_FOREACH (sigDouble_t *ptr, inputsig)
ptr->access(timedata);
BOOST_FOREACH (sigString_t *ptr, inputsigV)
ptr->access(timedata);
res = (*this)();
return res;
}
void add(sigDouble_t &sig) { inputsig.push_back(&sig); }
void add(sigString_t &sig) { inputsigV.push_back(&sig); }
T operator()();
T res;
int call;
int timedata;
};
template <> double DummyClass<double>::operator()() {
res = call * timedata;
return res;
}
template <> std::string DummyClass<std::string>::operator()() {
std::ostringstream oss;
oss << call * timedata;
return oss.str();
}
template <class T> T DummyClass<T>::operator()() { return this->res; }
BOOST_AUTO_TEST_CASE(normal_cst_test) {
SignalPtr<double, int> sigNotPlug(NULL, "sigNotPlug"); SignalPtr<double, int> sigNotPlug(NULL, "sigNotPlug");
SignalPtr<double, int> sigPtrAbstract(NULL, "sigPtrAbstract"); const SignalPtr<double, int> cstSigNotPlug(NULL, "sigNotPlug");
try { try {
sigNotPlug.getPtr(); sigNotPlug.getPtr();
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
cout << "Error catch" << std::endl; cout << "Error catch" << std::endl;
} }
// Test getPtr without plug
/// This create a ExceptionSignal::NOT_INITIALIZED
bool res = false;
try {
// Signal<double, int> * r =
sigNotPlug.getPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
/// Testing const getPtr() interface: no plug case
try {
cstSigNotPlug.getPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
/// Test needUpdate without plug
res = (sigNotPlug.needUpdate(5) == false);
BOOST_CHECK(res);
sigNotPlug.getTime();
output_test_stream output;
sigNotPlug.display(output);
cstSigNotPlug.display(output);
/// Testing getAbsatractPtr() interface: no plug
res = false;
try {
sigNotPlug.getAbstractPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
/// Testing const getAbstractPtr() interface: no plug case
try {
cstSigNotPlug.getAbstractPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
try {
sigNotPlug.checkCompatibility();
} catch (...) {
}
BOOST_CHECK(res);
}
BOOST_AUTO_TEST_CASE(normal_test) {
Signal<double, int> sig("sig");
Signal<int, int> sigint("sig");
Signal<std::string, int> sigstr("sig_str");
SignalPtr<double, int> sigPtrA(NULL, "sigPtrA"), sigPtrB(NULL, "sigPtrB");
SignalPtr<double, int> sigPtrAbstract(NULL, "sigPtrAbstract");
DummyClass<double> pro3("pro3");
sig.setConstant(1.56); sig.setConstant(1.56);
sig.recompute(2); sig.recompute(2);
std::string name = "sig"; std::string name = "sig";
...@@ -39,22 +149,72 @@ BOOST_AUTO_TEST_CASE(normal_test) { ...@@ -39,22 +149,72 @@ BOOST_AUTO_TEST_CASE(normal_test) {
std::string test = "test"; std::string test = "test";
try { try {
sig.getClassName(test); sig.getClassName(test);
} catch (ExceptionSignal e) { } catch (ExceptionSignal &e) {
e.getExceptionName(); e.getExceptionName();
} }
BOOST_CHECK(true);
SignalBase<int> &sigRef = sig; sigPtrA.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
/// Plugging signal.
SignalBase<int> &sigRef = sig, sigBase("sigBase");
SignalBase<int> &sigPtrARef = sigPtrA, &sigPtrBRef = sigPtrB, SignalBase<int> &sigPtrARef = sigPtrA, &sigPtrBRef = sigPtrB,
&sigPtrAbstractRef = sigPtrAbstract; &sigPtrAbstractRef = sigPtrAbstract;
sigPtrARef.plug(0);
sigPtrARef.plug(&sigRef); sigPtrARef.plug(&sigRef);
sigPtrBRef.plug(&sigPtrARef); sigPtrBRef.plug(&sigPtrARef);
/// Try to plug an incompatible signal.
/// leave
bool res = false;
try {
sigPtrARef.plug(&sigstr);
} catch (const ExceptionSignal &aes) {
res = (aes.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
// TODO here /// Plug the signal.
sigPtrAbstractRef.plug(&sigRef); sigPtrAbstractRef.plug(&sigRef);
sigPtrA.getPtr(); sigPtrA.getPtr();
BOOST_CHECK(true);
try {
sigPtrARef.checkCompatibility();
} catch (const ExceptionSignal &aes) {
/// Should be NOT_INITIALIZED becase the last plug
/// on sigstr failed.
res = (aes.getCode() == ExceptionSignal::NOT_INITIALIZED);
} catch (const std::exception &e) {
std::cout << "Standard Exception:" << e.what() << std::endl;
} catch (...) {
std::cout << "Anything else: " << std::endl;
}
sigPtrA.needUpdate(5);
BOOST_CHECK(true);
int ltime = sigPtrA.getTime();
sigPtrA.getPluged(); sigPtrA.getPluged();
sigPtrA(ltime);
BOOST_CHECK(true);
sigPtrB.getPtr(); sigPtrB.getPtr();
sigPtrAbstract.getAbstractPtr(); /// Test sigPtrAbstract with a normal plug.
res = false;
try {
sigPtrAbstract.getAbstractPtr();
} catch (ExceptionSignal &aes) {
/// Should be NOT_INITIALIZED becase the last plug
/// on sigstr failed.
std::cout << "Code: " << aes.getCode() << std::endl;
res = (aes.getCode() == ExceptionSignal::NOT_INITIALIZED);
} catch (...) {
std::cout << "Anything else with sigPtrAbstract.getAbstractPtr()"
<< std::endl;