summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-04-16 19:01:00 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-04-17 13:40:42 +0200
commit5d769f9b6253aa9f7792c3126cffb7f390177d88 (patch)
treed6797f37a2cf889c48c947228045c6543234a559 /test
parent9af3f07e5b3833f98461bbb7caccda5ff37e5d17 (diff)
downloadqtlocation-mapboxgl-5d769f9b6253aa9f7792c3126cffb7f390177d88.tar.gz
explicitly call .discard() to resize the view on static renders
- this is only a stopgap; we need to properly pass state between threads - doesn't fix changing the pixel ratio
Diffstat (limited to 'test')
-rw-r--r--test/api/repeated_render.cpp63
-rw-r--r--test/fixtures/api/1.pngbin0 -> 12529 bytes
-rw-r--r--test/fixtures/api/2.pngbin0 -> 115197 bytes
-rw-r--r--test/fixtures/api/water.json25
-rw-r--r--test/fixtures/tiles/streets.json14
-rw-r--r--test/fixtures/tiles/streets/0-0-0.vector.pbfbin0 -> 482553 bytes
-rw-r--r--test/test.gyp1
7 files changed, 103 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/fixtures/api/1.png b/test/fixtures/api/1.png
new file mode 100644
index 0000000000..69e3c8ca95
--- /dev/null
+++ b/test/fixtures/api/1.png
Binary files differ
diff --git a/test/fixtures/api/2.png b/test/fixtures/api/2.png
new file mode 100644
index 0000000000..2a28c639a5
--- /dev/null
+++ b/test/fixtures/api/2.png
Binary files differ
diff --git a/test/fixtures/api/water.json b/test/fixtures/api/water.json
new file mode 100644
index 0000000000..2bcce11992
--- /dev/null
+++ b/test/fixtures/api/water.json
@@ -0,0 +1,25 @@
+{
+ "version": 7,
+ "name": "Water",
+ "sources": {
+ "mapbox": {
+ "type": "vector",
+ "url": "asset://TEST_DATA/fixtures/tiles/streets.json"
+ }
+ },
+ "layers": [{
+ "id": "background",
+ "type": "background",
+ "paint": {
+ "background-color": "red"
+ }
+ }, {
+ "id": "water",
+ "type": "fill",
+ "source": "mapbox",
+ "source-layer": "water",
+ "paint": {
+ "fill-color": "blue"
+ }
+ }]
+}
diff --git a/test/fixtures/tiles/streets.json b/test/fixtures/tiles/streets.json
new file mode 100644
index 0000000000..a848a1bf72
--- /dev/null
+++ b/test/fixtures/tiles/streets.json
@@ -0,0 +1,14 @@
+{
+ "bounds": [ -180, -85.0511, 180, 85.0511 ],
+ "center": [ 0, 0, 0 ],
+ "description": "",
+ "format": "pbf",
+ "id": "streets",
+ "maskLevel": 8,
+ "maxzoom": 15,
+ "minzoom": 0,
+ "name": "Streets",
+ "scheme": "xyz",
+ "tilejson": "2.0.0",
+ "tiles": [ "asset://TEST_DATA/fixtures/tiles/streets/{z}-{x}-{y}.vector.pbf" ]
+}
diff --git a/test/fixtures/tiles/streets/0-0-0.vector.pbf b/test/fixtures/tiles/streets/0-0-0.vector.pbf
new file mode 100644
index 0000000000..a0f049ad43
--- /dev/null
+++ b/test/fixtures/tiles/streets/0-0-0.vector.pbf
Binary files differ
diff --git a/test/test.gyp b/test/test.gyp
index 2f14a4477d..2e89db58b0 100644
--- a/test/test.gyp
+++ b/test/test.gyp
@@ -36,6 +36,7 @@
'fixtures/fixture_log_observer.cpp',
'api/set_style.cpp',
+ 'api/repeated_render.cpp',
'headless/headless.cpp',