diff --git a/.gitignore b/.gitignore index 9c51d709c..e2c080ff1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 326616d7a..c94020792 100755 --- a/Makefile +++ b/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 \ diff --git a/SConstruct b/SConstruct index 7ae42e5c2..e54fce9c1 100644 --- a/SConstruct +++ b/SConstruct @@ -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') diff --git a/run_tests b/run_tests deleted file mode 100755 index 51d9ccf36..000000000 --- a/run_tests +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -failures=0 - -source ./localize.sh - -echo "*** Running C++ tests..." -./tests/cxx/run -failures=$((failures+$?)) -echo - -exit $failures diff --git a/tests/cxx/build.py b/test/build.py similarity index 54% rename from tests/cxx/build.py rename to test/build.py index 6626f03c4..ec6dce5b3 100644 --- a/tests/cxx/build.py +++ b/test/build.py @@ -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) diff --git a/tests/cxx/catch.hpp b/test/catch.hpp similarity index 100% rename from tests/cxx/catch.hpp rename to test/catch.hpp diff --git a/tests/cxx/font_registration_test.cpp b/test/standalone/font_registration_test.cpp similarity index 99% rename from tests/cxx/font_registration_test.cpp rename to test/standalone/font_registration_test.cpp index d39837f77..a876c6a17 100644 --- a/tests/cxx/font_registration_test.cpp +++ b/test/standalone/font_registration_test.cpp @@ -1,3 +1,4 @@ +#define CATCH_CONFIG_MAIN #include "catch.hpp" #include @@ -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(); diff --git a/test/unit/README.md b/test/unit/README.md new file mode 100644 index 000000000..d446edec0 --- /dev/null +++ b/test/unit/README.md @@ -0,0 +1,11 @@ + +## C++ unit tests + +### Building + + python scons/scons.py test/unit/run + + +### Running + + ./test/unit/run \ No newline at end of file diff --git a/tests/cxx/conversions_test.cpp b/test/unit/core/conversions_test.cpp similarity index 100% rename from tests/cxx/conversions_test.cpp rename to test/unit/core/conversions_test.cpp diff --git a/tests/cxx/copy_move_test.cpp b/test/unit/core/copy_move_test.cpp similarity index 98% rename from tests/cxx/copy_move_test.cpp rename to test/unit/core/copy_move_test.cpp index 38d23d2eb..3b38ae76c 100644 --- a/tests/cxx/copy_move_test.cpp +++ b/test/unit/core/copy_move_test.cpp @@ -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) ); diff --git a/tests/cxx/exceptions_test.cpp b/test/unit/core/exceptions_test.cpp similarity index 100% rename from tests/cxx/exceptions_test.cpp rename to test/unit/core/exceptions_test.cpp diff --git a/tests/cxx/map_request_test.cpp b/test/unit/core/map_request_test.cpp similarity index 54% rename from tests/cxx/map_request_test.cpp rename to test/unit/core/map_request_test.cpp index 59b6033ac..202514d77 100644 --- a/tests/cxx/map_request_test.cpp +++ b/test/unit/core/map_request_test.cpp @@ -20,49 +20,10 @@ #include #include -bool compare_images(std::string const& src_fn,std::string const& dest_fn) -{ - using namespace mapnik; - std::unique_ptr reader1(mapnik::get_image_reader(dest_fn,"png")); - if (!reader1.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + dest_fn); - } - std::shared_ptr image_ptr1 = std::make_shared(reader1->width(),reader1->height()); - reader1->read(0,0,*image_ptr1); - - std::unique_ptr reader2(mapnik::get_image_reader(src_fn,"png")); - if (!reader2.get()) - { - throw mapnik::image_reader_exception("Failed to load: " + src_fn); - } - std::shared_ptr image_ptr2 = std::make_shared(reader2->width(),reader2->height()); - reader2->read(0,0,*image_ptr2); - - image_rgba8 const& dest = *image_ptr1; - image_rgba8 const& src = *image_ptr2; - - unsigned int width = src.width(); - unsigned int height = src.height(); - if ((width != dest.width()) || height != dest.height()) return false; - for (unsigned int y = 0; y < height; ++y) - { - const unsigned int* row_from = src.getRow(y); - const unsigned int* row_to = dest.getRow(y); - for (unsigned int x = 0; x < width; ++x) - { - if (row_from[x] != row_to[x]) return false; - } - } - return true; -} - 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 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 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 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 diff --git a/tests/cxx/params_test.cpp b/test/unit/core/params_test.cpp similarity index 100% rename from tests/cxx/params_test.cpp rename to test/unit/core/params_test.cpp diff --git a/tests/cxx/datasources.cpp b/test/unit/datasource/datasources.cpp similarity index 100% rename from tests/cxx/datasources.cpp rename to test/unit/datasource/datasources.cpp diff --git a/tests/cxx/fontset_runtime_test.cpp b/test/unit/font/fontset_runtime_test.cpp similarity index 100% rename from tests/cxx/fontset_runtime_test.cpp rename to test/unit/font/fontset_runtime_test.cpp diff --git a/tests/cxx/geometry.cpp b/test/unit/geometry/geometry.cpp similarity index 100% rename from tests/cxx/geometry.cpp rename to test/unit/geometry/geometry.cpp diff --git a/tests/cxx/geometry_converters_test.cpp b/test/unit/geometry/geometry_converters_test.cpp similarity index 100% rename from tests/cxx/geometry_converters_test.cpp rename to test/unit/geometry/geometry_converters_test.cpp diff --git a/tests/cxx/geometry_envelope_test.cpp b/test/unit/geometry/geometry_envelope_test.cpp similarity index 100% rename from tests/cxx/geometry_envelope_test.cpp rename to test/unit/geometry/geometry_envelope_test.cpp diff --git a/tests/cxx/geometry_equal.hpp b/test/unit/geometry/geometry_equal.hpp similarity index 100% rename from tests/cxx/geometry_equal.hpp rename to test/unit/geometry/geometry_equal.hpp diff --git a/tests/cxx/geometry_hit_test.cpp b/test/unit/geometry/geometry_hit_test.cpp similarity index 100% rename from tests/cxx/geometry_hit_test.cpp rename to test/unit/geometry/geometry_hit_test.cpp diff --git a/tests/cxx/geometry_is_valid.cpp b/test/unit/geometry/geometry_is_valid.cpp similarity index 100% rename from tests/cxx/geometry_is_valid.cpp rename to test/unit/geometry/geometry_is_valid.cpp diff --git a/tests/cxx/geometry_reprojection.cpp b/test/unit/geometry/geometry_reprojection.cpp similarity index 100% rename from tests/cxx/geometry_reprojection.cpp rename to test/unit/geometry/geometry_reprojection.cpp diff --git a/tests/cxx/geometry_strategy_test.cpp b/test/unit/geometry/geometry_strategy_test.cpp similarity index 100% rename from tests/cxx/geometry_strategy_test.cpp rename to test/unit/geometry/geometry_strategy_test.cpp diff --git a/tests/cxx/label_algo_test.cpp b/test/unit/geometry/label_algo_test.cpp similarity index 100% rename from tests/cxx/label_algo_test.cpp rename to test/unit/geometry/label_algo_test.cpp diff --git a/tests/cxx/image_io_test.cpp b/test/unit/imaging/image_io_test.cpp similarity index 100% rename from tests/cxx/image_io_test.cpp rename to test/unit/imaging/image_io_test.cpp diff --git a/tests/cxx/image_painted_test.cpp b/test/unit/imaging/image_painted_test.cpp similarity index 100% rename from tests/cxx/image_painted_test.cpp rename to test/unit/imaging/image_painted_test.cpp diff --git a/tests/cxx/tiff_io.cpp b/test/unit/imaging/tiff_io.cpp similarity index 99% rename from tests/cxx/tiff_io.cpp rename to test/unit/imaging/tiff_io.cpp index 7f7d798d1..46cf4245f 100644 --- a/tests/cxx/tiff_io.cpp +++ b/test/unit/imaging/tiff_io.cpp @@ -8,7 +8,7 @@ #include #include -#include "../../src/tiff_reader.cpp" +#include "../../../src/tiff_reader.cpp" #define TIFF_ASSERT(filename) \ mapnik::tiff_reader tiff_reader(filename); \ diff --git a/tests/cxx/agg_blend_src_over_test.cpp b/test/unit/pixel/agg_blend_src_over_test.cpp similarity index 100% rename from tests/cxx/agg_blend_src_over_test.cpp rename to test/unit/pixel/agg_blend_src_over_test.cpp diff --git a/test/unit/run.cpp b/test/unit/run.cpp new file mode 100644 index 000000000..613c3adb2 --- /dev/null +++ b/test/unit/run.cpp @@ -0,0 +1,17 @@ +#define CATCH_CONFIG_RUNNER +#include "catch.hpp" + +#include // 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; +} diff --git a/tests/cxx/wkb_formats_test.cpp b/test/unit/serialization/wkb_formats_test.cpp similarity index 100% rename from tests/cxx/wkb_formats_test.cpp rename to test/unit/serialization/wkb_formats_test.cpp diff --git a/tests/cxx/sql_parse.cpp b/test/unit/sql/sql_parse.cpp similarity index 100% rename from tests/cxx/sql_parse.cpp rename to test/unit/sql/sql_parse.cpp diff --git a/tests/cxx/symbolizer_test.cpp b/test/unit/symbolizer/symbolizer_test.cpp similarity index 100% rename from tests/cxx/symbolizer_test.cpp rename to test/unit/symbolizer/symbolizer_test.cpp diff --git a/tests/cxx/valgrind.supp b/test/unit/valgrind.supp similarity index 100% rename from tests/cxx/valgrind.supp rename to test/unit/valgrind.supp diff --git a/tests/cxx/clipping_test.cpp b/test/unit/vertex_adapter/clipping_test.cpp similarity index 100% rename from tests/cxx/clipping_test.cpp rename to test/unit/vertex_adapter/clipping_test.cpp diff --git a/tests/cxx/line_offset_test.cpp b/test/unit/vertex_adapter/line_offset_test.cpp similarity index 100% rename from tests/cxx/line_offset_test.cpp rename to test/unit/vertex_adapter/line_offset_test.cpp diff --git a/tests/cxx/simplify_converters_test.cpp b/test/unit/vertex_adapter/simplify_converters_test.cpp similarity index 100% rename from tests/cxx/simplify_converters_test.cpp rename to test/unit/vertex_adapter/simplify_converters_test.cpp diff --git a/tests/cxx/vertex_adapter.cpp b/test/unit/vertex_adapter/vertex_adapter.cpp similarity index 100% rename from tests/cxx/vertex_adapter.cpp rename to test/unit/vertex_adapter/vertex_adapter.cpp diff --git a/tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png b/tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png deleted file mode 100644 index cb8e47826..000000000 Binary files a/tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png and /dev/null differ diff --git a/tests/cpp_tests/support/map-request-marker-text-line-expected.png b/tests/cpp_tests/support/map-request-marker-text-line-expected.png deleted file mode 100644 index 9de752a29..000000000 Binary files a/tests/cpp_tests/support/map-request-marker-text-line-expected.png and /dev/null differ diff --git a/tests/cxx/README.md b/tests/cxx/README.md deleted file mode 100644 index 273cade25..000000000 --- a/tests/cxx/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -Catch C++ tests - -### Building - - python scons/scons.py tests/cxx/run - - -### Running - - ./tests/cxx/run \ No newline at end of file diff --git a/tests/cxx/test_main.cpp b/tests/cxx/test_main.cpp deleted file mode 100644 index 0c7c351f4..000000000 --- a/tests/cxx/test_main.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "catch.hpp"