diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-09-28 11:45:33 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-09-28 16:34:22 +0200 |
commit | 3f3fc7b7723698e44427e2a14a2f4906832800bf (patch) | |
tree | 5acadfa4d77817c41f612c89c93925a149cbcfc0 /test/api/repeated_render.test.cpp | |
parent | a8b007daa0e85ea4b1a4898fd591d55d0117cc85 (diff) | |
download | qtlocation-mapboxgl-3f3fc7b7723698e44427e2a14a2f4906832800bf.tar.gz |
[test] add .test.cpp suffix to test case files
Diffstat (limited to 'test/api/repeated_render.test.cpp')
-rw-r--r-- | test/api/repeated_render.test.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp new file mode 100644 index 0000000000..cf71cb8416 --- /dev/null +++ b/test/api/repeated_render.test.cpp @@ -0,0 +1,74 @@ +#include <mbgl/test/util.hpp> +#include <mbgl/test/fixture_log_observer.hpp> + +#include <mbgl/map/map.hpp> +#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/platform/default/headless_display.hpp> +#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>(); + HeadlessView view(display, 1, 256, 512); +#ifdef MBGL_ASSET_ZIP + // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); +#else + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); +#endif + + Log::setObserver(std::make_unique<FixtureLogObserver>()); + + Map map(view, fileSource, MapMode::Still); + + { + map.setStyleJSON(style); + PremultipliedImage result; + map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { + result = std::move(image); + }); + + while (!result.size()) { + loop.runOnce(); + } + + ASSERT_EQ(256u, result.width); + ASSERT_EQ(512u, result.height); +#if !TEST_READ_ONLY + util::write_file("test/fixtures/api/1.png", encodePNG(result)); +#endif + } + + { + map.setStyleJSON(style); + PremultipliedImage result; + map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { + result = std::move(image); + }); + + while (!result.size()) { + loop.runOnce(); + } + + ASSERT_EQ(256u, result.width); + ASSERT_EQ(512u, result.height); +#if !TEST_READ_ONLY + util::write_file("test/fixtures/api/2.png", encodePNG(result)); +#endif + } + + auto observer = Log::removeObserver(); + auto flo = dynamic_cast<FixtureLogObserver*>(observer.get()); + auto unchecked = flo->unchecked(); + EXPECT_TRUE(unchecked.empty()) << unchecked; +} |