summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-09-21 13:15:58 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-09-28 14:10:23 -0700
commitaf392b9434fd176704e564dfc22ee74f3a50cdf6 (patch)
treec3c333a4729a18c660b4edd68adeb801c779721e /test
parent24a58344284ca8c882bf2ab83b9129ca8ce9d4b3 (diff)
downloadqtlocation-mapboxgl-af392b9434fd176704e564dfc22ee74f3a50cdf6.tar.gz
Rewrite annotation invalidation strategy
First, move style mutation code out of StyleParser and into AnnotationManager, coalescing it with the mutation code for shape layers. Second, allow AnnotationManager to keep track of stale tiles entirely internally. There's no reason to pass sets of TileIDs around. Third, correct the logic for invalidating the shape source. Since AnnotationManager does not track shape invalidations on a tile-by-tile basis, don't try to invalidate the shape source tile-by-tile. Fixes #1675 Fixes #2322 Fixes #2095
Diffstat (limited to 'test')
-rw-r--r--test/api/annotations.cpp96
-rw-r--r--test/style/resource_loading.cpp4
2 files changed, 68 insertions, 32 deletions
diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp
index a9ebb4ab01..a00a449a6d 100644
--- a/test/api/annotations.cpp
+++ b/test/api/annotations.cpp
@@ -14,9 +14,19 @@
#include <future>
#include <vector>
-TEST(Annotations, PointAnnotation) {
- using namespace mbgl;
+using namespace mbgl;
+
+std::string renderPNG(Map& map) {
+ std::promise<std::unique_ptr<const StillImage>> promise;
+ map.renderStill([&](std::exception_ptr, std::unique_ptr<const StillImage> image) {
+ promise.set_value(std::move(image));
+ });
+ auto result = promise.get_future().get();
+ return util::compress_png(result->width, result->height, result->pixels.get());
+}
+
+TEST(Annotations, PointAnnotation) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
DefaultFileSource fileSource(nullptr);
@@ -25,19 +35,10 @@ TEST(Annotations, PointAnnotation) {
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
- std::promise<std::unique_ptr<const StillImage>> promise;
- map.renderStill([&promise](std::exception_ptr, std::unique_ptr<const StillImage> image) {
- promise.set_value(std::move(image));
- });
-
- auto result = promise.get_future().get();
- const std::string png = util::compress_png(result->width, result->height, result->pixels.get());
- util::write_file("test/output/point_annotation.png", png);
+ util::write_file("test/output/point_annotation.png", renderPNG(map));
}
TEST(Annotations, LineAnnotation) {
- using namespace mbgl;
-
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
DefaultFileSource fileSource(nullptr);
@@ -56,25 +57,55 @@ TEST(Annotations, LineAnnotation) {
map.addShapeAnnotation(ShapeAnnotation(segments, styleProperties));
- std::promise<std::unique_ptr<const StillImage>> promise;
- map.renderStill([&promise](std::exception_ptr, std::unique_ptr<const StillImage> image) {
- promise.set_value(std::move(image));
- });
-
- auto result = promise.get_future().get();
- const std::string png = util::compress_png(result->width, result->height, result->pixels.get());
- util::write_file("test/output/line_annotation.png", png);
+ util::write_file("test/output/line_annotation.png", renderPNG(map));
}
TEST(Annotations, FillAnnotation) {
- using namespace mbgl;
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1);
+ DefaultFileSource fileSource(nullptr);
+
+ Map map(view, fileSource, MapMode::Still);
+ map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
+
+ AnnotationSegments segments = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
+
+ FillProperties fillProperties;
+ fillProperties.fill_color = {{ 255, 0, 0, 1 }};
+
+ StyleProperties styleProperties;
+ styleProperties.set<FillProperties>(fillProperties);
+
+ map.addShapeAnnotation(ShapeAnnotation(segments, styleProperties));
+
+ util::write_file("test/output/fill_annotation.png", renderPNG(map));
+}
+TEST(Annotations, AddMultiple) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1);
DefaultFileSource fileSource(nullptr);
Map map(view, fileSource, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
+ map.addPointAnnotation(PointAnnotation({ 0, -20 }, "default_marker"));
+
+ renderPNG(map);
+
+ map.addPointAnnotation(PointAnnotation({ 0, 20 }, "default_marker"));
+
+ util::write_file("test/output/add_multiple.png", renderPNG(map));
+}
+
+TEST(Annotations, NonImmediateAdd) {
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1);
+ DefaultFileSource fileSource(nullptr);
+
+ Map map(view, fileSource, MapMode::Still);
+ map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
+
+ renderPNG(map);
AnnotationSegments segments = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
@@ -86,12 +117,21 @@ TEST(Annotations, FillAnnotation) {
map.addShapeAnnotation(ShapeAnnotation(segments, styleProperties));
- std::promise<std::unique_ptr<const StillImage>> promise;
- map.renderStill([&promise](std::exception_ptr, std::unique_ptr<const StillImage> image) {
- promise.set_value(std::move(image));
- });
+ util::write_file("test/output/non_immediate_add.png", renderPNG(map));
+}
- auto result = promise.get_future().get();
- const std::string png = util::compress_png(result->width, result->height, result->pixels.get());
- util::write_file("test/output/fill_annotation.png", png);
+TEST(Annotations, SwitchStyle) {
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1);
+ DefaultFileSource fileSource(nullptr);
+
+ Map map(view, fileSource, MapMode::Still);
+ map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
+ map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
+
+ renderPNG(map);
+
+ map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
+
+ util::write_file("test/output/switch_style.png", renderPNG(map));
}
diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp
index 5ed09065a1..0562434586 100644
--- a/test/style/resource_loading.cpp
+++ b/test/style/resource_loading.cpp
@@ -63,10 +63,6 @@ public:
callback_(error);
}
- void onSpriteStoreLoaded() override {
- // no-op
- }
-
private:
MapData data_;
Transform transform_;