Skip to content
Snippets Groups Projects
Commit 157f5e62 authored by Olivier Stasse's avatar Olivier Stasse
Browse files

[tests] Improve tests on pool.cpp with respect to exceptions.

Add entity test to check writeCompletionList + license modification.
parent fa7f705f
No related branches found
No related tags found
No related merge requests found
Pipeline #3139 passed
// Copyright 2010 Thomas Moulard. /* Copyright 2010-2019 LAAS, CNRS
// * Thomas Moulard.
// This file is part of dynamic-graph. *
// dynamic-graph is free software: you can redistribute it and/or modify * See LICENSE file
// 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/>.
#define ENABLE_RT_LOG #define ENABLE_RT_LOG
...@@ -140,9 +132,9 @@ BOOST_AUTO_TEST_CASE (writeCompletionList) ...@@ -140,9 +132,9 @@ BOOST_AUTO_TEST_CASE (writeCompletionList)
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity"); dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output; output_test_stream output;
entity.writeGraph (output); entity.writeCompletionList (output);
BOOST_CHECK (output.is_equal ("")); BOOST_CHECK (output.is_equal ("print\nsignals\nsignalDep\n"));
} }
BOOST_AUTO_TEST_CASE (sendMsg) BOOST_AUTO_TEST_CASE (sendMsg)
......
...@@ -70,38 +70,78 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (MyEntity, "MyEntity"); ...@@ -70,38 +70,78 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (MyEntity, "MyEntity");
namespace dg = dynamicgraph; namespace dg = dynamicgraph;
BOOST_AUTO_TEST_CASE (pool_display) BOOST_AUTO_TEST_CASE (pool_display)
{ {
// Create Entity /// Create Entity
dg::Entity* entity = dg::Entity* entity =
dg::FactoryStorage::getInstance()-> dg::FactoryStorage::getInstance()->
newEntity("MyEntity", "MyEntityInst"); 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; output_test_stream output;
dg::Entity& e = dg::PoolStorage::getInstance()->getEntity dg::Entity& e = dg::PoolStorage::getInstance()->getEntity
("MyEntityInst"); ("MyEntityInst");
e.display(output); e.display(output);
BOOST_CHECK (output.is_equal ("Hello! My name is MyEntityInst !\n")); BOOST_CHECK (output.is_equal ("Hello! My name is MyEntityInst !\n"));
/// Search for an entity inside the map
// Testing entityMap 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 = const dg::PoolStorage::Entities& anEntityMap =
dg::PoolStorage::getInstance()->getEntityMap(); dg::PoolStorage::getInstance()->getEntityMap();
bool testExistence = anEntityMap.find("MyEntityInst")==anEntityMap.end(); bool testExistence = anEntityMap.find("MyEntityInst")==anEntityMap.end();
BOOST_CHECK(!testExistence); BOOST_CHECK(!testExistence);
// Testing the existence of an entity /// Testing the existence of an entity
testExistence = dg::PoolStorage::getInstance()->existEntity testExistence = dg::PoolStorage::getInstance()->existEntity
("MyEntityInst",entity); ("MyEntityInst",entity);
BOOST_CHECK(testExistence); BOOST_CHECK(testExistence);
// Testing the completion list of pool storage /// Testing the completion list of pool storage
dg::PoolStorage::getInstance()->writeCompletionList dg::PoolStorage::getInstance()->writeCompletionList
(output); (output);
BOOST_CHECK (output.is_equal ("MyEntityInst.in_double\nMyEntityInst.out_double\nprint\nsignals\nsignalDep\n")); BOOST_CHECK (output.is_equal ("MyEntityInst.in_double\nMyEntityInst.out_double\nprint\nsignals\nsignalDep\n"));
// Checking the graph generated by the pool /// Checking the graph generated by the pool
dg::PoolStorage::getInstance()->writeGraph("output.dot"); dg::PoolStorage::getInstance()->writeGraph("output.dot");
std::fstream the_debug_file; std::fstream the_debug_file;
the_debug_file.open("output.dot"); the_debug_file.open("output.dot");
...@@ -109,7 +149,7 @@ BOOST_AUTO_TEST_CASE (pool_display) ...@@ -109,7 +149,7 @@ BOOST_AUTO_TEST_CASE (pool_display)
oss_output_wgph << the_debug_file.rdbuf(); oss_output_wgph << the_debug_file.rdbuf();
the_debug_file.close(); the_debug_file.close();
/* Use a predefined output */ /// Use a predefined output
std::string str_to_test="/* This graph has been automatically generated.\n" std::string str_to_test="/* This graph has been automatically generated.\n"
" 2019 Month: 2 Day: 28 Time: 11:28 */\n" " 2019 Month: 2 Day: 28 Time: 11:28 */\n"
"digraph \"output\" { graph [ label=\"output\" bgcolor = white rankdir=LR ]\n" "digraph \"output\" { graph [ label=\"output\" bgcolor = white rankdir=LR ]\n"
...@@ -120,7 +160,7 @@ BOOST_AUTO_TEST_CASE (pool_display) ...@@ -120,7 +160,7 @@ BOOST_AUTO_TEST_CASE (pool_display)
" fontcolor = black, color = black, fillcolor=cyan, style=filled, shape=box ]\n" " fontcolor = black, color = black, fillcolor=cyan, style=filled, shape=box ]\n"
"}\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_output_wgph = oss_output_wgph.str();
std::string s_crmk="*/"; std::string s_crmk="*/";
...@@ -134,7 +174,7 @@ BOOST_AUTO_TEST_CASE (pool_display) ...@@ -134,7 +174,7 @@ BOOST_AUTO_TEST_CASE (pool_display)
BOOST_CHECK(two_sub_string_identical); BOOST_CHECK(two_sub_string_identical);
// Test name of an object. /// Test name of a valid signal.
std::istringstream an_iss("MyEntityInst.in_double"); std::istringstream an_iss("MyEntityInst.in_double");
dg::SignalBase<int> &aSignal= dg::SignalBase<int> &aSignal=
...@@ -143,15 +183,34 @@ BOOST_AUTO_TEST_CASE (pool_display) ...@@ -143,15 +183,34 @@ BOOST_AUTO_TEST_CASE (pool_display)
std::string aSignalName=aSignal.getName(); std::string aSignalName=aSignal.getName();
testExistence = aSignalName=="MyEntity(MyEntityInst)::input(double)::in_double"; testExistence = aSignalName=="MyEntity(MyEntityInst)::input(double)::in_double";
BOOST_CHECK(testExistence); 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 dg::PoolStorage::getInstance()->deregisterEntity
(entity->getName()); (entity->getName());
// Testing the existance of an entity /// Testing the existance of an entity
testExistence = dg::PoolStorage::getInstance()->existEntity testExistence = dg::PoolStorage::getInstance()->existEntity
("MyEntityInst",entity); ("MyEntityInst",entity);
BOOST_CHECK(!testExistence); BOOST_CHECK(!testExistence);
/// Create Entity
std::string name_entity("MyEntityInst2");
dg::PoolStorage::getInstance()->
clearPlugin(name_entity);
dg::PoolStorage::destroy(); dg::PoolStorage::destroy();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment