summaryrefslogtreecommitdiff
path: root/tests/pixbuf-short-gif-write.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-10-24 13:48:17 +0200
committerBastien Nocera <hadess@hadess.net>2014-10-24 13:48:48 +0200
commit0da968fd5f1c5f8b05f4549be6bf77fe2f1daa62 (patch)
treee56125f82b039c2594552abed13a3f056b03425a /tests/pixbuf-short-gif-write.c
parent692b0ceaf032be2cd2558396c2b74a64869048d5 (diff)
downloadgdk-pixbuf-0da968fd5f1c5f8b05f4549be6bf77fe2f1daa62.tar.gz
tests: Add test case for short GIF writes
Based on the test program from Andrey Tsyvarev <tsyvarev@ispras.ru> https://bugzilla.gnome.org/show_bug.cgi?id=581461
Diffstat (limited to 'tests/pixbuf-short-gif-write.c')
-rw-r--r--tests/pixbuf-short-gif-write.c61
1 files changed, 61 insertions, 0 deletions
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 <glib.h>
+
+/*
+ * 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 ();
+}