diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db6f1daacbb3f59eed15a970f6f01333bb7bdc7f..25f51daed0f7405c2796fe3175725209afc1ff79 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,7 @@ INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) ADD_DEFINITIONS(-DTESTS_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data") +ADD_DEFINITIONS(-DTESTS_PLUGINDIR="${LIBRARY_OUTPUT_PATH}") # DYNAMIC_GRAPH_TEST(NAME) # ------------------------ diff --git a/tests/interpreter.cpp b/tests/interpreter.cpp index d1db4760e007d1dbd4038f39e806396303e4c2f0..477fa53a03cfac060461aa8e45f3e40c8b1657ad 100644 --- a/tests/interpreter.cpp +++ b/tests/interpreter.cpp @@ -16,6 +16,7 @@ #include <sstream> #include <dynamic-graph/exception-factory.h> #include <dynamic-graph/interpreter.h> +#include <dynamic-graph/plugin-loader.h> #define BOOST_TEST_MODULE interpreter @@ -187,3 +188,51 @@ BOOST_AUTO_TEST_CASE (cmd_import_push) } } + +// Check that plug-in loading/unloading is working. +BOOST_AUTO_TEST_CASE (cmd_loadPlugin) +{ + dynamicgraph::PluginLoader pl; + dynamicgraph::Interpreter shell (&pl); + + { + RUN_COMMAND ("loadPlugin", "shell-functions.so" " " TESTS_PLUGINDIR); + BOOST_CHECK (output.is_empty ()); + } + { + RUN_COMMAND ("loadPlugin", "shell-procedure.so" " " TESTS_PLUGINDIR); + BOOST_CHECK (output.is_empty ()); + } + + { + RUN_COMMAND ("unloadPlugin", TESTS_PLUGINDIR "/shell-procedure.so"); + BOOST_CHECK (output.is_empty ()); + } + + { + RUN_COMMAND ("unloadPlugin", TESTS_PLUGINDIR "/shell-functions.so"); + BOOST_CHECK (output.is_empty ()); + } + + try + { + RUN_COMMAND ("loadPlugin", "idonotexist ."); + BOOST_ERROR ("Should never happen"); + } + catch (const dynamicgraph::ExceptionFactory& exception) + { + BOOST_CHECK_EQUAL (exception.getCode (), + dynamicgraph::ExceptionFactory::DYNAMIC_LOADING); + } + + try + { + RUN_COMMAND ("unloadPlugin", "idonotexist"); + BOOST_ERROR ("Should never happen"); + } + catch (const dynamicgraph::ExceptionFactory& exception) + { + BOOST_CHECK_EQUAL (exception.getCode (), + dynamicgraph::ExceptionFactory::OBJECT_CONFLICT); + } +}