summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-05-25 17:49:02 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2020-05-26 20:37:08 +0300
commitb8bc6228b4fb9741bc9382b0d2ab11bf77fd1dc1 (patch)
treec138944a4f74c7e42fcdad04790f7e5afba186a7
parent49d7f198f649f2ad1647857edb67a0a2e0535271 (diff)
downloadqtlocation-mapboxgl-b8bc6228b4fb9741bc9382b0d2ab11bf77fd1dc1.tar.gz
[test] Add Map.SymbolFlickeringOnZoom unit test
-rw-r--r--test/map/map.test.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index c221a80c4d..20ec3b4362 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -1658,4 +1658,83 @@ TEST(Map, VolatileSource) {
test.observer.didFinishLoadingMapCallback = [&] { test.runLoop.stop(); };
test.runLoop.run();
EXPECT_EQ(8, requestedTiles);
+}
+
+namespace {
+
+bool symbolHasFadedOut(const JointOpacityState& opacity) {
+ return (opacity.text.placed && opacity.text.opacity == 0.0f) ||
+ (opacity.icon.placed && opacity.icon.opacity == 0.0f);
+}
+
+} // namespace
+
+TEST(Map, SymbolFlickeringOnZoom) {
+ MapTest<> test{std::move(MapOptions().withMapMode(MapMode::Continuous))};
+ test.fileSource->spriteJSONResponse = makeResponse("sprite.json");
+ test.fileSource->spriteImageResponse = makeResponse("sprite.png");
+
+ test.frontend.getRenderer()->collectPlacedSymbolData(true);
+ test.map.getStyle().loadJSON(R"STYLE(
+{
+ "version": 8,
+ "sources": {
+ "geojson": {
+ "type": "geojson",
+ "data": {
+ "type": "Point",
+ "coordinates": [
+ -77.037603,
+ 38.917982
+ ]
+ }
+ }
+ },
+ "sprite": "local://sprites/sprite",
+ "layers": [
+ {
+ "id": "symbol",
+ "type": "symbol",
+ "source": "geojson",
+ "layout": {
+ "icon-image": "star-11"
+ }
+ }
+ ]
+}
+)STYLE");
+ test.frontend.getRenderer()->collectPlacedSymbolData(true);
+ test.observer.didFinishRenderingFrameCallback = [&](const auto& status) {
+ if (!status.needsRepaint) test.runLoop.stop();
+ };
+ const LatLng symbolLocation{38.917982, -77.037603};
+
+ test.map.jumpTo(CameraOptions().withZoom(12).withCenter(symbolLocation));
+ test.runLoop.run();
+
+ test.map.jumpTo(CameraOptions().withZoom(14).withCenter(symbolLocation));
+ test.runLoop.run();
+
+ bool flickeringChecked = false;
+ test.observer.didFinishRenderingFrameCallback = [&test, &flickeringChecked](const auto& status) {
+ if (!status.needsRepaint) test.runLoop.stop();
+ const auto& placedSymbols = test.frontend.getRenderer()->getPlacedSymbolsData();
+ if (placedSymbols.empty()) return; // Data reset at every render() call.
+ EXPECT_EQ(1u, placedSymbols.size());
+ const auto& placedSymbol = placedSymbols.front();
+ EXPECT_FALSE(placedSymbol.textPlaced || placedSymbol.textCollisionBox);
+ EXPECT_TRUE(placedSymbol.iconPlaced && placedSymbol.iconCollisionBox);
+ EXPECT_EQ("symbol", placedSymbol.layer);
+ if (placedSymbol.prevOpacity) {
+ // Make sure we're not placing already faded symbol,
+ // so that symbol flickering on zoom is avoided.
+ EXPECT_FALSE(symbolHasFadedOut(*placedSymbol.prevOpacity));
+ flickeringChecked = true;
+ }
+ };
+ // Zoom `14` tiles are fading.
+ test.map.jumpTo(CameraOptions().withZoom(12).withCenter(symbolLocation));
+
+ test.runLoop.run();
+ EXPECT_TRUE(flickeringChecked);
} \ No newline at end of file