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/storage/offline.test.cpp | |
parent | cf0313f21919b0df4840d3085d9db3fe4b6bbbec (diff) | |
download | qtlocation-mapboxgl-fae099933b23a36176dcc8c4a91c37816fa9b7fe.tar.gz |
[core] offline region definition - add support for arbitrary geometries
Diffstat (limited to 'test/storage/offline.test.cpp')
-rw-r--r-- | test/storage/offline.test.cpp | 74 |
1 files changed, 23 insertions, 51 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); } |