Add mapnik/filesystem.hpp ref:https://github.com/mapnik/mapnik/pull/4383#discussion_r1131405532
This commit is contained in:
parent
45b48721fa
commit
a244effa91
13 changed files with 109 additions and 137 deletions
43
include/mapnik/filesystem.hpp
Normal file
43
include/mapnik/filesystem.hpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Artem Pavlenko
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAPNIK_FILESYSTEM_HPP
|
||||||
|
#define MAPNIK_FILESYSTEM_HPP
|
||||||
|
|
||||||
|
#if defined(__cpp_lib_filesystem) && !defined(USE_BOOST_FILESYSTEM)
|
||||||
|
#include <filesystem>
|
||||||
|
#else
|
||||||
|
#include <boost/filesystem/operations.hpp> // for absolute, exists, etc
|
||||||
|
#include <boost/filesystem/path.hpp> // for path, operator/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace mapnik {
|
||||||
|
#if defined(__cpp_lib_filesystem) && !defined(USE_BOOST_FILESYSTEM)
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
using error_code = std::error_code;
|
||||||
|
#else
|
||||||
|
namespace fs = boost::filesystem;
|
||||||
|
using error_code = boost::system::error_code;
|
||||||
|
#endif
|
||||||
|
} // namespace mapnik
|
||||||
|
|
||||||
|
#endif // MAPNIK_FILESYSTEM_HPP
|
15
src/fs.cpp
15
src/fs.cpp
|
@ -23,20 +23,7 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/util/utf_conv_win.hpp>
|
#include <mapnik/util/utf_conv_win.hpp>
|
||||||
#include <mapnik/util/fs.hpp>
|
#include <mapnik/util/fs.hpp>
|
||||||
|
#include <mapnik/filesystem.hpp>
|
||||||
#include <mapnik/warning.hpp>
|
|
||||||
|
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
|
||||||
#include <mapnik/warning_ignore.hpp>
|
|
||||||
#include <boost/filesystem/operations.hpp> // for absolute, exists, etc
|
|
||||||
#include <boost/filesystem/path.hpp> // for path, operator/
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
|
@ -8,18 +8,7 @@
|
||||||
#include <mapnik/datasource.hpp>
|
#include <mapnik/datasource.hpp>
|
||||||
#include <mapnik/datasource_cache.hpp>
|
#include <mapnik/datasource_cache.hpp>
|
||||||
#include <mapnik/debug.hpp>
|
#include <mapnik/debug.hpp>
|
||||||
|
#include <mapnik/filesystem.hpp>
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
|
||||||
#include <filesystem>
|
|
||||||
#include <cstdio>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
using error_code = std::error_code;
|
|
||||||
#else
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
using error_code = boost::system::error_code;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/range/iterator_range_core.hpp>
|
#include <boost/range/iterator_range_core.hpp>
|
||||||
|
|
||||||
|
@ -42,13 +31,13 @@ std::string unique_mapnik_name()
|
||||||
class tmp_dir
|
class tmp_dir
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
fs::path m_path;
|
mapnik::fs::path m_path;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
tmp_dir()
|
tmp_dir()
|
||||||
: m_path(fs::temp_directory_path() / unique_mapnik_name())
|
: m_path(mapnik::fs::temp_directory_path() / unique_mapnik_name())
|
||||||
{
|
{
|
||||||
fs::create_directories(m_path);
|
mapnik::fs::create_directories(m_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
~tmp_dir()
|
~tmp_dir()
|
||||||
|
@ -57,16 +46,16 @@ class tmp_dir
|
||||||
// running, which isn't necessarily an error as far as this
|
// running, which isn't necessarily an error as far as this
|
||||||
// code is concerned - it just wants to delete everything
|
// code is concerned - it just wants to delete everything
|
||||||
// underneath the temporary directory.
|
// underneath the temporary directory.
|
||||||
error_code err;
|
mapnik::error_code err;
|
||||||
|
|
||||||
// catch all errors - we don't want to throw in the destructor
|
// catch all errors - we don't want to throw in the destructor
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// but loop while the path exists and the errors are
|
// but loop while the path exists and the errors are
|
||||||
// ignorable.
|
// ignorable.
|
||||||
while (fs::exists(m_path))
|
while (mapnik::fs::exists(m_path))
|
||||||
{
|
{
|
||||||
fs::remove_all(m_path, err);
|
mapnik::fs::remove_all(m_path, err);
|
||||||
|
|
||||||
// for any non-ignorable error, there's not much we can
|
// for any non-ignorable error, there's not much we can
|
||||||
// do from the destructor. it's in /tmp anyway, so it'll
|
// do from the destructor. it's in /tmp anyway, so it'll
|
||||||
|
@ -89,22 +78,22 @@ class tmp_dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path path() const { return m_path; }
|
mapnik::fs::path path() const { return m_path; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void compare_map(fs::path xml)
|
void compare_map(mapnik::fs::path xml)
|
||||||
{
|
{
|
||||||
tmp_dir dir;
|
tmp_dir dir;
|
||||||
mapnik::Map m(256, 256);
|
mapnik::Map m(256, 256);
|
||||||
REQUIRE(m.register_fonts("fonts", true));
|
REQUIRE(m.register_fonts("fonts", true));
|
||||||
fs::path abs_base = xml.parent_path();
|
mapnik::fs::path abs_base = xml.parent_path();
|
||||||
|
|
||||||
// first, load the XML into a map object and save it. this
|
// first, load the XML into a map object and save it. this
|
||||||
// is a normalisation step to ensure that the file is in
|
// is a normalisation step to ensure that the file is in
|
||||||
// whatever the current version of mapnik uses as the
|
// whatever the current version of mapnik uses as the
|
||||||
// standard indentation, quote style, etc...
|
// standard indentation, quote style, etc...
|
||||||
REQUIRE_NOTHROW(mapnik::load_map(m, xml.generic_string(), false, abs_base.generic_string()));
|
REQUIRE_NOTHROW(mapnik::load_map(m, xml.generic_string(), false, abs_base.generic_string()));
|
||||||
fs::path test_map1 = dir.path() / "mapnik-temp-map1.xml";
|
mapnik::fs::path test_map1 = dir.path() / "mapnik-temp-map1.xml";
|
||||||
REQUIRE_NOTHROW(mapnik::save_map(m, test_map1.generic_string()));
|
REQUIRE_NOTHROW(mapnik::save_map(m, test_map1.generic_string()));
|
||||||
|
|
||||||
// create a new map, load the one saved in the previous
|
// create a new map, load the one saved in the previous
|
||||||
|
@ -112,23 +101,24 @@ void compare_map(fs::path xml)
|
||||||
mapnik::Map new_map(256, 256);
|
mapnik::Map new_map(256, 256);
|
||||||
REQUIRE(new_map.register_fonts("fonts", true));
|
REQUIRE(new_map.register_fonts("fonts", true));
|
||||||
REQUIRE_NOTHROW(mapnik::load_map(new_map, test_map1.generic_string(), false, abs_base.generic_string()));
|
REQUIRE_NOTHROW(mapnik::load_map(new_map, test_map1.generic_string(), false, abs_base.generic_string()));
|
||||||
fs::path test_map2 = dir.path() / "mapnik-temp-map2.xml";
|
mapnik::fs::path test_map2 = dir.path() / "mapnik-temp-map2.xml";
|
||||||
REQUIRE_NOTHROW(mapnik::save_map(new_map, test_map2.generic_string()));
|
REQUIRE_NOTHROW(mapnik::save_map(new_map, test_map2.generic_string()));
|
||||||
|
|
||||||
// if all the information survived the load/save round-trip
|
// if all the information survived the load/save round-trip
|
||||||
// then the two files ought to be identical.
|
// then the two files ought to be identical.
|
||||||
REQUIRE(fs::is_regular_file(test_map1));
|
REQUIRE(mapnik::fs::is_regular_file(test_map1));
|
||||||
REQUIRE(fs::is_regular_file(test_map2));
|
REQUIRE(mapnik::fs::is_regular_file(test_map2));
|
||||||
REQUIRE(fs::file_size(test_map1) == fs::file_size(test_map2));
|
REQUIRE(mapnik::fs::file_size(test_map1) == mapnik::fs::file_size(test_map2));
|
||||||
std::ifstream in_map1(test_map1.native()), in_map2(test_map2.native());
|
std::ifstream in_map1(test_map1.native()), in_map2(test_map2.native());
|
||||||
REQUIRE(std::equal(std::istream_iterator<char>(in_map1),
|
REQUIRE(std::equal(std::istream_iterator<char>(in_map1),
|
||||||
std::istream_iterator<char>(),
|
std::istream_iterator<char>(),
|
||||||
std::istream_iterator<char>(in_map2)));
|
std::istream_iterator<char>(in_map2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_xml_files(fs::path dir, std::vector<fs::path>& xml_files)
|
void add_xml_files(mapnik::fs::path dir, std::vector<mapnik::fs::path>& xml_files)
|
||||||
{
|
{
|
||||||
for (auto const& entry : boost::make_iterator_range(fs::directory_iterator(dir), fs::directory_iterator()))
|
for (auto const& entry :
|
||||||
|
boost::make_iterator_range(mapnik::fs::directory_iterator(dir), mapnik::fs::directory_iterator()))
|
||||||
{
|
{
|
||||||
auto path = entry.path();
|
auto path = entry.path();
|
||||||
if (path.extension().generic_string() == ".xml")
|
if (path.extension().generic_string() == ".xml")
|
||||||
|
@ -138,7 +128,7 @@ void add_xml_files(fs::path dir, std::vector<fs::path>& xml_files)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_map(mapnik::Map& m, fs::path const& path)
|
void load_map(mapnik::Map& m, mapnik::fs::path const& path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -161,7 +151,7 @@ void load_map(mapnik::Map& m, fs::path const& path)
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
#ifndef MAPNIK_STATIC_PLUGINS
|
#ifndef MAPNIK_STATIC_PLUGINS
|
||||||
const bool registered =
|
const bool registered =
|
||||||
mapnik::datasource_cache::instance().register_datasources((fs::path("plugins") / "input").generic_string());
|
mapnik::datasource_cache::instance().register_datasources((mapnik::fs::path("plugins") / "input").generic_string());
|
||||||
#endif
|
#endif
|
||||||
TEST_CASE("map xml I/O")
|
TEST_CASE("map xml I/O")
|
||||||
{
|
{
|
||||||
|
@ -177,8 +167,8 @@ TEST_CASE("map xml I/O")
|
||||||
|
|
||||||
SECTION("good maps")
|
SECTION("good maps")
|
||||||
{
|
{
|
||||||
std::vector<fs::path> good_maps;
|
std::vector<mapnik::fs::path> good_maps;
|
||||||
add_xml_files(fs::path("test") / "data" / "good_maps", good_maps);
|
add_xml_files(mapnik::fs::path("test") / "data" / "good_maps", good_maps);
|
||||||
|
|
||||||
for (auto const& path : good_maps)
|
for (auto const& path : good_maps)
|
||||||
{
|
{
|
||||||
|
@ -197,7 +187,7 @@ TEST_CASE("map xml I/O")
|
||||||
SECTION("duplicate styles only throw in strict mode")
|
SECTION("duplicate styles only throw in strict mode")
|
||||||
{
|
{
|
||||||
std::string duplicate_stylename(
|
std::string duplicate_stylename(
|
||||||
(fs::path("test") / "data" / "broken_maps" / "duplicate_stylename.xml").generic_string());
|
(mapnik::fs::path("test") / "data" / "broken_maps" / "duplicate_stylename.xml").generic_string());
|
||||||
CAPTURE(duplicate_stylename);
|
CAPTURE(duplicate_stylename);
|
||||||
mapnik::Map m(256, 256);
|
mapnik::Map m(256, 256);
|
||||||
REQUIRE(m.register_fonts("fonts", true));
|
REQUIRE(m.register_fonts("fonts", true));
|
||||||
|
@ -209,9 +199,9 @@ TEST_CASE("map xml I/O")
|
||||||
|
|
||||||
SECTION("broken maps")
|
SECTION("broken maps")
|
||||||
{
|
{
|
||||||
std::vector<fs::path> broken_maps;
|
std::vector<mapnik::fs::path> broken_maps;
|
||||||
add_xml_files(fs::path("test") / "data" / "broken_maps", broken_maps);
|
add_xml_files(mapnik::fs::path("test") / "data" / "broken_maps", broken_maps);
|
||||||
broken_maps.emplace_back(fs::path("test") / "data" / "broken_maps" / "does_not_exist.xml");
|
broken_maps.emplace_back(mapnik::fs::path("test") / "data" / "broken_maps" / "does_not_exist.xml");
|
||||||
|
|
||||||
for (auto const& path : broken_maps)
|
for (auto const& path : broken_maps)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,21 +20,12 @@ MAPNIK_DISABLE_WARNING_PUSH
|
||||||
#include <boost/optional/optional_io.hpp>
|
#include <boost/optional/optional_io.hpp>
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
MAPNIK_DISABLE_WARNING_POP
|
||||||
|
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
#include <mapnik/filesystem.hpp>
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
|
||||||
#include <boost/filesystem/convenience.hpp>
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <mapnik/util/mapped_memory_file.hpp>
|
#include <mapnik/util/mapped_memory_file.hpp>
|
||||||
|
|
||||||
inline void make_directory(std::string const& dir)
|
inline void make_directory(std::string const& dir)
|
||||||
{
|
{
|
||||||
fs::create_directories(dir);
|
mapnik::fs::create_directories(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -1,20 +1,8 @@
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
#include <mapnik/cairo_io.hpp>
|
#include <mapnik/cairo_io.hpp>
|
||||||
|
#include <mapnik/filesystem.hpp>
|
||||||
#include <mapnik/util/fs.hpp>
|
#include <mapnik/util/fs.hpp>
|
||||||
|
|
||||||
#include <mapnik/warning.hpp>
|
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
MAPNIK_DISABLE_WARNING_PUSH
|
|
||||||
#include <mapnik/warning_ignore.hpp>
|
|
||||||
#include <boost/filesystem/convenience.hpp>
|
|
||||||
MAPNIK_DISABLE_WARNING_POP
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#if defined(HAVE_CAIRO)
|
#if defined(HAVE_CAIRO)
|
||||||
|
@ -28,7 +16,7 @@ TEST_CASE("cairo_io")
|
||||||
SECTION("save_to_cairo_file - SVG")
|
SECTION("save_to_cairo_file - SVG")
|
||||||
{
|
{
|
||||||
std::string directory_name("/tmp/mapnik-tests/");
|
std::string directory_name("/tmp/mapnik-tests/");
|
||||||
fs::create_directories(directory_name);
|
mapnik::fs::create_directories(directory_name);
|
||||||
REQUIRE(mapnik::util::exists(directory_name));
|
REQUIRE(mapnik::util::exists(directory_name));
|
||||||
|
|
||||||
std::string output_file(directory_name + "test_save_to_cairo_file.svg");
|
std::string output_file(directory_name + "test_save_to_cairo_file.svg");
|
||||||
|
|
|
@ -3,15 +3,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mapnik/mapnik.hpp>
|
#include <mapnik/mapnik.hpp>
|
||||||
|
#include <mapnik/filesystem.hpp>
|
||||||
#include <mapnik/util/fs.hpp>
|
#include <mapnik/util/fs.hpp>
|
||||||
#include <mapnik/datasource_cache.hpp>
|
#include <mapnik/datasource_cache.hpp>
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
#include <boost/filesystem/convenience.hpp>
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "cleanup.hpp" // run_cleanup()
|
#include "cleanup.hpp" // run_cleanup()
|
||||||
|
|
||||||
|
@ -49,7 +43,7 @@ int main(int argc, char** argv)
|
||||||
std::clog << "Could not find " << working_dir << "\n";
|
std::clog << "Could not find " << working_dir << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fs::current_path(working_dir);
|
mapnik::fs::current_path(working_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
|
|
|
@ -28,16 +28,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <mapnik/filesystem.hpp>
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
// boost
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <mapnik/geometry/box2d.hpp>
|
#include <mapnik/geometry/box2d.hpp>
|
||||||
|
|
||||||
namespace visual_tests {
|
namespace visual_tests {
|
||||||
|
@ -82,8 +73,8 @@ struct result
|
||||||
map_size size;
|
map_size size;
|
||||||
map_size tiles;
|
map_size tiles;
|
||||||
double scale_factor;
|
double scale_factor;
|
||||||
fs::path actual_image_path;
|
mapnik::fs::path actual_image_path;
|
||||||
fs::path reference_image_path;
|
mapnik::fs::path reference_image_path;
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
unsigned diff;
|
unsigned diff;
|
||||||
std::chrono::high_resolution_clock::duration duration;
|
std::chrono::high_resolution_clock::duration duration;
|
||||||
|
|
|
@ -57,14 +57,7 @@
|
||||||
#include <mapnik/svg/output/svg_renderer.hpp>
|
#include <mapnik/svg/output/svg_renderer.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
#include <mapnik/filesystem.hpp>
|
||||||
#include <filesystem>
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
// boost
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace visual_tests {
|
namespace visual_tests {
|
||||||
|
|
||||||
|
@ -76,7 +69,7 @@ struct raster_renderer_base
|
||||||
static constexpr const char* ext = ".png";
|
static constexpr const char* ext = ".png";
|
||||||
static constexpr const bool support_tiles = true;
|
static constexpr const bool support_tiles = true;
|
||||||
|
|
||||||
unsigned compare(image_type const& actual, fs::path const& reference) const
|
unsigned compare(image_type const& actual, mapnik::fs::path const& reference) const
|
||||||
{
|
{
|
||||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(reference.string(), "png"));
|
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(reference.string(), "png"));
|
||||||
if (!reader.get())
|
if (!reader.get())
|
||||||
|
@ -90,7 +83,7 @@ struct raster_renderer_base
|
||||||
return mapnik::compare(actual, reference_image, 0, true);
|
return mapnik::compare(actual, reference_image, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save(image_type const& image, fs::path const& path) const
|
void save(image_type const& image, mapnik::fs::path const& path) const
|
||||||
{
|
{
|
||||||
mapnik::save_to_file(image, path.string(), "png32");
|
mapnik::save_to_file(image, path.string(), "png32");
|
||||||
}
|
}
|
||||||
|
@ -102,7 +95,7 @@ struct vector_renderer_base
|
||||||
|
|
||||||
static constexpr const bool support_tiles = false;
|
static constexpr const bool support_tiles = false;
|
||||||
|
|
||||||
unsigned compare(image_type const& actual, fs::path const& reference) const
|
unsigned compare(image_type const& actual, mapnik::fs::path const& reference) const
|
||||||
{
|
{
|
||||||
std::ifstream stream(reference.string().c_str(), std::ios_base::in | std::ios_base::binary);
|
std::ifstream stream(reference.string().c_str(), std::ios_base::in | std::ios_base::binary);
|
||||||
if (!stream)
|
if (!stream)
|
||||||
|
@ -113,7 +106,7 @@ struct vector_renderer_base
|
||||||
return std::max(actual.size(), expected.size()) - std::min(actual.size(), expected.size());
|
return std::max(actual.size(), expected.size()) - std::min(actual.size(), expected.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void save(image_type const& image, fs::path const& path) const
|
void save(image_type const& image, mapnik::fs::path const& path) const
|
||||||
{
|
{
|
||||||
std::ofstream file(path.string().c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
|
std::ofstream file(path.string().c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
|
||||||
if (!file)
|
if (!file)
|
||||||
|
@ -308,7 +301,7 @@ class renderer
|
||||||
using renderer_type = Renderer;
|
using renderer_type = Renderer;
|
||||||
using image_type = typename Renderer::image_type;
|
using image_type = typename Renderer::image_type;
|
||||||
|
|
||||||
renderer(fs::path const& _output_dir, fs::path const& _reference_dir, bool _overwrite)
|
renderer(mapnik::fs::path const& _output_dir, mapnik::fs::path const& _reference_dir, bool _overwrite)
|
||||||
: ren()
|
: ren()
|
||||||
, output_dir(_output_dir)
|
, output_dir(_output_dir)
|
||||||
, reference_dir(_reference_dir)
|
, reference_dir(_reference_dir)
|
||||||
|
@ -346,8 +339,8 @@ class renderer
|
||||||
map_size const& tiles,
|
map_size const& tiles,
|
||||||
double scale_factor) const
|
double scale_factor) const
|
||||||
{
|
{
|
||||||
fs::path reference = reference_dir / image_file_name(name, size, tiles, scale_factor, true);
|
mapnik::fs::path reference = reference_dir / image_file_name(name, size, tiles, scale_factor, true);
|
||||||
bool reference_exists = fs::exists(reference);
|
bool reference_exists = mapnik::fs::exists(reference);
|
||||||
result res;
|
result res;
|
||||||
|
|
||||||
res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
|
res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
|
||||||
|
@ -361,8 +354,8 @@ class renderer
|
||||||
|
|
||||||
if (res.diff)
|
if (res.diff)
|
||||||
{
|
{
|
||||||
fs::create_directories(output_dir);
|
mapnik::fs::create_directories(output_dir);
|
||||||
fs::path path = output_dir / image_file_name(name, size, tiles, scale_factor, false);
|
mapnik::fs::path path = output_dir / image_file_name(name, size, tiles, scale_factor, false);
|
||||||
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);
|
||||||
|
@ -400,8 +393,8 @@ class renderer
|
||||||
}
|
}
|
||||||
|
|
||||||
const Renderer ren;
|
const Renderer ren;
|
||||||
const fs::path output_dir;
|
const mapnik::fs::path output_dir;
|
||||||
const fs::path reference_dir;
|
const mapnik::fs::path reference_dir;
|
||||||
const bool overwrite;
|
const bool overwrite;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ void console_short_report::report(result const& r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void html_report::report(result const& r, fs::path const& output_dir)
|
void html_report::report(result const& r, mapnik::fs::path const& output_dir)
|
||||||
{
|
{
|
||||||
if (r.state == STATE_ERROR)
|
if (r.state == STATE_ERROR)
|
||||||
{
|
{
|
||||||
|
@ -180,8 +180,7 @@ void html_report::report(result const& r, fs::path const& output_dir)
|
||||||
}
|
}
|
||||||
else if (r.state == STATE_FAIL)
|
else if (r.state == STATE_FAIL)
|
||||||
{
|
{
|
||||||
using namespace fs;
|
using namespace mapnik::fs;
|
||||||
|
|
||||||
path reference = output_dir / r.reference_image_path.filename();
|
path reference = output_dir / r.reference_image_path.filename();
|
||||||
path actual = output_dir / r.actual_image_path.filename();
|
path actual = output_dir / r.actual_image_path.filename();
|
||||||
|
|
||||||
|
@ -238,7 +237,7 @@ constexpr const char* html_footer = R"template(</div>
|
||||||
</body>
|
</body>
|
||||||
</html>)template";
|
</html>)template";
|
||||||
|
|
||||||
void html_report::summary(result_list const& results, fs::path const& output_dir)
|
void html_report::summary(result_list const& results, mapnik::fs::path const& output_dir)
|
||||||
{
|
{
|
||||||
s << html_header;
|
s << html_header;
|
||||||
|
|
||||||
|
@ -253,11 +252,11 @@ void html_report::summary(result_list const& results, fs::path const& output_dir
|
||||||
s << html_footer;
|
s << html_footer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void html_summary(result_list const& results, fs::path output_dir)
|
void html_summary(result_list const& results, mapnik::fs::path output_dir)
|
||||||
{
|
{
|
||||||
fs::path html_root = output_dir / "visual-test-results";
|
mapnik::fs::path html_root = output_dir / "visual-test-results";
|
||||||
fs::create_directories(html_root);
|
mapnik::fs::create_directories(html_root);
|
||||||
fs::path html_report_path = html_root / "index.html";
|
mapnik::fs::path html_report_path = html_root / "index.html";
|
||||||
std::clog << "View failure report at " << html_report_path << "\n";
|
std::clog << "View failure report at " << html_report_path << "\n";
|
||||||
std::ofstream output_file(html_report_path.string());
|
std::ofstream output_file(html_report_path.string());
|
||||||
html_report report(output_file);
|
html_report report(output_file);
|
||||||
|
|
|
@ -76,8 +76,8 @@ class html_report
|
||||||
: s(_s)
|
: s(_s)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void report(result const& r, fs::path const& output_dir);
|
void report(result const& r, mapnik::fs::path const& output_dir);
|
||||||
void summary(result_list const& results, fs::path const& output_dir);
|
void summary(result_list const& results, mapnik::fs::path const& output_dir);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::ostream& s;
|
std::ostream& s;
|
||||||
|
@ -119,7 +119,7 @@ class summary_visitor
|
||||||
result_list const& result_;
|
result_list const& result_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void html_summary(result_list const& results, fs::path output_dir);
|
void html_summary(result_list const& results, mapnik::fs::path output_dir);
|
||||||
|
|
||||||
} // namespace visual_tests
|
} // namespace visual_tests
|
||||||
|
|
||||||
|
|
|
@ -59,19 +59,15 @@ std::string unique_name()
|
||||||
{
|
{
|
||||||
std::mt19937 gen(entropy());
|
std::mt19937 gen(entropy());
|
||||||
std::uniform_int_distribution<> distrib(0, 65535);
|
std::uniform_int_distribution<> distrib(0, 65535);
|
||||||
auto fmt = boost::format("%1$04x-%2$04x-%3$04x-%4$04x")
|
auto fmt = boost::format("%1$04x-%2$04x-%3$04x-%4$04x") % distrib(gen) % distrib(gen) % distrib(gen) % distrib(gen);
|
||||||
% distrib(gen)
|
|
||||||
% distrib(gen)
|
|
||||||
% distrib(gen)
|
|
||||||
%distrib(gen);
|
|
||||||
return fmt.str();
|
return fmt.str();
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
runner::renderer_container
|
runner::renderer_container
|
||||||
create_renderers(po::variables_map const& args, fs::path const& output_dir, bool force_append = false)
|
create_renderers(po::variables_map const& args, mapnik::fs::path const& output_dir, bool force_append = false)
|
||||||
{
|
{
|
||||||
fs::path reference_dir(args["images-dir"].as<std::string>());
|
mapnik::fs::path reference_dir(args["images-dir"].as<std::string>());
|
||||||
bool overwrite = args.count("overwrite");
|
bool overwrite = args.count("overwrite");
|
||||||
runner::renderer_container renderers;
|
runner::renderer_container renderers;
|
||||||
|
|
||||||
|
@ -205,7 +201,7 @@ int main(int argc, char** argv)
|
||||||
mapnik::freetype_engine::register_fonts(vm["fonts"].as<std::string>(), true);
|
mapnik::freetype_engine::register_fonts(vm["fonts"].as<std::string>(), true);
|
||||||
mapnik::datasource_cache::instance().register_datasources(vm["plugins"].as<std::string>());
|
mapnik::datasource_cache::instance().register_datasources(vm["plugins"].as<std::string>());
|
||||||
|
|
||||||
fs::path output_dir(vm["output-dir"].as<std::string>());
|
mapnik::fs::path output_dir(vm["output-dir"].as<std::string>());
|
||||||
|
|
||||||
if (vm.count("unique-subdir"))
|
if (vm.count("unique-subdir"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -149,8 +149,8 @@ runner::runner(runner::path_type const& styles_dir,
|
||||||
|
|
||||||
result_list runner::test_all(report_type& report) const
|
result_list runner::test_all(report_type& report) const
|
||||||
{
|
{
|
||||||
fs::directory_iterator begin(styles_dir_);
|
mapnik::fs::directory_iterator begin(styles_dir_);
|
||||||
fs::directory_iterator end;
|
mapnik::fs::directory_iterator end;
|
||||||
std::vector<runner::path_type> files(begin, end);
|
std::vector<runner::path_type> files(begin, end);
|
||||||
return test_parallel(files, report, jobs_);
|
return test_parallel(files, report, jobs_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace visual_tests {
|
||||||
|
|
||||||
class runner
|
class runner
|
||||||
{
|
{
|
||||||
using path_type = fs::path;
|
using path_type = mapnik::fs::path;
|
||||||
using files_iterator = std::vector<path_type>::const_iterator;
|
using files_iterator = std::vector<path_type>::const_iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue