diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-04-17 15:43:20 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-04-17 15:43:20 +0200 |
commit | 7827d4954cea5b4fcfce3f245aae2e8c66e0ccb2 (patch) | |
tree | 4db146c25b77fb118e732118ca021859752cc076 /test/api | |
parent | cd496645d435a192af3060f06fbe9f2baca76d1a (diff) | |
parent | 9072df709d30ed0ed2c913482e1e6bae6a3d5dd5 (diff) | |
download | qtlocation-mapboxgl-7827d4954cea5b4fcfce3f245aae2e8c66e0ccb2.tar.gz |
Merge pull request #1272 from mapbox/1272-render-still-images-on-thread
Render still/static images on a separate thread as well, aligning it with the way continuous render mode works
Diffstat (limited to 'test/api')
-rw-r--r-- | test/api/repeated_render.cpp | 63 | ||||
-rw-r--r-- | test/api/set_style.cpp | 33 |
2 files changed, 96 insertions, 0 deletions
diff --git a/test/api/repeated_render.cpp b/test/api/repeated_render.cpp new file mode 100644 index 0000000000..16688ec36f --- /dev/null +++ b/test/api/repeated_render.cpp @@ -0,0 +1,63 @@ +#include "../fixtures/util.hpp" +#include "../fixtures/fixture_log_observer.hpp" + +#include <mbgl/map/map.hpp> +#include <mbgl/map/still_image.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 <future> + +TEST(API, RepeatedRender) { + using namespace mbgl; + + const auto style = util::read_file("test/fixtures/api/water.json"); + + auto display = std::make_shared<mbgl::HeadlessDisplay>(); + HeadlessView view(display); + DefaultFileSource fileSource(nullptr); + + Log::setObserver(util::make_unique<FixtureLogObserver>()); + + Map map(view, fileSource); + + map.start(Map::Mode::Static); + + { + view.resize(128, 512, 1); + map.setStyleJSON(style, "test/suite"); + std::promise<std::unique_ptr<const StillImage>> promise; + map.renderStill([&promise](std::unique_ptr<const StillImage> image) { + promise.set_value(std::move(image)); + }); + auto result = promise.get_future().get(); + ASSERT_EQ(128, result->width); + ASSERT_EQ(512, result->height); + const std::string png = util::compress_png(result->width, result->height, result->pixels.get()); + util::write_file("test/fixtures/api/1.png", png); + } + + { + view.resize(512, 512, 2); + map.setStyleJSON(style, "TEST_DATA/suite"); + std::promise<std::unique_ptr<const StillImage>> promise; + map.renderStill([&promise](std::unique_ptr<const StillImage> image) { + promise.set_value(std::move(image)); + }); + auto result = promise.get_future().get(); + ASSERT_EQ(1024, result->width); + ASSERT_EQ(1024, result->height); + const std::string png = util::compress_png(result->width, result->height, result->pixels.get()); + util::write_file("test/fixtures/api/2.png", png); + } + + map.stop(); + + auto observer = Log::removeObserver(); + auto flo = dynamic_cast<FixtureLogObserver*>(observer.get()); + auto unchecked = flo->unchecked(); + EXPECT_TRUE(unchecked.empty()) << unchecked; +} diff --git a/test/api/set_style.cpp b/test/api/set_style.cpp new file mode 100644 index 0000000000..973989d1c8 --- /dev/null +++ b/test/api/set_style.cpp @@ -0,0 +1,33 @@ +#include "../fixtures/util.hpp" +#include "../fixtures/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> + + +TEST(API, SetStyle) { + using namespace mbgl; + + auto display = std::make_shared<mbgl::HeadlessDisplay>(); + HeadlessView view(display); + DefaultFileSource fileSource(nullptr); + + Log::setObserver(util::make_unique<FixtureLogObserver>()); + + Map map(view, fileSource); + + map.start(Map::Mode::Static); + + map.setStyleJSON("invalid", "test/suite"); + + map.stop(); + + auto observer = Log::removeObserver(); + auto flo = dynamic_cast<FixtureLogObserver*>(observer.get()); + EXPECT_EQ(1ul, flo->count({ EventSeverity::Error, Event::ParseStyle, -1, + "Error parsing style JSON at 0: Expect either an object or array at root" })); + auto unchecked = flo->unchecked(); + EXPECT_TRUE(unchecked.empty()) << unchecked; +} |