diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-17 20:36:02 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-17 20:36:02 +0100 |
commit | 4be4e730f5dbf0a2e29593d84e5abf64b4a3e5a6 (patch) | |
tree | 7301a0d85ff50f76a9529e6834b5743e4fc8ba12 | |
parent | Add instantiation macros (diff) | |
download | libadhocutil-4be4e730f5dbf0a2e29593d84e5abf64b4a3e5a6.tar.bz2 libadhocutil-4be4e730f5dbf0a2e29593d84e5abf64b4a3e5a6.tar.xz libadhocutil-4be4e730f5dbf0a2e29593d84e5abf64b4a3e5a6.zip |
Test loading and unloading a library containing a plugin
-rw-r--r-- | libadhocutil/unittests/Jamfile.jam | 25 | ||||
-rw-r--r-- | libadhocutil/unittests/testPlugins.cpp | 12 | ||||
-rw-r--r-- | libadhocutil/unittests/testPluginsRuntime.cpp | 34 | ||||
-rw-r--r-- | libadhocutil/unittests/utilTestClasses.cpp | 5 | ||||
-rw-r--r-- | libadhocutil/unittests/utilTestClasses.h | 20 |
5 files changed, 85 insertions, 11 deletions
diff --git a/libadhocutil/unittests/Jamfile.jam b/libadhocutil/unittests/Jamfile.jam index ecee7d1..b4ec60a 100644 --- a/libadhocutil/unittests/Jamfile.jam +++ b/libadhocutil/unittests/Jamfile.jam @@ -6,6 +6,7 @@ lib boost_utf : : <name>boost_unit_test_framework ; lib boost_filesystem ; lib boost_system ; lib boost_thread ; +lib dl ; run testContext.cpp @@ -119,17 +120,41 @@ run testCache ; +lib utilTestClasses : + utilTestClasses.cpp + : : + <define>BOOST_TEST_DYN_LINK + <library>..//adhocutil + <library>boost_utf + ; + run testPlugins.cpp : : : <define>BOOST_TEST_DYN_LINK <library>..//adhocutil <library>boost_utf + <library>utilTestClasses : testPlugins ; run + testPluginsRuntime.cpp + : : : + <define>ROOT=\"$(me)\" + <define>BOOST_TEST_DYN_LINK + <library>..//adhocutil + <library>boost_utf + <library>boost_filesystem + <library>boost_system + <library>dl + <dependency>utilTestClasses + : + testPluginsRuntime + ; + +run testFactory.cpp : : : <define>BOOST_TEST_DYN_LINK diff --git a/libadhocutil/unittests/testPlugins.cpp b/libadhocutil/unittests/testPlugins.cpp index 130d577..ef5ed4b 100644 --- a/libadhocutil/unittests/testPlugins.cpp +++ b/libadhocutil/unittests/testPlugins.cpp @@ -3,20 +3,10 @@ #include "plugins.h" #include "plugins.impl.h" +#include "utilTestClasses.h" using namespace AdHoc; -class BaseThing { }; - -class ImplOfThing : public BaseThing { }; -class OtherImplOfThing : public BaseThing { }; - -class OtherBase { }; - -class OtherImpl : public OtherBase { }; - -PLUGIN(ImplOfThing, BaseThing); - BOOST_AUTO_TEST_CASE( ready ) { BOOST_REQUIRE(PluginManager::getDefault()); diff --git a/libadhocutil/unittests/testPluginsRuntime.cpp b/libadhocutil/unittests/testPluginsRuntime.cpp new file mode 100644 index 0000000..0aa9955 --- /dev/null +++ b/libadhocutil/unittests/testPluginsRuntime.cpp @@ -0,0 +1,34 @@ +#define BOOST_TEST_MODULE Plugins +#include <boost/test/unit_test.hpp> + +#include "plugins.h" +#include "plugins.impl.h" +#include "utilTestClasses.h" +#include <definedDirs.h> +#include <dlfcn.h> + +using namespace AdHoc; + +auto variant = selfExe.parent_path().leaf(); +auto toolset = selfExe.parent_path().parent_path().leaf(); +auto lib = rootDir / "bin" / toolset / variant / "libutilTestClasses.so"; + +BOOST_AUTO_TEST_CASE( ready ) +{ + BOOST_REQUIRE(PluginManager::getDefault()); + BOOST_REQUIRE(boost::filesystem::exists(lib)); +} + +BOOST_AUTO_TEST_CASE( clean ) +{ + BOOST_REQUIRE_EQUAL(0, AdHoc::PluginManager::getDefault()->getAll<BaseThing>().size()); +} + +BOOST_AUTO_TEST_CASE( loadAndUnloadlib ) +{ + void * handle = dlopen(lib.c_str(), RTLD_NOW); + BOOST_REQUIRE(handle); + BOOST_REQUIRE_EQUAL(1, AdHoc::PluginManager::getDefault()->getAll<BaseThing>().size()); + dlclose(handle); + BOOST_REQUIRE_EQUAL(0, AdHoc::PluginManager::getDefault()->getAll<BaseThing>().size()); +} diff --git a/libadhocutil/unittests/utilTestClasses.cpp b/libadhocutil/unittests/utilTestClasses.cpp new file mode 100644 index 0000000..cb31104 --- /dev/null +++ b/libadhocutil/unittests/utilTestClasses.cpp @@ -0,0 +1,5 @@ +#include "utilTestClasses.h" +#include "plugins.impl.h" + +PLUGIN(ImplOfThing, BaseThing); + diff --git a/libadhocutil/unittests/utilTestClasses.h b/libadhocutil/unittests/utilTestClasses.h new file mode 100644 index 0000000..f2a2036 --- /dev/null +++ b/libadhocutil/unittests/utilTestClasses.h @@ -0,0 +1,20 @@ +#ifndef LIBADHOCUTIL_UNITTESTS_UTILTESTCLASSES_H +#define LIBADHOCUTIL_UNITTESTS_UTILTESTCLASSES_H + +class BaseThing { +}; + +class ImplOfThing : public BaseThing { +}; + +class OtherImplOfThing : public BaseThing { +}; + +class OtherBase { +}; + +class OtherImpl : public OtherBase { +}; + +#endif + |