diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-24 02:08:08 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-24 02:08:08 +0100 |
commit | e197aca58ef73ac89535611bdf87195f3238ad68 (patch) | |
tree | 9c3fac3653ed6cd367966ef201ce28edefbcd058 | |
parent | Fix single include macro names (diff) | |
download | libdbpp-e197aca58ef73ac89535611bdf87195f3238ad68.tar.bz2 libdbpp-e197aca58ef73ac89535611bdf87195f3238ad68.tar.xz libdbpp-e197aca58ef73ac89535611bdf87195f3238ad68.zip |
Register mocked database instances with the plugin manager and wrap up opening connections to them by name
-rw-r--r-- | libdbpp/mockDatabase.cpp | 20 | ||||
-rw-r--r-- | libdbpp/mockDatabase.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp index 3ef8728..b611c70 100644 --- a/libdbpp/mockDatabase.cpp +++ b/libdbpp/mockDatabase.cpp @@ -2,6 +2,18 @@ #include <buffer.h> #include <fstream> #include <modifycommand.h> +#include <plugins.impl.h> + +namespace AdHoc { + template <> + PluginOf<DB::MockDatabase>::~PluginOf() + { + // This implementation doesn't delete .implementation as + // mock databases simply unregister themselves (via destructor) + // when the mock framework tears them down. + } +} +INSTANIATEPLUGINOF(DB::MockDatabase); namespace DB { @@ -10,10 +22,18 @@ unsigned int MockDatabase::mocked = 0; MockDatabase::MockDatabase(const std::string & name) : mockName(name) { + AdHoc::PluginManager::getDefault()->add(AdHoc::PluginPtr(new AdHoc::PluginOf<MockDatabase>(this, mockName, __FILE__, __LINE__))); } MockDatabase::~MockDatabase() { + AdHoc::PluginManager::getDefault()->remove<MockDatabase>(mockName); +} + +Connection * +MockDatabase::openConnectionTo(const std::string & mockName) +{ + return AdHoc::PluginManager::getDefault()->get<DB::MockDatabase>(mockName)->implementation()->openConnection(); } void diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h index a1d935b..3e26201 100644 --- a/libdbpp/mockDatabase.h +++ b/libdbpp/mockDatabase.h @@ -15,6 +15,7 @@ class DLL_PUBLIC MockDatabase { virtual ~MockDatabase(); virtual DB::Connection * openConnection() const = 0; + static Connection * openConnectionTo(const std::string &); protected: virtual void CreateNewDatabase() const = 0; |