summaryrefslogtreecommitdiff
path: root/test/headless
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-04-20 16:29:18 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-04-20 17:01:27 -0700
commit75af3db17dcc8647a3705fb8dee5a23279b2c0b9 (patch)
tree5a6ff50ac4c5a1c33ca296e6bd29c2887c29dc49 /test/headless
parent1efb3869afdda83733c12d17a1ef25915516ee60 (diff)
downloadqtlocation-mapboxgl-75af3db17dcc8647a3705fb8dee5a23279b2c0b9.tar.gz
Use a promise rather than async dance
Diffstat (limited to 'test/headless')
-rw-r--r--test/headless/headless.cpp33
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();
}