diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-04-20 15:55:13 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-04-20 21:54:31 +0300 |
commit | f41992819d5e6d16b395d96c441b7a1ecc91638e (patch) | |
tree | 0ff95e97139d0d0c51f666063ad046a1f4aa7e43 | |
parent | ac6c5d9ce09b76f0de3872589437b22c1c4984ac (diff) | |
download | qtlocation-mapboxgl-f41992819d5e6d16b395d96c441b7a1ecc91638e.tar.gz |
Add Source.SourceMinimumUpdateInterval unit test
-rw-r--r-- | test/style/source.test.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 06afd6427f..a77be5523c 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -749,6 +749,7 @@ public: renderable = true; } void setNecessity(TileNecessity necessity) override; + void setMinimumUpdateInterval(Duration) override; bool layerPropertiesUpdated(const Immutable<style::LayerProperties>&) override { return true; } std::unique_ptr<TileRenderData> createRenderData() override { return nullptr; } @@ -760,6 +761,7 @@ private: class FakeTileSource : public RenderTileSetSource { public: MOCK_METHOD1(tileSetNecessity, void(TileNecessity)); + MOCK_METHOD1(tileSetMinimumUpdateInterval, void(Duration)); explicit FakeTileSource(Immutable<style::Source::Impl> impl_) : RenderTileSetSource(std::move(impl_)) {} void updateInternal(const Tileset& tileset, @@ -787,6 +789,10 @@ void FakeTile::setNecessity(TileNecessity necessity) { source.tileSetNecessity(necessity); } +void FakeTile::setMinimumUpdateInterval(Duration interval) { + source.tileSetMinimumUpdateInterval(interval); +} + } // namespace TEST(Source, InvisibleSourcesTileNecessity) { @@ -812,6 +818,49 @@ TEST(Source, InvisibleSourcesTileNecessity) { renderSource->update(initialized.baseImpl, layers, true, false, test.tileParameters()); } +TEST(Source, SourceMinimumUpdateInterval) { + SourceTest test; + VectorSource initialized("source", Tileset{{"tiles"}}); + initialized.loadDescription(*test.fileSource); + + FakeTileSource renderTilesetSource{initialized.baseImpl}; + RenderSource* renderSource = &renderTilesetSource; + LineLayer layer("id", "source"); + Immutable<LayerProperties> layerProperties = + makeMutable<LineLayerProperties>(staticImmutableCast<LineLayer::Impl>(layer.baseImpl)); + std::vector<Immutable<LayerProperties>> layers{layerProperties}; + + Duration minimumTileUpdateInterval = initialized.getMinimumTileUpdateInterval(); + auto baseImpl = initialized.baseImpl; + EXPECT_EQ(Duration::zero(), minimumTileUpdateInterval); + EXPECT_CALL(renderTilesetSource, tileSetMinimumUpdateInterval(minimumTileUpdateInterval)).Times(1); + renderSource->update(baseImpl, layers, true, false, test.tileParameters()); + + initialized.setMinimumTileUpdateInterval(Seconds(1)); + EXPECT_NE(baseImpl, initialized.baseImpl) << "Source impl was updated"; + baseImpl = initialized.baseImpl; + + initialized.setMinimumTileUpdateInterval(Seconds(1)); // Set the same interval again. + EXPECT_EQ(baseImpl, initialized.baseImpl) << "Source impl was not updated"; + + minimumTileUpdateInterval = initialized.getMinimumTileUpdateInterval(); + EXPECT_EQ(Seconds(1), minimumTileUpdateInterval); + EXPECT_CALL(renderTilesetSource, tileSetMinimumUpdateInterval(minimumTileUpdateInterval)).Times(1); + renderSource->update(baseImpl, layers, true, false, test.tileParameters()); + + initialized.setMinimumTileUpdateInterval(Seconds(2)); + minimumTileUpdateInterval = initialized.getMinimumTileUpdateInterval(); + EXPECT_EQ(Seconds(2), minimumTileUpdateInterval); + + // No network activity for invisible tiles, and no reason to set the update interval. + EXPECT_CALL(renderTilesetSource, tileSetMinimumUpdateInterval(minimumTileUpdateInterval)).Times(0); + renderSource->update(initialized.baseImpl, layers, false, false, test.tileParameters()); + + // Tiles got visible, set the update interval now. + EXPECT_CALL(renderTilesetSource, tileSetMinimumUpdateInterval(minimumTileUpdateInterval)).Times(1); + renderSource->update(initialized.baseImpl, layers, true, false, test.tileParameters()); +} + TEST(Source, RenderTileSetSourceUpdate) { SourceTest test; |