improve test coverage of geojson indexing
This commit is contained in:
parent
9df548670c
commit
14589dabd1
1 changed files with 134 additions and 43 deletions
|
@ -30,6 +30,8 @@
|
|||
#include <mapnik/util/fs.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
namespace detail {
|
||||
|
||||
mapnik::feature_ptr fetch_first_feature(std::string const& filename, bool cache_features)
|
||||
|
@ -168,9 +170,22 @@ TEST_CASE("geojson") {
|
|||
|
||||
SECTION("GeoJSON GeometryCollection")
|
||||
{
|
||||
std::string filename("./test/data/json/geometrycollection.json");
|
||||
for (auto create_index : { true, false })
|
||||
{
|
||||
if (create_index)
|
||||
{
|
||||
int ret = detail::create_disk_index(filename, true);
|
||||
int ret_posix = (ret >> 8) & 0x000000ff;
|
||||
INFO(ret);
|
||||
INFO(ret_posix);
|
||||
// index will not exist because this is not a featurecollection
|
||||
CHECK(!mapnik::util::exists(filename + ".index"));
|
||||
}
|
||||
|
||||
for (auto cache_features : {true, false})
|
||||
{
|
||||
auto feature = detail::fetch_first_feature("./test/data/json/geometrycollection.json", cache_features);
|
||||
auto feature = detail::fetch_first_feature(filename, cache_features);
|
||||
// test
|
||||
auto const& geometry = feature->get_geometry();
|
||||
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::GeometryCollection);
|
||||
|
@ -181,13 +196,27 @@ TEST_CASE("geojson") {
|
|||
REQUIRE(mapnik::geometry::envelope(collection) == mapnik::box2d<double>(100,0,102,1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("GeoJSON Feature")
|
||||
{
|
||||
// Create datasource
|
||||
mapnik::parameters params;
|
||||
params["type"] = "geojson";
|
||||
params["file"] = "./test/data/json/feature.json";
|
||||
std::string filename("./test/data/json/feature.json");
|
||||
params["file"] = filename;
|
||||
for (auto create_index : { true, false })
|
||||
{
|
||||
if (create_index)
|
||||
{
|
||||
int ret = detail::create_disk_index(filename, true);
|
||||
int ret_posix = (ret >> 8) & 0x000000ff;
|
||||
INFO(ret);
|
||||
INFO(ret_posix);
|
||||
// index will not exist because this is not a featurecollection
|
||||
CHECK(!mapnik::util::exists(filename + ".index"));
|
||||
}
|
||||
|
||||
for (auto cache_features : {true, false})
|
||||
{
|
||||
params["cache-features"] = cache_features;
|
||||
|
@ -205,11 +234,18 @@ TEST_CASE("geojson") {
|
|||
REQUIRE(feature != nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("GeoJSON FeatureCollection")
|
||||
{
|
||||
std::string filename("./test/data/json/featurecollection.json");
|
||||
|
||||
// cleanup in the case of a failed previous run
|
||||
if (mapnik::util::exists(filename + ".index"))
|
||||
{
|
||||
boost::filesystem::remove(filename + ".index");
|
||||
}
|
||||
|
||||
for (auto create_index : { true, false })
|
||||
{
|
||||
if (create_index)
|
||||
|
@ -264,7 +300,26 @@ TEST_CASE("geojson") {
|
|||
// Create datasource
|
||||
mapnik::parameters params;
|
||||
params["type"] = "geojson";
|
||||
params["file"] = "./test/data/json/feature_collection_extra_properties.json";
|
||||
std::string filename("./test/data/json/feature_collection_extra_properties.json");
|
||||
params["file"] = filename;
|
||||
|
||||
// cleanup in the case of a failed previous run
|
||||
if (mapnik::util::exists(filename + ".index"))
|
||||
{
|
||||
boost::filesystem::remove(filename + ".index");
|
||||
}
|
||||
|
||||
for (auto create_index : { true, false })
|
||||
{
|
||||
if (create_index)
|
||||
{
|
||||
int ret = detail::create_disk_index(filename, true);
|
||||
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;
|
||||
|
@ -282,19 +337,55 @@ TEST_CASE("geojson") {
|
|||
REQUIRE(feature != nullptr);
|
||||
REQUIRE(feature->envelope() == mapnik::box2d<double>(123,456,123,456));
|
||||
}
|
||||
|
||||
// cleanup
|
||||
if (create_index && mapnik::util::exists(filename + ".index"))
|
||||
{
|
||||
boost::filesystem::remove(filename + ".index");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("GeoJSON ensure input fully consumed and throw exception otherwise")
|
||||
{
|
||||
mapnik::parameters params;
|
||||
params["type"] = "geojson";
|
||||
params["file"] = "./test/data/json/points-malformed.geojson"; // mismatched parentheses
|
||||
std::string filename("./test/data/json/points-malformed.geojson");
|
||||
params["file"] = filename; // mismatched parentheses
|
||||
|
||||
// cleanup in the case of a failed previous run
|
||||
if (mapnik::util::exists(filename + ".index"))
|
||||
{
|
||||
boost::filesystem::remove(filename + ".index");
|
||||
}
|
||||
|
||||
for (auto create_index : { true, false })
|
||||
{
|
||||
if (create_index)
|
||||
{
|
||||
CHECK(!mapnik::util::exists(filename + ".index"));
|
||||
int ret = detail::create_disk_index(filename, true);
|
||||
int ret_posix = (ret >> 8) & 0x000000ff;
|
||||
INFO(ret);
|
||||
INFO(ret_posix);
|
||||
CHECK(mapnik::util::exists(filename + ".index"));
|
||||
}
|
||||
|
||||
for (auto cache_features : {true, false})
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "testcase: create index " << create_index << " cache-features " << cache_features;
|
||||
params["cache-features"] = cache_features;
|
||||
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params));
|
||||
params["cache-features"] = true;
|
||||
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params));
|
||||
INFO(msg.str());
|
||||
CHECK_THROWS(mapnik::datasource_cache::instance().create(params));
|
||||
}
|
||||
|
||||
// cleanup
|
||||
if (create_index && mapnik::util::exists(filename + ".index"))
|
||||
{
|
||||
boost::filesystem::remove(filename + ".index");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue