[test] Add pixelmatch; use in annotation tests
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/platform/default/headless_view.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
|
||||
#include <future>
|
||||
@@ -15,12 +14,18 @@
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
std::string renderPNG(Map& map) {
|
||||
UnassociatedImage render(Map& map) {
|
||||
std::promise<UnassociatedImage> promise;
|
||||
map.renderStill([&](std::exception_ptr, UnassociatedImage&& image) {
|
||||
promise.set_value(std::move(image));
|
||||
});
|
||||
return encodePNG(promise.get_future().get());
|
||||
return std::move(promise.get_future().get());
|
||||
}
|
||||
|
||||
void checkRendering(Map& map, const char * name) {
|
||||
UnassociatedImage actual = render(map);
|
||||
test::checkImage(std::string("test/fixtures/annotations/") + name + "/",
|
||||
actual, 0.0002, 0.1);
|
||||
}
|
||||
|
||||
TEST(Annotations, PointAnnotation) {
|
||||
@@ -30,9 +35,9 @@ TEST(Annotations, PointAnnotation) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker"));
|
||||
|
||||
util::write_file("test/output/point_annotation.png", renderPNG(map));
|
||||
checkRendering(map, "point_annotation");
|
||||
}
|
||||
|
||||
TEST(Annotations, LineAnnotation) {
|
||||
@@ -51,7 +56,7 @@ TEST(Annotations, LineAnnotation) {
|
||||
|
||||
map.addShapeAnnotation(ShapeAnnotation(segments, properties));
|
||||
|
||||
util::write_file("test/output/line_annotation.png", renderPNG(map));
|
||||
checkRendering(map, "line_annotation");
|
||||
}
|
||||
|
||||
TEST(Annotations, FillAnnotation) {
|
||||
@@ -69,7 +74,7 @@ TEST(Annotations, FillAnnotation) {
|
||||
|
||||
map.addShapeAnnotation(ShapeAnnotation(segments, properties));
|
||||
|
||||
util::write_file("test/output/fill_annotation.png", renderPNG(map));
|
||||
checkRendering(map, "fill_annotation");
|
||||
}
|
||||
|
||||
TEST(Annotations, StyleSourcedShapeAnnotation) {
|
||||
@@ -84,7 +89,7 @@ TEST(Annotations, StyleSourcedShapeAnnotation) {
|
||||
|
||||
map.addShapeAnnotation(ShapeAnnotation(segments, "annotation"));
|
||||
|
||||
util::write_file("test/output/style_sourced_shape_annotation.png", renderPNG(map));
|
||||
checkRendering(map, "style_sourced_shape_annotation");
|
||||
}
|
||||
|
||||
TEST(Annotations, AddMultiple) {
|
||||
@@ -96,11 +101,11 @@ TEST(Annotations, AddMultiple) {
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker"));
|
||||
|
||||
renderPNG(map);
|
||||
render(map);
|
||||
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 20 }, "default_marker"));
|
||||
|
||||
util::write_file("test/output/add_multiple.png", renderPNG(map));
|
||||
checkRendering(map, "add_multiple");
|
||||
}
|
||||
|
||||
TEST(Annotations, NonImmediateAdd) {
|
||||
@@ -111,7 +116,7 @@ TEST(Annotations, NonImmediateAdd) {
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
|
||||
renderPNG(map);
|
||||
render(map);
|
||||
|
||||
AnnotationSegments segments = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
|
||||
|
||||
@@ -120,7 +125,7 @@ TEST(Annotations, NonImmediateAdd) {
|
||||
|
||||
map.addShapeAnnotation(ShapeAnnotation(segments, properties));
|
||||
|
||||
util::write_file("test/output/non_immediate_add.png", renderPNG(map));
|
||||
checkRendering(map, "non_immediate_add");
|
||||
}
|
||||
|
||||
TEST(Annotations, RemovePoint) {
|
||||
@@ -132,11 +137,11 @@ TEST(Annotations, RemovePoint) {
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
uint32_t point = map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
|
||||
|
||||
renderPNG(map);
|
||||
render(map);
|
||||
|
||||
map.removeAnnotation(point);
|
||||
|
||||
util::write_file("test/output/remove_point.png", renderPNG(map));
|
||||
checkRendering(map, "remove_point");
|
||||
}
|
||||
|
||||
TEST(Annotations, RemoveShape) {
|
||||
@@ -154,11 +159,11 @@ TEST(Annotations, RemoveShape) {
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
uint32_t shape = map.addShapeAnnotation(ShapeAnnotation(segments, properties));
|
||||
|
||||
renderPNG(map);
|
||||
render(map);
|
||||
|
||||
map.removeAnnotation(shape);
|
||||
|
||||
util::write_file("test/output/remove_shape.png", renderPNG(map));
|
||||
checkRendering(map, "remove_shape");
|
||||
}
|
||||
|
||||
TEST(Annotations, ImmediateRemoveShape) {
|
||||
@@ -170,7 +175,7 @@ TEST(Annotations, ImmediateRemoveShape) {
|
||||
map.removeAnnotation(map.addShapeAnnotation(ShapeAnnotation({}, {})));
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
|
||||
renderPNG(map);
|
||||
render(map);
|
||||
}
|
||||
|
||||
TEST(Annotations, SwitchStyle) {
|
||||
@@ -180,13 +185,13 @@ TEST(Annotations, SwitchStyle) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker"));
|
||||
|
||||
renderPNG(map);
|
||||
render(map);
|
||||
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
|
||||
util::write_file("test/output/switch_style.png", renderPNG(map));
|
||||
checkRendering(map, "switch_style");
|
||||
}
|
||||
|
||||
TEST(Annotations, CustomIcon) {
|
||||
@@ -199,5 +204,5 @@ TEST(Annotations, CustomIcon) {
|
||||
map.setSprite("cafe", std::make_shared<SpriteImage>(12, 12, 1, std::string(12 * 12 * 4, '\xFF')));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "cafe"));
|
||||
|
||||
util::write_file("test/output/custom_icon.png", renderPNG(map));
|
||||
checkRendering(map, "custom_icon");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user