From baaae99a03202641ae5b8024e57b691fe61a6688 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 5 May 2017 16:31:03 -0700 Subject: [core, android] Factor JSON string conversions This adds a `convertJSON` template, to be used like: Error error optional foo = convertJSON(string, error); Internally, it parses the string with RapidJSON and then calls `convert(parsed, error)`. While here, rationalize GeoJSON converters and fix error handling for Tileset conversion in OfflineDownload. --- test/fixtures/style_parser/tilejson.raster.json | 8 ------ test/fixtures/style_parser/tilejson.vector.json | 8 ------ test/style/tile_source.test.cpp | 37 ------------------------- test/util/mapbox.test.cpp | 27 ++++++++++++++++++ 4 files changed, 27 insertions(+), 53 deletions(-) delete mode 100644 test/fixtures/style_parser/tilejson.raster.json delete mode 100644 test/fixtures/style_parser/tilejson.vector.json delete mode 100644 test/style/tile_source.test.cpp (limited to 'test') diff --git a/test/fixtures/style_parser/tilejson.raster.json b/test/fixtures/style_parser/tilejson.raster.json deleted file mode 100644 index 3fc819f292..0000000000 --- a/test/fixtures/style_parser/tilejson.raster.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "minzoom": 0, - "maxzoom": 15, - "center": [ 1, 2, 3 ], - "bounds": [ 4, 5, 6, 7 ], - "attribution": "attribution", - "tiles": [ "http://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token=key" ] -} diff --git a/test/fixtures/style_parser/tilejson.vector.json b/test/fixtures/style_parser/tilejson.vector.json deleted file mode 100644 index 9144bd502c..0000000000 --- a/test/fixtures/style_parser/tilejson.vector.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "minzoom": 0, - "maxzoom": 15, - "center": [ 1, 2, 3 ], - "bounds": [ 4, 5, 6, 7 ], - "attribution": "attribution", - "tiles": [ "http://a.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.vector.pbf?access_token=key" ] -} diff --git a/test/style/tile_source.test.cpp b/test/style/tile_source.test.cpp deleted file mode 100644 index 35d037a049..0000000000 --- a/test/style/tile_source.test.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include - -#include -#include - -using namespace mbgl; -using namespace mbgl::style; - -TEST(TileSourceImpl, ParseTileJSONRaster) { - auto result = TileSourceImpl::parseTileJSON( - util::read_file("test/fixtures/style_parser/tilejson.raster.json"), - "mapbox://mapbox.satellite", - SourceType::Raster, - 256); - - EXPECT_EQ(0, result.zoomRange.min); - EXPECT_EQ(15, result.zoomRange.max); - EXPECT_EQ("attribution", result.attribution); -#if !defined(__ANDROID__) && !defined(__APPLE__) - EXPECT_EQ("mapbox://tiles/mapbox.satellite/{z}/{x}/{y}{ratio}.webp", result.tiles[0]); -#else - EXPECT_EQ("mapbox://tiles/mapbox.satellite/{z}/{x}/{y}{ratio}.png", result.tiles[0]); -#endif -} - -TEST(TileSourceImpl, ParseTileJSONVector) { - auto result = TileSourceImpl::parseTileJSON( - util::read_file("test/fixtures/style_parser/tilejson.vector.json"), - "mapbox://mapbox.streets", - SourceType::Vector, - 256); - - EXPECT_EQ(0, result.zoomRange.min); - EXPECT_EQ(15, result.zoomRange.max); - EXPECT_EQ("attribution", result.attribution); - EXPECT_EQ("mapbox://tiles/mapbox.streets/{z}/{x}/{y}.vector.pbf", result.tiles[0]); -} diff --git a/test/util/mapbox.test.cpp b/test/util/mapbox.test.cpp index 299f0df833..ba867ccb5c 100644 --- a/test/util/mapbox.test.cpp +++ b/test/util/mapbox.test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include using namespace mbgl; @@ -210,3 +211,29 @@ TEST(Mapbox, CanonicalURL) { "http://api.mapbox.com/v4/a.b/{z}/{x}/{y}/.", mbgl::util::mapbox::canonicalizeTileURL("http://api.mapbox.com/v4/a.b/{z}/{x}/{y}/.", SourceType::Raster, 256)); } + +TEST(Mapbox, CanonicalizeRasterTileset) { + mbgl::Tileset tileset; + tileset.tiles = { + "http://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token=key" + }; + + mbgl::util::mapbox::canonicalizeTileset(tileset, "mapbox://mapbox.satellite", SourceType::Raster, 256); + +#if !defined(__ANDROID__) && !defined(__APPLE__) + EXPECT_EQ("mapbox://tiles/mapbox.satellite/{z}/{x}/{y}{ratio}.webp", tileset.tiles[0]); +#else + EXPECT_EQ("mapbox://tiles/mapbox.satellite/{z}/{x}/{y}{ratio}.png", tileset.tiles[0]); +#endif +} + +TEST(Mapbox, CanonicalizeVectorTileset) { + mbgl::Tileset tileset; + tileset.tiles = { + "http://a.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.vector.pbf?access_token=key" + }; + + mbgl::util::mapbox::canonicalizeTileset(tileset, "mapbox://mapbox.streets", SourceType::Vector, 512); + + EXPECT_EQ("mapbox://tiles/mapbox.streets/{z}/{x}/{y}.vector.pbf", tileset.tiles[0]); +} -- cgit v1.2.1