diff --git a/src/plug-in/plugininterface.h b/src/plug-in/plugininterface.h deleted file mode 100644 index ef45d99dd9563a2c9d218a26a82c4485f04ae8d7..0000000000000000000000000000000000000000 --- a/src/plug-in/plugininterface.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef PLUGIN_INTERFACE_H -#define PLUGIN_INTERFACE_H - -#include <string> -#include "global.h" - -#include "plugin.h" - -/* - * @file plugininterface.h - * @brief Define a plugin object - */ - -namespace sflphone { - - class Plugin; - - class PluginInterface { - - public: - PluginInterface( const std::string &name ){ - _name = name; - } - - virtual ~PluginInterface() {} - - inline std::string getInterfaceName (void) { return _name; } - - /** - * Return the minimal core version required so that the plugin could work - * @return int The version required - */ - virtual int initFunc () = 0; - - virtual int registerFunc (Plugin **plugin) = 0; - - private: - PluginInterface &operator =(const PluginInterface &plugin); - - std::string _name; - }; - - typedef PluginInterface* createFunc (void); - - typedef void destroyFunc( PluginInterface* ); - -} - -#endif //PLUGIN_INTERFACE_H - diff --git a/src/plug-in/test/pluginTest.cpp b/src/plug-in/test/pluginTest.cpp index 066501d6588f7d02ced18d627160fd8a3b7da8ab..cbd1b1d760dd79797bdafead09b73fb69c1836a4 100644 --- a/src/plug-in/test/pluginTest.cpp +++ b/src/plug-in/test/pluginTest.cpp @@ -1,40 +1,49 @@ -#include "../plugininterface.h" +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + #include "../plugin.h" -namespace sflphone { +#define MAJOR_VERSION 1 +#define MINOR_VERSION 0 - class PluginTest : public PluginInterface { - - public: - PluginTest( const std::string &name ):PluginInterface( name ){ - } +class PluginTest : public Plugin { - virtual int initFunc (void) - { - return 0; + public: + PluginTest( const std::string &name ) + :Plugin( name ) { } - virtual int registerFunc (Plugin **plugin) - { - Plugin *ret; + virtual int initFunc (PluginInfo **info) { - ret = new Plugin(this); - - ret->_name = getInterfaceName(); - ret->_required = 1; - ret->_version_major=1; - ret->_version_minor=0; + (*info)->_plugin = this; + (*info)->_major_version = MAJOR_VERSION; + (*info)->_minor_version = MINOR_VERSION; + (*info)->_name = getPluginName(); - *plugin = ret; - return 0; - } - }; + return 0; + } +}; -} -extern "C" ::sflphone::PluginInterface* create (void){ - return new ::sflphone::PluginTest("test"); +extern "C" Plugin* createPlugin (void){ + return new PluginTest("mytest"); } -extern "C" void* destroy( ::sflphone::PluginInterface *p ){ +extern "C" void destroyPlugin (Plugin *p){ delete p; } diff --git a/test/pluginmanagerTest.cpp b/test/pluginmanagerTest.cpp index 7fd16c28cd0e8c46d185830d1781df2819aea429..96994b6925219cfc565906873e8d6574fcc3c238 100644 --- a/test/pluginmanagerTest.cpp +++ b/test/pluginmanagerTest.cpp @@ -19,32 +19,77 @@ #include <stdio.h> #include <sstream> +#include <dlfcn.h> #include "pluginmanagerTest.h" using std::cout; using std::endl; +#define PLUGIN_TEST_DIR "/usr/lib/sflphone/plugins/" +#define PLUGIN_TEST_DESC "mytest" +#define PLUGIN_TEST_NAME "/usr/lib/sflphone/plugins/libplugintest.so" + + void PluginManagerTest::setUp(){ - _pm = ::sflphone::PluginManager::instance(); + // Instanciate the plugin manager singleton + _pm = PluginManager::instance(); + library = 0; + plugin = 0; +} + +void PluginManagerTest::testLoadDynamicLibrary(){ + CPPUNIT_ASSERT(_pm->loadDynamicLibrary(PLUGIN_TEST_NAME) != NULL); } -void PluginManagerTest::testLoadPluginDirectory(){ - CPPUNIT_ASSERT(_pm->loadPlugins() == 0); +void PluginManagerTest::testUnloadDynamicLibrary(){ + library = _pm->loadDynamicLibrary(PLUGIN_TEST_NAME); + CPPUNIT_ASSERT(library != NULL); + CPPUNIT_ASSERT(_pm->unloadDynamicLibrary(library) == 0 ); } -void PluginManagerTest::testLoadPlugin(){ - CPPUNIT_ASSERT(_pm->loadPlugins() == 0); - //CPPUNIT_ASSERT( _pm->isPluginLoaded("test") == NULL ); +void PluginManagerTest::testInstanciatePlugin(){ + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT(library != NULL); + CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); + CPPUNIT_ASSERT (plugin!=NULL); +} + +void PluginManagerTest::testInitPlugin(){ + + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT(library != NULL); + CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); + CPPUNIT_ASSERT (plugin!=NULL); + CPPUNIT_ASSERT (plugin->getPluginName() == PLUGIN_TEST_DESC); } void PluginManagerTest::testRegisterPlugin(){ - // First load the default directory - _pm->loadPlugins(); - // Resolve the symbol + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT(library != NULL); + CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false); + CPPUNIT_ASSERT (_pm->registerPlugin (plugin, library) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); +} + +void PluginManagerTest::testLoadPlugins (){ + CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); +} + +void PluginManagerTest::testUnloadPlugins (){ + CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); + CPPUNIT_ASSERT (_pm->unloadPlugins () == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false); } void PluginManagerTest::tearDown(){ // Delete the plugin manager object delete _pm; _pm=0; + if(plugin) + delete plugin; plugin = 0; + if(library) + delete library; library = 0; }