Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cberge/dynamic-graph
  • ostasse/dynamic-graph
  • gsaurel/dynamic-graph
  • stack-of-tasks/dynamic-graph
4 results
Show changes
// Copyright 2010 Thomas Moulard.
//
#include <string>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/pool.h>
#include <boost/foreach.hpp>
#include <iostream>
#include <string>
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_suite.hpp>
#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 std::cout;
template <class T>
class DummyClass {
public:
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;
}
int main( void )
{
using namespace dynamicgraph;
using std::cout;
BOOST_AUTO_TEST_CASE(normal_cst_test) {
SignalPtr<double, int> sigNotPlug(NULL, "sigNotPlug");
const SignalPtr<double, int> cstSigNotPlug(NULL, "sigNotPlug");
Signal<double,int> sig("sig");
SignalPtr<double,int> sigPtrA(NULL,"sigPtrA"),sigPtrB(NULL,"sigPtrB");
try {
sigNotPlug.getPtr();
} catch (ExceptionSignal &e) {
cout << "Error catch" << std::endl;
}
sig.setConstant( 1.56 );
// 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);
SignalBase<int> & sigRef = sig;
SignalBase<int> & sigPtrARef = sigPtrA, & sigPtrBRef = sigPtrB;
sigPtrARef.plug( & sigRef );
sigPtrBRef.plug( & sigPtrARef );
/// Testing const getPtr() interface: no plug case
try {
cstSigNotPlug.getPtr();
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::NOT_INITIALIZED);
}
BOOST_CHECK(res);
cout << "Sig = "; sigRef.get(cout); cout << std::endl;
cout << "SigPtrA = "; sigPtrARef.get(cout); cout << std::endl;
cout << "SigPtrB = "; sigPtrBRef.get(cout); cout << std::endl;
/// 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.recompute(2);
std::string name = "sig";
sig.getClassName(name);
std::string test = "test";
try {
sig.getClassName(test);
} catch (ExceptionSignal &e) {
e.getExceptionName();
}
BOOST_CHECK(true);
sigPtrA.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
sigPtrA.recompute(3);
/// Plugging signal.
SignalBase<int> &sigRef = sig, sigBase("sigBase");
SignalBase<int> &sigPtrARef = sigPtrA, &sigPtrBRef = sigPtrB,
&sigPtrAbstractRef = sigPtrAbstract;
sigPtrARef.plug(0);
sigPtrARef.plug(&sigRef);
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);
/// Plug the signal.
sigPtrAbstractRef.plug(&sigRef);
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(ltime);
BOOST_CHECK(true);
sigPtrB.getPtr();
/// 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;
}
BOOST_CHECK(true);
/// Test the case where the plug ref is zero.
sigPtrAbstractRef.plug(0);
BOOST_CHECK(true);
assert(sigRef.isPlugged() != true);
SignalBase<int> *t = sigRef.getPluged();
// assert(sigPtrA.get()=false);
// TODO Can't check if the constant change
sigPtrA.setConstantDefault(1.2);
// getconstant
sigPtrA.setConstantDefault();
// getconstant
sigPtrA.setConstant(3.4);
// getconstant
double tab_D[2];
tab_D[0] = 1.2;
tab_D[1] = 3.4;
sigPtrA.setReference(tab_D, NULL);
sigPtrA.access(5);
output_test_stream output;
sigPtrA.display(output);
sigPtrA.setReferenceNonConstant(tab_D, NULL);
sigPtrA.access(5);
sigPtrA.display(output);
// getreference
sigPtrA.operator=(1.2);
// getconstant
sigPtrA.displayDependencies(output);
cout << t << std::endl;
cout << "Sig = ";
sigRef.get(cout);
cout << std::endl;
cout << "SigPtrA = ";
sigPtrARef.get(cout);
cout << std::endl;
cout << "SigPtrB = ";
sigPtrBRef.get(cout);
cout << std::endl;
sigPtrA.unplug();
}
BOOST_AUTO_TEST_CASE(plug_signal_string) {
Signal<std::string, int> outSig("output");
SignalPtr<std::string, int> inSig(NULL, "input");
Signal<dynamicgraph::Vector, int> outSigVec("outputVec");
SignalPtr<dynamicgraph::Vector, int> inSigVec(NULL, "inputVec");
std::string str("two words");
outSig.setConstant(str);
inSig.plug(&outSig);
inSig.recompute(1);
std::ostringstream os1;
inSig.get(os1);
std::string res(os1.str());
BOOST_CHECK(res == str);
dynamicgraph::Vector aVec;
aVec.resize(5);
aVec(0) = 1.0;
aVec(1) = 2.0;
aVec(2) = 3.0;
aVec(3) = 4.0;
aVec(4) = 5.0;
outSigVec.setConstant(aVec);
inSigVec.plug(&outSigVec);
inSigVec.recompute(1);
output_test_stream output;
inSigVec.get(output);
BOOST_CHECK(output.is_equal("1 2 3 4 5"));
Signal<std::string, int> s("signal");
std::ostringstream os2;
s.setConstant(str);
os2.clear();
s.get(os2);
res = os2.str();
std::cout << "res=" << res << std::endl;
BOOST_CHECK(res == str);
}
return 0;
BOOST_AUTO_TEST_CASE(set_signal_string) {
Signal<std::string, int> s("signal");
std::string str("");
std::ostringstream os;
os << str;
std::istringstream value(os.str());
try {
s.set(value);
} catch (const std::exception &exc) {
std::cout << exc.what() << std::endl;
BOOST_CHECK(!(bool)("Tentative to set signal to empty string"));
}
}
// Copyright 2010 Thomas Moulard.
//
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h>
#include <boost/foreach.hpp>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <iostream>
#define BOOST_TEST_MODULE signal_time_dependent
#include <boost/test/unit_test.hpp>
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
typedef dynamicgraph::SignalTimeDependent<double, int> sigDouble_t;
typedef dynamicgraph::SignalTimeDependent<std::string, int> sigString_t;
template<class T>
class DummyClass
{
public:
template <class T>
class DummyClass {
public:
std::string proname;
std::list<sigDouble_t*> inputsig;
std::list<sigString_t*> inputsigV;
std::list<sigDouble_t *> inputsig;
std::list<sigString_t *> inputsigV;
DummyClass (const std::string& n)
: proname (n),
res (),
call (),
timedata ()
{}
explicit DummyClass(const std::string &n)
: proname(n), res(), call(), timedata() {}
T& fun (T& res, int t)
{
T &fun(T &res, int t) {
++call;
timedata=t;
timedata = t;
BOOST_FOREACH (sigDouble_t* ptr, inputsig)
ptr->access(timedata);
BOOST_FOREACH (sigDouble_t *ptr, inputsig) ptr->access(timedata);
BOOST_FOREACH (sigString_t* ptr,
inputsigV)
ptr->access(timedata);
BOOST_FOREACH (sigString_t *ptr, inputsigV) ptr->access(timedata);
res = (*this) ();
res = (*this)();
return res;
}
void add (sigDouble_t& sig)
{
inputsig.push_back (&sig);
}
void add (sigString_t& sig)
{
inputsigV.push_back (&sig);
}
void add(sigDouble_t &sig) { inputsig.push_back(&sig); }
void add(sigString_t &sig) { inputsigV.push_back(&sig); }
T operator() ();
T operator()();
T res;
int call;
int timedata;
};
template<>
double
DummyClass<double>::operator() ()
{
res=call * timedata;
template <>
double DummyClass<double>::operator()() {
res = call * timedata;
return res;
}
template<>
std::string
DummyClass<std::string>::operator() ()
{
template <>
std::string DummyClass<std::string>::operator()() {
std::ostringstream oss;
oss << call * timedata;
return oss.str ();
return oss.str();
}
template< class T >
T DummyClass<T>::operator() ()
{
template <class T>
T DummyClass<T>::operator()() {
return this->res;
}
BOOST_AUTO_TEST_CASE (signaltimedependent)
{
DummyClass<double> pro1 ("pro1"), pro3 ("pro3"), pro5 ("pro5");
DummyClass<std::string> pro2 ("pro2"), pro4 ("pro4"), pro6 ("pro6");
BOOST_AUTO_TEST_CASE(signaltimedependent) {
DummyClass<double> pro1("pro1"), pro3("pro3"), pro5("pro5");
DummyClass<std::string> pro2("pro2"), pro4("pro4"), pro6("pro6");
sigDouble_t sig5 ("Sig5");
sigString_t sig6 ("Sig6");
sigDouble_t sig5("Sig5");
sigString_t sig6("Sig6");
sigString_t sig4(sig5, "Sig4");
sigString_t sig2(sig4 << sig4 << sig4 << sig6, "Sig2");
sigDouble_t sig3(sig2 << sig5 << sig6, "Sig3");
sigDouble_t sig1
(boost::bind (&DummyClass<double>::fun, &pro1, _1, _2),
sig2 << sig3, "Sig1");
sigDouble_t sig1(boost::bind(&DummyClass<double>::fun, &pro1, _1, _2),
sig2 << sig3, "Sig1");
sigDouble_t sig7("Sig7");
sig2.setFunction (boost::bind (&DummyClass<std::string>::fun,&pro2, _1, _2));
sig3.setFunction (boost::bind (&DummyClass<double>::fun,&pro3, _1, _2));
sig4.setFunction (boost::bind (&DummyClass<std::string>::fun,&pro4, _1, _2));
sig5.setFunction (boost::bind (&DummyClass<double>::fun,&pro5, _1, _2));
sig6.setFunction (boost::bind (&DummyClass<std::string>::fun,&pro6, _1, _2));
sig2.setFunction(boost::bind(&DummyClass<std::string>::fun, &pro2, _1, _2));
sig3.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2));
sig4.setFunction(boost::bind(&DummyClass<std::string>::fun, &pro4, _1, _2));
sig5.setFunction(boost::bind(&DummyClass<double>::fun, &pro5, _1, _2));
sig6.setFunction(boost::bind(&DummyClass<std::string>::fun, &pro6, _1, _2));
pro1.add(sig2);
pro1.add(sig3);
......@@ -118,127 +100,141 @@ BOOST_AUTO_TEST_CASE (signaltimedependent)
pro3.add(sig5);
pro3.add(sig6);
sig5.setDependencyType (dynamicgraph::TimeDependency<int>::ALWAYS_READY);
sig6.setDependencyType (dynamicgraph::TimeDependency<int>::BOOL_DEPENDENT);
sig5.setDependencyType(dynamicgraph::TimeDependency<int>::ALWAYS_READY);
sig6.setDependencyType(dynamicgraph::TimeDependency<int>::BOOL_DEPENDENT);
sig5.setPeriodTime(3);
assert(sig5.getPeriodTime() == 3);
sig6.setReady();
{
output_test_stream output;
sig1.displayDependencies (output);
BOOST_CHECK (output.is_equal
("-- Sig:Sig1 (Type Fun) (t=0 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=0 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=0 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=0 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"
));
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=0 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=0 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=0 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=0 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=TRUE)\n"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=0 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
BOOST_CHECK (sig1.needUpdate (2));
sig1.access (2);
BOOST_CHECK(sig1.needUpdate(2));
sig1.access(2);
{
output_test_stream output;
sig1.displayDependencies (output);
BOOST_CHECK (output.is_equal
(
"-- Sig:Sig1 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"
));
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=2 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
sig2.access (4);
sig2.access(4);
{
output_test_stream output;
sig1.displayDependencies (output);
BOOST_CHECK (output.is_equal
(
"-- Sig:Sig1 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"
));
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=2 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
sig1.access (4);
sig1.access(4);
{
output_test_stream output;
sig1.displayDependencies (output);
BOOST_CHECK (output.is_equal
(
"-- Sig:Sig1 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"
));
sig1.displayDependencies(output);
BOOST_CHECK(
output.is_equal("-- Sig:Sig1 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig3 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | | `-- Sig:Sig5 (Type Fun) (A)\n"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )\n"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" | `-- Sig:Sig5 (Type Fun) (A)\n"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )\n"
" `-- Sig:Sig5 (Type Fun) (A)"));
}
sig1.needUpdate (6);
sig1.needUpdate (6);
sig1.needUpdate(6);
sig1.needUpdate(6);
output_test_stream output;
sig1.writeGraph(output);
BOOST_CHECK(output.is_equal(""));
sig1.removeDependency(sig3);
BOOST_CHECK(true);
const double &avalue = sig1(6);
output << avalue;
BOOST_CHECK(true);
/// Verify check compatibility
try {
sig1.checkCompatibility();
}
// catch(double e)
catch (...) {
std::cout << "Message: test \n";
}
BOOST_CHECK(true);
}
/* Copyright 2019, LAAS-CNRS
*
* Olivier Stasse
*
*/
#include <unistd.h>
#include <dynamic-graph/process-list.hh>
#include <fstream>
#include <iostream>
#include <sstream>
#define BOOST_TEST_MODULE debug - trace
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
BOOST_AUTO_TEST_CASE(testMt) {
dynamicgraph::CPU::System aSystem;
// create and open a character archive for output
std::ofstream ofs("cpu_state.dat");
boost::archive::text_oarchive oa(ofs);
oa << aSystem;
for (unsigned int i = 0; i < 10; i++) {
usleep(100000);
aSystem.readProcStat();
}
}
// Copyright 2011 Florent Lamiraux, Thomas Moulard.
//
#include <iostream>
#include "dynamic-graph/value.h"
#include <dynamic-graph/exception-factory.h>
#include <iostream>
#define BOOST_TEST_MODULE value
#include <boost/test/unit_test.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 105900
#include <boost/test/tools/output_test_stream.hpp>
#else
#include <boost/test/output_test_stream.hpp>
#endif
#include <boost/test/unit_test.hpp>
using boost::test_tools::output_test_stream;
BOOST_AUTO_TEST_CASE (value_string)
{
using dynamicgraph::command::Value;
namespace dg = dynamicgraph;
BOOST_AUTO_TEST_CASE(value_none) {
using dg::command::Value;
Value value1;
Value value(value1);
// Similar to NaN != NaN
BOOST_CHECK(!(value1 == value));
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=unknown, value="));
}
}
BOOST_AUTO_TEST_CASE(value_bool) {
using dg::command::Value;
bool abool1(false);
Value value1(abool1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=bool, value=0"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=bool, value=0"));
}
}
BOOST_AUTO_TEST_CASE(value_exceptions) {
using dg::command::Value;
Value value1;
dg::command::EitherType anet(value1);
output_test_stream output, output2;
// Check if the exception is working when calling intValue
// while we are having a none.
bool res = false;
try {
int aInt(anet);
aInt++; // silence unused variable warnings to have a stable release in the
// ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
output << aea.getExceptionName();
output2 << aea.what();
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
BOOST_CHECK(output.is_equal("Abstract"));
BOOST_CHECK(output2.is_equal("value is not an int"));
// Check if the exception is working when calling boolValue
// while we are having a none.
res = false;
try {
bool abool(anet);
abool = !abool; // silence unused variable warnings to have a stable
// release in the ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling unsignedintValue
// while we are having a none.
res = false;
try {
unsigned int aint(anet);
aint++; // silence unused variable warnings to have a stable release in the
// ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling doubleValue
// while we are having a none.
res = false;
try {
double adouble(anet);
adouble++; // silence unused variable warnings to have a stable release in
// the ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling floatValue
// while we are having a none.
res = false;
try {
float afloat(anet);
afloat++; // silence unused variable warnings to have a stable release in
// the ros buildfarm
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling stringValue
// while we are having a none.
res = false;
try {
std::string astring(anet);
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling vectorValue
// while we are having a none.
res = false;
try {
dg::Vector avector;
avector = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling matrixXdValue
// while we are having a none.
res = false;
try {
Eigen::MatrixXd amatrixXd;
amatrixXd = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
// Check if the exception is working when calling matrix4dValue
// while we are having a none.
res = false;
try {
Eigen::Matrix4d amatrix4d;
amatrix4d = anet;
} catch (const dg::ExceptionAbstract &aea) {
res = (aea.getCode() == dg::ExceptionAbstract::TOOLS);
}
BOOST_CHECK(res);
}
BOOST_AUTO_TEST_CASE(value_unsigned_int) {
using dg::command::Value;
unsigned int aint1(5);
Value value1(aint1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=unsigned int, value=5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=unsigned int, value=5"));
}
}
BOOST_AUTO_TEST_CASE(value_int) {
using dg::command::Value;
int aint1(5);
Value value1(aint1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=int, value=5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=int, value=5"));
}
}
BOOST_AUTO_TEST_CASE(value_float) {
using dg::command::Value;
float afloat1(0.5);
Value value1(afloat1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=float, value=0.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=float, value=0.5"));
}
}
BOOST_AUTO_TEST_CASE(value_double) {
using dg::command::Value;
double adouble1(0.5);
Value value1(adouble1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=double, value=0.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=double, value=0.5"));
}
}
BOOST_AUTO_TEST_CASE(value_vector) {
using dg::command::Value;
dg::Vector avector1;
avector1.resize(2);
avector1[0] = 0.5;
avector1[1] = 1.5;
Value value1(avector1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=vector, value=0.5\n1.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=vector, value=0.5\n1.5"));
}
}
BOOST_AUTO_TEST_CASE(value_string) {
using dg::command::Value;
std::string str1("value #1");
Value value1(str1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK (output.is_equal ("Type=string, value=value #1"));
BOOST_CHECK(output.is_equal("Type=string, value=value #1"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK (output.is_equal ("Type=string, value=value #1"));
BOOST_CHECK(output.is_equal("Type=string, value=value #1"));
}
std::string str2("value #2");
......@@ -38,12 +316,116 @@ BOOST_AUTO_TEST_CASE (value_string)
{
output_test_stream output;
output << value2;
BOOST_CHECK (output.is_equal ("Type=string, value=value #2"));
BOOST_CHECK(output.is_equal("Type=string, value=value #2"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK (output.is_equal ("Type=string, value=value #2"));
BOOST_CHECK(output.is_equal("Type=string, value=value #2"));
}
}
BOOST_AUTO_TEST_CASE(value_matrixXd) {
using dg::command::Value;
Eigen::MatrixXd avector1;
avector1.resize(2, 2);
avector1(0, 0) = 0.5;
avector1(0, 1) = 1.5;
avector1(1, 0) = 2.5;
avector1(1, 1) = 3.5;
Value value1(avector1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(output.is_equal("Type=matrixXd, value=0.5 1.5\n2.5 3.5"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(output.is_equal("Type=matrixXd, value=0.5 1.5\n2.5 3.5"));
}
}
BOOST_AUTO_TEST_CASE(value_matrix4d) {
using dg::command::Value;
Eigen::Matrix4d avector1;
avector1.setZero();
avector1(0, 0) = 0.5;
avector1(0, 1) = 1.5;
avector1(1, 0) = 2.5;
avector1(1, 1) = 3.5;
Value value1(avector1);
Value value = value1;
BOOST_CHECK(value1 == value);
{
output_test_stream output;
output << value1;
BOOST_CHECK(
output.is_equal("Type=matrix4d, value=0.5 1.5 0 0\n"
"2.5 3.5 0 0\n 0 0 0 0\n"
" 0 0 0 0"));
}
{
output_test_stream output;
output << value;
BOOST_CHECK(
output.is_equal("Type=matrix4d, value=0.5 1.5 0 0\n"
"2.5 3.5 0 0\n 0 0 0 0\n"
" 0 0 0 0"));
}
}
BOOST_AUTO_TEST_CASE(value_values) {
using namespace dynamicgraph::command;
std::string s1("value #1");
double d1 = 0.3;
Value vs1(s1);
Value vd1(d1);
Values values;
values.push_back(vs1);
values.push_back(vd1);
Value vvalues(values);
BOOST_CHECK_EQUAL(vvalues.type(), Value::VALUES);
{ // Const ref
const Values &vs = vvalues.constValuesValue();
BOOST_CHECK_EQUAL(vs.size(), values.size());
BOOST_CHECK(vs == values);
}
{
// Cast does not work.
// dg::command::EitherType eitherType (vvalues);
// Values vs = static_cast<Values>(eitherType);
// BOOST_CHECK_EQUAL(vs.size(), values.size());
// BOOST_CHECK(vs == values);
} { // Constructor
Value vvs(vvalues);
BOOST_CHECK(vvs == vvalues);
}
{
output_test_stream output;
output << vvalues;
BOOST_CHECK(
output.is_equal("Type=values, value=[ "
"Value(Type=string, value=value #1), "
"Value(Type=double, value=0.3), "
"]"));
}
}