diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-02-10 19:05:52 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-02-10 19:05:52 +0000 |
commit | 6fe39014b97f5a2bb647d92e201dabaade44dbd6 (patch) | |
tree | e8aecd37da5a6c571ffa899a3da01fc79e7e3503 | |
parent | 3352eee4953d7429851883865232e299badcc6d2 (diff) |
Add a feature test for the self handle (fd.o#17519)
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | tests/dbus/Makefile.am | 3 | ||||
-rw-r--r-- | tests/dbus/self-handle.c | 144 | ||||
-rw-r--r-- | tests/lib/simple-conn.c | 16 | ||||
-rw-r--r-- | tests/lib/simple-conn.h | 3 |
5 files changed, 167 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 38b3f9d1b..577b35fc6 100644 --- a/.gitignore +++ b/.gitignore @@ -87,6 +87,7 @@ tests/dbus/test-invalidated-while-invoking-signals tests/dbus/test-message-mixin tests/dbus/test-properties tests/dbus/test-message-mixin +tests/dbus/test-self-handle tests/dbus/test-self-presence tests/dbus/test-text-mixin tests/dbus/test-text-respawn diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am index fd0be5c8e..7c9c0f42a 100644 --- a/tests/dbus/Makefile.am +++ b/tests/dbus/Makefile.am @@ -21,6 +21,7 @@ noinst_PROGRAMS = \ test-invalidated-while-invoking-signals \ test-message-mixin \ test-properties \ + test-self-handle \ test-self-presence \ test-text-mixin \ test-text-respawn \ @@ -79,6 +80,8 @@ nodist_test_properties_SOURCES = \ _gen/svc.h \ _gen/svc.c +test_self_handle_SOURCES = self-handle.c + test_self_presence_SOURCES = self-presence.c test_text_mixin_LDADD = \ diff --git a/tests/dbus/self-handle.c b/tests/dbus/self-handle.c new file mode 100644 index 000000000..e8f0bb2bf --- /dev/null +++ b/tests/dbus/self-handle.c @@ -0,0 +1,144 @@ +/* Feature test for the user's self-handle changing. + * + * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright (C) 2009 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 <telepathy-glib/connection.h> +#include <telepathy-glib/dbus.h> +#include <telepathy-glib/debug.h> +#include <telepathy-glib/gtypes.h> +#include <telepathy-glib/interfaces.h> + +#include "tests/lib/contacts-conn.h" +#include "tests/lib/debug.h" +#include "tests/lib/myassert.h" +#include "tests/lib/util.h" + +static int fail = 0; + +static void +myassert_failed (void) +{ + fail = 1; +} + +static void +on_self_handle_changed (TpConnection *client_conn, + GParamSpec *param_spec G_GNUC_UNUSED, + gpointer user_data) +{ + guint *times = user_data; + + ++*times; +} + +static void +test_self_handle (SimpleConnection *service_conn, + TpConnection *client_conn) +{ + TpBaseConnection *service_conn_as_base = TP_BASE_CONNECTION (service_conn); + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles ( + service_conn_as_base, TP_HANDLE_TYPE_CONTACT); + TpHandle handle; + guint times = 0; + + g_signal_connect (client_conn, "notify::self-handle", + G_CALLBACK (on_self_handle_changed), ×); + + MYASSERT_SAME_STRING (tp_handle_inspect (contact_repo, + tp_base_connection_get_self_handle (service_conn_as_base)), + "me@example.com"); + + MYASSERT_SAME_UINT (tp_connection_get_self_handle (client_conn), + tp_base_connection_get_self_handle (service_conn_as_base)); + + g_object_get (client_conn, + "self-handle", &handle, + NULL); + MYASSERT_SAME_UINT (handle, + tp_base_connection_get_self_handle (service_conn_as_base)); + + MYASSERT_SAME_UINT (times, 0); + + /* similar to /nick in IRC */ + simple_connection_set_identifier (service_conn, "myself@example.org"); + test_connection_run_until_dbus_queue_processed (client_conn); + MYASSERT_SAME_UINT (times, 1); + + MYASSERT_SAME_STRING (tp_handle_inspect (contact_repo, + tp_base_connection_get_self_handle (service_conn_as_base)), + "myself@example.org"); + + MYASSERT_SAME_UINT (tp_connection_get_self_handle (client_conn), + tp_base_connection_get_self_handle (service_conn_as_base)); + + g_object_get (client_conn, + "self-handle", &handle, + NULL); + MYASSERT_SAME_UINT (handle, + tp_base_connection_get_self_handle (service_conn_as_base)); +} + +int +main (int argc, + char **argv) +{ + TpDBusDaemon *dbus; + SimpleConnection *service_conn; + TpBaseConnection *service_conn_as_base; + gchar *name; + gchar *conn_path; + GError *error = NULL; + TpConnection *client_conn; + + /* Setup */ + + g_type_init (); + tp_debug_set_flags ("all"); + dbus = tp_dbus_daemon_new (tp_get_bus ()); + + service_conn = SIMPLE_CONNECTION (g_object_new ( + SIMPLE_TYPE_CONNECTION, + "account", "me@example.com", + "protocol", "simple", + NULL)); + service_conn_as_base = TP_BASE_CONNECTION (service_conn); + MYASSERT (service_conn != NULL, ""); + MYASSERT (service_conn_as_base != NULL, ""); + + MYASSERT (tp_base_connection_register (service_conn_as_base, "simple", + &name, &conn_path, &error), ""); + MYASSERT_NO_ERROR (error); + + client_conn = tp_connection_new (dbus, name, conn_path, &error); + MYASSERT (client_conn != NULL, ""); + MYASSERT_NO_ERROR (error); + MYASSERT (tp_connection_run_until_ready (client_conn, TRUE, &error, NULL), + ""); + MYASSERT_NO_ERROR (error); + + /* Tests */ + + test_self_handle (service_conn, client_conn); + + /* Teardown */ + + MYASSERT (tp_cli_connection_run_disconnect (client_conn, -1, &error, NULL), + ""); + MYASSERT_NO_ERROR (error); + g_object_unref (client_conn); + + service_conn_as_base = NULL; + g_object_unref (service_conn); + g_free (name); + g_free (conn_path); + + g_object_unref (dbus); + + return fail; +} diff --git a/tests/lib/simple-conn.c b/tests/lib/simple-conn.c index 8dba8a59b..74eea1a75 100644 --- a/tests/lib/simple-conn.c +++ b/tests/lib/simple-conn.c @@ -224,3 +224,19 @@ simple_connection_class_init (SimpleConnectionClass *klass) G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB); g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); } + +void +simple_connection_set_identifier (SimpleConnection *self, + const gchar *identifier) +{ + TpBaseConnection *conn = (TpBaseConnection *) self; + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn, + TP_HANDLE_TYPE_CONTACT); + TpHandle handle = tp_handle_ensure (contact_repo, identifier, NULL, NULL); + + /* if this fails then the identifier was bad - caller error */ + g_return_if_fail (handle != 0); + + tp_base_connection_set_self_handle (conn, handle); + tp_handle_unref (contact_repo, handle); +} diff --git a/tests/lib/simple-conn.h b/tests/lib/simple-conn.h index 93cd7efef..7fd3310ab 100644 --- a/tests/lib/simple-conn.h +++ b/tests/lib/simple-conn.h @@ -54,6 +54,9 @@ GType simple_connection_get_type (void); void simple_connection_inject_disconnect (SimpleConnection *self); +void simple_connection_set_identifier (SimpleConnection *self, + const gchar *identifier); + G_END_DECLS #endif /* #ifndef __SIMPLE_CONN_H__ */ |