Unverified Commit 982a0e0e authored by Guilhem Saurel's avatar Guilhem Saurel Committed by GitHub

Merge pull request #43 from corentinberge/coverage

Coverage
parents 1bcf9a54 c6e0ce11
Pipeline #5239 passed with stage
in 8 minutes and 25 seconds
......@@ -62,7 +62,7 @@ namespace dynamicgraph {
#define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg,MSG_TYPE_WARNING_STREAM)
#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg,MSG_TYPE_ERROR_STREAM)
template<typename T>
/*template<typename T>
std::string toString(const T& v, const int precision=3, const int width=-1)
{
std::stringstream ss;
......@@ -71,7 +71,7 @@ namespace dynamicgraph {
else
ss<<std::fixed<<std::setprecision(precision)<<v;
return ss.str();
}
}*/
template<typename T>
std::string toString(const std::vector<T>& v, const int precision=3, const int width=-1,
......
......@@ -61,10 +61,9 @@ namespace dynamicgraph
SignalBase<Time>* getAbstractPtr (); // throw
const SignalBase<Time>* getAbstractPtr () const; // throw
virtual void plug( SignalBase<Time>* ref );
virtual void unplug () { plug(NULL); }
virtual bool isPluged () const DYNAMIC_GRAPH_DEPRECATED {
return isPlugged ();
}
virtual bool isPlugged () const { return (NULL!=signalPtr); }
virtual SignalBase<Time>* getPluged () const { return signalPtr; }
virtual bool isAbstractPluged () const;
......
......@@ -12,6 +12,7 @@
#endif
#define ENABLE_RT_LOG
#include <sstream>
#include <stdio.h>
#include <iostream>
#include <iomanip> // std::setprecision
......@@ -65,7 +66,9 @@ namespace dynamicgraph
if( isStreamMsg(type))
{
// check whether counter already exists
string id = file+toString(line);
std::ostringstream oss;
oss << file << line;
std::string id (oss.str());
map<string,double>::iterator it = m_stream_msg_counters.find(id);
if(it == m_stream_msg_counters.end())
{
......
......@@ -85,7 +85,7 @@ void CPUData::ProcessLine(std::istringstream &aCPULine)
guest_time_ = lguest_all_time;
total_time_ = ltotal_time;
if (total_period_!=0.0)
if (total_period_!=0)
{
percent_ = (double)(user_mode_period_)/(double)(total_period_) * 100.0;
percent_ += (double)( nice_period_)/(double)(total_period_) * 100.0;
......@@ -94,8 +94,7 @@ void CPUData::ProcessLine(std::istringstream &aCPULine)
percent_ += (double)( softirq_period_)/(double)(total_period_) * 100.0;
percent_ += (double)( steal_period_)/(double)(total_period_) * 100.0;
percent_ += (double)( iowait_period_)/(double)(total_period_) * 100.0;
}
std::cout << cpu_id_ << " " << percent_ << std::endl;
}
}
System::System()
......
......@@ -61,6 +61,7 @@ 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)
DYNAMIC_GRAPH_TEST(command-test)
DYNAMIC_GRAPH_TEST(test-mt)
TARGET_LINK_LIBRARIES(test-mt tracer)
TARGET_LINK_LIBRARIES(test-mt tracer)
\ No newline at end of file
......@@ -50,6 +50,7 @@ BOOST_AUTO_TEST_CASE (constructor)
dynamicgraph::FactoryStorage::getInstance()->
newEntity("CustomEntity", "my-entity");
BOOST_CHECK_EQUAL (entity->getName (), "my-entity");
BOOST_CHECK_EQUAL (entity->Entity::getClassName (), "Entity");
BOOST_CHECK_EQUAL (entity->getClassName (), CustomEntity::CLASS_NAME);
//CustomEntity entity2 ("");
......
......@@ -17,129 +17,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
......@@ -25,18 +25,20 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#include <iostream>
using boost::test_tools::output_test_stream;
typedef Eigen::VectorXd Vector;
typedef Eigen::MatrixXd Matrix;
struct EigenCastRegisterer : public dynamicgraph::SignalCastRegisterer
struct EigenCastRegisterer_V : public dynamicgraph::SignalCastRegisterer
{
typedef Vector bnuVector;
EigenCastRegisterer () :
EigenCastRegisterer_V () :
SignalCastRegisterer
(typeid(bnuVector), dispVector, castVector, traceVector)
{}
......@@ -66,7 +68,38 @@ struct EigenCastRegisterer : public dynamicgraph::SignalCastRegisterer
}
};
EigenCastRegisterer myVectorCast;
template<typename Derived>
struct EigenCastRegisterer_M : public dynamicgraph::SignalCastRegisterer
{
typedef Matrix bnuMatrix;
EigenCastRegisterer_M () :
SignalCastRegisterer
(typeid(bnuMatrix), dispMatrix, castMatrix, traceMatrix)
{}
static boost::any castMatrix (std::istringstream& iss)
{
bnuMatrix res;
iss >> res;
return res;
}
static void dispMatrix (const boost::any& object, std::ostream& os)
{
const bnuMatrix& m = boost::any_cast<bnuMatrix> (object);
os << m << std::endl;
}
static void traceMatrix (const boost::any& object, std::ostream& os)
{
const bnuMatrix& m = boost::any_cast<bnuMatrix> (object);
os << m << std::endl;
}
};
EigenCastRegisterer_V myVectorCast;
EigenCastRegisterer_M<int> myMatrixCast;
// Define a new cast with a type that supports streaming operators to
// and from it (this could be automated with macros).
......@@ -109,6 +142,7 @@ BOOST_AUTO_TEST_CASE (standard_double_registerer)
output_test_stream output;
mySignal.trace (output);
BOOST_CHECK (output.is_equal (test.second));
}
}
......@@ -156,24 +190,166 @@ BOOST_AUTO_TEST_CASE (custom_vector_registerer)
BOOST_CHECK (output.is_equal (fmt.str ()));
}
//Catch Exception of ss (not good input)
//ss[0] != "["
try {
std::istringstream ss ("test");
myVectorSignal.set (ss);
} catch(ExceptionSignal e) {
std::cout << "Test passed : ss[0] != \"[\"";
}
//ss[1] != %i
try {
std::istringstream ss ("[test");
myVectorSignal.set (ss);
} catch(ExceptionSignal e) {
std::cout << "Test passed : ss[1] != %i";
}
//ss[2] != "]"
try {
std::istringstream ss ("[5[");
myVectorSignal.set (ss);
} catch(ExceptionSignal e) {
std::cout << "Test passed : ss[2] != \"]\"";
}
//ss[3] != "("
try {
std::istringstream ss ("[5]test");
myVectorSignal.set (ss);
} catch(ExceptionSignal e) {
std::cout << "Test passed : ss[3] != \"(\"";
}
//ss[4] != ' ' || ','
try {
std::istringstream ss ("[5](1, ");
myVectorSignal.set (ss);
} catch(ExceptionSignal e) {
BOOST_ERROR("Can't happened");
}
//ss[-1] != ")"
try {
std::istringstream ss ("[5](1,2,3,4,5]");
myVectorSignal.set (ss);
} catch(ExceptionSignal e) {
std::cout << "Test passed : ss[-1] != \")\"";
}
}
BOOST_AUTO_TEST_CASE (custom_matrix_registerer) {
// One issue with the strategy used by the
// dynamicgraph::SignalCastRegisterer is that it relies on the
// typeid. In practice, it means that two signals defined in two
// different libraries will have different typeid and one will not be
// able to plug one into the other unless the symbol have merged when
// the plug-in is loaded. See man(3) dlopen in Linux for more
// information about plug-in loading and the RTLD_GLOBAL flag
// necessary to make cast registerer work as expected.
//
// Here we make sure that two instances of the same type
// declared in two separate libraries are resolved into the
// same typeid.
BOOST_AUTO_TEST_CASE (typeid_issue)
{
BOOST_CHECK (typeid(vA) == typeid(vB));
BOOST_CHECK_EQUAL (std::string (typeid(vA).name ()),
std::string (typeid(vB).name ()));
dynamicgraph::Signal<dynamicgraph::Matrix, int> myMatrixSignal("matrix");
// Print the signal name.
{
output_test_stream output;
output << myMatrixSignal;
BOOST_CHECK (output.is_equal ("Sig:matrix (Type Cst)"));
}
//Catch Exception of ss (not good input)
//ss[0] != "["
try {
std::istringstream ss("test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[0] != \"[\"";
}
//ss[1] != %i
try {
std::istringstream ss("[test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[1] != %i";
}
//ss[2] != ","
try {
std::istringstream ss("[5[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[2] != \",\"";
}
//ss[3] != %i
try {
std::istringstream ss("[5,c");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[3] != %i";
}
//ss[4] != "]"
try {
std::istringstream ss("[5,3[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[4] != \"]\"";
}
//ss[5] != "("
try {
std::istringstream ss("[5,3]test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[5] != \"(\"";
}
//ss[6] != "("
try {
std::istringstream ss("[5,3](test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[6] != \"(\"";
}
//ss[8] != " " || ","
try {
std::istringstream ss("[5,3]((1,");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
BOOST_ERROR("Can't happened");
}
//ss[6+n] != ")"
try {
std::istringstream ss("[5,3]((1,2,3]");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << ("ss[6+n] != \")\"");
}
//ss[-3] != ")"
try {
std::istringstream ss("[5,1]((1)(2)(3[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[5] != \")\"";
}
//ss[-3] != ")"
try {
std::istringstream ss("[5,1]((1)(2)(3)[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[5] != \")\"";
}
//ss[-1]!= ")"
try {
std::istringstream ss("[3,1]((1)(2),(3)[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
std::cout << "Test passed : ss[5] != \")\" and ignore \",\"";
}
//[...]((...))
}
......@@ -8,29 +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>
#include <string>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>