2010-07-21 09:43:13 +02:00
|
|
|
#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>
|
2012-08-28 02:58:49 +02:00
|
|
|
#include <mapnik/svg/output/svg_renderer.hpp>
|
2010-07-21 09:43:13 +02:00
|
|
|
#include <mapnik/color_factory.hpp>
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <fstream>
|
2010-07-22 06:48:11 +02:00
|
|
|
#include <iterator>
|
2010-07-21 09:43:13 +02:00
|
|
|
|
2012-10-31 03:21:34 +01:00
|
|
|
namespace fs = boost::filesystem;
|
2010-07-21 09:43:13 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2010-07-22 06:48:11 +02:00
|
|
|
typedef svg_renderer<std::ostream_iterator<char> > svg_ren;
|
2010-07-21 09:43:13 +02:00
|
|
|
|
|
|
|
Map map(800, 600);
|
2012-08-29 19:44:04 +02:00
|
|
|
map.set_background(parse_color("blue"));
|
2010-07-21 09:43:13 +02:00
|
|
|
|
|
|
|
std::string output_filename = "file_output_test_case.svg";
|
|
|
|
std::ofstream output_stream(output_filename.c_str());
|
|
|
|
|
|
|
|
if(output_stream)
|
|
|
|
{
|
2011-05-04 17:53:36 +02:00
|
|
|
std::ostream_iterator<char> output_stream_iterator(output_stream);
|
2012-04-17 07:33:37 +02:00
|
|
|
|
2011-05-04 17:53:36 +02:00
|
|
|
svg_ren renderer(map, output_stream_iterator);
|
|
|
|
renderer.apply();
|
2012-04-17 07:33:37 +02:00
|
|
|
|
2011-05-04 17:53:36 +02:00
|
|
|
output_stream.close();
|
2012-04-17 07:33:37 +02:00
|
|
|
|
2012-10-31 03:21:34 +01:00
|
|
|
fs::path output_filename_path =
|
|
|
|
fs::system_complete(fs::path(".")) / fs::path(output_filename);
|
2012-04-17 07:33:37 +02:00
|
|
|
|
2012-10-31 03:21:34 +01:00
|
|
|
BOOST_CHECK_MESSAGE(fs::exists(output_filename_path), "File '"+output_filename_path.string()+"' was created.");
|
2010-07-21 09:43:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-04 17:53:36 +02:00
|
|
|
BOOST_FAIL("Could not create create/open file '"+output_filename+"'.");
|
2010-07-21 09:43:13 +02:00
|
|
|
}
|
|
|
|
}
|