diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-10 12:36:53 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-17 01:01:15 +0100 |
commit | 50f0f919c38a905b8b169fcbd3e77c03bf48d17b (patch) | |
tree | e5b798dcca7afabf89f80c9c4810861c22db13e5 /test | |
parent | 5479b75c9fa971332aadfede6b380267eebbd566 (diff) | |
download | qtlocation-mapboxgl-50f0f919c38a905b8b169fcbd3e77c03bf48d17b.tar.gz |
[test] Use shared headless display
Prevents some OpenGL implementations from bailing out.
Diffstat (limited to 'test')
-rw-r--r-- | test/api/annotations.test.cpp | 4 | ||||
-rw-r--r-- | test/api/api_misuse.test.cpp | 9 | ||||
-rw-r--r-- | test/api/custom_layer.test.cpp | 4 | ||||
-rw-r--r-- | test/api/query.test.cpp | 2 | ||||
-rw-r--r-- | test/api/render_missing.test.cpp | 4 | ||||
-rw-r--r-- | test/api/repeated_render.test.cpp | 8 | ||||
-rw-r--r-- | test/gl/object.test.cpp | 2 | ||||
-rw-r--r-- | test/map/map.test.cpp | 8 | ||||
-rw-r--r-- | test/src/mbgl/test/util.cpp | 6 | ||||
-rw-r--r-- | test/src/mbgl/test/util.hpp | 4 | ||||
-rw-r--r-- | test/util/memory.test.cpp | 2 | ||||
-rw-r--r-- | test/util/offscreen_texture.test.cpp | 4 |
12 files changed, 37 insertions, 20 deletions
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index b143bd961c..ef70ee188c 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -23,8 +23,8 @@ std::shared_ptr<SpriteImage> namedMarker(const std::string &name) { class AnnotationTest { public: util::RunLoop loop; - HeadlessBackend backend; - OffscreenView view{ backend.getContext() }; + HeadlessBackend backend { test::sharedDisplay() }; + OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; Map map { backend, view.size, 1, fileSource, threadPool, MapMode::Still }; diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp index 50a8f38c33..f96bf78612 100644 --- a/test/api/api_misuse.test.cpp +++ b/test/api/api_misuse.test.cpp @@ -14,14 +14,15 @@ using namespace mbgl; + TEST(API, RenderWithoutCallback) { auto log = new FixtureLogObserver(); Log::setObserver(std::unique_ptr<Log::Observer>(log)); util::RunLoop loop; - HeadlessBackend backend; - OffscreenView view(backend.getContext(), { 128, 512 }); + HeadlessBackend backend { test::sharedDisplay() }; + OffscreenView view { backend.getContext(), { 128, 512 } }; StubFileSource fileSource; ThreadPool threadPool(4); @@ -45,8 +46,8 @@ TEST(API, RenderWithoutCallback) { TEST(API, RenderWithoutStyle) { util::RunLoop loop; - HeadlessBackend backend; - OffscreenView view(backend.getContext(), { 128, 512 }); + HeadlessBackend backend { test::sharedDisplay() }; + OffscreenView view { backend.getContext(), { 128, 512 } }; StubFileSource fileSource; ThreadPool threadPool(4); diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index 9d4ba04cee..9287f02189 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -85,8 +85,8 @@ public: TEST(CustomLayer, Basic) { util::RunLoop loop; - HeadlessBackend backend; - OffscreenView view(backend.getContext()); + HeadlessBackend backend { test::sharedDisplay() }; + OffscreenView view { backend.getContext() }; #ifdef MBGL_ASSET_ZIP // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp index d3c233ad34..506464ea1a 100644 --- a/test/api/query.test.cpp +++ b/test/api/query.test.cpp @@ -26,7 +26,7 @@ public: } util::RunLoop loop; - HeadlessBackend backend; + HeadlessBackend backend { test::sharedDisplay() }; OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; diff --git a/test/api/render_missing.test.cpp b/test/api/render_missing.test.cpp index b24d59ab21..8f7821205b 100644 --- a/test/api/render_missing.test.cpp +++ b/test/api/render_missing.test.cpp @@ -25,8 +25,8 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json"); - HeadlessBackend backend; - OffscreenView view(backend.getContext(), { 256, 512 }); + HeadlessBackend backend { test::sharedDisplay() }; + OffscreenView view { backend.getContext(), { 256, 512 } }; #ifdef MBGL_ASSET_ZIP // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp index 1bea05b1fb..67670916fc 100644 --- a/test/api/repeated_render.test.cpp +++ b/test/api/repeated_render.test.cpp @@ -12,15 +12,17 @@ #include <future> +using namespace mbgl; + + TEST(API, RepeatedRender) { - using namespace mbgl; util::RunLoop loop; const auto style = util::read_file("test/fixtures/api/water.json"); - HeadlessBackend backend; - OffscreenView view(backend.getContext(), { 256, 512 }); + HeadlessBackend backend { test::sharedDisplay() }; + OffscreenView view { backend.getContext(), { 256, 512 } }; #ifdef MBGL_ASSET_ZIP // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); diff --git a/test/gl/object.test.cpp b/test/gl/object.test.cpp index fb143c55c8..6e1e068c28 100644 --- a/test/gl/object.test.cpp +++ b/test/gl/object.test.cpp @@ -60,7 +60,7 @@ TEST(GLObject, Value) { } TEST(GLObject, Store) { - HeadlessBackend backend; + HeadlessBackend backend { test::sharedDisplay() }; OffscreenView view(backend.getContext()); gl::Context context; diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 741aa869f3..682060324e 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -23,7 +23,7 @@ using namespace std::literals::string_literals; struct MapTest { util::RunLoop runLoop; - HeadlessBackend backend; + HeadlessBackend backend { test::sharedDisplay() }; OffscreenView view { backend.getContext() }; StubFileSource fileSource; ThreadPool threadPool { 4 }; @@ -447,6 +447,10 @@ TEST(Map, DontLoadUnneededTiles) { class MockBackend : public HeadlessBackend { public: + MockBackend(std::shared_ptr<HeadlessDisplay> display_) + : HeadlessBackend(display_) { + } + std::function<void()> callback; void invalidate() override { if (callback) { @@ -457,7 +461,7 @@ public: TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) { util::RunLoop runLoop; - MockBackend backend; + MockBackend backend { test::sharedDisplay() }; OffscreenView view { backend.getContext() }; ThreadPool threadPool { 4 }; diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp index 2a82e0059f..a3b6117d02 100644 --- a/test/src/mbgl/test/util.cpp +++ b/test/src/mbgl/test/util.cpp @@ -2,6 +2,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/platform/default/offscreen_view.hpp> +#include <mbgl/platform/default/headless_display.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> @@ -98,6 +99,11 @@ Server::~Server() { } } +std::shared_ptr<HeadlessDisplay> sharedDisplay() { + static auto display = std::make_shared<HeadlessDisplay>(); + return display; +} + PremultipliedImage render(Map& map, OffscreenView& view) { PremultipliedImage result; map.renderStill(view, [&](std::exception_ptr) { diff --git a/test/src/mbgl/test/util.hpp b/test/src/mbgl/test/util.hpp index b8ecf175aa..8445822699 100644 --- a/test/src/mbgl/test/util.hpp +++ b/test/src/mbgl/test/util.hpp @@ -46,6 +46,7 @@ #include <mbgl/util/chrono.hpp> #include <cstdint> +#include <memory> #include <gtest/gtest.h> @@ -53,6 +54,7 @@ namespace mbgl { class Map; class OffscreenView; +class HeadlessDisplay; namespace test { @@ -65,6 +67,8 @@ private: int fd = -1; }; +std::shared_ptr<HeadlessDisplay> sharedDisplay(); + PremultipliedImage render(Map&, OffscreenView&); void checkImage(const std::string& base, diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index 07927b43eb..bd67e2c26b 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -56,7 +56,7 @@ public: } util::RunLoop runLoop; - HeadlessBackend backend; + HeadlessBackend backend { test::sharedDisplay() }; OffscreenView view{ backend.getContext(), { 512, 512 } }; StubFileSource fileSource; ThreadPool threadPool { 4 }; diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index 683a4e6095..9a07f4f3bf 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -10,7 +10,7 @@ using namespace mbgl; TEST(OffscreenTexture, EmptyRed) { - HeadlessBackend backend; + HeadlessBackend backend { test::sharedDisplay() }; OffscreenView view(backend.getContext(), { 512, 256 }); view.bind(); @@ -67,7 +67,7 @@ struct Buffer { TEST(OffscreenTexture, RenderToTexture) { - HeadlessBackend backend; + HeadlessBackend backend { test::sharedDisplay() }; auto& context = backend.getContext(); MBGL_CHECK_ERROR(glEnable(GL_BLEND)); |