diff options
author | Bastien Nocera <hadess@hadess.net> | 2014-10-24 13:48:17 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2014-10-24 13:48:48 +0200 |
commit | 0da968fd5f1c5f8b05f4549be6bf77fe2f1daa62 (patch) | |
tree | e56125f82b039c2594552abed13a3f056b03425a | |
parent | 692b0ceaf032be2cd2558396c2b74a64869048d5 (diff) | |
download | gdk-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
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/pixbuf-short-gif-write.c | 61 |
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 868da9d24..99238c384 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -32,6 +32,7 @@ test_programs = \ pixbuf-stream \ pixbuf-resource \ pixbuf-scale \ + pixbuf-short-gif-write \ pixbuf-save \ pixbuf-readonly-to-mutable \ $(NULL) @@ -88,6 +89,9 @@ pixbuf_save_SOURCES = \ test-common.h \ $(NULL) +pixbuf_short_git_write_SOURCES = \ + pixbuf-short-gif-write.c + pixbuf_readonly_to_mutable_SOURCES = \ pixbuf-readonly-to-mutable.c \ test-common.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 <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 (); +} |