From ee63a6f05540924ea5796eac147ae66cf238ebe7 Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Mon, 14 Feb 2022 10:15:09 +0100 Subject: [PATCH] [tests] also test when using static --- test/unit/datasource/csv.cpp | 128 +++++++++++++--------------- test/unit/datasource/gdal.cpp | 4 +- test/unit/datasource/geobuf.cpp | 4 +- test/unit/datasource/geojson.cpp | 4 +- test/unit/datasource/ogr.cpp | 6 +- test/unit/datasource/shapeindex.cpp | 8 +- 6 files changed, 73 insertions(+), 81 deletions(-) diff --git a/test/unit/datasource/csv.cpp b/test/unit/datasource/csv.cpp index 93724d05e..d9734edca 100644 --- a/test/unit/datasource/csv.cpp +++ b/test/unit/datasource/csv.cpp @@ -85,17 +85,15 @@ mapnik::datasource_ptr get_csv_ds(std::string const& file_name, bool strict = tr TEST_CASE("csv") { using mapnik::util::from_u8string; - std::string csv_plugin("./plugins/input/csv.input"); - if (mapnik::util::exists(csv_plugin)) + + // check the CSV datasource is loaded + const bool have_csv_plugin = mapnik::datasource_cache::instance().plugin_registered("csv"); + if (have_csv_plugin) { // make the tests silent since we intentionally test error conditions that are noisy auto const severity = mapnik::logger::instance().get_severity(); mapnik::logger::instance().set_severity(mapnik::logger::none); - // check the CSV datasource is loaded - const std::vector plugin_names = mapnik::datasource_cache::instance().plugin_names(); - const bool have_csv_plugin = std::find(plugin_names.begin(), plugin_names.end(), "csv") != plugin_names.end(); - SECTION("CSV I/O errors") { std::string filename = "does_not_exist.csv"; @@ -125,83 +123,77 @@ TEST_CASE("csv") { for (auto create_index : {false, true}) { - if (have_csv_plugin) - { - std::vector broken; - add_csv_files("test/data/csv/fails", broken); - add_csv_files("test/data/csv/warns", broken); - broken.emplace_back("test/data/csv/fails/does_not_exist.csv"); + std::vector broken; + add_csv_files("test/data/csv/fails", broken); + add_csv_files("test/data/csv/warns", broken); + broken.emplace_back("test/data/csv/fails/does_not_exist.csv"); - for (auto const& path : broken) + for (auto const& path : broken) + { + bool require_fail = true; + if (create_index) { - bool require_fail = true; - if (create_index) + int ret = create_disk_index(path); + int ret_posix = (ret >> 8) & 0x000000ff; + INFO(ret); + INFO(ret_posix); + require_fail = (boost::iends_with(path, "feature_id_counting.csv")) ? false : true; + if (!require_fail) { - int ret = create_disk_index(path); - int ret_posix = (ret >> 8) & 0x000000ff; - INFO(ret); - INFO(ret_posix); - require_fail = (boost::iends_with(path, "feature_id_counting.csv")) ? false : true; - if (!require_fail) - { - REQUIRE(mapnik::util::exists(path + ".index")); - } - } - INFO(path); - if (require_fail) - { - REQUIRE_THROWS(get_csv_ds(path)); - } - else - { - CHECK(bool(get_csv_ds(path))); - } - if (mapnik::util::exists(path + ".index")) - { - CHECK(mapnik::util::remove(path + ".index")); + REQUIRE(mapnik::util::exists(path + ".index")); } } + INFO(path); + if (require_fail) + { + REQUIRE_THROWS(get_csv_ds(path)); + } + else + { + CHECK(bool(get_csv_ds(path))); + } + if (mapnik::util::exists(path + ".index")) + { + CHECK(mapnik::util::remove(path + ".index")); + } } } } // END SECTION SECTION("good files") { - if (have_csv_plugin) - { - std::vector good; - add_csv_files("test/data/csv", good); - add_csv_files("test/data/csv/warns", good); + std::vector good; + add_csv_files("test/data/csv", good); + add_csv_files("test/data/csv/warns", good); - for (auto const& path : good) + for (auto const& path : good) + { + // cleanup in the case of a failed previous run + if (mapnik::util::exists(path + ".index")) { - // cleanup in the case of a failed previous run + mapnik::util::remove(path + ".index"); + } + for (auto create_index : {false, true}) + { + if (create_index) + { + int ret = create_disk_index(path); + int ret_posix = (ret >> 8) & 0x000000ff; + INFO(ret); + INFO(ret_posix); + if (!boost::iends_with(path, + "more_headers_than_column_values.csv")) // mapnik-index won't create + // *.index for 0 features + { + CHECK(mapnik::util::exists(path + ".index")); + } + } + auto ds = get_csv_ds(path, false); + // require a non-null pointer returned + REQUIRE(bool(ds)); if (mapnik::util::exists(path + ".index")) { - mapnik::util::remove(path + ".index"); - } - for (auto create_index : {false, true}) - { - if (create_index) - { - int ret = create_disk_index(path); - int ret_posix = (ret >> 8) & 0x000000ff; - INFO(ret); - INFO(ret_posix); - if (!boost::iends_with(path, - "more_headers_than_column_values.csv")) // mapnik-index won't create - // *.index for 0 features - { - CHECK(mapnik::util::exists(path + ".index")); - } - } - auto ds = get_csv_ds(path, false); - // require a non-null pointer returned - REQUIRE(bool(ds)); - if (mapnik::util::exists(path + ".index")) - { - CHECK(mapnik::util::remove(path + ".index")); - } + CHECK(mapnik::util::remove(path + ".index")); } } } diff --git a/test/unit/datasource/gdal.cpp b/test/unit/datasource/gdal.cpp index e7d13b3dc..e83cd5a52 100644 --- a/test/unit/datasource/gdal.cpp +++ b/test/unit/datasource/gdal.cpp @@ -31,8 +31,8 @@ namespace { mapnik::datasource_ptr get_gdal_ds(std::string const& file_name, boost::optional band) { - std::string gdal_plugin("./plugins/input/gdal.input"); - if (!mapnik::util::exists(gdal_plugin)) + const bool have_gdal_plugin = mapnik::datasource_cache::instance().plugin_registered("gdal"); + if (!have_gdal_plugin) { return mapnik::datasource_ptr(); } diff --git a/test/unit/datasource/geobuf.cpp b/test/unit/datasource/geobuf.cpp index 82859851c..4d371ced6 100644 --- a/test/unit/datasource/geobuf.cpp +++ b/test/unit/datasource/geobuf.cpp @@ -37,8 +37,8 @@ TEST_CASE("Geobuf") { - std::string geobuf_plugin("./plugins/input/geobuf.input"); - if (mapnik::util::exists(geobuf_plugin)) + const bool have_geobuf_plugin = mapnik::datasource_cache::instance().plugin_registered("geobuf"); + if (have_geobuf_plugin) { SECTION("Point") { diff --git a/test/unit/datasource/geojson.cpp b/test/unit/datasource/geojson.cpp index 528c0263b..308e51cff 100644 --- a/test/unit/datasource/geojson.cpp +++ b/test/unit/datasource/geojson.cpp @@ -81,8 +81,8 @@ void iterate_over_features(mapnik::featureset_ptr features) TEST_CASE("geojson") { - std::string geojson_plugin("./plugins/input/geojson.input"); - if (mapnik::util::exists(geojson_plugin)) + const bool have_geojson_plugin = mapnik::datasource_cache::instance().plugin_registered("geojson"); + if (have_geojson_plugin) { SECTION("GeoJSON I/O errors") { diff --git a/test/unit/datasource/ogr.cpp b/test/unit/datasource/ogr.cpp index c6bfc8bb9..8441ecc55 100644 --- a/test/unit/datasource/ogr.cpp +++ b/test/unit/datasource/ogr.cpp @@ -28,12 +28,12 @@ #include #include #include -#include +#include TEST_CASE("ogr") { - std::string geojson_plugin("./plugins/input/ogr.input"); - if (mapnik::util::exists(geojson_plugin)) + const bool have_ogr_plugin = mapnik::datasource_cache::instance().plugin_registered("ogr"); + if (have_ogr_plugin) { SECTION("ogr point feature") { diff --git a/test/unit/datasource/shapeindex.cpp b/test/unit/datasource/shapeindex.cpp index 45aaa2334..76881235b 100644 --- a/test/unit/datasource/shapeindex.cpp +++ b/test/unit/datasource/shapeindex.cpp @@ -98,8 +98,8 @@ int create_shapefile_index(std::string const& filename, bool index_parts, bool s TEST_CASE("invalid shapeindex") { - std::string shape_plugin("./plugins/input/shape.input"); - if (mapnik::util::exists(shape_plugin)) + const bool have_shape_plugin = mapnik::datasource_cache::instance().plugin_registered("shape"); + if (have_shape_plugin) { SECTION("Invalid index") { @@ -141,8 +141,8 @@ TEST_CASE("invalid shapeindex") TEST_CASE("shapeindex") { - std::string shape_plugin("./plugins/input/shape.input"); - if (mapnik::util::exists(shape_plugin)) + const bool have_shape_plugin = mapnik::datasource_cache::instance().plugin_registered("shape"); + if (have_shape_plugin) { SECTION("Index") {