Added template specialization svg_renderer<std::ofstream> to output SVG to file. Run tests/cpp_tests/svg_renderer_tests/file_output_test.cpp to generate one.
This commit is contained in:
parent
94e8ee3a9f
commit
f2a419bda7
12 changed files with 110 additions and 0 deletions
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(building_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(building_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(glyph_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(glyph_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(line_pattern_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(line_pattern_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(line_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(line_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(markers_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(markers_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(point_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(point_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(polygon_pattern_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(polygon_pattern_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(polygon_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(polygon_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(raster_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(raster_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(shield_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(shield_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ namespace mapnik
|
|||
template void svg_renderer<std::ostringstream>::process(text_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
|
||||
template void svg_renderer<std::ofstream>::process(text_symbolizer const& sym,
|
||||
Feature const& feature,
|
||||
proj_transform const& prj_trans);
|
||||
}
|
||||
|
|
66
tests/cpp_tests/svg_renderer_tests/file_output_test.cpp
Normal file
66
tests/cpp_tests/svg_renderer_tests/file_output_test.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#define BOOST_TEST_MODULE file_output_test
|
||||
|
||||
/*
|
||||
* This test module contains test cases that
|
||||
* verify the correct generation of SVG output
|
||||
* using file streams as destinations.
|
||||
*/
|
||||
|
||||
// boost.test
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
// boost.filesystem
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/svg_renderer.hpp>
|
||||
#include <mapnik/color_factory.hpp>
|
||||
|
||||
// stl
|
||||
#include <fstream>
|
||||
|
||||
namespace filesystem = boost::filesystem;
|
||||
|
||||
/*
|
||||
* This test case tests the generation of an SVG document
|
||||
* using a file stream. It uses svg_renderer parameterized
|
||||
* with an std::ofstream as a target for output.
|
||||
*
|
||||
* It's important to notice that svg_renderer doesn't create
|
||||
* or close the file stream, but leaves that task to the client.
|
||||
*
|
||||
* The test fails if the file can't be created and succeeds
|
||||
* otherwise.
|
||||
*
|
||||
* Note: the file is created in the directory in which the
|
||||
* test is run.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(file_output_test_case)
|
||||
{
|
||||
using namespace mapnik;
|
||||
typedef svg_renderer<std::ofstream> svg_ren;
|
||||
|
||||
Map map(800, 600);
|
||||
map.set_background(color_factory::from_string("blue"));
|
||||
|
||||
std::string output_filename = "file_output_test_case.svg";
|
||||
std::ofstream output_stream(output_filename.c_str());
|
||||
|
||||
if(output_stream)
|
||||
{
|
||||
svg_ren renderer(map, output_stream);
|
||||
renderer.apply();
|
||||
|
||||
output_stream.close();
|
||||
|
||||
filesystem::path output_filename_path =
|
||||
filesystem::system_complete(filesystem::path(".")) / filesystem::path(output_filename);
|
||||
|
||||
BOOST_CHECK_MESSAGE(filesystem::exists(output_filename_path), "File '"+output_filename_path.string()+"' was created.");
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_FAIL("Could not create create/open file 'file_output_test_case.svg'.");
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue