From 13d678d9afb5d66165ee5b0bd0cd2a9aaca9bbb0 Mon Sep 17 00:00:00 2001 From: talaj Date: Thu, 14 Sep 2017 15:21:30 +0200 Subject: [PATCH] visual tests: allow to ignore particular renderer (#3768) * visual tests: refactor parsing parameters from the style * visual tests: allow to ignore particular renderer * update visual tests --- test/data-visual | 2 +- test/visual/config.hpp | 9 ++++- test/visual/runner.cpp | 89 +++++++++++++++++++++++++++--------------- test/visual/runner.hpp | 1 + 4 files changed, 68 insertions(+), 33 deletions(-) diff --git a/test/data-visual b/test/data-visual index 817df2ff5..7a8f60815 160000 --- a/test/data-visual +++ b/test/data-visual @@ -1 +1 @@ -Subproject commit 817df2ff5dbe6de95b33a9e5e0516b3a3308a33d +Subproject commit 7a8f60815c2962db6eb8977e0dd75740096f0c00 diff --git a/test/visual/config.hpp b/test/visual/config.hpp index f584ff736..974383fa0 100644 --- a/test/visual/config.hpp +++ b/test/visual/config.hpp @@ -25,12 +25,15 @@ // stl #include +#include #include #include // boost #include +#include + namespace visual_tests { @@ -47,12 +50,16 @@ struct config config() : status(true), scales({ 1.0, 2.0 }), sizes({ { 500, 100 } }), - tiles({ { 1, 1 } }) { } + tiles({ { 1, 1 } }), + bbox(), + ignored_renderers() { } bool status; std::vector scales; std::vector sizes; std::vector tiles; + mapnik::box2d bbox; + std::set ignored_renderers; }; enum result_state : std::uint8_t diff --git a/test/visual/runner.cpp b/test/visual/runner.cpp index 3762c9c19..98ac7961f 100644 --- a/test/visual/runner.cpp +++ b/test/visual/runner.cpp @@ -34,6 +34,15 @@ namespace visual_tests { +struct renderer_name_visitor +{ + template + std::string operator()(Renderer const&) const + { + return Renderer::renderer_type::name; + } +}; + class renderer_visitor { public: @@ -249,6 +258,44 @@ result_list runner::test_range(files_iterator begin, return results; } +void runner::parse_params(mapnik::parameters const & params, config & cfg) const +{ + cfg.status = *params.get("status", cfg.status); + + boost::optional sizes = params.get("sizes"); + + if (sizes) + { + cfg.sizes.clear(); + parse_map_sizes(*sizes, cfg.sizes); + } + + boost::optional tiles = params.get("tiles"); + + if (tiles) + { + cfg.tiles.clear(); + parse_map_sizes(*tiles, cfg.tiles); + } + + boost::optional bbox_string = params.get("bbox"); + + if (bbox_string) + { + cfg.bbox.from_string(*bbox_string); + } + + for (auto const & renderer : renderers_) + { + std::string renderer_name = mapnik::util::apply_visitor(renderer_name_visitor(), renderer); + boost::optional enabled = params.get(renderer_name); + if (enabled && !*enabled) + { + cfg.ignored_renderers.insert(renderer_name); + } + } +} + result_list runner::test_one(runner::path_type const& style_path, report_type & report, std::atomic & fail_count) const @@ -272,39 +319,13 @@ result_list runner::test_one(runner::path_type const& style_path, throw; } - mapnik::parameters const & params = map.get_extra_parameters(); + parse_params(map.get_extra_parameters(), cfg); - boost::optional status = params.get("status", cfg.status); - - if (!*status) + if (!cfg.status) { return results; } - boost::optional sizes = params.get("sizes"); - - if (sizes) - { - cfg.sizes.clear(); - parse_map_sizes(*sizes, cfg.sizes); - } - - boost::optional tiles = params.get("tiles"); - - if (tiles) - { - cfg.tiles.clear(); - parse_map_sizes(*tiles, cfg.tiles); - } - - boost::optional bbox_string = params.get("bbox"); - mapnik::box2d box; - - if (bbox_string) - { - box.from_string(*bbox_string); - } - std::string name(style_path.stem().string()); for (auto const & size : cfg.sizes) @@ -324,10 +345,16 @@ result_list runner::test_one(runner::path_type const& style_path, for (auto const & ren : renderers_) { - map.resize(size.width, size.height); - if (box.valid()) + std::string renderer_name = mapnik::util::apply_visitor(renderer_name_visitor(), ren); + if (cfg.ignored_renderers.count(renderer_name)) { - map.zoom_to_box(box); + continue; + } + + map.resize(size.width, size.height); + if (cfg.bbox.valid()) + { + map.zoom_to_box(cfg.bbox); } else { diff --git a/test/visual/runner.hpp b/test/visual/runner.hpp index d764b592a..3c205ede5 100644 --- a/test/visual/runner.hpp +++ b/test/visual/runner.hpp @@ -57,6 +57,7 @@ private: result_list test_one(path_type const & style_path, report_type & report, std::atomic & fail_limit) const; + void parse_params(mapnik::parameters const & params, config & cfg) const; const path_type styles_dir_; const config defaults_;