2019-02-08 13:32:01 +01:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include <mapnik/cairo_io.hpp>
|
|
|
|
#include <mapnik/util/fs.hpp>
|
|
|
|
|
2020-11-19 15:30:30 +01:00
|
|
|
#include <mapnik/warning.hpp>
|
2023-03-09 14:17:28 +01:00
|
|
|
#if __cplusplus >= 201703L && !defined(USE_BOOST_FILESYSTEM)
|
|
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
#else
|
2020-11-19 15:30:30 +01:00
|
|
|
MAPNIK_DISABLE_WARNING_PUSH
|
2019-02-08 13:32:01 +01:00
|
|
|
#include <mapnik/warning_ignore.hpp>
|
|
|
|
#include <boost/filesystem/convenience.hpp>
|
2020-11-19 15:30:30 +01:00
|
|
|
MAPNIK_DISABLE_WARNING_POP
|
2023-03-09 14:17:28 +01:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
#endif
|
2019-02-08 13:32:01 +01:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#if defined(HAVE_CAIRO)
|
2022-04-05 10:31:26 +02:00
|
|
|
#include <cairo-version.h>
|
|
|
|
|
|
|
|
// see https://gitlab.freedesktop.org/cairo/cairo/-/issues/553
|
|
|
|
// TLDR: cairo has removed the writing of the svg version in cairo 1.17.6
|
|
|
|
#if (CAIRO_VERSION_MAJOR <= 1) && (CAIRO_VERSION_MINOR <= 17) && (CAIRO_VERSION_MICRO < 6)
|
2022-01-26 23:25:53 +01:00
|
|
|
TEST_CASE("cairo_io")
|
|
|
|
{
|
|
|
|
SECTION("save_to_cairo_file - SVG")
|
|
|
|
{
|
|
|
|
std::string directory_name("/tmp/mapnik-tests/");
|
2023-03-09 14:17:28 +01:00
|
|
|
fs::create_directories(directory_name);
|
2022-01-26 23:25:53 +01:00
|
|
|
REQUIRE(mapnik::util::exists(directory_name));
|
2019-02-08 13:32:01 +01:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
std::string output_file(directory_name + "test_save_to_cairo_file.svg");
|
2019-02-08 13:32:01 +01:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
mapnik::Map map(256, 256);
|
|
|
|
mapnik::save_to_cairo_file(map, output_file);
|
2019-02-08 13:32:01 +01:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
std::ifstream stream(output_file, std::ios_base::in | std::ios_base::binary);
|
|
|
|
std::string actual_output(std::istreambuf_iterator<char>(stream.rdbuf()), std::istreambuf_iterator<char>());
|
2019-02-08 13:32:01 +01:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
// Check the Cairo SVG surface is using SVG 1.2
|
|
|
|
CHECK(actual_output.find("version=\"1.2\"") != std::string::npos);
|
|
|
|
}
|
2019-02-08 13:32:01 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-04-05 10:31:26 +02:00
|
|
|
#endif
|