diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2018-03-23 15:44:21 +0200 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2018-08-20 22:49:01 +0300 |
commit | fae099933b23a36176dcc8c4a91c37816fa9b7fe (patch) | |
tree | c1a57fb87405cd341c2dc8e5b5bffc9b4b08cc7f /test | |
parent | cf0313f21919b0df4840d3085d9db3fe4b6bbbec (diff) | |
download | qtlocation-mapboxgl-fae099933b23a36176dcc8c4a91c37816fa9b7fe.tar.gz |
[core] offline region definition - add support for arbitrary geometries
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/offline.test.cpp | 74 | ||||
-rw-r--r-- | test/storage/offline_database.test.cpp | 96 | ||||
-rw-r--r-- | test/storage/offline_download.test.cpp | 2 |
3 files changed, 81 insertions, 91 deletions
diff --git a/test/storage/offline.test.cpp b/test/storage/offline.test.cpp index 59aebebaba..90f9570320 100644 --- a/test/storage/offline.test.cpp +++ b/test/storage/offline.test.cpp @@ -6,58 +6,30 @@ using namespace mbgl; using SourceType = mbgl::style::SourceType; -static const LatLngBounds sanFrancisco = - LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 }); -static const LatLngBounds sanFranciscoWrapped = - LatLngBounds::hull({ 37.6609, 238.5744 }, { 37.8271, 238.3204 }); - -TEST(OfflineTilePyramidRegionDefinition, TileCoverEmpty) { - OfflineTilePyramidRegionDefinition region("", LatLngBounds::empty(), 0, 20, 1.0); - - EXPECT_EQ((std::vector<CanonicalTileID>{}), region.tileCover(SourceType::Vector, 512, { 0, 22 })); -} - -TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomIntersection) { - OfflineTilePyramidRegionDefinition region("", sanFrancisco, 2, 2, 1.0); - - EXPECT_EQ((std::vector<CanonicalTileID>{ { 2, 0, 1 } }), - region.tileCover(SourceType::Vector, 512, { 0, 22 })); - - EXPECT_EQ((std::vector<CanonicalTileID>{}), region.tileCover(SourceType::Vector, 512, { 3, 22 })); -} - -TEST(OfflineTilePyramidRegionDefinition, TileCoverTileSize) { - OfflineTilePyramidRegionDefinition region("", LatLngBounds::world(), 0, 0, 1.0); - - EXPECT_EQ((std::vector<CanonicalTileID>{ { 0, 0, 0 } }), - region.tileCover(SourceType::Vector, 512, { 0, 22 })); - - EXPECT_EQ((std::vector<CanonicalTileID>{ { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 } }), - region.tileCover(SourceType::Vector, 256, { 0, 22 })); -} - -TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomRounding) { - OfflineTilePyramidRegionDefinition region("", sanFrancisco, 0.6, 0.7, 1.0); - - EXPECT_EQ((std::vector<CanonicalTileID>{ { 0, 0, 0 } }), - region.tileCover(SourceType::Vector, 512, { 0, 22 })); - - EXPECT_EQ((std::vector<CanonicalTileID>{ { 1, 0, 0 } }), - region.tileCover(SourceType::Raster, 512, { 0, 22 })); +TEST(OfflineTilePyramidRegionDefinition, EncodeDecode) { + OfflineTilePyramidRegionDefinition region("mapbox://style", LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 }), 0, 20, 1.0); + + auto encoded = encodeOfflineRegionDefinition(region); + auto decoded = decodeOfflineRegionDefinition(encoded).get<OfflineTilePyramidRegionDefinition>(); + + EXPECT_EQ(decoded.styleURL, region.styleURL); + EXPECT_EQ(decoded.minZoom, region.minZoom); + EXPECT_EQ(decoded.maxZoom, region.maxZoom); + EXPECT_EQ(decoded.pixelRatio, region.pixelRatio); + EXPECT_EQ(decoded.bounds.southwest(), region.bounds.southwest()); + EXPECT_EQ(decoded.bounds.northeast(), region.bounds.northeast()); } -TEST(OfflineTilePyramidRegionDefinition, TileCoverWrapped) { - OfflineTilePyramidRegionDefinition region("", sanFranciscoWrapped, 0, 0, 1.0); - - EXPECT_EQ((std::vector<CanonicalTileID>{ { 0, 0, 0 } }), - region.tileCover(SourceType::Vector, 512, { 0, 22 })); -} - -TEST(OfflineTilePyramidRegionDefinition, TileCount) { - OfflineTilePyramidRegionDefinition region("", sanFranciscoWrapped, 0, 22, 1.0); - - //These numbers match the count from tileCover().size(). - EXPECT_EQ(38424u, region.tileCount(SourceType::Vector, 512, { 10, 18 })); - EXPECT_EQ(9675240u, region.tileCount(SourceType::Vector, 512, { 3, 22 })); +TEST(OfflineGeometryRegionDefinition, EncodeDecode) { + OfflineGeometryRegionDefinition region("mapbox://style", Point<double>(-122.5744, 37.6609), 0, 2, 1.0); + + auto encoded = encodeOfflineRegionDefinition(region); + auto decoded = decodeOfflineRegionDefinition(encoded).get<OfflineGeometryRegionDefinition>(); + + EXPECT_EQ(decoded.styleURL, region.styleURL); + EXPECT_EQ(decoded.minZoom, region.minZoom); + EXPECT_EQ(decoded.maxZoom, region.maxZoom); + EXPECT_EQ(decoded.pixelRatio, region.pixelRatio); + EXPECT_EQ(decoded.geometry, region.geometry); } diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 346cd6da80..2ed72e0d8c 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -411,25 +411,31 @@ TEST(OfflineDatabase, PutTileNotFound) { TEST(OfflineDatabase, CreateRegion) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); - EXPECT_EQ(definition.styleURL, region->getDefinition().styleURL); - EXPECT_EQ(definition.bounds, region->getDefinition().bounds); - EXPECT_EQ(definition.minZoom, region->getDefinition().minZoom); - EXPECT_EQ(definition.maxZoom, region->getDefinition().maxZoom); - EXPECT_EQ(definition.pixelRatio, region->getDefinition().pixelRatio); - EXPECT_EQ(metadata, region->getMetadata()); - EXPECT_EQ(0u, log.uncheckedCount()); + + region->getDefinition().match( + [&](OfflineTilePyramidRegionDefinition& def) { + EXPECT_EQ(definition.styleURL, def.styleURL); + EXPECT_EQ(definition.bounds, def.bounds); + EXPECT_EQ(definition.minZoom, def.minZoom); + EXPECT_EQ(definition.maxZoom, def.maxZoom); + EXPECT_EQ(definition.pixelRatio, def.pixelRatio); + }, [](auto&) { + EXPECT_FALSE(false); + } + ); + EXPECT_EQ(metadata, region->getMetadata()); } TEST(OfflineDatabase, UpdateMetadata) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); @@ -445,7 +451,7 @@ TEST(OfflineDatabase, UpdateMetadata) { TEST(OfflineDatabase, ListRegions) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); @@ -453,12 +459,19 @@ TEST(OfflineDatabase, ListRegions) { auto regions = db.listRegions().value(); ASSERT_EQ(1u, regions.size()); + EXPECT_EQ(region->getID(), regions.at(0).getID()); - EXPECT_EQ(definition.styleURL, regions.at(0).getDefinition().styleURL); - EXPECT_EQ(definition.bounds, regions.at(0).getDefinition().bounds); - EXPECT_EQ(definition.minZoom, regions.at(0).getDefinition().minZoom); - EXPECT_EQ(definition.maxZoom, regions.at(0).getDefinition().maxZoom); - EXPECT_EQ(definition.pixelRatio, regions.at(0).getDefinition().pixelRatio); + regions.at(0).getDefinition().match( + [&](OfflineTilePyramidRegionDefinition& def) { + EXPECT_EQ(definition.styleURL, def.styleURL); + EXPECT_EQ(definition.bounds, def.bounds); + EXPECT_EQ(definition.minZoom, def.minZoom); + EXPECT_EQ(definition.maxZoom, def.maxZoom); + EXPECT_EQ(definition.pixelRatio, def.pixelRatio); + }, + [&](auto&) { + EXPECT_FALSE(false); + }); EXPECT_EQ(metadata, regions.at(0).getMetadata()); EXPECT_EQ(0u, log.uncheckedCount()); @@ -467,27 +480,30 @@ TEST(OfflineDatabase, ListRegions) { TEST(OfflineDatabase, GetRegionDefinition) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; - auto region = db.createRegion(definition, metadata); - ASSERT_TRUE(region); - auto result = db.getRegionDefinition(region->getID()); - ASSERT_TRUE(result); - - EXPECT_EQ(definition.styleURL, result->styleURL); - EXPECT_EQ(definition.bounds, result->bounds); - EXPECT_EQ(definition.minZoom, result->minZoom); - EXPECT_EQ(definition.maxZoom, result->maxZoom); - EXPECT_EQ(definition.pixelRatio, result->pixelRatio); - EXPECT_EQ(0u, log.uncheckedCount()); + + auto region = db.createRegion(definition, metadata); + db.getRegionDefinition(region->getID())->match( + [&](OfflineTilePyramidRegionDefinition& result) { + EXPECT_EQ(definition.styleURL, result.styleURL); + EXPECT_EQ(definition.bounds, result.bounds); + EXPECT_EQ(definition.minZoom, result.minZoom); + EXPECT_EQ(definition.maxZoom, result.maxZoom); + EXPECT_EQ(definition.pixelRatio, result.pixelRatio); + }, + [&](auto&) { + EXPECT_FALSE(false); + } + ); } TEST(OfflineDatabase, DeleteRegion) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata {{ 1, 2, 3 }}; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); @@ -509,15 +525,17 @@ TEST(OfflineDatabase, DeleteRegion) { TEST(OfflineDatabase, CreateRegionInfiniteMaxZoom) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; OfflineRegionMetadata metadata; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); - EXPECT_EQ(0, region->getDefinition().minZoom); - EXPECT_EQ(INFINITY, region->getDefinition().maxZoom); - EXPECT_EQ(0u, log.uncheckedCount()); + + region->getDefinition().match([&](auto& def) { + EXPECT_EQ(0, def.minZoom); + EXPECT_EQ(INFINITY, def.maxZoom); + }); } TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) { @@ -600,7 +618,7 @@ TEST(OfflineDatabase, PutEvictsLeastRecentlyUsedResources) { TEST(OfflineDatabase, PutRegionResourceDoesNotEvict) { FixtureLog log; OfflineDatabase db(":memory:", 1024 * 100); - OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -637,7 +655,7 @@ TEST(OfflineDatabase, PutFailsWhenEvictionInsuffices) { TEST(OfflineDatabase, GetRegionCompletedStatus) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata; auto region = db.createRegion(definition, metadata); ASSERT_TRUE(region); @@ -676,7 +694,7 @@ TEST(OfflineDatabase, GetRegionCompletedStatus) { TEST(OfflineDatabase, HasRegionResource) { FixtureLog log; OfflineDatabase db(":memory:", 1024 * 100); - OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -700,7 +718,7 @@ TEST(OfflineDatabase, HasRegionResource) { TEST(OfflineDatabase, HasRegionResourceTile) { FixtureLog log; OfflineDatabase db(":memory:", 1024 * 100); - OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -734,7 +752,7 @@ TEST(OfflineDatabase, HasRegionResourceTile) { TEST(OfflineDatabase, OfflineMapboxTileCount) { FixtureLog log; OfflineDatabase db(":memory:"); - OfflineRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; + OfflineTilePyramidRegionDefinition definition { "http://example.com/style", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 2.0 }; OfflineRegionMetadata metadata; auto region1 = db.createRegion(definition, metadata); @@ -795,7 +813,7 @@ TEST(OfflineDatabase, OfflineMapboxTileCount) { TEST(OfflineDatabase, BatchInsertion) { FixtureLog log; OfflineDatabase db(":memory:", 1024 * 100); - OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); @@ -821,7 +839,7 @@ TEST(OfflineDatabase, BatchInsertionMapboxTileCountExceeded) { FixtureLog log; OfflineDatabase db(":memory:", 1024 * 100); db.setOfflineMapboxTileCountLimit(1); - OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; auto region = db.createRegion(definition, OfflineRegionMetadata()); ASSERT_TRUE(region); diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp index 93b4dd623a..492e68e869 100644 --- a/test/storage/offline_download.test.cpp +++ b/test/storage/offline_download.test.cpp @@ -66,7 +66,7 @@ public: std::size_t size = 0; auto createRegion() { - OfflineRegionDefinition definition { "", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 1.0 }; + OfflineTilePyramidRegionDefinition definition { "", LatLngBounds::hull({1, 2}, {3, 4}), 5, 6, 1.0 }; OfflineRegionMetadata metadata; return db.createRegion(definition, metadata); } |