summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-07-06 16:38:31 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-07-08 19:46:03 +0200
commit1f4b5e773634f12c00b6d6c846defc908ec79604 (patch)
treea153bb7ab6f4a2a8e957dcee9e66d5e2e1be9a6c
parentc66ec8739b0a0bfb22c59f05c6125717763c6f7e (diff)
downloadqtlocation-mapboxgl-1f4b5e773634f12c00b6d6c846defc908ec79604.tar.gz
add custom imagery visual test
-rw-r--r--test/fixtures/headless/pois.json26
-rw-r--r--test/fixtures/tiles/streets/15-17605-10749.vector.pbfbin0 -> 143637 bytes
-rw-r--r--test/fixtures/tiles/streets/15-17605-10750.vector.pbfbin0 -> 123586 bytes
-rw-r--r--test/headless/custom_sprites.cpp61
-rw-r--r--test/headless/headless.cpp6
-rw-r--r--test/test.gypi1
6 files changed, 93 insertions, 1 deletions
diff --git a/test/fixtures/headless/pois.json b/test/fixtures/headless/pois.json
new file mode 100644
index 0000000000..7a4488608a
--- /dev/null
+++ b/test/fixtures/headless/pois.json
@@ -0,0 +1,26 @@
+{
+ "version": 7,
+ "name": "POIs",
+ "sources": {
+ "mapbox": {
+ "type": "vector",
+ "url": "asset://TEST_DATA/fixtures/tiles/streets.json"
+ }
+ },
+ "layers": [{
+ "id": "background",
+ "type": "background",
+ "paint": {
+ "background-color": "#CCCCCC"
+ }
+ }, {
+ "id": "pois",
+ "type": "symbol",
+ "source": "mapbox",
+ "source-layer": "poi_label",
+ "filter": ["in", "maki", "cafe", "bakery"],
+ "layout": {
+ "icon-image": "{maki}"
+ }
+ }]
+}
diff --git a/test/fixtures/tiles/streets/15-17605-10749.vector.pbf b/test/fixtures/tiles/streets/15-17605-10749.vector.pbf
new file mode 100644
index 0000000000..1f43a6c487
--- /dev/null
+++ b/test/fixtures/tiles/streets/15-17605-10749.vector.pbf
Binary files differ
diff --git a/test/fixtures/tiles/streets/15-17605-10750.vector.pbf b/test/fixtures/tiles/streets/15-17605-10750.vector.pbf
new file mode 100644
index 0000000000..1ad616a56c
--- /dev/null
+++ b/test/fixtures/tiles/streets/15-17605-10750.vector.pbf
Binary files differ
diff --git a/test/headless/custom_sprites.cpp b/test/headless/custom_sprites.cpp
new file mode 100644
index 0000000000..e2c479a5c2
--- /dev/null
+++ b/test/headless/custom_sprites.cpp
@@ -0,0 +1,61 @@
+#include "../fixtures/util.hpp"
+#include "../fixtures/fixture_log_observer.hpp"
+
+#include <mbgl/map/map.hpp>
+#include <mbgl/map/still_image.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/annotation/sprite_image.hpp>
+
+#include <mbgl/util/io.hpp>
+
+#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/storage/default_file_source.hpp>
+
+#include <future>
+
+using namespace mbgl;
+
+TEST(Headless, CustomSpriteImages) {
+ FixtureLog log;
+
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1);
+ view.resize(256, 256);
+ DefaultFileSource fileSource(nullptr);
+
+ const auto style = util::read_file("test/fixtures/headless/pois.json");
+
+ Map map(view, fileSource, MapMode::Still);
+
+ map.setLatLngZoom(LatLng{ 52.499167, 13.418056 }, 15);
+
+ map.setStyleJSON(style, "test/suite");
+ map.setSprite("cafe",
+ std::make_shared<SpriteImage>(12, 12, 1, std::string(12 * 12 * 4, '\xFF')));
+ std::promise<std::unique_ptr<const StillImage>> promise;
+ map.renderStill([&promise](std::exception_ptr error, std::unique_ptr<const StillImage> image) {
+ if (error) {
+ promise.set_exception(error);
+ } else {
+ promise.set_value(std::move(image));
+ }
+ });
+ auto result = promise.get_future().get();
+ ASSERT_EQ(256, result->width);
+ ASSERT_EQ(256, result->height);
+
+ EXPECT_EQ(
+ 21u,
+ log.count({
+ EventSeverity::Info, Event::Sprite, int64_t(-1), "Can't find sprite named 'bakery'",
+ }));
+
+ // const size_t bytes = result->width * result->height * 4;
+ // const auto hash = test::crc64(reinterpret_cast<const char*>(result->pixels.get()), bytes);
+ // EXPECT_EQ(0xC40A4BCD76AEC564u, hash) << std::hex << hash;
+
+ // const std::string png = util::compress_png(result->width, result->height,
+ // result->pixels.get());
+ // util::write_file("test/fixtures/headless/1.actual.png", png);
+}
diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp
index 60f72b0be3..80951433ed 100644
--- a/test/headless/headless.cpp
+++ b/test/headless/headless.cpp
@@ -150,7 +150,11 @@ TEST_P(HeadlessTest, render) {
map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom);
map.setBearing(bearing);
- map.renderStill([&](std::exception_ptr, std::unique_ptr<const StillImage> image) {
+ map.renderStill([&](std::exception_ptr error, std::unique_ptr<const StillImage> image) {
+ if (error) {
+ promise.set_exception(error);
+ return;
+ }
const std::string png = util::compress_png(image->width, image->height, image->pixels.get());
util::write_file("test/suite/tests/" + base + "/" + name + "/actual.png", png);
promise.set_value();
diff --git a/test/test.gypi b/test/test.gypi
index f5930867bb..8cf7b1b063 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -46,6 +46,7 @@
'api/repeated_render.cpp',
'api/set_style.cpp',
+ 'headless/custom_sprites.cpp',
'headless/headless.cpp',
'miscellaneous/clip_ids.cpp',