improve test coverage of geojson indexing

This commit is contained in:
Dane Springmeyer 2015-10-20 22:56:03 -07:00
parent 9df548670c
commit 14589dabd1

View file

@ -30,6 +30,8 @@
#include <mapnik/util/fs.hpp> #include <mapnik/util/fs.hpp>
#include <cstdlib> #include <cstdlib>
#include <boost/filesystem/operations.hpp>
namespace detail { namespace detail {
mapnik::feature_ptr fetch_first_feature(std::string const& filename, bool cache_features) mapnik::feature_ptr fetch_first_feature(std::string const& filename, bool cache_features)
@ -168,9 +170,22 @@ TEST_CASE("geojson") {
SECTION("GeoJSON GeometryCollection") 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}) 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 // test
auto const& geometry = feature->get_geometry(); auto const& geometry = feature->get_geometry();
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::GeometryCollection); 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)); REQUIRE(mapnik::geometry::envelope(collection) == mapnik::box2d<double>(100,0,102,1));
} }
} }
}
SECTION("GeoJSON Feature") SECTION("GeoJSON Feature")
{ {
// Create datasource // Create datasource
mapnik::parameters params; mapnik::parameters params;
params["type"] = "geojson"; 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}) for (auto cache_features : {true, false})
{ {
params["cache-features"] = cache_features; params["cache-features"] = cache_features;
@ -205,11 +234,18 @@ TEST_CASE("geojson") {
REQUIRE(feature != nullptr); REQUIRE(feature != nullptr);
} }
} }
}
SECTION("GeoJSON FeatureCollection") SECTION("GeoJSON FeatureCollection")
{ {
std::string filename("./test/data/json/featurecollection.json"); 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 }) for (auto create_index : { true, false })
{ {
if (create_index) if (create_index)
@ -264,7 +300,26 @@ TEST_CASE("geojson") {
// Create datasource // Create datasource
mapnik::parameters params; mapnik::parameters params;
params["type"] = "geojson"; 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}) for (auto cache_features : {true, false})
{ {
params["cache-features"] = cache_features; params["cache-features"] = cache_features;
@ -282,19 +337,55 @@ TEST_CASE("geojson") {
REQUIRE(feature != nullptr); REQUIRE(feature != nullptr);
REQUIRE(feature->envelope() == mapnik::box2d<double>(123,456,123,456)); 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") SECTION("GeoJSON ensure input fully consumed and throw exception otherwise")
{ {
mapnik::parameters params; mapnik::parameters params;
params["type"] = "geojson"; 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}) for (auto cache_features : {true, false})
{ {
std::stringstream msg;
msg << "testcase: create index " << create_index << " cache-features " << cache_features;
params["cache-features"] = cache_features; params["cache-features"] = cache_features;
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params)); INFO(msg.str());
params["cache-features"] = true; CHECK_THROWS(mapnik::datasource_cache::instance().create(params));
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params)); }
// cleanup
if (create_index && mapnik::util::exists(filename + ".index"))
{
boost::filesystem::remove(filename + ".index");
}
} }
} }
} }