Commit 4271a05a authored by Bergé's avatar Bergé

Commit for PR

parent ee04e13f
......@@ -49,7 +49,6 @@ DYNAMIC_GRAPH_TEST(signal-cast-registerer)
IF(NOT APPLE)
DYNAMIC_GRAPH_TEST(entity)
ENDIF(NOT APPLE)
DYNAMIC_GRAPH_TEST(command)
DYNAMIC_GRAPH_TEST(custom-entity)
DYNAMIC_GRAPH_TEST(factory)
DYNAMIC_GRAPH_TEST(pool)
......@@ -62,3 +61,4 @@ DYNAMIC_GRAPH_TEST(debug-tracer)
TARGET_LINK_LIBRARIES(debug-tracer tracer)
DYNAMIC_GRAPH_TEST(debug-logger)
DYNAMIC_GRAPH_TEST(debug-logger-winit)
DYNAMIC_GRAPH_TEST(signal-all)
//
// Created by corentin on 7/3/19.
//
#include <boost/foreach.hpp>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/signal-array.h>
#include <dynamic-graph/command-bind.h>
#include <dynamic-graph/tracer.h>
#include <assert.h>
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#define BOOST_TEST_MODULE signal_array
using boost::test_tools::output_test_stream;
dynamicgraph::SignalArray_const<double> sig;
using namespace std;
using namespace dynamicgraph;
using namespace dynamicgraph::command;
template <class E >
struct CV0 : public dynamicgraph::command::CommandVoid0<E> {
public:
CV0(E& entity, boost::function<void(void)> function,
const std::string& docString)
: dynamicgraph::command::CommandVoid0<E>(entity, function, docString),test(function)
{};
void Exec() {
dynamicgraph::command::CommandVoid0<E>::doExecute();
}
private:
boost::function<void(void)> test;
};
template <class E >
CV0<E>* makeCV0(E& entity, boost::function<void(void)> function,
const std::string& docString)
{
return new CV0<E>(entity,function,docString);
}
Tracer::Tracer( const std::string n )
:Entity(n)
,toTraceSignals ()
,traceStyle(TRACE_STYLE_DEFAULT)
,frequency(1)
,basename ()
,suffix(".dat")
,rootdir ()
,namesSet( false )
,files ()
,names ()
,play(false)
,timeStart(0)
,triger( boost::bind(&Tracer::recordTrigger,this,_1,_2),
sotNOSIGNAL,
"Tracer("+n+")::triger" )
{
std::string doc;
doc = docCommandVoid0("test");
addCommand("clear",
makeCV0(*this,&Tracer::clearSignalToTrace,doc ));
}
BOOST_AUTO_TEST_CASE (test) {
output_test_stream test;
test << "1";
BOOST_CHECK(test.is_equal("1"));
}
\ No newline at end of file
// Copyright 2010 Thomas Moulard.
//
#include <iostream>
#include <sstream>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/entity.h>
......@@ -17,129 +18,143 @@ using boost::test_tools::output_test_stream;
namespace dynamicgraph
{
class CustomEntity : public Entity
{
public:
static const std::string CLASS_NAME;
virtual const std::string& getClassName () const
class CustomEntity : public Entity
{
return CLASS_NAME;
}
CustomEntity (const std::string n)
: Entity (n)
{
}
};
const std::string CustomEntity::CLASS_NAME = "CustomEntity";
public:
static const std::string CLASS_NAME;
virtual const std::string& getClassName () const
{
return CLASS_NAME;
}
CustomEntity (const std::string n)
: Entity (n)
{
}
};
const std::string CustomEntity::CLASS_NAME = "CustomEntity";
}
dynamicgraph::Entity* makeEntity(const std::string& objectName)
{
return new dynamicgraph::CustomEntity (objectName);
return new dynamicgraph::CustomEntity (objectName);
}
BOOST_AUTO_TEST_CASE (constructor)
{
dynamicgraph::FactoryStorage::getInstance();
dynamicgraph::FactoryStorage::getInstance();
}
BOOST_AUTO_TEST_CASE (registerEntity)
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
try
try
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
BOOST_ERROR ("Should never happen.");
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
}
try
try
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", 0);
BOOST_ERROR ("Should never happen.");
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", 0);
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
}
}
BOOST_AUTO_TEST_CASE (unregisterEntity)
{
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity ("myEntity");
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity ("myEntity");
try
try
{
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity("myEntity");
BOOST_ERROR ("Should never happen.");
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity("myEntity");
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
}
try
try
{
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity
("I do not exist.");
BOOST_ERROR ("Should never happen.");
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity
("I do not exist.");
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
}
}
BOOST_AUTO_TEST_CASE (newEntity)
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
{
boost::shared_ptr<dynamicgraph::Entity> entity
(dynamicgraph::FactoryStorage::getInstance()->newEntity
("myEntity", "foo"));
{
boost::shared_ptr<dynamicgraph::Entity> entity
(dynamicgraph::FactoryStorage::getInstance()->newEntity
("myEntity", "foo"));
boost::shared_ptr<dynamicgraph::Entity> entity2
(dynamicgraph::FactoryStorage::getInstance()->newEntity
("myEntity", "foo2"));
boost::shared_ptr<dynamicgraph::Entity> entity2
(dynamicgraph::FactoryStorage::getInstance()->newEntity
("myEntity", "foo2"));
boost::shared_ptr<dynamicgraph::Entity> entity3
(dynamicgraph::FactoryStorage::getInstance()->newEntity
("myEntity", ""));
}
boost::shared_ptr<dynamicgraph::Entity> entity3
(dynamicgraph::FactoryStorage::getInstance()->newEntity
("myEntity", ""));
}
try
{
dynamicgraph::FactoryStorage::getInstance()->newEntity
("I do not exist.", "");
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::UNREFERED_OBJECT);
}
try
try
{
dynamicgraph::FactoryStorage::getInstance()->newEntity
("I do not exist.", "");
BOOST_ERROR ("Should never happen.");
dynamicgraph::FactoryStorage::getInstance()->destroy();
dynamicgraph::FactoryStorage::getInstance()->existEntity("myEntity");
//BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::UNREFERED_OBJECT);
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::UNREFERED_OBJECT);
}
}
BOOST_AUTO_TEST_CASE (existEntity)
{
BOOST_CHECK (dynamicgraph::FactoryStorage::getInstance()->existEntity
("myEntity"));
BOOST_CHECK (!dynamicgraph::FactoryStorage::getInstance()->existEntity
("myEntity2"));
BOOST_CHECK (!dynamicgraph::FactoryStorage::getInstance()->existEntity (""));
//BOOST_CHECK (dynamicgraph::FactoryStorage::getInstance()->existEntity
// ("myEntity"));
BOOST_CHECK (!dynamicgraph::FactoryStorage::getInstance()->existEntity
("myEntity2"));
BOOST_CHECK (!dynamicgraph::FactoryStorage::getInstance()->existEntity (""));
}
//
// Created by corentin on 7/3/19.
//
#include <boost/foreach.hpp>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/signal-array.h>
#include <dynamic-graph/tracer.h>
#include <dynamic-graph/signal-cast-helper.h>
#include <assert.h>
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#define BOOST_TEST_MODULE signal_array
using boost::test_tools::output_test_stream;
dynamicgraph::SignalArray_const<double> sig;
using namespace std;
using namespace dynamicgraph;
using namespace dynamicgraph::command;
BOOST_AUTO_TEST_CASE (test_array) {
SignalBase<int> sigBa("add test");
SignalArray_const<int> sigArr_C(1);
sigArr_C.operator<<(sigBa);
sigArr_C.operator<<(sigBa);
BOOST_CHECK_EQUAL(2, sigArr_C.getSize());
SignalArray<int> sigArr(1);
sigArr.operator<<(sigBa);
sigArr.operator<<(sigBa);
BOOST_CHECK_EQUAL(2,sigArr.getSize());
SignalBase<int> sigB("constructor test");
SignalArray<int> sigA(2);
sigA << sigB;
sigA.operator<<(sigB);
SignalArray_const<int> sig_C(sigA);
BOOST_CHECK_EQUAL(sigA.getSize(),sig_C.getSize());
}
BOOST_AUTO_TEST_CASE(test_base)
{
SignalBase<int> sigB("test");
sigB.setReady();
BOOST_CHECK_EQUAL(true,sigB.getReady());
}
BOOST_AUTO_TEST_CASE(test_cast_helper)
{
DefaultCastRegisterer<int> defaultCR;
std::istringstream iss;
iss.str("1");
defaultCR.cast(iss);
try{
std::istringstream iss_fail;
iss.str("test");
defaultCR.cast(iss_fail);
} catch(ExceptionSignal e){
//Take int, not string
}
}
\ No newline at end of file
//
// Created by corentin on 7/3/19.
//
#include <boost/foreach.hpp>
#include <dynamic-graph/signal.h>
#define BOOST_TEST_MODULE signal_array
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
typedef dynamicgraph::SignalArray_const<int> sigInt_t;
template <>
class DummyClass
{
public:
DEF_SIZE = 20;
protected:
std::list<int> inputsig;
unsigned int inputsig_S,inputsig_R;
};
\ No newline at end of file
......@@ -8,60 +8,78 @@
#include <dynamic-graph/factory.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/pool.h>
#include <iostream>
//#define BOOST_TEST_MODULE signal_ptr
/*#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>*/
/*using boost::test_tools::output_test_stream;
typedef dynamicgraph::SignalPtr<double, int> sigDouble_t;
template<class T>
class DummyClass
{
public:
std::string proname;*/
#include <string>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
using namespace dynamicgraph;
using std::cout;
int main( void )
BOOST_AUTO_TEST_CASE(normal_test)
{
using namespace dynamicgraph;
using std::cout;
Signal<double,int> sig("sig");
SignalPtr<double,int> sigPtrA(NULL,"sigPtrA"),sigPtrB(NULL,"sigPtrB");
SignalPtr<double,int> sigNotPlug(NULL,"sigNotPlug");
SignalPtr<double,int> sigPtrAbstract(NULL,"sigPtrAbstract");
try {
sigNotPlug.getPtr();
} catch (ExceptionSignal e){
cout << "Error catch" << std::endl;
}
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();
}
SignalBase<int> & sigRef = sig;
SignalBase<int> & sigPtrARef = sigPtrA, & sigPtrBRef = sigPtrB;
SignalBase<int> & sigPtrARef = sigPtrA, & sigPtrBRef = sigPtrB, & sigPtrAbstractRef = sigPtrAbstract;
sigPtrARef.plug( & sigRef );
sigPtrBRef.plug( & sigPtrARef );
assert(sigRef.isPlugged()!=true);
sigPtrBRef.unplug();
assert(sigPtrBRef.isPlugged()!=true);
//TODO here
sigPtrAbstractRef.plug( & sigRef);
sigPtrA.getPtr();
sigPtrA.getPluged();
sigPtrB.getPtr();
sigPtrAbstract.getAbstractPtr();
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);
//getreference
sigPtrA.operator=(1.2);
//getconstant
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;
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment