From 58f30f3d427d99419b696d3325e73d63e787a471 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 9 Nov 2015 10:47:07 -0800 Subject: [PATCH] more CSV test coverage - refs #3098 --- test/unit/datasource/csv.cpp | 39 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/test/unit/datasource/csv.cpp b/test/unit/datasource/csv.cpp index 9fb9f9fe7..72e87193c 100644 --- a/test/unit/datasource/csv.cpp +++ b/test/unit/datasource/csv.cpp @@ -63,7 +63,7 @@ void add_csv_files(std::string dir, std::vector &csv_files) } } -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, std::string const& base="") { mapnik::parameters params; params["type"] = std::string("csv"); @@ -130,6 +130,10 @@ TEST_CASE("csv") { params["type"] = "csv"; params["file"] = filename; REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params)); + params["base"] = ""; + REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params)); + params["base"] = "/"; + REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params)); } } @@ -268,21 +272,24 @@ TEST_CASE("csv") { { for (auto create_index : { false, true }) { - std::string filename = "test/data/csv/nypd.csv"; + std::string base = "test/data/csv/"; + std::string filename = "nypd.csv"; + std::string filepath = base + filename; // cleanup in the case of a failed previous run - if (mapnik::util::exists(filename + ".index")) + if (mapnik::util::exists(filepath + ".index")) { - mapnik::util::remove(filename + ".index"); + mapnik::util::remove(filepath + ".index"); } if (create_index) { - int ret = create_disk_index(filename); + int ret = create_disk_index(filepath); int ret_posix = (ret >> 8) & 0x000000ff; INFO(ret); INFO(ret_posix); - CHECK(mapnik::util::exists(filename + ".index")); + CHECK(mapnik::util::exists(filepath + ".index")); } - auto ds = get_csv_ds(filename); + auto ds = get_csv_ds(filepath,true,base); + CHECK(ds->type() == mapnik::datasource::datasource_t::Vector); auto fields = ds->get_descriptor().get_descriptors(); require_field_names(fields, {"Precinct", "Phone", "Address", "City", "geo_longitude", "geo_latitude", "geo_accuracy"}); require_field_types(fields, {mapnik::String, mapnik::String, mapnik::String, mapnik::String, mapnik::Double, mapnik::Double, mapnik::String}); @@ -290,8 +297,14 @@ TEST_CASE("csv") { CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point); CHECK(count_features(all_features(ds)) == 2); - auto feature = all_features(ds)->next(); - require_attributes(feature, { + auto fs = all_features(ds); + auto fs2 = ds->features_at_point(ds->envelope().center(),10000); + REQUIRE(fs != nullptr); + auto feature = fs->next(); + auto feature2 = fs2->next(); + REQUIRE(feature != nullptr); + REQUIRE(feature2 != nullptr); + auto expected_attr = { attr { "City", mapnik::value_unicode_string("New York, NY") } , attr { "geo_accuracy", mapnik::value_unicode_string("house") } , attr { "Phone", mapnik::value_unicode_string("(212) 334-0711") } @@ -299,10 +312,12 @@ TEST_CASE("csv") { , attr { "Precinct", mapnik::value_unicode_string("5th Precinct") } , attr { "geo_longitude", mapnik::value_integer(-70) } , attr { "geo_latitude", mapnik::value_integer(40) } - }); - if (mapnik::util::exists(filename + ".index")) + }; + require_attributes(feature, expected_attr); + require_attributes(feature2, expected_attr); + if (mapnik::util::exists(filepath + ".index")) { - mapnik::util::remove(filename + ".index"); + mapnik::util::remove(filepath + ".index"); } } } // END SECTION