From f68f7e88de8117a3ebadfd7330d2300c729ae0d6 Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Sat, 21 Nov 2020 19:03:55 +0100 Subject: [PATCH] fixed map_xml_test --- cmake/CopyDllsForDebug.cmake | 31 +++++++++++++++++++++++++++++++ test/CMakeLists.txt | 31 ++++++++++++++++++++----------- test/standalone/map_xml_test.cpp | 26 +++++++++++++------------- 3 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 cmake/CopyDllsForDebug.cmake diff --git a/cmake/CopyDllsForDebug.cmake b/cmake/CopyDllsForDebug.cmake new file mode 100644 index 000000000..f2f2b153b --- /dev/null +++ b/cmake/CopyDllsForDebug.cmake @@ -0,0 +1,31 @@ +# This is a helper script to run BundleUtilities fixup_bundle as postbuild +# for a target. The primary use case is to copy .DLLs to the build directory for +# the Windows platform. It allows generator expressions to be used to determine +# the binary location +# +# Usage : copy_dlls_for_debug TARGET LIBS DIRS +# - TARGET : A cmake target +# - See fixup_bundle for LIBS and DIRS arguments + +if(RUN_IT) +# Script ran by the add_custom_command + include(BundleUtilities) + include(InstallRequiredSystemLibraries) + fixup_bundle("${TO_FIXUP_FILE}" "${TO_FIXUP_LIBS}" "${TO_FIXUP_DIRS}") +# End of script ran by the add_custom_command +else() + +set(THIS_FILE ${CMAKE_CURRENT_LIST_FILE}) +function(copy_dlls_for_debug _target _libs _dirs) + if(WIN32) + add_custom_command( + TARGET ${_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -DRUN_IT:BOOL=ON -DTO_FIXUP_FILE=$ -DTO_FIXUP_LIBS=${_libs} -DTO_FIXUP_DIRS=${_dirs} -P ${THIS_FILE} + COMMENT "Fixing up dependencies for ${_target}" + VERBATIM + ) + endif(WIN32) +endfunction() + +endif() + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e551e8b8..400931134 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,7 @@ project(mapnik-test) -Include(FetchContent) +include(FetchContent) +include(CopyDllsForDebug) FetchContent_Declare( Catch2 @@ -13,6 +14,8 @@ set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) add_library(Catch INTERFACE) target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) + + add_executable(mapnik-test-unit unit/run.cpp unit/color/css_color.cpp @@ -131,15 +134,15 @@ target_link_libraries(font_registration_test PUBLIC mapnik::json ) -# not workable since boost::filesystem native returns a wstring and the function taskes a std::string -#add_executable(map_xml_test standalone/map_xml_test.cpp) -#target_link_libraries(map_xml_test PUBLIC -# Catch -# mapnik::headers -# mapnik::mapnik -# mapnik::agg -# mapnik::json -#) +#not workable since boost::filesystem native returns a wstring and the function taskes a std::string +add_executable(map_xml_test standalone/map_xml_test.cpp) +target_link_libraries(map_xml_test PUBLIC + Catch + mapnik::headers + mapnik::mapnik + mapnik::agg + mapnik::json +) add_executable(mapnik-test-visual visual/parse_map_sizes.cpp @@ -160,9 +163,15 @@ target_link_libraries( include(CTest) include(${catch2_SOURCE_DIR}/contrib/Catch.cmake) include(${catch2_SOURCE_DIR}/contrib/ParseAndAddCatchTests.cmake) +set(APPS mapnik-test-unit mapnik-test-visual mapnik::mapnik) # paths to executables +set(DIRS ${CMAKE_BINARY_DIR}/src/RelWithDebInfo) # directories to search for prerequisites +copy_dlls_for_debug(${APPS} \"\" ${DIRS}) + +file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test) +file(COPY data-visual DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test) ParseAndAddCatchTests(mapnik-test-unit) catch_discover_tests(agg_rasterizer_integer_overflow_test) catch_discover_tests(datasource_registration_test) catch_discover_tests(font_registration_test) -#catch_discover_tests(map_xml_test) \ No newline at end of file +catch_discover_tests(map_xml_test) \ No newline at end of file diff --git a/test/standalone/map_xml_test.cpp b/test/standalone/map_xml_test.cpp index b33a3f718..0bd42d14c 100644 --- a/test/standalone/map_xml_test.cpp +++ b/test/standalone/map_xml_test.cpp @@ -76,17 +76,17 @@ void compare_map(bfs::path xml) { // is a normalisation step to ensure that the file is in // whatever the current version of mapnik uses as the // standard indentation, quote style, etc... - REQUIRE_NOTHROW(mapnik::load_map(m, xml.native(), false, abs_base.native())); + REQUIRE_NOTHROW(mapnik::load_map(m, xml.generic_string(), false, abs_base.generic_string())); bfs::path test_map1 = dir.path() / "mapnik-temp-map1.xml"; - REQUIRE_NOTHROW(mapnik::save_map(m, test_map1.native())); + REQUIRE_NOTHROW(mapnik::save_map(m, test_map1.generic_string())); // create a new map, load the one saved in the previous // step, and write it out again. mapnik::Map new_map(256, 256); REQUIRE(new_map.register_fonts("fonts", true)); - REQUIRE_NOTHROW(mapnik::load_map(new_map, test_map1.native(), false, abs_base.native())); + REQUIRE_NOTHROW(mapnik::load_map(new_map, test_map1.generic_string(), false, abs_base.generic_string())); bfs::path test_map2 = dir.path() / "mapnik-temp-map2.xml"; - REQUIRE_NOTHROW(mapnik::save_map(new_map, test_map2.native())); + REQUIRE_NOTHROW(mapnik::save_map(new_map, test_map2.generic_string())); // if all the information survived the load/save round-trip // then the two files ought to be identical. @@ -102,7 +102,7 @@ void add_xml_files(bfs::path dir, std::vector &xml_files) { for (auto const &entry : boost::make_iterator_range( bfs::directory_iterator(dir), bfs::directory_iterator())) { auto path = entry.path(); - if (path.extension().native() == ".xml") { + if (path.extension().generic_string() == ".xml") { xml_files.emplace_back(path); } } @@ -112,7 +112,7 @@ void load_map(mapnik::Map &m, bfs::path const &path) { try { - mapnik::load_map(m, path.native()); + mapnik::load_map(m, path.generic_string()); } catch (std::exception const &ex) { @@ -129,7 +129,7 @@ void load_map(mapnik::Map &m, bfs::path const &path) { } // anonymous namespace -const bool registered = mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); +const bool registered = mapnik::datasource_cache::instance().register_datasources((bfs::path("plugins") / "input").generic_string()); TEST_CASE("map xml I/O") { // make sure plugins are loaded @@ -141,7 +141,7 @@ TEST_CASE("map xml I/O") { SECTION("good maps") { std::vector good_maps; - add_xml_files("test/data/good_maps", good_maps); + add_xml_files(bfs::path("test") / "data" / "good_maps", good_maps); for (auto const &path : good_maps) { CAPTURE(path.native()); @@ -157,7 +157,7 @@ TEST_CASE("map xml I/O") { } // END SECTION SECTION("duplicate styles only throw in strict mode") { - std::string duplicate_stylename("test/data/broken_maps/duplicate_stylename.xml"); + std::string duplicate_stylename((bfs::path("test") / "data" / "broken_maps" / "duplicate_stylename.xml").generic_string()); CAPTURE(duplicate_stylename); mapnik::Map m(256, 256); REQUIRE(m.register_fonts("fonts", true)); @@ -169,15 +169,15 @@ TEST_CASE("map xml I/O") { SECTION("broken maps") { std::vector broken_maps; - add_xml_files("test/data/broken_maps", broken_maps); - broken_maps.emplace_back("test/data/broken_maps/does_not_exist.xml"); + add_xml_files(bfs::path("test") / "data" / "broken_maps", broken_maps); + broken_maps.emplace_back(bfs::path("test") / "data" / "broken_maps" / "does_not_exist.xml"); for (auto const &path : broken_maps) { - CAPTURE(path.native()); + CAPTURE(path.generic_string()); mapnik::Map m(256, 256); REQUIRE(m.register_fonts("fonts", true)); - REQUIRE_THROWS(mapnik::load_map(m, path.native(), true)); + REQUIRE_THROWS(mapnik::load_map(m, path.generic_string(), true)); } } // END SECTION