[gdk-pixbuf] tests: Split off failing test into 2 separate tests



commit 4ffc78b66b60ac8741bc78be60386b3ddb0b33ba
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 13 14:13:18 2017 +0200

    tests: Split off failing test into 2 separate tests
    
    One with the tiniest of buffers, one with the biggest one possible.
    This catches some crashes that weren't caught with the original "1 byte"
    buffers test.
    
    This makes it possible to reproduce the crasher in
    https://bugzilla.gnome.org/show_bug.cgi?id=784866

 tests/pixbuf-fail.c |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/tests/pixbuf-fail.c b/tests/pixbuf-fail.c
index 0e37c2d..322d5f6 100644
--- a/tests/pixbuf-fail.c
+++ b/tests/pixbuf-fail.c
@@ -26,17 +26,16 @@
 #include "test-common.h"
 
 static void
-test_fail (gconstpointer data)
+test_fail_size (GFile *file,
+               guint  chunk_size)
 {
   GdkPixbufLoader *loader;
   GError *error = NULL;
-  GFile *file;
   guchar *contents;
   gsize i, contents_length;
   char *filename, *content_type, *mime_type;
   gboolean success;
 
-  file = G_FILE (data);
   if (!file_supported (file))
     {
       g_test_skip ("format not supported");
@@ -57,9 +56,9 @@ test_fail (gconstpointer data)
   g_assert_no_error (error);
   g_assert (loader != NULL);
 
-  for (i = 0; i < contents_length; i++)
+  for (i = 0; i < contents_length; i += chunk_size)
     {
-      success = gdk_pixbuf_loader_write (loader, &contents[i], 1, &error);
+      success = gdk_pixbuf_loader_write (loader, &contents[i], MIN(chunk_size, contents_length - i), &error);
       if (!success)
         {
           g_assert (error);
@@ -82,6 +81,22 @@ out:
   g_free (filename);
 }
 
+static void
+test_fail_tiny (gconstpointer data)
+{
+  GFile *file = (GFile *) data;
+
+  test_fail_size (file, 1);
+}
+
+static void
+test_fail_huge (gconstpointer data)
+{
+  GFile *file = (GFile *) data;
+
+  test_fail_size (file, G_MAXUINT);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -96,7 +111,8 @@ main (int argc, char **argv)
       test_images = g_build_filename (g_test_get_dir (G_TEST_DIST), "test-images/fail", NULL);
       dir = g_file_new_for_path (test_images);
       
-      add_test_for_all_images ("/pixbuf/fail", dir, dir, test_fail, NULL);
+      add_test_for_all_images ("/pixbuf/fail_tiny", dir, dir, test_fail_tiny, NULL);
+      add_test_for_all_images ("/pixbuf/fail_huge", dir, dir, test_fail_huge, NULL);
 
       g_object_unref (dir);
       g_free (test_images);
@@ -109,7 +125,8 @@ main (int argc, char **argv)
         {
           GFile *file = g_file_new_for_commandline_arg (argv[i]);
 
-          add_test_for_all_images ("/pixbuf/fail", NULL, file, test_fail, NULL);
+          add_test_for_all_images ("/pixbuf/fail_tiny", NULL, file, test_fail_tiny, NULL);
+          add_test_for_all_images ("/pixbuf/fail_huge", NULL, file, test_fail_huge, NULL);
 
           g_object_unref (file);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]