Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit b0c56dd

Browse files
committed
[tests] Add tests for Map::[add|remove]Icon
1 parent 0d224b5 commit b0c56dd

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

test/fixtures/api/icon_style.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": 8,
3+
"sources": {
4+
"geojson": {
5+
"type": "geojson",
6+
"data": {
7+
"type": "Point",
8+
"coordinates": [
9+
0,
10+
0
11+
]
12+
}
13+
}
14+
},
15+
"layers": [
16+
{
17+
"id": "symbol",
18+
"type": "symbol",
19+
"source": "geojson",
20+
"layout": {
21+
"icon-image": "test-icon"
22+
}
23+
}
24+
]
25+
}
1.7 KB
Loading
355 Bytes
Loading

test/map/map.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include <mbgl/map/map.hpp>
77
#include <mbgl/platform/default/headless_view.hpp>
88
#include <mbgl/platform/default/headless_display.hpp>
9+
#include <mbgl/sprite/sprite_image.hpp>
910
#include <mbgl/storage/network_status.hpp>
1011
#include <mbgl/storage/default_file_source.hpp>
12+
#include <mbgl/util/image.hpp>
1113
#include <mbgl/util/io.hpp>
1214
#include <mbgl/util/run_loop.hpp>
1315
#include <mbgl/style/layers/background_layer.hpp>
@@ -262,3 +264,35 @@ TEST(Map, Classes) {
262264
EXPECT_TRUE(map.getClasses().empty());
263265
EXPECT_FALSE(map.getTransitionOptions().duration);
264266
}
267+
268+
TEST(Map, AddIcon) {
269+
MapTest test;
270+
271+
Map map(test.view, test.fileSource, MapMode::Still);
272+
auto image = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
273+
auto icon = std::make_shared<SpriteImage>(std::move(image), 1.0);
274+
275+
// No-op.
276+
map.addIcon("test-icon", icon);
277+
278+
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
279+
map.addIcon("test-icon", icon);
280+
test::checkImage("test/fixtures/map/add_icon", test::render(map));
281+
}
282+
283+
TEST(Map, RemoveIcon) {
284+
MapTest test;
285+
286+
Map map(test.view, test.fileSource, MapMode::Still);
287+
auto image = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
288+
auto icon = std::make_shared<SpriteImage>(std::move(image), 1.0);
289+
290+
// No-op.
291+
map.addIcon("test-icon", icon);
292+
293+
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
294+
map.addIcon("test-icon", icon);
295+
map.removeIcon("test-icon");
296+
test::checkImage("test/fixtures/map/remove_icon", test::render(map));
297+
}
298+

0 commit comments

Comments
 (0)