Merge pull request #2810 from mapycz/improve-visual-test-2

handle styles with missing reference images
This commit is contained in:
Artem Pavlenko 2015-05-14 14:11:09 +01:00
commit 86a603ac8d

View file

@ -31,6 +31,7 @@
// mapnik // mapnik
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#include <mapnik/util/fs.hpp>
#include <mapnik/agg_renderer.hpp> #include <mapnik/agg_renderer.hpp>
#if defined(HAVE_CAIRO) #if defined(HAVE_CAIRO)
#include <mapnik/cairo/cairo_renderer.hpp> #include <mapnik/cairo/cairo_renderer.hpp>
@ -117,15 +118,16 @@ public:
{ {
typename Renderer::image_type image(ren.render(map, scale_factor)); typename Renderer::image_type image(ren.render(map, scale_factor));
boost::filesystem::path reference = reference_dir / image_file_name(name, map.width(), map.height(), scale_factor, true); boost::filesystem::path reference = reference_dir / image_file_name(name, map.width(), map.height(), scale_factor, true);
bool reference_exists = mapnik::util::exists(reference.string());
result res; result res;
res.state = STATE_OK; res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
res.name = name; res.name = name;
res.renderer_name = Renderer::name; res.renderer_name = Renderer::name;
res.scale_factor = scale_factor; res.scale_factor = scale_factor;
res.size = map_size(map.width(), map.height()); res.size = map_size(map.width(), map.height());
res.reference_image_path = reference; res.reference_image_path = reference;
res.diff = ren.compare(image, reference); res.diff = reference_exists ? ren.compare(image, reference) : 0;
if (res.diff) if (res.diff)
{ {
@ -134,12 +136,12 @@ public:
res.actual_image_path = path; res.actual_image_path = path;
res.state = STATE_FAIL; res.state = STATE_FAIL;
ren.save(image, path); ren.save(image, path);
}
if (overwrite) if ((res.diff && overwrite) || !reference_exists)
{ {
ren.save(image, reference); ren.save(image, reference);
res.state = STATE_OVERWRITE; res.state = STATE_OVERWRITE;
}
} }
return res; return res;