diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-09-01 15:07:17 +0300 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-14 13:44:08 -0700 |
commit | 204c7fee032bf8509747046b43a788366a189ae7 (patch) | |
tree | 8719b7ab8838bea52babd8bf42f2234ddc43dc9a /test/api | |
parent | 18d8e80f52345a13236ae1da99b5866e7643f85b (diff) | |
download | qtlocation-mapboxgl-204c7fee032bf8509747046b43a788366a189ae7.tar.gz |
[core] Render from the main thread
Do not create a thread for the MapContext anymore.
Diffstat (limited to 'test/api')
-rw-r--r-- | test/api/annotations.cpp | 25 | ||||
-rw-r--r-- | test/api/api_misuse.cpp | 16 | ||||
-rw-r--r-- | test/api/custom_layer.cpp | 3 | ||||
-rw-r--r-- | test/api/render_missing.cpp | 11 | ||||
-rw-r--r-- | test/api/repeated_render.cpp | 27 | ||||
-rw-r--r-- | test/api/set_style.cpp | 3 |
6 files changed, 69 insertions, 16 deletions
diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp index 0af64095c1..f403512660 100644 --- a/test/api/annotations.cpp +++ b/test/api/annotations.cpp @@ -8,6 +8,7 @@ #include <mbgl/platform/default/headless_view.hpp> #include <mbgl/storage/online_file_source.hpp> #include <mbgl/util/io.hpp> +#include <mbgl/util/run_loop.hpp> #include <future> #include <vector> @@ -29,6 +30,8 @@ void checkRendering(Map& map, const char * name) { } // end namespace TEST(Annotations, PointAnnotation) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -42,6 +45,8 @@ TEST(Annotations, PointAnnotation) { } TEST(Annotations, LineAnnotation) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -61,6 +66,8 @@ TEST(Annotations, LineAnnotation) { } TEST(Annotations, FillAnnotation) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -79,6 +86,8 @@ TEST(Annotations, FillAnnotation) { } TEST(Annotations, StyleSourcedShapeAnnotation) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -94,6 +103,8 @@ TEST(Annotations, StyleSourcedShapeAnnotation) { } TEST(Annotations, AddMultiple) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -111,6 +122,8 @@ TEST(Annotations, AddMultiple) { } TEST(Annotations, NonImmediateAdd) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -131,6 +144,8 @@ TEST(Annotations, NonImmediateAdd) { } TEST(Annotations, UpdateIcon) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -150,6 +165,8 @@ TEST(Annotations, UpdateIcon) { } TEST(Annotations, UpdatePoint) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -168,6 +185,8 @@ TEST(Annotations, UpdatePoint) { } TEST(Annotations, RemovePoint) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -185,6 +204,8 @@ TEST(Annotations, RemovePoint) { } TEST(Annotations, RemoveShape) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -207,6 +228,8 @@ TEST(Annotations, RemoveShape) { } TEST(Annotations, ImmediateRemoveShape) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; @@ -219,6 +242,8 @@ TEST(Annotations, ImmediateRemoveShape) { } TEST(Annotations, SwitchStyle) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; diff --git a/test/api/api_misuse.cpp b/test/api/api_misuse.cpp index 932c4717e8..5e413df369 100644 --- a/test/api/api_misuse.cpp +++ b/test/api/api_misuse.cpp @@ -6,6 +6,7 @@ #include <mbgl/platform/default/headless_view.hpp> #include <mbgl/storage/online_file_source.hpp> #include <mbgl/util/exception.hpp> +#include <mbgl/util/run_loop.hpp> #include <future> @@ -15,6 +16,8 @@ TEST(API, RenderWithoutCallback) { FixtureLogObserver* log = new FixtureLogObserver(); Log::setObserver(std::unique_ptr<Log::Observer>(log)); + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); view.resize(128, 512); @@ -37,6 +40,8 @@ TEST(API, RenderWithoutCallback) { } TEST(API, RenderWithoutStyle) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); view.resize(128, 512); @@ -44,13 +49,16 @@ TEST(API, RenderWithoutStyle) { Map map(view, fileSource, MapMode::Still); - std::promise<std::exception_ptr> promise; - map.renderStill([&promise](std::exception_ptr error, PremultipliedImage&&) { - promise.set_value(error); + std::exception_ptr error; + map.renderStill([&](std::exception_ptr error_, PremultipliedImage&&) { + error = error_; + loop.stop(); }); + loop.run(); + try { - std::rethrow_exception(promise.get_future().get()); + std::rethrow_exception(error); } catch (const util::MisuseException& ex) { EXPECT_EQ(std::string(ex.what()), "Map doesn't have a style"); } catch (const std::exception&) { diff --git a/test/api/custom_layer.cpp b/test/api/custom_layer.cpp index 5346fee124..46eecb2250 100644 --- a/test/api/custom_layer.cpp +++ b/test/api/custom_layer.cpp @@ -7,6 +7,7 @@ #include <mbgl/layer/custom_layer.hpp> #include <mbgl/util/io.hpp> #include <mbgl/util/mat4.hpp> +#include <mbgl/util/run_loop.hpp> using namespace mbgl; @@ -68,6 +69,8 @@ public: }; TEST(CustomLayer, Basic) { + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; diff --git a/test/api/render_missing.cpp b/test/api/render_missing.cpp index f29a0c2b9c..bb14416840 100644 --- a/test/api/render_missing.cpp +++ b/test/api/render_missing.cpp @@ -7,6 +7,7 @@ #include <mbgl/storage/default_file_source.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> +#include <mbgl/util/run_loop.hpp> #include <future> @@ -19,6 +20,8 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { using namespace mbgl; + util::RunLoop loop; + const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json"); auto display = std::make_shared<mbgl::HeadlessDisplay>(); @@ -38,8 +41,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { // This host does not respond (== connection error). map.setStyleJSON(style, ""); - std::promise<void> promise; - map.renderStill([&promise, &message](std::exception_ptr err, PremultipliedImage&&) { + map.renderStill([&](std::exception_ptr err, PremultipliedImage&&) { ASSERT_TRUE(err.operator bool()); try { std::rethrow_exception(err); @@ -47,9 +49,10 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) { message = ex.what(); EXPECT_TRUE(message.find("connect") != std::string::npos); } - promise.set_value(); + loop.stop(); }); - promise.get_future().get(); + + loop.run(); auto observer = Log::removeObserver(); auto flo = dynamic_cast<FixtureLogObserver*>(observer.get()); diff --git a/test/api/repeated_render.cpp b/test/api/repeated_render.cpp index ef707aa7c4..cf5d115997 100644 --- a/test/api/repeated_render.cpp +++ b/test/api/repeated_render.cpp @@ -7,12 +7,15 @@ #include <mbgl/storage/default_file_source.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> +#include <mbgl/util/run_loop.hpp> #include <future> TEST(API, RepeatedRender) { using namespace mbgl; + util::RunLoop loop; + const auto style = util::read_file("test/fixtures/api/water.json"); auto display = std::make_shared<mbgl::HeadlessDisplay>(); @@ -30,11 +33,15 @@ TEST(API, RepeatedRender) { { map.setStyleJSON(style, ""); - std::promise<PremultipliedImage> promise; - map.renderStill([&promise](std::exception_ptr, PremultipliedImage&& image) { - promise.set_value(std::move(image)); + PremultipliedImage result; + map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { + result = std::move(image); }); - auto result = promise.get_future().get(); + + while (!result.size()) { + loop.runOnce(); + } + ASSERT_EQ(256, result.width); ASSERT_EQ(512, result.height); #if !TEST_READ_ONLY @@ -44,11 +51,15 @@ TEST(API, RepeatedRender) { { map.setStyleJSON(style, ""); - std::promise<PremultipliedImage> promise; - map.renderStill([&promise](std::exception_ptr, PremultipliedImage&& image) { - promise.set_value(std::move(image)); + PremultipliedImage result; + map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { + result = std::move(image); }); - auto result = promise.get_future().get(); + + while (!result.size()) { + loop.runOnce(); + } + ASSERT_EQ(256, result.width); ASSERT_EQ(512, result.height); #if !TEST_READ_ONLY diff --git a/test/api/set_style.cpp b/test/api/set_style.cpp index 329ec2801d..317021b8db 100644 --- a/test/api/set_style.cpp +++ b/test/api/set_style.cpp @@ -5,11 +5,14 @@ #include <mbgl/platform/default/headless_view.hpp> #include <mbgl/platform/default/headless_display.hpp> #include <mbgl/storage/online_file_source.hpp> +#include <mbgl/util/run_loop.hpp> TEST(API, SetStyle) { using namespace mbgl; + util::RunLoop loop; + auto display = std::make_shared<mbgl::HeadlessDisplay>(); HeadlessView view(display, 1); OnlineFileSource fileSource; |