GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
// Copyright 2010 Thomas Moulard. |
||
2 |
// |
||
3 |
|||
4 |
#include <dynamic-graph/entity.h> |
||
5 |
#include <dynamic-graph/exception-factory.h> |
||
6 |
#include <dynamic-graph/factory.h> |
||
7 |
|||
8 |
#include <sstream> |
||
9 |
|||
10 |
#define BOOST_TEST_MODULE factory |
||
11 |
|||
12 |
#if BOOST_VERSION >= 105900 |
||
13 |
#include <boost/test/tools/output_test_stream.hpp> |
||
14 |
#else |
||
15 |
#include <boost/test/output_test_stream.hpp> |
||
16 |
#endif |
||
17 |
#include <boost/test/unit_test.hpp> |
||
18 |
|||
19 |
using boost::test_tools::output_test_stream; |
||
20 |
|||
21 |
namespace dynamicgraph { |
||
22 |
class CustomEntity : public Entity { |
||
23 |
public: |
||
24 |
static const std::string CLASS_NAME; |
||
25 |
virtual const std::string &getClassName() const { return CLASS_NAME; } |
||
26 |
3 |
explicit CustomEntity(const std::string &n) : Entity(n) {} |
|
27 |
}; |
||
28 |
const std::string CustomEntity::CLASS_NAME = "CustomEntity"; |
||
29 |
} // namespace dynamicgraph |
||
30 |
|||
31 |
3 |
dynamicgraph::Entity *makeEntity(const std::string &objectName) { |
|
32 |
✓✗ | 3 |
return new dynamicgraph::CustomEntity(objectName); |
33 |
} |
||
34 |
|||
35 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(constructor) { |
36 |
2 |
dynamicgraph::FactoryStorage::getInstance(); |
|
37 |
2 |
} |
|
38 |
|||
39 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(registerEntity) { |
40 |
✓✗✓✗ |
2 |
dynamicgraph::FactoryStorage::getInstance()->registerEntity("myEntity", |
41 |
&makeEntity); |
||
42 |
|||
43 |
try { |
||
44 |
✓✗✓✗ ✗✓ |
6 |
dynamicgraph::FactoryStorage::getInstance()->registerEntity("myEntity", |
45 |
&makeEntity); |
||
46 |
BOOST_ERROR("Should never happen."); |
||
47 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
48 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
49 |
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT); |
||
50 |
} |
||
51 |
|||
52 |
try { |
||
53 |
✓✗✓✗ ✗✓ |
6 |
dynamicgraph::FactoryStorage::getInstance()->registerEntity("myEntity", 0); |
54 |
BOOST_ERROR("Should never happen."); |
||
55 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
56 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
57 |
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT); |
||
58 |
} |
||
59 |
2 |
} |
|
60 |
|||
61 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(unregisterEntity) { |
62 |
✓✗✓✗ |
2 |
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity("myEntity"); |
63 |
|||
64 |
try { |
||
65 |
✓✗✓✗ ✗✓ |
6 |
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity("myEntity"); |
66 |
BOOST_ERROR("Should never happen."); |
||
67 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
68 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
69 |
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT); |
||
70 |
} |
||
71 |
|||
72 |
try { |
||
73 |
✓✗✓✗ ✗✓ |
6 |
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity( |
74 |
"I do not exist."); |
||
75 |
BOOST_ERROR("Should never happen."); |
||
76 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
77 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
78 |
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT); |
||
79 |
} |
||
80 |
2 |
} |
|
81 |
|||
82 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(newEntity) { |
83 |
✓✗✓✗ |
2 |
dynamicgraph::FactoryStorage::getInstance()->registerEntity("myEntity", |
84 |
&makeEntity); |
||
85 |
|||
86 |
{ |
||
87 |
boost::shared_ptr<dynamicgraph::Entity> entity( |
||
88 |
dynamicgraph::FactoryStorage::getInstance()->newEntity("myEntity", |
||
89 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
6 |
"foo")); |
90 |
|||
91 |
boost::shared_ptr<dynamicgraph::Entity> entity2( |
||
92 |
dynamicgraph::FactoryStorage::getInstance()->newEntity("myEntity", |
||
93 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
6 |
"foo2")); |
94 |
|||
95 |
boost::shared_ptr<dynamicgraph::Entity> entity3( |
||
96 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
dynamicgraph::FactoryStorage::getInstance()->newEntity("myEntity", "")); |
97 |
} |
||
98 |
|||
99 |
try { |
||
100 |
✓✗✓✗ ✓✗✗✓ |
10 |
dynamicgraph::FactoryStorage::getInstance()->newEntity("I do not exist.", |
101 |
""); |
||
102 |
BOOST_ERROR("Should never happen."); |
||
103 |
4 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
|
104 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK_EQUAL(exception.getCode(), |
105 |
dynamicgraph::ExceptionFactory::UNREFERED_OBJECT); |
||
106 |
} |
||
107 |
|||
108 |
try { |
||
109 |
✓✗✓✗ |
2 |
dynamicgraph::FactoryStorage::getInstance()->destroy(); |
110 |
✓✗✓✗ ✓✗ |
2 |
dynamicgraph::FactoryStorage::getInstance()->existEntity("myEntity"); |
111 |
// BOOST_ERROR ("Should never happen."); |
||
112 |
} catch (const dynamicgraph::ExceptionFactory &exception) { |
||
113 |
BOOST_CHECK_EQUAL(exception.getCode(), |
||
114 |
dynamicgraph::ExceptionFactory::UNREFERED_OBJECT); |
||
115 |
} |
||
116 |
2 |
} |
|
117 |
|||
118 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4 |
BOOST_AUTO_TEST_CASE(existEntity) { |
119 |
// BOOST_CHECK (dynamicgraph::FactoryStorage::getInstance()->existEntity |
||
120 |
// ("myEntity")); |
||
121 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK( |
122 |
!dynamicgraph::FactoryStorage::getInstance()->existEntity("myEntity2")); |
||
123 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✓ |
2 |
BOOST_CHECK(!dynamicgraph::FactoryStorage::getInstance()->existEntity("")); |
124 |
2 |
} |
Generated by: GCOVR (Version 4.2) |