summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-05-02 18:17:29 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-05-02 18:17:29 +0100
commit3c7f89796275ff535c190c4a58775da48f76cb46 (patch)
treeb465fdd5aaaa566b2ae224ae1a0d43c1632c4381
parentCentralize the mocking code (diff)
downloadproject2-3c7f89796275ff535c190c4a58775da48f76cb46.tar.bz2
project2-3c7f89796275ff535c190c4a58775da48f76cb46.tar.xz
project2-3c7f89796275ff535c190c4a58775da48f76cb46.zip
Refactor, more OO, less hacky bind
-rw-r--r--project2/sql/mockDatabase.cpp4
-rw-r--r--project2/sql/mockDatabase.h3
-rw-r--r--project2/sql/mockDatasource.cpp4
-rw-r--r--project2/sql/mockDatasource.h4
4 files changed, 8 insertions, 7 deletions
diff --git a/project2/sql/mockDatabase.cpp b/project2/sql/mockDatabase.cpp
index 259dfd6..80322cf 100644
--- a/project2/sql/mockDatabase.cpp
+++ b/project2/sql/mockDatabase.cpp
@@ -3,7 +3,6 @@
#include <misc.h>
#include <logger.h>
#include <fstream>
-#include <boost/bind.hpp>
MockDatabase::MockDatabase(const std::string & name) :
mockName(name)
@@ -35,7 +34,7 @@ MockDatabase::PlaySchemaScripts(const std::vector<boost::filesystem::path> & ss)
}
delete conn;
Logger()->messagebf(LOG_DEBUG, "%s initialized", mockName);
- MockConnectionLoader::mocks[mockName] = boost::bind(&MockDatabase::openConnection, this);
+ MockConnectionLoader::mocks[mockName] = this;
}
catch (...) {
if (conn->inTx()) {
@@ -72,5 +71,6 @@ MockServerDatabase::DropDatabase() const
{
Logger()->messagebf(LOG_INFO, "Creating new database %s", testDbName);
master->execute("DROP DATABASE IF EXISTS " + testDbName);
+ MockConnectionLoader::mocks.erase(mockName);
}
diff --git a/project2/sql/mockDatabase.h b/project2/sql/mockDatabase.h
index 49e49a8..5cf42f2 100644
--- a/project2/sql/mockDatabase.h
+++ b/project2/sql/mockDatabase.h
@@ -11,11 +11,12 @@ class MockDatabase {
MockDatabase(const std::string & mockName);
virtual ~MockDatabase();
+ virtual DB::Connection * openConnection() const = 0;
+
protected:
virtual void CreateNewDatabase() const = 0;
virtual void PlaySchemaScripts(const std::vector<boost::filesystem::path> & ss) const;
virtual void DropDatabase() const = 0;
- virtual DB::Connection * openConnection() const = 0;
const std::string mockName;
};
diff --git a/project2/sql/mockDatasource.cpp b/project2/sql/mockDatasource.cpp
index 06648ad..df5d325 100644
--- a/project2/sql/mockDatasource.cpp
+++ b/project2/sql/mockDatasource.cpp
@@ -4,12 +4,12 @@
DECLARE_CUSTOM_COMPONENT_LOADER("mock", T, MockConnectionLoader, ConnectionLoader);
-std::map<std::string, MockConnectionLoader::ConnectionCreator> MockConnectionLoader::mocks;
+std::map<std::string, const MockDatabase *> MockConnectionLoader::mocks;
unsigned int MockConnectionLoader::mocked = 0;
DB::Connection *
MockConnectionLoader::create(const std::string & n) const
{
- return safeMapFind<std::runtime_error>(mocks, n)->second();
+ return safeMapFind<std::runtime_error>(mocks, n)->second->openConnection();
}
diff --git a/project2/sql/mockDatasource.h b/project2/sql/mockDatasource.h
index facc8a5..ee1e976 100644
--- a/project2/sql/mockDatasource.h
+++ b/project2/sql/mockDatasource.h
@@ -2,14 +2,14 @@
#define MOCKDATASOURCE_H
#include <rdbmsDataSource.h>
+#include "mockDatabase.h"
class MockConnectionLoader : public ConnectionLoader {
public:
DB::Connection * create(const std::string &) const;
static unsigned int mocked;
- typedef boost::function<DB::Connection *()> ConnectionCreator;
- static std::map<std::string, ConnectionCreator> mocks;
+ static std::map<std::string, const MockDatabase *> mocks;
};
#endif