[test] Only use our SQLite3 wrapper in tests

This commit is contained in:
Bruno de Oliveira Abinader
2018-01-08 18:02:56 +02:00
parent 7f2f40fb8d
commit f86c1b7d0f
2 changed files with 2 additions and 47 deletions

View File

@@ -1,6 +1,5 @@
include(platform/qt/qt.cmake)
mason_use(sqlite VERSION 3.14.2)
mason_use(gtest VERSION 1.8.0${MASON_CXXABI_SUFFIX})
if(NOT WITH_QT_DECODERS)
@@ -81,8 +80,6 @@ macro(mbgl_platform_test)
PROPERTIES COMPILE_FLAGS -DWORK_DIRECTORY="${CMAKE_SOURCE_DIR}"
)
target_add_mason_package(mbgl-test PRIVATE sqlite)
target_link_libraries(mbgl-test
PRIVATE qmapboxgl
PRIVATE mbgl-filesource

View File

@@ -9,7 +9,6 @@
#include <gtest/gtest.h>
#include <sqlite3.hpp>
#include <sqlite3.h>
#include <thread>
#include <random>
@@ -39,45 +38,6 @@ void writeFile(const char* name, const std::string& data) {
mbgl::util::write_file(name, data);
}
class FileLock {
public:
FileLock(const std::string& path) {
const int err = sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, nullptr);
if (err != SQLITE_OK) {
throw std::runtime_error("Could not open db");
}
lock();
}
void lock() {
assert(!locked);
const int err = sqlite3_exec(db, "begin exclusive transaction", nullptr, nullptr, nullptr);
if (err != SQLITE_OK) {
throw std::runtime_error("Could not lock db");
}
locked = true;
}
void unlock() {
assert(locked);
const int err = sqlite3_exec(db, "commit", nullptr, nullptr, nullptr);
if (err != SQLITE_OK) {
throw std::runtime_error("Could not unlock db");
}
locked = false;
}
~FileLock() {
if (locked) {
unlock();
}
}
private:
sqlite3* db = nullptr;
bool locked = false;
};
} // namespace
TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Create)) {
@@ -102,10 +62,8 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(SchemaVersion)) {
std::string path("test/fixtures/offline_database/offline.db");
{
sqlite3* db = nullptr;
sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
sqlite3_exec(db, "PRAGMA user_version = 1", nullptr, nullptr, nullptr);
sqlite3_close_v2(db);
mapbox::sqlite::Database db(path, mapbox::sqlite::Create | mapbox::sqlite::ReadWrite);
db.exec("PRAGMA user_version = 1");
}
Log::setObserver(std::make_unique<FixtureLogObserver>());