format c++ tests

This commit is contained in:
Dane Springmeyer 2012-04-16 22:33:37 -07:00
parent b0d857a66a
commit e986bce7f6
8 changed files with 266 additions and 266 deletions

View file

@ -9,70 +9,70 @@ namespace sys = boost::system;
int main( int, char*[] )
{
std::string fontdir("fonts/");
BOOST_TEST( fs::exists( fontdir ) );
BOOST_TEST( fs::is_directory( fontdir ) );
std::string fontdir("fonts/");
std::vector<std::string> face_names;
BOOST_TEST( fs::exists( fontdir ) );
BOOST_TEST( fs::is_directory( fontdir ) );
std::string foo("foo");
std::vector<std::string> face_names;
// fake directories
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo , true ) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
std::string foo("foo");
// directories without fonts
std::string src("src");
// an empty directory will not return true
// we need to register at least one font and not fail on any
// to return true
BOOST_TEST( mapnik::freetype_engine::register_font(src) == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts(src, true) == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
// fake directories
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo , true ) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo) );
face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 0 );
// bogus, emtpy file that looks like font
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/fake.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/fake.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
// directories without fonts
std::string src("src");
// an empty directory will not return true
// we need to register at least one font and not fail on any
// to return true
BOOST_TEST( mapnik::freetype_engine::register_font(src) == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts(src, true) == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/intentionally-broken.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/intentionally-broken.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
// bogus, emtpy file that looks like font
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/fake.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/fake.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
// register unifont, since we know it sits in the root fonts/ dir
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() > 0 );
BOOST_TEST( face_names.size() == 1 );
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/intentionally-broken.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/intentionally-broken.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
// re-register unifont, should not have any affect
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 1 );
// register unifont, since we know it sits in the root fonts/ dir
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() > 0 );
BOOST_TEST( face_names.size() == 1 );
// register a single dejavu font
std::string dejavu_bold_oblique("tests/data/fonts/DejaVuSansMono-BoldOblique.ttf");
BOOST_TEST( mapnik::freetype_engine::register_font(dejavu_bold_oblique) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 2 );
// re-register unifont, should not have any affect
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 1 );
// recurse to find all dejavu fonts
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 22 );
// register a single dejavu font
std::string dejavu_bold_oblique("tests/data/fonts/DejaVuSansMono-BoldOblique.ttf");
BOOST_TEST( mapnik::freetype_engine::register_font(dejavu_bold_oblique) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 2 );
if (!::boost::detail::test_errors()) {
std::clog << "C++ fonts registration: \x1b[1;32m✓ \x1b[0m\n";
} else {
return ::boost::report_errors();
}
// recurse to find all dejavu fonts
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) );
face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 22 );
if (!::boost::detail::test_errors()) {
std::clog << "C++ fonts registration: \x1b[1;32m✓ \x1b[0m\n";
} else {
return ::boost::report_errors();
}
}

View file

@ -7,71 +7,71 @@
int main( int, char*[] )
{
mapnik::parameters params;
// true
params["bool"] = true;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
mapnik::parameters params;
params["bool"] = "true";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
// true
params["bool"] = true;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = 1;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "true";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "1";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = 1;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "True";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "1";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "on";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "True";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "yes";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "on";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
// false
params["bool"] = false;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = "yes";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "false";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
// false
params["bool"] = false;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = 0;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "false";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = "0";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = 0;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "False";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "0";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "off";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "False";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "no";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "off";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
// strings
params["string"] = "hello";
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
params["bool"] = "no";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
// int
params["int"] = 1;
BOOST_TEST( (params.get<int>("int") && *params.get<int>("int") == 1) );
// strings
params["string"] = "hello";
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
// double
params["double"] = 1.5;
BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) );
// int
params["int"] = 1;
BOOST_TEST( (params.get<int>("int") && *params.get<int>("int") == 1) );
// value_null
params["null"] = mapnik::value_null();
//BOOST_TEST( (params.get<mapnik::value_null>("null")/* && *params.get<mapnik::value_null>("null") == mapnik::value_null()*/) );
// double
params["double"] = 1.5;
BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) );
if (!::boost::detail::test_errors()) {
std::clog << "C++ parameters: \x1b[1;32m✓ \x1b[0m\n";
} else {
return ::boost::report_errors();
}
// value_null
params["null"] = mapnik::value_null();
//BOOST_TEST( (params.get<mapnik::value_null>("null")/* && *params.get<mapnik::value_null>("null") == mapnik::value_null()*/) );
if (!::boost::detail::test_errors()) {
std::clog << "C++ parameters: \x1b[1;32m✓ \x1b[0m\n";
} else {
return ::boost::report_errors();
}
}

