From b85055ee38da59baaaa2a590d3144e4240d142d8 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 6 Nov 2015 11:48:32 +0000 Subject: [PATCH] unit test - add malformed "Feature" tests --- test/data | 2 +- test/unit/datasource/geojson.cpp | 47 +++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/test/data b/test/data index 47421b1b5..e2ddd49ea 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 47421b1b57ce623bb8f829870b04f03877bacafa +Subproject commit e2ddd49eaf1638dd871ab168f7d3f88a10d42696 diff --git a/test/unit/datasource/geojson.cpp b/test/unit/datasource/geojson.cpp index cd9edcecd..785d66995 100644 --- a/test/unit/datasource/geojson.cpp +++ b/test/unit/datasource/geojson.cpp @@ -125,7 +125,7 @@ TEST_CASE("geojson") { } } - SECTION("GeoJSON Point ") + SECTION("GeoJSON Point") { for (auto cache_features : {true, false}) { @@ -436,10 +436,55 @@ TEST_CASE("geojson") { } } + SECTION("GeoJSON ensure mapnik::datasource_cache::instance().create() throws on malformed input") + { + mapnik::parameters params; + params["type"] = "geojson"; + + for (auto const& c_str : {"./test/data/json/feature-malformed-1.geojson", + "./test/data/json/feature-malformed-2.geojson", + "./test/data/json/feature-malformed-3.geojson"}) + { + std::string filename(c_str); + params["file"] = filename; // mismatched parentheses + + // cleanup in the case of a failed previous run + if (mapnik::util::exists(filename + ".index")) + { + mapnik::util::remove(filename + ".index"); + } + + for (auto create_index : { true, false }) + { + if (create_index) + { + CHECK(!mapnik::util::exists(filename + ".index")); + int ret = create_disk_index(filename); + int ret_posix = (ret >> 8) & 0x000000ff; + INFO(ret); + INFO(ret_posix); + CHECK(!mapnik::util::exists(filename + ".index")); + } + + for (auto cache_features : {true, false}) + { + CHECK_THROWS(mapnik::datasource_cache::instance().create(params)); + } + + // cleanup + if (create_index && mapnik::util::exists(filename + ".index")) + { + mapnik::util::remove(filename + ".index"); + } + } + } + } + SECTION("GeoJSON ensure input fully consumed and throw exception otherwise") { mapnik::parameters params; params["type"] = "geojson"; + std::string filename("./test/data/json/points-malformed.geojson"); params["file"] = filename; // mismatched parentheses