[next] telepathy-glib: Test: Stop implementing TSvcConnection for bug 19101 regression test

Simon McVittie smcv at kemper.freedesktop.org
Wed May 7 02:18:22 PDT 2014


Module: telepathy-glib
Branch: next
Commit: af41cbd3511d91ef57b4a10a43c0ba1335db89ab
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=af41cbd3511d91ef57b4a10a43c0ba1335db89ab

Author: Xavier Claessens <xavier.claessens at collabora.com>
Date:   Sun Apr  6 09:12:54 2014 -0400

Test: Stop implementing TSvcConnection for bug 19101 regression test

TpBaseConnection is about to stop implementing it and use
gdbus-codegen's skeleton instead.

Reviewed-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77189

---

 tests/dbus/contacts-bug-19101.c |   58 +++++++++++++++++++++++++++++++--
 tests/lib/Makefile.am           |    2 --
 tests/lib/bug-19101-conn.c      |   68 ---------------------------------------
 tests/lib/bug-19101-conn.h      |   51 -----------------------------
 4 files changed, 56 insertions(+), 123 deletions(-)

diff --git a/tests/dbus/contacts-bug-19101.c b/tests/dbus/contacts-bug-19101.c
index 1e43bc4..9bd58a9 100644
--- a/tests/dbus/contacts-bug-19101.c
+++ b/tests/dbus/contacts-bug-19101.c
@@ -7,7 +7,7 @@
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/debug.h>
 
-#include "tests/lib/bug-19101-conn.h"
+#include "tests/lib/contacts-conn.h"
 #include "tests/lib/debug.h"
 #include "tests/lib/myassert.h"
 #include "tests/lib/util.h"
@@ -15,8 +15,56 @@
 typedef struct {
     GMainLoop *loop;
     GError *error /* initialized to 0 */;
+    guint serial;
 } Result;
 
