Skip to content
Snippets Groups Projects
Commit 20375709 authored by Alexandre Savard's avatar Alexandre Savard
Browse files
parents ef339abd 73a3c5a3
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ pushd sflphone-common/test ...@@ -29,7 +29,7 @@ pushd sflphone-common/test
rm -rf $XML_RESULTS rm -rf $XML_RESULTS
make check make check
# if at least one test failed, exit # if at least one test failed, exit
./test --xml || exit 1 CODECS_PATH="../src/audio/codecs" FAKE_PLUGIN_DIR="../src/plug-in/test/" FAKE_PLUGIN_NAME="../src/plug-in/test/libplugintest.so" ./test --xml || exit 1
popd popd
# Compile the client # Compile the client
......
...@@ -192,9 +192,13 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory (void) ...@@ -192,9 +192,13 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory (void)
std::string libDir = std::string (CODECS_DIR).append ("/"); std::string libDir = std::string (CODECS_DIR).append ("/");
std::string homeDir = std::string (HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR + "/"; std::string homeDir = std::string (HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR + "/";
// look for a CODECS_PATH environment variable...used in tests
const char *envDir = getenv("CODECS_PATH");
std::vector<std::string> dirToScan; std::vector<std::string> dirToScan;
dirToScan.push_back (homeDir); dirToScan.push_back (homeDir);
dirToScan.push_back (libDir); dirToScan.push_back (libDir);
if (envDir)
dirToScan.push_back(std::string(envDir) + DIR_SEPARATOR_STR);
for (i = 0 ; (unsigned int) i < dirToScan.size() ; i++) { for (i = 0 ; (unsigned int) i < dirToScan.size() ; i++) {
std::string dirStr = dirToScan[i]; std::string dirStr = dirToScan[i];
......
...@@ -56,6 +56,15 @@ PluginManager::~PluginManager() ...@@ -56,6 +56,15 @@ PluginManager::~PluginManager()
_instance = 0; _instance = 0;
} }
namespace {
bool hasSharedExtension(const std::string &fn)
{
size_t dot_position = fn.rfind(".");
return (dot_position != std::string::npos and
fn.substr(dot_position) == ".so");
}
}
int int
PluginManager::loadPlugins (const std::string &path) PluginManager::loadPlugins (const std::string &path)
{ {
...@@ -69,7 +78,10 @@ PluginManager::loadPlugins (const std::string &path) ...@@ -69,7 +78,10 @@ PluginManager::loadPlugins (const std::string &path)
const std::string cDir = "."; const std::string cDir = ".";
/* The directory in which plugins are dropped. Default: /usr/lib/sflphone/plugins/ */ /* The directory in which plugins are dropped. Default: /usr/lib/sflphone/plugins/ */
(path == "") ? pluginDir = std::string (PLUGINS_DIR).append ("/") :pluginDir = path; if (path.empty())
pluginDir = std::string (PLUGINS_DIR).append("/");
else
pluginDir = path;
_debug ("Loading plugins from %s...", pluginDir.c_str()); _debug ("Loading plugins from %s...", pluginDir.c_str());
dir = opendir (pluginDir.c_str()); dir = opendir (pluginDir.c_str());
...@@ -80,9 +92,9 @@ PluginManager::loadPlugins (const std::string &path) ...@@ -80,9 +92,9 @@ PluginManager::loadPlugins (const std::string &path)
while ( (dirStruct=readdir (dir))) { while ( (dirStruct=readdir (dir))) {
/* Get the name of the current item in the directory */ /* Get the name of the current item in the directory */
current = dirStruct->d_name; current = dirStruct->d_name;
/* Test if the current item is not the parent or the current directory */ /* Test if the current item is not the parent or the current directory and that it ends with .so*/
if (current != pDir && current != cDir) { if (current != pDir && current != cDir and hasSharedExtension(current)) {
/* Load the dynamic library */ /* Load the dynamic library */
library = loadDynamicLibrary (pluginDir + current); library = loadDynamicLibrary (pluginDir + current);
......
include ../globals.mak include ../globals.mak
TESTS_ENVIRONMENT = CODECS_PATH="$(top_builddir)/src/audio/codecs" \
FAKE_PLUGIN_DIR="$(top_builddir)/src/plug-in/test/" \
FAKE_PLUGIN_NAME="$(top_builddir)/src/plug-in/test/libplugintest.so"
check_PROGRAMS = test check_PROGRAMS = test
test_CXXFLAGS = $(CPPUNIT_CFLAGS) test_CXXFLAGS = $(CPPUNIT_CFLAGS)
......
...@@ -37,13 +37,13 @@ ...@@ -37,13 +37,13 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
#define PLUGIN_TEST_DIR "/usr/lib/sflphone/plugins/" #define FAKE_PLUGIN_DESC "mytest"
#define PLUGIN_TEST_DESC "mytest"
#define PLUGIN_TEST_NAME "/usr/lib/sflphone/plugins/libplugintest.so"
void PluginManagerTest::setUp() void PluginManagerTest::setUp()
{ {
FAKE_PLUGIN_DIR = std::string(getenv("FAKE_PLUGIN_DIR"));
FAKE_PLUGIN_NAME = std::string(getenv("FAKE_PLUGIN_NAME"));
// Instanciate the plugin manager singleton // Instanciate the plugin manager singleton
_pm = PluginManager::instance(); _pm = PluginManager::instance();
library = 0; library = 0;
...@@ -54,14 +54,14 @@ void PluginManagerTest::testLoadDynamicLibrary() ...@@ -54,14 +54,14 @@ void PluginManagerTest::testLoadDynamicLibrary()
{ {
_debug ("-------------------- PluginManagerTest::testLoadDynamicLibrary --------------------\n"); _debug ("-------------------- PluginManagerTest::testLoadDynamicLibrary --------------------\n");
CPPUNIT_ASSERT (_pm->loadDynamicLibrary (PLUGIN_TEST_NAME) != NULL); CPPUNIT_ASSERT (_pm->loadDynamicLibrary (FAKE_PLUGIN_NAME) != NULL);
} }
void PluginManagerTest::testUnloadDynamicLibrary() void PluginManagerTest::testUnloadDynamicLibrary()
{ {
_debug ("-------------------- PluginManagerTest::testUnloadDynamicLibrary --------------------\n"); _debug ("-------------------- PluginManagerTest::testUnloadDynamicLibrary --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL); CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->unloadDynamicLibrary (library) == 0); CPPUNIT_ASSERT (_pm->unloadDynamicLibrary (library) == 0);
} }
...@@ -70,7 +70,7 @@ void PluginManagerTest::testInstanciatePlugin() ...@@ -70,7 +70,7 @@ void PluginManagerTest::testInstanciatePlugin()
{ {
_debug ("-------------------- PluginManagerTest::testInstanciatePlugin --------------------\n"); _debug ("-------------------- PluginManagerTest::testInstanciatePlugin --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL); CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (plugin!=NULL); CPPUNIT_ASSERT (plugin!=NULL);
...@@ -80,32 +80,31 @@ void PluginManagerTest::testInitPlugin() ...@@ -80,32 +80,31 @@ void PluginManagerTest::testInitPlugin()
{ {
_debug ("-------------------- PluginManagerTest::testInitPlugin --------------------\n"); _debug ("-------------------- PluginManagerTest::testInitPlugin --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL); CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (plugin!=NULL); CPPUNIT_ASSERT (plugin!=NULL);
CPPUNIT_ASSERT (plugin->getPluginName() == PLUGIN_TEST_DESC); CPPUNIT_ASSERT (plugin->getPluginName() == FAKE_PLUGIN_DESC);
} }
void PluginManagerTest::testRegisterPlugin() void PluginManagerTest::testRegisterPlugin()
{ {
_debug ("-------------------- PluginManagerTest::testRegisterPlugin --------------------\n"); _debug ("-------------------- PluginManagerTest::testRegisterPlugin --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL); CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false); CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == false);
CPPUNIT_ASSERT (_pm->registerPlugin (plugin, library) == 0); CPPUNIT_ASSERT (_pm->registerPlugin (plugin, library) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == true);
} }
void PluginManagerTest::testLoadPlugins () void PluginManagerTest::testLoadPlugins ()
{ {
_debug ("-------------------- PluginManagerTest::testLoadPlugins --------------------\n"); _debug ("-------------------- PluginManagerTest::testLoadPlugins --------------------\n");
try { try {
CPPUNIT_ASSERT (_pm->loadPlugins (FAKE_PLUGIN_DIR) == 0);
CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == true);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true);
} }
catch (LibraryManagerException &e){ catch (LibraryManagerException &e){
...@@ -118,10 +117,10 @@ void PluginManagerTest::testUnloadPlugins () ...@@ -118,10 +117,10 @@ void PluginManagerTest::testUnloadPlugins ()
try { try {
CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); CPPUNIT_ASSERT (_pm->loadPlugins (FAKE_PLUGIN_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == true);
CPPUNIT_ASSERT (_pm->unloadPlugins () == 0); CPPUNIT_ASSERT (_pm->unloadPlugins () == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false); CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == false);
} }
catch (LibraryManagerException &e) { catch (LibraryManagerException &e) {
......
...@@ -94,6 +94,8 @@ class PluginManagerTest : public CppUnit::TestCase { ...@@ -94,6 +94,8 @@ class PluginManagerTest : public CppUnit::TestCase {
void testUnloadPlugins (); void testUnloadPlugins ();
private: private:
std::string FAKE_PLUGIN_DIR;
std::string FAKE_PLUGIN_NAME;
PluginManager *_pm; PluginManager *_pm;
LibraryManager *library; LibraryManager *library;
Plugin *plugin; Plugin *plugin;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment