Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph
Commits
157f5e62
Commit
157f5e62
authored
Mar 01, 2019
by
Olivier Stasse
Browse files
[tests] Improve tests on pool.cpp with respect to exceptions.
Add entity test to check writeCompletionList + license modification.
parent
fa7f705f
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/entity.cpp
View file @
157f5e62
// Copyright 2010 Thomas Moulard.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
/* Copyright 2010-2019 LAAS, CNRS
* Thomas Moulard.
*
* See LICENSE file
*
*/
#define ENABLE_RT_LOG
...
...
@@ -140,9 +132,9 @@ BOOST_AUTO_TEST_CASE (writeCompletionList)
dynamicgraph
::
PoolStorage
::
getInstance
()
->
getEntity
(
"my-entity"
);
output_test_stream
output
;
entity
.
write
Graph
(
output
);
entity
.
write
CompletionList
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
""
));
BOOST_CHECK
(
output
.
is_equal
(
"
print
\n
signals
\n
signalDep
\n
"
));
}
BOOST_AUTO_TEST_CASE
(
sendMsg
)
...
...
tests/pool.cpp
View file @
157f5e62
...
...
@@ -70,38 +70,78 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (MyEntity, "MyEntity");
namespace
dg
=
dynamicgraph
;
BOOST_AUTO_TEST_CASE
(
pool_display
)
{
// Create Entity
//
/
Create Entity
dg
::
Entity
*
entity
=
dg
::
FactoryStorage
::
getInstance
()
->
newEntity
(
"MyEntity"
,
"MyEntityInst"
);
// Search for an entity inside the map
/// Test exception catching when registering Entity
bool
res
=
false
;
try
{
dg
::
Entity
*
entity2
=
dg
::
FactoryStorage
::
getInstance
()
->
newEntity
(
"MyEntity"
,
"MyEntityInst"
);
bool
res2
=
(
entity2
==
entity
);
BOOST_CHECK
(
res2
);
}
catch
(
const
dg
::
ExceptionFactory
&
aef
)
{
res
=
(
aef
.
getCode
()
==
dg
::
ExceptionFactory
::
OBJECT_CONFLICT
);
}
BOOST_CHECK
(
res
);
/// Test exception catching when deregistering Entity
res
=
false
;
try
{
dg
::
FactoryStorage
::
getInstance
()
->
deregisterEntity
(
"MyEntityInstFailure"
);
}
catch
(
const
dg
::
ExceptionFactory
&
aef
)
{
res
=
(
aef
.
getCode
()
==
dg
::
ExceptionFactory
::
OBJECT_CONFLICT
);
}
BOOST_CHECK
(
res
);
/// Search for an entity inside the map
output_test_stream
output
;
dg
::
Entity
&
e
=
dg
::
PoolStorage
::
getInstance
()
->
getEntity
(
"MyEntityInst"
);
e
.
display
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"Hello! My name is MyEntityInst !
\n
"
));
// Testing entityMap
/// Search for an entity inside the map
res
=
false
;
try
{
dg
::
PoolStorage
::
getInstance
()
->
getEntity
(
"MyEntityInstFailure"
);
}
catch
(
const
dg
::
ExceptionFactory
&
aef
)
{
res
=
(
aef
.
getCode
()
==
dg
::
ExceptionFactory
::
UNREFERED_OBJECT
);
}
BOOST_CHECK
(
res
);
/// Testing entityMap
const
dg
::
PoolStorage
::
Entities
&
anEntityMap
=
dg
::
PoolStorage
::
getInstance
()
->
getEntityMap
();
bool
testExistence
=
anEntityMap
.
find
(
"MyEntityInst"
)
==
anEntityMap
.
end
();
BOOST_CHECK
(
!
testExistence
);
// Testing the existence of an entity
//
/
Testing the existence of an entity
testExistence
=
dg
::
PoolStorage
::
getInstance
()
->
existEntity
(
"MyEntityInst"
,
entity
);
BOOST_CHECK
(
testExistence
);
// Testing the completion list of pool storage
//
/
Testing the completion list of pool storage
dg
::
PoolStorage
::
getInstance
()
->
writeCompletionList
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"MyEntityInst.in_double
\n
MyEntityInst.out_double
\n
print
\n
signals
\n
signalDep
\n
"
));
// Checking the graph generated by the pool
//
/
Checking the graph generated by the pool
dg
::
PoolStorage
::
getInstance
()
->
writeGraph
(
"output.dot"
);
std
::
fstream
the_debug_file
;
the_debug_file
.
open
(
"output.dot"
);
...
...
@@ -109,7 +149,7 @@ BOOST_AUTO_TEST_CASE (pool_display)
oss_output_wgph
<<
the_debug_file
.
rdbuf
();
the_debug_file
.
close
();
/
*
Use a predefined output
*/
/
//
Use a predefined output
std
::
string
str_to_test
=
"/* This graph has been automatically generated.
\n
"
" 2019 Month: 2 Day: 28 Time: 11:28 */
\n
"
"digraph
\"
output
\"
{ graph [ label=
\"
output
\"
bgcolor = white rankdir=LR ]
\n
"
...
...
@@ -120,7 +160,7 @@ BOOST_AUTO_TEST_CASE (pool_display)
" fontcolor = black, color = black, fillcolor=cyan, style=filled, shape=box ]
\n
"
"}
\n
"
;
/
*
Check the two substring (remove the date) -
**/
/
//
Check the two substring (remove the date) -
std
::
string
s_output_wgph
=
oss_output_wgph
.
str
();
std
::
string
s_crmk
=
"*/"
;
...
...
@@ -134,7 +174,7 @@ BOOST_AUTO_TEST_CASE (pool_display)
BOOST_CHECK
(
two_sub_string_identical
);
// Test name of a
n object
.
//
/
Test name of a
valid signal
.
std
::
istringstream
an_iss
(
"MyEntityInst.in_double"
);
dg
::
SignalBase
<
int
>
&
aSignal
=
...
...
@@ -143,15 +183,34 @@ BOOST_AUTO_TEST_CASE (pool_display)
std
::
string
aSignalName
=
aSignal
.
getName
();
testExistence
=
aSignalName
==
"MyEntity(MyEntityInst)::input(double)::in_double"
;
BOOST_CHECK
(
testExistence
);
/// Test name of an unvalid signal.
an_iss
.
str
(
"MyEntityInst.in2double"
);
try
{
dg
::
PoolStorage
::
getInstance
()
->
getSignal
(
an_iss
);
}
catch
(
const
dg
::
ExceptionFactory
&
aef
)
{
res
=
(
aef
.
getCode
()
==
dg
::
ExceptionFactory
::
UNREFERED_SIGNAL
);
}
BOOST_CHECK
(
res
);
// Deregister the entity.
/// Deregister the entity.
dg
::
PoolStorage
::
getInstance
()
->
deregisterEntity
(
entity
->
getName
());
// Testing the existance of an entity
//
/
Testing the existance of an entity
testExistence
=
dg
::
PoolStorage
::
getInstance
()
->
existEntity
(
"MyEntityInst"
,
entity
);
BOOST_CHECK
(
!
testExistence
);
/// Create Entity
std
::
string
name_entity
(
"MyEntityInst2"
);
dg
::
PoolStorage
::
getInstance
()
->
clearPlugin
(
name_entity
);
dg
::
PoolStorage
::
destroy
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment