diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-11-25 14:44:46 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-12-09 14:59:24 +0200 |
commit | 46a39632b5a7712561d6b58184425f98d59b184b (patch) | |
tree | 50890ba267541cbab96ab24ccd6aff7ed4555ed3 | |
parent | 7c3175523a7e4ab3f9ad28a587d6256c687bc0db (diff) |
[core] Add OfflineDatabase.Pack unit test
-rw-r--r-- | include/mbgl/storage/default_file_source.hpp | 6 | ||||
-rw-r--r-- | test/storage/offline_database.test.cpp | 30 |
2 files changed, 33 insertions, 3 deletions
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index 0a06934a3..4937524e3 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -200,7 +200,7 @@ public: * Sets whether packing the database file occurs automatically after an offline * region is deleted (deleteOfflineRegion()) or the ambient cache is cleared * (clearAmbientCache()). - * + * * By default, packing is enabled. If disabled, disk space will not be freed * after resources are removed unless packDatabase() is explicitly called. */ @@ -223,8 +223,8 @@ public: /* * Erase resources from the ambient cache, freeing storage space. * - * Erases the ambient cache, freeing resources. - * + * Erases the ambient cache, freeing resources. + * * Note that this operation can be potentially slow if packing the database * occurs automatically (see runPackDatabaseAutomatically() and packDatabase()). * diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index e9164e7c6..ef7ad257d 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -733,6 +733,36 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DeleteRegion)) { EXPECT_EQ(0u, log.uncheckedCount()); } +TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Pack)) { + FixtureLog log; + deleteDatabaseFiles(); + + OfflineDatabase db(filename); + size_t initialSize = util::read_file(filename).size(); + db.runPackDatabaseAutomatically(false); + + Response response; + response.data = randomString(.5 * 1024 * 1024); + + for (unsigned i = 0; i < 50; ++i) { + const Resource tile = Resource::tile("mapbox://tile_" + std::to_string(i), 1, 0, 0, 0, Tileset::Scheme::XYZ); + db.put(tile, response); + + const Resource style = Resource::style("mapbox://style_" + std::to_string(i)); + db.put(style, response); + } + size_t populatedSize = util::read_file(filename).size(); + ASSERT_GT(populatedSize, initialSize); + + db.clearAmbientCache(); + EXPECT_EQ(populatedSize, util::read_file(filename).size()); + EXPECT_EQ(0u, log.uncheckedCount()); + + db.pack(); + EXPECT_EQ(initialSize, util::read_file(filename).size()); + EXPECT_EQ(0u, log.uncheckedCount()); +} + TEST(OfflineDatabase, MapboxTileLimitExceeded) { FixtureLog log; |