diff options
author | Matthias Clasen <mclasen@redhat.com> | 2013-12-19 13:50:01 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-12-19 13:50:01 -0500 |
commit | dd3b97116bfaa4f44e42b724113abcaeb55c6666 (patch) | |
tree | 2bb8763f04a0db48a133548331eaf113f76f3f2b /tests/pixbuf-threads.c | |
parent | 5123cd38d218cf048ee7c02bf1ad5a99746af080 (diff) | |
download | gdk-pixbuf-dd3b97116bfaa4f44e42b724113abcaeb55c6666.tar.gz |
Convert pixbuf-threads test
Make this test use g_test_run, so it is compatible with using TAP.
Diffstat (limited to 'tests/pixbuf-threads.c')
-rw-r--r-- | tests/pixbuf-threads.c | 113 |
1 files changed, 38 insertions, 75 deletions
diff --git a/tests/pixbuf-threads.c b/tests/pixbuf-threads.c index 588c0f88b..5eeb9dd7e 100644 --- a/tests/pixbuf-threads.c +++ b/tests/pixbuf-threads.c @@ -18,116 +18,79 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ -#include "config.h" #include "gdk-pixbuf/gdk-pixbuf.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static gboolean verbose = FALSE; static void -load_image (gpointer data, +load_image (gpointer data, gpointer user_data) { gchar *filename = data; + const gchar *path; FILE *file; int nbytes; - guchar buf[1024]; - size_t bufsize = 1024; + guchar buffer[1024]; GdkPixbufLoader *loader; GError *error = NULL; - GThread *self; - self = g_thread_self (); loader = gdk_pixbuf_loader_new (); + path = g_test_get_filename (G_TEST_DIST, "test-images", filename, NULL); - file = fopen (filename, "r"); - if (!file) - { - g_warning ("failed to open %s\n", filename); - g_assert_not_reached (); - } + g_test_message ("reading %s", path); + file = fopen (path, "r"); + g_assert (file != NULL); - if (verbose) g_print ("%p start image %s\n", self, filename); while (!feof (file)) { - nbytes = fread (buf, 1, bufsize, file); - if (!gdk_pixbuf_loader_write (loader, buf, nbytes, &error)) - { - g_warning ("Error writing %s to loader: %s", filename, error->message); - g_error_free (error); - error = NULL; - break; - } - if (verbose) g_print ("%p read %d bytes\n", self, nbytes); - + nbytes = fread (buffer, 1, sizeof (buffer), file); + gdk_pixbuf_loader_write (loader, buffer, nbytes, &error); + g_assert_no_error (error); g_thread_yield (); } fclose (file); - if (verbose) g_print ("%p finish image %s\n", self, filename); - - if (!gdk_pixbuf_loader_close (loader, &error)) - { - g_warning ("Error closing loader for %s: %s", filename, error->message); - g_error_free (error); - } + gdk_pixbuf_loader_close (loader, &error); + g_assert_no_error (error); g_object_unref (loader); } -int -main (int argc, char **argv) +static void +test_threads (void) { - 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 (g_getenv ("ITERATIONS")) - iterations = atoi (g_getenv ("ITERATIONS")); - else - iterations = 1000; - - g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); - - start = 1; - if (argc > 1 && strcmp (argv[1], "--verbose") == 0) - { - verbose = TRUE; - start = 2; - } + gint iterations; + gint i; pool = g_thread_pool_new (load_image, NULL, 20, FALSE, NULL); - l = 0; - - for (i = start; i < argc; i++) - g_ptr_array_add (files, argv[i]); + if (g_test_thorough ()) + iterations = 100; + else + iterations = 1; - if (files->len == 0) + for (i = 0; i < iterations; i++) { - 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_thread_pool_push (pool, "valid_jpeg_test", NULL); + g_thread_pool_push (pool, "valid_png_test", NULL); + g_thread_pool_push (pool, "valid_gif_test", NULL); + g_thread_pool_push (pool, "valid_bmp_test", NULL); + g_thread_pool_push (pool, "valid_jpeg_progressive_test", NULL); + g_thread_pool_push (pool, "valid_xpm_test", NULL); + g_thread_pool_push (pool, "valid_ras_test", NULL); + g_thread_pool_push (pool, "valid_tga_test", NULL); + g_thread_pool_push (pool, "valid_tiff1_test", NULL); } - g_assert_cmpint (files->len, >, 0); + g_thread_pool_free (pool, FALSE, TRUE); +} - 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)); - } - } +int +main (int argc, char **argv) +{ + g_test_init (&argc, &argv, NULL); - g_thread_pool_free (pool, FALSE, TRUE); + g_test_add_func ("/pixbuf/threads", test_threads); - return 0; + return g_test_run (); } |