diff options
Diffstat (limited to 'test/headless/headless.cpp')
-rw-r--r-- | test/headless/headless.cpp | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp index cccd0d44bd..aac5dda833 100644 --- a/test/headless/headless.cpp +++ b/test/headless/headless.cpp @@ -16,10 +16,10 @@ #include <mbgl/platform/default/headless_display.hpp> #include <mbgl/storage/default_file_source.hpp> -#include <uv.h> - #include <dirent.h> +#include <future> + void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) { ASSERT_TRUE(value.IsString()); auto string = std::string { value.GetString(),value.GetStringLength() }; @@ -154,32 +154,15 @@ TEST_P(HeadlessTest, render) { map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); map.setBearing(bearing); - struct Data { - std::string path; - std::unique_ptr<const StillImage> image; - }; - - uv_async_t *async = new uv_async_t; - async->data = new Data { "test/suite/tests/" + base + "/" + name + "/actual.png", nullptr }; - uv_async_init(uv_default_loop(), async, [](uv_async_t *as, int) { - auto data = std::unique_ptr<Data>(reinterpret_cast<Data *>(as->data)); - as->data = nullptr; - uv_close(reinterpret_cast<uv_handle_t *>(as), [](uv_handle_t *handle) { - delete reinterpret_cast<uv_async_t *>(handle); - }); - - assert(data); - const std::string png = util::compress_png(data->image->width, data->image->height, data->image->pixels.get()); - util::write_file(data->path, png); - }); + std::promise<void> promise; - map.renderStill([async](std::unique_ptr<const StillImage> image) { - reinterpret_cast<Data *>(async->data)->image = std::move(image); - uv_async_send(async); + map.renderStill([&](std::unique_ptr<const StillImage> image) { + const std::string png = util::compress_png(image->width, image->height, image->pixels.get()); + util::write_file("test/suite/tests/" + base + "/" + name + "/actual.png", png); + promise.set_value(); }); - // This loop will terminate once the async was fired. - uv_run(uv_default_loop(), UV_RUN_DEFAULT); + promise.get_future().get(); map.stop(); } |