Skip to content
Snippets Groups Projects
Commit 73a3c5a3 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6300: tests do not require an installed sflphone

Instead, they will use environment variables.
parent 67c4d4fb
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ pushd sflphone-common/test
rm -rf $XML_RESULTS
make check
# 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
# Compile the client
......
......@@ -192,9 +192,13 @@ std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory (void)
std::string libDir = std::string (CODECS_DIR).append ("/");
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;
dirToScan.push_back (homeDir);
dirToScan.push_back (libDir);
if (envDir)
dirToScan.push_back(std::string(envDir) + DIR_SEPARATOR_STR);
for (i = 0 ; (unsigned int) i < dirToScan.size() ; i++) {
std::string dirStr = dirToScan[i];
......
......@@ -56,6 +56,15 @@ PluginManager::~PluginManager()
_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
PluginManager::loadPlugins (const std::string &path)
{
......@@ -69,7 +78,10 @@ PluginManager::loadPlugins (const std::string &path)
const std::string cDir = ".";
/* 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());
dir = opendir (pluginDir.c_str());
......@@ -80,9 +92,9 @@ PluginManager::loadPlugins (const std::string &path)
while ( (dirStruct=readdir (dir))) {
/* Get the name of the current item in the directory */
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 */
library = loadDynamicLibrary (pluginDir + current);
......
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
test_CXXFLAGS = $(CPPUNIT_CFLAGS)
......
......@@ -37,13 +37,13 @@
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"
#define FAKE_PLUGIN_DESC "mytest"
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
_pm = PluginManager::instance();
library = 0;
......@@ -54,14 +54,14 @@ void PluginManagerTest::testLoadDynamicLibrary()
{
_debug ("-------------------- PluginManagerTest::testLoadDynamicLibrary --------------------\n");
CPPUNIT_ASSERT (_pm->loadDynamicLibrary (PLUGIN_TEST_NAME) != NULL);
CPPUNIT_ASSERT (_pm->loadDynamicLibrary (FAKE_PLUGIN_NAME) != NULL);
}
void PluginManagerTest::testUnloadDynamicLibrary()
{
_debug ("-------------------- PluginManagerTest::testUnloadDynamicLibrary --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->unloadDynamicLibrary (library) == 0);
}
......@@ -70,7 +70,7 @@ void PluginManagerTest::testInstanciatePlugin()
{
_debug ("-------------------- PluginManagerTest::testInstanciatePlugin --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (plugin!=NULL);
......@@ -80,32 +80,31 @@ void PluginManagerTest::testInitPlugin()
{
_debug ("-------------------- PluginManagerTest::testInitPlugin --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (plugin!=NULL);
CPPUNIT_ASSERT (plugin->getPluginName() == PLUGIN_TEST_DESC);
CPPUNIT_ASSERT (plugin->getPluginName() == FAKE_PLUGIN_DESC);
}
void PluginManagerTest::testRegisterPlugin()
{
_debug ("-------------------- PluginManagerTest::testRegisterPlugin --------------------\n");
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
library = _pm->loadDynamicLibrary (FAKE_PLUGIN_NAME);
CPPUNIT_ASSERT (library != NULL);
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->isPluginLoaded (PLUGIN_TEST_DESC) == true);
CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == true);
}
void PluginManagerTest::testLoadPlugins ()
{
_debug ("-------------------- PluginManagerTest::testLoadPlugins --------------------\n");
try {
CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true);
CPPUNIT_ASSERT (_pm->loadPlugins (FAKE_PLUGIN_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == true);
}
catch (LibraryManagerException &e){
......@@ -118,10 +117,10 @@ void PluginManagerTest::testUnloadPlugins ()
try {
CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true);
CPPUNIT_ASSERT (_pm->loadPlugins (FAKE_PLUGIN_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == true);
CPPUNIT_ASSERT (_pm->unloadPlugins () == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false);
CPPUNIT_ASSERT (_pm->isPluginLoaded (FAKE_PLUGIN_DESC) == false);
}
catch (LibraryManagerException &e) {
......
......@@ -94,6 +94,8 @@ class PluginManagerTest : public CppUnit::TestCase {
void testUnloadPlugins ();
private:
std::string FAKE_PLUGIN_DIR;
std::string FAKE_PLUGIN_NAME;
PluginManager *_pm;
LibraryManager *library;
Plugin *plugin;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment