add tests for no-existing svg file + bogus color in fill and stroke

This commit is contained in:
artemp 2015-07-22 11:52:18 +02:00
parent e3f28ba4d3
commit 9eadd48d7b
3 changed files with 45 additions and 2 deletions

View file

@ -109,6 +109,7 @@ mapnik::color parse_color(T & error_messages, const char* str)
} }
catch (mapnik::config_error const& ex) catch (mapnik::config_error const& ex)
{ {
error_messages.emplace_back(ex.what()); error_messages.emplace_back(ex.what());
} }
return c; return c;

@ -1 +1 @@
Subproject commit d1795652ab1e9fce645498b94a33ca660d3650f4 Subproject commit 41793d29ba9068e68c7ec46da3e4d5e1c2f75b1a

View file

@ -27,11 +27,21 @@
#include <mapnik/marker.hpp> #include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp> #include <mapnik/marker_cache.hpp>
#include <mapnik/vertex.hpp> #include <mapnik/vertex.hpp>
//#include <mapnik/svg/svg_path_adapter.hpp>
//#include <mapnik/svg/svg_renderer_agg.hpp>
//#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/svg/svg_parser.hpp>
#include <mapnik/svg/svg_storage.hpp>
#include <mapnik/svg/svg_converter.hpp>
#include <mapnik/svg/svg_path_adapter.hpp> #include <mapnik/svg/svg_path_adapter.hpp>
#include <mapnik/svg/svg_renderer_agg.hpp>
#include <mapnik/svg/svg_path_attributes.hpp> #include <mapnik/svg/svg_path_attributes.hpp>
#include <libxml/parser.h> // for xmlInitParser(), xmlCleanupParser() #include <libxml/parser.h> // for xmlInitParser(), xmlCleanupParser()
#include <cmath> #include <cmath>
#include <fstream>
#include <streambuf>
namespace detail { namespace detail {
@ -52,6 +62,38 @@ struct vertex_equal
TEST_CASE("SVG parser") { TEST_CASE("SVG parser") {
xmlInitParser(); xmlInitParser();
SECTION("SVG i/o")
{
std::string svg_name("FAIL");
std::shared_ptr<mapnik::marker const> marker = mapnik::marker_cache::instance().find(svg_name, false);
REQUIRE(marker);
REQUIRE(marker->is<mapnik::marker_null>());
}
SECTION("SVG parser color <fail>")
{
std::string svg_name("./test/data/svg/color_fail.svg");
std::ifstream in(svg_name.c_str());
std::string svg_str((std::istreambuf_iterator<char>(in)),
std::istreambuf_iterator<char>());
using namespace mapnik::svg;
mapnik::svg_storage_type path;
vertex_stl_adapter<svg_path_storage> stl_storage(path.source());
svg_path_adapter svg_path(stl_storage);
svg_converter_type svg(svg_path, path.attributes());
svg_parser p(svg);
if (!p.parse_from_string(svg_str))
{
for (auto const& msg : p.error_messages())
{
REQUIRE(msg == "Failed to parse color: \"fail\"");
}
}
}
SECTION("SVG <rect>") SECTION("SVG <rect>")
{ {
//<rect width="20" height="15" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)" /> //<rect width="20" height="15" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)" />