+static GDBusMessage *
+filter_cb (GDBusConnection *connection,
+    GDBusMessage *message,
+    gboolean incoming,
+    gpointer user_data)
+{
+  Result *r = user_data;
+
+  /* We are only interested in outgoing messages */
+  if (incoming)
+    return message;
+
+  if (!tp_strdiff (g_dbus_message_get_member (message), "GetContactByID"))
+    {
+      /* Remember the serial of the message so we can catch the reply */
+      g_assert (r->serial == 0);
+      r->serial = g_dbus_message_get_serial (message);
+    }
+  else if (r->serial != 0 &&
+      g_dbus_message_get_message_type (message) ==
+          G_DBUS_MESSAGE_TYPE_METHOD_RETURN &&
+      g_dbus_message_get_reply_serial (message) == r->serial)
+    {
+      GDBusMessage *tmp;
+      GVariant *body;
+      TpHandle handle;
+      GError *error = NULL;
+
+      /* Replace message by a copy to be able to modify it */
+      tmp = g_dbus_message_copy (message, &error);
+      g_assert_no_error (error);
+      g_object_unref (message);
+      message = tmp;
+
+      /* Replace body's asv to an empty one */
+      body = g_dbus_message_get_body (message);
+      g_variant_get (body, "(ua{sv})", &handle, NULL);
+      g_dbus_message_set_body (message,
+          g_variant_new ("(u at a{sv})", handle,
+              g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0)));
+
+      r->serial = 0;
+    }
+
+  return message;
+}
+
 static void
 by_id_cb (GObject *source,
     GAsyncResult *result,
@@ -37,6 +85,11 @@ static void
 test_by_id (TpConnection *client_conn)
 {
   Result result = { g_main_loop_new (NULL, FALSE) };
+  GDBusConnection *dbus_connection = tp_proxy_get_dbus_connection (client_conn);
+  guint filter_id;
+
+  filter_id = g_dbus_connection_add_filter (dbus_connection,
+      filter_cb, &result, NULL);
 
   tp_connection_dup_contact_by_id_async (client_conn,
       "Alice", NULL, by_id_cb, &result);
@@ -49,6 +102,7 @@ test_by_id (TpConnection *client_conn)
   /* clean up */
   g_main_loop_unref (result.loop);
   g_error_free (result.error);
+  g_dbus_connection_remove_filter (dbus_connection, filter_id);
 }
 
 int
@@ -69,7 +123,7 @@ main (int argc,
   test_dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
   g_test_dbus_up (test_dbus);
 
-  tp_tests_create_conn (TP_TESTS_TYPE_BUG19101_CONNECTION, "me at example.com",
+  tp_tests_create_conn (TP_TESTS_TYPE_CONTACTS_CONNECTION, "me at example.com",
       TRUE, &service_conn_as_base, &client_conn);
   service_conn = TP_TESTS_CONTACTS_CONNECTION (service_conn_as_base);
 
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 72286f3..183d2ff 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -15,8 +15,6 @@ noinst_LTLIBRARIES = \
     $(NULL)
 
 libtp_glib_tests_la_SOURCES = \
-    bug-19101-conn.c \
-    bug-19101-conn.h \
     broken-client-types-conn.c \
     broken-client-types-conn.h \
     contacts-conn.c \
diff --git a/tests/lib/bug-19101-conn.c b/tests/lib/bug-19101-conn.c
deleted file mode 100644
index 19b322a..0000000
--- a/tests/lib/bug-19101-conn.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * bug-19101-conn.c - a broken connection to reproduce bug #19101
- *
- * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) 2008 Nokia Corporation
- *
- * Copying and distribution of this file, with or without modification,
- * are permitted in any medium without royalty provided the copyright
- * notice and this notice are preserved.
- */
-
-#include "config.h"
-
-#include "bug-19101-conn.h"
-
-#include <telepathy-glib/telepathy-glib.h>
-#include <telepathy-glib/telepathy-glib-dbus.h>
-
-#include "debug.h"
-
-static void conn_iface_init (TpSvcConnectionClass *klass);
-
-G_DEFINE_TYPE_WITH_CODE (TpTestsBug19101Connection,
-    tp_tests_bug19101_connection, TP_TESTS_TYPE_CONTACTS_CONNECTION,
-    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION, conn_iface_init))
-
-static void
-tp_tests_bug19101_connection_init (TpTestsBug19101Connection *self)
-{
-}
-
-static void
-tp_tests_bug19101_connection_class_init (TpTestsBug19101ConnectionClass *klass)
-{
-}
-
-/* A broken implementation of GetContactByID, which returns an empty dict
- * of attributes for each id.
- */
-static void
-tp_tests_bug19101_connection_get_contact_by_id (
-    TpSvcConnection *iface,
-    const gchar *id,
-    const char **interfaces,
-    GDBusMethodInvocation *context)
-{
-  TpBaseConnection *base_conn = TP_BASE_CONNECTION (iface);
-  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
-      base_conn, TP_ENTITY_TYPE_CONTACT);
-  TpHandle handle;
-  GHashTable *table;
-
-  handle = tp_handle_ensure (contact_repo, id, NULL, NULL);
-  table = g_hash_table_new (NULL, NULL);
-
-  tp_svc_connection_return_from_get_contact_by_id (context, handle, table);
-
-  g_hash_table_unref (table);
-}
-
-static void
-conn_iface_init (TpSvcConnectionClass *klass)
-{
-#define IMPLEMENT(x) tp_svc_connection_implement_##x ( \
-    klass, tp_tests_bug19101_connection_##x)
-  IMPLEMENT(get_contact_by_id);
-#undef IMPLEMENT
-}
diff --git a/tests/lib/bug-19101-conn.h b/tests/lib/bug-19101-conn.h
deleted file mode 100644
index 23b670e..0000000
--- a/tests/lib/bug-19101-conn.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * bug-19101-conn.h - header for a broken connection to reproduce bug #19101
- *
- * Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) 2007-2008 Nokia Corporation
- *
- * Copying and distribution of this file, with or without modification,
- * are permitted in any medium without royalty provided the copyright
- * notice and this notice are preserved.
- */
-
-#ifndef __TP_TESTS_BUG19101_CONN_H__
-#define __TP_TESTS_BUG19101_CONN_H__
-
-#include "contacts-conn.h"
-
-G_BEGIN_DECLS
-
-typedef struct _TpTestsBug19101Connection TpTestsBug19101Connection;
-typedef struct _TpTestsBug19101ConnectionClass TpTestsBug19101ConnectionClass;
-
-struct _TpTestsBug19101ConnectionClass {
-    TpTestsContactsConnectionClass parent_class;
-};
-
-struct _TpTestsBug19101Connection {
-    TpTestsContactsConnection parent;
-};
-
-GType tp_tests_bug19101_connection_get_type (void);
-
-/* TYPE MACROS */
-#define TP_TESTS_TYPE_BUG19101_CONNECTION \
-  (tp_tests_bug19101_connection_get_type ())
-#define BUG_19101_CONNECTION(obj) \
-  (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_BUG19101_CONNECTION, \
-                              TpTestsBug19101Connection))
-#define BUG_19101_CONNECTION_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_BUG19101_CONNECTION, \
-                           TpTestsBug19101ConnectionClass))
-#define BUG_19101_IS_CONNECTION(obj) \
-  (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_BUG19101_CONNECTION))
-#define BUG_19101_IS_CONNECTION_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_BUG19101_CONNECTION))
-#define BUG_19101_CONNECTION_GET_CLASS(obj) \
-  (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_BUG19101_CONNECTION, \
-                              TpTestsBug19101ConnectionClass))
-
-G_END_DECLS
-
-#endif /* #ifndef __TP_TESTS_BUG19101_CONN_H__ */



More information about the telepathy-commits mailing list