summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-06-07 15:05:32 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-06-12 17:41:16 +0200
commit4477dd41198ac827781a6bbf50aeb0b1d3a66a45 (patch)
tree0e24918a8bafa9acf982d5a28b3a01bbd50d14b7 /test
parenta50493ea511989d0b040f24780964d532f1f4ee3 (diff)
downloadqtlocation-mapboxgl-4477dd41198ac827781a6bbf50aeb0b1d3a66a45.tar.gz
[core] support moving Database object during a Transaction
Diffstat (limited to 'test')
-rw-r--r--test/storage/offline_database.test.cpp1
-rw-r--r--test/storage/sqlite.test.cpp31
2 files changed, 30 insertions, 2 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp
index cb75551e40..e54cd6813b 100644
--- a/test/storage/offline_database.test.cpp
+++ b/test/storage/offline_database.test.cpp
@@ -7,7 +7,6 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/string.hpp>
-#include <gtest/gtest.h>
#include <sqlite3.hpp>
#include <thread>
#include <random>
diff --git a/test/storage/sqlite.test.cpp b/test/storage/sqlite.test.cpp
index 553736a0b1..a7c9d95e9b 100644
--- a/test/storage/sqlite.test.cpp
+++ b/test/storage/sqlite.test.cpp
@@ -1,8 +1,10 @@
#include <mbgl/test/util.hpp>
+#include <mbgl/test/fixture_log_observer.hpp>
-#include <gtest/gtest.h>
#include <sqlite3.hpp>
+using namespace mbgl;
+
TEST(SQLite, Statement) {
using namespace mbgl;
@@ -29,9 +31,36 @@ TEST(SQLite, Statement) {
}
TEST(SQLite, TEST_REQUIRES_WRITE(TryOpen)) {
+ FixtureLog log;
+
// Should return a CANTOPEN exception when the database doesn't exist,
// make sure all the backends behave the same way.
auto result = mapbox::sqlite::Database::tryOpen("test/fixtures/offline_database/foobar123.db", mapbox::sqlite::ReadOnly);
ASSERT_TRUE(result.is<mapbox::sqlite::Exception>());
ASSERT_EQ(result.get<mapbox::sqlite::Exception>().code, mapbox::sqlite::ResultCode::CantOpen);
+
+#ifndef __QT__
+ // Only non-Qt platforms are setting a logger on the SQLite object.
+ EXPECT_EQ(1u, log.count({ EventSeverity::Info, Event::Database, static_cast<int64_t>(mapbox::sqlite::ResultCode::CantOpen), "cannot open file" }, true));
+ EXPECT_EQ(1u, log.count({ EventSeverity::Info, Event::Database, static_cast<int64_t>(mapbox::sqlite::ResultCode::CantOpen), "No such file or directory" }, true));
+#endif
+ EXPECT_EQ(0u, log.uncheckedCount());
+}
+
+TEST(SQLite, CloseDatabaseWithPendingTransaction) {
+ auto db = std::make_unique<mapbox::sqlite::Database>(mapbox::sqlite::Database::open(
+ ":memory:", mapbox::sqlite::ReadWrite | mapbox::sqlite::Create));
+ mapbox::sqlite::Transaction transaction(*db);
+ transaction.commit();
+}
+
+TEST(SQLite, CloseMovedDatabaseWithPendingTransaction) {
+ // Verifies that we can correctly commit a transaction even if we move the Database object to
+ // another address.
+ auto db1 = mapbox::sqlite::Database::open(":memory:",
+ mapbox::sqlite::ReadWrite | mapbox::sqlite::Create);
+ std::unique_ptr<mapbox::sqlite::Database> db2;
+ mapbox::sqlite::Transaction transaction(db1);
+ db2 = std::make_unique<mapbox::sqlite::Database>(std::move(db1));
+ transaction.commit();
}