-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check pixbuf loader signals #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <gdk-pixbuf/gdk-pixbuf.h> | ||
|
||
typedef struct | ||
{ | ||
gint area_prepared_cb_count; | ||
gint area_updated_cb_count; | ||
gint closed_cb_count; | ||
gint size_prepared_cb_count; | ||
} SignalsCounters; | ||
|
||
void | ||
area_prepared_cb (GdkPixbufLoader* self, gpointer user_data) | ||
{ | ||
SignalsCounters *counters = (SignalsCounters *) user_data; | ||
|
||
counters->area_prepared_cb_count++; | ||
} | ||
|
||
void | ||
area_updated_cb (GdkPixbufLoader* self, gint x, gint y, gint width, gint height, gpointer user_data) | ||
{ | ||
SignalsCounters *counters = (SignalsCounters *) user_data; | ||
|
||
counters->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) | ||
{ | ||
SignalsCounters *counters = (SignalsCounters *) user_data; | ||
|
||
counters->closed_cb_count++; | ||
} | ||
|
||
void | ||
size_prepared_cb (GdkPixbufLoader* self, gint width, gint height, gpointer user_data) | ||
{ | ||
SignalsCounters *counters = (SignalsCounters *) user_data; | ||
|
||
counters->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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please set to NULL for safety |
||
SignalsCounters *counters = g_new0(SignalsCounters, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can actually do |
||
|
||
loader = gdk_pixbuf_loader_new(); | ||
|
||
g_signal_connect (G_OBJECT(loader), "area-prepared", G_CALLBACK(area_prepared_cb), counters); | ||
g_signal_connect (G_OBJECT(loader), "area-updated", G_CALLBACK(area_updated_cb), counters); | ||
g_signal_connect (G_OBJECT(loader), "closed", G_CALLBACK(closed_cb), counters); | ||
g_signal_connect (G_OBJECT(loader), "size-prepared", G_CALLBACK(size_prepared_cb), counters); | ||
|
||
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_clear_pointer(&pixbuf_data, g_free); | ||
|
||
gdk_pixbuf_loader_close(loader, &error); | ||
if (error) | ||
g_error ("%s", error->message); | ||
g_assert (error == NULL); | ||
|
||
g_clear_object(&loader); | ||
|
||
g_clear_pointer(&env, g_strfreev); | ||
|
||
g_assert_cmpint (counters->area_prepared_cb_count, ==, 1); | ||
g_assert_cmpint (counters->area_updated_cb_count, ==, 1); | ||
g_assert_cmpint (counters->closed_cb_count, ==, 1); | ||
g_assert_cmpint (counters->size_prepared_cb_count, ==, 1); | ||
|
||
g_clear_pointer(&counters, g_free); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we use counters on the stack we don't need to free it anymore so we need to drop this line. |
||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of uninitialized pointers, please call gdk_pixbuf_loader_new() here or just declare the variable down below, we can use modern C patterns here.