GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* Copyright 2019, LAAS-CNRS |
||
2 |
* |
||
3 |
* Olivier Stasse |
||
4 |
* |
||
5 |
*/ |
||
6 |
|||
7 |
#include <dynamic-graph/entity.h> |
||
8 |
#include <dynamic-graph/exception-factory.h> |
||
9 |
#include <dynamic-graph/factory.h> |
||
10 |
#include <dynamic-graph/pool.h> |
||
11 |
#include <dynamic-graph/signal-ptr.h> |
||
12 |
#include <dynamic-graph/signal-time-dependent.h> |
||
13 |
#include <dynamic-graph/tracer.h> |
||
14 |
|||
15 |
#include <iostream> |
||
16 |
|||
17 |
#define BOOST_TEST_MODULE debug - tracer |
||
18 |
|||
19 |
#if BOOST_VERSION >= 105900 |
||
20 |
#include <boost/test/tools/output_test_stream.hpp> |
||
21 |
#else |
||
22 |
#include <boost/test/output_test_stream.hpp> |
||
23 |
#endif |
||
24 |
#include <boost/test/unit_test.hpp> |
||
25 |
|||
26 |
namespace dynamicgraph { |
||
27 |
struct MyEntity : public dynamicgraph::Entity { |
||
28 |
static const std::string CLASS_NAME; |
||
29 |
|||
30 |
dynamicgraph::Signal<double, int> m_sigdSIN; |
||
31 |
dynamicgraph::SignalTimeDependent<double, int> m_sigdTimeDepSOUT; |
||
32 |
dynamicgraph::SignalTimeDependent<Vector, int> m_sigVTimeDepSOUT; |
||
33 |
dynamicgraph::SignalTimeDependent<double, int> m_sigdTwoTimeDepSOUT; |
||
34 |
|||
35 |
1 |
explicit MyEntity(const std::string &name) |
|
36 |
1 |
: Entity(name), |
|
37 |
✓✗ | 2 |
m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"), |
38 |
m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2), |
||
39 |
m_sigdSIN, |
||
40 |
✓✗ | 2 |
"MyEntity(" + name + ")::input(double)::out_double"), |
41 |
m_sigVTimeDepSOUT(boost::bind(&MyEntity::updateVector, this, _1, _2), |
||
42 |
m_sigdSIN, |
||
43 |
✓✗ | 2 |
"MyEntity(" + name + ")::input(vector)::out_vector"), |
44 |
m_sigdTwoTimeDepSOUT( |
||
45 |
boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN, |
||
46 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
7 |
"MyEntity(" + name + ")::input(double)::out2double") |
47 |
|||
48 |
{ |
||
49 |
✓✗✓✗ |
2 |
signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigVTimeDepSOUT |
50 |
✓✗✓✗ |
1 |
<< m_sigdTwoTimeDepSOUT); |
51 |
1 |
} |
|
52 |
|||
53 |
virtual void display(std::ostream &os) const { |
||
54 |
os << "Hello! My name is " << getName() << " !" << std::endl; |
||
55 |
} |
||
56 |
|||
57 |
virtual const std::string &getClassName() const { return CLASS_NAME; } |
||
58 |
|||
59 |
double &update(double &res, const int &inTime) { |
||
60 |
const double &aDouble = m_sigdSIN(inTime); |
||
61 |
res = aDouble; |
||
62 |
return res; |
||
63 |
} |
||
64 |
|||
65 |
1000 |
Vector &updateVector(Vector &res, const int &inTime) { |
|
66 |
1000 |
const double &aDouble = m_sigdSIN(inTime); |
|
67 |
1000 |
res.resize(2); |
|
68 |
✓✗ | 1000 |
res << aDouble, 2 * aDouble; |
69 |
1000 |
return res; |
|
70 |
} |
||
71 |
}; |
||
72 |
✓✗ | 1 |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity, "MyEntity"); |
73 |
} // namespace dynamicgraph |
||
74 |
|||
75 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_tracer) { |
76 |
using dynamicgraph::Vector; |
||
77 |
|||
78 |
// Creates a tracer. |
||
79 |
dynamicgraph::Tracer &atracer = *dynamic_cast<dynamicgraph::Tracer *>( |
||
80 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
dynamicgraph::FactoryStorage::getInstance()->newEntity("Tracer", |
81 |
2 |
"my-tracer")); |
|
82 |
|||
83 |
dynamicgraph::Entity &entity = |
||
84 |
✓✗✓✗ ✓✗✓✗ |
2 |
*dynamicgraph::FactoryStorage::getInstance()->newEntity("MyEntity", |
85 |
"my-entity"); |
||
86 |
|||
87 |
✓✗ | 4 |
std::string rootdir("/tmp"); |
88 |
✓✗ | 4 |
std::string basename("my-tracer"); |
89 |
✓✗ | 4 |
std::string suffix(".dat"); |
90 |
|||
91 |
/// Test openfiles |
||
92 |
✓✗ | 2 |
atracer.openFiles(rootdir, basename, suffix); |
93 |
|||
94 |
/// Add trace by name |
||
95 |
✓✗✓✗ ✓✗ |
2 |
atracer.addSignalToTraceByName("my-entity.out_double", "output"); |
96 |
/// Add trace by name |
||
97 |
✓✗✓✗ ✓✗ |
2 |
atracer.addSignalToTraceByName("my-entity.out_vector", "output-vector"); |
98 |
|||
99 |
✓✗✓✗ |
2 |
dynamicgraph::SignalBase<int> &aSignal = entity.getSignal("out2double"); |
100 |
|||
101 |
dynamicgraph::Signal<double, int> &aSignalInt = |
||
102 |
*(dynamic_cast<dynamicgraph::Signal<double, int> *>( |
||
103 |
✓✗✓✗ ✓✗ |
2 |
&entity.getSignal("in_double"))); |
104 |
|||
105 |
dynamicgraph::Signal<Vector, int> &aSignalVector = |
||
106 |
*(dynamic_cast<dynamicgraph::Signal<Vector, int> *>( |
||
107 |
✓✗✓✗ ✓✗ |
2 |
&entity.getSignal("out_vector"))); |
108 |
|||
109 |
/// Add trace by signal object |
||
110 |
✓✗✓✗ |
2 |
atracer.addSignalToTrace(aSignal, "output2"); |
111 |
|||
112 |
✓✗ | 2 |
aSignalInt.setConstant(1.5); |
113 |
|||
114 |
2 |
atracer.start(); |
|
115 |
|||
116 |
✓✓ | 2002 |
for (int i = 0; i < 1000; i++) { |
117 |
✓✗ | 2000 |
aSignal.setTime(i); |
118 |
✓✗ | 2000 |
aSignalInt.access(i); |
119 |
✓✗ | 2000 |
aSignalInt.setTime(i); |
120 |
✓✗ | 2000 |
aSignalVector.recompute(i); |
121 |
✓✗ | 2000 |
aSignalVector.setTime(i); |
122 |
✓✗ | 2000 |
atracer.recordTrigger(i, i); |
123 |
} |
||
124 |
|||
125 |
2 |
atracer.stop(); |
|
126 |
✓✗ | 2 |
atracer.clearSignalToTrace(); |
127 |
✓✗ | 2 |
atracer.closeFiles(); |
128 |
|||
129 |
✓✗ | 2 |
atracer.record(); |
130 |
2 |
} |
Generated by: GCOVR (Version 4.2) |