summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-01-05 06:35:31 -0800
committerGitHub <noreply@github.com>2018-01-05 06:35:31 -0800
commit10a44050f485a18f8dd6523aca6a7a9f82f7afc7 (patch)
treefea7f30e35b3228b5989250ff9db225e12bd10ed /test
parentbfa4cea24c2ab3973f845fda6da6d4a9e8f03e56 (diff)
downloadqtlocation-mapboxgl-10a44050f485a18f8dd6523aca6a7a9f82f7afc7.tar.gz
Support TileJSON bounds property (#10701)
* [core] Parse TileJSON bounds property * [core] Add TileRange and LatLngBounds::contains(CanonicalTileID) Move LatLngBounds::contains impl to cpp file * [core] Skip tile creation outside of tileset bounds * [core] Fix TileRange for wrapped bounds and use for CustomTileLoader instead of LatLngBounds comparisons for tiles.
Diffstat (limited to 'test')
-rw-r--r--test/style/conversion/tileset.test.cpp72
-rw-r--r--test/util/tile_range.test.cpp56
2 files changed, 128 insertions, 0 deletions
diff --git a/test/style/conversion/tileset.test.cpp b/test/style/conversion/tileset.test.cpp
new file mode 100644
index 0000000000..8002cd038f
--- /dev/null
+++ b/test/style/conversion/tileset.test.cpp
@@ -0,0 +1,72 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/conversion/json.hpp>
+#include <mbgl/style/conversion/tileset.hpp>
+
+#include <mbgl/util/logging.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style::conversion;
+
+TEST(Tileset, Empty) {
+ Error error;
+ mbgl::optional<Tileset> converted = convertJSON<Tileset>("{}", error);
+ EXPECT_FALSE((bool) converted);
+}
+
+TEST(Tileset, ErrorHandling) {
+ Error error;
+ mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
+ "tiles": "should not be a string"
+ })JSON", error);
+ EXPECT_FALSE((bool) converted);
+}
+
+TEST(Tileset, InvalidBounds) {
+ {
+ Error error;
+ mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
+ "tiles": ["http://mytiles"],
+ "bounds": [73, -180, -73, -120]
+ })JSON", error);
+
+ EXPECT_FALSE((bool) converted);
+ }
+ {
+ Error error;
+ mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
+ "tiles": ["http://mytiles"],
+ "bounds": [-120]
+ })JSON", error);
+
+ EXPECT_FALSE((bool) converted);
+ }
+ {
+ Error error;
+ mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
+ "tiles": ["http://mytiles"],
+ "bounds": "should not be a string"
+ })JSON", error);
+
+ EXPECT_FALSE((bool) converted);
+ }
+}
+
+TEST(Tileset, FullConversion) {
+ Error error;
+ Tileset converted = *convertJSON<Tileset>(R"JSON({
+ "tiles": ["http://mytiles"],
+ "scheme": "xyz",
+ "minzoom": 1,
+ "maxzoom": 2,
+ "attribution": "mapbox",
+ "bounds": [-180, -73, -120, 73]
+ })JSON", error);
+
+ EXPECT_EQ(converted.tiles[0], "http://mytiles");
+ EXPECT_EQ(converted.scheme, Tileset::Scheme::XYZ);
+ EXPECT_EQ(converted.zoomRange.min, 1);
+ EXPECT_EQ(converted.zoomRange.max, 2);
+ EXPECT_EQ(converted.attribution, "mapbox");
+ EXPECT_EQ(converted.bounds, LatLngBounds::hull({73, -180}, {-73, -120}));
+}
diff --git a/test/util/tile_range.test.cpp b/test/util/tile_range.test.cpp
new file mode 100644
index 0000000000..dc8ae28705
--- /dev/null
+++ b/test/util/tile_range.test.cpp
@@ -0,0 +1,56 @@
+
+#include <mbgl/util/tile_range.hpp>
+#include <mbgl/util/geo.hpp>
+#include <mbgl/map/transform.hpp>
+
+#include <gtest/gtest.h>
+
+using namespace mbgl;
+
+TEST(TileRange, ContainsWorld) {
+ auto range = util::TileRange::fromLatLngBounds(LatLngBounds::world(), 0);
+ EXPECT_TRUE(range.contains(CanonicalTileID(0, 0, 0)));
+ EXPECT_FALSE(range.contains(CanonicalTileID(10, 0, 0)));
+}
+
+TEST(TileRange, ContainsBoundsFromTile) {
+ {
+ const LatLngBounds bounds{ CanonicalTileID(3, 7, 0) };
+ auto range = util::TileRange::fromLatLngBounds(bounds, 3);
+ EXPECT_TRUE(range.contains(CanonicalTileID(3, 7, 0)));
+ }
+ {
+ const LatLngBounds bounds{ CanonicalTileID(10, 162, 395) };
+ auto range = util::TileRange::fromLatLngBounds(bounds, 10);
+ EXPECT_TRUE(range.contains(CanonicalTileID(10, 162, 395)));
+ }
+}
+TEST(TileRange, ContainsIntersectingTiles) {
+ auto bounds = LatLngBounds::hull({ 37.6609, -122.5744 }, { 37.8271, -122.3204 });
+ auto range = util::TileRange::fromLatLngBounds(bounds, 13);
+ EXPECT_FALSE(range.contains(CanonicalTileID(13, 1316, 3100)));
+ EXPECT_TRUE(range.contains(CanonicalTileID(13, 1310, 3166)));
+}
+
+TEST(TileRange, ContainsWrappedBounds) {
+ auto wrappedBounds = LatLngBounds::hull({ 37.6609, 237.6796 }, { 37.8271, 237.4256 });
+ auto range = util::TileRange::fromLatLngBounds(wrappedBounds, 13);
+ EXPECT_FALSE(range.contains(CanonicalTileID(13, 1316, 3100)));
+ EXPECT_TRUE(range.contains(CanonicalTileID(13, 1310, 3166)));
+}
+
+TEST(TileRange, ContainsBoundsCrossingAntimeridian) {
+ {
+ auto cossingBounds = LatLngBounds::hull({-20.9615, -214.309}, {19.477, -155.830});
+ auto range = util::TileRange::fromLatLngBounds(cossingBounds, 1);
+ EXPECT_TRUE(range.contains(CanonicalTileID(1, 1, 1)));
+ EXPECT_TRUE(range.contains(CanonicalTileID(1, 0, 0)));
+ }
+ {
+ auto cossingBounds = LatLngBounds::hull({-20.9615, -214.309}, {19.477, -155.830});
+ auto range = util::TileRange::fromLatLngBounds(cossingBounds, 6);
+ EXPECT_FALSE(range.contains(CanonicalTileID(6, 55, 34)));
+ EXPECT_FALSE(range.contains(CanonicalTileID(6, 5, 28)));
+ EXPECT_TRUE(range.contains(CanonicalTileID(6, 63, 28)));
+ }
+}