summaryrefslogtreecommitdiff
path: root/tests/test-common.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-10-12 07:22:11 +0200
committerBenjamin Otte <otte@redhat.com>2015-10-13 02:56:48 +0200
commit71b59cd4b5e8502b492892cffa1c3ef7f4182198 (patch)
treef764c6ce28e562178a1230ec4a452a8aaa58d42a /tests/test-common.c
parent337210def48ed85745ac292ff6cc3958570309ac (diff)
downloadgdk-pixbuf-71b59cd4b5e8502b492892cffa1c3ef7f4182198.tar.gz
tests: Make add_test_for_all_images() GFile based
Use that to make pixbuf-reftest accept arguments on the command line to specify a file to test.
Diffstat (limited to 'tests/test-common.c')
-rw-r--r--tests/test-common.c81
1 files changed, 65 insertions, 16 deletions
diff --git a/tests/test-common.c b/tests/test-common.c
index 0f4e4c01e..611a36f05 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -166,32 +166,81 @@ pixdata_equal (GdkPixbuf *test,
return TRUE;
}
+static int
+compare_files (gconstpointer a, gconstpointer b)
+{
+ GFile *file1 = G_FILE (a);
+ GFile *file2 = G_FILE (b);
+ char *uri1, *uri2;
+ int result;
+
+ uri1 = g_file_get_uri (file1);
+ uri2 = g_file_get_uri (file2);
+
+ result = strcmp (uri1, uri2);
+
+ g_free (uri1);
+ g_free (uri2);
+
+ return result;
+}
+
void
add_test_for_all_images (const gchar *prefix,
- const gchar *path,
+ GFile *base,
+ GFile *file,
GTestDataFunc test_func,
AddTestFunc add_test_func)
{
- GDir *dir;
- const gchar *name;
+ GFileEnumerator *enumerator;
+ GFileInfo *info;
+ GList *l, *files;
+ GError *error = NULL;
+
- dir = g_dir_open (path, 0, NULL);
- while ((name = g_dir_read_name (dir)) != NULL)
+ if (g_file_query_file_type (file, 0, NULL) != G_FILE_TYPE_DIRECTORY)
{
gchar *test_path;
- gchar *dir_path;
+ gchar *relative_path;
+
+ if (base)
+ relative_path = g_file_get_relative_path (base, file);
+ else
+ relative_path = g_file_get_path (file);
+
+ test_path = g_strconcat (prefix, "/", relative_path, NULL);
+
+ g_test_add_data_func_full (test_path, g_object_ref (file), test_func, g_object_unref);
+ return;
+ }
- test_path = g_strconcat (prefix, "/", name, NULL);
- dir_path = g_strconcat (path, "/", name, NULL);
- if (add_test_func == NULL || add_test_func (dir_path))
+
+ enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
+ g_assert_no_error (error);
+ files = NULL;
+
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
+ {
+ GFile *next_file = g_file_get_child (file, g_file_info_get_name (info));
+
+ if (add_test_func == NULL || add_test_func (next_file))
{
- if (g_file_test (dir_path, G_FILE_TEST_IS_DIR))
- add_test_for_all_images (test_path, dir_path, test_func, add_test_func);
- else
- g_test_add_data_func_full (test_path, g_strdup (dir_path), test_func, g_free);
+ files = g_list_prepend (files, g_object_ref (next_file));
}
- g_free (test_path);
- g_free (dir_path);
+
+ g_object_unref (next_file);
+ g_object_unref (info);
}
- g_dir_close (dir);
+
+ g_assert_no_error (error);
+ g_object_unref (enumerator);
+
+ files = g_list_sort (files, compare_files);
+
+ for (l = files; l; l = l->next)
+ {
+ add_test_for_all_images (prefix, base, l->data, test_func, add_test_func);
+ }
+
+ g_list_free_full (files, g_object_unref);
}