summaryrefslogtreecommitdiff
path: root/test/sprite/sprite_atlas.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/sprite/sprite_atlas.test.cpp')
-rw-r--r--test/sprite/sprite_atlas.test.cpp40
1 files changed, 40 insertions, 0 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);
+}