diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 19412e613..aaf0271bd 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -17,6 +17,7 @@ set(MBGL_TEST_FILES test/api/api_misuse.test.cpp test/api/custom_layer.test.cpp test/api/query.test.cpp + test/api/recycle_map.cpp # gl test/gl/bucket.test.cpp diff --git a/test/api/recycle_map.cpp b/test/api/recycle_map.cpp new file mode 100644 index 000000000..8cd622fe7 --- /dev/null +++ b/test/api/recycle_map.cpp @@ -0,0 +1,58 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbgl; +using namespace mbgl::style; + + +TEST(API, RecycleMapUpdateImages) { + util::RunLoop loop; + + StubFileSource fileSource; + ThreadPool threadPool(4); + float pixelRatio { 1 }; + + HeadlessFrontend frontend { pixelRatio, fileSource, threadPool }; + auto map = std::make_unique(frontend, MapObserver::nullObserver(), frontend.getSize(), + pixelRatio, fileSource, threadPool, MapMode::Still); + + EXPECT_TRUE(map); + + auto loadStyle = [&](auto markerName, auto markerPath) { + auto source = std::make_unique("geometry"); + source->setGeoJSON({ Point { 0, 0 } }); + + auto layer = std::make_unique("geometry", "geometry"); + layer->setIconImage({ markerName }); + + map->getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); + map->getStyle().addSource(std::move(source)); + map->getStyle().addLayer(std::move(layer)); + map->getStyle().addImage(std::make_unique(markerName, decodeImage(util::read_file(markerPath)), 1.0)); + }; + + // default marker + + loadStyle("default_marker", "test/fixtures/sprites/default_marker.png"); + test::checkImage("test/fixtures/recycle_map/default_marker", frontend.render(*map), 0.0006, 0.1); + + // flipped marker + + loadStyle("flipped_marker", "test/fixtures/sprites/flipped_marker.png"); + test::checkImage("test/fixtures/recycle_map/flipped_marker", frontend.render(*map), 0.0006, 0.1); +} diff --git a/test/fixtures/recycle_map/default_marker/expected.png b/test/fixtures/recycle_map/default_marker/expected.png new file mode 100644 index 000000000..a23b79f8d Binary files /dev/null and b/test/fixtures/recycle_map/default_marker/expected.png differ diff --git a/test/fixtures/recycle_map/flipped_marker/expected.png b/test/fixtures/recycle_map/flipped_marker/expected.png new file mode 100644 index 000000000..3c4847f3a Binary files /dev/null and b/test/fixtures/recycle_map/flipped_marker/expected.png differ