summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2016-09-13 17:46:37 -0400
committerJason Wray <jason@mapbox.com>2016-09-14 15:48:53 -0400
commit9237ad3c5894ef1fd68e3a37505b12e2b4fad978 (patch)
tree94845ab291349d18e58feac2359044a231b1285b
parent83d0b39adbbdc5f86508cf2f3b036490d597ae82 (diff)
downloadqtlocation-mapboxgl-9237ad3c5894ef1fd68e3a37505b12e2b4fad978.tar.gz
[tests] Add v3 & v4 database migration tests
-rw-r--r--test/fixtures/offline_database/v3.dbbin0 -> 43008 bytes
-rw-r--r--test/fixtures/offline_database/v4.dbbin0 -> 43008 bytes
-rw-r--r--test/fixtures/offline_database/v4.db-shmbin0 -> 32768 bytes
-rw-r--r--test/fixtures/offline_database/v4.db-wal0
-rw-r--r--test/storage/offline_database.cpp58
5 files changed, 58 insertions, 0 deletions
diff --git a/test/fixtures/offline_database/v3.db b/test/fixtures/offline_database/v3.db
new file mode 100644
index 0000000000..eba0a351a7
--- /dev/null
+++ b/test/fixtures/offline_database/v3.db
Binary files differ
diff --git a/test/fixtures/offline_database/v4.db b/test/fixtures/offline_database/v4.db
new file mode 100644
index 0000000000..7d45956a2b
--- /dev/null
+++ b/test/fixtures/offline_database/v4.db
Binary files differ
diff --git a/test/fixtures/offline_database/v4.db-shm b/test/fixtures/offline_database/v4.db-shm
new file mode 100644
index 0000000000..43e73c0962
--- /dev/null
+++ b/test/fixtures/offline_database/v4.db-shm
Binary files differ
diff --git a/test/fixtures/offline_database/v4.db-wal b/test/fixtures/offline_database/v4.db-wal
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/fixtures/offline_database/v4.db-wal
diff --git a/test/storage/offline_database.cpp b/test/storage/offline_database.cpp
index 3ce42cdba0..656fc2878a 100644
--- a/test/storage/offline_database.cpp
+++ b/test/storage/offline_database.cpp
@@ -554,6 +554,20 @@ static int databaseUserVersion(const std::string& path) {
return stmt.get<int>(0);
}
+static std::string databaseJournalMode(const std::string& path) {
+ mapbox::sqlite::Database db(path, mapbox::sqlite::ReadOnly);
+ mapbox::sqlite::Statement stmt = db.prepare("pragma journal_mode");
+ stmt.run();
+ return stmt.get<std::string>(0);
+}
+
+static int databaseSyncMode(const std::string& path) {
+ mapbox::sqlite::Database db(path, mapbox::sqlite::ReadOnly);
+ mapbox::sqlite::Statement stmt = db.prepare("pragma synchronous");
+ stmt.run();
+ return stmt.get<int>(0);
+}
+
TEST(OfflineDatabase, MigrateFromV2Schema) {
using namespace mbgl;
@@ -574,3 +588,47 @@ TEST(OfflineDatabase, MigrateFromV2Schema) {
EXPECT_LT(databasePageCount("test/fixtures/offline_database/v5.db"),
databasePageCount("test/fixtures/offline_database/v2.db"));
}
+
+TEST(OfflineDatabase, MigrateFromV3Schema) {
+ using namespace mbgl;
+
+ // v3.db is a v3 database, migrated from v2.
+
+ deleteFile("test/fixtures/offline_database/v5.db");
+ writeFile("test/fixtures/offline_database/v5.db", util::read_file("test/fixtures/offline_database/v3.db"));
+
+ {
+ OfflineDatabase db("test/fixtures/offline_database/v5.db", 0);
+ auto regions = db.listRegions();
+ for (auto& region : regions) {
+ db.deleteRegion(std::move(region));
+ }
+ }
+
+ EXPECT_EQ(5, databaseUserVersion("test/fixtures/offline_database/v5.db"));
+}
+
+TEST(OfflineDatabase, MigrateFromV4Schema) {
+ using namespace mbgl;
+
+ // v4.db is a v4 database, migrated from v2 & v3. This database used `journal_mode = WAL` and `synchronous = NORMAL`.
+
+ deleteFile("test/fixtures/offline_database/v5.db");
+ writeFile("test/fixtures/offline_database/v5.db", util::read_file("test/fixtures/offline_database/v4.db"));
+
+ {
+ OfflineDatabase db("test/fixtures/offline_database/v5.db", 0);
+ auto regions = db.listRegions();
+ for (auto& region : regions) {
+ db.deleteRegion(std::move(region));
+ }
+ }
+
+ EXPECT_EQ(5, databaseUserVersion("test/fixtures/offline_database/v5.db"));
+
+ // Journal mode should be DELETE after migration to v5.
+ EXPECT_EQ("delete", databaseJournalMode("test/fixtures/offline_database/v5.db"));
+
+ // Synchronous setting should be FULL (2) after migration to v5.
+ EXPECT_EQ(2, databaseSyncMode("test/fixtures/offline_database/v5.db"));
+}