summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-25 14:44:46 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-12-02 13:46:51 +0200
commit6d4e5f57ec68751ca5857d72f444331f3674733e (patch)
treeaf0225f44a202ea37139dfe63c7bf9c8af84f995
parent4c49f0c9db68fe998e83ac7a0f3d095c3d2ffed1 (diff)
downloadqtlocation-mapboxgl-6d4e5f57ec68751ca5857d72f444331f3674733e.tar.gz
[core] Add OfflineDatabase.Pack unit test
-rw-r--r--include/mbgl/storage/default_file_source.hpp6
-rw-r--r--test/storage/offline_database.test.cpp30
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 4ec72180d5..2942a25a85 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 e9164e7c66..ef7ad257d7 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;