From 0da968fd5f1c5f8b05f4549be6bf77fe2f1daa62 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 24 Oct 2014 13:48:17 +0200 Subject: tests: Add test case for short GIF writes Based on the test program from Andrey Tsyvarev https://bugzilla.gnome.org/show_bug.cgi?id=581461 --- tests/pixbuf-short-gif-write.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/pixbuf-short-gif-write.c (limited to 'tests/pixbuf-short-gif-write.c') diff --git a/tests/pixbuf-short-gif-write.c b/tests/pixbuf-short-gif-write.c new file mode 100644 index 000000000..592ef6b23 --- /dev/null +++ b/tests/pixbuf-short-gif-write.c @@ -0,0 +1,61 @@ +#include "config.h" +#include "gdk-pixbuf/gdk-pixbuf.h" +#include + +/* + * Reads count_bytes from the channel and write them to the loader. + * Returns number of bytes written. + * count_bytes = G_MAXSIZE means read as many bytes as possible. + */ +static gsize +loader_write_from_channel (GdkPixbufLoader *loader, + GIOChannel *channel, + gsize count_bytes) +{ + guchar* buffer = NULL; + gsize bytes_read = 0; + GIOStatus read_status; + GError* error = NULL; + if(count_bytes < G_MAXSIZE) { + //read no more than 'count_bytes' bytes + buffer = g_malloc (count_bytes); + read_status = g_io_channel_read_chars (channel, (gchar*)buffer, count_bytes, &bytes_read, NULL); + } else { + //read up to end + read_status = g_io_channel_read_to_end (channel, (gchar**)&buffer, &bytes_read, NULL); + } + g_assert (read_status == G_IO_STATUS_NORMAL || read_status == G_IO_STATUS_EOF); + + g_assert (gdk_pixbuf_loader_write(loader, buffer, bytes_read, &error)); + g_assert_no_error (error); + g_free(buffer); + return bytes_read; +} + +static void +test_short_gif_write (void) +{ + GIOChannel* channel = g_io_channel_new_file (g_test_get_filename (G_TEST_DIST, "test-animation.gif", NULL), "r", NULL); + g_assert_nonnull (channel); + g_io_channel_set_encoding (channel, NULL, NULL); + + GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_type ("gif", NULL); + g_assert_nonnull (loader); + + loader_write_from_channel (loader, channel, 10); + loader_write_from_channel (loader, channel, G_MAXSIZE); + + g_io_channel_unref (channel); + + gdk_pixbuf_loader_close (loader, NULL); + g_object_unref (loader); +} + +int main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/animation/short_gif_write", test_short_gif_write); + + return g_test_run (); +} -- cgit v1.2.1