GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* Copyright 2010-2019 LAAS, CNRS |
||
2 |
* Thomas Moulard. |
||
3 |
* |
||
4 |
*/ |
||
5 |
|||
6 |
#define ENABLE_RT_LOG |
||
7 |
|||
8 |
#include <dynamic-graph/command-direct-getter.h> |
||
9 |
#include <dynamic-graph/command-direct-setter.h> |
||
10 |
#include <dynamic-graph/entity.h> |
||
11 |
#include <dynamic-graph/exception-factory.h> |
||
12 |
#include <dynamic-graph/real-time-logger.h> |
||
13 |
#include <dynamic-graph/signal-ptr.h> |
||
14 |
#include <dynamic-graph/signal-time-dependent.h> |
||
15 |
|||
16 |
#include <sstream> |
||
17 |
|||
18 |
#include "dynamic-graph/factory.h" |
||
19 |
#include "dynamic-graph/pool.h" |
||
20 |
|||
21 |
#define BOOST_TEST_MODULE entity |
||
22 |
|||
23 |
#if BOOST_VERSION >= 105900 |
||
24 |
#include <boost/test/tools/output_test_stream.hpp> |
||
25 |
#else |
||
26 |
#include <boost/test/output_test_stream.hpp> |
||
27 |
#endif |
||
28 |
#include <boost/test/unit_test.hpp> |
||
29 |
|||
30 |
using boost::test_tools::output_test_stream; |
||
31 |
|||
32 |
namespace dynamicgraph { |
||
33 |
class CustomEntity : public Entity { |
||
34 |
public: |
||
35 |
dynamicgraph::SignalPtr<double, int> m_sigdSIN, m_sigdSIN2; |
||
36 |
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT; |
||
37 |
|||
38 |
static const std::string CLASS_NAME; |
||
39 |
3 |
virtual const std::string &getClassName() const { return CLASS_NAME; } |
|
40 |
2 |
explicit CustomEntity(const std::string &n) |
|
41 |
2 |
: Entity(n), |
|
42 |
✓✗ | 4 |
m_sigdSIN(NULL, "CustomEntity(" + name + ")::input(double)::in_double"), |
43 |
m_sigdSIN2(NULL, |
||
44 |
✓✗ | 4 |
"CustomEntity(" + name + ")::input(double)::in_double"), |
45 |
m_sigdTimeDepSOUT( |
||
46 |
boost::bind(&CustomEntity::update, this, _1, _2), m_sigdSIN, |
||
47 |
✓✗ | 4 |
"CustomEntity(" + name + ")::input(double)::out_double"), |
48 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
14 |
m_value(0.0) {} |
49 |
|||
50 |
2 |
~CustomEntity() { entityDeregistration(); } |
|
51 |
|||
52 |
1 |
void addSignal() { |
|
53 |
✓✗ | 1 |
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT); |
54 |
/// Try a second time to generate an exception |
||
55 |
try { |
||
56 |
✓✗✗✓ |
2 |
signalRegistration(m_sigdSIN2 << m_sigdTimeDepSOUT); |
57 |
2 |
} catch (ExceptionFactory &aef) { |
|
58 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
1 |
BOOST_CHECK_EQUAL(aef.getCode(), |
59 |
dynamicgraph::ExceptionFactory::SIGNAL_CONFLICT); |
||
60 |
} |
||
61 |
1 |
} |
|
62 |
|||
63 |
2 |
void rmValidSignal() { |
|
64 |
✓✗✓✓ |
4 |
signalDeregistration("in_double"); |
65 |
✓✗✓✗ |
1 |
signalDeregistration("out_double"); |
66 |
1 |
} |
|
67 |
|||
68 |
double &update(double &res, const int &inTime) { |
||
69 |
const double &aDouble = m_sigdSIN(inTime); |
||
70 |
res = aDouble; |
||
71 |
return res; |
||
72 |
} |
||
73 |
|||
74 |
public: |
||
75 |
double m_value; |
||
76 |
}; |
||
77 |
✓✗ | 1 |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity"); |
78 |
} // namespace dynamicgraph |
||
79 |
|||
80 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(constructor) { |
81 |
namespace dg = dynamicgraph; |
||
82 |
namespace dgc = dynamicgraph::command; |
||
83 |
|||
84 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(dg::CustomEntity::CLASS_NAME, "CustomEntity"); |
85 |
|||
86 |
✓✗✓✗ ✓✗✓✗ |
2 |
dg::Entity &entity = *dg::FactoryStorage::getInstance()->newEntity( |
87 |
"CustomEntity", "my-entity"); |
||
88 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(entity.getName(), "my-entity"); |
89 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(entity.getClassName(), dg::CustomEntity::CLASS_NAME); |
90 |
|||
91 |
✓✗✓✗ |
6 |
dg::CustomEntity entity2(""); |
92 |
|||
93 |
// Test Commands |
||
94 |
dgc::DirectGetter<dg::CustomEntity, double> a_direct_getter( |
||
95 |
entity2, &entity2.m_value, |
||
96 |
✓✗✓✗ ✓✗✓✗ |
6 |
dgc::docDirectGetter("Get value m_value", "double")); |
97 |
|||
98 |
dgc::DirectSetter<dg::CustomEntity, double> a_direct_setter( |
||
99 |
entity2, &entity2.m_value, |
||
100 |
✓✗✓✗ ✓✗✓✗ |
6 |
dgc::docDirectSetter("Set value m_value", "double")); |
101 |
|||
102 |
✓✗ | 4 |
dgc::Value aValue(2.0); |
103 |
4 |
std::vector<dgc::Value> values; |
|
104 |
✓✗ | 2 |
values.push_back(aValue); |
105 |
✓✗ | 2 |
a_direct_setter.setParameterValues(values); |
106 |
✓✗ | 2 |
a_direct_setter.execute(); |
107 |
✓✗ | 2 |
a_direct_getter.execute(); |
108 |
|||
109 |
✓✗✓✗ |
2 |
output_test_stream output; |
110 |
✓✗ | 2 |
output << entity2.m_value; |
111 |
✓✗ | 2 |
output << entity2; |
112 |
|||
113 |
✓✗ | 2 |
entity.getDocString(); |
114 |
2 |
} |
|
115 |
|||
116 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(signal) { |
117 |
dynamicgraph::Entity &entity = |
||
118 |
✓✗✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
119 |
|||
120 |
// Non const getter. |
||
121 |
try { |
||
122 |
✓✗✗✓ |
6 |
entity.getSignal("I do not exist"); |
123 |
BOOST_ERROR("Should never happen."); |
||
124 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
125 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
126 |
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL); |
||
127 |
} |
||
128 |
|||
129 |
// Const getter. |
||
130 |
try { |
||
131 |
2 |
const dynamicgraph::Entity &entityConst = entity; |
|
132 |
✓✗✗✓ |
6 |
entityConst.getSignal("I do not exist"); |
133 |
BOOST_ERROR("Should never happen."); |
||
134 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
135 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
136 |
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL); |
||
137 |
} |
||
138 |
// deregistration |
||
139 |
try { |
||
140 |
2 |
dynamicgraph::CustomEntity *customEntity = |
|
141 |
✓✗ | 2 |
dynamic_cast<dynamicgraph::CustomEntity *>(&entity); |
142 |
✓✗ | 2 |
customEntity->addSignal(); |
143 |
✓✗ | 4 |
std::string signame("CustomEntity(my-entity)::input(double)::in_double"); |
144 |
✓✗ | 2 |
customEntity->Entity::hasSignal(signame); |
145 |
✓✗✓✗ |
4 |
output_test_stream output; |
146 |
✓✗ | 2 |
customEntity->Entity::displaySignalList(output); |
147 |
✓✗ | 4 |
dynamicgraph::Entity::SignalMap asigmap = customEntity->getSignalMap(); |
148 |
✓✗ | 2 |
output << customEntity; |
149 |
// Removing signals is working the first time |
||
150 |
✓✗ | 2 |
customEntity->rmValidSignal(); |
151 |
// Removing signals generates an exception the second time. |
||
152 |
✗✓ | 2 |
customEntity->rmValidSignal(); |
153 |
BOOST_ERROR("Should never happen."); |
||
154 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
155 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
156 |
dynamicgraph::ExceptionFactory::UNREFERED_SIGNAL); |
||
157 |
} |
||
158 |
2 |
} |
|
159 |
|||
160 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(displaySignalList) { |
161 |
dynamicgraph::Entity &entity = |
||
162 |
✓✗✓✗ ✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
163 |
|||
164 |
✓✗✓✗ |
4 |
output_test_stream output; |
165 |
|||
166 |
✓✗ | 2 |
entity.displaySignalList(output); |
167 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("--- <my-entity> signal list: \n")); |
168 |
2 |
} |
|
169 |
|||
170 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(display) { |
171 |
dynamicgraph::Entity &entity = |
||
172 |
✓✗✓✗ ✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
173 |
|||
174 |
✓✗✓✗ |
4 |
output_test_stream output; |
175 |
|||
176 |
✓✗ | 2 |
entity.display(output); |
177 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("CustomEntity: my-entity")); |
178 |
2 |
} |
|
179 |
|||
180 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(getCommandList) { |
181 |
dynamicgraph::Entity &entity = |
||
182 |
✓✗✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
183 |
|||
184 |
✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(entity.getCommandList(), "print\nsignals\nsignalDep"); |
185 |
2 |
} |
|
186 |
|||
187 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(writeGraph) { |
188 |
dynamicgraph::Entity &entity = |
||
189 |
✓✗✓✗ ✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
190 |
|||
191 |
✓✗✓✗ |
4 |
output_test_stream output; |
192 |
✓✗ | 2 |
entity.writeGraph(output); |
193 |
|||
194 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("")); |
195 |
2 |
} |
|
196 |
|||
197 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(writeCompletionList) { |
198 |
dynamicgraph::Entity &entity = |
||
199 |
✓✗✓✗ ✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
200 |
|||
201 |
✓✗✓✗ |
4 |
output_test_stream output; |
202 |
✓✗ | 2 |
entity.writeCompletionList(output); |
203 |
|||
204 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("print\nsignals\nsignalDep\n")); |
205 |
2 |
} |
|
206 |
|||
207 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(sendMsg) { |
208 |
✓✗ | 4 |
std::ofstream of; |
209 |
✓✗ | 2 |
of.open("/tmp/dg-LOGS.txt", std::ofstream::out | std::ofstream::app); |
210 |
✓✗✓✗ ✓✗✓✗ |
2 |
dgADD_OSTREAM_TO_RTLOG(of); |
211 |
|||
212 |
dynamicgraph::Entity &entity = |
||
213 |
✓✗✓✗ ✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
214 |
|||
215 |
✓✗✓✗ |
4 |
output_test_stream output; |
216 |
|||
217 |
✓✓ | 10 |
for (unsigned int i = 0; i < 4; i++) { |
218 |
✓✓ | 16008 |
for (unsigned int j = 0; j < 2000; j++) { |
219 |
16000 |
dynamicgraph::LoggerVerbosity aLoggerVerbosityLevel = |
|
220 |
(dynamicgraph::LoggerVerbosity)i; |
||
221 |
✓✗ | 16000 |
entity.setLoggerVerbosityLevel(aLoggerVerbosityLevel); |
222 |
✓✗✗✓ |
16000 |
if (entity.getLoggerVerbosityLevel() != aLoggerVerbosityLevel) |
223 |
output << "Mismatch output"; |
||
224 |
|||
225 |
#define __FILELINE__ __FILE__ BOOST_PP_STRINGIZE(__LINE__) |
||
226 |
✓✗✓✗ |
32000 |
entity.logger().stream(dynamicgraph::MSG_TYPE_DEBUG, __FILELINE__) |
227 |
✓✗ | 16000 |
<< "Auto Test Case" |
228 |
✓✗✓✗ |
16000 |
<< " DEBUG" << '\n'; |
229 |
✓✗✓✗ |
32000 |
entity.logger().stream(dynamicgraph::MSG_TYPE_INFO, __FILELINE__) |
230 |
✓✗ | 16000 |
<< "Auto Test Case" |
231 |
✓✗✓✗ |
16000 |
<< " INFO" << '\n'; |
232 |
✓✗✓✗ |
32000 |
entity.logger().stream(dynamicgraph::MSG_TYPE_WARNING, __FILELINE__) |
233 |
✓✗ | 16000 |
<< "Auto Test Case" |
234 |
✓✗✓✗ |
16000 |
<< " WARNING" << '\n'; |
235 |
✓✗✓✗ |
32000 |
entity.logger().stream(dynamicgraph::MSG_TYPE_ERROR, __FILELINE__) |
236 |
✓✗ | 16000 |
<< "Auto Test Case" |
237 |
✓✗✓✗ |
16000 |
<< " ERROR" << '\n'; |
238 |
#undef __FILELINE__ |
||
239 |
}; |
||
240 |
}; |
||
241 |
|||
242 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("")); |
243 |
✓✗ | 2 |
dynamicgraph::RealTimeLogger::destroy(); |
244 |
2 |
} |
|
245 |
|||
246 |
// WTF? |
||
247 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(wtf) { |
248 |
dynamicgraph::Entity &entity = |
||
249 |
✓✗✓✗ |
2 |
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); |
250 |
|||
251 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(entity.test(), |
252 |
static_cast<dynamicgraph::SignalBase<int> *>(0)); |
||
253 |
|||
254 |
2 |
entity.test2(static_cast<dynamicgraph::SignalBase<int> *>(0)); |
|
255 |
2 |
} |
Generated by: GCOVR (Version 4.2) |