diff --git a/tests/custom-entity.cpp b/tests/custom-entity.cpp index c19b16314d1d4bea40d25e3c14e6e366aa09f85e..8d4cae42c65dfc154bca6c3bb1f89f59ddd75e32 100644 --- a/tests/custom-entity.cpp +++ b/tests/custom-entity.cpp @@ -29,7 +29,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; } diff --git a/tests/entity.cpp b/tests/entity.cpp index c6ea7dd97bfe265dcbdce603b96478115077f592..0bd94db79d198173b836aa25ef49e5f9cb699889 100644 --- a/tests/entity.cpp +++ b/tests/entity.cpp @@ -16,6 +16,7 @@ #include <sstream> #include <dynamic-graph/entity.h> #include <dynamic-graph/exception-factory.h> +#include <dynamic-graph/factory.h> #define BOOST_TEST_MODULE entity @@ -24,20 +25,39 @@ using boost::test_tools::output_test_stream; +namespace dynamicgraph +{ + class CustomEntity : public Entity + { + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName () const + { + return CLASS_NAME; + } + CustomEntity (const std::string n) + : Entity (n) + { + } + }; + DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity"); +} + + BOOST_AUTO_TEST_CASE (constructor) { - BOOST_CHECK_EQUAL (dynamicgraph::Entity::CLASS_NAME, "Entity"); + BOOST_CHECK_EQUAL (dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); - dynamicgraph::Entity entity ("my-entity"); - BOOST_CHECK_EQUAL (entity.getName (), "my-entity"); - BOOST_CHECK_EQUAL (entity.getClassName (), dynamicgraph::Entity::CLASS_NAME); + dynamicgraph::CustomEntity entity ("my-entity"); + BOOST_CHECK_EQUAL (entity.getName (), "my-entity"); + BOOST_CHECK_EQUAL (entity.getClassName (), dynamicgraph::Entity::CLASS_NAME); - dynamicgraph::Entity entity2 (""); + dynamicgraph::CustomEntity entity2 (""); } BOOST_AUTO_TEST_CASE (signal) { - dynamicgraph::Entity entity (""); + dynamicgraph::CustomEntity entity (""); // Non const getter. try @@ -54,7 +74,7 @@ BOOST_AUTO_TEST_CASE (signal) // Const getter. try { - const dynamicgraph::Entity& entityConst = entity; + const dynamicgraph::CustomEntity& entityConst = entity; entityConst.getSignal ("I do not exist"); BOOST_ERROR ("Should never happen."); } @@ -67,7 +87,7 @@ BOOST_AUTO_TEST_CASE (signal) BOOST_AUTO_TEST_CASE (displaySignalList) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; @@ -77,7 +97,7 @@ BOOST_AUTO_TEST_CASE (displaySignalList) BOOST_AUTO_TEST_CASE (display) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; @@ -87,13 +107,13 @@ BOOST_AUTO_TEST_CASE (display) BOOST_AUTO_TEST_CASE (getCommandList) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); BOOST_CHECK_EQUAL (entity.getCommandList (), "print\nsignals\nsignalDep"); } BOOST_AUTO_TEST_CASE (commandLine_help) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; @@ -112,19 +132,19 @@ BOOST_AUTO_TEST_CASE (commandLine_help) BOOST_AUTO_TEST_CASE (commandLine_print) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; std::istringstream args; entity.commandLine("print", args, output); - BOOST_CHECK (output.is_equal ("Entity: my-entity\n")); + BOOST_CHECK (output.is_equal ("CustomEntity: my-entity\n")); } BOOST_AUTO_TEST_CASE (commandLine_signals) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; @@ -137,7 +157,7 @@ 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::CustomEntity entity ("my-entity"); output_test_stream output; @@ -159,7 +179,7 @@ BOOST_AUTO_TEST_CASE (commandLine_signalDep) BOOST_AUTO_TEST_CASE (commandLine_unknown) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; @@ -181,7 +201,7 @@ BOOST_AUTO_TEST_CASE (commandLine_unknown) BOOST_AUTO_TEST_CASE (writeGraph) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; entity.writeGraph (output); @@ -191,7 +211,7 @@ BOOST_AUTO_TEST_CASE (writeGraph) BOOST_AUTO_TEST_CASE (writeCompletionList) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); output_test_stream output; entity.writeGraph (output); @@ -202,7 +222,7 @@ BOOST_AUTO_TEST_CASE (writeCompletionList) // WTF? BOOST_AUTO_TEST_CASE (wtf) { - dynamicgraph::Entity entity ("my-entity"); + dynamicgraph::CustomEntity entity ("my-entity"); BOOST_CHECK_EQUAL (entity.test (), static_cast<dynamicgraph::SignalBase<int>*> (0)); diff --git a/tests/factory.cpp b/tests/factory.cpp index 716964d903dfc921d7cd9217496264521e5cdcdd..3a2c3668d728cfa945ae3d2daafbe4ddbace6e5e 100644 --- a/tests/factory.cpp +++ b/tests/factory.cpp @@ -26,9 +26,29 @@ using boost::test_tools::output_test_stream; + +namespace dynamicgraph +{ + class CustomEntity : public Entity + { + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName () const + { + return CLASS_NAME; + } + CustomEntity (const std::string n) + : Entity (n) + { + } + }; + const std::string CustomEntity::CLASS_NAME = "CustomEntity"; +} + + dynamicgraph::Entity* makeEntity(const std::string& objectName) { - return new dynamicgraph::Entity (objectName); + return new dynamicgraph::CustomEntity (objectName); }