summaryrefslogtreecommitdiff
path: root/libsqlitepp/sqlite-mock.cpp
blob: 2f0958d7dbb8893e60c87da0269e82de519d357c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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();
}

}