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*[] ) int main( int, char*[] )
{ {
std::string fontdir("fonts/"); std::string fontdir("fonts/");
BOOST_TEST( fs::exists( fontdir ) );
BOOST_TEST( fs::is_directory( fontdir ) );
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 std::string foo("foo");
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 );
// directories without fonts // fake directories
std::string src("src"); BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo , true ) );
// an empty directory will not return true face_names = mapnik::freetype_engine::face_names();
// we need to register at least one font and not fail on any BOOST_TEST( face_names.size() == 0 );
// to return true BOOST_TEST( !mapnik::freetype_engine::register_fonts(foo) );
BOOST_TEST( mapnik::freetype_engine::register_font(src) == false ); face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( mapnik::freetype_engine::register_fonts(src, true) == false ); BOOST_TEST( face_names.size() == 0 );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
// bogus, emtpy file that looks like font // directories without fonts
BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/fake.ttf") == false ); std::string src("src");
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/fake.ttf") == false ); // an empty directory will not return true
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 ); // 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 ); // bogus, emtpy file that looks like font
BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/intentionally-broken.ttf") == false ); BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/fake.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 ); 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_font("tests/data/fonts/intentionally-broken.ttf") == false );
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir) ); BOOST_TEST( mapnik::freetype_engine::register_fonts("tests/data/fonts/intentionally-broken.ttf") == false );
face_names = mapnik::freetype_engine::face_names(); BOOST_TEST( mapnik::freetype_engine::face_names().size() == 0 );
//std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() > 0 );
BOOST_TEST( face_names.size() == 1 );
// re-register unifont, should not have any affect // register unifont, since we know it sits in the root fonts/ dir
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) ); BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir) );
face_names = mapnik::freetype_engine::face_names(); face_names = mapnik::freetype_engine::face_names();
//std::clog << "number of registered fonts: " << face_names.size() << std::endl; //std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 1 ); BOOST_TEST( face_names.size() > 0 );
BOOST_TEST( face_names.size() == 1 );
// register a single dejavu font // re-register unifont, should not have any affect
std::string dejavu_bold_oblique("tests/data/fonts/DejaVuSansMono-BoldOblique.ttf"); BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) );
BOOST_TEST( mapnik::freetype_engine::register_font(dejavu_bold_oblique) ); face_names = mapnik::freetype_engine::face_names();
face_names = mapnik::freetype_engine::face_names(); //std::clog << "number of registered fonts: " << face_names.size() << std::endl;
//std::clog << "number of registered fonts: " << face_names.size() << std::endl; BOOST_TEST( face_names.size() == 1 );
BOOST_TEST( face_names.size() == 2 );
// recurse to find all dejavu fonts // register a single dejavu font
BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) ); std::string dejavu_bold_oblique("tests/data/fonts/DejaVuSansMono-BoldOblique.ttf");
face_names = mapnik::freetype_engine::face_names(); BOOST_TEST( mapnik::freetype_engine::register_font(dejavu_bold_oblique) );
//std::clog << "number of registered fonts: " << face_names.size() << std::endl; face_names = mapnik::freetype_engine::face_names();
BOOST_TEST( face_names.size() == 22 ); //std::clog << "number of registered fonts: " << face_names.size() << std::endl;
BOOST_TEST( face_names.size() == 2 );
if (!::boost::detail::test_errors()) { // recurse to find all dejavu fonts
std::clog << "C++ fonts registration: \x1b[1;32m✓ \x1b[0m\n"; BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) );
} else { face_names = mapnik::freetype_engine::face_names();
return ::boost::report_errors(); //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*[] ) int main( int, char*[] )
{ {
mapnik::parameters params; mapnik::parameters params;
// true
params["bool"] = true;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "true"; // true
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; params["bool"] = "true";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "1"; params["bool"] = 1;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "True"; params["bool"] = "1";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "on"; params["bool"] = "True";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "yes"; params["bool"] = "on";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
// false params["bool"] = "yes";
params["bool"] = false; BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = "false"; // false
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; params["bool"] = "false";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = "0"; params["bool"] = 0;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "False"; params["bool"] = "0";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "off"; params["bool"] = "False";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "no"; params["bool"] = "off";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false)); BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
// strings params["bool"] = "no";
params["string"] = "hello"; BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
// int // strings
params["int"] = 1; params["string"] = "hello";
BOOST_TEST( (params.get<int>("int") && *params.get<int>("int") == 1) ); BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
// double // int
params["double"] = 1.5; params["int"] = 1;
BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) ); BOOST_TEST( (params.get<int>("int") && *params.get<int>("int") == 1) );
// value_null // double
params["null"] = mapnik::value_null(); params["double"] = 1.5;
//BOOST_TEST( (params.get<mapnik::value_null>("null")/* && *params.get<mapnik::value_null>("null") == mapnik::value_null()*/) ); BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) );
if (!::boost::detail::test_errors()) { // value_null
std::clog << "C++ parameters: \x1b[1;32m✓ \x1b[0m\n"; params["null"] = mapnik::value_null();
} else { //BOOST_TEST( (params.get<mapnik::value_null>("null")/* && *params.get<mapnik::value_null>("null") == mapnik::value_null()*/) );
return ::boost::report_errors();
} 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 #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 * the implementation of a background color in SVG
* using a rectangle. * using a rectangle.
*/ */
@ -25,16 +25,16 @@ namespace repository = boost::spirit::repository;
namespace fusion = boost::fusion; namespace fusion = boost::fusion;
using namespace karma; using namespace karma;
struct F struct F
{ {
F() : F() :
x(0), x(0),
y(0), y(0),
width(100), width(100),
height(100), height(100),
bgcolor("#ffffff"), bgcolor("#ffffff"),
expected_output("<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" style=\"fill: #ffffff\"/>") {} expected_output("<rect x=\"0\" y=\"0\" width=\"100px\" height=\"100px\" style=\"fill: #ffffff\"/>") {}
~F() {} ~F() {}
const int x; const int x;
@ -61,14 +61,14 @@ struct F
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F) BOOST_FIXTURE_TEST_CASE(bgcolor_stream_test_case, F)
{ {
actual_output actual_output
<< format( << format(
"<rect x=\"" << int_ << "\" " "<rect x=\"" << int_ << "\" "
<< "y=\"" << int_ << "\" " << "y=\"" << int_ << "\" "
<< "width=\"" << int_ << string << "\" " << "width=\"" << int_ << string << "\" "
<< "height=\"" << int_ << string << "\" " << "height=\"" << int_ << string << "\" "
<< "style=\"fill: " << string << "\"" << "style=\"fill: " << string << "\""
<< "/>", << "/>",
x, y, width, "px", height, "px", bgcolor); x, y, width, "px", height, "px", bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output); 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. * Notice that the generators' attribute list contains also tuples.
* Tuples are needed to specify each confix's attributes that contain * 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>). * generator needs a tuple: tuple<int, string>).
* *
* The difference between this generator and the one in test case * 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; using fusion::tuple;
actual_output actual_output
<< format( << format(
"<rect x=" << confix('"', '"')[int_] "<rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_] << " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string] << " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string] << " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string] << " style=" << confix('"', '"')["fill: " << string]
<< "/>", << "/>",
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor); x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output); 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 * using confix. notice that a confix generator can be part of another
* confix generator's expression. * confix generator's expression.
* *
* Notice also that the attribute list is the same as in * Notice also that the attribute list is the same as in
* 'bgcolor_stream_confix_test_case'. From this one can see that each * '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. * 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. * list will be another list (a tuple, for example) inside the latter's.
*/ */
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_complete_test_case, F) 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; using fusion::tuple;
actual_output actual_output
<< format( << format(
confix('<', "/>")[ confix('<', "/>")[
"rect x=" << confix('"', '"')[int_] "rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_] << " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string] << " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string] << " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]], << " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor); x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output); 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); std::ostream_iterator<char> actual_output_iterator(actual_output);
generate( generate(
actual_output_iterator, actual_output_iterator,
confix("<", "/>")[ confix("<", "/>")[
"rect x=" << confix('"', '"')[int_] "rect x=" << confix('"', '"')[int_]
<< " y=" << confix('"', '"')[int_] << " y=" << confix('"', '"')[int_]
<< " width=" << confix('"', '"')[int_ << string] << " width=" << confix('"', '"')[int_ << string]
<< " height=" << confix('"', '"')[int_ << string] << " height=" << confix('"', '"')[int_ << string]
<< " style=" << confix('"', '"')["fill: " << string]], << " style=" << confix('"', '"')["fill: " << string]],
x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor); x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);
BOOST_CHECK_EQUAL(actual_output.str(), expected_output); 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); svg_ren renderer(map, output_stream_iterator);
renderer.apply(); renderer.apply();
/*std::string expected_output = /*std::string expected_output =
svg_ren::XML_DECLARATION svg_ren::XML_DECLARATION
+ "\n" + "\n"
+ svg_ren::SVG_DTD + svg_ren::SVG_DTD
+ "\n" + "\n"
+ "<svg width=\"800px\" height=\"600px\" version=\"1.1\" xmlns=\"" + "<svg width=\"800px\" height=\"600px\" version=\"1.1\" xmlns=\""
+ svg_ren::SVG_NAMESPACE_URL + svg_ren::SVG_NAMESPACE_URL
+ "\">" + "\">"
+"\n" +"\n"
+"<rect x=\"0\" y=\"0\" width=\"800px\" height=\"600px\" style=\"fill: #ffffff\"/>" +"<rect x=\"0\" y=\"0\" width=\"800px\" height=\"600px\" style=\"fill: #ffffff\"/>"
+"\n" +"\n"
+"</svg>"; +"</svg>";
std::string actual_output = output_stream.str(); std::string actual_output = output_stream.str();
BOOST_CHECK_EQUAL(actual_output, expected_output); BOOST_CHECK_EQUAL(actual_output, expected_output);
*/ */
} }

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@
# batch format *.{hpp,cpp} files # batch format *.{hpp,cpp} files
MAPNIK_DIR=`pwd` 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" EMACS="emacs"
for file in $(find $DIRS -name '*.cpp' -o -name '*.hpp') for file in $(find $DIRS -name '*.cpp' -o -name '*.hpp')