Commit 41f4f368 authored by Olivier Stasse's avatar Olivier Stasse Committed by olivier stasse

[linter] Apply cppcheck

parent 3d88a00c
......@@ -144,7 +144,7 @@ TimeDependency<Time>::displayDependencies(std::ostream &os, const int depth,
std::string ajout = "|";
std::string ajout2 = "|";
typename Dependencies::const_iterator it2 = it;
it2++;
++it2;
if (it2 == dependencies.end()) {
ajout = "`";
ajout2 = " ";
......
......@@ -72,22 +72,22 @@ struct RealTimeLogger::thread {
bool changedThreadParams;
boost::thread t_;
thread(RealTimeLogger *logger)
explicit thread(RealTimeLogger *logger)
: requestShutdown_(false), threadPolicy_(SCHED_OTHER), threadPriority_(0),
changedThreadParams(true), t_(&thread::spin, this, logger) {}
void setThreadPolicy(int policy) {
threadPolicy_ = policy;
changedThreadParams = true;
}
// void setThreadPolicy(int policy) {
// threadPolicy_ = policy;
// changedThreadParams = true;
// }
void setPriority(int priority) {
threadPriority_ = priority;
changedThreadParams = true;
}
// void setPriority(int priority) {
// threadPriority_ = priority;
// changedThreadParams = true;
// }
int getThreadPolicy() { return threadPolicy_; }
int getThreadPriority() { return threadPriority_; }
// int getThreadPolicy() { return threadPolicy_; }
// int getThreadPriority() { return threadPriority_; }
void changeThreadParams() {
int threadPolicy;
......
......@@ -46,7 +46,7 @@ Entity::Entity(const string &name__) : name(name__) {
Entity::~Entity() {
dgDEBUG(25) << "# In (" << name << " { " << endl;
for (std::map<const std::string, Command *>::iterator it = commandMap.begin();
it != commandMap.end(); it++) {
it != commandMap.end(); ++it) {
delete it->second;
}
dgDEBUGOUT(25);
......
......@@ -83,7 +83,7 @@ std::vector<std::string> SignalCaster::listTypenames() const {
std::vector<std::string> typeList;
for (std::map<std::string, cast_functions_type>::const_iterator iter =
functions_.begin();
iter != functions_.end(); iter++)
iter != functions_.end(); ++iter)
typeList.push_back(iter->first);
return typeList;
}
......
......@@ -317,7 +317,7 @@ void TracerRealTime::display(std::ostream &os) const {
os.precision(PRECISION);
}
os << endl;
iterFile++;
++iterFile;
}
}
......
......@@ -67,3 +67,4 @@ DYNAMIC_GRAPH_TEST(signal-all)
DYNAMIC_GRAPH_TEST(command-test)
DYNAMIC_GRAPH_TEST(test-mt)
TARGET_LINK_LIBRARIES(test-mt tracer)
DYNAMIC_GRAPH_TEST(exceptions)
......@@ -37,7 +37,7 @@ public:
bool test_four_args_;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {
explicit CustomEntity(const std::string &n) : Entity(n) {
test_zero_arg_ = false;
test_one_arg_ = false;
test_two_args_ = false;
......@@ -164,13 +164,13 @@ BOOST_AUTO_TEST_CASE(command_test) {
/// Try to find the command 1_arg
res = false;
Command *a_cmd = entity.getNewStyleCommand(vec_fname[0]);
entity.getNewStyleCommand(vec_fname[0]);
BOOST_CHECK(true);
/// Generate an exception by searching a command with an empty name.w
std::string empty("");
try {
a_cmd = entity.getNewStyleCommand(empty);
entity.getNewStyleCommand(empty);
} catch (dynamicgraph::ExceptionFactory &aef) {
res = (aef.getCode() == dynamicgraph::ExceptionFactory::UNREFERED_FUNCTION);
}
......
......@@ -19,7 +19,7 @@ struct CustomEntity : public dynamicgraph::Entity {
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {}
explicit CustomEntity(const std::string &n) : Entity(n) {}
virtual ~CustomEntity() {}
......
......@@ -32,7 +32,7 @@ class CustomEntity : public Entity {
public:
static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {
explicit CustomEntity(const std::string &n) : Entity(n) {
logger_.setTimeSample(0.001);
logger_.setStreamPrintPeriod(0.005);
logger_.setVerbosity(VERBOSITY_ALL);
......@@ -62,10 +62,7 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
} // namespace dynamicgraph
BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) {
std::ofstream of;
dynamicgraph::RealTimeLogger::instance();
// of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
// dgADD_OSTREAM_TO_RTLOG (of);
BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
......
......@@ -28,7 +28,7 @@ class CustomEntity : public Entity {
public:
static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {
explicit CustomEntity(const std::string &n) : Entity(n) {
logger_.setTimeSample(0.001);
logger_.setStreamPrintPeriod(0.005);
logger_.setVerbosity(VERBOSITY_ALL);
......
......@@ -28,7 +28,7 @@ struct MyEntity : public dynamicgraph::Entity {
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT;
MyEntity(const std::string &name)
explicit MyEntity(const std::string &name)
: Entity(name),
m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
......
......@@ -28,7 +28,7 @@ class CustomEntity : public Entity {
public:
static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {
explicit CustomEntity(const std::string &n) : Entity(n) {
dynamicgraph::dgDEBUGFLOW.openFile("/tmp/dynamic-graph-traces.txt");
}
~CustomEntity() {
......@@ -53,10 +53,13 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
BOOST_AUTO_TEST_CASE(testDebugTrace) {
BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
dynamicgraph::CustomEntity &entity =
*(dynamic_cast<dynamicgraph::CustomEntity *>(
dynamicgraph::CustomEntity *ptr_entity =
(dynamic_cast<dynamicgraph::CustomEntity *>(
dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
"my-entity")));
dynamicgraph::CustomEntity &entity = *ptr_entity;
entity.testDebugTrace();
/// Copy the debug file into the oss_debug_file
......@@ -89,4 +92,6 @@ BOOST_AUTO_TEST_CASE(testDebugTrace) {
two_sub_string_identical = str_to_test == oss_debug_file.str();
BOOST_CHECK(two_sub_string_identical);
delete ptr_entity;
}
......@@ -27,7 +27,7 @@ struct MyEntity : public dynamicgraph::Entity {
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT;
MyEntity(const std::string &name)
explicit MyEntity(const std::string &name)
: Entity(name),
m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
......
......@@ -31,14 +31,15 @@ public:
static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n)
explicit CustomEntity(const std::string &n)
: Entity(n),
m_sigdSIN(NULL, "CustomEntity(" + name + ")::input(double)::in_double"),
m_sigdSIN2(NULL,
"CustomEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(
boost::bind(&CustomEntity::update, this, _1, _2), m_sigdSIN,
"CustomEntity(" + name + ")::input(double)::out_double") {}
"CustomEntity(" + name + ")::input(double)::out_double"),
m_value(0.0) {}
~CustomEntity() { entityDeregistration(); }
......
// Copyright 2020 Olivier Stasse
// LAAS, CNRS
#include <dynamic-graph/exception-abstract.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/exception-traces.h>
#include <sstream>
#include <boost/test/output_test_stream.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_suite.hpp>
using boost::test_tools::output_test_stream;
using namespace dynamicgraph;
BOOST_AUTO_TEST_CASE(exception_abstract) {
std::string msg_aea("Test exception abstract");
ExceptionAbstract aEA(10, msg_aea);
const char *aC = aEA.getMessage();
output_test_stream output;
output << aC;
BOOST_CHECK(output.is_equal("Test exception abstract"));
output << aEA;
BOOST_CHECK(
output.is_equal("AbstractError [#10]: Test exception abstract\n"));
std::string msg_aet("Test exception abstract");
ExceptionTraces aET(ExceptionTraces::GENERIC, msg_aet);
output << aET;
}
......@@ -18,7 +18,7 @@ class CustomEntity : public Entity {
public:
static const std::string CLASS_NAME;
virtual const std::string &getClassName() const { return CLASS_NAME; }
CustomEntity(const std::string n) : Entity(n) {}
explicit CustomEntity(const std::string &n) : Entity(n) {}
};
const std::string CustomEntity::CLASS_NAME = "CustomEntity";
} // namespace dynamicgraph
......
......@@ -23,7 +23,7 @@ struct MyEntity : public dynamicgraph::Entity {
dynamicgraph::SignalPtr<double, int> m_sigdSIN;
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT;
MyEntity(const std::string &name)
explicit MyEntity(const std::string &name)
: Entity(name),
m_sigdSIN(NULL, "MyEntity(" + name + ")::input(double)::in_double"),
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
......
......@@ -76,6 +76,7 @@ BOOST_AUTO_TEST_CASE(test_base) {
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
res = false;
try {
......@@ -83,6 +84,7 @@ BOOST_AUTO_TEST_CASE(test_base) {
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
}
BOOST_CHECK(res);
res = false;
try {
......@@ -101,6 +103,7 @@ BOOST_AUTO_TEST_CASE(test_base) {
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// get a value
res = false;
......@@ -110,6 +113,7 @@ BOOST_AUTO_TEST_CASE(test_base) {
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Trigger revaluation of the signal
res = false;
......@@ -118,6 +122,7 @@ BOOST_AUTO_TEST_CASE(test_base) {
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Trace the signal
res = false;
......@@ -126,6 +131,7 @@ BOOST_AUTO_TEST_CASE(test_base) {
} catch (const ExceptionSignal &aea) {
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
}
BOOST_CHECK(res);
/// Display the signal
sigB.display(output);
......@@ -142,7 +148,7 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
std::istringstream iss_fail;
iss.str("test");
defaultCR.cast(iss_fail);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
// Take int, not string
}
}
......@@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try {
std::istringstream ss("test");
myVectorSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[0] != \"[\"";
}
......@@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try {
std::istringstream ss("[test");
myVectorSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[1] != %i";
}
......@@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try {
std::istringstream ss("[5[");
myVectorSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[2] != \"]\"";
}
......@@ -195,7 +195,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try {
std::istringstream ss("[5]test");
myVectorSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[3] != \"(\"";
}
......@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try {
std::istringstream ss("[5](1, ");
myVectorSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
BOOST_ERROR("Can't happened");
}
......@@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
try {
std::istringstream ss("[5](1,2,3,4,5]");
myVectorSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[-1] != \")\"";
}
}
......@@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[0] != \"[\"";
}
......@@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[1] != %i";
}
......@@ -248,7 +248,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[2] != \",\"";
}
......@@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,c");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[3] != %i";
}
......@@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,3[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[4] != \"]\"";
}
......@@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,3]test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \"(\"";
}
......@@ -280,7 +280,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,3](test");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[6] != \"(\"";
}
......@@ -288,7 +288,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,3]((1,");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
BOOST_ERROR("Can't happened");
}
......@@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,3]((1,2,3]");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << ("ss[6+n] != \")\"");
}
......@@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,1]((1)(2)(3[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\"";
}
......@@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[5,1]((1)(2)(3)[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\"";
}
......@@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(custom_matrix_registerer) {
try {
std::istringstream ss("[3,1]((1)(2),(3)[");
myMatrixSignal.set(ss);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
std::cout << "Test passed : ss[5] != \")\" and ignore \",\"";
}
......
......@@ -34,7 +34,8 @@ public:
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) {
++call;
......@@ -78,7 +79,7 @@ BOOST_AUTO_TEST_CASE(normal_cst_test) {
try {
sigNotPlug.getPtr();
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
cout << "Error catch" << std::endl;
}
......@@ -102,7 +103,8 @@ BOOST_AUTO_TEST_CASE(normal_cst_test) {
BOOST_CHECK(res);
/// Test needUpdate without plug
res = sigNotPlug.needUpdate(5);
res = (sigNotPlug.needUpdate(5) == false);
BOOST_CHECK(res);
sigNotPlug.getTime();
output_test_stream output;
sigNotPlug.display(output);
......@@ -147,7 +149,7 @@ BOOST_AUTO_TEST_CASE(normal_test) {
std::string test = "test";
try {
sig.getClassName(test);
} catch (ExceptionSignal e) {
} catch (ExceptionSignal &e) {
e.getExceptionName();
}
BOOST_CHECK(true);
......
......@@ -22,7 +22,8 @@ public:
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) {
++call;
......
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