Skip to content
Snippets Groups Projects
Commit 9dd7ed09 authored by Francois Bleibel's avatar Francois Bleibel
Browse files

Added two unit tests.

- signals dependency testing
- factory testing (needs some SOT shared libraries to work though)
parent 2892dc41
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
SET(tests SET(tests
test_shell test_shell
test_pool test_pool
test_depend) test_depend
test_factory)
FOREACH(test_name ${tests}) FOREACH(test_name ${tests})
SET(EXECUTABLE_NAME ${test_name}) SET(EXECUTABLE_NAME ${test_name})
......
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet VISTA / IRISA, 2003
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_categorie.cc
* Project: Traces
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id: test_boost.cpp,v 1.1.1.1 2006-07-03 05:17:37 nmansard Exp $
*
* Description
* ============
*
* Test la classe CategorieTrace.
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
// #include <sot/sotSignal.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-time-dependant.h>
//#include <sot/TimeDependancy.h>
#include <dynamic-graph/debug.h>
#include <iostream>
#include <string>
using namespace std;
template< class Res=double >
class DummyClass
{
public:
std::string proname;
list< SignalTimeDependant<double,int>* > inputsig;
list< SignalTimeDependant<string,int>* > inputsigV;
public:
DummyClass( const std::string& n ) : proname(n),res(),appel(0),timedata(0) {}
Res& fun( Res& res,int t)
{
appel++; timedata=t;
cout << "Inside " << proname << " -> " << this
<< endl;
for( list< SignalTimeDependant<double,int>* >::iterator it=inputsig.begin();
it!=inputsig.end();++it )
{
cout << *(*it) << endl;
(*it)->access(timedata);
}
for( list< SignalTimeDependant<string,int>* >::iterator it=inputsigV.begin();
it!=inputsigV.end();++it )
{ cout << *(*it) << endl; (*it)->access(timedata);}
return res=(*this)();
}
void add( SignalTimeDependant<double,int>& sig )
{ inputsig.push_back(&sig); }
void add( SignalTimeDependant<string,int>& sig )
{ inputsigV.push_back(&sig); }
Res operator() ( void );
Res res;
int appel;
int timedata;
};
template< class Res >
Res DummyClass<Res>::operator() (void)
{ return this->res; }
template<>
double DummyClass<double>::operator() (void)
{
res=appel*timedata; return res;
}
template<>
string DummyClass<string>::operator() (void)
{
ostringstream oss;
oss << appel*timedata;
return oss.str();
}
int main( void )
{
DummyClass<double> pro1("pro1"),pro3("pro3"),pro5("pro5");
DummyClass<string> pro2("pro2"),pro4("pro4"),pro6("pro6");
SignalTimeDependant<double,int> sig5("Sig5");
SignalTimeDependant<string,int> sig6("Sig6");
SignalTimeDependant<string,int> sig4(sig5,"Sig4");
SignalTimeDependant<string,int> sig2(sig4<<sig4<<sig4<<sig6,"Sig2");
SignalTimeDependant<double,int> sig3(sig2<<sig5<<sig6,"Sig3");
SignalTimeDependant<double,int> sig1( boost::bind(&DummyClass<double>::fun,&pro1,_1,_2),
sig2<<sig3,"Sig1");
// cout << "--- Test Array ------ "<<endl;
// sotSignalArray<int> tarr(12);
// tarr<<sig3<<sig2;//+sig2+sig3;
// dispArray(sig4<<sig2<<sig3);
// dispArray(tarr);
sig2.setFunction( boost::bind(&DummyClass<string>::fun,&pro2,_1,_2) );
sig3.setFunction( boost::bind(&DummyClass<double>::fun,&pro3,_1,_2) );
sig4.setFunction( boost::bind(&DummyClass<string>::fun,&pro4,_1,_2) );
sig5.setFunction( boost::bind(&DummyClass<double>::fun,&pro5,_1,_2) );
sig6.setFunction( boost::bind(&DummyClass<string>::fun,&pro6,_1,_2) );
pro1.add(sig2);
pro1.add(sig3);
pro2.add(sig4);
pro2.add(sig4);
pro2.add(sig4);
pro3.add(sig2);
pro4.add(sig5);
pro2.add(sig6);
pro3.add(sig5);
pro3.add(sig6);
sig5.setDependancyType(TimeDependancy<int>::ALWAYS_READY);
sig6.setDependancyType(TimeDependancy<int>::BOOL_DEPENDANT);
sig6.setReady();
sig1.displayDependancies(cout)<<endl;
cout << "Needs update?"<< endl << sig1.needUpdate(2) << endl;
dgDEBUG(1) << "Access sig1(2) "<<endl;
sig1.access(2);
sig1.displayDependancies(cout)<<endl;
dgDEBUG(1) << "Access sig2(4) "<<endl;
sig2.access(4);
sig1.displayDependancies(cout)<<endl;
dgDEBUG(1) << "Access sig1(4) "<<endl;
sig1.access(4);
sig1.displayDependancies(cout)<<endl;
sig1.needUpdate(6);
sig1.needUpdate(6);
return 0;
}
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <sstream>
#include <dynamic-graph/factory.h> #include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h> #include <dynamic-graph/entity.h>
...@@ -96,7 +97,8 @@ if( NULL==dlib ) ...@@ -96,7 +97,8 @@ if( NULL==dlib )
#endif #endif
if( NULL==dlib ) if( NULL==dlib )
{ {
cerr << " Error dl"<<endl; cout << "This test can only be run after the package StackOfTasks has been installed\n"
"Could not find sotGainAdaptive shared library" << endl;
#ifndef WIN32 #ifndef WIN32
cerr << dlerror() <<endl; cerr << dlerror() <<endl;
#else #else
...@@ -120,7 +122,13 @@ if( NULL==dlib ) ...@@ -120,7 +122,13 @@ if( NULL==dlib )
exit(0); exit(0);
} }
Entity* gain = factory.newEntity("GainAdaptative","Gain"); Entity* gain = 0;
if ( !factory.existEntity("GainAdaptative") ) {
cout << "Could not find entity class 'GainAdaptative'" << endl;
exit(0);
}
else
gain = factory.newEntity("GainAdaptative","Gain");
gain->display(cout); cout << endl; gain->display(cout); cout << endl;
......
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