diff --git a/test/fixtures/api/icon_style.json b/test/fixtures/api/icon_style.json new file mode 100644 index 000000000..17d41c6b6 --- /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 000000000..0297f7c0c Binary files /dev/null and b/test/fixtures/map/add_icon/expected.png differ diff --git a/test/fixtures/map/remove_icon/expected.png b/test/fixtures/map/remove_icon/expected.png new file mode 100644 index 000000000..b97b635a2 Binary files /dev/null and b/test/fixtures/map/remove_icon/expected.png differ diff --git a/test/map/map.cpp b/test/map/map.cpp index 043729635..12d4ff2bc 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -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(std::move(decoded1), 1.0); + auto image2 = std::make_unique(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(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)); +} +