Commit 71bf1af7 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Make package pass tests successfully.

parent 36268f12
......@@ -15,6 +15,7 @@
#include <sstream>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
......@@ -29,7 +30,7 @@ struct CustomEntity : public dynamicgraph::Entity
{
static const std::string CLASS_NAME;
virtual const std::string& getClassName ()
virtual const std::string& getClassName () const
{
return CLASS_NAME;
}
......@@ -71,85 +72,27 @@ BOOST_AUTO_TEST_CASE (constructor)
{
BOOST_CHECK_EQUAL (CustomEntity::CLASS_NAME, "CustomEntity");
CustomEntity entity ("my-entity");
BOOST_CHECK_EQUAL (entity.getName (), "my-entity");
BOOST_CHECK_EQUAL (entity.getClassName (), CustomEntity::CLASS_NAME);
dynamicgraph::Entity* entity =
dynamicgraph::FactoryStorage::getInstance()->
newEntity("CustomEntity", "my-entity");
BOOST_CHECK_EQUAL (entity->getName (), "my-entity");
BOOST_CHECK_EQUAL (entity->getClassName (), CustomEntity::CLASS_NAME);
CustomEntity entity2 ("");
//CustomEntity entity2 ("");
// Deregister entities before destroying them
dynamicgraph::PoolStorage::destroy();
}
BOOST_AUTO_TEST_CASE (display)
{
CustomEntity entity ("my-entity");
dynamicgraph::Entity* entity = dynamicgraph::FactoryStorage::getInstance()->
newEntity("CustomEntity", "my-entity");
output_test_stream output;
entity.display(output);
entity->display(output);
BOOST_CHECK (output.is_equal ("custom entity"));
// Deregister entities before destroying them
dynamicgraph::PoolStorage::destroy();
}
BOOST_AUTO_TEST_CASE (commandLine_help)
{
CustomEntity entity ("my-entity");
output_test_stream output;
std::istringstream args;
entity.commandLine("help", args, output);
BOOST_CHECK
(output.is_equal
(
"This is a custom help.\n"
"Entity : \n"
" - print\t\t\tWhat d'you think?\n"
" - signals\t\t\tDisplay the signals list.\n"
" - signalDep <signame> \tDisplay the dependency graph for signal signame.\n"
));
}
BOOST_AUTO_TEST_CASE (commandLine_print)
{
CustomEntity entity ("my-entity");
output_test_stream output;
std::istringstream args;
entity.commandLine("print", args, output);
BOOST_CHECK (output.is_equal ("custom entity\n"));
}
BOOST_AUTO_TEST_CASE (commandLine_nothing)
{
CustomEntity entity ("my-entity");
output_test_stream output;
std::istringstream args;
entity.commandLine("nothing", args, output);
BOOST_CHECK (output.is_empty ());
}
BOOST_AUTO_TEST_CASE (commandLine_unknown)
{
CustomEntity entity ("my-entity");
output_test_stream output;
std::istringstream args;
try
{
entity.commandLine("unknown", args, output);
BOOST_ERROR ("Should never happen.");
}
catch (const dynamicgraph::ExceptionFactory& exception)
{
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::UNREFERED_FUNCTION);
}
BOOST_CHECK (output.is_empty ());
}
......@@ -16,6 +16,8 @@
#include <sstream>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
#include "dynamic-graph/factory.h"
#include "dynamic-graph/pool.h"
#define BOOST_TEST_MODULE entity
......@@ -24,11 +26,23 @@
using boost::test_tools::output_test_stream;
extern "C" {
dynamicgraph::Entity* EntityMaker_Entity(const std::string& objname)
{
return new dynamicgraph::Entity (objname);
}
}
BOOST_AUTO_TEST_CASE (constructor)
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
(dynamicgraph::Entity::CLASS_NAME, &EntityMaker_Entity);
BOOST_CHECK_EQUAL (dynamicgraph::Entity::CLASS_NAME, "Entity");
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
*dynamicgraph::FactoryStorage::getInstance()->newEntity("Entity",
"my-entity");
BOOST_CHECK_EQUAL (entity.getName (), "my-entity");
BOOST_CHECK_EQUAL (entity.getClassName (), dynamicgraph::Entity::CLASS_NAME);
......@@ -37,7 +51,8 @@ BOOST_AUTO_TEST_CASE (constructor)
BOOST_AUTO_TEST_CASE (signal)
{
dynamicgraph::Entity entity ("");
dynamicgraph::Entity& entity =
*dynamicgraph::FactoryStorage::getInstance()->newEntity("Entity", "");
// Non const getter.
try
......@@ -67,7 +82,8 @@ BOOST_AUTO_TEST_CASE (signal)
BOOST_AUTO_TEST_CASE (displaySignalList)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -77,7 +93,8 @@ BOOST_AUTO_TEST_CASE (displaySignalList)
BOOST_AUTO_TEST_CASE (display)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -87,13 +104,16 @@ BOOST_AUTO_TEST_CASE (display)
BOOST_AUTO_TEST_CASE (getCommandList)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
BOOST_CHECK_EQUAL (entity.getCommandList (), "print\nsignals\nsignalDep");
}
BOOST_AUTO_TEST_CASE (commandLine_help)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -112,7 +132,8 @@ BOOST_AUTO_TEST_CASE (commandLine_help)
BOOST_AUTO_TEST_CASE (commandLine_print)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -124,7 +145,8 @@ BOOST_AUTO_TEST_CASE (commandLine_print)
BOOST_AUTO_TEST_CASE (commandLine_signals)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -137,7 +159,8 @@ BOOST_AUTO_TEST_CASE (commandLine_signals)
// FIXME: is it what we should expect?
BOOST_AUTO_TEST_CASE (commandLine_signalDep)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -159,7 +182,8 @@ BOOST_AUTO_TEST_CASE (commandLine_signalDep)
BOOST_AUTO_TEST_CASE (commandLine_unknown)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
......@@ -181,7 +205,8 @@ BOOST_AUTO_TEST_CASE (commandLine_unknown)
BOOST_AUTO_TEST_CASE (writeGraph)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
entity.writeGraph (output);
......@@ -191,7 +216,8 @@ BOOST_AUTO_TEST_CASE (writeGraph)
BOOST_AUTO_TEST_CASE (writeCompletionList)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
output_test_stream output;
entity.writeGraph (output);
......@@ -202,7 +228,9 @@ BOOST_AUTO_TEST_CASE (writeCompletionList)
// WTF?
BOOST_AUTO_TEST_CASE (wtf)
{
dynamicgraph::Entity entity ("my-entity");
dynamicgraph::Entity& entity =
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
BOOST_CHECK_EQUAL (entity.test (),
static_cast<dynamicgraph::SignalBase<int>*> (0));
......
......@@ -65,12 +65,10 @@ BOOST_AUTO_TEST_CASE (registerEntity)
BOOST_CHECK_EQUAL (exception.getCode (),
dynamicgraph::ExceptionFactory::OBJECT_CONFLICT);
}
}
BOOST_AUTO_TEST_CASE (unregisterEntity)
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity ("myEntity", &makeEntity);
dynamicgraph::FactoryStorage::getInstance()->deregisterEntity ("myEntity");
try
......@@ -131,9 +129,6 @@ BOOST_AUTO_TEST_CASE (newEntity)
BOOST_AUTO_TEST_CASE (existEntity)
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
("myEntity", &makeEntity);
BOOST_CHECK (dynamicgraph::FactoryStorage::getInstance()->existEntity
("myEntity"));
BOOST_CHECK (!dynamicgraph::FactoryStorage::getInstance()->existEntity
......
......@@ -47,26 +47,18 @@ struct MyEntity : public dynamicgraph::Entity
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (MyEntity, "MyEntity");
BOOST_AUTO_TEST_CASE (pool_list)
{
MyEntity myEntity("MyEntityInst");
std::istringstream in;
output_test_stream output;
dynamicgraph::PoolStorage::getInstance()->commandLine
("pool", "list", in, output);
BOOST_CHECK (output.is_equal ("MyEntityInst (MyEntity)\n"));
dynamicgraph::PoolStorage::getInstance()->deregisterEntity
(myEntity.getName());
}
BOOST_AUTO_TEST_CASE (pool_display)
{
MyEntity myEntity("MyEntityInst");
dynamicgraph::Entity* entity =
dynamicgraph::FactoryStorage::getInstance()->
newEntity("MyEntity", "MyEntityInst");
output_test_stream output;
dynamicgraph::Entity& e = dynamicgraph::PoolStorage::getInstance()->getEntity
("MyEntityInst");
e.display(output);
BOOST_CHECK (output.is_equal ("Hello! My name is MyEntityInst !\n"));
dynamicgraph::PoolStorage::getInstance()->deregisterEntity
(myEntity.getName());
(entity->getName());
dynamicgraph::PoolStorage::destroy();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment