summaryrefslogtreecommitdiff
path: root/test/storage
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-17 18:15:51 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-21 01:04:01 +0300
commit19f5686eb21c9499e5cc34d217308aa99f31c666 (patch)
treed2ca30fd5e62ff669a72439d7dae968af6149b1d /test/storage
parent1def782cf23736f06d0d6809ea0881f7913796b2 (diff)
downloadqtlocation-mapboxgl-19f5686eb21c9499e5cc34d217308aa99f31c666.tar.gz
[tests] Add unit tests for offline data invalidation
Diffstat (limited to 'test/storage')
-rw-r--r--test/storage/offline_database.test.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp
index 0351ef2531..a5de89d670 100644
--- a/test/storage/offline_database.test.cpp
+++ b/test/storage/offline_database.test.cpp
@@ -526,6 +526,73 @@ TEST(OfflineDatabase, DeleteRegion) {
EXPECT_EQ(0u, log.uncheckedCount());
}
+TEST(OfflineDatabase, Invalidate) {
+ using namespace std::chrono_literals;
+
+ FixtureLog log;
+ OfflineDatabase db(":memory:");
+
+ Response response;
+ response.noContent = true;
+ response.mustRevalidate = false;
+ response.expires = util::now() + 1h;
+
+ const Resource ambient = Resource::tile("mapbox://tile_ambient", 1, 0, 0, 0, Tileset::Scheme::XYZ);
+ db.put(ambient, response);
+
+ OfflineTilePyramidRegionDefinition definition { "mapbox://style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0, true };
+ OfflineRegionMetadata metadata {{ 1, 2, 3 }};
+
+ auto region1 = db.createRegion(definition, metadata);
+ const Resource offline1 = Resource::tile("mapbox://tile_offline_region1", 1.0, 0, 0, 0, Tileset::Scheme::XYZ);
+ db.putRegionResource(region1->getID(), offline1, response);
+
+ auto region2 = db.createRegion(definition, metadata);
+ const Resource offline2 = Resource::tile("mapbox://tile_offline_region2", 1.0, 0, 0, 0, Tileset::Scheme::XYZ);
+ db.putRegionResource(region2->getID(), offline2, response);
+
+ // Prior to invalidation, all tiles are usable.
+ EXPECT_TRUE(db.get(ambient)->isUsable());
+ EXPECT_TRUE(db.get(offline1)->isUsable());
+ EXPECT_TRUE(db.get(offline2)->isUsable());
+
+ // Invalidate a region will not invalidate ambient
+ // tiles or other regions.
+ EXPECT_TRUE(db.invalidateRegion(region1->getID()) == nullptr);
+
+ EXPECT_TRUE(db.get(ambient)->isUsable());
+ EXPECT_FALSE(db.get(offline1)->isUsable());
+ EXPECT_TRUE(db.get(offline2)->isUsable());
+
+ // Invalidate the ambient cache will not invalidate
+ // the regions that are still valid.
+ EXPECT_TRUE(db.invalidateTileCache() == nullptr);
+
+ EXPECT_FALSE(db.get(ambient)->isUsable());
+ EXPECT_FALSE(db.get(offline1)->isUsable());
+ EXPECT_TRUE(db.get(offline2)->isUsable());
+
+ // Sanity check.
+ EXPECT_TRUE(db.get(ambient)->expires < util::now());
+ EXPECT_TRUE(db.get(offline1)->expires < util::now());
+ EXPECT_TRUE(db.get(offline2)->expires > util::now());
+
+ EXPECT_TRUE(db.get(ambient)->mustRevalidate);
+ EXPECT_TRUE(db.get(offline1)->mustRevalidate);
+ EXPECT_FALSE(db.get(offline2)->mustRevalidate);
+
+ // Should not throw.
+ EXPECT_TRUE(db.invalidateRegion(region2->getID()) == nullptr);
+ EXPECT_TRUE(db.invalidateRegion(region2->getID()) == nullptr);
+ EXPECT_TRUE(db.invalidateRegion(123) == nullptr);
+
+ // Invalidate != delete.
+ auto regions = db.listRegions().value();
+ ASSERT_EQ(2u, regions.size());
+
+ EXPECT_EQ(0u, log.uncheckedCount());
+}
+
TEST(OfflineDatabase, CreateRegionInfiniteMaxZoom) {
FixtureLog log;
OfflineDatabase db(":memory:");