port all old c++ tests to new c++ tests
This commit is contained in:
parent
8bb605e2e9
commit
0170ba1ae3
19 changed files with 1 additions and 2525 deletions
|
@ -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
|
||||
|
|
|
@ -1,220 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#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<typename blender>
|
||||
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<agg::pixfmt_rgba32_pre>;
|
||||
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<class ColorT, class Order> 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<std::string> 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 source_over_old_agg = agg::comp_op_rgba_src_over2<color, agg::order_rgba>;
|
||||
using source_over = agg::comp_op_rgba_src_over<color, agg::order_rgba>;
|
||||
|
||||
try
|
||||
{
|
||||
color white(255,255,255,255);
|
||||
color black(0,0,0,255);
|
||||
|
||||
BOOST_TEST_EQ( to_string(blend<source_over>(white,white)), to_string(white) );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over>(white,black)), to_string(white) );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over>(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<source_over_old_agg>(near_white,near_trans)), to_string(color(253,253,253,254)) );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over>(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_over>(source,dest,cover)), expected_str );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(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_over>(source,dest,cover)), expected_str );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(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_over>(source,dest,cover)), expected_str );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(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_over>(source,dest,cover)), expected_str );
|
||||
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(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();
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
// mapnik
|
||||
#include <mapnik/util/conversions.hpp>
|
||||
#include <mapnik/util/trim.hpp>
|
||||
#include <mapnik/path.hpp>
|
||||
// boost
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
// 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 <typename T>
|
||||
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<double> const& bbox,
|
||||
mapnik::path_type const& path)
|
||||
{
|
||||
using line_clipper = agg::conv_clip_polyline<mapnik::vertex_adapter>;
|
||||
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<std::string> vertices;
|
||||
boost::split(vertices, geom_string, boost::is_any_of(","));
|
||||
for (std::string const& vert : vertices)
|
||||
{
|
||||
std::vector<std::string> 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<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try {
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
std::string filename("tests/cpp_tests/data/cases.txt");
|
||||
std::ifstream stream(filename.c_str(),std::ios_base::in | std::ios_base::binary);
|
||||
if (!stream.is_open())
|
||||
throw std::runtime_error("could not open: '" + filename + "'");
|
||||
|
||||
std::string csv_line;
|
||||
while(std::getline(stream,csv_line,'\n'))
|
||||
{
|
||||
if (csv_line.empty() || csv_line[0] == '#') continue;
|
||||
std::vector<std::string> parts;
|
||||
boost::split(parts, csv_line, boost::is_any_of(";"));
|
||||
// first part is clipping box
|
||||
mapnik::box2d<double> 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();
|
||||
}
|
||||
}
|
|
@ -1,309 +0,0 @@
|
|||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/util/conversions.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#include <cstdio>
|
||||
#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<std::string> 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 mapnik::util::to_string;
|
||||
using mapnik::util::string2bool;
|
||||
|
||||
try
|
||||
{
|
||||
std::string out;
|
||||
|
||||
// Test double
|
||||
to_string(out, double(0));
|
||||
BOOST_TEST_EQ( out, "0" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1));
|
||||
BOOST_TEST_EQ( out, "1" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-1));
|
||||
BOOST_TEST_EQ( out, "-1" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.1));
|
||||
BOOST_TEST_EQ( out, "0.1" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-0.1));
|
||||
BOOST_TEST_EQ( out, "-0.1" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.123));
|
||||
BOOST_TEST_EQ( out, "0.123" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-0.123));
|
||||
BOOST_TEST_EQ( out, "-0.123" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1e-06));
|
||||
BOOST_TEST_EQ( out, "1e-06" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-1e-06));
|
||||
BOOST_TEST_EQ( out, "-1e-06" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1e-05));
|
||||
BOOST_TEST_EQ( out, "1e-05" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-1e-05));
|
||||
BOOST_TEST_EQ( out, "-1e-05" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.0001));
|
||||
BOOST_TEST_EQ( out, "0.0001" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-0.0001));
|
||||
BOOST_TEST_EQ( out, "-0.0001" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.0001));
|
||||
BOOST_TEST_EQ( out, "0.0001" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.00001));
|
||||
BOOST_TEST_EQ( out, "1e-05" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.000001));
|
||||
BOOST_TEST_EQ( out, "1e-06" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.0000001));
|
||||
BOOST_TEST_EQ( out, "1e-07" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.00000001));
|
||||
BOOST_TEST_EQ( out, "1e-08" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.000000001));
|
||||
BOOST_TEST_EQ( out, "1e-09" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.0000000001));
|
||||
BOOST_TEST_EQ( out, "1e-10" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-1.234e+16));
|
||||
BOOST_TEST_EQ( out, "-1.234e+16" );
|
||||
out.clear();
|
||||
|
||||
// critical failure when karam is used
|
||||
// https://github.com/mapnik/mapnik/issues/1741
|
||||
// https://github.com/mapbox/tilemill/issues/1456
|
||||
to_string(out, double(8.3));
|
||||
BOOST_TEST_EQ( out, "8.3" );
|
||||
out.clear();
|
||||
|
||||
// non-critical failures if karma is used
|
||||
to_string(out, double(0.0001234567890123456));
|
||||
// TODO: https://github.com/mapnik/mapnik/issues/1676
|
||||
BOOST_TEST_EQ( out, "0.000123457" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.00000000001));
|
||||
BOOST_TEST_EQ( out, "1e-11" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.000000000001));
|
||||
BOOST_TEST_EQ( out, "1e-12" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.0000000000001));
|
||||
BOOST_TEST_EQ( out, "1e-13" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.00000000000001));
|
||||
BOOST_TEST_EQ( out, "1e-14" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(0.000000000000001));
|
||||
BOOST_TEST_EQ( out, "1e-15" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000));
|
||||
BOOST_TEST_EQ( out, "100000" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1000000));
|
||||
BOOST_TEST_EQ( out, "1e+06" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(10000000));
|
||||
BOOST_TEST_EQ( out, "1e+07" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000000));
|
||||
BOOST_TEST_EQ( out, "1e+08" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1000000000));
|
||||
BOOST_TEST_EQ( out, "1e+09" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(10000000000));
|
||||
BOOST_TEST_EQ( out, "1e+10" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000000000));
|
||||
BOOST_TEST_EQ( out, "1e+11" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1000000000000));
|
||||
BOOST_TEST_EQ( out, "1e+12" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(10000000000000));
|
||||
BOOST_TEST_EQ( out, "1e+13" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000000000000));
|
||||
BOOST_TEST_EQ( out, "1e+14" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1000000000000005));
|
||||
BOOST_TEST_EQ( out, "1e+15" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(-1000000000000000));
|
||||
BOOST_TEST_EQ( out, "-1e+15" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000000000000.1));
|
||||
BOOST_TEST_EQ( out, "1e+14" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1.00001));
|
||||
BOOST_TEST_EQ( out, "1.00001" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(67.65));
|
||||
BOOST_TEST_EQ( out, "67.65" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(67.35));
|
||||
BOOST_TEST_EQ( out, "67.35" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1234000000000000));
|
||||
BOOST_TEST_EQ( out, "1.234e+15" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1e+16));
|
||||
BOOST_TEST_EQ( out, "1e+16" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1.234e+16));
|
||||
BOOST_TEST_EQ( out, "1.234e+16" );
|
||||
out.clear();
|
||||
|
||||
// int
|
||||
to_string(out, int(2));
|
||||
BOOST_TEST_EQ( out, "2" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, int(0));
|
||||
BOOST_TEST_EQ( out, "0" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, int(-2));
|
||||
BOOST_TEST_EQ( out, "-2" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, int(2147483647));
|
||||
BOOST_TEST_EQ( out, "2147483647" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, int(-2147483648));
|
||||
BOOST_TEST_EQ( out, "-2147483648" );
|
||||
out.clear();
|
||||
|
||||
// unsigned
|
||||
to_string(out, unsigned(4294967295));
|
||||
BOOST_TEST_EQ( out, "4294967295" );
|
||||
out.clear();
|
||||
|
||||
#ifdef BIGINT
|
||||
// long long
|
||||
to_string(out,mapnik::value_integer(-0));
|
||||
BOOST_TEST_EQ( out, "0" );
|
||||
out.clear();
|
||||
|
||||
to_string(out,mapnik::value_integer(-2));
|
||||
BOOST_TEST_EQ( out, "-2" );
|
||||
out.clear();
|
||||
|
||||
to_string(out,mapnik::value_integer(9223372036854775807));
|
||||
BOOST_TEST_EQ( out, "9223372036854775807" );
|
||||
out.clear();
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#pragma NOTE("BIGINT not defined so skipping large number conversion tests")
|
||||
#else
|
||||
#warning BIGINT not defined so skipping large number conversion tests
|
||||
#endif
|
||||
#endif
|
||||
// bool
|
||||
to_string(out, true);
|
||||
BOOST_TEST_EQ( out, "true" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, false);
|
||||
BOOST_TEST_EQ( out, "false" );
|
||||
out.clear();
|
||||
|
||||
bool val = false;
|
||||
BOOST_TEST( !string2bool("this is invalid",val) );
|
||||
BOOST_TEST_EQ( val, false );
|
||||
BOOST_TEST( string2bool("true",val) );
|
||||
BOOST_TEST_EQ( val, true );
|
||||
|
||||
// mapnik::value hashability
|
||||
using values_container = boost::unordered_map<mapnik::value, unsigned>;
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/color.hpp>
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::Map m0(100,100);
|
||||
mapnik::Map m2(200,100);
|
||||
|
||||
// mapnik::datasource
|
||||
mapnik::datasource_cache::instance().register_datasources("plugins/input/shape.input");
|
||||
mapnik::parameters p;
|
||||
p["type"]="shape";
|
||||
p["file"]="demo/data/boundaries";
|
||||
p["encoding"]="latin1";
|
||||
auto ds0 = mapnik::datasource_cache::instance().create(p);
|
||||
|
||||
auto ds1 = ds0; // shared ptr copy
|
||||
BOOST_TEST(ds1 == ds0);
|
||||
BOOST_TEST(*ds1 == *ds0);
|
||||
ds1 = mapnik::datasource_cache::instance().create(p); // new with the same parameters
|
||||
BOOST_TEST(ds1 != ds0);
|
||||
BOOST_TEST(*ds1 == *ds0);
|
||||
auto ds2 = std::move(ds1);
|
||||
BOOST_TEST(ds2 != ds0);
|
||||
BOOST_TEST(*ds2 == *ds0);
|
||||
|
||||
// mapnik::layer
|
||||
mapnik::layer l0("test-layer");
|
||||
l0.set_datasource(ds0);
|
||||
|
||||
mapnik::layer l1 = l0; // copy assignment
|
||||
BOOST_TEST(l1 == l0);
|
||||
mapnik::layer l2(l0); // copy ctor
|
||||
BOOST_TEST(l2 == l0);
|
||||
mapnik::layer l3(mapnik::layer("test-layer")); // move ctor
|
||||
l3.set_datasource(ds2);
|
||||
|
||||
BOOST_TEST(l3 == l0);
|
||||
mapnik::layer l4 = std::move(l3);
|
||||
BOOST_TEST(l4 == l0); // move assignment
|
||||
|
||||
m0.add_layer(l4);
|
||||
m0.set_background(mapnik::color("skyblue"));
|
||||
m2.set_background(mapnik::color("skyblue"));
|
||||
|
||||
auto m1 = m0; //copy
|
||||
|
||||
BOOST_TEST(m0 == m1);
|
||||
BOOST_TEST(m0 != m2);
|
||||
|
||||
m2 = m1; // copy
|
||||
BOOST_TEST(m2 == m1);
|
||||
m2 = std::move(m1);
|
||||
BOOST_TEST(m2 == m0);
|
||||
BOOST_TEST(m1 != m0);
|
||||
|
||||
BOOST_TEST(m0 == m2);
|
||||
}
|
||||
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++ copy/move/assignment tests: \x1b[1;32m✓ \x1b[0m\n";
|
||||
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/save_map.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/memory_datasource.hpp>
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/expression.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/agg_renderer.hpp>
|
||||
#include <mapnik/config_error.hpp>
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
#include <mapnik/params.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
try {
|
||||
mapnik::projection srs("foo");
|
||||
// to avoid unused variable warning
|
||||
srs.params();
|
||||
BOOST_TEST(false);
|
||||
} catch (...) {
|
||||
BOOST_TEST(true);
|
||||
}
|
||||
|
||||
// https://github.com/mapnik/mapnik/issues/2170
|
||||
try {
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
mapnik::projection srs("+proj=longlat foo",true);
|
||||
BOOST_TEST(srs.is_geographic());
|
||||
BOOST_TEST(true);
|
||||
srs.init_proj4();
|
||||
// oddly init_proj4 does not throw with old proj/ubuntu precise
|
||||
//BOOST_TEST(false);
|
||||
} catch (...) {
|
||||
BOOST_TEST(true);
|
||||
}
|
||||
|
||||
try {
|
||||
mapnik::transcoder tr("bogus encoding");
|
||||
BOOST_TEST(false);
|
||||
} catch (...) {
|
||||
BOOST_TEST(true);
|
||||
}
|
||||
|
||||
mapnik::Map map(256,256);
|
||||
mapnik::rule r;
|
||||
r.set_filter(mapnik::parse_expression("[foo]='bar'"));
|
||||
r.append(std::move(mapnik::markers_symbolizer()));
|
||||
mapnik::feature_type_style style;
|
||||
style.add_rule(std::move(r));
|
||||
map.insert_style("style", std::move(style));
|
||||
|
||||
std::string csv_plugin("./plugins/input/csv.input");
|
||||
if (mapnik::util::exists(csv_plugin)) {
|
||||
try {
|
||||
mapnik::datasource_cache::instance().register_datasource(csv_plugin);
|
||||
mapnik::parameters p;
|
||||
p["type"]="csv";
|
||||
p["inline"]="x,y\n0,0";
|
||||
mapnik::datasource_ptr ds = mapnik::datasource_cache::instance().create(p);
|
||||
mapnik::layer l("layer");
|
||||
l.set_datasource(ds);
|
||||
l.add_style("style");
|
||||
mapnik::Map m = map;
|
||||
m.add_layer(l);
|
||||
m.zoom_all();
|
||||
mapnik::image_rgba8 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> 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();
|
||||
}
|
||||
}
|
|
@ -1,207 +0,0 @@
|
|||
#include <mapnik/font_engine_freetype.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/load_map.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::logger logger;
|
||||
mapnik::logger::severity_type original_severity = logger.get_severity();
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
|
||||
// grab references to global statics of registered/cached fonts
|
||||
auto const& global_mapping = mapnik::freetype_engine::get_mapping();
|
||||
auto const& global_cache = mapnik::freetype_engine::get_cache();
|
||||
|
||||
// mapnik.Map object has parallel structure for localized fonts
|
||||
mapnik::Map m(1,1);
|
||||
auto const& local_mapping = m.get_font_file_mapping();
|
||||
auto const& local_cache = m.get_font_memory_cache();
|
||||
|
||||
// should be empty to start
|
||||
BOOST_TEST( global_mapping.empty() );
|
||||
BOOST_TEST( global_cache.empty() );
|
||||
BOOST_TEST( local_mapping.empty() );
|
||||
BOOST_TEST( local_cache.empty() );
|
||||
|
||||
std::string fontdir("fonts/");
|
||||
|
||||
BOOST_TEST( mapnik::util::exists( fontdir ) );
|
||||
BOOST_TEST( mapnik::util::is_directory( fontdir ) );
|
||||
|
||||
// test map cached fonts
|
||||
BOOST_TEST( m.register_fonts(fontdir , false ) );
|
||||
BOOST_TEST( m.get_font_memory_cache().size() == 0 );
|
||||
BOOST_TEST( m.get_font_file_mapping().size() == 1 );
|
||||
BOOST_TEST( m.load_fonts() );
|
||||
BOOST_TEST( m.get_font_memory_cache().size() == 1 );
|
||||
BOOST_TEST( m.register_fonts(fontdir , true ) );
|
||||
BOOST_TEST( m.get_font_file_mapping().size() == 22 );
|
||||
BOOST_TEST( m.load_fonts() );
|
||||
BOOST_TEST( m.get_font_memory_cache().size() == 22 );
|
||||
|
||||
// copy discards memory cache but not file mapping
|
||||
mapnik::Map m2(m);
|
||||
BOOST_TEST( m2.get_font_memory_cache().size() == 0 );
|
||||
BOOST_TEST( m2.get_font_file_mapping().size() == 22 );
|
||||
BOOST_TEST( m2.load_fonts() );
|
||||
BOOST_TEST( m2.get_font_memory_cache().size() == 22 );
|
||||
|
||||
// test font-directory from XML
|
||||
mapnik::Map m3(1,1);
|
||||
mapnik::load_map_string(m3,"<Map font-directory=\"fonts/\"></Map>");
|
||||
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<std::string> 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<std::string, std::pair<int,std::string> >;
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/memory_datasource.hpp>
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/params.hpp>
|
||||
#include <mapnik/expression.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
#include <mapnik/agg_renderer.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/color_factory.hpp>
|
||||
#include <mapnik/save_map.hpp>
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <mapnik/text/placements/dummy.hpp>
|
||||
#include <mapnik/text/formatting/text.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <mapnik/make_unique.hpp>
|
||||
|
||||
// icu - for memory cleanup (to make valgrind happy)
|
||||
#include "unicode/uclean.h"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try {
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
// create a renderable map with a fontset and a text symbolizer
|
||||
// and do not register any fonts, to ensure the error thrown is reasonable
|
||||
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
|
||||
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_type>(mapnik::geometry::geometry_types::Point);
|
||||
//pt->move_to(128,128);
|
||||
mapnik::geometry::point<double> pt(128,128);
|
||||
feature->set_geometry(std::move(pt));
|
||||
|
||||
mapnik::parameters params;
|
||||
params["type"]="memory";
|
||||
auto ds = std::make_shared<mapnik::memory_datasource>(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<mapnik::text_placements_dummy>();
|
||||
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::formatting::text_node>(mapnik::parse_expression("[name]")));
|
||||
mapnik::put<mapnik::text_placements_ptr>(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<double>(-256,-256,
|
||||
256,256));
|
||||
mapnik::image_rgba8 buf(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> 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();
|
||||
}
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/view_transform.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/vertex_converters.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include <mapnik/well_known_srs.hpp>
|
||||
#include <mapnik/wkt/wkt_generator_grammar.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
#if 0 // FIXME
|
||||
struct output_geometry_backend
|
||||
{
|
||||
output_geometry_backend(mapnik::geometry_container & paths, mapnik::geometry_type::types type)
|
||||
: paths_(paths),
|
||||
type_(type) {}
|
||||
|
||||
template <typename T>
|
||||
void add_path(T & path)
|
||||
{
|
||||
mapnik::vertex2d vtx(mapnik::vertex2d::no_init);
|
||||
path.rewind(0);
|
||||
std::unique_ptr<mapnik::geometry_type> 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<std::string> linestring_bbox_clipping(mapnik::box2d<double> 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::context_type>();
|
||||
mapnik::feature_impl f(ctx,0);
|
||||
vertex_converter<output_geometry_backend,clip_line_tag>
|
||||
converter(bbox, backend, sym, t, prj_trans, tr, f, attributes(), 1.0);
|
||||
|
||||
converter.set<clip_line_tag>();
|
||||
|
||||
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>;
|
||||
std::string wkt;
|
||||
sink_type sink(wkt);
|
||||
static const mapnik::wkt::wkt_multi_generator<sink_type, mapnik::geometry_container> generator;
|
||||
if (boost::spirit::karma::generate(sink, generator, output_paths))
|
||||
{
|
||||
return boost::optional<std::string>(wkt);
|
||||
}
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
boost::optional<std::string> polygon_bbox_clipping(mapnik::box2d<double> 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::context_type>();
|
||||
mapnik::feature_impl f(ctx,0);
|
||||
vertex_converter<output_geometry_backend, clip_poly_tag>
|
||||
converter(bbox, backend, sym, t, prj_trans, tr, f, attributes(), 1.0);
|
||||
|
||||
converter.set<clip_poly_tag>();
|
||||
|
||||
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>;
|
||||
std::string wkt; // Use Python String directly ?
|
||||
sink_type sink(wkt);
|
||||
static const mapnik::wkt::wkt_multi_generator<sink_type, mapnik::geometry_container> generator;
|
||||
if (boost::spirit::karma::generate(sink, generator, output_paths))
|
||||
{
|
||||
return boost::optional<std::string>(wkt);
|
||||
}
|
||||
|
||||
return boost::optional<std::string>();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
try
|
||||
{
|
||||
#if 0
|
||||
// LineString/bbox clipping
|
||||
{
|
||||
std::string wkt_in("LineString(0 0,200 200)");
|
||||
boost::optional<std::string> result = linestring_bbox_clipping(mapnik::box2d<double>(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<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(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<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(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<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(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<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(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();
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/image.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#if defined(HAVE_CAIRO)
|
||||
#include <mapnik/cairo/cairo_context.hpp>
|
||||
#include <mapnik/cairo/cairo_image_util.hpp>
|
||||
#endif
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
std::string should_throw;
|
||||
boost::optional<std::string> 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<mapnik::image_reader> 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<mapnik::image_reader> 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<mapnik::image_reader> 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<mapnik::image_reader> 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<mapnik::image_reader> 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();
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/rule.hpp>
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
#include <mapnik/agg_renderer.hpp>
|
||||
#include <mapnik/expression.hpp>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> 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<image_rgba8> 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;
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_centroid.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try
|
||||
{
|
||||
// reused these for simplicity
|
||||
mapnik::geometry::point<double> centroid;
|
||||
{
|
||||
// single point
|
||||
mapnik::geometry::point<double> 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<double> 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();
|
||||
}
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
// mapnik
|
||||
#include <mapnik/coord.hpp>
|
||||
#include <mapnik/vertex_cache.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <algorithm>
|
||||
|
||||
// test
|
||||
#include "utils.hpp"
|
||||
|
||||
struct fake_path
|
||||
{
|
||||
using coord_type = std::tuple<double, double, unsigned>;
|
||||
using cont_type = std::vector<coord_type>;
|
||||
cont_type vertices_;
|
||||
cont_type::iterator itr_;
|
||||
|
||||
fake_path(std::initializer_list<double> l)
|
||||
: fake_path(l.begin(), l.size()) {
|
||||
}
|
||||
|
||||
fake_path(std::vector<double> const &v)
|
||||
: fake_path(v.begin(), v.size()) {
|
||||
}
|
||||
|
||||
template <typename Itr>
|
||||
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<class T, class U>
|
||||
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<double> 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<double> 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<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try {
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
std::vector<double> 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();
|
||||
}
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/load_map.hpp>
|
||||
#include <mapnik/agg_renderer.hpp>
|
||||
#if defined(HAVE_CAIRO)
|
||||
#include <mapnik/cairo/cairo_renderer.hpp>
|
||||
#endif
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
#include <mapnik/font_engine_freetype.hpp>
|
||||
#include <mapnik/image.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/scale_denominator.hpp>
|
||||
#include <mapnik/feature_style_processor.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "utils.hpp"
|
||||
|
||||
bool compare_images(std::string const& src_fn,std::string const& dest_fn)
|
||||
{
|
||||
using namespace mapnik;
|
||||
std::unique_ptr<mapnik::image_reader> 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_rgba8> image_ptr1 = std::make_shared<image_rgba8>(reader1->width(),reader1->height());
|
||||
reader1->read(0,0,*image_ptr1);
|
||||
|
||||
std::unique_ptr<mapnik::image_reader> 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_rgba8> image_ptr2 = std::make_shared<image_rgba8>(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<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
std::string expected("./tests/cpp_tests/support/map-request-marker-text-line-expected.png");
|
||||
std::string expected_cairo("./tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png");
|
||||
try {
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
mapnik::datasource_cache::instance().register_datasources("plugins/input/csv.input");
|
||||
mapnik::freetype_engine::register_fonts("./fonts", true );
|
||||
mapnik::Map m(256,256);
|
||||
mapnik::load_map(m,"./tests/data/good_maps/marker-text-line.xml",false);
|
||||
m.zoom_all();
|
||||
mapnik::image_rgba8 im(m.width(),m.height());
|
||||
double scale_factor = 1.2;
|
||||
|
||||
// render normally with apply() and just map and image
|
||||
mapnik::agg_renderer<mapnik::image_rgba8> 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<mapnik::image_rgba8> 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<mapnik::image_rgba8> 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<std::string> 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<mapnik::cairo_ptr> 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();
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/params.hpp>
|
||||
#include <mapnik/boolean.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
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<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try
|
||||
{
|
||||
mapnik::parameters params;
|
||||
|
||||
// true
|
||||
params["bool"] = mapnik::value_integer(true);
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
params["bool"] = "true";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
params["bool"] = mapnik::value_integer(1);
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
params["bool"] = "1";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
params["bool"] = "True";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
params["bool"] = "on";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
params["bool"] = "yes";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == true));
|
||||
|
||||
// false
|
||||
params["bool"] = mapnik::value_integer(false);
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false) );
|
||||
|
||||
params["bool"] = "false";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false) );
|
||||
|
||||
params["bool"] = mapnik::value_integer(0);
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
||||
|
||||
params["bool"] = "0";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
||||
|
||||
params["bool"] = "False";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
||||
|
||||
params["bool"] = "off";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
||||
|
||||
params["bool"] = "no";
|
||||
BOOST_TEST( (params.get<mapnik::boolean_type>("bool") && *params.get<mapnik::boolean_type>("bool") == false));
|
||||
|
||||
// strings
|
||||
params["string"] = "hello";
|
||||
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
|
||||
|
||||
// int
|
||||
params["int"] = mapnik::value_integer(1);
|
||||
BOOST_TEST( (params.get<mapnik::value_integer>("int") && *params.get<mapnik::value_integer>("int") == 1) );
|
||||
|
||||
// double
|
||||
params["double"] = 1.5;
|
||||
BOOST_TEST( (params.get<double>("double") && *params.get<double>("double") == 1.5) );
|
||||
|
||||
// value_null
|
||||
params["null"] = mapnik::value_null();
|
||||
// https://github.com/mapnik/mapnik/issues/2471
|
||||
//BOOST_TEST( (params.get<mapnik::value_null>("null") && *params.get<mapnik::value_null>("null") == mapnik::value_null()) );
|
||||
|
||||
std::string value("value");
|
||||
params["value"] = value;
|
||||
BOOST_TEST(params.get<std::string>("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<std::string>("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();
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include <mapnik/wkt/wkt_generator_grammar.hpp>
|
||||
#include <mapnik/simplify.hpp>
|
||||
#include <mapnik/simplify_converter.hpp>
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
|
||||
// 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<mapnik::vertex_adapter> 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<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
BOOST_TEST(set_working_dir(args));
|
||||
|
||||
simplify( std::string("LineString(0 0,2 2,3 5,4 1,5 0,6 7,7 0)"),
|
||||
4, "douglas-peucker",
|
||||
std::string("LineString(0 0,6 7,7 0)"));
|
||||
|
||||
simplify( std::string("LineString(0 0,2 2,3 5,4 1,5 0,6 7,7 0)"),
|
||||
2, "douglas-peucker",
|
||||
std::string("LineString(0 0,3 5,5 0,6 7,7 0)"));
|
||||
|
||||
simplify( std::string("LineString(10 0,9 -4,7 -7,4 -9,0 -10,-4 -9,-7 -7,-9 -4,-10 0,-9 4,-7 7,-4 9,0 10,4 9,7 7,9 4)"),
|
||||
4, "douglas-peucker",
|
||||
std::string("LineString(10 0,0 -10,-10 0,0 10,9 4)"));
|
||||
|
||||
simplify( std::string("LineString(0 0,1 1,2 2,0 10,0 0)"),
|
||||
10, "douglas-peucker",
|
||||
std::string("LineString(0 0,0 0)"));
|
||||
|
||||
simplify( std::string("LineString(0 0,1 1,2 2,0 10,0 0)"),
|
||||
8, "douglas-peucker",
|
||||
std::string("LineString(0 0,0 10,0 0)"));
|
||||
|
||||
simplify( std::string("LineString(0 0,1 1,2 2,0 10,0 0)"),
|
||||
1, "douglas-peucker",
|
||||
std::string("LineString(0 0,2 2,0 10,0 0)"));
|
||||
|
||||
simplify( std::string("LineString(0 0, 1 -1, 2 2, 0 -10, 0 0, -5 7, 4 6)"),
|
||||
3, "douglas-peucker",
|
||||
std::string("LineString(0 0,0 -10,-5 7,4 6)"));
|
||||
|
||||
if (!::boost::detail::test_errors())
|
||||
{
|
||||
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
|
||||
else std::clog << "C++ simplify conversions: \x1b[1;32m✓ \x1b[0m\n";
|
||||
::boost::detail::report_errors_remind().called_report_errors_function = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace mapnik;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
try {
|
||||
marker_multi_policy_enum policy_in = MARKER_WHOLE_MULTI;
|
||||
BOOST_TEST_EQ(policy_in,MARKER_WHOLE_MULTI);
|
||||
markers_symbolizer sym;
|
||||
put(sym, keys::markers_multipolicy, policy_in);
|
||||
BOOST_TEST_EQ(sym.properties.count(keys::markers_multipolicy),static_cast<unsigned long>(1));
|
||||
marker_multi_policy_enum policy_out = get<mapnik::marker_multi_policy_enum>(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();
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
|
||||
inline static bool set_working_dir(std::vector<std::string> args)
|
||||
{
|
||||
std::vector<std::string>::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;
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <mapnik/params.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/geometry_is_valid.hpp>
|
||||
#include <mapnik/geometry_is_simple.hpp>
|
||||
#include <mapnik/geometry_correct.hpp>
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
namespace {
|
||||
void test_simple_and_valid(const mapnik::geometry::geometry<double> &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<std::string> args;
|
||||
for (int i=1;i<argc;++i)
|
||||
{
|
||||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
|
||||
unsigned char sp_valid_blob[] = {
|
||||
0x0, 0x1, 0xBC, 0xB, 0x0, 0x0, 0x1F, 0x12, 0xDB, 0xCF, 0xC3, 0xA2, 0x41, 0x41, 0x9D, 0x74, 0xB0, 0x31, 0xE6, 0x34, 0x53, 0x41, 0xDB,
|
||||
0x1B, 0xB6, 0x7C, 0xD9, 0xA2, 0x41, 0x41, 0x67, 0xA7, 0xB6, 0xF, 0xF6, 0x34, 0x53, 0x41, 0x7C, 0x6, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0,
|
||||
0x0, 0x69, 0x3, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x12, 0x0, 0x0, 0x0, 0xBB, 0x4B, 0x9C, 0x59, 0xD2, 0xA2, 0x41, 0x41, 0x3A, 0xAA,
|
||||
0x3F, 0xAE, 0xEB, 0x34, 0x53, 0x41, 0xA2, 0xC2, 0xE4, 0xC6, 0xD1, 0xA2, 0x41, 0x41, 0x4C, 0xFE, 0x6, 0x2B, 0xEC, 0x34, 0x53, 0x41,
|
||||
0xEC, 0x65, 0x5F, 0x6, 0xCE, 0xA2, 0x41, 0x41, 0xDD, 0x33, 0x7F, 0x24, 0xEF, 0x34, 0x53, 0x41, 0x2D, 0x35, 0x2D, 0x30, 0xCB, 0xA2,
|
||||
0x41, 0x41, 0x4E, 0xA7, 0x88, 0x9, 0xF1, 0x34, 0x53, 0x41, 0x58, 0x2F, 0x12, 0x96, 0xCA, 0xA2, 0x41, 0x41, 0x52, 0xD1, 0xBD, 0xDC,
|
||||
0xF0, 0x34, 0x53, 0x41, 0x1F, 0x12, 0xDB, 0xCF, 0xC3, 0xA2, 0x41, 0x41, 0xB9, 0x31, 0xA4, 0xE1, 0xF5, 0x34, 0x53, 0x41, 0x21, 0xBB,
|
||||
0x20, 0x6D, 0xC4, 0xA2, 0x41, 0x41, 0x67, 0xA7, 0xB6, 0xF, 0xF6, 0x34, 0x53, 0x41, 0x5A, 0x82, 0x4A, 0xD3, 0xCA, 0xA2, 0x41, 0x41,
|
||||
0xA7, 0x85, 0x3D, 0x58, 0xF1, 0x34, 0x53, 0x41, 0x22, 0xB8, 0x3A, 0x7D, 0xCB, 0xA2, 0x41, 0x41, 0x7D, 0x89, 0xA1, 0x8E, 0xF1, 0x34,
|
||||
0x53, 0x41, 0xD0, 0x77, 0x3F, 0x80, 0xCF, 0xA2, 0x41, 0x41, 0x57, 0x69, 0x83, 0xC4, 0xEE, 0x34, 0x53, 0x41, 0xA7, 0xF5, 0x8E, 0xF9,
|
||||
0xD1, 0xA2, 0x41, 0x41, 0x9A, 0xA2, 0x31, 0xEE, 0xEC, 0x34, 0x53, 0x41, 0x2A, 0xCD, 0xDE, 0x4C, 0xD4, 0xA2, 0x41, 0x41, 0x11, 0x43,
|
||||
0xE1, 0xF7, 0xEA, 0x34, 0x53, 0x41, 0xF, 0x89, 0xB1, 0x66, 0xD5, 0xA2, 0x41, 0x41, 0xC8, 0x5D, 0x86, 0xF1, 0xE9, 0x34, 0x53, 0x41,
|
||||
0x19, 0xF4, 0x73, 0x63, 0xD7, 0xA2, 0x41, 0x41, 0x7, 0xB1, 0x14, 0x36, 0xE8, 0x34, 0x53, 0x41, 0xDB, 0x1B, 0xB6, 0x7C, 0xD9, 0xA2,
|
||||
0x41, 0x41, 0x98, 0xB5, 0xE0, 0x74, 0xE6, 0x34, 0x53, 0x41, 0xC0, 0x3F, 0xC6, 0xAC, 0xD8, 0xA2, 0x41, 0x41, 0x9D, 0x74, 0xB0, 0x31,
|
||||
0xE6, 0x34, 0x53, 0x41, 0xF0, 0xB5, 0xB1, 0x53, 0xD5, 0xA2, 0x41, 0x41, 0x97, 0x47, 0xAD, 0x36, 0xE9, 0x34, 0x53, 0x41, 0xBB, 0x4B,
|
||||
0x9C, 0x59, 0xD2, 0xA2, 0x41, 0x41, 0x3A, 0xAA, 0x3F, 0xAE, 0xEB, 0x34, 0x53, 0x41, 0xFE };
|
||||
|
||||
unsigned char sp_invalid_blob[] = {
|
||||
0x0, 0x1, 0xBC, 0xB, 0x0, 0x0, 0x1F, 0x12, 0xDB, 0xCF, 0xC3, 0xA2, 0x41, 0x41, 0x9D, 0x74, 0xB0, 0x31, 0xE6, 0x34, 0x53, 0x41, 0xDB,
|
||||
0x1B, 0xB6, 0x7C, 0xD9, 0xA2, 0x41, 0x41, 0x67, 0xA7, 0xB6, 0xF, 0xF6, 0x34, 0x53, 0x41, 0x7C, 0x6, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0,
|
||||
0x0, 0x69, 0x3, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x12, 0x0, 0x0, 0x0, 0xBB, 0x4B, 0x9C, 0x59, 0xD2, 0xA2, 0x41, 0x41, 0x3A, 0xAA,
|
||||
0x3F, 0xAE, 0xEB, 0x34, 0x53, 0x41, 0xA2, 0xC2, 0xE4, 0xC6, 0xD1, 0xA2, 0x41, 0x41, 0x4C, 0xFE, 0x6, 0x2B, 0xEC, 0x34, 0x53, 0x41,
|
||||
0xEC, 0x65, 0x5F, 0x6, 0xCE, 0xA2, 0x41, 0x41, 0xDD, 0x33, 0x7F, 0x24, 0xEF, 0x34, 0x53, 0x41, 0x2D, 0x35, 0x2D, 0x30, 0xCB, 0xA2,
|
||||
0x41, 0x41, 0x4E, 0xA7, 0x88, 0x9, 0xF1, 0x34, 0x53, 0x41, 0x58, 0x2F, 0x12, 0x96, 0xCA, 0xA2, 0x41, 0x41, 0x52, 0xD1, 0xBD, 0xDC,
|
||||
0xF0, 0x34, 0x53, 0x41, 0x1F, 0x12, 0xDB, 0xCF, 0xC3, 0xA2, 0x41, 0x41, 0xB9, 0x31, 0xA4, 0xE1, 0xF5, 0x34, 0x53, 0x41, 0x21, 0xBB,
|
||||
0x20, 0x6D, 0xC4, 0xA2, 0x41, 0x41, 0x67, 0xA7, 0xB6, 0xF, 0xF6, 0x34, 0x53, 0x41, 0x5A, 0x82, 0x4A, 0xD3, 0xCA, 0xA2, 0x41, 0x41,
|
||||
0xA7, 0x85, 0x3D, 0x58, 0xF1, 0x34, 0x53, 0x41, 0x22, 0xB8, 0x3A, 0x7D, 0xCB, 0xA2, 0x41, 0x41, 0x7D, 0x89, 0xA1, 0x8E, 0xF1, 0x34,
|
||||
0x53, 0x41, 0xD0, 0x77, 0x3F, 0x80, 0xCF, 0xA2, 0x41, 0x41, 0x57, 0x69, 0x83, 0xC4, 0xEE, 0x34, 0x53, 0x41, 0xA7, 0xF5, 0x8E, 0xF9,
|
||||
0xD1, 0xA2, 0x41, 0x41, 0x9A, 0xA2, 0x31, 0xEE, 0xEC, 0x34, 0x53, 0x41, 0x2A, 0xCD, 0xDE, 0x4C, 0xD4, 0xA2, 0x41, 0x41, 0x11, 0x43,
|
||||
0xE1, 0xF7, 0xEA, 0x34, 0x53, 0x41, 0xF, 0x89, 0xB1, 0x66, 0xD5, 0xA2, 0x41, 0x41, 0xC8, 0x5D, 0x86, 0xF1, 0xE9, 0x34, 0x53, 0x41,
|
||||
0x19, 0xF4, 0x73, 0x63, 0xD7, 0xA2, 0x41, 0x41, 0x7, 0xB1, 0x14, 0x36, 0xE8, 0x34, 0x53, 0x41, 0xDB, 0x1B, 0xB6, 0x7C, 0xD9, 0xA2,
|
||||
0x41, 0x41, 0x98, 0xB5, 0xE0, 0x74, 0xE6, 0x34, 0x53, 0x41, 0xC0, 0x3F, 0xC6, 0xAC, 0xD8, 0xA2, 0x41, 0x41, 0x9D, 0x74, 0xB0, 0x31,
|
||||
0xE6, 0x34, 0x53, 0x41, 0xF0, 0xB5, 0xB1, 0x53, 0xD5, 0xA2, 0x41, 0x41, 0x97, 0x47, 0xAD, 0x36, 0xE9, 0x34, 0x53, 0x41, 0xBB, 0x4B,
|
||||
0x9C, 0x59, 0xD2, 0xA2, 0x41, 0x41, 0x3A, 0xAA, 0x3F, 0xAE, 0xEB, 0x34, 0x53, 0x41 };
|
||||
|
||||
unsigned char sq_valid_blob[] = {
|
||||
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x40 };
|
||||
|
||||
unsigned char sq_invalid_blob[] = {
|
||||
0x23, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x40, 0x23 };
|
||||
|
||||
mapnik::context_ptr ctx(new mapnik::context_type);
|
||||
mapnik::feature_ptr feature = mapnik::feature_factory::create(ctx, 1);
|
||||
|
||||
// test of parsing wkb geometries
|
||||
try {
|
||||
|
||||
// spatialite blob
|
||||
mapnik::geometry::geometry<double> 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<mapnik::geometry::geometry_empty>()); // 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<mapnik::geometry::geometry_empty>()); // 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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue