diff options
Diffstat (limited to 'test/util/merge_lines.test.cpp')
-rw-r--r-- | test/util/merge_lines.test.cpp | 113 |
1 files changed, 47 insertions, 66 deletions
diff --git a/test/util/merge_lines.test.cpp b/test/util/merge_lines.test.cpp index 8a3a400887..d3a2ebae03 100644 --- a/test/util/merge_lines.test.cpp +++ b/test/util/merge_lines.test.cpp @@ -1,50 +1,31 @@ #include <mbgl/test/util.hpp> +#include <mbgl/test/stub_geometry_tile_feature.hpp> #include <mbgl/layout/merge_lines.hpp> #include <mbgl/layout/symbol_feature.hpp> +#include <utility> const std::u16string aaa = u"a"; const std::u16string bbb = u"b"; using namespace mbgl; -class GeometryTileFeatureStub : public GeometryTileFeature { -public: - GeometryTileFeatureStub(optional<FeatureIdentifier> id_, FeatureType type_, GeometryCollection geometry_, - std::unordered_map<std::string, Value> properties_) : - id(id_), - type(type_), - geometry(geometry_), - properties(properties_) - {} - - FeatureType getType() const override { return type; } - optional<Value> getValue(const std::string& key) const override { - auto it = properties.find(key); - if (it != properties.end()) { - return it->second; - } - return {}; - }; - std::unordered_map<std::string,Value> getProperties() const override { return properties; }; - optional<FeatureIdentifier> getID() const override { return id; }; - GeometryCollection getGeometries() const override { return geometry; }; - - optional<FeatureIdentifier> id; - FeatureType type; - GeometryCollection geometry; - std::unordered_map<std::string,Value> properties; -}; +namespace { + +PropertyMap properties; +LineString<int16_t> emptyLine; + +} class SymbolFeatureStub : public SymbolFeature { public: SymbolFeatureStub(optional<FeatureIdentifier> id_, FeatureType type_, GeometryCollection geometry_, - std::unordered_map<std::string, Value> properties_, optional<std::u16string> text_, - optional<std::string> icon_, std::size_t index_) : - SymbolFeature(std::make_unique<GeometryTileFeatureStub>(id_, type_, geometry_, properties_)) + PropertyMap properties_, optional<std::u16string> text_, + optional<std::string> icon_, std::size_t index_) : + SymbolFeature(std::make_unique<StubGeometryTileFeature>(std::move(id_), type_, std::move(geometry_), std::move(properties_))) { - text = text_; - icon = icon_; + text = std::move(text_); + icon = std::move(icon_); index = index_; } }; @@ -52,20 +33,20 @@ public: TEST(MergeLines, SameText) { // merges lines with the same text std::vector<mbgl::SymbolFeature> input1; - input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, {}, aaa, {}, 0)); - input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, {}, bbb, {}, 0)); - input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{8, 0}, {9, 0}}}, {}, aaa, {}, 0)); - input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, {}, aaa, {}, 0)); - input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{6, 0}, {7, 0}, {8, 0}}}, {}, aaa, {}, 0)); - input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{5, 0}, {6, 0}}}, {}, aaa, {}, 0)); - - const std::vector<GeometryTileFeatureStub> expected1 = { - { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}}, {} }, - { {}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, {} }, - { {}, FeatureType::LineString, {{{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}}, {} }, - { {}, FeatureType::LineString, {{}}, {} }, - { {}, FeatureType::LineString, {{}}, {} }, - { {}, FeatureType::LineString, {{}}, {} } + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, properties, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, properties, bbb, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{8, 0}, {9, 0}}}, properties, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, properties, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{6, 0}, {7, 0}, {8, 0}}}, properties, aaa, {}, 0)); + input1.push_back(SymbolFeatureStub({}, FeatureType::LineString, {{{5, 0}, {6, 0}}}, properties, aaa, {}, 0)); + + const std::vector<StubGeometryTileFeature> expected1 = { + { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}}, properties }, + { {}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, properties }, + { {}, FeatureType::LineString, {{{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}}, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties } }; mbgl::util::mergeLines(input1); @@ -78,14 +59,14 @@ TEST(MergeLines, SameText) { TEST(MergeLines, BothEnds) { // mergeLines handles merge from both ends std::vector<mbgl::SymbolFeature> input2; - input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, {}, aaa, {}, 0 }); - input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, {}, aaa, {}, 0 }); - input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, {}, aaa, {}, 0 }); - - const std::vector<GeometryTileFeatureStub> expected2 = { - { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}}, {} }, - { {}, FeatureType::LineString, {{}}, {} }, - { {}, FeatureType::LineString, {{}}, {} } + input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, properties, aaa, {}, 0 }); + input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{4, 0}, {5, 0}, {6, 0}}}, properties, aaa, {}, 0 }); + input2.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, properties, aaa, {}, 0 }); + + const std::vector<StubGeometryTileFeature> expected2 = { + { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}}, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties } }; mbgl::util::mergeLines(input2); @@ -98,14 +79,14 @@ TEST(MergeLines, BothEnds) { TEST(MergeLines, CircularLines) { // mergeLines handles circular lines std::vector<mbgl::SymbolFeature> input3; - input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, {}, aaa, {}, 0 }); - input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, {}, aaa, {}, 0 }); - input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{4, 0}, {0, 0}}}, {}, aaa, {}, 0 }); - - const std::vector<GeometryTileFeatureStub> expected3 = { - { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {0, 0}}}, {} }, - { {}, FeatureType::LineString, {{}}, {} }, - { {}, FeatureType::LineString, {{}}, {} } + input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}}}, properties, aaa, {}, 0 }); + input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{2, 0}, {3, 0}, {4, 0}}}, properties, aaa, {}, 0 }); + input3.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{{4, 0}, {0, 0}}}, properties, aaa, {}, 0 }); + + const std::vector<StubGeometryTileFeature> expected3 = { + { {}, FeatureType::LineString, {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {0, 0}}}, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties }, + { {}, FeatureType::LineString, { emptyLine }, properties } }; mbgl::util::mergeLines(input3); @@ -117,9 +98,9 @@ TEST(MergeLines, CircularLines) { TEST(MergeLines, EmptyOuterGeometry) { std::vector<mbgl::SymbolFeature> input; - input.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {}, {}, aaa, {}, 0 }); + input.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {}, properties, aaa, {}, 0 }); - const std::vector<GeometryTileFeatureStub> expected = { { {}, FeatureType::LineString, {}, {} } }; + const std::vector<StubGeometryTileFeature> expected = { { {}, FeatureType::LineString, {}, properties } }; mbgl::util::mergeLines(input); @@ -128,9 +109,9 @@ TEST(MergeLines, EmptyOuterGeometry) { TEST(MergeLines, EmptyInnerGeometry) { std::vector<mbgl::SymbolFeature> input; - input.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {{}}, {}, aaa, {}, 0 }); + input.push_back(SymbolFeatureStub { {}, FeatureType::LineString, {}, properties, aaa, {}, 0 }); - const std::vector<GeometryTileFeatureStub> expected = { { {}, FeatureType::LineString, {{}}, {} } }; + const std::vector<StubGeometryTileFeature> expected = { { {}, FeatureType::LineString, {}, properties } }; mbgl::util::mergeLines(input); |