diff options
-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; |