From f8c6ad1e29d8a4924b02a65b87f433820a407533 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/visual/config.hpp | 9 ++++- test/visual/runner.cpp | 89 +++++++++++++++++++++++++++--------------- test/visual/runner.hpp | 1 + 3 files changed, 67 insertions(+), 32 deletions(-) diff --git a/test/visual/config.hpp b/test/visual/config.hpp index 0dac1d983..2f5f6acde 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 d0c7222fb..44787e97d 100644 --- a/test/visual/runner.cpp +++ b/test/visual/runner.cpp @@ -32,6 +32,15 @@ namespace visual_tests { +struct renderer_name_visitor +{ + template + std::string operator()(Renderer const&) const + { + return Renderer::renderer_type::name; + } +}; + class renderer_visitor { public: @@ -247,6 +256,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 @@ -270,39 +317,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) @@ -322,10 +343,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 e38e39422..bf068ec22 100644 --- a/test/visual/runner.hpp +++ b/test/visual/runner.hpp @@ -59,6 +59,7 @@ private: report_type & report, std::atomic & fail_limit) const; void parse_map_sizes(std::string const & str, std::vector & sizes) const; + void parse_params(mapnik::parameters const & params, config & cfg) const; const map_sizes_grammar map_sizes_parser_; const path_type styles_dir_;