diff --git a/run_tests b/run_tests index 858a8bf64..51d9ccf36 100755 --- a/run_tests +++ b/run_tests @@ -4,14 +4,9 @@ failures=0 source ./localize.sh -echo "*** Running Next Gen C++ tests..." +echo "*** Running C++ tests..." ./tests/cxx/run failures=$((failures+$?)) echo -echo "*** Running Old C++ tests..." -./tests/cpp_tests/run -failures=$((failures+$?)) -echo - exit $failures diff --git a/tests/cpp_tests/agg_blend_src_over_test.cpp b/tests/cpp_tests/agg_blend_src_over_test.cpp deleted file mode 100644 index eb86e4cad..000000000 --- a/tests/cpp_tests/agg_blend_src_over_test.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "agg_color_rgba.h" -#include "agg_pixfmt_rgba.h" -#include "agg_rendering_buffer.h" -#include "agg_renderer_base.h" - -using color = agg::rgba8; -using order = agg::order_rgba; - -std::string to_string(color const& c) -{ - std::ostringstream s; - s << "rgba(" << (unsigned)c.r << "," << (unsigned)c.g << "," << (unsigned)c.b << "," << (unsigned)c.a << ")"; - return s.str(); -} - -template -color blend(color const& source, color const& dest, unsigned cover=255) -{ - unsigned stride = 4; - unsigned size = 1; - - color source_pre = source; - source_pre.premultiply(); - color dest_pre = dest; - dest_pre.premultiply(); - - unsigned char* buffer = new unsigned char[size*size*stride]; - std::memset(buffer, 0, size*size*stride); - buffer[0] = dest_pre.r; - buffer[1] = dest_pre.g; - buffer[2] = dest_pre.b; - buffer[3] = dest_pre.a; - // http://www.antigrain.com/doc/basic_renderers/basic_renderers.agdoc.html - agg::rendering_buffer rbuf(buffer, - size, - size, - size * stride); - color::value_type* psource = (color::value_type*)rbuf.row_ptr(0,0,1); - blender::blend_pix(psource,source_pre.r,source_pre.g,source_pre.b,source_pre.a,cover); - color color_result(psource[0],psource[1],psource[2],psource[3]); - color_result.demultiply(); - delete [] buffer; - return color_result; -} - -// agg::pixfmt_alpha_blend_rgba -color normal_blend(color const& source, color const& dest, unsigned cover=255) -{ - using renderer_type = agg::renderer_base; - unsigned stride = 4; - unsigned size = 1; - color source_pre = source; - source_pre.premultiply(); - color dest_pre = dest; - dest_pre.premultiply(); - // source buffer - unsigned char* source_buffer = new unsigned char[size*size*stride]; - std::memset(source_buffer, 0, size*size*stride); - source_buffer[0] = source_pre.r; - source_buffer[1] = source_pre.g; - source_buffer[2] = source_pre.b; - source_buffer[3] = source_pre.a; - agg::rendering_buffer source_rbuffer(source_buffer,size,size,size * 4); - agg::pixfmt_rgba32_pre pixf_source(source_rbuffer); - - // destination buffer - unsigned char* dest_buffer = new unsigned char[size*size*stride]; - std::memset(dest_buffer, 0, size*size*stride); - dest_buffer[0] = dest_pre.r; - dest_buffer[1] = dest_pre.g; - dest_buffer[2] = dest_pre.b; - dest_buffer[3] = dest_pre.a; - agg::rendering_buffer dest_rbuffer(dest_buffer,size,size,size * 4); - agg::pixfmt_rgba32_pre pixf_dest(dest_rbuffer); - - // renderer: blends source into destination - renderer_type ren(pixf_dest); - ren.blend_from(pixf_source,0,0,0,cover); - color color_result(dest_buffer[0],dest_buffer[1],dest_buffer[2],dest_buffer[3]); - color_result.demultiply(); - delete [] source_buffer; - delete [] dest_buffer; - return color_result; -} - - - -namespace agg { - -// the original agg template code for src_over -// before we changed A as per https://github.com/mapnik/mapnik/issues/1452 -template struct comp_op_rgba_src_over2 -{ - using color_type = ColorT; - using order_type = Order; - using value_type = typename color_type::value_type; - using calc_type = typename color_type::calc_type; - enum base_scale_e - { - base_shift = color_type::base_shift, - base_mask = color_type::base_mask - }; - - // Dca' = Sca + Dca.(1 - Sa) - // Da' = Sa + Da - Sa.Da - static void blend_pix(value_type* p, - unsigned sr, unsigned sg, unsigned sb, - unsigned sa, unsigned cover) - { - if(cover < 255) - { - sr = (sr * cover + 255) >> 8; - sg = (sg * cover + 255) >> 8; - sb = (sb * cover + 255) >> 8; - sa = (sa * cover + 255) >> 8; - } - calc_type s1a = base_mask - sa; - p[Order::R] = (value_type)(sr + ((p[Order::R] * s1a + base_mask) >> base_shift)); - p[Order::G] = (value_type)(sg + ((p[Order::G] * s1a + base_mask) >> base_shift)); - p[Order::B] = (value_type)(sb + ((p[Order::B] * s1a + base_mask) >> base_shift)); - p[Order::A] = (value_type)(sa + p[Order::A] - ((sa * p[Order::A] + base_mask) >> base_shift)); - } -}; - -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i; - using source_over = agg::comp_op_rgba_src_over; - - try - { - color white(255,255,255,255); - color black(0,0,0,255); - - BOOST_TEST_EQ( to_string(blend(white,white)), to_string(white) ); - BOOST_TEST_EQ( to_string(blend(white,black)), to_string(white) ); - BOOST_TEST_EQ( to_string(blend(black,white)), to_string(black) ); - - color near_white(254,254,254,254); // Source - color near_trans(1,1,1,1); // Dest - color expected_color(253,253,253,255); // expected result - BOOST_TEST_EQ( to_string(blend(near_white,near_trans)), to_string(color(253,253,253,254)) ); - BOOST_TEST_EQ( to_string(blend(near_white,near_trans)), to_string(expected_color) ); - BOOST_TEST_EQ( to_string(normal_blend(near_white,near_trans)), to_string(expected_color) ); - - // using normal_blend as expected, compare a variety of other colors - - { - color source(128,128,128,255); - color dest(128,128,128,255); - unsigned cover = 128; - std::string expected_str = to_string(normal_blend(source,dest,cover)); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - } - - { - color source(128,128,128,255); - color dest(128,128,128,255); - unsigned cover = 245; - std::string expected_str = to_string(normal_blend(source,dest,cover)); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - } - - // commenting until I study these failures more (dane) - /* - { - // fails, why? - color source(127,127,127,127); - color dest(127,127,127,127); - unsigned cover = 255; - std::string expected_str = to_string(normal_blend(source,dest,cover)); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - } - - { - // fails, why? - color source(128,128,128,128); - color dest(128,128,128,128); - unsigned cover = 128; - std::string expected_str = to_string(normal_blend(source,dest,cover)); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - BOOST_TEST_EQ( to_string(blend(source,dest,cover)), expected_str ); - } - */ - } - catch (std::exception const & ex) - { - std::clog << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ AGG blending: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - std::clog << "C++ AGG blending: "; - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/clipping_test.cpp b/tests/cpp_tests/clipping_test.cpp deleted file mode 100644 index 3d788e049..000000000 --- a/tests/cpp_tests/clipping_test.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// mapnik -#include -#include -#include -// boost -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wunused-local-typedef" -#include -#include -#pragma GCC diagnostic pop - -// stl -#include -#include -#include -#include -#include -#include - -// agg -#include "agg_conv_clip_polygon.h" -#include "agg_conv_clip_polyline.h" -//#include "agg_path_storage.h" -//#include "agg_conv_clipper.h" - -#include "utils.hpp" - -template -std::string dump_path(T & path) -{ - unsigned cmd = 1; - double x = 0; - double y = 0; - unsigned idx = 0; - std::ostringstream s; - path.rewind(0); - while ((cmd = path.vertex(&x, &y)) != mapnik::SEG_END) - { - if (idx > 0) s << ","; - s << x << " " << y << " " << cmd; - idx++; - } - return s.str(); -} - -std::string clip_line(mapnik::box2d const& bbox, - mapnik::path_type const& path) -{ - using line_clipper = agg::conv_clip_polyline; - mapnik::vertex_adapter va(path); - line_clipper clipped(va); - clipped.clip_box(bbox.minx(),bbox.miny(),bbox.maxx(),bbox.maxy()); - return dump_path(clipped); -} - -void parse_geom(mapnik::path_type & path, - std::string const& geom_string) { - std::vector vertices; - boost::split(vertices, geom_string, boost::is_any_of(",")); - for (std::string const& vert : vertices) - { - std::vector commands; - boost::split(commands, vert, boost::is_any_of(" ")); - if (commands.size() != 3) - { - throw std::runtime_error(std::string("could not parse geometry '") + geom_string + "'"); - } - double x = 0; - double y = 0; - int c = 0; - if (mapnik::util::string2double(commands[0],x) - && mapnik::util::string2double(commands[1],y) - && mapnik::util::string2int(commands[2],c)) - { - path.push_vertex(x,y,(mapnik::CommandType)c); - } - else - { - throw std::runtime_error(std::string("could not parse geometry '") + geom_string + "'"); - } - } -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i parts; - boost::split(parts, csv_line, boost::is_any_of(";")); - // first part is clipping box - mapnik::box2d bbox; - if (!bbox.from_string(parts[0])) { - throw std::runtime_error(std::string("could not parse bbox '") + parts[0] + "'"); - } - // second part is input geometry - mapnik::path_type path; - parse_geom(path, parts[1]); - //std::clog << dump_path(path) << "\n"; - // third part is expected, clipped geometry - BOOST_TEST_EQ(clip_line(bbox, path),mapnik::util::trim_copy(parts[2])); - } - stream.close(); - } - catch (std::exception const& ex) - { - std::cerr << ex.what() << "\n"; - } - - if (!::boost::detail::test_errors()) - { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ clipping: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } - else - { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/conversions_test.cpp b/tests/cpp_tests/conversions_test.cpp deleted file mode 100644 index bb86f7138..000000000 --- a/tests/cpp_tests/conversions_test.cpp +++ /dev/null @@ -1,309 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_MSC_VER) && _MSC_VER < 1900 -#include -#endif - -int main(int argc, char** argv) -{ - #if defined(_MSC_VER) && _MSC_VER < 1900 - unsigned int old = _set_output_format(_TWO_DIGIT_EXPONENT); - #endif - std::vector args; - for (int i=1;i; - values_container vc; - mapnik::value val2(1); - vc[val2] = 1; - BOOST_TEST_EQ( (int)vc[1], (int)1 ); - - } - catch (std::exception const & ex) - { - std::clog << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ type conversions: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/copy_move_test.cpp b/tests/cpp_tests/copy_move_test.cpp deleted file mode 100644 index 665483e70..000000000 --- a/tests/cpp_tests/copy_move_test.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utils.hpp" - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i ren(m,im); - //std::clog << mapnik::save_map_to_string(m) << "\n"; - BOOST_TEST(true); - // should throw here with "CSV Plugin: no attribute 'foo'. Valid attributes are: x,y." - ren.apply(); - BOOST_TEST(false); - } catch (...) { - BOOST_TEST(true); - } - } - - std::string shape_plugin("./plugins/input/shape.input"); - if (mapnik::util::exists(shape_plugin)) { - try { - mapnik::datasource_cache::instance().register_datasource(shape_plugin); - mapnik::parameters p2; - p2["type"]="shape"; - p2["file"]="foo"; - mapnik::datasource_cache::instance().create(p2); - BOOST_TEST(false); - } catch (...) { - BOOST_TEST(true); - } - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ exceptions: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/font_registration_test.cpp b/tests/cpp_tests/font_registration_test.cpp deleted file mode 100644 index 39e568e3f..000000000 --- a/tests/cpp_tests/font_registration_test.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include "utils.hpp" - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i"); - BOOST_TEST( m3.get_font_memory_cache().size() == 0 ); - BOOST_TEST( m3.load_fonts() ); - BOOST_TEST( m3.get_font_memory_cache().size() == 1 ); - - std::vector face_names; - std::string foo("foo"); - // 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 ); - - // directories without fonts - // silence warnings here by altering the logging severity - logger.set_severity(mapnik::logger::none); - 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 ); - - // 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 ); - - 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 ); - - // now restore the original severity - logger.set_severity(original_severity); - - // 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(); - BOOST_TEST( face_names.size() > 0 ); - BOOST_TEST( face_names.size() == 1 ); - - // re-register unifont, should not have any affect - BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, false) ); - face_names = mapnik::freetype_engine::face_names(); - BOOST_TEST( face_names.size() == 1 ); - - // single dejavu font in separate location - 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(); - BOOST_TEST( face_names.size() == 2 ); - - // now, inspect font mapping and confirm the correct 'DejaVu Sans Mono Bold Oblique' is registered - using font_file_mapping = std::map >; - font_file_mapping const& name2file = mapnik::freetype_engine::get_mapping(); - bool found_dejavu = false; - for (auto const& item : name2file) - { - if (item.first == "DejaVu Sans Mono Bold Oblique") - { - found_dejavu = true; - BOOST_TEST( item.second.first == 0 ); - BOOST_TEST( item.second.second == dejavu_bold_oblique ); - } - } - BOOST_TEST( found_dejavu ); - - // recurse to find all dejavu fonts - BOOST_TEST( mapnik::freetype_engine::register_fonts(fontdir, true) ); - face_names = mapnik::freetype_engine::face_names(); - BOOST_TEST( face_names.size() == 22 ); - - // we should have re-registered 'DejaVu Sans Mono Bold Oblique' again, - // but now at a new path - bool found_dejavu2 = false; - for (auto const& item : name2file) - { - if (item.first == "DejaVu Sans Mono Bold Oblique") - { - found_dejavu2 = true; - BOOST_TEST( item.second.first == 0 ); - // path should be different - BOOST_TEST( item.second.second != dejavu_bold_oblique ); - } - } - BOOST_TEST( found_dejavu2 ); - - // now that global registry is populated - // now test that a map only loads new fonts - mapnik::Map m4(1,1); - BOOST_TEST( m4.register_fonts(fontdir , true ) ); - BOOST_TEST( m4.get_font_memory_cache().size() == 0 ); - BOOST_TEST( m4.get_font_file_mapping().size() == 22 ); - BOOST_TEST( !m4.load_fonts() ); - BOOST_TEST( m4.get_font_memory_cache().size() == 0 ); - BOOST_TEST( m4.register_fonts(dejavu_bold_oblique, false) ); - BOOST_TEST( m4.load_fonts() ); - BOOST_TEST( m4.get_font_memory_cache().size() == 1 ); - - // check that we can correctly read a .ttc containing - // multiple valid faces - // https://github.com/mapnik/mapnik/issues/2274 - BOOST_TEST( mapnik::freetype_engine::register_font("tests/data/fonts/NotoSans-Regular.ttc") ); - face_names = mapnik::freetype_engine::face_names(); - BOOST_TEST( face_names.size() == 24 ); - - // now blindly register as many system fonts as possible - // the goal here to make sure we don't crash - // linux - mapnik::freetype_engine::register_fonts("/usr/share/fonts/", true); - mapnik::freetype_engine::register_fonts("/usr/local/share/fonts/", true); - // osx - mapnik::freetype_engine::register_fonts("/Library/Fonts/", true); - mapnik::freetype_engine::register_fonts("/System/Library/Fonts/", true); - // windows - mapnik::freetype_engine::register_fonts("C:\\Windows\\Fonts", true); - face_names = mapnik::freetype_engine::face_names(); - BOOST_TEST( face_names.size() > 22 ); - } - catch (std::exception const & ex) - { - std::clog << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ fonts registration: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/fontset_runtime_test.cpp b/tests/cpp_tests/fontset_runtime_test.cpp deleted file mode 100644 index 73d4c9feb..000000000 --- a/tests/cpp_tests/fontset_runtime_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// icu - for memory cleanup (to make valgrind happy) -#include "unicode/uclean.h" - -#include "utils.hpp" - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i(); - ctx->push("name"); - mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1)); - mapnik::transcoder tr("utf-8"); - mapnik::value_unicode_string ustr = tr.transcode("hello world!"); - feature->put("name",ustr); - //auto pt = std::make_unique(mapnik::geometry::geometry_types::Point); - //pt->move_to(128,128); - mapnik::geometry::point pt(128,128); - feature->set_geometry(std::move(pt)); - - mapnik::parameters params; - params["type"]="memory"; - auto ds = std::make_shared(params); - ds->push(feature); - mapnik::Map m(256,256); - mapnik::font_set fontset("fontset"); - // NOTE: this is a valid font, but will fail because none are registered - fontset.add_face_name("DejaVu Sans Book"); - m.insert_fontset("fontset", fontset); - mapnik::layer lyr("layer"); - lyr.set_datasource(ds); - lyr.add_style("style"); - m.add_layer(lyr); - mapnik::feature_type_style the_style; - mapnik::rule r; - mapnik::text_symbolizer text_sym; - mapnik::text_placements_ptr placement_finder = std::make_shared(); - placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book"; - placement_finder->defaults.format_defaults.text_size = 10.0; - placement_finder->defaults.format_defaults.fill = mapnik::color(0,0,0); - placement_finder->defaults.format_defaults.fontset = fontset; - placement_finder->defaults.set_format_tree(std::make_shared(mapnik::parse_expression("[name]"))); - mapnik::put(text_sym, mapnik::keys::text_placements_, placement_finder); - r.append(std::move(text_sym)); - the_style.add_rule(std::move(r)); - m.insert_style("style", std::move(the_style) ); - m.zoom_to_box(mapnik::box2d(-256,-256, - 256,256)); - mapnik::image_rgba8 buf(m.width(),m.height()); - mapnik::agg_renderer ren(m,buf); - ren.apply(); - } catch (std::exception const& ex) { - BOOST_TEST_EQ(std::string(ex.what()),std::string("Unable to find specified font face 'DejaVu Sans Book' in font set: 'fontset'")); - } - u_cleanup(); - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ fontset runtime: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/geometry_converters_test.cpp b/tests/cpp_tests/geometry_converters_test.cpp deleted file mode 100644 index 1932ea0d7..000000000 --- a/tests/cpp_tests/geometry_converters_test.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include -#include -#include -#include -#include "utils.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// stl -#include -#if 0 // FIXME -struct output_geometry_backend -{ - output_geometry_backend(mapnik::geometry_container & paths, mapnik::geometry_type::types type) - : paths_(paths), - type_(type) {} - - template - void add_path(T & path) - { - mapnik::vertex2d vtx(mapnik::vertex2d::no_init); - path.rewind(0); - std::unique_ptr geom_ptr(new mapnik::geometry_type(type_)); - - while ((vtx.cmd = path.vertex(&vtx.x, &vtx.y)) != mapnik::SEG_END) - { - //std::cerr << vtx.x << "," << vtx.y << " cmd=" << vtx.cmd << std::endl; - geom_ptr->push_vertex(vtx.x, vtx.y, (mapnik::CommandType)vtx.cmd); - } - paths_.push_back(geom_ptr.release()); - } - mapnik::geometry_container & paths_; - mapnik::geometry_type::types type_; -}; - -boost::optional linestring_bbox_clipping(mapnik::box2d bbox, - std::string wkt_in) -{ - using namespace mapnik; - agg::trans_affine tr; - projection src(MAPNIK_LONGLAT_PROJ); - projection dst(MAPNIK_LONGLAT_PROJ); - proj_transform prj_trans(src,dst); - line_symbolizer sym; - view_transform t(bbox.width(),bbox.height(), bbox); - mapnik::geometry_container output_paths; - output_geometry_backend backend(output_paths, mapnik::geometry::geometry_types::LineString); - - mapnik::context_ptr ctx = std::make_shared(); - mapnik::feature_impl f(ctx,0); - vertex_converter - converter(bbox, backend, sym, t, prj_trans, tr, f, attributes(), 1.0); - - converter.set(); - - mapnik::geometry_container p; - if (!mapnik::from_wkt(wkt_in , p)) - { - throw std::runtime_error("Failed to parse WKT"); - } - - for (geometry_type const& geom : p) - { - vertex_adapter va(geom); - converter.apply(va); - } - - using sink_type = std::back_insert_iterator; - std::string wkt; - sink_type sink(wkt); - static const mapnik::wkt::wkt_multi_generator generator; - if (boost::spirit::karma::generate(sink, generator, output_paths)) - { - return boost::optional(wkt); - } - return boost::optional(); -} - -boost::optional polygon_bbox_clipping(mapnik::box2d bbox, - std::string wkt_in) -{ - using namespace mapnik; - agg::trans_affine tr; - projection src(MAPNIK_LONGLAT_PROJ); - projection dst(MAPNIK_LONGLAT_PROJ); - proj_transform prj_trans(src,dst); - polygon_symbolizer sym; - view_transform t(bbox.width(),bbox.height(), bbox); - mapnik::geometry_container output_paths; - output_geometry_backend backend(output_paths, mapnik::geometry::geometry_types::Polygon); - - mapnik::context_ptr ctx = std::make_shared(); - mapnik::feature_impl f(ctx,0); - vertex_converter - converter(bbox, backend, sym, t, prj_trans, tr, f, attributes(), 1.0); - - converter.set(); - - mapnik::geometry_container p; - if (!mapnik::from_wkt(wkt_in , p)) - { - throw std::runtime_error("Failed to parse WKT"); - } - - for (geometry_type const& geom : p) - { - vertex_adapter va(geom); - converter.apply(va); - } - - using sink_type = std::back_insert_iterator; - std::string wkt; // Use Python String directly ? - sink_type sink(wkt); - static const mapnik::wkt::wkt_multi_generator generator; - if (boost::spirit::karma::generate(sink, generator, output_paths)) - { - return boost::optional(wkt); - } - - return boost::optional(); -} - -#endif - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i result = linestring_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); - BOOST_TEST(result); - BOOST_TEST_EQ(*result,std::string("LineString(50 50,150 150)")); - } - // Polygon/bbox clipping - { - std::string wkt_in("Polygon((50 50,150 50,150 150,50 150,50 50))"); - boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); - BOOST_TEST(result); - // TODO - the extra 50 50 is not ideal, but we enforce this result for now to prevent - // regressions and because we don't have actionable solution to drop extra 50 50 - BOOST_TEST_EQ(*result,std::string("Polygon((50 50,150 50,150 150,50 150,50 50,50 50))")); - // below is ideal, but not current result - //BOOST_TEST_EQ(*result,std::string("Polygon((50 50,150 50,150 150,50 150,50 50))")); - } - - { - std::string wkt_in("Polygon((60 60,140 60,140 160,60 140,60 60))"); - boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); - BOOST_TEST(result); - BOOST_TEST_EQ(*result,std::string("Polygon((60 60,140 60,140 150,100 150,60 140,60 60,60 60))")); - //BOOST_TEST_EQ(*result,std::string("Polygon((60 60,140 60,140 160,60 140,60 60))")); - } - - { - std::string wkt_in("Polygon((0 0,10 0,10 10,0 10,0 0))"); - boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); - BOOST_TEST(result); - // TODO - this is completely wrong: should not have )) and ideally should be EMPTY - BOOST_TEST_EQ(*result, std::string("Polygon())")); - } - { - std::string wkt_in("Polygon((0 0,100 200,200 0,0 0 ))"); - boost::optional result = polygon_bbox_clipping(mapnik::box2d(50,50,150,150),wkt_in); - BOOST_TEST(result); - BOOST_TEST_EQ(*result, std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50))")); - //BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))")); - } -#endif - } - catch (std::exception const & ex) - { - std::clog << ex.what() << "\n"; - BOOST_TEST(false); - } - - - if (!::boost::detail::test_errors()) - { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ geometry conversions: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } - else - { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/image_io_test.cpp b/tests/cpp_tests/image_io_test.cpp deleted file mode 100644 index 1ea4008cf..000000000 --- a/tests/cpp_tests/image_io_test.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(HAVE_CAIRO) -#include -#include -#endif - -#include "utils.hpp" - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i type; - try - { - BOOST_TEST(set_working_dir(args)); -#if defined(HAVE_JPEG) - should_throw = "./tests/cpp_tests/data/blank.jpg"; - BOOST_TEST( mapnik::util::exists( should_throw ) ); - type = mapnik::type_from_filename(should_throw); - BOOST_TEST( type ); - try - { - std::unique_ptr reader(mapnik::get_image_reader(should_throw,*type)); - BOOST_TEST( false ); - } - catch (std::exception const&) - { - BOOST_TEST( true ); - } -#endif - - try - { - mapnik::image_rgba8 im(-10,-10); // should throw rather than overflow - BOOST_TEST( im.width() < 10 ); // should not get here, but if we did this test should fail - } - catch (std::exception const& ex) - { - BOOST_TEST( true ); // should hit bad alloc here - } - -#if defined(HAVE_CAIRO) - mapnik::cairo_surface_ptr image_surface( - cairo_image_surface_create(CAIRO_FORMAT_ARGB32,256,257), - mapnik::cairo_surface_closer()); - mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface)); - im_data.set(1); - BOOST_TEST( (unsigned)im_data(0,0) == unsigned(1) ); - // Should set back to fully transparent - mapnik::cairo_image_to_rgba8(im_data, image_surface); - BOOST_TEST( (unsigned)im_data(0,0) == unsigned(0) ); -#endif - -#if defined(HAVE_PNG) - should_throw = "./tests/cpp_tests/data/blank.png"; - BOOST_TEST( mapnik::util::exists( should_throw ) ); - type = mapnik::type_from_filename(should_throw); - BOOST_TEST( type ); - try - { - std::unique_ptr reader(mapnik::get_image_reader(should_throw,*type)); - BOOST_TEST( false ); - } - catch (std::exception const&) - { - BOOST_TEST( true ); - } - - should_throw = "./tests/data/images/xcode-CgBI.png"; - BOOST_TEST( mapnik::util::exists( should_throw ) ); - type = mapnik::type_from_filename(should_throw); - BOOST_TEST( type ); - try - { - std::unique_ptr reader(mapnik::get_image_reader(should_throw,*type)); - BOOST_TEST( false ); - } - catch (std::exception const&) - { - BOOST_TEST( true ); - } -#endif - -#if defined(HAVE_TIFF) - should_throw = "./tests/cpp_tests/data/blank.tiff"; - BOOST_TEST( mapnik::util::exists( should_throw ) ); - type = mapnik::type_from_filename(should_throw); - BOOST_TEST( type ); - try - { - std::unique_ptr reader(mapnik::get_image_reader(should_throw,*type)); - BOOST_TEST( false ); - } - catch (std::exception const&) - { - BOOST_TEST( true ); - } -#endif - -#if defined(HAVE_WEBP) - should_throw = "./tests/cpp_tests/data/blank.webp"; - BOOST_TEST( mapnik::util::exists( should_throw ) ); - type = mapnik::type_from_filename(should_throw); - BOOST_TEST( type ); - try - { - std::unique_ptr reader(mapnik::get_image_reader(should_throw,*type)); - BOOST_TEST( false ); - } - catch (std::exception const&) - { - BOOST_TEST( true ); - } -#endif - } - catch (std::exception const & ex) - { - std::clog << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ image i/o: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/image_painted_test.cpp b/tests/cpp_tests/image_painted_test.cpp deleted file mode 100644 index b58a87e07..000000000 --- a/tests/cpp_tests/image_painted_test.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - std::vector args; - for (int i = 1; i < argc; ++i) - { - args.push_back(argv[i]); - } - bool quiet = std::find(args.begin(), args.end(), "-q") != args.end(); - - using namespace mapnik; - - try - { - datasource_cache::instance().register_datasources("plugins/input/csv.input"); - - Map m(256, 256); - - feature_type_style lines_style; - { - rule r; - line_symbolizer line_sym; - r.append(std::move(line_sym)); - lines_style.add_rule(std::move(r)); - } - m.insert_style("lines", std::move(lines_style)); - - feature_type_style markers_style; - { - rule r; - r.set_filter(parse_expression("False")); - markers_symbolizer mark_sym; - r.append(std::move(mark_sym)); - markers_style.add_rule(std::move(r)); - } - m.insert_style("markers", std::move(markers_style)); - - parameters p; - p["type"] = "csv"; - p["separator"] = "|"; - p["inline"] = "wkt\nLINESTRING(-10 0, 0 20, 10 0, 15 5)"; - - layer lyr("layer"); - lyr.set_datasource(datasource_cache::instance().create(p)); - lyr.add_style("lines"); - lyr.add_style("markers"); - m.add_layer(lyr); - - m.zoom_all(); - - image_rgba8 image(m.width(), m.height()); - agg_renderer ren(m, image); - ren.apply(); - - BOOST_TEST_EQ(image.painted(), true); - } - catch (std::exception const & ex) - { - std::clog << ex.what() << std::endl; - BOOST_TEST(false); - } - - if (::boost::detail::test_errors()) - { - return ::boost::report_errors(); - } - else - { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ image painted: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } -} diff --git a/tests/cpp_tests/label_algo_test.cpp b/tests/cpp_tests/label_algo_test.cpp deleted file mode 100644 index f872edec7..000000000 --- a/tests/cpp_tests/label_algo_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i centroid; - { - // single point - mapnik::geometry::point pt(10,10); - BOOST_TEST( mapnik::geometry::centroid(pt, centroid)); - BOOST_TEST( pt.x == centroid.x); - BOOST_TEST( pt.y == centroid.y); - } - - // linestring with three consecutive verticies - { - mapnik::geometry::line_string line; - line.add_coord(0, 0); - line.add_coord(25, 25); - line.add_coord(50, 50); - BOOST_TEST(mapnik::geometry::centroid(line, centroid)); - BOOST_TEST( centroid.x == 25 ); - BOOST_TEST( centroid.y == 25 ); - } - // TODO - centroid and interior should be equal but they appear not to be (check largest) - // MULTIPOLYGON(((-52 40,-60 32,-68 40,-60 48,-52 40)),((-60 50,-80 30,-100 49.9999999999999,-80.0000000000001 70,-60 50)),((-52 60,-60 52,-68 60,-60 68,-52 60))) -#if 0 - // hit tests - { - mapnik::geometry_type pt_hit(mapnik::geometry::geometry_types::Point); - pt_hit.move_to(10,10); - mapnik::vertex_adapter va(pt_hit); - BOOST_TEST( mapnik::label::hit_test(va, 10, 10, 0.1) ); - BOOST_TEST( !mapnik::label::hit_test(va, 9, 9, 0) ); - BOOST_TEST( mapnik::label::hit_test(va, 9, 9, 1.5) ); - } - { - mapnik::geometry_type line_hit(mapnik::geometry::geometry_types::LineString); - line_hit.move_to(0,0); - line_hit.line_to(50,50); - mapnik::vertex_adapter va(line_hit); - BOOST_TEST( mapnik::label::hit_test(va, 0, 0, 0.001) ); - BOOST_TEST( !mapnik::label::hit_test(va, 1, 1, 0) ); - BOOST_TEST( mapnik::label::hit_test(va, 1, 1, 1.001) ); - } -#endif - } - catch (std::exception const & ex) - { - std::clog << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ label algorithms: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/line_offset_test.cpp b/tests/cpp_tests/line_offset_test.cpp deleted file mode 100644 index d8dce5847..000000000 --- a/tests/cpp_tests/line_offset_test.cpp +++ /dev/null @@ -1,236 +0,0 @@ -// mapnik -#include -#include - -// boost -#include - -// stl -#include -#include -#include -#include -#include -#include - -// test -#include "utils.hpp" - -struct fake_path -{ - using coord_type = std::tuple; - using cont_type = std::vector; - cont_type vertices_; - cont_type::iterator itr_; - - fake_path(std::initializer_list l) - : fake_path(l.begin(), l.size()) { - } - - fake_path(std::vector const &v) - : fake_path(v.begin(), v.size()) { - } - - template - fake_path(Itr itr, size_t sz) { - size_t num_coords = sz >> 1; - vertices_.reserve(num_coords); - - for (size_t i = 0; i < num_coords; ++i) { - double x = *itr++; - double y = *itr++; - unsigned cmd = (i == 0) ? agg::path_cmd_move_to : agg::path_cmd_line_to; - vertices_.push_back(std::make_tuple(x, y, cmd)); - } - itr_ = vertices_.begin(); - } - - unsigned vertex(double *x, double *y) { - if (itr_ == vertices_.end()) { - return agg::path_cmd_stop; - } - *x = std::get<0>(*itr_); - *y = std::get<1>(*itr_); - unsigned cmd = std::get<2>(*itr_); - ++itr_; - return cmd; - } - - void rewind(unsigned) { - itr_ = vertices_.begin(); - } -}; - -double dist(mapnik::pixel_position const &a, - mapnik::pixel_position const &b) -{ - mapnik::pixel_position d = a - b; - return std::sqrt(d.x*d.x + d.y*d.y); -} - -namespace boost { namespace detail { - -template -inline void test_leq_impl(char const * expr1, char const * expr2, - char const * file, int line, char const * function, - T const & t, U const & u) -{ - if( t > u ) - { - BOOST_LIGHTWEIGHT_TEST_OSTREAM - << file << "(" << line << "): test '" << expr1 << " == " << expr2 - << "' failed in function '" << function << "': " - << "'" << t << "' > '" << u << "'" << std::endl; - ++test_errors(); - } -} - -} } - -#define BOOST_TEST_LEQ(expr1,expr2) ( ::boost::detail::test_leq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) - -void test_simple_segment(double const &offset) -{ - const double dx = 0.01; - fake_path path = {0, 0, 1, 0}, off_path = {0, offset, 1, offset}; - mapnik::vertex_cache vc(path), off_vc(off_path); - - vc.reset(); vc.next_subpath(); - off_vc.reset(); off_vc.next_subpath(); - - while (vc.move(dx)) { - double pos = vc.linear_position(); - double off_pos = off_vc.position_closest_to(vc.current_position()); - BOOST_TEST_LEQ(std::abs(pos - off_pos), 1.0e-6); - } -} - -void test_straight_line(double const &offset) { - const double dx = 0.01; - fake_path path = {0, 0, 0.1, 0, 0.9, 0, 1, 0}, - off_path = {0, offset, 0.4, offset, 0.6, offset, 1, offset}; - mapnik::vertex_cache vc(path), off_vc(off_path); - - vc.reset(); vc.next_subpath(); - off_vc.reset(); off_vc.next_subpath(); - - while (vc.move(dx)) { - double pos = vc.linear_position(); - double off_pos = off_vc.position_closest_to(vc.current_position()); - BOOST_TEST_LEQ(std::abs(pos - off_pos), 1.0e-6); - } -} - -void test_offset_curve(double const &offset) { - const double dx = 0.01; - const double r = (1.0 + offset); - - std::vector pos, off_pos; - const size_t max_i = 1000; - for (size_t i = 0; i <= max_i; ++i) { - double x = M_PI * double(i) / max_i; - pos.push_back(-std::cos(x)); pos.push_back(std::sin(x)); - off_pos.push_back(-r * std::cos(x)); off_pos.push_back(r * std::sin(x)); - } - - fake_path path(pos), off_path(off_pos); - mapnik::vertex_cache vc(path), off_vc(off_path); - - vc.reset(); vc.next_subpath(); - off_vc.reset(); off_vc.next_subpath(); - - while (vc.move(dx)) { - double pos = vc.linear_position(); - double off_pos = off_vc.position_closest_to(vc.current_position()); - { - mapnik::vertex_cache::scoped_state s(off_vc); - off_vc.move(off_pos); - BOOST_TEST_LEQ(dist(vc.current_position(), off_vc.current_position()), (1.001 * offset)); - } - BOOST_TEST_LEQ(std::abs((pos / vc.length()) - (off_pos / off_vc.length())), 1.0e-3); - } -} - -void test_s_shaped_curve(double const &offset) { - const double dx = 0.01; - const double r = (1.0 + offset); - const double r2 = (1.0 - offset); - - std::vector pos, off_pos; - const size_t max_i = 1000; - for (size_t i = 0; i <= max_i; ++i) { - double x = M_PI * double(i) / max_i; - pos.push_back(-std::cos(x) - 1); pos.push_back(std::sin(x)); - off_pos.push_back(-r * std::cos(x) - 1); off_pos.push_back(r * std::sin(x)); - } - for (size_t i = 0; i <= max_i; ++i) { - double x = M_PI * double(i) / max_i; - pos.push_back(-std::cos(x) + 1); pos.push_back(-std::sin(x)); - off_pos.push_back(-r2 * std::cos(x) + 1); off_pos.push_back(-r2 * std::sin(x)); - } - - fake_path path(pos), off_path(off_pos); - mapnik::vertex_cache vc(path), off_vc(off_path); - - vc.reset(); vc.next_subpath(); - off_vc.reset(); off_vc.next_subpath(); - - while (vc.move(dx)) { - double off_pos = off_vc.position_closest_to(vc.current_position()); - { - mapnik::vertex_cache::scoped_state s(off_vc); - off_vc.move(off_pos); - BOOST_TEST_LEQ(dist(vc.current_position(), off_vc.current_position()), (1.002 * offset)); - } - } -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i offsets = { 0.01, 0.02, 0.1, 0.2 }; - for (double offset : offsets) { - // test simple straight line segment - should be easy to - // find the correspondance here. - test_simple_segment(offset); - - // test straight line consisting of more than one segment. - test_straight_line(offset); - - // test an offset outer curve - test_offset_curve(offset); - - // test an offset along an S-shaped curve, which is harder - // because the positions along the offset are no longer - // linearly related to the positions along the original - // curve. - test_s_shaped_curve(offset); - } - } - catch (std::exception const& ex) - { - std::cerr << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) - { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ line offset: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } - else - { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/map_request_test.cpp b/tests/cpp_tests/map_request_test.cpp deleted file mode 100644 index 45e9ec411..000000000 --- a/tests/cpp_tests/map_request_test.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include - -#include -#include -#include -#include -#if defined(HAVE_CAIRO) -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "utils.hpp" - -bool compare_images(std::string const& src_fn,std::string const& dest_fn) -{ - using namespace mapnik; - std::unique_ptr reader1(mapnik::get_image_reader(dest_fn,"png")); - if (!reader1.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + dest_fn); - } - std::shared_ptr image_ptr1 = std::make_shared(reader1->width(),reader1->height()); - reader1->read(0,0,*image_ptr1); - - std::unique_ptr reader2(mapnik::get_image_reader(src_fn,"png")); - if (!reader2.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + src_fn); - } - std::shared_ptr image_ptr2 = std::make_shared(reader2->width(),reader2->height()); - reader2->read(0,0,*image_ptr2); - - image_rgba8 const& dest = *image_ptr1; - image_rgba8 const& src = *image_ptr2; - - unsigned int width = src.width(); - unsigned int height = src.height(); - if ((width != dest.width()) || height != dest.height()) return false; - for (unsigned int y = 0; y < height; ++y) - { - const unsigned int* row_from = src.getRow(y); - const unsigned int* row_to = dest.getRow(y); - for (unsigned int x = 0; x < width; ++x) - { - if (row_from[x] != row_to[x]) return false; - } - } - return true; -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i renderer1(m,im,scale_factor); - renderer1.apply(); - std::string actual1("/tmp/map-request-marker-text-line-actual1.png"); - //mapnik::save_to_file(im,expected); - mapnik::save_to_file(im,actual1); - // TODO - re-enable if we can control the freetype/cairo versions used - // https://github.com/mapnik/mapnik/issues/1868 - //BOOST_TEST(compare_images(actual1,expected)); - - // reset image - mapnik::fill(im, 0); - - // set up a mapnik::request object - mapnik::request req(m.width(),m.height(),m.get_current_extent()); - req.set_buffer_size(m.buffer_size()); - - // render using apply() and mapnik::request - mapnik::attributes vars; - mapnik::agg_renderer renderer2(m,req,vars,im,scale_factor); - renderer2.apply(); - std::string actual2("/tmp/map-request-marker-text-line-actual2.png"); - mapnik::save_to_file(im,actual2); - // TODO - re-enable if we can control the freetype/cairo versions used - // https://github.com/mapnik/mapnik/issues/1868 - //BOOST_TEST(compare_images(actual2,expected)); - - // reset image - mapnik::fill(im, 0); - - // render with apply_to_layer api and mapnik::request params passed to apply_to_layer - mapnik::agg_renderer renderer3(m,req,vars,im,scale_factor); - renderer3.start_map_processing(m); - mapnik::projection map_proj(m.srs(),true); - double scale_denom = mapnik::scale_denominator(req.scale(),map_proj.is_geographic()); - scale_denom *= scale_factor; - for (mapnik::layer const& lyr : m.layers() ) - { - if (lyr.visible(scale_denom)) - { - std::set names; - renderer3.apply_to_layer(lyr, - renderer3, - map_proj, - req.scale(), - scale_denom, - req.width(), - req.height(), - req.extent(), - req.buffer_size(), - names); - - } - } - renderer3.end_map_processing(m); - std::string actual3("/tmp/map-request-marker-text-line-actual3.png"); - mapnik::save_to_file(im,actual3); - // TODO - re-enable if we can control the freetype/cairo versions used - // https://github.com/mapnik/mapnik/issues/1868 - //BOOST_TEST(compare_images(actual3,expected)); - - // also test cairo -#if defined(HAVE_CAIRO) - mapnik::cairo_surface_ptr image_surface( - cairo_image_surface_create(CAIRO_FORMAT_ARGB32,req.width(),req.height()), - mapnik::cairo_surface_closer()); - mapnik::cairo_ptr image_context = (mapnik::create_context(image_surface)); - mapnik::cairo_renderer png_render(m,req,vars,image_context,scale_factor); - png_render.apply(); - //cairo_surface_write_to_png(&*image_surface, expected_cairo.c_str()); - std::string actual_cairo("/tmp/map-request-marker-text-line-actual4.png"); - cairo_surface_write_to_png(&*image_surface, actual_cairo.c_str()); - // TODO - re-enable if we can control the freetype/cairo versions used - // https://github.com/mapnik/mapnik/issues/1868 - //BOOST_TEST(compare_images(actual_cairo,expected_cairo)); -#endif - // TODO - test grid_renderer - - } catch (std::exception const& ex) { - std::clog << ex.what() << "\n"; - } - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ Map Request rendering hook: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/params_test.cpp b/tests/cpp_tests/params_test.cpp deleted file mode 100644 index 0e83a805e..000000000 --- a/tests/cpp_tests/params_test.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace detail { - -class string_holder { - public: - string_holder() : - member_("member") {} - std::string const& get_string() const - { - return member_; - } - private: - std::string member_; -}; - -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i("bool") && *params.get("bool") == true)); - - params["bool"] = "true"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == true)); - - params["bool"] = mapnik::value_integer(1); - BOOST_TEST( (params.get("bool") && *params.get("bool") == true)); - - params["bool"] = "1"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == true)); - - params["bool"] = "True"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == true)); - - params["bool"] = "on"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == true)); - - params["bool"] = "yes"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == true)); - - // false - params["bool"] = mapnik::value_integer(false); - BOOST_TEST( (params.get("bool") && *params.get("bool") == false) ); - - params["bool"] = "false"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == false) ); - - params["bool"] = mapnik::value_integer(0); - BOOST_TEST( (params.get("bool") && *params.get("bool") == false)); - - params["bool"] = "0"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == false)); - - params["bool"] = "False"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == false)); - - params["bool"] = "off"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == false)); - - params["bool"] = "no"; - BOOST_TEST( (params.get("bool") && *params.get("bool") == false)); - - // strings - params["string"] = "hello"; - BOOST_TEST( (params.get("string") && *params.get("string") == "hello") ); - - // int - params["int"] = mapnik::value_integer(1); - BOOST_TEST( (params.get("int") && *params.get("int") == 1) ); - - // double - params["double"] = 1.5; - BOOST_TEST( (params.get("double") && *params.get("double") == 1.5) ); - - // value_null - params["null"] = mapnik::value_null(); - // https://github.com/mapnik/mapnik/issues/2471 - //BOOST_TEST( (params.get("null") && *params.get("null") == mapnik::value_null()) ); - - std::string value("value"); - params["value"] = value; - BOOST_TEST(params.get("value") == std::string("value")); - BOOST_TEST(value == std::string("value")); - - // ensure that const member is not moved incorrectly when added to params - detail::string_holder holder; - std::string const& holder_member = holder.get_string(); - params["member"] = holder_member; - BOOST_TEST(params.get("member") == std::string("member")); - BOOST_TEST(holder_member == std::string("member")); - } - catch (std::exception const& ex) - { - std::cerr << ex.what() << "\n"; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ parameters: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/simplify_converters_test.cpp b/tests/cpp_tests/simplify_converters_test.cpp deleted file mode 100644 index 8d5331de5..000000000 --- a/tests/cpp_tests/simplify_converters_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include -#include "utils.hpp" - -#include -#include -#include -#include -#include - -// stl -#include - -// Convenience method for test cases -void simplify(std::string const& wkt_in, double tolerance, std::string const& method, std::string const& expected) -{ -#if 0 // FIXME - //grab the geom - mapnik::geometry_container multi_input; - if (!mapnik::from_wkt(wkt_in , multi_input)) - { - throw std::runtime_error("Failed to parse WKT"); - } - //setup the generalization - mapnik::vertex_adapter va(multi_input.front()); - mapnik::simplify_converter generalizer(va); - generalizer.set_simplify_algorithm(mapnik::simplify_algorithm_from_string(method).get()); - generalizer.set_simplify_tolerance(tolerance); - //suck the vertices back out of it - mapnik::geometry_type* output = new mapnik::geometry_type(multi_input.front().type()); - mapnik::CommandType cmd; - double x, y; - while ((cmd = (mapnik::CommandType)generalizer.vertex(&x, &y)) != mapnik::SEG_END) - { - output->push_vertex(x, y, cmd); - } - //construct the answer - mapnik::geometry_container multi_out; - multi_out.push_back(output); - std::string wkt_out; - BOOST_TEST(mapnik::to_wkt(multi_out, wkt_out)); - BOOST_TEST_EQ(wkt_out, expected); -#endif -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i -#include -#include -#include -#include - -using namespace mapnik; - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i(1)); - marker_multi_policy_enum policy_out = get(sym, keys::markers_multipolicy); - BOOST_TEST_EQ(policy_out,MARKER_WHOLE_MULTI); - } - catch (std::exception const & ex) - { - std::clog << ex.what() << std::endl; - BOOST_TEST(false); - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ symbolizer test: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -} diff --git a/tests/cpp_tests/utils.hpp b/tests/cpp_tests/utils.hpp deleted file mode 100644 index b4a541adc..000000000 --- a/tests/cpp_tests/utils.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include -#include - -inline static bool set_working_dir(std::vector args) -{ - std::vector::iterator itr = std::find(args.begin(), args.end(), "-d"); - if (itr!=args.end()) - { - unsigned dist = std::distance(args.begin(),itr); - if (args.size() > dist+1) - { - std::string chdir = args.at(dist+1); - bool exists = mapnik::util::exists( chdir ); - if (exists) - { - boost::filesystem::current_path(chdir); - return true; - } - } - return false; - } - return true; -} diff --git a/tests/cpp_tests/wkb_formats_test.cpp b/tests/cpp_tests/wkb_formats_test.cpp deleted file mode 100644 index 73508c467..000000000 --- a/tests/cpp_tests/wkb_formats_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { -void test_simple_and_valid(const mapnik::geometry::geometry &geom) { -// only Boost >= 1.56 has is_valid and is_simple -#if BOOST_VERSION >= 105600 - BOOST_TEST(mapnik::geometry::is_valid(geom) && mapnik::geometry::is_simple(geom)); -#endif -} -} - -int main(int argc, char** argv) -{ - std::vector args; - for (int i=1;i geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob, - sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]), - mapnik::wkbSpatiaLite); - // winding order is not correct per OGC so we'll fix it - mapnik::geometry::correct(geom); - test_simple_and_valid(geom); - - geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob, - sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]), - mapnik::wkbAuto); - mapnik::geometry::correct(geom); - test_simple_and_valid(geom); - - geom = mapnik::geometry_utils::from_wkb((const char*)sp_invalid_blob, - sizeof(sp_invalid_blob) / sizeof(sp_invalid_blob[0]), - mapnik::wkbAuto); - BOOST_TEST(geom.is()); // returns geometry_empty - - // sqlite generic wkb blob - - geom = mapnik::geometry_utils::from_wkb((const char*)sq_valid_blob, - sizeof(sq_valid_blob) / sizeof(sq_valid_blob[0]), - mapnik::wkbGeneric); - test_simple_and_valid(geom); - - geom = mapnik::geometry_utils::from_wkb( (const char*)sq_valid_blob, - sizeof(sq_valid_blob) / sizeof(sq_valid_blob[0]), - mapnik::wkbAuto); - - test_simple_and_valid(geom); - - geom = mapnik::geometry_utils::from_wkb((const char*)sq_invalid_blob, - sizeof(sq_invalid_blob) / sizeof(sq_invalid_blob[0]), - mapnik::wkbGeneric); - BOOST_TEST(geom.is()); // returns geometry_empty - - } catch (std::exception const& ex) { - BOOST_TEST(false); - std::clog << "threw: " << ex.what() << "\n"; - } - - if (!::boost::detail::test_errors()) { - if (quiet) std::clog << "\x1b[1;32m.\x1b[0m"; - else std::clog << "C++ WKB formats test: \x1b[1;32m✓ \x1b[0m\n"; - ::boost::detail::report_errors_remind().called_report_errors_function = true; - } else { - return ::boost::report_errors(); - } -}