reorganize c++ tests
This commit is contained in:
parent
c03998d4c9
commit
edf7616b19
41 changed files with 61 additions and 109 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -49,5 +49,5 @@ demo/viewer/release/
|
|||
demo/viewer/ui_about.h
|
||||
demo/viewer/ui_info.h
|
||||
demo/viewer/ui_layer_info.h
|
||||
tests/cpp_tests/*-bin
|
||||
tests/cxx/run
|
||||
test/standalone/*-bin
|
||||
test/unit/run
|
||||
|
|
19
Makefile
19
Makefile
|
@ -59,18 +59,12 @@ uninstall:
|
|||
@$(PYTHON) scons/scons.py -j$(JOBS) --config=cache --implicit-cache --max-drift=1 uninstall
|
||||
|
||||
test:
|
||||
./run_tests
|
||||
@source localize.sh && ./test/unit/run && \
|
||||
for FILE in test/standalone/*-bin; do \
|
||||
$${FILE}; \
|
||||
done;
|
||||
|
||||
test-local:
|
||||
make test
|
||||
|
||||
test-cpp:
|
||||
./tests/cpp_tests/run
|
||||
|
||||
test-cxx:
|
||||
./tests/cxx/run
|
||||
|
||||
check: test-local
|
||||
check: test
|
||||
|
||||
bench:
|
||||
./benchmark/run
|
||||
|
@ -86,9 +80,10 @@ pep8:
|
|||
@pep8 -r --select=W391 -q --filename=*.py `pwd`/tests/ | xargs ged -i '/./,/^$$/!d'
|
||||
|
||||
grind:
|
||||
@for FILE in tests/cpp_tests/*-bin; do \
|
||||
@for FILE in test/standalone/*-bin; do \
|
||||
valgrind --leak-check=full --log-fd=1 $${FILE} | grep definitely; \
|
||||
done
|
||||
valgrind --leak-check=full --log-fd=1 ./test/unit/run | grep definitely
|
||||
|
||||
render:
|
||||
@for FILE in tests/data/good_maps/*xml; do \
|
||||
|
|
|
@ -1950,7 +1950,7 @@ if not HELP_REQUESTED:
|
|||
SConscript('fonts/build.py')
|
||||
|
||||
# build C++ tests
|
||||
SConscript('tests/cxx/build.py')
|
||||
SConscript('test/build.py')
|
||||
|
||||
if env['BENCHMARK']:
|
||||
SConscript('benchmark/build.py')
|
||||
|
|
12
run_tests
12
run_tests
|
@ -1,12 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
failures=0
|
||||
|
||||
source ./localize.sh
|
||||
|
||||
echo "*** Running C++ tests..."
|
||||
./tests/cxx/run
|
||||
failures=$((failures+$?))
|
||||
echo
|
||||
|
||||
exit $failures
|
|
@ -7,7 +7,7 @@ Import ('env')
|
|||
test_env = env.Clone()
|
||||
|
||||
if not env['CPP_TESTS']:
|
||||
for cpp_test_bin in glob.glob('*-bin'):
|
||||
for cpp_test_bin in glob.glob('./*/*-bin'):
|
||||
os.unlink(cpp_test_bin)
|
||||
else:
|
||||
test_env['LIBS'] = [env['MAPNIK_NAME']]
|
||||
|
@ -22,11 +22,23 @@ else:
|
|||
if test_env['HAS_CAIRO']:
|
||||
test_env.PrependUnique(CPPPATH=test_env['CAIRO_CPPPATHS'])
|
||||
test_env.Append(CPPDEFINES = '-DHAVE_CAIRO')
|
||||
test_env.PrependUnique(CPPPATH=['./'])
|
||||
test_env_local = test_env.Clone()
|
||||
test_program = test_env_local.Program("run", source=glob.glob('*.cpp'))
|
||||
Depends(test_program, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
|
||||
Depends(test_program, env.subst('../../src/json/libmapnik-json${LIBSUFFIX}'))
|
||||
Depends(test_program, env.subst('../../src/wkt/libmapnik-wkt${LIBSUFFIX}'))
|
||||
|
||||
|
||||
# unit tests
|
||||
sources = glob.glob('./unit/*/*.cpp')
|
||||
sources.extend(glob.glob('./unit/*.cpp'))
|
||||
test_program = test_env_local.Program("./unit/run", source=sources)
|
||||
Depends(test_program, env.subst('../src/%s' % env['MAPNIK_LIB_NAME']))
|
||||
Depends(test_program, env.subst('../src/json/libmapnik-json${LIBSUFFIX}'))
|
||||
Depends(test_program, env.subst('../src/wkt/libmapnik-wkt${LIBSUFFIX}'))
|
||||
|
||||
# standalone tests
|
||||
for standalone in glob.glob('./standalone/*cpp'):
|
||||
test_program = test_env_local.Program(standalone.replace('.cpp','-bin'), source=standalone)
|
||||
Depends(test_program, env.subst('../src/%s' % env['MAPNIK_LIB_NAME']))
|
||||
|
||||
# build locally if installing
|
||||
if 'install' in COMMAND_LINE_TARGETS:
|
||||
env.Alias('install',test_program)
|
|
@ -1,3 +1,4 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/font_engine_freetype.hpp>
|
||||
|
@ -18,8 +19,6 @@ SECTION("registration") {
|
|||
mapnik::logger logger;
|
||||
mapnik::logger::severity_type original_severity = logger.get_severity();
|
||||
|
||||
|
||||
|
||||
// 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();
|
11
test/unit/README.md
Normal file
11
test/unit/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
## C++ unit tests
|
||||
|
||||
### Building
|
||||
|
||||
python scons/scons.py test/unit/run
|
||||
|
||||
|
||||
### Running
|
||||
|
||||
./test/unit/run
|
|
@ -28,7 +28,7 @@ SECTION("layers") {
|
|||
|
||||
auto ds1 = ds0; // shared ptr copy
|
||||
REQUIRE( (ds1 == ds0) );
|
||||
REQUIRE( (*ds1 != *ds0) );
|
||||
REQUIRE( !(*ds1 != *ds0) );
|
||||
REQUIRE( (ds1.get() == ds0.get()) );
|
||||
ds1 = mapnik::datasource_cache::instance().create(p); // new with the same parameters
|
||||
REQUIRE( (ds1 != ds0) );
|
|
@ -20,49 +20,10 @@
|
|||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
TEST_CASE("mapnik::request") {
|
||||
|
||||
SECTION("rendering") {
|
||||
|
||||
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 {
|
||||
|
||||
mapnik::datasource_cache::instance().register_datasources("plugins/input/csv.input");
|
||||
|
@ -76,12 +37,6 @@ SECTION("rendering") {
|
|||
// 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
|
||||
//REQUIRE(compare_images(actual1,expected));
|
||||
|
||||
// reset image
|
||||
mapnik::fill(im, 0);
|
||||
|
@ -94,11 +49,6 @@ SECTION("rendering") {
|
|||
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
|
||||
//REQUIRE(compare_images(actual2,expected));
|
||||
|
||||
// reset image
|
||||
mapnik::fill(im, 0);
|
||||
|
@ -128,11 +78,6 @@ SECTION("rendering") {
|
|||
}
|
||||
}
|
||||
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
|
||||
//REQUIRE(compare_images(actual3,expected));
|
||||
|
||||
// also test cairo
|
||||
#if defined(HAVE_CAIRO)
|
||||
|
@ -143,11 +88,9 @@ SECTION("rendering") {
|
|||
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
|
||||
//REQUIRE(compare_images(actual_cairo,expected_cairo));
|
||||
//std::string actual_cairo("/tmp/map-request-marker-text-line-actual4.png");
|
||||
//cairo_surface_write_to_png(&*image_surface, actual_cairo.c_str());
|
||||
// TODO - non visual way to test
|
||||
#endif
|
||||
// TODO - test grid_renderer
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
#include <mapnik/util/file_io.hpp>
|
||||
|
||||
#include <mapnik/tiff_io.hpp>
|
||||
#include "../../src/tiff_reader.cpp"
|
||||
#include "../../../src/tiff_reader.cpp"
|
||||
|
||||
#define TIFF_ASSERT(filename) \
|
||||
mapnik::tiff_reader<boost::iostreams::file_source> tiff_reader(filename); \
|
17
test/unit/run.cpp
Normal file
17
test/unit/run.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <libxml/parser.h> // for xmlInitParser(), xmlCleanupParser()
|
||||
|
||||
int main (int argc, char* const argv[])
|
||||
{
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
if (!result) printf("\x1b[1;32m ✓ \x1b[0m\n");
|
||||
|
||||
// only call this once, on exit
|
||||
// to make sure valgrind output is clean
|
||||
// http://xmlsoft.org/xmlmem.html
|
||||
xmlCleanupParser();
|
||||
|
||||
return result;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 30 KiB |
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
|
@ -1,11 +0,0 @@
|
|||
|
||||
Catch C++ tests
|
||||
|
||||
### Building
|
||||
|
||||
python scons/scons.py tests/cxx/run
|
||||
|
||||
|
||||
### Running
|
||||
|
||||
./tests/cxx/run
|
|
@ -1,2 +0,0 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
Loading…
Reference in a new issue