summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/storage/offline_database.test.cpp51
1 files changed, 39 insertions, 12 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp
index a0adbb4207..fc1efc1a31 100644
--- a/test/storage/offline_database.test.cpp
+++ b/test/storage/offline_database.test.cpp
@@ -517,23 +517,46 @@ TEST(OfflineDatabase, GetRegionDefinition) {
TEST(OfflineDatabase, DeleteRegion) {
FixtureLog log;
- OfflineDatabase db(":memory:");
- OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true };
- OfflineRegionMetadata metadata {{ 1, 2, 3 }};
- auto region = db.createRegion(definition, metadata);
- ASSERT_TRUE(region);
+ deleteDatabaseFiles();
- Response response;
- response.noContent = true;
+ {
+ OfflineDatabase dbCreate(filename);
+ }
- db.putRegionResource(region->getID(), Resource::style("http://example.com/"), response);
- db.putRegionResource(region->getID(), Resource::tile("http://example.com/", 1.0, 0, 0, 0, Tileset::Scheme::XYZ), response);
+ size_t initialSize = util::read_file(filename).size();
- db.deleteRegion(std::move(*region));
+ {
+ Response response;
+ response.data = randomString(.5 * 1024 * 1024);
- auto regions = db.listRegions().value();
- ASSERT_EQ(0u, regions.size());
+ OfflineDatabase db(filename);
+ OfflineTilePyramidRegionDefinition definition{ "mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true };
+ OfflineRegionMetadata metadata{{ 1, 2, 3 }};
+
+ auto region = db.createRegion(definition, metadata);
+
+ for (unsigned i = 0; i < 100; ++i) {
+ const Resource tile = Resource::tile("mapbox://tile_" + std::to_string(i), 1, 0, 0, 0, Tileset::Scheme::XYZ);
+ db.putRegionResource(region->getID(), tile, response);
+ }
+
+ db.deleteRegion(std::move(*region));
+
+ auto regions = db.listRegions().value();
+ ASSERT_EQ(0u, regions.size());
+
+ // The tiles from the offline region will migrate to the
+ // ambient cache and shrink the database to the maximum
+ // size defined by default.
+ EXPECT_LE(util::read_file(filename).size(), util::DEFAULT_MAX_CACHE_SIZE);
+
+ // After clearing the cache, the size of the database
+ // should get back to the original size.
+ db.clearTileCache();
+ }
+
+ EXPECT_EQ(initialSize, util::read_file(filename).size());
EXPECT_EQ(0u, log.uncheckedCount());
}
@@ -668,6 +691,10 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) {
for (auto i = 0; i < 100; i++) {
db2.put(fixture::resource, fixture::response);
EXPECT_TRUE(bool(db2.get(fixture::resource)));
+
+ if (i == 50) {
+ db2.clearTileCache();
+ }
}
});