diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-02-27 17:27:36 +0200 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2018-03-30 01:45:52 -0400 |
commit | c6b8d9dbb47f10b3ab7501b8b5881f1caeb23294 (patch) | |
tree | fcd2cfe285f798e7fe501f84a766ee60982b57a0 /test | |
parent | 23ccfce1765588511ce5055e20994894c6b2251e (diff) | |
download | qtlocation-mapboxgl-c6b8d9dbb47f10b3ab7501b8b5881f1caeb23294.tar.gz |
[test] Update Map.PrefetchTilesupstream/fb-11334-boba-cherry-pick
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/map/prefetch/expected.png | bin | 2198 -> 0 bytes | |||
-rw-r--r-- | test/fixtures/map/prefetch/tile.png (renamed from test/fixtures/map/prefetch/tile_green.png) | bin | 659 -> 659 bytes | |||
-rw-r--r-- | test/fixtures/map/prefetch/tile_red.png | bin | 659 -> 0 bytes | |||
-rw-r--r-- | test/map/map.test.cpp | 46 | ||||
-rw-r--r-- | test/map/prefetch.test.cpp | 40 | ||||
-rw-r--r-- | test/src/mbgl/test/stub_map_observer.hpp | 49 |
6 files changed, 74 insertions, 61 deletions
diff --git a/test/fixtures/map/prefetch/expected.png b/test/fixtures/map/prefetch/expected.png Binary files differdeleted file mode 100644 index e1111b37f7..0000000000 --- a/test/fixtures/map/prefetch/expected.png +++ /dev/null diff --git a/test/fixtures/map/prefetch/tile_green.png b/test/fixtures/map/prefetch/tile.png Binary files differindex 553cd10cd1..553cd10cd1 100644 --- a/test/fixtures/map/prefetch/tile_green.png +++ b/test/fixtures/map/prefetch/tile.png diff --git a/test/fixtures/map/prefetch/tile_red.png b/test/fixtures/map/prefetch/tile_red.png Binary files differdeleted file mode 100644 index 5fa561fb92..0000000000 --- a/test/fixtures/map/prefetch/tile_red.png +++ /dev/null diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 30c076ad89..f95e26fd82 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -1,5 +1,6 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_file_source.hpp> +#include <mbgl/test/stub_map_observer.hpp> #include <mbgl/test/fake_file_source.hpp> #include <mbgl/test/fixture_log_observer.hpp> @@ -23,45 +24,6 @@ using namespace mbgl; using namespace mbgl::style; using namespace std::literals::string_literals; -class StubMapObserver : public MapObserver { -public: - void onWillStartLoadingMap() final { - if (onWillStartLoadingMapCallback) { - onWillStartLoadingMapCallback(); - } - } - - void onDidFinishLoadingMap() final { - if (onDidFinishLoadingMapCallback) { - onDidFinishLoadingMapCallback(); - } - } - - void onDidFailLoadingMap(std::exception_ptr) final { - if (didFailLoadingMapCallback) { - didFailLoadingMapCallback(); - } - } - - void onDidFinishLoadingStyle() final { - if (didFinishLoadingStyleCallback) { - didFinishLoadingStyleCallback(); - } - } - - void onDidFinishRenderingFrame(RenderMode mode) final { - if (didFinishRenderingFrame) { - didFinishRenderingFrame(mode); - } - } - - std::function<void()> onWillStartLoadingMapCallback; - std::function<void()> onDidFinishLoadingMapCallback; - std::function<void()> didFailLoadingMapCallback; - std::function<void()> didFinishLoadingStyleCallback; - std::function<void(RenderMode)> didFinishRenderingFrame; -}; - template <class FileSource = StubFileSource> class MapTest { public: @@ -371,7 +333,7 @@ TEST(Map, MapLoadingSignal) { MapTest<> test; bool emitted = false; - test.observer.onWillStartLoadingMapCallback = [&]() { + test.observer.willStartLoadingMapCallback = [&]() { emitted = true; }; test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); @@ -381,7 +343,7 @@ TEST(Map, MapLoadingSignal) { TEST(Map, MapLoadedSignal) { MapTest<> test { 1, MapMode::Continuous }; - test.observer.onDidFinishLoadingMapCallback = [&]() { + test.observer.didFinishLoadingMapCallback = [&]() { test.runLoop.stop(); }; @@ -607,7 +569,7 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { HeadlessFrontend frontend(pixelRatio, fileSource, threadPool); StubMapObserver observer; - observer.didFinishRenderingFrame = [&] (MapObserver::RenderMode) { + observer.didFinishRenderingFrameCallback = [&] (MapObserver::RenderMode) { // Start a timer that ends the test one second from now. If we are continuing to render // indefinitely, the timer will be constantly restarted and never trigger. Instead, the // emergency shutoff above will trigger, failing the test. diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp index 4c82b2c965..9b61224027 100644 --- a/test/map/prefetch.test.cpp +++ b/test/map/prefetch.test.cpp @@ -1,5 +1,6 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_file_source.hpp> +#include <mbgl/test/stub_map_observer.hpp> #include <mbgl/map/map.hpp> #include <mbgl/gl/headless_frontend.hpp> @@ -17,34 +18,38 @@ using namespace mbgl; using namespace mbgl::style; using namespace std::literals::string_literals; +using namespace std::chrono_literals; TEST(Map, PrefetchTiles) { util::RunLoop runLoop; ThreadPool threadPool(4); StubFileSource fileSource; + + util::Timer emergencyShutoff; + emergencyShutoff.start(10s, 0s, [&] { + runLoop.stop(); + FAIL() << "Did not stop rendering"; + }); + + StubMapObserver observer; + observer.didFinishLoadingMapCallback = [&] () { + runLoop.stop(); + }; + HeadlessFrontend frontend { { 512, 512 }, 1, fileSource, threadPool }; - Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), 1, fileSource, threadPool, MapMode::Static); + Map map(frontend, observer, frontend.getSize(), 1, fileSource, threadPool, MapMode::Continuous); std::vector<int> tiles; fileSource.response = [&] (const Resource& res) -> optional<Response> { - Response response; + static std::string tile = util::read_file("test/fixtures/map/prefetch/tile.png"); auto zoom = std::stoi(res.url); tiles.push_back(zoom); - // Return a red tile for prefetched tiles or green to the actual tile. - // The end rendering result should be all green because the map is only - // considered fully rendered when only ideal tiles are shown. - if (zoom == int(map.getZoom()) + 1) { - response.data = std::make_shared<std::string>( - util::read_file("test/fixtures/map/prefetch/tile_green.png")); - } else { - response.data = std::make_shared<std::string>( - util::read_file("test/fixtures/map/prefetch/tile_red.png")); - } - - return { std::move(response) }; + Response response; + response.data = std::make_shared<std::string>(tile); + return response; }; auto checkTilesForZoom = [&](int zoom, const std::vector<int>& expected) { @@ -53,14 +58,11 @@ TEST(Map, PrefetchTiles) { // Force tile reloading. map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/empty.json")); map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/style.json")); - map.setLatLngZoom({ 40.726989, -73.992857 }, zoom); // Manhattan + runLoop.run(); - // Should always render the ideal tiles (i.e. a green map) - test::checkImage("test/fixtures/map/prefetch", frontend.render(map)); - + ASSERT_EQ(tiles.size(), expected.size()); ASSERT_TRUE(std::is_permutation(tiles.begin(), tiles.end(), expected.begin())); - ASSERT_FALSE(tiles.empty()); }; // Check defaults, should be 4. diff --git a/test/src/mbgl/test/stub_map_observer.hpp b/test/src/mbgl/test/stub_map_observer.hpp new file mode 100644 index 0000000000..1371577473 --- /dev/null +++ b/test/src/mbgl/test/stub_map_observer.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include <mbgl/map/map_observer.hpp> + +#include <functional> + +namespace mbgl { + +class StubMapObserver : public MapObserver { +public: + void onWillStartLoadingMap() final { + if (willStartLoadingMapCallback) { + willStartLoadingMapCallback(); + } + } + + void onDidFinishLoadingMap() final { + if (didFinishLoadingMapCallback) { + didFinishLoadingMapCallback(); + } + } + + void onDidFailLoadingMap(std::exception_ptr) final { + if (didFailLoadingMapCallback) { + didFailLoadingMapCallback(); + } + } + + void onDidFinishLoadingStyle() final { + if (didFinishLoadingStyleCallback) { + didFinishLoadingStyleCallback(); + } + } + + void onDidFinishRenderingFrame(RenderMode mode) final { + if (didFinishRenderingFrameCallback) { + didFinishRenderingFrameCallback(mode); + } + } + + std::function<void()> willStartLoadingMapCallback; + std::function<void()> didFinishLoadingMapCallback; + std::function<void()> didFailLoadingMapCallback; + std::function<void()> didFinishLoadingStyleCallback; + std::function<void(RenderMode)> didFinishRenderingFrameCallback; +}; + + +} // namespace mbgl |