From ed37ff4b8923f55b0f40e2ec279eb7c37f8f14f9 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 17 Mar 2016 12:52:35 +0100 Subject: [PATCH] basic TopoJSON parsing tests (work-in-progress) --- test/unit/datasource/topojson.cpp | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/unit/datasource/topojson.cpp diff --git a/test/unit/datasource/topojson.cpp b/test/unit/datasource/topojson.cpp new file mode 100644 index 000000000..d9a5b5f86 --- /dev/null +++ b/test/unit/datasource/topojson.cpp @@ -0,0 +1,68 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2016 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include "catch.hpp" + +#include +#include +#include +#include +#include + +namespace { + +using iterator_type = std::string::const_iterator; +const mapnik::topojson::topojson_grammar grammar; + +bool parse_topology(std::string const& filename, mapnik::topojson::topology & topo) +{ + mapnik::util::file file(filename); + std::string buffer; + buffer.resize(file.size()); + std::fread(&buffer[0], buffer.size(), 1, file.get()); + if (!file) return false; + boost::spirit::standard::space_type space; + iterator_type itr = buffer.begin(); + iterator_type end = buffer.end(); + bool result = boost::spirit::qi::phrase_parse(itr, end, grammar, space, topo); + return (result && (itr == end)); +} + + +} + +TEST_CASE("topology") +{ + SECTION("geometry parsing") + { + for (auto const& path : mapnik::util::list_directory("test/data/topojson/")) + { + mapnik::topojson::topology topo; + REQUIRE(parse_topology(path, topo)); + for (auto const& geom : topo.geometries) + { + mapnik::box2d box = mapnik::util::apply_visitor(mapnik::topojson::bounding_box_visitor(topo), geom); + //std::cerr << box << std::endl; + } + } + } +}