summaryrefslogtreecommitdiff
path: root/egg
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2011-11-06 13:38:19 +0100
committerStef Walter <stefw@collabora.co.uk>2011-11-06 13:38:51 +0100
commite670fe5645eb43fb48c67e566ac7c0fb85dd37f8 (patch)
tree688d8ff77ea6924456f18c05c0cd6655a37b80b4 /egg
parent38031d943e6cc2b7c12dc36d5792830713f140f4 (diff)
downloadlibsecret-e670fe5645eb43fb48c67e566ac7c0fb85dd37f8.tar.gz
Fix for deprecations in glib 2.31.0
Diffstat (limited to 'egg')
-rw-r--r--egg/egg-libgcrypt.c6
-rw-r--r--egg/egg-testing.c122
-rw-r--r--egg/egg-testing.h4
3 files changed, 70 insertions, 62 deletions
diff --git a/egg/egg-libgcrypt.c b/egg/egg-libgcrypt.c
index e5b3f55..a198f4d 100644
--- a/egg/egg-libgcrypt.c
+++ b/egg/egg-libgcrypt.c
@@ -56,14 +56,16 @@ fatal_handler (gpointer unused, int unknown, const gchar *msg)
static int
glib_thread_mutex_init (void **lock)
{
- *lock = g_mutex_new ();
+ *lock = g_slice_new (GMutex);
+ g_mutex_init (*lock);
return 0;
}
static int
glib_thread_mutex_destroy (void **lock)
{
- g_mutex_free (*lock);
+ g_mutex_clear (*lock);
+ g_slice_free (GMutex, *lock);
return 0;
}
diff --git a/egg/egg-testing.c b/egg/egg-testing.c
index 0235ac0..91cd77c 100644
--- a/egg/egg-testing.c
+++ b/egg/egg-testing.c
@@ -25,14 +25,13 @@
#include "egg-testing.h"
+#include <glib-object.h>
+
+#include <valgrind/valgrind.h>
+
#include <errno.h>
#include <unistd.h>
-static GCond *wait_condition = NULL;
-static GCond *wait_start = NULL;
-static GMutex *wait_mutex = NULL;
-static gboolean wait_waiting = FALSE;
-
static const char HEXC[] = "0123456789ABCDEF";
static gchar*
@@ -79,79 +78,84 @@ egg_assertion_message_cmpmem (const char *domain,
g_free (s);
}
+static void (*wait_stop_impl) (void);
+static gboolean (*wait_until_impl) (int timeout);
+
void
egg_test_wait_stop (void)
{
- GTimeVal tv;
-
- g_get_current_time (&tv);
- g_time_val_add (&tv, 1000);
-
- g_assert (wait_mutex);
- g_assert (wait_condition);
- g_mutex_lock (wait_mutex);
- if (!wait_waiting)
- g_cond_timed_wait (wait_start, wait_mutex, &tv);
- g_assert (wait_waiting);
- g_cond_broadcast (wait_condition);
- g_mutex_unlock (wait_mutex);
+ g_assert (wait_stop_impl != NULL);
+ (wait_stop_impl) ();
}
gboolean
egg_test_wait_until (int timeout)
{
- GTimeVal tv;
- gboolean ret;
-
- g_get_current_time (&tv);
- g_time_val_add (&tv, timeout * 1000);
-
- g_assert (wait_mutex);
- g_assert (wait_condition);
- g_mutex_lock (wait_mutex);
- g_assert (!wait_waiting);
- wait_waiting = TRUE;
- g_cond_broadcast (wait_start);
- ret = g_cond_timed_wait (wait_condition, wait_mutex, &tv);
- g_assert (wait_waiting);
- wait_waiting = FALSE;
- g_mutex_unlock (wait_mutex);
+ g_assert (wait_until_impl != NULL);
+ return (wait_until_impl) (timeout);
+}
- return ret;
+static GMainLoop *wait_loop = NULL;
+
+static void
+loop_wait_stop (void)
+{
+ g_assert (wait_loop != NULL);
+ g_main_loop_quit (wait_loop);
}
-static gpointer
-testing_thread (gpointer loop)
+static gboolean
+on_loop_wait_timeout (gpointer data)
{
- /* Must have been defined by the test including this file */
- gint ret = g_test_run ();
- g_main_loop_quit (loop);
- return GINT_TO_POINTER (ret);
+ gboolean *timed_out = data;
+ *timed_out = TRUE;
+
+ g_assert (wait_loop != NULL);
+ g_main_loop_quit (wait_loop);
+
+ return TRUE; /* we remove this source later */
}
-gint
-egg_tests_run_in_thread_with_loop (void)
+static gboolean
+loop_wait_until (int timeout)
{
- GThread *thread;
- GMainLoop *loop;
- gpointer ret;
+ gboolean ret = FALSE;
+ gboolean timed_out = FALSE;
+ guint source;
- g_thread_init (NULL);
+ g_assert (wait_loop == NULL);
+ wait_loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
- loop = g_main_loop_new (NULL, FALSE);
- wait_condition = g_cond_new ();
- wait_start = g_cond_new ();
- wait_mutex = g_mutex_new ();
+ source = g_timeout_add (timeout, on_loop_wait_timeout, &timed_out);
- thread = g_thread_create (testing_thread, loop, TRUE, NULL);
- g_assert (thread);
+ g_main_loop_run (wait_loop);
- g_main_loop_run (loop);
- ret = g_thread_join (thread);
- g_main_loop_unref (loop);
+ if (timed_out) {
+ g_source_remove (source);
+ ret = FALSE;
+ } else {
+ ret = TRUE;
+ }
+
+ g_main_loop_unref (wait_loop);
+ wait_loop = NULL;
+ return ret;
+}
- g_cond_free (wait_condition);
- g_mutex_free (wait_mutex);
+gint
+egg_tests_run_with_loop (void)
+{
+ gint ret;
- return GPOINTER_TO_INT (ret);
+ wait_stop_impl = loop_wait_stop;
+ wait_until_impl = loop_wait_until;
+
+ ret = g_test_run ();
+
+ wait_stop_impl = NULL;
+ wait_until_impl = NULL;
+
+ while (g_main_context_iteration (NULL, FALSE));
+
+ return ret;
}
diff --git a/egg/egg-testing.h b/egg/egg-testing.h
index f6b7a0e..0fd23b9 100644
--- a/egg/egg-testing.h
+++ b/egg/egg-testing.h
@@ -45,8 +45,10 @@ void egg_assertion_message_cmpmem (const char *domain, const char *
void egg_test_wait_stop (void);
+#define egg_test_wait() g_assert (egg_test_wait_until (20000) != FALSE)
+
gboolean egg_test_wait_until (int timeout);
-gint egg_tests_run_in_thread_with_loop (void);
+gint egg_tests_run_with_loop (void);
#endif /* EGG_DH_H_ */