summaryrefslogtreecommitdiff
path: root/test/sprite
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-22 13:28:09 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-26 11:21:56 -0700
commitaa216d00254c18f7b5903026ab1a489ae7797dd8 (patch)
tree7decb42cb0f8a8a5ae0e9d3bdcfdf69e76949e15 /test/sprite
parent6cf9d5cfbfe8120121d8d53cbbf8915cea8f4879 (diff)
downloadqtlocation-mapboxgl-aa216d00254c18f7b5903026ab1a489ae7797dd8.tar.gz
[core] Don't use a separate SpriteAtlas for annotation images
Instead, just add them to the Style as needed. Includes changes from #8905 and takes care to avoid regressing #3817.
Diffstat (limited to 'test/sprite')
-rw-r--r--test/sprite/sprite_atlas.test.cpp40
-rw-r--r--test/sprite/sprite_image_collection.test.cpp45
2 files changed, 40 insertions, 45 deletions
diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp
index 7a638a9ec5..4291fe9902 100644
--- a/test/sprite/sprite_atlas.test.cpp
+++ b/test/sprite/sprite_atlas.test.cpp
@@ -145,3 +145,43 @@ TEST(SpriteAtlas, RemoveReleasesBinPackRect) {
EXPECT_TRUE(atlas.getIcon("big"));
EXPECT_TRUE(log.empty());
}
+
+class StubIconRequestor : public IconRequestor {
+public:
+ void onIconsAvailable(IconMap icons) final {
+ if (iconsAvailable) iconsAvailable(icons);
+ }
+
+ std::function<void (IconMap)> iconsAvailable;
+};
+
+TEST(SpriteAtlas, NotifiesRequestorWhenSpriteIsLoaded) {
+ SpriteAtlas atlas;
+ StubIconRequestor requestor;
+ bool notified = false;
+
+ requestor.iconsAvailable = [&] (IconMap) {
+ notified = true;
+ };
+
+ atlas.getIcons(requestor, {"one"});
+ ASSERT_FALSE(notified);
+
+ atlas.onSpriteLoaded();
+ ASSERT_TRUE(notified);
+}
+
+TEST(SpriteAtlas, NotifiesRequestorImmediatelyIfDependenciesAreSatisfied) {
+ SpriteAtlas atlas;
+ StubIconRequestor requestor;
+ bool notified = false;
+
+ requestor.iconsAvailable = [&] (IconMap) {
+ notified = true;
+ };
+
+ atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2));
+ atlas.getIcons(requestor, {"one"});
+
+ ASSERT_TRUE(notified);
+}
diff --git a/test/sprite/sprite_image_collection.test.cpp b/test/sprite/sprite_image_collection.test.cpp
deleted file mode 100644
index 788d7a59d5..0000000000
--- a/test/sprite/sprite_image_collection.test.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <mbgl/test/util.hpp>
-#include <mbgl/test/fixture_log_observer.hpp>
-
-#include <mbgl/sprite/sprite_image_collection.hpp>
-#include <mbgl/util/image.hpp>
-#include <mbgl/util/string.hpp>
-
-#include <utility>
-
-using namespace mbgl;
-
-TEST(SpriteImageCollection, OtherPixelRatio) {
- FixtureLog log;
- Images images;
-
- // Adding mismatched sprite image
- addSpriteImage(images, std::make_unique<style::Image>("one", PremultipliedImage({ 8, 8 }), 2));
-}
-
-TEST(SpriteImageCollection, Replace) {
- FixtureLog log;
- Images images;
-
- addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
- auto image = images.find("sprite")->second.get();
- addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
- EXPECT_NE(image, images.find("sprite")->second.get());
-}
-
-TEST(SpriteImageCollection, ReplaceWithDifferentDimensions) {
- FixtureLog log;
- Images images;
-
- addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
- addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 18, 18 }), 2));
-
- EXPECT_EQ(1u, log.count({
- EventSeverity::Warning,
- Event::Sprite,
- int64_t(-1),
- "Can't change sprite dimensions for 'sprite'",
- }));
-}
-
-