[tests] also test when using static

This commit is contained in:
Mathis Logemann 2022-02-14 10:15:09 +01:00
parent 0f0e06c6b8
commit ee63a6f055
6 changed files with 73 additions and 81 deletions

View file

@ -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<std::string> 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<std::string> 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<std::string> 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<std::string> good;
add_csv_files("test/data/csv", good);
add_csv_files("test/data/csv/warns", good);
std::vector<std::string> 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"));
}
}
}

View file

@ -31,8 +31,8 @@ namespace {
mapnik::datasource_ptr get_gdal_ds(std::string const& file_name, boost::optional<mapnik::value_integer> 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();
}

View file

@ -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")
{

View file

@ -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")
{

View file

@ -28,12 +28,12 @@
#include <mapnik/image.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/util/fs.hpp>
#include <mapnik/datasource_cache.hpp>
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")
{

View file

@ -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")
{