diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp index 2c6bfdb67..1b088b52c 100644 --- a/test/api/annotations.cpp +++ b/test/api/annotations.cpp @@ -19,11 +19,15 @@ std::shared_ptr namedMarker(const std::string &name) { return std::make_shared(image.width, image.height, 1.0, std::string(reinterpret_cast(image.data.get()), image.size())); } +namespace { + void checkRendering(Map& map, const char * name) { test::checkImage(std::string("test/fixtures/annotations/") + name + "/", test::render(map), 0.0002, 0.1); } +} // end namespace + TEST(Annotations, PointAnnotation) { auto display = std::make_shared(); HeadlessView view(display, 1); diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp index 1a6733e68..5eeb428ec 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 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 71f7c2a4b..e2cadc50d 100644 --- a/test/fixtures/util.hpp +++ b/test/fixtures/util.hpp @@ -3,6 +3,7 @@ #include +#include #include #include @@ -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); - } }