From 9eadd48d7b588d01f6bd115bd305332d68437f15 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 22 Jul 2015 11:52:18 +0200 Subject: [PATCH] add tests for no-existing svg file + bogus color in `fill` and `stroke` --- src/svg/svg_parser.cpp | 1 + test/data | 2 +- test/unit/svg/svg_parser_test.cpp | 44 ++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index 72a4baebc..6fc51674d 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -109,6 +109,7 @@ mapnik::color parse_color(T & error_messages, const char* str) } catch (mapnik::config_error const& ex) { + error_messages.emplace_back(ex.what()); } return c; diff --git a/test/data b/test/data index d1795652a..41793d29b 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit d1795652ab1e9fce645498b94a33ca660d3650f4 +Subproject commit 41793d29ba9068e68c7ec46da3e4d5e1c2f75b1a diff --git a/test/unit/svg/svg_parser_test.cpp b/test/unit/svg/svg_parser_test.cpp index 6bd37bede..8ff4013bd 100644 --- a/test/unit/svg/svg_parser_test.cpp +++ b/test/unit/svg/svg_parser_test.cpp @@ -27,11 +27,21 @@ #include #include #include + +//#include +//#include +//#include + +#include +#include +#include #include -#include #include + #include // for xmlInitParser(), xmlCleanupParser() #include +#include +#include namespace detail { @@ -52,6 +62,38 @@ struct vertex_equal TEST_CASE("SVG parser") { xmlInitParser(); + SECTION("SVG i/o") + { + std::string svg_name("FAIL"); + std::shared_ptr marker = mapnik::marker_cache::instance().find(svg_name, false); + REQUIRE(marker); + REQUIRE(marker->is()); + } + + SECTION("SVG parser color ") + { + + std::string svg_name("./test/data/svg/color_fail.svg"); + std::ifstream in(svg_name.c_str()); + std::string svg_str((std::istreambuf_iterator(in)), + std::istreambuf_iterator()); + + using namespace mapnik::svg; + mapnik::svg_storage_type path; + vertex_stl_adapter 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 ") { //