diff options
author | Iain Lane <iain@orangesquash.org.uk> | 2015-09-20 13:24:21 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-09-22 15:56:21 +0200 |
commit | e7f940102d40997f2e23a0589247cfb189dfaa98 (patch) | |
tree | c7404813bfe9b95f777a12a80ddac00f6e7423cc | |
parent | 3868cfe2abd45e32f7ba8abce1d603ed1842f45e (diff) | |
download | gdk-pixbuf-e7f940102d40997f2e23a0589247cfb189dfaa98.tar.gz |
Skip tests when we can't run them due to lack of memory
Check if we have failed due to insufficient memory and skip if
so.
https://bugzilla.gnome.org/show_bug.cgi?id=754387
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/cve-2015-4491.c | 4 | ||||
-rw-r--r-- | tests/pixbuf-scale.c | 25 | ||||
-rw-r--r-- | tests/test-common.c | 14 | ||||
-rw-r--r-- | tests/test-common.h | 1 |
5 files changed, 43 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index d5dca44e9..1f09711f1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,6 +65,8 @@ dist_installed_test_data = \ cve_2015_4491_SOURCES = \ cve-2015-4491.c \ + test-common.c \ + test-common.h \ resources.h \ resources.c \ $(NULL) diff --git a/tests/cve-2015-4491.c b/tests/cve-2015-4491.c index 34ba94f29..988cb495d 100644 --- a/tests/cve-2015-4491.c +++ b/tests/cve-2015-4491.c @@ -20,6 +20,8 @@ #include <gdk-pixbuf.h> +#include "test-common.h" + static void test_original (void) { @@ -28,6 +30,8 @@ test_original (void) GError* err = NULL; buf = gdk_pixbuf_new_from_resource_at_scale ("/test/resource/cve-2015-4491.bmp", size, size, FALSE, &err); + if (skip_if_insufficient_memory (&err)) + return; g_assert_no_error (err); diff --git a/tests/pixbuf-scale.c b/tests/pixbuf-scale.c index e2be5f586..60d0a2029 100644 --- a/tests/pixbuf-scale.c +++ b/tests/pixbuf-scale.c @@ -83,6 +83,9 @@ test_scale_down (gconstpointer data) path = g_test_get_filename (G_TEST_DIST, filename, NULL); ref = gdk_pixbuf_new_from_file (path, &error); + + if (skip_if_insufficient_memory (&error)) + return; g_assert_no_error (error); width = gdk_pixbuf_get_width (ref); @@ -111,10 +114,20 @@ test_add_alpha (gconstpointer data) path = g_test_get_filename (G_TEST_DIST, filename, NULL); ref = gdk_pixbuf_new_from_file (path, &error); + + if (skip_if_insufficient_memory (&error)) + return; g_assert_no_error (error); pixbuf = gdk_pixbuf_add_alpha (ref, FALSE, 0, 0, 0); - g_assert (pixbuf != NULL); + + if (pixbuf == NULL) + { + g_test_skip ("Couldn't add alpha to the image - your system probably lacks sufficient memory."); + g_object_unref (ref); + return; + } + g_object_unref (pixbuf); pixbuf = gdk_pixbuf_add_alpha (ref, TRUE, 0, 0, 255); @@ -141,11 +154,17 @@ test_rotate (gconstpointer data) path = g_test_get_filename (G_TEST_DIST, filename, NULL); ref = gdk_pixbuf_new_from_file (path, &error); + + if (skip_if_insufficient_memory (&error)) + return; g_assert_no_error (error); pixbuf = gdk_pixbuf_rotate_simple (ref, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); - g_assert (pixbuf != NULL); - g_object_unref (pixbuf); + + if (pixbuf == NULL) + g_test_skip ("Couldn't rotate the image - your system probably lacks sufficient memory."); + else + g_object_unref (pixbuf); g_object_unref (ref); } diff --git a/tests/test-common.c b/tests/test-common.c index 7071d4c31..0f70a8bfa 100644 --- a/tests/test-common.c +++ b/tests/test-common.c @@ -65,6 +65,20 @@ format_supported (const gchar *filename) } gboolean +skip_if_insufficient_memory (GError **err) +{ + if (*err && g_error_matches (*err, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY)) + { + g_test_skip ((*err)->message); + g_error_free (*err); + *err = NULL; + return TRUE; + } + + return FALSE; +} + +gboolean pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error) { if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2)) { diff --git a/tests/test-common.h b/tests/test-common.h index 56e4418d4..0514cd757 100644 --- a/tests/test-common.h +++ b/tests/test-common.h @@ -28,6 +28,7 @@ G_BEGIN_DECLS gboolean format_supported (const gchar *filename); +gboolean skip_if_insufficient_memory (GError **err); gboolean pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error); G_END_DECLS |