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
Select Git revision

Target

Select target project
  • cberge/dynamic-graph
  • ostasse/dynamic-graph
  • gsaurel/dynamic-graph
  • stack-of-tasks/dynamic-graph
4 results
Select Git revision
Show changes
#
# Copyright
#
### tests
SET(tests
test_shell
test_pool
test_depend
test_factory)
FOREACH(test_name ${tests})
SET(EXECUTABLE_NAME ${test_name})
ADD_DEFINITIONS(-DDEBUG=2)
ADD_EXECUTABLE(${EXECUTABLE_NAME}
${test_name}.cpp)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
LINK_DIRECTORIES(${${PROJECT_NAME}_BINARY_DIR}/lib)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
${PROJECT_NAME}
dl)
INSTALL(TARGETS ${test_name}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
ENDFOREACH(test_name)
\ No newline at end of file
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 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;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_factory.cc
* Project: SOT
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <string>
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
using namespace std;
using namespace dynamicgraph;
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
#ifdef WIN32
typedef HMODULE sotPluginKey;
#else
typedef void* sotPluginKey;
#endif
int main()
{
dgDEBUG(0) << "# In {"<<endl;
// Entity test("");
// sotExceptionFeature t2(sotExceptionFeature::BAD_INIT);
// sotExceptionSignal t4(sotExceptionSignal::COPY_NOT_INITIALIZED);
// sotFlags t3;
// TestFeature t5;
#ifndef WIN32
sotPluginKey dlib = dlopen("lib/plugin/sotFeatureVisualPoint.so", RTLD_NOW);
#else
sotPluginKey dlib = LoadLibrary ( "lib/plugin/sotFeatureVisualPoint.lib");
#endif
if( NULL==dlib )
{
cerr << " Error dl"<<endl;
#ifndef WIN32
cerr << dlerror() <<endl;
#else
// Retrieve the system error message for the last-error code
LPTSTR pszMessage;
DWORD dwLastError = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&pszMessage,
0, NULL );
cerr << pszMessage <<endl;
LocalFree(pszMessage);
#endif
exit(0);
}
#ifndef WIN32
dlib = dlopen("lib/plugin/sotGainAdaptative.so", RTLD_NOW);
#else
dlib = LoadLibrary ("lib/plugin/sotGainAdaptative.lib");
#endif
if( NULL==dlib )
{
cout << "This test can only be run after the package StackOfTasks has been installed\n"
"Could not find sotGainAdaptive shared library" << endl;
#ifndef WIN32
cerr << dlerror() <<endl;
#else
// Retrieve the system error message for the last-error code
LPTSTR pszMessage;
DWORD dwLastError = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&pszMessage,
0, NULL );
cerr << pszMessage <<endl;
LocalFree(pszMessage);
#endif
exit(0);
}
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;
cout <<gain->getClassName(); cout << endl;
dgDEBUG(0) << "# Out }"<<endl;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_entity.cc
* Project: dynamicGraph
* Author: François Bleibel
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <string>
#include <iostream>
#include <cstdlib>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/pool.h>
#include <memory>
using namespace std;
using namespace dynamicgraph;
class MyEntity
: public Entity
{
public:
MyEntity(const std::string& name);
public: /* --- ENTITY INHERITANCE --- */
static const std::string CLASS_NAME;
virtual void display( std::ostream& os ) const;
virtual const std::string& getClassName( void ) const { return CLASS_NAME; }
protected:
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity,"MyEntity");
MyEntity::MyEntity(const std::string& name)
: Entity(name){
}
void MyEntity::display(std::ostream& os ) const {
os << "Hello! My name is " << getName() << " !" << endl;
}
main() {
MyEntity myEntity("MyEntity");
cout << "-- Pool.list" << endl;
pool.commandLine("pool", "list", *auto_ptr<istringstream>(new istringstream("")), cout);
Entity& e = pool.getEntity("MyEntity");
cout << "-- Display" << endl;
e.display(cout);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-JAPAN, Tsukuba, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: test_shell.cc
* Project: SOT
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include <dynamic-graph/entity.h>
#include <dynamic-graph/plugin-loader.h>
#include <dynamic-graph/interpreter.h>
#include <dynamic-graph/debug.h>
#include <sstream>
using namespace std;
using namespace dynamicgraph;
extern std::ofstream debugfile;
int main( int argc,char** argv )
{
dgDEBUGIN(15);
dgDEBUG(5) << " Loading..." << endl;
PluginLoader pl;
Shell.referencePluginLoader( &pl );
int fileIdx;
try
{
for( fileIdx=1;fileIdx<argc;++fileIdx )
{
std::istringstream script( argv[fileIdx] );
cout << "Run "<< argv[fileIdx] << endl;
Shell.cmd( "run",script,cout );
}
}
catch( ExceptionAbstract& e )
{
cout << "!! In file <" << argv[fileIdx] << "> : " << e <<endl;
}
catch ( const char* str ) {
cout << "!! In file <" << argv[fileIdx] << "> : "
<< "Unknown exception " << str << endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
while(1)
{
try
{
dgDEBUG(5) << "Run shell." << endl;
Shell.shell(cin,cout);
dgDEBUG(5) << "Shell over." << endl;
if( cin.eof() ) break;
}
catch( ExceptionAbstract& e )
{
cout << "!! " << e <<endl;
}
catch( ... ){ dgDEBUG(5) << "!! Unknown! " <<endl ; }
}
dgDEBUGOUT(15);
return 0;
}