[gdk-pixbuf] tests: Add pixbuf-fail test
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] tests: Add pixbuf-fail test
- Date: Tue, 13 Oct 2015 01:03:19 +0000 (UTC)
commit 4a78a60d34e1a1b2f6651df26ba8d37394328c6e
Author: Benjamin Otte <otte redhat com>
Date: Mon Oct 12 11:37:13 2015 +0200
tests: Add pixbuf-fail test
pixbuf-fail goes into test-images/fail and loads all the images in
there, checking that a proper error happens during loading.
This is useful for invalid images that cause crashes: Put them in there
after they are fixed.
tests/Makefile.am | 7 +++
tests/pixbuf-fail.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ed1c25c..7cf9bff 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,6 +25,7 @@ noinst_PROGRAMS += \
test_programs = \
animation \
cve-2015-4491 \
+ pixbuf-fail \
pixbuf-icon-serialize \
pixbuf-randomly-modified \
pixbuf-threads \
@@ -89,6 +90,12 @@ pixbuf_dpi_SOURCES = \
test-common.h \
$(NULL)
+pixbuf_fail_SOURCES = \
+ pixbuf-fail.c \
+ test-common.c \
+ test-common.h \
+ $(NULL)
+
pixbuf_scale_SOURCES = \
pixbuf-scale.c \
test-common.c \
diff --git a/tests/pixbuf-fail.c b/tests/pixbuf-fail.c
new file mode 100644
index 0000000..0e37c2d
--- /dev/null
+++ b/tests/pixbuf-fail.c
@@ -0,0 +1,119 @@
+/* -*- Mode: C; c-basic-offset: 2; -*- */
+/* GdkPixbuf library - test loaders
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Otte
+ */
+
+#include "config.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "test-common.h"
+
+static void
+test_fail (gconstpointer data)
+{
+ 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");
+ return;
+ }
+
+ filename = g_file_get_path (file);
+
+ success = g_file_load_contents (file, NULL, (gchar **) &contents, &contents_length, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ content_type = g_content_type_guess (filename, contents, contents_length, NULL);
+ mime_type = g_content_type_get_mime_type (content_type);
+ g_assert (mime_type);
+
+ loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
+ g_assert_no_error (error);
+ g_assert (loader != NULL);
+
+ for (i = 0; i < contents_length; i++)
+ {
+ success = gdk_pixbuf_loader_write (loader, &contents[i], 1, &error);
+ if (!success)
+ {
+ g_assert (error);
+ g_clear_error (&error);
+ goto out;
+ }
+ g_assert_no_error (error);
+ }
+
+ success = gdk_pixbuf_loader_close (loader, &error);
+ g_assert (!success);
+ g_assert (error);
+ g_clear_error (&error);
+
+out:
+ g_free (mime_type);
+ g_free (content_type);
+ g_free (contents);
+ g_object_unref (loader);
+ g_free (filename);
+}
+
+int
+main (int argc, char **argv)
+{
+
+ g_test_init (&argc, &argv, NULL);
+
+ if (argc < 2)
+ {
+ GFile *dir;
+ gchar *test_images;
+
+ 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);
+
+ g_object_unref (dir);
+ g_free (test_images);
+ }
+ else
+ {
+ guint i;
+
+ for (i = 1; i < argc; i++)
+ {
+ GFile *file = g_file_new_for_commandline_arg (argv[i]);
+
+ add_test_for_all_images ("/pixbuf/fail", NULL, file, test_fail, NULL);
+
+ g_object_unref (file);
+ }
+ }
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]