From 35382065da97e8e98c3883caebc0b8f51aa33e90 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 24 Sep 2015 03:05:12 +0100 Subject: SQLite mocking and tests from Project2 --- libsqlitepp/mock.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 libsqlitepp/mock.cpp (limited to 'libsqlitepp/mock.cpp') 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 +#include + +namespace SQLite { + +Mock::Mock(const std::string & name, const std::vector & 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(); +} + +} + -- cgit v1.2.3