Skip to content

Commit

Permalink
Check pixbuf loader signals
Browse files Browse the repository at this point in the history
This test will detect the problem noted in aruiz#73.
  • Loading branch information
caclark committed Dec 24, 2023
1 parent 481533d commit b5f2a04
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ t_null_error = executable('t_null_error', 't_null_error.c', dependencies : [gdk
t_scaled = executable('t_scaled', 't_scaled.c', dependencies : [gdkpb, webp, webpdemux])
t_jpeg = executable('t_jpeg', 't_jpeg.c', dependencies : [gdkpb, webp, webpdemux])
t_large = executable('t_large', 't_large.c', dependencies : [gdkpb, webp, webpdemux, gio])
t_signals = executable('t_signals', 't_signals.c', dependencies : [gdkpb, webp, webpdemux, gio])

loaders_data = configuration_data()
loaders_data.set('MODULE_PATH', fs.as_posix(pbl_webp.full_path()))
Expand All @@ -29,4 +30,5 @@ test('icc data', t_icc, env : test_env + [ test_file_base / 't2.webp']
test('NULL GError', t_null_error, env : test_env + [ test_file_base / 't2.webp'])
test('large file', t_large, env : test_env + [ test_file_base / 't_large.webp'])
test('scaled image', t_scaled, env : test_env + [ test_file_base / 't2.webp', 'TEST_FILE_ANIM=' + meson.current_source_dir() / 'data' / 't3.webp'])
test('jpeg with .webp extension', t_jpeg, env : test_env + [ test_file_base / 'test_jpeg_as_webp.webp'])
test('jpeg with .webp extension', t_jpeg, env : test_env + [ test_file_base / 'test_jpeg_as_webp.webp'])
test('signal handling', t_signals, env : test_env + [ test_file_base / 't2.webp'])
83 changes: 83 additions & 0 deletions tests/t_signals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <gdk-pixbuf/gdk-pixbuf.h>

gint area_prepared_cb_count = 0;
gint area_updated_cb_count = 0;
gint closed_cb_count = 0;
gint size_prepared_cb_count = 0;

void
area_prepared_cb (GdkPixbufLoader* self, gpointer user_data)
{
area_prepared_cb_count++;
}

void
area_updated_cb (GdkPixbufLoader* self, gint x, gint y, gint width, gint height, gpointer user_data)
{
area_updated_cb_count++;

g_assert_cmpint (x, ==, 0);
g_assert_cmpint (y, ==, 0);
g_assert_cmpint (width, ==, 200);
g_assert_cmpint (height, ==, 200);
}

void
closed_cb (GdkPixbufLoader* self, gpointer user_data)
{
closed_cb_count++;
}

void
size_prepared_cb (GdkPixbufLoader* self, gint width, gint height, gpointer user_data)
{
size_prepared_cb_count++;

g_assert_cmpint (width, ==, 200);
g_assert_cmpint (height, ==, 200);
}

gint
main (gint argc, gchar **argv)
{
gchar **env = g_get_environ ();
GdkPixbufLoader *loader;
GError *error = NULL;
gsize pixbuf_size;
guchar *pixbuf_data;

loader = gdk_pixbuf_loader_new();

g_signal_connect (G_OBJECT(loader), "area-prepared", G_CALLBACK(area_prepared_cb), NULL);
g_signal_connect (G_OBJECT(loader), "area-updated", G_CALLBACK(area_updated_cb), NULL);
g_signal_connect (G_OBJECT(loader), "closed", G_CALLBACK(closed_cb), NULL);
g_signal_connect (G_OBJECT(loader), "size-prepared", G_CALLBACK(size_prepared_cb), NULL);

g_file_get_contents (g_environ_getenv (env, "TEST_FILE"), (gchar**)&pixbuf_data, &pixbuf_size, &error);
if (error)
g_error ("%s", error->message);
g_assert (error == NULL);

gdk_pixbuf_loader_write(loader, pixbuf_data, pixbuf_size, &error);
if (error)
g_error ("%s", error->message);
g_assert (error == NULL);

g_free(pixbuf_data);

gdk_pixbuf_loader_close(loader, &error);
if (error)
g_error ("%s", error->message);
g_assert (error == NULL);

g_object_unref(G_OBJECT(loader));

g_strfreev (env);

g_assert_cmpint (area_prepared_cb_count, ==, 1);
g_assert_cmpint (area_updated_cb_count, ==, 1);
g_assert_cmpint (closed_cb_count, ==, 1);
g_assert_cmpint (size_prepared_cb_count, ==, 1);

return 0;
}

0 comments on commit b5f2a04

Please sign in to comment.