From 8ec37be6b8417d6c23c9ca3e37eb15b3c10a1784 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 5 Oct 2012 15:59:12 +0100 Subject: [PATCH 4/4] self-handle test: test with a modern CM, not just an archaic one If we'd done this at the time, we wouldn't have broken SelfHandleChanged. Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55666 --- tests/dbus/Makefile.am | 5 ++++ tests/dbus/self-handle.c | 45 +++++++++++++++++++++++++---------- tests/lib/Makefile.am | 4 ++++ tests/lib/simple-conn.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am index 80766ff..78ce997 100644 --- a/tests/dbus/Makefile.am +++ b/tests/dbus/Makefile.am @@ -215,6 +215,11 @@ test_protocol_objects_LDADD = \ test_protocol_objects_SOURCES = protocol-objects.c test_self_handle_SOURCES = self-handle.c +test_self_handle_LDADD = \ + $(top_builddir)/tests/lib/libtp-glib-tests-internal.la \ + $(top_builddir)/telepathy-glib/libtelepathy-glib-internal.la \ + $(GLIB_LIBS) \ + $(NULL) test_self_presence_SOURCES = self-presence.c diff --git a/tests/dbus/self-handle.c b/tests/dbus/self-handle.c index 7d348e7..f08d641 100644 --- a/tests/dbus/self-handle.c +++ b/tests/dbus/self-handle.c @@ -35,7 +35,7 @@ typedef struct { static void setup (Fixture *f, - gconstpointer unused G_GNUC_UNUSED) + gconstpointer arg) { gboolean ok; @@ -45,7 +45,7 @@ setup (Fixture *f, tp_tests_object_new_static_class (TP_TESTS_TYPE_SIMPLE_CONNECTION, "account", "me@example.com", "protocol", "simple", - "break-0192-properties", TRUE, + "break-0192-properties", (!tp_strdiff (arg, "archaic")), NULL)); f->service_conn_as_base = TP_BASE_CONNECTION (f->service_conn); g_object_ref (f->service_conn_as_base); @@ -220,11 +220,12 @@ test_change_early (Fixture *f, static void test_change_inconveniently (Fixture *f, - gconstpointer unused G_GNUC_UNUSED) + gconstpointer arg) { TpHandle handle; TpContact *after; guint handle_times = 0, contact_times = 0, got_self_handle_times = 0; + guint got_all_times = 0; gboolean ok; GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 }; @@ -232,8 +233,18 @@ test_change_inconveniently (Fixture *f, G_CALLBACK (swapped_counter_cb), &handle_times); g_signal_connect_swapped (f->client_conn, "notify::self-contact", G_CALLBACK (swapped_counter_cb), &contact_times); - g_signal_connect_swapped (f->service_conn, "got-self-handle", - G_CALLBACK (swapped_counter_cb), &got_self_handle_times); + + if (!tp_strdiff (arg, "archaic")) + { + g_signal_connect_swapped (f->service_conn, "got-self-handle", + G_CALLBACK (swapped_counter_cb), &got_self_handle_times); + } + else + { + g_signal_connect_swapped (f->service_conn, + "got-all::" TP_IFACE_CONNECTION, + G_CALLBACK (swapped_counter_cb), &got_all_times); + } tp_proxy_prepare_async (f->client_conn, features, tp_tests_result_ready_cb, &f->result); @@ -252,11 +263,12 @@ test_change_inconveniently (Fixture *f, TP_CONNECTION_STATUS_CONNECTED, TP_CONNECTION_STATUS_REASON_REQUESTED); - /* run the main loop until just after GetSelfHandle is processed, to make - * sure the client first saw the old self handle */ - while (got_self_handle_times == 0) + /* run the main loop until just after GetSelfHandle or GetAll(Connection) + * is processed, to make sure the client first saw the old self handle */ + while (got_self_handle_times == 0 && got_all_times == 0) g_main_context_iteration (NULL, TRUE); + g_debug ("changing my own identifier to something else"); tp_tests_simple_connection_set_identifier (f->service_conn, "myself@example.org"); g_assert_cmpstr (tp_handle_inspect (f->contact_repo, @@ -291,11 +303,14 @@ test_change_inconveniently (Fixture *f, static void test_self_handle_fails (Fixture *f, - gconstpointer unused G_GNUC_UNUSED) + gconstpointer arg) { GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 }; gboolean ok; + /* This test assumes that spec 0.19.2 properties are unsupported. */ + g_assert_cmpstr (arg, ==, "archaic"); + tp_proxy_prepare_async (f->client_conn, features, tp_tests_result_ready_cb, &f->result); g_assert (f->result == NULL); @@ -351,11 +366,17 @@ main (int argc, g_test_add ("/self-handle", Fixture, NULL, setup_and_connect, test_self_handle, teardown); + g_test_add ("/self-handle/archaic", Fixture, "archaic", setup_and_connect, + test_self_handle, teardown); g_test_add ("/self-handle/change-early", Fixture, NULL, setup, test_change_early, teardown); - g_test_add ("/self-handle/change-inconveniently", Fixture, NULL, setup, - test_change_inconveniently, teardown); - g_test_add ("/self-handle/fails", Fixture, NULL, setup, + g_test_add ("/self-handle/change-early/archaic", Fixture, "archaic", setup, + test_change_early, teardown); + g_test_add ("/self-handle/change-inconveniently", Fixture, NULL, + setup, test_change_inconveniently, teardown); + g_test_add ("/self-handle/change-inconveniently/archaic", Fixture, + "archaic", setup, test_change_inconveniently, teardown); + g_test_add ("/self-handle/fails", Fixture, "archaic", setup, test_self_handle_fails, teardown); return g_test_run (); diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 4450896..246adec 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -95,6 +95,10 @@ AM_LDFLAGS = \ $(ERROR_LDFLAGS) \ $(NULL) +libtp_glib_tests_internal_la_CPPFLAGS = \ + -DTP_GLIB_TESTS_INTERNAL \ + $(NULL) + libtp_glib_tests_internal_la_LIBADD = \ $(DBUS_LIBS) \ $(GLIB_LIBS) \ diff --git a/tests/lib/simple-conn.c b/tests/lib/simple-conn.c index b57e607..ec0a75a 100644 --- a/tests/lib/simple-conn.c +++ b/tests/lib/simple-conn.c @@ -24,14 +24,20 @@ #include #include +#ifdef TP_GLIB_TESTS_INTERNAL +# include "telepathy-glib/dbus-properties-mixin-internal.h" +#endif + #include "textchan-null.h" #include "room-list-chan.h" #include "util.h" +static void props_iface_init (TpSvcDBusPropertiesClass *); static void conn_iface_init (TpSvcConnectionClass *); G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleConnection, tp_tests_simple_connection, TP_TYPE_BASE_CONNECTION, + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, props_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION, conn_iface_init)) /* type definition stuff */ @@ -47,6 +53,7 @@ enum enum { SIGNAL_GOT_SELF_HANDLE, + SIGNAL_GOT_ALL, N_SIGNALS }; @@ -344,6 +351,13 @@ tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 0); + + signals[SIGNAL_GOT_ALL] = g_signal_new ("got-all", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, + 0, + NULL, NULL, NULL, + G_TYPE_NONE, 0); } void @@ -507,3 +521,48 @@ conn_iface_init (TpSvcConnectionClass *iface) IMPLEMENT(,get_self_handle); #undef IMPLEMENT } + +#ifdef TP_GLIB_TESTS_INTERNAL +static void +get_all (TpSvcDBusProperties *iface, + const gchar *interface_name, + DBusGMethodInvocation *context) +{ + GHashTable *values = _tp_dbus_properties_mixin_get_all (G_OBJECT (iface), + interface_name); + GHashTableIter iter; + gpointer k, v; + + g_hash_table_iter_init (&iter, values); + + g_debug ("overridden GetAll:"); + + while (g_hash_table_iter_next (&iter, &k, &v)) + { + gchar *pretty = g_strdup_value_contents (v); + + g_debug ("\t%s = '%s'", (const gchar *) k, pretty); + g_free (pretty); + } + + g_debug ("\tend"); + + tp_svc_dbus_properties_return_from_get_all (context, values); + g_hash_table_unref (values); + g_signal_emit (iface, signals[SIGNAL_GOT_ALL], + g_quark_from_string (interface_name)); +} +#endif /* TP_GLIB_TESTS_INTERNAL */ + +static void +props_iface_init (TpSvcDBusPropertiesClass *iface) +{ +#ifdef TP_GLIB_TESTS_INTERNAL + +#define IMPLEMENT(x) \ + tp_svc_dbus_properties_implement_##x (iface, x) + IMPLEMENT (get_all); +#undef IMPLEMENT + +#endif /* TP_GLIB_TESTS_INTERNAL */ +} -- 1.7.10.4