[libhandy] test: Check that the avatar image_load_func is only called when needed



commit e52a8be3f23cb349fcaf6d4626d0763fe6ed6b5a
Author: Julian Sparber <julian sparber net>
Date:   Mon Oct 26 11:45:28 2020 +0100

    test: Check that the avatar image_load_func is only called when needed

 tests/test-avatar.c | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/tests/test-avatar.c b/tests/test-avatar.c
index ad330aeb..6ee6ef56 100644
--- a/tests/test-avatar.c
+++ b/tests/test-avatar.c
@@ -11,6 +11,8 @@
 #define TEST_SIZE 128
 
 
+gint load_image_func_count;
+
 static gboolean
 is_surface_empty (cairo_surface_t *surface)
 {
@@ -32,6 +34,7 @@ static GdkPixbuf *
 load_null_image_func (gint size,
                       gpointer data)
 {
+  load_image_func_count++;
   return NULL;
 }
 
@@ -43,6 +46,8 @@ load_image_func (gint size,
   cairo_surface_t *surface;
   cairo_t *cr;
 
+  load_image_func_count++;
+
   surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
   cr = cairo_create (surface);
   if (color != NULL) {
@@ -159,6 +164,8 @@ test_hdy_avatar_custom_image (void)
 
   g_assert (HDY_IS_AVATAR (avatar));
 
+  load_image_func_count = 0;
+
   hdy_avatar_set_image_load_func (HDY_AVATAR (avatar),
                                   (HdyAvatarImageLoadFunc) load_image_func,
                                   NULL,
@@ -189,6 +196,8 @@ test_hdy_avatar_custom_image (void)
 
   g_assert_true (did_draw_something (avatar));
 
+  g_assert_cmpint (load_image_func_count, ==, 3);
+
   g_object_unref (avatar);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]