View file

@ -1,7 +1,7 @@
#define BOOST_TEST_MODULE background_color_test
/*
* This test module contains several generators for
* This test module contains several generators for
* the implementation of a background color in SVG
* using a rectangle.
*/
@ -25,16 +25,16 @@ namespace repository = boost::spirit::repository;
namespace fusion = boost::fusion;
using namespace karma;
struct F
struct F
{
F() :
x(0),
y(0),
width(100),
height(100),
bgcolor("#ffffff"),
expected_output("<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" style=\"fill: #ffffff\"/>") {}
x(0),
y(0),
width(100),
height(100),
bgcolor("#ffffff"),
expected_output("<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" style=\"fill: #ffffff\"/>") {}
~F() {}
const int x;
@ -61,14 +61,14 @@ struct F
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
{
actual_output
<< format(
"<rect x=\"" << int_ << "\" "
<< "y=\"" << int_ << "\" "
<< "width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" "
<< "style=\"fill: " << string << "\""
<< "/>",
x, y, width, "px", height, "px", bgcolor);
<< format(
"<rect x=\"" << int_ << "\" "
<< "y=\"" << int_ << "\" "
<< "width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" "
<< "style=\"fill: " << string << "\""
<< "/>",
x, y, width, "px", height, "px", bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
@ -79,7 +79,7 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
*
* Notice that the generators' attribute list contains also tuples.
* Tuples are needed to specify each confix's attributes that contain
* more than one generator, like confix()[int_ << string] (this
* more than one generator, like confix()[int_ << string] (this
* generator needs a tuple: tuple<int, string>).
*
* The difference between this generator and the one in test case
@ -92,15 +92,15 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
using fusion::tuple;
actual_output
<< format(
"<rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]
<< "/>",
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
<< format(
"<rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]
<< "/>",
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
@ -109,11 +109,11 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
* using confix. notice that a confix generator can be part of another
* confix generator's expression.
*
* Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each
* generator is meant to have a list of attributes if it has more than one.
* Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each
* generator is meant to have a list of attributes if it has more than one.
*
* If the generator is nested inside another generator, the former's attribute
* If the generator is nested inside another generator, the former's attribute
* list will be another list (a tuple, for example) inside the latter's.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F)
@ -122,15 +122,15 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F)
using fusion::tuple;
actual_output
<< format(
confix('<', "/>")[
"rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
<< format(
confix('<', "/>")[
"rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
@ -152,14 +152,14 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_iterator_test_case, F)
std::ostream_iterator<char> actual_output_iterator(actual_output);
generate(
actual_output_iterator,
confix("<", "/>")[
"rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
actual_output_iterator,
confix("<", "/>")[
"rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}

View file

@ -37,21 +37,21 @@ BOOST_AUTO_TEST_CASE(combined_test_case)
svg_ren renderer(map, output_stream_iterator);
renderer.apply();
/*std::string expected_output =
svg_ren::XML_DECLARATION
+ "\n"
+ svg_ren::SVG_DTD
+ "\n"
+ "<svg width=\"800px\" height=\"600px\" version=\"1.1\" xmlns=\""
+ svg_ren::SVG_NAMESPACE_URL
+ "\">"
+"\n"
+"<rect x=\"0\" y=\"0\" width=\"800px\" height=\"600px\" style=\"fill: #ffffff\"/>"
+"\n"
+"</svg>";
/*std::string expected_output =
svg_ren::XML_DECLARATION
+ "\n"
+ svg_ren::SVG_DTD
+ "\n"
+ "<svg width=\"800px\" height=\"600px\" version=\"1.1\" xmlns=\""
+ svg_ren::SVG_NAMESPACE_URL
+ "\">"
+"\n"
+"<rect x=\"0\" y=\"0\" width=\"800px\" height=\"600px\" style=\"fill: #ffffff\"/>"
+"\n"
+"</svg>";
std::string actual_output = output_stream.str();
BOOST_CHECK_EQUAL(actual_output, expected_output);
std::string actual_output = output_stream.str();
BOOST_CHECK_EQUAL(actual_output, expected_output);
*/
}

View file

@ -51,15 +51,15 @@ BOOST_AUTO_TEST_CASE(file_output_test_case)
if(output_stream)
{
std::ostream_iterator<char> output_stream_iterator(output_stream);
svg_ren renderer(map, output_stream_iterator);
renderer.apply();
output_stream.close();
filesystem::path output_filename_path =
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

View file

@ -25,54 +25,54 @@ namespace filesystem = boost::filesystem;
using namespace mapnik;
void prepare_map(Map& m)
{
{
const std::string mapnik_dir("/usr/local/lib/mapnik/");
std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "input/" << "\n";
datasource_cache::instance()->register_datasources(mapnik_dir + "input/");
datasource_cache::instance()->register_datasources(mapnik_dir + "input/");
// create styles
// Provinces (polygon)
feature_type_style provpoly_style;
rule provpoly_rule_on;
provpoly_rule_on.set_filter(parse_expression("[NAME_EN] = 'Ontario'"));
provpoly_rule_on.append(polygon_symbolizer(color(250, 190, 183)));
provpoly_style.add_rule(provpoly_rule_on);
rule provpoly_rule_qc;
provpoly_rule_qc.set_filter(parse_expression("[NOM_FR] = 'Québec'"));
provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203)));
provpoly_style.add_rule(provpoly_rule_qc);
m.insert_style("provinces",provpoly_style);
// Provinces (polyline)
feature_type_style provlines_style;
stroke provlines_stk (color(0,0,0),1.0);
provlines_stk.add_dash(8, 4);
provlines_stk.add_dash(2, 2);
provlines_stk.add_dash(2, 2);
rule provlines_rule;
provlines_rule.append(line_symbolizer(provlines_stk));
provlines_style.add_rule(provlines_rule);
m.insert_style("provlines",provlines_style);
// Drainage
// Drainage
feature_type_style qcdrain_style;
rule qcdrain_rule;
qcdrain_rule.set_filter(parse_expression("[HYC] = 8"));
qcdrain_rule.append(polygon_symbolizer(color(153, 204, 255)));
qcdrain_style.add_rule(qcdrain_rule);
m.insert_style("drainage",qcdrain_style);
// Roads 3 and 4 (The "grey" roads)
feature_type_style roads34_style;
feature_type_style roads34_style;
rule roads34_rule;
roads34_rule.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
stroke roads34_rule_stk(color(171,158,137),2.0);
@ -80,9 +80,9 @@ void prepare_map(Map& m)
roads34_rule_stk.set_line_join(ROUND_JOIN);
roads34_rule.append(line_symbolizer(roads34_rule_stk));
roads34_style.add_rule(roads34_rule);
m.insert_style("smallroads",roads34_style);
// Roads 2 (The thin yellow ones)
feature_type_style roads2_style_1;
rule roads2_rule_1;
@ -92,9 +92,9 @@ void prepare_map(Map& m)
roads2_rule_stk_1.set_line_join(ROUND_JOIN);
roads2_rule_1.append(line_symbolizer(roads2_rule_stk_1));
roads2_style_1.add_rule(roads2_rule_1);
m.insert_style("road-border", roads2_style_1);
feature_type_style roads2_style_2;
rule roads2_rule_2;
roads2_rule_2.set_filter(parse_expression("[CLASS] = 2"));
@ -103,9 +103,9 @@ void prepare_map(Map& m)
roads2_rule_stk_2.set_line_join(ROUND_JOIN);
roads2_rule_2.append(line_symbolizer(roads2_rule_stk_2));
roads2_style_2.add_rule(roads2_rule_2);
m.insert_style("road-fill", roads2_style_2);
// Roads 1 (The big orange ones, the highways)
feature_type_style roads1_style_1;
rule roads1_rule_1;
@ -116,7 +116,7 @@ void prepare_map(Map& m)
roads1_rule_1.append(line_symbolizer(roads1_rule_stk_1));
roads1_style_1.add_rule(roads1_rule_1);
m.insert_style("highway-border", roads1_style_1);
feature_type_style roads1_style_2;
rule roads1_rule_2;
roads1_rule_2.set_filter(parse_expression("[CLASS] = 1"));
@ -125,21 +125,21 @@ void prepare_map(Map& m)
roads1_rule_stk_2.set_line_join(ROUND_JOIN);
roads1_rule_2.append(line_symbolizer(roads1_rule_stk_2));
roads1_style_2.add_rule(roads1_rule_2);
m.insert_style("highway-fill", roads1_style_2);
m.insert_style("highway-fill", roads1_style_2);
// layers
// Provincial polygons
{
parameters p;
p["type"]="shape";
p["file"]="../../../demo/data/boundaries";
layer lyr("Provinces");
layer lyr("Provinces");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("provinces");
lyr.add_style("provinces");
m.addLayer(lyr);
}
// Drainage
{
parameters p;
@ -147,46 +147,46 @@ void prepare_map(Map& m)
p["file"]="../../../demo/data/qcdrainage";
layer lyr("Quebec Hydrography");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("drainage");
lyr.add_style("drainage");
m.addLayer(lyr);
}
{
parameters p;
p["type"]="shape";
p["file"]="../../../demo/data/ontdrainage";
layer lyr("Ontario Hydrography");
layer lyr("Ontario Hydrography");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("drainage");
lyr.add_style("drainage");
m.addLayer(lyr);
}
// Provincial boundaries
{
parameters p;
p["type"]="shape";
p["file"]="../../../demo/data/boundaries_l";
layer lyr("Provincial borders");
layer lyr("Provincial borders");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("provlines");
lyr.add_style("provlines");
m.addLayer(lyr);
}
// Roads
{
parameters p;
p["type"]="shape";
p["file"]="../../../demo/data/roads";
layer lyr("Roads");
p["file"]="../../../demo/data/roads";
layer lyr("Roads");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("smallroads");
lyr.add_style("road-border");
lyr.add_style("road-fill");
lyr.add_style("highway-border");
lyr.add_style("highway-fill");
m.addLayer(lyr);
m.addLayer(lyr);
}
}
@ -197,19 +197,19 @@ void render_to_file(Map const& m, const std::string output_filename)
if(output_stream)
{
typedef svg_renderer<std::ostream_iterator<char> > svg_ren;
std::ostream_iterator<char> output_stream_iterator(output_stream);
svg_ren renderer(m, output_stream_iterator);
renderer.apply();
output_stream.close();
filesystem::path output_filename_path =
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.");
BOOST_CHECK_MESSAGE(filesystem::exists(output_filename_path),
"File '"+output_filename_path.string()+"' was created.");
}
else
{
@ -220,12 +220,12 @@ void render_to_file(Map const& m, const std::string output_filename)
BOOST_AUTO_TEST_CASE(path_element_test_case_1)
{
Map m(800,600);
m.set_background(color_factory::from_string("steelblue"));
m.set_background(color_factory::from_string("steelblue"));
prepare_map(m);
//m.zoom_to_box(box2d<double>(1405120.04127408, -247003.813399447,
//1706357.31328276, -25098.593149577));
m.zoom_all();
//1706357.31328276, -25098.593149577));
m.zoom_all();
render_to_file(m, "path_element_test_case_1.svg");
}

View file

@ -1,7 +1,7 @@
#define BOOST_TEST_MODULE root_element_test
/*
* This test module contains several generators for
* This test module contains several generators for
* the SVG root element.
*/
@ -24,14 +24,14 @@ namespace repository = boost::spirit::repository;
namespace fusion = boost::fusion;
using namespace karma;
struct F
struct F
{
F() :
width(100),
height(100),
version(1.1),
xmlns("http://www.w3.org/2000/svg"),
expected_output("<svg width=\"100px\" height=\"100px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">") {}
width(100),
height(100),
version(1.1),
xmlns("http://www.w3.org/2000/svg"),
expected_output("<svg width=\"100px\" height=\"100px\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">") {}
~F() {}
@ -58,13 +58,13 @@ struct F
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
{
actual_output
<< format(
"<svg width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" "
<< "version=\"" << float_ << "\" "
<< "xmlns=\"" << string << "\""
<< ">",
width, "px", height, "px", version, xmlns);
<< format(
"<svg width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" "
<< "version=\"" << float_ << "\" "
<< "xmlns=\"" << string << "\""
<< ">",
width, "px", height, "px", version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
@ -75,7 +75,7 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
*
* Notice that the generators' attribute list contains also tuples.
* Tuples are needed to specify each confix's attributes that contain
* more than one generator, like confix()[int_ << string] (this
* more than one generator, like confix()[int_ << string] (this
* generator needs a tuple: tuple<int, string>).
*
* The difference between this generator and the one in test case
@ -88,14 +88,14 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
using fusion::tuple;
actual_output
<< format(
"<svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]
<< ">",
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
<< format(
"<svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]
<< ">",
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
@ -104,11 +104,11 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
* using confix. notice that a confix generator can be part of another
* confix generator's expression.
*
* Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each
* generator is meant to have a list of attributes if it has more than one.
* Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each
* generator is meant to have a list of attributes if it has more than one.
*
* If the generator is nested inside another generator, the former's attribute
* If the generator is nested inside another generator, the former's attribute
* list will be another list (a tuple, for example) inside the latter's.
*/
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F)
@ -117,14 +117,14 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F)
using fusion::tuple;
actual_output
<< format(
confix('<', ">")[
"svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]],
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
<< format(
confix('<', ">")[
"svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]],
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
@ -146,13 +146,13 @@ BOOST_FIXTURE_TEST_CASE(bgcolor_stream_iterator_test_case, F)
std::ostream_iterator<char> actual_output_iterator(actual_output);
generate(
actual_output_iterator,
confix("<", ">")[
"svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]],
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
actual_output_iterator,
confix("<", ">")[
"svg width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string]
<< " version=" << confix('"', '"')[float_]
<< " xmlns=" << confix('"', '"')[string]],
tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}

View file

@ -3,7 +3,7 @@
# batch format *.{hpp,cpp} files
MAPNIK_DIR=`pwd`
DIRS="$MAPNIK_DIR/plugins $MAPNIK_DIR/demo/c++ $MAPNIK_DIR/src $MAPNIK_DIR/include $MAPNIK_DIR/bindings $MAPNIK_DIR/utils"
DIRS="$MAPNIK_DIR/plugins $MAPNIK_DIR/demo/c++ $MAPNIK_DIR/src $MAPNIK_DIR/include $MAPNIK_DIR/bindings $MAPNIK_DIR/utils $MAPNIK_DIR/tests"
EMACS="emacs"
for file in $(find $DIRS -name '*.cpp' -o -name '*.hpp')