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

Commit 4d3356d

Browse files
committed
[tests] Add tests for Map::[add|remove]Image
1 parent 486bddd commit 4d3356d

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-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

+33
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>
@@ -343,3 +345,34 @@ TEST(Map, Classes) {
343345
EXPECT_TRUE(map.getClasses().empty());
344346
EXPECT_FALSE(map.getTransitionOptions().duration);
345347
}
348+
349+
TEST(Map, AddImage) {
350+
MapTest test;
351+
352+
Map map(test.view, test.fileSource, MapMode::Still);
353+
auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
354+
auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
355+
auto image1 = std::make_unique<SpriteImage>(std::move(decoded1), 1.0);
356+
auto image2 = std::make_unique<SpriteImage>(std::move(decoded2), 1.0);
357+
358+
// No-op.
359+
map.addImage("test-icon", std::move(image1));
360+
361+
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
362+
map.addImage("test-icon", std::move(image2));
363+
test::checkImage("test/fixtures/map/add_icon", test::render(map));
364+
}
365+
366+
TEST(Map, RemoveImage) {
367+
MapTest test;
368+
369+
Map map(test.view, test.fileSource, MapMode::Still);
370+
auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
371+
auto image = std::make_unique<SpriteImage>(std::move(decoded), 1.0);
372+
373+
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
374+
map.addImage("test-icon", std::move(image));
375+
map.removeImage("test-icon");
376+
test::checkImage("test/fixtures/map/remove_icon", test::render(map));
377+
}
378+

0 commit comments

Comments
 (0)