GCC Code Coverage Report


Directory: ./
File: tests/signal/test_ptr.cpp
Date: 2024-12-13 12:22:33
Exec Total Coverage
Lines: 31 43 72.1%
Branches: 21 56 37.5%

Line Branch Exec Source
1 /*
2 * Copyright 2010,
3 * François Bleibel,
4 * Olivier Stasse,
5 *
6 * CNRS/AIST
7 *
8 */
9
10 /* -------------------------------------------------------------------------- */
11 /* --- INCLUDES ------------------------------------------------------------- */
12 /* -------------------------------------------------------------------------- */
13 #include <dynamic-graph/all-signals.h>
14 #include <dynamic-graph/linear-algebra.h>
15
16 #include <iostream>
17 #include <sot/core/debug.hh>
18 #include <sot/core/exception-abstract.hh>
19 #include <sot/core/matrix-geometry.hh>
20
21 using namespace std;
22 using namespace dynamicgraph::sot;
23 using namespace dynamicgraph;
24
25 template <class Res = double>
26 class DummyClass {
27 public:
28
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 DummyClass(void) : res(), appel(0), timedata(0) {}
29
30 2 Res &fun(Res &res, int t) {
31 2 appel++;
32 2 timedata = t;
33
34 sotDEBUG(5) << "Inside " << typeid(Res).name() << endl;
35 2 for (list<SignalTimeDependent<double, int> *>::iterator it =
36 2 inputsig.begin();
37
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 it != inputsig.end(); ++it) {
38 sotDEBUG(5) << *(*it) << endl;
39 (*it)->access(timedata);
40 }
41 2 for (list<SignalTimeDependent<dynamicgraph::Vector, int> *>::iterator it =
42 2 inputsigV.begin();
43
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 it != inputsigV.end(); ++it) {
44 sotDEBUG(5) << *(*it) << endl;
45 (*it)->access(timedata);
46 }
47
48 2 return res = (*this)();
49 }
50
51 list<SignalTimeDependent<double, int> *> inputsig;
52 list<SignalTimeDependent<dynamicgraph::Vector, int> *> inputsigV;
53
54 void add(SignalTimeDependent<double, int> &sig) { inputsig.push_back(&sig); }
55 void add(SignalTimeDependent<dynamicgraph::Vector, int> &sig) {
56 inputsigV.push_back(&sig);
57 }
58
59 Res operator()(void);
60
61 Res res;
62 int appel;
63 int timedata;
64 };
65
66 template <class Res>
67 Res DummyClass<Res>::operator()(void) {
68 return this->res;
69 }
70
71 template <>
72 double DummyClass<double>::operator()(void) {
73 res = appel * timedata;
74 return res;
75 }
76 template <>
77 dynamicgraph::Vector DummyClass<dynamicgraph::Vector>::operator()(void) {
78 res.resize(3);
79 res.fill(appel * timedata);
80 return res;
81 }
82 template <>
83 2 VectorUTheta DummyClass<VectorUTheta>::operator()(void) {
84 2 res.angle() = 0.26;
85
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 res.axis() = Eigen::Vector3d::UnitX();
86 2 return res;
87 }
88
89 // void dispArray( const SignalArray<int> &ar )
90 // {
91 // for( unsigned int i=0;i<ar.rank;++i ) sotDEBUG(5)<<*ar.array[i]<<endl;
92 // }
93
94 1 void funtest(dynamicgraph::Vector & /*v*/) {}
95
96 #include <vector>
97 1 int main(void) {
98
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 DummyClass<VectorUTheta> pro3;
99
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2 SignalTimeDependent<VectorUTheta, int> sig3(sotNOSIGNAL, "Sig3");
100
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2 SignalPtr<Eigen::AngleAxisd, int> sigTo3(NULL, "SigTo3");
101
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dynamicgraph::Vector v;
102
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 VectorUTheta v3;
103 1 funtest(v);
104
105
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
1 sig3.setFunction(boost::bind(&DummyClass<VectorUTheta>::fun, pro3, _1, _2));
106 try {
107
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 sigTo3.plug(&sig3);
108 } catch (sot::ExceptionAbstract &e) {
109 cout << "Plugin error " << e << endl;
110 exit(1);
111 }
112
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 sig3.access(1);
113 1 sig3.setReady();
114
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 sigTo3.access(2);
115
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 cout << sigTo3.access(2);
116
117 1 return 0;
118 1 }
119