summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-09-16 17:02:43 -0700
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-09-22 17:43:28 +0300
commit4d3356dc1e1239d8f4fb985d2f584a403aea8521 (patch)
tree60d03809da1b5d6e6856db7fb3957cc63b63bd27
parent486bdddb23c93572c29068a229041b2575f383e8 (diff)
downloadqtlocation-mapboxgl-4d3356dc1e1239d8f4fb985d2f584a403aea8521.tar.gz
[tests] Add tests for Map::[add|remove]Image
-rw-r--r--test/fixtures/api/icon_style.json25
-rw-r--r--test/fixtures/map/add_icon/expected.pngbin0 -> 1741 bytes
-rw-r--r--test/fixtures/map/remove_icon/expected.pngbin0 -> 355 bytes
-rw-r--r--test/map/map.cpp33
4 files changed, 58 insertions, 0 deletions
diff --git a/test/fixtures/api/icon_style.json b/test/fixtures/api/icon_style.json
new file mode 100644
index 0000000000..17d41c6b68
--- /dev/null
+++ b/test/fixtures/api/icon_style.json
@@ -0,0 +1,25 @@
+{
+ "version": 8,
+ "sources": {
+ "geojson": {
+ "type": "geojson",
+ "data": {
+ "type": "Point",
+ "coordinates": [
+ 0,
+ 0
+ ]
+ }
+ }
+ },
+ "layers": [
+ {
+ "id": "symbol",
+ "type": "symbol",
+ "source": "geojson",
+ "layout": {
+ "icon-image": "test-icon"
+ }
+ }
+ ]
+}
diff --git a/test/fixtures/map/add_icon/expected.png b/test/fixtures/map/add_icon/expected.png
new file mode 100644
index 0000000000..0297f7c0ce
--- /dev/null
+++ b/test/fixtures/map/add_icon/expected.png
Binary files differ
diff --git a/test/fixtures/map/remove_icon/expected.png b/test/fixtures/map/remove_icon/expected.png
new file mode 100644
index 0000000000..b97b635a21
--- /dev/null
+++ b/test/fixtures/map/remove_icon/expected.png
Binary files differ
diff --git a/test/map/map.cpp b/test/map/map.cpp
index 0437296350..12d4ff2bcd 100644
--- a/test/map/map.cpp
+++ b/test/map/map.cpp
@@ -6,8 +6,10 @@
#include <mbgl/map/map.hpp>
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/storage/network_status.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 <mbgl/style/layers/background_layer.hpp>
@@ -343,3 +345,34 @@ TEST(Map, Classes) {
EXPECT_TRUE(map.getClasses().empty());
EXPECT_FALSE(map.getTransitionOptions().duration);
}
+
+TEST(Map, AddImage) {
+ MapTest test;
+
+ Map map(test.view, test.fileSource, MapMode::Still);
+ auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
+ auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
+ auto image1 = std::make_unique<SpriteImage>(std::move(decoded1), 1.0);
+ auto image2 = std::make_unique<SpriteImage>(std::move(decoded2), 1.0);
+
+ // No-op.
+ map.addImage("test-icon", std::move(image1));
+
+ map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
+ map.addImage("test-icon", std::move(image2));
+ test::checkImage("test/fixtures/map/add_icon", test::render(map));
+}
+
+TEST(Map, RemoveImage) {
+ MapTest test;
+
+ Map map(test.view, test.fileSource, MapMode::Still);
+ auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
+ auto image = std::make_unique<SpriteImage>(std::move(decoded), 1.0);
+
+ map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
+ map.addImage("test-icon", std::move(image));
+ map.removeImage("test-icon");
+ test::checkImage("test/fixtures/map/remove_icon", test::render(map));
+}
+