formatting
This commit is contained in:
parent
d4bc32908f
commit
710ec057e5
1 changed files with 611 additions and 603 deletions
|
@ -21,17 +21,21 @@
|
||||||
namespace bfs = boost::filesystem;
|
namespace bfs = boost::filesystem;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void add_csv_files(bfs::path dir, std::vector<bfs::path> &csv_files) {
|
void add_csv_files(bfs::path dir, std::vector<bfs::path> &csv_files)
|
||||||
|
{
|
||||||
for (auto const &entry : boost::make_iterator_range(
|
for (auto const &entry : boost::make_iterator_range(
|
||||||
bfs::directory_iterator(dir), bfs::directory_iterator())) {
|
bfs::directory_iterator(dir), bfs::directory_iterator()))
|
||||||
|
{
|
||||||
auto path = entry.path();
|
auto path = entry.path();
|
||||||
if (path.extension().native() == ".csv") {
|
if (path.extension().native() == ".csv")
|
||||||
|
{
|
||||||
csv_files.emplace_back(path);
|
csv_files.emplace_back(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mapnik::datasource_ptr get_csv_ds(std::string const &file_name, bool strict = true) {
|
mapnik::datasource_ptr get_csv_ds(std::string const &file_name, bool strict = true)
|
||||||
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
params["type"] = std::string("csv");
|
params["type"] = std::string("csv");
|
||||||
params["file"] = file_name;
|
params["file"] = file_name;
|
||||||
|
@ -43,12 +47,14 @@ mapnik::datasource_ptr get_csv_ds(std::string const &file_name, bool strict = tr
|
||||||
}
|
}
|
||||||
|
|
||||||
void require_field_names(std::vector<mapnik::attribute_descriptor> const &fields,
|
void require_field_names(std::vector<mapnik::attribute_descriptor> const &fields,
|
||||||
std::initializer_list<std::string> const &names) {
|
std::initializer_list<std::string> const &names)
|
||||||
|
{
|
||||||
REQUIRE(fields.size() == names.size());
|
REQUIRE(fields.size() == names.size());
|
||||||
auto itr_a = fields.begin();
|
auto itr_a = fields.begin();
|
||||||
auto const end_a = fields.end();
|
auto const end_a = fields.end();
|
||||||
auto itr_b = names.begin();
|
auto itr_b = names.begin();
|
||||||
for (; itr_a != end_a; ++itr_a, ++itr_b) {
|
for (; itr_a != end_a; ++itr_a, ++itr_b)
|
||||||
|
{
|
||||||
CHECK(itr_a->get_name() == *itr_b);
|
CHECK(itr_a->get_name() == *itr_b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,9 +171,7 @@ TEST_CASE("csv") {
|
||||||
|
|
||||||
if (mapnik::util::exists(csv_plugin))
|
if (mapnik::util::exists(csv_plugin))
|
||||||
{
|
{
|
||||||
|
|
||||||
REQUIRE(registered);
|
REQUIRE(registered);
|
||||||
|
|
||||||
// make the tests silent since we intentially test error conditions that are noisy
|
// make the tests silent since we intentially test error conditions that are noisy
|
||||||
auto const severity = mapnik::logger::instance().get_severity();
|
auto const severity = mapnik::logger::instance().get_severity();
|
||||||
mapnik::logger::instance().set_severity(mapnik::logger::none);
|
mapnik::logger::instance().set_severity(mapnik::logger::none);
|
||||||
|
@ -185,7 +189,8 @@ TEST_CASE("csv") {
|
||||||
add_csv_files("test/data/csv/warns", broken);
|
add_csv_files("test/data/csv/warns", broken);
|
||||||
broken.emplace_back("test/data/csv/fails/does_not_exist.csv");
|
broken.emplace_back("test/data/csv/fails/does_not_exist.csv");
|
||||||
|
|
||||||
for (auto const &path : broken) {
|
for (auto const &path : broken)
|
||||||
|
{
|
||||||
REQUIRE_THROWS(get_csv_ds(path.native()));
|
REQUIRE_THROWS(get_csv_ds(path.native()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +202,8 @@ TEST_CASE("csv") {
|
||||||
add_csv_files("test/data/csv", good);
|
add_csv_files("test/data/csv", good);
|
||||||
add_csv_files("test/data/csv/warns", good);
|
add_csv_files("test/data/csv/warns", good);
|
||||||
|
|
||||||
for (auto const &path : good) {
|
for (auto const& path : good)
|
||||||
|
{
|
||||||
auto ds = get_csv_ds(path.native(), false);
|
auto ds = get_csv_ds(path.native(), false);
|
||||||
// require a non-null pointer returned
|
// require a non-null pointer returned
|
||||||
REQUIRE(bool(ds));
|
REQUIRE(bool(ds));
|
||||||
|
@ -205,9 +211,12 @@ TEST_CASE("csv") {
|
||||||
}
|
}
|
||||||
} // END SECTION
|
} // END SECTION
|
||||||
|
|
||||||
SECTION("lon/lat detection") {
|
SECTION("lon/lat detection")
|
||||||
for (auto const &lon_name : {std::string("lon"), std::string("lng")}) {
|
{
|
||||||
|
for (auto const &lon_name : {std::string("lon"), std::string("lng")})
|
||||||
|
{
|
||||||
auto ds = get_csv_ds((boost::format("test/data/csv/%1%_lat.csv") % lon_name).str());
|
auto ds = get_csv_ds((boost::format("test/data/csv/%1%_lat.csv") % lon_name).str());
|
||||||
|
std::cerr << (boost::format("test/data/csv/%1%_lat.csv") % lon_name).str() << std::endl;
|
||||||
auto fields = ds->get_descriptor().get_descriptors();
|
auto fields = ds->get_descriptor().get_descriptors();
|
||||||
require_field_names(fields, {lon_name, "lat"});
|
require_field_names(fields, {lon_name, "lat"});
|
||||||
require_field_types(fields, {mapnik::Integer, mapnik::Integer});
|
require_field_types(fields, {mapnik::Integer, mapnik::Integer});
|
||||||
|
@ -215,7 +224,8 @@ TEST_CASE("csv") {
|
||||||
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
||||||
|
|
||||||
mapnik::query query(ds->envelope());
|
mapnik::query query(ds->envelope());
|
||||||
for (auto const &field : fields) {
|
for (auto const &field : fields)
|
||||||
|
{
|
||||||
query.add_property_name(field.get_name());
|
query.add_property_name(field.get_name());
|
||||||
}
|
}
|
||||||
auto features = ds->features(query);
|
auto features = ds->features(query);
|
||||||
|
@ -587,17 +597,16 @@ TEST_CASE("csv") {
|
||||||
using row = std::pair<std::string, std::size_t>;
|
using row = std::pair<std::string, std::size_t>;
|
||||||
|
|
||||||
for (auto const &r : {
|
for (auto const &r : {
|
||||||
row{"test/data/csv/fails/needs_headers_two_lines.csv", 2}
|
row{"test/data/csv/fails/needs_headers_two_lines.csv", 2},
|
||||||
, row{"test/data/csv/fails/needs_headers_one_line.csv", 1}
|
row{"test/data/csv/fails/needs_headers_one_line.csv", 1},
|
||||||
, row{"test/data/csv/fails/needs_headers_one_line_no_newline.csv", 1}
|
row{"test/data/csv/fails/needs_headers_one_line_no_newline.csv", 1}})
|
||||||
}) {
|
{
|
||||||
mapnik::parameters params;
|
mapnik::parameters params;
|
||||||
params["type"] = std::string("csv");
|
params["type"] = std::string("csv");
|
||||||
params["file"] = r.first;
|
params["file"] = r.first;
|
||||||
params["headers"] = "x,y,name";
|
params["headers"] = "x,y,name";
|
||||||
auto ds = mapnik::datasource_cache::instance().create(params);
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
||||||
REQUIRE(bool(ds));
|
REQUIRE(bool(ds));
|
||||||
|
|
||||||
auto fields = ds->get_descriptor().get_descriptors();
|
auto fields = ds->get_descriptor().get_descriptors();
|
||||||
require_field_names(fields, {"x", "y", "name"});
|
require_field_names(fields, {"x", "y", "name"});
|
||||||
require_field_types(fields, {mapnik::Integer, mapnik::Integer, mapnik::String});
|
require_field_types(fields, {mapnik::Integer, mapnik::Integer, mapnik::String});
|
||||||
|
@ -674,7 +683,6 @@ TEST_CASE("csv") {
|
||||||
auto feat = fs->next();
|
auto feat = fs->next();
|
||||||
CHECK(feature_count(feat->get_geometry()) == 1);
|
CHECK(feature_count(feat->get_geometry()) == 1);
|
||||||
} // END SECTION
|
} // END SECTION
|
||||||
|
|
||||||
mapnik::logger::instance().set_severity(severity);
|
mapnik::logger::instance().set_severity(severity);
|
||||||
}
|
}
|
||||||
} // END TEST CASE
|
} // END TEST CASE
|
||||||
|
|
Loading…
Reference in a new issue