add more cxx tests of new geometry
This commit is contained in:
parent
89e36a8685
commit
6c57c08a53
3 changed files with 95 additions and 0 deletions
56
tests/cxx/datasources.cpp
Normal file
56
tests/cxx/datasources.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
||||
TEST_CASE("datasources") {
|
||||
|
||||
SECTION("hello world") {
|
||||
|
||||
std::string plugin("./plugins/input/templates/hello.input");
|
||||
if (mapnik::util::exists(plugin))
|
||||
{
|
||||
try
|
||||
{
|
||||
mapnik::datasource_cache::instance().register_datasource(plugin);
|
||||
mapnik::parameters p;
|
||||
p["type"]="hello";
|
||||
mapnik::datasource_ptr ds = mapnik::datasource_cache::instance().create(p);
|
||||
mapnik::box2d<double> bbox = ds->envelope();
|
||||
mapnik::query q(bbox);
|
||||
mapnik::featureset_ptr fs = ds->features(q);
|
||||
REQUIRE( fs != mapnik::featureset_ptr() );
|
||||
mapnik::feature_ptr feat1 = fs->next();
|
||||
REQUIRE( feat1 != mapnik::feature_ptr() );
|
||||
mapnik::feature_ptr feat2 = fs->next();
|
||||
REQUIRE( feat2 != mapnik::feature_ptr() );
|
||||
REQUIRE( fs->next() == mapnik::feature_ptr() );
|
||||
REQUIRE( feat1->id() == static_cast<mapnik::value_integer>(1) );
|
||||
REQUIRE( feat2->id() == static_cast<mapnik::value_integer>(2) );
|
||||
auto const& geom1 = feat1->get_geometry();
|
||||
REQUIRE( geom1.is<mapnik::new_geometry::point>() );
|
||||
auto const& point = mapnik::util::get<mapnik::new_geometry::point>(geom1);
|
||||
REQUIRE( point.x == bbox.center().x );
|
||||
REQUIRE( point.y == bbox.center().y );
|
||||
auto const& geom2 = feat2->get_geometry();
|
||||
REQUIRE( geom2.is<mapnik::new_geometry::line_string>() );
|
||||
auto const& line = mapnik::util::get<mapnik::new_geometry::line_string>(geom2);
|
||||
REQUIRE( line.size() == 4 );
|
||||
REQUIRE( line[0].x == bbox.minx() );
|
||||
REQUIRE( line[0].y == bbox.maxy() );
|
||||
}
|
||||
catch (std::exception const& ex)
|
||||
{
|
||||
FAIL(ex.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN( std::string("could not register ") + plugin );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
38
tests/cxx/geometry.cpp
Normal file
38
tests/cxx/geometry.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
#include <mapnik/util/file_io.hpp>
|
||||
#include <mapnik/json/geometry_parser.hpp>
|
||||
//#include <mapnik/util/geometry_to_geojson.hpp>
|
||||
#include <mapnik/json/geometry_generator_grammar.hpp>
|
||||
#include <mapnik/json/geometry_generator_grammar_impl.hpp>
|
||||
|
||||
TEST_CASE("geometry") {
|
||||
|
||||
SECTION("json") {
|
||||
mapnik::util::file input("./tests/data/json/fixtures/point1.json");
|
||||
auto json = input.data();
|
||||
mapnik::new_geometry::geometry geom;
|
||||
std::string json_string(json.get());
|
||||
REQUIRE( mapnik::json::from_geojson(json_string,geom) );
|
||||
if (geom.is<mapnik::new_geometry::point>()) {
|
||||
auto const& point = mapnik::util::get<mapnik::new_geometry::point>(geom);
|
||||
REQUIRE( point.x == 30 );
|
||||
REQUIRE( point.y == 10 );
|
||||
using adapter_type = mapnik::new_geometry::point_vertex_adapter;
|
||||
adapter_type va(point);
|
||||
std::string new_json;
|
||||
using sink_type = std::back_insert_iterator<std::string>;
|
||||
// TODO: need to round trip, but does not compile yet
|
||||
/*
|
||||
static const mapnik::json::geometry_generator_grammar<sink_type, adapter_type> grammar;
|
||||
sink_type sink(new_json);
|
||||
REQUIRE( boost::spirit::karma::generate(sink, grammar, va) );
|
||||
*/
|
||||
//REQUIRE( mapnik::util::to_geojson(new_json,va) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1
tests/data/json/fixtures/point1.json
Normal file
1
tests/data/json/fixtures/point1.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"type":"Point","coordinates":[30,10]}
|
Loading…
Add table
Reference in a new issue