[telepathy-mission-control/master] mc-debug-server: create a new temporary keyring for each test
Jonny Lamb
jonny.lamb at collabora.co.uk
Mon Sep 14 11:09:17 PDT 2009
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
test/twisted/Makefile.am | 4 ++
test/twisted/mc-debug-server.c | 76 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 02f2a12..1b463c7 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -91,6 +91,10 @@ INCLUDES = \
-DMC_DISABLE_DEPRECATED \
-DLIBDIR="@libdir@" -DLIBVERSION="0"
+if ENABLE_GNOME_KEYRING
+INCLUDES += $(GNOME_KEYRING_CFLAGS)
+endif
+
TESTS =
TMPSUFFIX = foo
diff --git a/test/twisted/mc-debug-server.c b/test/twisted/mc-debug-server.c
index cc0316e..27aba03 100644
--- a/test/twisted/mc-debug-server.c
+++ b/test/twisted/mc-debug-server.c
@@ -23,6 +23,8 @@
*
*/
+#include "config.h"
+
#include <stdlib.h>
#include <unistd.h>
#include <glib.h>
@@ -33,10 +35,18 @@
#include <telepathy-glib/debug.h>
#include <telepathy-glib/util.h>
+#if ENABLE_GNOME_KEYRING
+#include <gnome-keyring.h>
+#endif
+
#include "mcd-service.h"
static McdService *mcd = NULL;
+#if ENABLE_GNOME_KEYRING
+static gchar *keyring_name = NULL;
+#endif
+
static gboolean
the_end (gpointer data)
{
@@ -123,9 +133,14 @@ main (int argc, char **argv)
int ret = 1;
GMainLoop *teardown_loop;
guint linger_time = 5;
+#if ENABLE_GNOME_KEYRING
+ GnomeKeyringResult result;
+#endif
g_type_init ();
+ g_set_application_name ("Mission Control regression tests");
+
mcd_debug_init ();
tp_debug_set_flags (g_getenv ("MC_TP_DEBUG"));
@@ -146,6 +161,50 @@ main (int argc, char **argv)
((TpProxy *) bus_daemon)->dbus_connection);
dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL);
+#if ENABLE_GNOME_KEYRING
+ while (TRUE)
+ {
+ keyring_name = g_strdup_printf ("mc-test-%u", g_random_int ());
+ result = gnome_keyring_create_sync (keyring_name, "");
+
+ if (result == GNOME_KEYRING_RESULT_OK)
+ {
+ break;
+ }
+ else if (result == GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS)
+ {
+ g_free (keyring_name);
+ continue;
+ }
+ else
+ {
+ g_free (keyring_name);
+ keyring_name = NULL;
+ break;
+ }
+ }
+
+ if (keyring_name != NULL)
+ {
+ if ((result = gnome_keyring_set_default_keyring_sync (keyring_name)) ==
+ GNOME_KEYRING_RESULT_OK)
+ {
+ g_debug ("Successfully set up temporary keyring %s for tests",
+ keyring_name);
+ }
+ else
+ {
+ g_warning ("Failed to set %s as the default kerying: %s",
+ keyring_name, gnome_keyring_result_to_message (result));
+ }
+ }
+ else
+ {
+ g_debug ("Failed to create keyring %s: %s", keyring_name,
+ gnome_keyring_result_to_message (result));
+ }
+#endif
+
mcd = mcd_service_new ();
/* Listen for suicide notification */
@@ -184,6 +243,23 @@ out:
dbus_shutdown ();
+#if ENABLE_GNOME_KEYRING
+ if (keyring_name != NULL)
+ {
+ if ((result = gnome_keyring_delete_sync (keyring_name)) ==
+ GNOME_KEYRING_RESULT_OK)
+ {
+ g_debug ("Successfully removed temporary keyring %s", keyring_name);
+ }
+ else
+ {
+ g_warning ("Failed to remove temporary keyring %s", keyring_name);
+ }
+
+ g_free (keyring_name);
+ }
+#endif
+
g_message ("Exiting with %d", ret);
return ret;
--
1.5.6.5
More information about the telepathy-commits
mailing list