formatting

This commit is contained in:
artemp 2015-08-19 12:04:45 +02:00
parent d4bc32908f
commit 710ec057e5

View file

@ -21,17 +21,21 @@
namespace bfs = boost::filesystem;
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(
bfs::directory_iterator(dir), bfs::directory_iterator())) {
bfs::directory_iterator(dir), bfs::directory_iterator()))
{
auto path = entry.path();
if (path.extension().native() == ".csv") {
if (path.extension().native() == ".csv")
{
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;
params["type"] = std::string("csv");
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,
std::initializer_list<std::string> const &names) {
std::initializer_list<std::string> const &names)
{
REQUIRE(fields.size() == names.size());
auto itr_a = fields.begin();
auto const end_a = fields.end();
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);
}
}
@ -165,9 +171,7 @@ TEST_CASE("csv") {
if (mapnik::util::exists(csv_plugin))
{
REQUIRE(registered);
// make the tests silent since we intentially test error conditions that are noisy
auto const severity = mapnik::logger::instance().get_severity();
mapnik::logger::instance().set_severity(mapnik::logger::none);
@ -185,7 +189,8 @@ TEST_CASE("csv") {
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)
{
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/warns", good);
for (auto const &path : good) {
for (auto const& path : good)
{
auto ds = get_csv_ds(path.native(), false);
// require a non-null pointer returned
REQUIRE(bool(ds));
@ -205,9 +211,12 @@ TEST_CASE("csv") {
}
} // END SECTION
SECTION("lon/lat detection") {
for (auto const &lon_name : {std::string("lon"), std::string("lng")}) {
SECTION("lon/lat detection")
{
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());
std::cerr << (boost::format("test/data/csv/%1%_lat.csv") % lon_name).str() << std::endl;
auto fields = ds->get_descriptor().get_descriptors();
require_field_names(fields, {lon_name, "lat"});
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);
mapnik::query query(ds->envelope());
for (auto const &field : fields) {
for (auto const &field : fields)
{
query.add_property_name(field.get_name());
}
auto features = ds->features(query);
@ -587,17 +597,16 @@ TEST_CASE("csv") {
using row = std::pair<std::string, std::size_t>;
for (auto const &r : {
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_no_newline.csv", 1}
}) {
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_no_newline.csv", 1}})
{
mapnik::parameters params;
params["type"] = std::string("csv");
params["file"] = r.first;
params["headers"] = "x,y,name";
auto ds = mapnik::datasource_cache::instance().create(params);
REQUIRE(bool(ds));
auto fields = ds->get_descriptor().get_descriptors();
require_field_names(fields, {"x", "y", "name"});
require_field_types(fields, {mapnik::Integer, mapnik::Integer, mapnik::String});
@ -674,7 +683,6 @@ TEST_CASE("csv") {
auto feat = fs->next();
CHECK(feature_count(feat->get_geometry()) == 1);
} // END SECTION
mapnik::logger::instance().set_severity(severity);
}
} // END TEST CASE