From 82be3104cd40372e6f99284ff0fccd1e3879fd1d Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 26 Nov 2018 08:26:26 +0200 Subject: [core] Fix VectorTileFeature::getValue() semantics after geometry@v1.0.0 --- src/mbgl/tile/vector_tile_data.cpp | 3 ++- test/tile/vector_tile.test.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index 6363b0d3dd..2d47515e0f 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -22,7 +22,8 @@ FeatureType VectorTileFeature::getType() const { } optional VectorTileFeature::getValue(const std::string& key) const { - return feature.getValue(key); + const optional value(feature.getValue(key)); + return value->is() ? nullopt : std::move(value); } std::unordered_map VectorTileFeature::getProperties() const { diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index cd53c7c4a4..ed3eda7863 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -73,3 +74,36 @@ TEST(VectorTile, Issue8542) { std::vector result; tile.querySourceFeatures(result, { { {"layer"} }, {} }); } + +TEST(VectorTileData, ParseResults) { + VectorTileData data(std::make_shared(util::read_file("test/fixtures/map/issue12432/0-0-0.mvt"))); + + std::vector layerNames = data.layerNames(); + ASSERT_EQ(layerNames.size(), 2u); + ASSERT_EQ(layerNames.at(0), "admin"); + ASSERT_EQ(layerNames.at(1), "water"); + + ASSERT_FALSE(data.getLayer("invalid")); + + std::unique_ptr layer = data.getLayer("admin"); + ASSERT_EQ(layer->getName(), "admin"); + ASSERT_EQ(layer->featureCount(), 17154u); + + try { + layer->getFeature(17154u); + ASSERT_TRUE(false) << "should throw: feature index is out of range."; + } catch (const std::out_of_range&) { + ASSERT_TRUE(true); + } + + std::unique_ptr feature = layer->getFeature(0u); + ASSERT_EQ(feature->getType(), mbgl::FeatureType::LineString); + ASSERT_TRUE(feature->getID().is()); + ASSERT_EQ(feature->getID().get(), 1u); + + std::unordered_map properties = feature->getProperties(); + ASSERT_EQ(properties.size(), 3u); + ASSERT_EQ(properties.at("disputed"), *feature->getValue("disputed")); + + ASSERT_EQ(feature->getValue("invalid"), nullopt); +} \ No newline at end of file -- cgit v1.2.1