summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-03-26 17:11:03 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-02 11:50:52 +0300
commit57cd47b2fc9d74a18e5c72b08feb352079f8e6ca (patch)
tree9ff2851e09a3cc256720adf01dfb821c85626195 /test
parentc3b68fe91b648f26f10cb8e03f6a8e65681fd023 (diff)
downloadqtlocation-mapboxgl-57cd47b2fc9d74a18e5c72b08feb352079f8e6ca.tar.gz
Add Map.PlacedSymbolData unit test
Diffstat (limited to 'test')
-rw-r--r--test/map/map.test.cpp72
1 files changed, 71 insertions, 1 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index f582a662e0..2c3ca0cea3 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -1389,4 +1389,74 @@ TEST(Map, KeepRenderData) {
test.frontend.render(test.map);
EXPECT_EQ(resourcesCount * i, requestsCount);
}
-} \ No newline at end of file
+}
+
+namespace {
+
+bool isInsideTile(const mapbox::geometry::box<float>& box, float padding, Size viewportSize) {
+ if (box.min.x - padding < 0) return false;
+ if (box.min.y - padding < 0) return false;
+ if (box.max.x - padding > viewportSize.width) return false;
+ if (box.max.y - padding > viewportSize.height) return false;
+ return true;
+}
+
+} // namespace
+
+TEST(Map, PlacedSymbolData) {
+ MapTest<> test{std::move(MapOptions().withMapMode(MapMode::Tile))};
+
+ test.fileSource->tileResponse = makeResponse("vector.tile", true);
+ test.fileSource->glyphsResponse = makeResponse("glyphs.pbf", true);
+ test.fileSource->styleResponse = makeResponse("style_vector.json");
+ test.fileSource->sourceResponse = makeResponse("source_vector.json");
+ test.fileSource->spriteJSONResponse = makeResponse("sprite.json");
+ test.fileSource->spriteImageResponse = makeResponse("sprite.png");
+
+ // Camera options will give exactly one tile (12/1171/1566)
+ test.map.jumpTo(CameraOptions().withZoom(12).withCenter(LatLng{38.917982, -77.037603}));
+ test.map.getStyle().loadURL("mapbox://streets");
+ Size viewportSize = test.frontend.getSize();
+ test.frontend.getRenderer()->collectPlacedSymbolData(true);
+ test.frontend.render(test.map);
+
+ const auto& placedSymbols = test.frontend.getRenderer()->getPlacedSymbolsData();
+ EXPECT_FALSE(placedSymbols.empty());
+
+ int placedTextInsideTile = 0;
+ int placedText = 0;
+
+ int placedIconInsideTile = 0;
+ int placedIcon = 0;
+
+ int placedTotal = 0;
+
+ for (const auto& placedSymbol : placedSymbols) {
+ if (placedSymbol.textPlaced && placedSymbol.textCollisionBox) {
+ if (isInsideTile(*placedSymbol.textCollisionBox, placedSymbol.viewportPadding, viewportSize)) {
+ EXPECT_FALSE(placedSymbol.intersectsTileBorder);
+ ++placedTextInsideTile;
+ }
+ ++placedText;
+ }
+ if (placedSymbol.iconPlaced && placedSymbol.iconCollisionBox) {
+ if (isInsideTile(*placedSymbol.iconCollisionBox, placedSymbol.viewportPadding, viewportSize)) {
+ EXPECT_FALSE(placedSymbol.intersectsTileBorder);
+ ++placedIconInsideTile;
+ }
+ ++placedIcon;
+ }
+ ++placedTotal;
+ }
+ EXPECT_EQ(1, placedTextInsideTile);
+ EXPECT_EQ(28, placedText);
+
+ EXPECT_EQ(2, placedIconInsideTile);
+ EXPECT_EQ(29, placedIcon);
+
+ EXPECT_EQ(50, placedTotal);
+ test.frontend.getRenderer()->collectPlacedSymbolData(false);
+ test.frontend.render(test.map);
+
+ EXPECT_TRUE(test.frontend.getRenderer()->getPlacedSymbolsData().empty());
+}