From e2cf79260fe9f14a3012d631e02476b30b270a20 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 25 Nov 2015 12:46:21 +0000 Subject: [PATCH] unit tests - add 'ensure original ordering in geojson.input' test ref #3182 --- test/data | 2 +- test/unit/datasource/geojson.cpp | 58 +++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/test/data b/test/data index 3161747e4..94fa33e08 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 3161747e4a47aea0a5f968caf3443e8fdf298772 +Subproject commit 94fa33e08b81686d85d712afee0b12d4e78f7a0a diff --git a/test/unit/datasource/geojson.cpp b/test/unit/datasource/geojson.cpp index ad1f2d9be..d27347c6b 100644 --- a/test/unit/datasource/geojson.cpp +++ b/test/unit/datasource/geojson.cpp @@ -503,7 +503,7 @@ TEST_CASE("geojson") { for (auto cache_features : {true,false}) { - params["cache_features"] = false; + params["cache_features"] = cache_features; auto ds = mapnik::datasource_cache::instance().create(params); auto fields = ds->get_descriptor().get_descriptors(); mapnik::query query(ds->envelope()); @@ -573,5 +573,61 @@ TEST_CASE("geojson") { } } } + + SECTION("GeoJSON ensure original feature ordering is preserved") + { + mapnik::parameters params; + params["type"] = "geojson"; + + std::string filename("./test/data/json/ordered.json"); + params["file"] = filename; + + // 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}) + { + params["cache_features"] = cache_features; + auto ds = mapnik::datasource_cache::instance().create(params); + REQUIRE(bool(ds)); + auto fields = ds->get_descriptor().get_descriptors(); + mapnik::query query(ds->envelope()); + for (auto const& field : fields) + { + query.add_property_name(field.get_name()); + } + auto features = ds->features(query); + auto feature = features->next(); + mapnik::value_integer count = 0; + while (feature != nullptr) + { + // ids are in ascending order, starting from 1 + mapnik::value val= feature->get("id"); + REQUIRE(val.get() == ++count); + feature = features->next(); + } + } + // cleanup + if (create_index && mapnik::util::exists(filename + ".index")) + { + mapnik::util::remove(filename + ".index"); + } + } + } } }