[gdk-pixbuf: 3/5] tests: Don't depend on mime type detection without GDK_PIXBUF_USE_GIO_MIME
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf: 3/5] tests: Don't depend on mime type detection without GDK_PIXBUF_USE_GIO_MIME
- Date: Tue, 11 Dec 2018 15:44:31 +0000 (UTC)
commit 873dbd1ab75076d3241a17ed3ee101b75d21be76
Author: Christoph Reiter <reiter christoph gmail com>
Date: Tue Dec 11 13:50:01 2018 +0100
tests: Don't depend on mime type detection without GDK_PIXBUF_USE_GIO_MIME
When building without GDK_PIXBUF_USE_GIO_MIME detect the format based on the
fill extension and not the mime type.
This makes these tests pass on Windows.
tests/pixbuf-fail.c | 30 ++++++++++++++++++++++--------
tests/pixbuf-reftest.c | 29 ++++++++++++++++++++++-------
tests/test-common.c | 10 +++++++++-
tests/test-common.h | 1 +
4 files changed, 54 insertions(+), 16 deletions(-)
---
diff --git a/tests/pixbuf-fail.c b/tests/pixbuf-fail.c
index 322d5f6f2..711ff9018 100644
--- a/tests/pixbuf-fail.c
+++ b/tests/pixbuf-fail.c
@@ -33,7 +33,7 @@ test_fail_size (GFile *file,
GError *error = NULL;
guchar *contents;
gsize i, contents_length;
- char *filename, *content_type, *mime_type;
+ char *filename;
gboolean success;
if (!file_supported (file))
@@ -48,11 +48,27 @@ test_fail_size (GFile *file,
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);
+#ifdef GDK_PIXBUF_USE_GIO_MIME
+ {
+ char *mime_type, *content_type;
+
+ 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_free (mime_type);
+ g_free (content_type);
+ }
+#else
+ {
+ char *format;
+
+ success = find_format (filename, &format);
+ g_assert_true (success);
+ loader = gdk_pixbuf_loader_new_with_type (format, &error);
+ g_free (format);
+ }
+#endif
g_assert_no_error (error);
g_assert (loader != NULL);
@@ -74,8 +90,6 @@ test_fail_size (GFile *file,
g_clear_error (&error);
out:
- g_free (mime_type);
- g_free (content_type);
g_free (contents);
g_object_unref (loader);
g_free (filename);
diff --git a/tests/pixbuf-reftest.c b/tests/pixbuf-reftest.c
index caf841c6c..ac0bb2d46 100644
--- a/tests/pixbuf-reftest.c
+++ b/tests/pixbuf-reftest.c
@@ -138,7 +138,7 @@ test_reftest (gconstpointer data)
GInputStream *stream;
guchar *contents;
gsize i, contents_length;
- char *filename, *content_type, *mime_type;
+ char *filename;
gboolean success;
file = G_FILE (data);
@@ -163,11 +163,28 @@ test_reftest (gconstpointer data)
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);
+#ifdef GDK_PIXBUF_USE_GIO_MIME
+ {
+ char *mime_type, *content_type;
+
+ 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_free (mime_type);
+ g_free (content_type);
+ }
+#else
+ {
+ char *format;
+
+ success = find_format (filename, &format);
+ g_assert_true (success);
+ loader = gdk_pixbuf_loader_new_with_type (format, &error);
+ g_free (format);
+ }
+#endif
- loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
g_assert_no_error (error);
g_assert (loader != NULL);
g_signal_connect (loader, "size-prepared", G_CALLBACK (loader_size_prepared), &loaded);
@@ -191,8 +208,6 @@ test_reftest (gconstpointer data)
g_assert_no_error (error);
g_assert (success);
- g_free (mime_type);
- g_free (content_type);
g_free (contents);
g_object_unref (loaded);
g_object_unref (loader);
diff --git a/tests/test-common.c b/tests/test-common.c
index 2f4f3a411..8ce15dd08 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -85,7 +85,7 @@ make_rg (int width, int height)
}
gboolean
-format_supported (const gchar *filename)
+find_format (const gchar *filename, gchar **found_format)
{
GSList *formats, *l;
gboolean retval;
@@ -102,6 +102,8 @@ format_supported (const gchar *filename)
{
if (g_str_has_suffix (filename, extensions[i]))
{
+ if (found_format != NULL)
+ *found_format = gdk_pixbuf_format_get_name (format);
retval = TRUE;
break;
}
@@ -116,6 +118,12 @@ format_supported (const gchar *filename)
return retval;
}
+gboolean
+format_supported (const gchar *filename)
+{
+ return find_format(filename, NULL);
+}
+
gboolean
file_supported (GFile *file)
{
diff --git a/tests/test-common.h b/tests/test-common.h
index 8e7f676b0..dbe07e9e2 100644
--- a/tests/test-common.h
+++ b/tests/test-common.h
@@ -31,6 +31,7 @@ typedef gboolean (* AddTestFunc) (GFile *file);
gboolean format_supported (const gchar *filename);
gboolean file_supported (GFile *file);
+gboolean find_format (const gchar *filename, gchar **found_format);
gboolean skip_if_insufficient_memory (GError **err);
gboolean pixdata_equal (GdkPixbuf *test, GdkPixbuf *ref, GError **error);
GdkPixbuf *make_checkerboard (int width, int height);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]