diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-24 03:05:12 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-24 03:06:07 +0100 |
commit | 35382065da97e8e98c3883caebc0b8f51aa33e90 (patch) | |
tree | 5b53d246def27e0f588ab0d02a91532e0c913908 /libsqlitepp/mock.cpp | |
parent | Connector compatibility fix (diff) | |
download | libdbpp-sqlite-35382065da97e8e98c3883caebc0b8f51aa33e90.tar.bz2 libdbpp-sqlite-35382065da97e8e98c3883caebc0b8f51aa33e90.tar.xz libdbpp-sqlite-35382065da97e8e98c3883caebc0b8f51aa33e90.zip |
SQLite mocking and tests from Project2
Diffstat (limited to 'libsqlitepp/mock.cpp')
-rw-r--r-- | libsqlitepp/mock.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libsqlitepp/mock.cpp b/libsqlitepp/mock.cpp new file mode 100644 index 0000000..4748116 --- /dev/null +++ b/libsqlitepp/mock.cpp @@ -0,0 +1,39 @@ +#include "mock.h" +#include "connection.h" +#include <buffer.h> +#include <boost/filesystem/operations.hpp> + +namespace SQLite { + +Mock::Mock(const std::string & name, const std::vector<boost::filesystem::path> & ss) : + MockDatabase(name), + testDbPath(boost::filesystem::path("/tmp") / "sqliteut" / stringbf("%d", getpid()) / stringbf("%d", ++DB::MockDatabase::mocked)) +{ + CreateNewDatabase(); + PlaySchemaScripts(ss); +} + +DB::Connection * +Mock::openConnection() const +{ + return new Connection(testDbPath.string()); +} + +Mock::~Mock() +{ + DropDatabase(); +} + +void Mock::DropDatabase() const +{ + boost::filesystem::remove(testDbPath); +} + +void Mock::CreateNewDatabase() const +{ + boost::filesystem::create_directories(testDbPath.parent_path()); + delete openConnection(); +} + +} + |