[gdk-pixbuf] Convert pixbuf-threads test



commit dd3b97116bfaa4f44e42b724113abcaeb55c6666
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 19 13:50:01 2013 -0500

    Convert pixbuf-threads test
    
    Make this test use g_test_run, so it is compatible with using TAP.

 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 588c0f8..5eeb9dd 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 ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]