diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2014-04-06 09:12:54 -0400 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-10 20:21:00 +0100 |
commit | aef682a020d242f4b1c91220274d6324e244fc97 (patch) | |
tree | 04117dc90f5516df6946794022fd39062ce491b6 | |
parent | 54357652c565811df4f64da58762098e1243005e (diff) |
Test: Stop implementing TSvcConnection for bug 19101 regression test
TpBaseConnection is about to stop implementing it and use
gdbus-codegen's skeleton instead.
-rw-r--r-- | tests/dbus/contacts-bug-19101.c | 58 | ||||
-rw-r--r-- | tests/lib/Makefile.am | 2 | ||||
-rw-r--r-- | tests/lib/bug-19101-conn.c | 68 | ||||
-rw-r--r-- | 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 1e43bc457..9bd58a9e3 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@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@example.com", + tp_tests_create_conn (TP_TESTS_TYPE_CONTACTS_CONNECTION, "me@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 72286f355..183d2ff9e 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 19b322a74..000000000 --- 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 23b670e36..000000000 --- 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__ */ |