From 99b70dba573f685c4c9ae27c7b1c1e60f2ec5dcf Mon Sep 17 00:00:00 2001
From: Thomas Moulard <thomas.moulard@gmail.com>
Date: Wed, 29 Dec 2010 01:32:20 +0100
Subject: [PATCH] Add tests for plug-in loading/unloading.

---
 tests/CMakeLists.txt  |  1 +
 tests/interpreter.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index db6f1da..25f51da 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 d1db476..477fa53 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);
+    }
+}
-- 
GitLab