Merge remote-tracking branch 'origin/json-properties' into json-properties

This commit is contained in:
artemp 2016-05-06 10:58:44 +02:00
commit 908203f15e
2 changed files with 70 additions and 5 deletions

View file

@ -106,13 +106,18 @@ inline std::size_t count_features(mapnik::featureset_ptr features) {
}
using attr = std::tuple<std::string, mapnik::value>;
#define REQUIRE_ATTRIBUTES(feature, attrs) \
REQUIRE(bool(feature)); \
for (auto const &kv : attrs) { \
REQUIRE(feature->has_key(std::get<0>(kv))); \
CHECK(feature->get(std::get<0>(kv)) == std::get<1>(kv)); \
} \
inline void require_attributes(mapnik::feature_ptr feature,
std::initializer_list<attr> const &attrs) {
REQUIRE(bool(feature));
for (auto const &kv : attrs) {
REQUIRE(feature->has_key(std::get<0>(kv)));
CHECK(feature->get(std::get<0>(kv)) == std::get<1>(kv));
}
REQUIRE_ATTRIBUTES(feature, attrs);
}
namespace detail {

View file

@ -654,5 +654,65 @@ TEST_CASE("geojson") {
}
}
}
SECTION("GeoJSON properties are properly expressed")
{
mapnik::parameters params;
params["type"] = "geojson";
std::string filename("./test/data/json/escaped.geojson");
params["file"] = filename;
// cleanup in the case of a failed previous run
if (mapnik::util::exists(filename + ".index"))
{
mapnik::util::remove(filename + ".index");
}
for (auto create_index : { true, false })
{
if (create_index)
{
CHECK(!mapnik::util::exists(filename + ".index"));
int ret = create_disk_index(filename);
int ret_posix = (ret >> 8) & 0x000000ff;
INFO(ret);
INFO(ret_posix);
CHECK(mapnik::util::exists(filename + ".index"));
}
for (auto cache_features : {true, false})
{
params["cache_features"] = cache_features;
auto ds = mapnik::datasource_cache::instance().create(params);
REQUIRE(bool(ds));
auto fields = ds->get_descriptor().get_descriptors();
std::initializer_list<std::string> names = {"NOM_FR","array","boolean","description","double","int","name","object","spaces"};
REQUIRE_FIELD_NAMES(fields, names);
auto fs = all_features(ds);
REQUIRE(bool(fs));
std::initializer_list<attr> attrs = {
attr{"name", mapnik::value_unicode_string("Test")},
attr{"NOM_FR", mapnik::value_unicode_string("Québec")},
attr{"bool", mapnik::value_bool("true")},
attr{"description", mapnik::value_unicode_string("Test: \u005C")},
attr{"double", mapnik::value_double(1.1)},
attr{"int", mapnik::value_integer(1)},
attr{"object", mapnik::value_unicode_string("{\"name\":\"waka\",\"spaces\":\"value with spaces\",\"int\": 1,\"double\":1.1,\"boolean\":false,\"NOM_FR\":\"Québec\"}")},
attr{"spaces", mapnik::value_unicode_string("this has spaces")},
attr{"array", mapnik::value_unicode_string("[\"string\",\"value with spaces\",3,1.1,null,true,\"Québec\"]")}
};
auto feature = fs->next();
REQUIRE(bool(feature));
REQUIRE_ATTRIBUTES(feature, attrs);
}
// cleanup
if (create_index && mapnik::util::exists(filename + ".index"))
{
mapnik::util::remove(filename + ".index");
}
}
}
}
}