summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTore Halset <halset@pvv.ntnu.no>2016-10-17 18:27:07 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-10-17 09:27:07 -0700
commita4b79ac2892770456b03692c08f619bcc173c597 (patch)
tree11676e523b07156198fa78bdc518548d04a21b86 /test
parent76ed537be59482ac22b19e1e116388aea8c7742b (diff)
downloadqtlocation-mapboxgl-a4b79ac2892770456b03692c08f619bcc173c597.tar.gz
[core] Optimize OfflineDownload::ensureResource (#6707)
Add `OfflineDatabase::hasRegionResource`, for use when the actual contents are not needed by the caller, avoiding IO and decompression costs.
Diffstat (limited to 'test')
-rw-r--r--test/storage/offline_database.test.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp
index bcc9784b35..2e25835d80 100644
--- a/test/storage/offline_database.test.cpp
+++ b/test/storage/offline_database.test.cpp
@@ -496,6 +496,59 @@ TEST(OfflineDatabase, GetRegionCompletedStatus) {
EXPECT_EQ(tileSize, status3.completedTileSize);
}
+TEST(OfflineDatabase, HasRegionResource) {
+ using namespace mbgl;
+
+ OfflineDatabase db(":memory:", 1024 * 100);
+ OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 };
+ OfflineRegion region = db.createRegion(definition, OfflineRegionMetadata());
+
+ EXPECT_FALSE(bool(db.hasRegionResource(region.getID(), Resource::style("http://example.com/1"))));
+ EXPECT_FALSE(bool(db.hasRegionResource(region.getID(), Resource::style("http://example.com/20"))));
+
+ Response response;
+ response.data = randomString(1024);
+
+ for (uint32_t i = 1; i <= 100; i++) {
+ db.putRegionResource(region.getID(), Resource::style("http://example.com/"s + util::toString(i)), response);
+ }
+
+ EXPECT_TRUE(bool(db.hasRegionResource(region.getID(), Resource::style("http://example.com/1"))));
+ EXPECT_TRUE(bool(db.hasRegionResource(region.getID(), Resource::style("http://example.com/20"))));
+ EXPECT_EQ(1024, *(db.hasRegionResource(region.getID(), Resource::style("http://example.com/20"))));
+}
+
+TEST(OfflineDatabase, HasRegionResourceTile) {
+ using namespace mbgl;
+
+ OfflineDatabase db(":memory:", 1024 * 100);
+ OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 };
+ OfflineRegion region = db.createRegion(definition, OfflineRegionMetadata());
+
+ Resource resource { Resource::Tile, "http://example.com/" };
+ resource.tileData = Resource::TileData {
+ "http://example.com/",
+ 1,
+ 0,
+ 0,
+ 0
+ };
+ Response response;
+
+ response.data = std::make_shared<std::string>("first");
+
+ EXPECT_FALSE(bool(db.hasRegionResource(region.getID(), resource)));
+ db.putRegionResource(region.getID(), resource, response);
+ EXPECT_TRUE(bool(db.hasRegionResource(region.getID(), resource)));
+ EXPECT_EQ(5, *(db.hasRegionResource(region.getID(), resource)));
+
+ OfflineRegion anotherRegion = db.createRegion(definition, OfflineRegionMetadata());
+ EXPECT_LT(region.getID(), anotherRegion.getID());
+ EXPECT_TRUE(bool(db.hasRegionResource(anotherRegion.getID(), resource)));
+ EXPECT_EQ(5, *(db.hasRegionResource(anotherRegion.getID(), resource)));
+
+}
+
TEST(OfflineDatabase, OfflineMapboxTileCount) {
using namespace mbgl;