summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-06-24 16:37:57 +0100
committerColin Walters <walters@verbum.org>2013-06-24 16:37:57 +0100
commit67b5737712ea43c54ac31a19f349cef74aa2287f (patch)
tree2d436be0eea7c950e3cfb17f914fdfdc4d1a5213
parentb4049c42255086280404ab95d44e64b19d6650a9 (diff)
downloadgdk-pixbuf-67b5737712ea43c54ac31a19f349cef74aa2287f.tar.gz
tests: Fix up pixbuf tests to know how to find data files
These tests were broken by: 8ec55ff29e0626a05a3aa9d92060e28767ee142f Previously we were relying on hand-written .test files which used sh -c and wildcard expansion, but with modern GLib we can just use g_test_get_dir() to find the datadir relative to our binary path.
-rw-r--r--tests/pixbuf-randomly-modified.c32
-rw-r--r--tests/pixbuf-randomly-modified.test.in3
-rw-r--r--tests/pixbuf-threads.c49
-rw-r--r--tests/pixbuf-threads.test.in3
4 files changed, 52 insertions, 35 deletions
diff --git a/tests/pixbuf-randomly-modified.c b/tests/pixbuf-randomly-modified.c
index 83dd2ea70..8dd176b1f 100644
--- a/tests/pixbuf-randomly-modified.c
+++ b/tests/pixbuf-randomly-modified.c
@@ -98,18 +98,18 @@ int
main (int argc, char **argv)
{
int seed, i;
+ GError *err = NULL;
gboolean got_seed = FALSE;
GPtrArray *files = g_ptr_array_new ();
int l, iterations;
+ g_test_init (&argc, &argv, NULL);
+
if (g_getenv ("ITERATIONS"))
iterations = atoi (g_getenv ("ITERATIONS"));
else
iterations = 1000;
- if (argc == 1)
- usage ();
-
seed = time (NULL);
for (i = 1; i < argc; ++i)
@@ -142,17 +142,33 @@ main (int argc, char **argv)
#endif
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+ if (files->len == 0)
+ {
+ const gchar *name;
+ const gchar *distdir = g_test_get_dir (G_TEST_DIST);
+ gchar *test_images_dir = g_build_filename (distdir, "test-images", NULL);
+ GDir *dir = g_dir_open (test_images_dir, 0, &err);
+ if (!dir)
+ goto out;
+ while ((name = g_dir_read_name (dir)) != NULL)
+ g_ptr_array_add (files, g_build_filename (test_images_dir, name, NULL));
+ g_dir_close (dir);
+ g_free (test_images_dir);
+ }
+
+ g_assert_cmpint (files->len, >, 0);
+
for (l = 0; l < iterations; l++)
for (i = 0; i < files->len; ++i)
{
gchar *contents;
gsize size;
- GError *err = NULL;
fflush (stdout);
if (!g_file_get_contents (files->pdata[i], &contents, &size, &err))
{
- g_warning ("%s: error: %s\n", (char *)files->pdata[i], err->message);
+ g_prefix_error (&err, "Reading %s: ", (char *)files->pdata[i]);
+ goto out;
}
else
{
@@ -166,5 +182,11 @@ main (int argc, char **argv)
}
}
+ out:
+ if (err)
+ {
+ g_printerr ("%s\n", err->message);
+ return 1;
+ }
return 0;
}
diff --git a/tests/pixbuf-randomly-modified.test.in b/tests/pixbuf-randomly-modified.test.in
deleted file mode 100644
index 05a6165cd..000000000
--- a/tests/pixbuf-randomly-modified.test.in
+++ /dev/null
@@ -1,3 +0,0 @@
-[Test]
-Exec=sh -c "env ITERATIONS=10 @pkglibexecdir@/installed-tests/pixbuf-randomly-modified @pkglibexecdir@/installed-tests/test-images/*"
-Type=session
diff --git a/tests/pixbuf-threads.c b/tests/pixbuf-threads.c
index 268b01fb8..8af6acfda 100644
--- a/tests/pixbuf-threads.c
+++ b/tests/pixbuf-threads.c
@@ -78,20 +78,16 @@ load_image (gpointer data,
g_object_unref (loader);
}
-static void
-usage (void)
-{
- g_print ("usage: pixbuf-threads [--verbose] <files>\n");
- exit (EXIT_FAILURE);
-}
-
int
main (int argc, char **argv)
{
int i, start;
GThreadPool *pool;
+ GPtrArray *files = g_ptr_array_new_with_free_func ((GDestroyNotify)g_free);
int l, iterations;
+ g_test_init (&argc, &argv, NULL);
+
#if !GLIB_CHECK_VERSION (2, 35, 3)
g_type_init ();
#endif
@@ -108,11 +104,8 @@ main (int argc, char **argv)
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
- if (argc == 1)
- usage();
-
start = 1;
- if (strcmp (argv[1], "--verbose") == 0)
+ if (argc > 1 && strcmp (argv[1], "--verbose") == 0)
{
verbose = TRUE;
start = 2;
@@ -121,19 +114,27 @@ main (int argc, char **argv)
pool = g_thread_pool_new (load_image, NULL, 20, FALSE, NULL);
l = 0;
- i = start;
- while (1) {
- i++;
- if (i == argc)
- {
- i = start;
- l++;
- }
- g_thread_pool_push (pool, argv[i], NULL);
- if (verbose) g_print ("now %d items pending\n", g_thread_pool_unprocessed (pool));
- if (l == iterations)
- break;
- }
+
+ for (i = start; i < argc; i++)
+ g_ptr_array_add (files, argv[i]);
+
+ if (files->len == 0)
+ {
+ const gchar *distdir = g_test_get_dir (G_TEST_DIST);
+ g_ptr_array_add (files, g_build_filename (distdir, "test-images", "valid_jpeg_progressive_test", NULL));
+ g_ptr_array_add (files, g_build_filename (distdir, "test-images", "valid_png_test", NULL));
+ }
+
+ g_assert_cmpint (files->len, >, 0);
+
+ for (l = 0; l < iterations; l++)
+ {
+ for (i = 0; i < files->len; i++)
+ {
+ g_thread_pool_push (pool, files->pdata[i], NULL);
+ if (verbose) g_print ("now %d items pending\n", g_thread_pool_unprocessed (pool));
+ }
+ }
g_thread_pool_free (pool, FALSE, TRUE);
diff --git a/tests/pixbuf-threads.test.in b/tests/pixbuf-threads.test.in
deleted file mode 100644
index dbe2a99b2..000000000
--- a/tests/pixbuf-threads.test.in
+++ /dev/null
@@ -1,3 +0,0 @@
-[Test]
-Exec=sh -c "env ITERATIONS=50 @pkglibexecdir@/installed-tests/pixbuf-threads @pkglibexecdir@/installed-tests/test-images/{valid_jpeg_progressive_test,valid_png_test}"
-Type=session