topojson: add test with empty "objects" and "arcs"
This commit is contained in:
parent
74b2886036
commit
ee28954786
1 changed files with 52 additions and 1 deletions
|
@ -29,8 +29,12 @@
|
||||||
#include <mapnik/json/topojson_grammar_x3.hpp>
|
#include <mapnik/json/topojson_grammar_x3.hpp>
|
||||||
#include <mapnik/json/topojson_utils.hpp>
|
#include <mapnik/json/topojson_utils.hpp>
|
||||||
|
|
||||||
|
#define HEREDOC(...) #__VA_ARGS__
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
bool parse_topology_string(std::string const& buffer, mapnik::topojson::topology & topo);
|
||||||
|
|
||||||
bool parse_topology(std::string const& filename, mapnik::topojson::topology & topo)
|
bool parse_topology(std::string const& filename, mapnik::topojson::topology & topo)
|
||||||
{
|
{
|
||||||
mapnik::util::file file(filename);
|
mapnik::util::file file(filename);
|
||||||
|
@ -38,6 +42,17 @@ bool parse_topology(std::string const& filename, mapnik::topojson::topology & to
|
||||||
buffer.resize(file.size());
|
buffer.resize(file.size());
|
||||||
std::fread(&buffer[0], buffer.size(), 1, file.get());
|
std::fread(&buffer[0], buffer.size(), 1, file.get());
|
||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
|
return parse_topology_string(buffer, topo);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parse_topology_string(std::string const& buffer)
|
||||||
|
{
|
||||||
|
mapnik::topojson::topology topo;
|
||||||
|
return parse_topology_string(buffer, topo);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parse_topology_string(std::string const& buffer, mapnik::topojson::topology & topo)
|
||||||
|
{
|
||||||
using space_type = boost::spirit::x3::standard::space_type;
|
using space_type = boost::spirit::x3::standard::space_type;
|
||||||
char const* itr = buffer.c_str();
|
char const* itr = buffer.c_str();
|
||||||
char const* end = itr + buffer.length();
|
char const* end = itr + buffer.length();
|
||||||
|
@ -58,8 +73,44 @@ bool parse_topology(std::string const& filename, mapnik::topojson::topology & to
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("topojson")
|
TEST_CASE("TopoJSON")
|
||||||
{
|
{
|
||||||
|
SECTION("Minimal Topology")
|
||||||
|
{
|
||||||
|
// + A topology must have a member with the name “objects” whose value is another object.
|
||||||
|
// + A topology must have a member with the name “arcs” whose value is an array of arcs.
|
||||||
|
CHECK(parse_topology_string(HEREDOC(
|
||||||
|
{
|
||||||
|
"type": "Topology", "objects": {}, "arcs": []
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
CHECK(parse_topology_string(HEREDOC(
|
||||||
|
{
|
||||||
|
"type": "Topology", "arcs": [], "objects": {}
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
CHECK(parse_topology_string(HEREDOC(
|
||||||
|
{
|
||||||
|
"objects": {}, "type": "Topology", "arcs": []
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
CHECK(parse_topology_string(HEREDOC(
|
||||||
|
{
|
||||||
|
"objects": {}, "arcs": [], "type": "Topology"
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
CHECK(parse_topology_string(HEREDOC(
|
||||||
|
{
|
||||||
|
"arcs": [], "type": "Topology", "objects": {}
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
CHECK(parse_topology_string(HEREDOC(
|
||||||
|
{
|
||||||
|
"arcs": [], "objects": {}, "type": "Topology"
|
||||||
|
}
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("geometry parsing")
|
SECTION("geometry parsing")
|
||||||
{
|
{
|
||||||
mapnik::value_integer feature_id = 0;
|
mapnik::value_integer feature_id = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue