summaryrefslogtreecommitdiff
path: root/test/fixtures
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-01-04 12:29:38 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-01-08 13:23:01 +0100
commit7e815aed2e6adb73b3596b450bb85e93ce569e2a (patch)
tree0cc3e0e02c61bbc934e00bc642991011cc99ec1d /test/fixtures
parent4479f5db6c1ce26bc187a1b5a938f4bdb45915d4 (diff)
downloadqtlocation-mapboxgl-7e815aed2e6adb73b3596b450bb85e93ce569e2a.tar.gz
[test] allow aborting rendering after a timeout
Diffstat (limited to 'test/fixtures')
-rw-r--r--test/fixtures/util.cpp12
-rw-r--r--test/fixtures/util.hpp5
2 files changed, 13 insertions, 4 deletions
diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp
index 1a6733e685..5eeb428ec7 100644
--- a/test/fixtures/util.cpp
+++ b/test/fixtures/util.cpp
@@ -108,12 +108,20 @@ uint64_t crc64(const std::string& str) {
return crc64(str.data(), str.size());
}
-PremultipliedImage render(Map& map) {
+PremultipliedImage render(Map& map, std::chrono::milliseconds timeout) {
std::promise<PremultipliedImage> promise;
map.renderStill([&](std::exception_ptr, PremultipliedImage&& image) {
promise.set_value(std::move(image));
});
- return promise.get_future().get();
+
+ // Limit maximum wait time.
+ auto future = promise.get_future();
+ if (future.wait_for(timeout) != std::future_status::ready) {
+ // Alas, we didn't get the promised future :(
+ Log::Error(Event::Image, "Failed to generate image within %dms", timeout.count());
+ return { 0, 0 };
+ }
+ return future.get();
}
void checkImage(const std::string& base,
diff --git a/test/fixtures/util.hpp b/test/fixtures/util.hpp
index 71f7c2a4b3..e2cadc50dd 100644
--- a/test/fixtures/util.hpp
+++ b/test/fixtures/util.hpp
@@ -3,6 +3,7 @@
#include <mbgl/util/image.hpp>
+#include <chrono>
#include <cstdint>
#include <gtest/gtest.h>
@@ -35,13 +36,13 @@ private:
uint64_t crc64(const char*, size_t);
uint64_t crc64(const std::string&);
-PremultipliedImage render(Map&);
+PremultipliedImage render(Map&,
+ std::chrono::milliseconds timeout = std::chrono::milliseconds(1000));
void checkImage(const std::string& base,
const PremultipliedImage& actual,
double imageThreshold = 0,
double pixelThreshold = 0);
-
}
}