diff options
author | Jason Wray <jason@mapbox.com> | 2016-09-13 17:46:37 -0400 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2016-09-14 15:48:53 -0400 |
commit | 9237ad3c5894ef1fd68e3a37505b12e2b4fad978 (patch) | |
tree | 94845ab291349d18e58feac2359044a231b1285b | |
parent | 83d0b39adbbdc5f86508cf2f3b036490d597ae82 (diff) | |
download | qtlocation-mapboxgl-9237ad3c5894ef1fd68e3a37505b12e2b4fad978.tar.gz |
[tests] Add v3 & v4 database migration tests
-rw-r--r-- | test/fixtures/offline_database/v3.db | bin | 0 -> 43008 bytes | |||
-rw-r--r-- | test/fixtures/offline_database/v4.db | bin | 0 -> 43008 bytes | |||
-rw-r--r-- | test/fixtures/offline_database/v4.db-shm | bin | 0 -> 32768 bytes | |||
-rw-r--r-- | test/fixtures/offline_database/v4.db-wal | 0 | ||||
-rw-r--r-- | test/storage/offline_database.cpp | 58 |
5 files changed, 58 insertions, 0 deletions
diff --git a/test/fixtures/offline_database/v3.db b/test/fixtures/offline_database/v3.db Binary files differnew file mode 100644 index 0000000000..eba0a351a7 --- /dev/null +++ b/test/fixtures/offline_database/v3.db diff --git a/test/fixtures/offline_database/v4.db b/test/fixtures/offline_database/v4.db Binary files differnew file mode 100644 index 0000000000..7d45956a2b --- /dev/null +++ b/test/fixtures/offline_database/v4.db diff --git a/test/fixtures/offline_database/v4.db-shm b/test/fixtures/offline_database/v4.db-shm Binary files differnew file mode 100644 index 0000000000..43e73c0962 --- /dev/null +++ b/test/fixtures/offline_database/v4.db-shm 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")); +} |