diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4a2acc16bfe052bd8e44f00e47485a00e78f0dd9..24ac5b401c9faf8a82bc68e0e5dd52f253c58b1d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,8 +39,6 @@ MACRO(DYNAMIC_GRAPH_TEST NAME) # Link against Boost. TARGET_LINK_LIBRARIES(${NAME} ${Boost_LIBRARIES}) ENDMACRO(DYNAMIC_GRAPH_TEST) - -DYNAMIC_GRAPH_TEST(test_pool) DYNAMIC_GRAPH_TEST(test_depend) @@ -59,4 +57,5 @@ TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${signalcast_libs}) # Unit testing. DYNAMIC_GRAPH_TEST(entity) DYNAMIC_GRAPH_TEST(custom-entity) -DYNAMIC_GRAPH_TEST(factory) \ No newline at end of file +DYNAMIC_GRAPH_TEST(factory) +DYNAMIC_GRAPH_TEST(pool) \ No newline at end of file diff --git a/tests/pool.cpp b/tests/pool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ba65815627339ad5438cafa28cdeb1f8dc0ebf0 --- /dev/null +++ b/tests/pool.cpp @@ -0,0 +1,66 @@ +// 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/>. + +#include <sstream> +#include <dynamic-graph/entity.h> +#include <dynamic-graph/factory.h> +#include <dynamic-graph/exception-factory.h> +#include <dynamic-graph/pool.h> + +#define BOOST_TEST_MODULE pool + +#include <boost/test/unit_test.hpp> +#include <boost/test/output_test_stream.hpp> + +using boost::test_tools::output_test_stream; + +struct MyEntity : public dynamicgraph::Entity +{ + static const std::string CLASS_NAME; + + MyEntity (const std::string& name) + : Entity (name) + {} + + virtual void display (std::ostream& os) const + { + os << "Hello! My name is " << getName () << " !" << std::endl; + } + + virtual const std::string& getClassName () const + { + return CLASS_NAME; + } +}; + +DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (MyEntity, "MyEntity"); + +BOOST_AUTO_TEST_CASE (pool_list) +{ + MyEntity myEntity("MyEntityInst"); + std::istringstream in; + output_test_stream output; + dynamicgraph::g_pool.commandLine("pool", "list", in, output); + BOOST_CHECK (output.is_equal ("MyEntityInst (MyEntity)\n")); +} + +BOOST_AUTO_TEST_CASE (pool_display) +{ + MyEntity myEntity("MyEntityInst"); + output_test_stream output; + dynamicgraph::Entity& e = dynamicgraph::g_pool.getEntity("MyEntityInst"); + e.display(output); + BOOST_CHECK (output.is_equal ("Hello! My name is MyEntityInst !\n")); +} diff --git a/tests/test_pool.cpp b/tests/test_pool.cpp deleted file mode 100644 index 208d5daec229e3a3e41077fea82fc5f1e2a7e4c5..0000000000000000000000000000000000000000 --- a/tests/test_pool.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * 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/>. - */ - -/* -------------------------------------------------------------------------- */ -/* --- INCLUDES ------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - - -#include <string> -#include <iostream> -#include <cstdlib> - -#include <dynamic-graph/factory.h> -#include <dynamic-graph/entity.h> -#include <dynamic-graph/debug.h> -#include <dynamic-graph/pool.h> - -#include <memory> - -using namespace std; -using namespace dynamicgraph; - -class MyEntity -: public Entity -{ - - public: - MyEntity(const std::string& name); - - - public: /* --- ENTITY INHERITANCE --- */ - static const std::string CLASS_NAME; - virtual void display( std::ostream& os ) const; - virtual const std::string& getClassName( void ) const { return CLASS_NAME; } - - - protected: -}; - -DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity,"MyEntity"); - -MyEntity::MyEntity(const std::string& name) - : Entity(name){ - -} - -void MyEntity::display(std::ostream& os ) const { - os << "Hello! My name is " << getName() << " !" << endl; -} - -int main() { - MyEntity myEntity("MyEntity"); - - cout << "-- Pool.list" << endl; - g_pool.commandLine("pool", "list", *auto_ptr<istringstream>(new istringstream("")), cout); - Entity& e = g_pool.getEntity("MyEntity"); - cout << "-- Display" << endl; - e.display(cout); -}