From 69e5340ceb682e8fa68617b6cf55473487e6fc9b Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 23 Mar 2017 13:44:51 +0000 Subject: [PATCH] add valid/invalid `empty` GeoJSON geometry tests --- test/unit/datasource/geojson.cpp | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/unit/datasource/geojson.cpp b/test/unit/datasource/geojson.cpp index d65977d93..05cd55d03 100644 --- a/test/unit/datasource/geojson.cpp +++ b/test/unit/datasource/geojson.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -115,6 +116,41 @@ TEST_CASE("geojson") { } } + SECTION("GeoJSON empty Geometries handling") + { + auto valid_empty_geometries = + { + "null", // Point can't be empty + "{ \"type\": \"LineString\", \"coordinates\": [] }", + "{ \"type\": \"Polygon\", \"coordinates\": [ [ ] ] } ", + "{ \"type\": \"MultiPoint\", \"coordinates\": [ ] }", + "{ \"type\": \"MultiLineString\", \"coordinates\": [ [] ] }", + "{ \"type\": \"MultiPolygon\", \"coordinates\": [[ []] ] }" + }; + + for (auto const& json : valid_empty_geometries) + { + mapnik::geometry::geometry geom; + CHECK(mapnik::json::from_geojson(json, geom)); + } + + auto invalid_empty_geometries = + { + "{ \"type\": \"Point\", \"coordinates\": [] }", + "{ \"type\": \"LineString\", \"coordinates\": [[]] }" + "{ \"type\": \"Polygon\", \"coordinates\": [[[]]] }", + "{ \"type\": \"MultiPoint\", \"coordinates\": [[]] }", + "{ \"type\": \"MultiLineString\", \"coordinates\": [[[]]] }", + "{ \"type\": \"MultiPolygon\", \"coordinates\": [[[[]]]] }" + }; + + for (auto const& json : invalid_empty_geometries) + { + mapnik::geometry::geometry geom; + CHECK(!mapnik::json::from_geojson(json, geom)); + } + } + SECTION("GeoJSON num_features_to_query") { std::string filename = "./test/data/json/featurecollection-multipleprops.geojson";