GCC Code Coverage Report


Directory: ./
File: tests/nodes.cpp
Date: 2024-12-20 15:53:58
Exec Total Coverage
Lines: 40 48 83.3%
Branches: 127 300 42.3%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 CNRS
3 // Authors: Joseph Mirabel
4 //
5 //
6 // This file is part of gepetto-viewer
7 // gepetto-viewer is free software: you can redistribute it
8 // and/or modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation, either version
10 // 3 of the License, or (at your option) any later version.
11 //
12 // gepetto-viewer is distributed in the hope that it will be
13 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Lesser Public License for more details. You should have
16 // received a copy of the GNU Lesser General Public License along with
17 // gepetto-viewer If not, see
18 // <http://www.gnu.org/licenses/>.
19
20 #define BOOST_TEST_MODULE nodes
21 #ifndef Q_MOC_RUN
22 #include <boost/test/unit_test.hpp>
23 #include <boost/utility/binary.hpp>
24 #endif
25
26 #include <gepetto/viewer/leaf-node-box.h>
27 #include <gepetto/viewer/node.h>
28
29 #define CHECK_VECT_CLOSE(a, b, tol) \
30 BOOST_CHECK_SMALL((a - b).length2(), float(tol));
31
32 #define CHECK_QUAT_CLOSE(a, b, tol) \
33 { \
34 osgQuat qres(a.inverse() * b); \
35 osgVector3 axis; \
36 double angle; \
37 qres.getRotate(angle, axis); \
38 if (std::fabs(angle - 2 * M_PI) < std::fabs(angle)) \
39 BOOST_CHECK_CLOSE(angle, 2 * M_PI, (double)tol); \
40 else \
41 BOOST_CHECK_SMALL(angle, (double)tol); \
42 }
43
44 namespace osg {
45 std::ostream& operator<<(std::ostream& os, const Matrix& m) {
46 const char* s = ", ";
47 const char* l = "\n";
48 os << m(0, 0) << s << m(0, 1) << s << m(0, 2) << s << m(0, 3) << l << m(1, 0)
49 << s << m(1, 1) << s << m(1, 2) << s << m(1, 3) << l << m(2, 0) << s
50 << m(2, 1) << s << m(2, 2) << s << m(2, 3) << l << m(3, 0) << s << m(3, 1)
51 << s << m(3, 2) << s << m(3, 3);
52 return os;
53 }
54 } // namespace osg
55
56 namespace gepetto {
57 namespace viewer {
58 struct NodeTest {
59 1 static void checkAbstractClass(NodePtr_t node) {
60 1 osgQuat q, so;
61 1 osgVector3 t, s;
62
63 // Check transforms
64
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 osgVector3 _ts = node->getStaticPosition();
65
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 osgQuat _qs = node->getStaticRotation();
66 1 osgVector3 ts(1.f, 1.f, 1.f);
67 1 osgQuat qs(1.f, 0.f, 0.f, 0.f);
68
69
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 node->setDirty(false);
70
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 node->setStaticTransform(ts, qs);
71
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
1 BOOST_CHECK(node->isDirty());
72
73
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
1 CHECK_VECT_CLOSE(node->getStaticPosition(), ts, 1e-4);
74
8/28
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 39 taken 1 times.
✗ Branch 40 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
1 CHECK_QUAT_CLOSE(node->getStaticRotation(), qs, 1e-4);
75
76
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 node->setDirty(false);
77
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 node->applyConfiguration(osgVector3(0.f, 0.f, 0.f),
78 2 osgQuat(0.f, 0.f, 0.f, 1.f));
79 // Not dirty since configuration did not change.
80
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
1 BOOST_CHECK(!node->isDirty());
81
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 node->applyConfiguration(osgVector3(0.f, 0.f, 1.f),
82 2 osgQuat(0.f, 0.f, 0.f, 1.f));
83
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
1 BOOST_CHECK(node->isDirty());
84
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 node->applyConfiguration(osgVector3(0.f, 0.f, 0.f),
85 1 osgQuat(0.f, 0.f, 0.f, 1.f));
86
87 const osg::MatrixTransform* matrixTransform =
88
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 dynamic_cast<osg::MatrixTransform*>(node->asQueue().get());
89
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
1 BOOST_REQUIRE(matrixTransform != NULL);
90
91
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 matrixTransform->getMatrix().decompose(t, q, s, so);
92
93
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 times.
1 CHECK_VECT_CLOSE(t, ts, 1e-4);
94
7/26
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 1 times.
1 CHECK_QUAT_CLOSE(q, qs, 1e-4);
95
96 1 osgVector3 t1(0.f, 0.f, 1.f);
97 1 osgQuat q1(0.5f, 0.5f, 0.5f, 0.5f);
98
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 node->applyConfiguration(t1, q1);
99
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
1 CHECK_VECT_CLOSE(node->getGlobalTransform().position, t1, 1e-4);
100
8/28
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 39 taken 1 times.
✗ Branch 40 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 1 times.
1 CHECK_QUAT_CLOSE(node->getGlobalTransform().quat, q1, 1e-4);
101
102
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 matrixTransform->getMatrix().decompose(t, q, s, so);
103 // This is very counter intuitive...
104
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
1 CHECK_VECT_CLOSE(t, (t1 + q1 * ts), 1e-4);
105
8/26
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
1 CHECK_QUAT_CLOSE(q, (qs * q1), 1e-4);
106
107
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 node->setStaticTransform(_ts, _qs);
108 1 }
109 };
110 } /* namespace viewer */
111 } // namespace gepetto
112
113 using namespace gepetto::viewer;
114
115 BOOST_AUTO_TEST_SUITE(node)
116
117
33/66
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
4 BOOST_AUTO_TEST_CASE(box) {
118 LeafNodeBoxPtr_t box =
119
2/4
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
4 LeafNodeBox::create("box", osgVector3(0.1f, 0.2f, 0.3f));
120
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 NodeTest::checkAbstractClass(box);
121 2 }
122
123 BOOST_AUTO_TEST_SUITE_END()
124