GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
// |
||
2 |
// Created by corentin on 7/3/19. |
||
3 |
// |
||
4 |
|||
5 |
#include <assert.h> |
||
6 |
#include <dynamic-graph/debug.h> |
||
7 |
#include <dynamic-graph/factory.h> |
||
8 |
#include <dynamic-graph/signal-array.h> |
||
9 |
#include <dynamic-graph/signal-caster.h> |
||
10 |
#include <dynamic-graph/tracer.h> |
||
11 |
|||
12 |
#include <boost/foreach.hpp> |
||
13 |
#if BOOST_VERSION >= 105900 |
||
14 |
#include <boost/test/tools/output_test_stream.hpp> |
||
15 |
#else |
||
16 |
#include <boost/test/output_test_stream.hpp> |
||
17 |
#endif |
||
18 |
#include <boost/test/unit_test.hpp> |
||
19 |
#include <iostream> |
||
20 |
|||
21 |
#define BOOST_TEST_MODULE signal_array |
||
22 |
|||
23 |
using boost::test_tools::output_test_stream; |
||
24 |
|||
25 |
dynamicgraph::SignalArray_const<double> sig; |
||
26 |
|||
27 |
using namespace std; |
||
28 |
using namespace dynamicgraph; |
||
29 |
using namespace dynamicgraph::command; |
||
30 |
|||
31 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_array) { |
32 |
✓✗✓✗ |
6 |
SignalBase<int> sigBa("add test"); |
33 |
✓✗ | 4 |
SignalArray_const<int> sigArr_C(1); |
34 |
✓✗ | 2 |
sigArr_C.operator<<(sigBa); |
35 |
✓✗ | 2 |
sigArr_C.operator<<(sigBa); |
36 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(2, sigArr_C.getSize()); |
37 |
|||
38 |
✓✗ | 4 |
SignalArray<int> sigArr(1); |
39 |
✓✗ | 2 |
sigArr.operator<<(sigBa); |
40 |
✓✗ | 2 |
sigArr.operator<<(sigBa); |
41 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(2, sigArr.getSize()); |
42 |
|||
43 |
✓✗✓✗ |
6 |
SignalBase<int> sigB("constructor test"); |
44 |
✓✗ | 4 |
SignalArray<int> sigA(2); |
45 |
✓✗ | 2 |
sigA << sigB; |
46 |
✓✗ | 2 |
sigA.operator<<(sigB); |
47 |
✓✗ | 4 |
SignalArray_const<int> sig_C(sigA); |
48 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(sigA.getSize(), sig_C.getSize()); |
49 |
2 |
} |
|
50 |
|||
51 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_base) { |
52 |
✓✗✓✗ |
6 |
SignalBase<int> sigA("testA"); |
53 |
✓✗✓✗ |
6 |
SignalBase<int> sigB("test"); |
54 |
2 |
sigB.setReady(); |
|
55 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(true, sigB.getReady()); |
56 |
// Does nothing, just check that the interface |
||
57 |
// still exist at the abstract level. |
||
58 |
2 |
sigB.setPeriodTime(1); |
|
59 |
2 |
sigB.getPeriodTime(); |
|
60 |
2 |
sigB.addDependency(sigA); |
|
61 |
2 |
sigB.removeDependency(sigA); |
|
62 |
2 |
sigB.clearDependencies(); |
|
63 |
✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK_EQUAL(true, sigB.needUpdate(10)); |
64 |
✓✗✓✗ |
4 |
output_test_stream output; |
65 |
2 |
sigB.writeGraph(output); |
|
66 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("")); |
67 |
|||
68 |
/// Verify plug operations |
||
69 |
2 |
bool res = false; |
|
70 |
try { |
||
71 |
✗✓ | 2 |
sigB.plug(&sigA); |
72 |
2 |
} catch (const ExceptionSignal &aea) { |
|
73 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE); |
74 |
} |
||
75 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
76 |
|||
77 |
2 |
res = false; |
|
78 |
try { |
||
79 |
✗✓ | 2 |
sigB.unplug(); |
80 |
2 |
} catch (const ExceptionSignal &aea) { |
|
81 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE); |
82 |
} |
||
83 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
84 |
|||
85 |
2 |
res = false; |
|
86 |
try { |
||
87 |
✗✓ | 2 |
sigB.setConstantDefault(); |
88 |
2 |
} catch (const ExceptionSignal &aea) { |
|
89 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE); |
90 |
} |
||
91 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
92 |
|||
93 |
2 |
res = false; |
|
94 |
try { |
||
95 |
/// Check signal compatibility. |
||
96 |
✗✓ | 2 |
sigB.checkCompatibility(); |
97 |
2 |
} catch (const ExceptionSignal &aea) { |
|
98 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE); |
99 |
} |
||
100 |
/// Verify set command value |
||
101 |
|||
102 |
/// set |
||
103 |
✓✗✓✗ |
6 |
std::istringstream iss("empty"); |
104 |
2 |
res = false; |
|
105 |
try { |
||
106 |
✗✓ | 2 |
sigB.set(iss); |
107 |
2 |
} catch (const ExceptionSignal &aea) { |
|
108 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE); |
109 |
} |
||
110 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
111 |
|||
112 |
/// get a value |
||
113 |
2 |
res = false; |
|
114 |
✓✗ | 4 |
std::ostringstream oss; |
115 |
try { |
||
116 |
✗✓ | 2 |
sigB.get(oss); |
117 |
2 |
} catch (const ExceptionSignal &aea) { |
|
118 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE); |
119 |
} |
||
120 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
121 |
|||
122 |
/// Trigger revaluation of the signal |
||
123 |
2 |
res = false; |
|
124 |
try { |
||
125 |
✗✓ | 2 |
sigB.recompute(100); |
126 |
2 |
} catch (const ExceptionSignal &aea) { |
|
127 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE); |
128 |
} |
||
129 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
130 |
|||
131 |
/// Trace the signal |
||
132 |
2 |
res = false; |
|
133 |
try { |
||
134 |
✗✓ | 2 |
sigB.trace(oss); |
135 |
2 |
} catch (const ExceptionSignal &aea) { |
|
136 |
✓✗ | 2 |
res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE); |
137 |
} |
||
138 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(res); |
139 |
|||
140 |
/// Display the signal |
||
141 |
✓✗ | 2 |
sigB.display(output); |
142 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓ |
2 |
BOOST_CHECK(output.is_equal("Sig:test")); |
143 |
2 |
} |
|
144 |
|||
145 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(test_cast_helper) { |
146 |
✓✗ | 4 |
std::istringstream iss; |
147 |
✓✗✓✗ |
2 |
iss.str("1"); |
148 |
✓✗ | 2 |
signal_io<int>::cast(iss); |
149 |
|||
150 |
{ |
||
151 |
✓✗ | 4 |
std::istringstream iss_fail; |
152 |
✓✗✓✗ |
2 |
iss.str("test"); |
153 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✓ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
6 |
BOOST_CHECK_THROW(signal_io<int>::cast(iss_fail), ExceptionSignal); |
154 |
} |
||
155 |
|||
156 |
/// Test cast register with Vector |
||
157 |
✓✗✓✗ |
4 |
output_test_stream output; |
158 |
✓✗ | 4 |
dynamicgraph::Vector avec; |
159 |
✓✗ | 2 |
avec.resize(4); |
160 |
✓✗ | 2 |
avec[0] = 1.0; |
161 |
✓✗ | 2 |
avec[1] = 2.0; |
162 |
✓✗ | 2 |
avec[2] = 3.0; |
163 |
✓✗ | 2 |
avec[3] = 4.0; |
164 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓✗✓ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗ |
2 |
BOOST_CHECK_NO_THROW(signal_io<Vector>::trace(avec, output)); |
165 |
|||
166 |
/// Test cast register with Matrix |
||
167 |
✓✗ | 4 |
dynamicgraph::Matrix amatrix; |
168 |
✓✗ | 2 |
amatrix.resize(2, 2); |
169 |
✓✗ | 2 |
amatrix(0, 0) = 0.0; |
170 |
✓✗ | 2 |
amatrix(0, 1) = 1.0; |
171 |
✓✗ | 2 |
amatrix(1, 0) = 2.0; |
172 |
✓✗ | 2 |
amatrix(1, 1) = 3.0; |
173 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✓✗✓ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗ |
2 |
BOOST_CHECK_NO_THROW(signal_io<Matrix>::trace(amatrix, output)); |
174 |
|||
175 |
✓✗✓✗ |
4 |
std::istringstream aiss("test"); |
176 |
✓✗ | 2 |
signal_io<std::string>::cast(aiss); |
177 |
2 |
} |
Generated by: GCOVR (Version 4.2) |