summaryrefslogtreecommitdiff
path: root/libsqlitepp/sqlite-mock.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-24 04:13:24 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-24 04:13:24 +0000
commit5dd91c7b80443c1f0e747088159c4d8b78d1856d (patch)
tree226331b6026e722f6a69765963ff19a9436155c1 /libsqlitepp/sqlite-mock.cpp
parentUse parent glibmm (diff)
downloadlibdbpp-sqlite-5dd91c7b80443c1f0e747088159c4d8b78d1856d.tar.bz2
libdbpp-sqlite-5dd91c7b80443c1f0e747088159c4d8b78d1856d.tar.xz
libdbpp-sqlite-5dd91c7b80443c1f0e747088159c4d8b78d1856d.zip
SQLite files prefixed with sqlite-
Diffstat (limited to 'libsqlitepp/sqlite-mock.cpp')
-rw-r--r--libsqlitepp/sqlite-mock.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/libsqlitepp/sqlite-mock.cpp b/libsqlitepp/sqlite-mock.cpp
new file mode 100644
index 0000000..2f0958d
--- /dev/null
+++ b/libsqlitepp/sqlite-mock.cpp
@@ -0,0 +1,39 @@
+#include "sqlite-mock.h"
+#include "sqlite-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();
+}
+
+}
+