summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-01-08 12:07:57 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-01-08 12:12:08 +0000
commit156d18599a9b56abe575eb4076e970ba34aa2860 (patch)
tree784dfaf1b2eafb52b4331c24174337fb5d7be100
parent414118702d96a042848625552ef6b8b2a168ef6e (diff)
Add a test for setting your own name
-rw-r--r--tests/dbus/Makefile.am3
-rw-r--r--tests/dbus/self-names.c224
2 files changed, 227 insertions, 0 deletions
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 78ce99758..dfb4a45c9 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -53,6 +53,7 @@ tests_list = \
test-proxy-preparation \
test-room-list \
test-self-handle \
+ test-self-names \
test-self-presence \
test-simple-approver \
test-simple-handler \
@@ -221,6 +222,8 @@ test_self_handle_LDADD = \
$(GLIB_LIBS) \
$(NULL)
+test_self_names_SOURCES = self-names.c
+
test_self_presence_SOURCES = self-presence.c
test_text_mixin_SOURCES = text-mixin.c
diff --git a/tests/dbus/self-names.c b/tests/dbus/self-names.c
new file mode 100644
index 000000000..e05460377
--- /dev/null
+++ b/tests/dbus/self-names.c
@@ -0,0 +1,224 @@
+/* Feature test for setting your own name.
+ *
+ * Copyright © 2013 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * 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 <telepathy-glib/connection.h>
+#include <telepathy-glib/contact.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/debug.h>
+
+#include "tests/lib/contacts-conn.h"
+#include "tests/lib/debug.h"
+#include "tests/lib/util.h"
+
+typedef struct {
+ enum { NAMES_BOTH, NAMES_MISSING, NAMES_ONLY } names;
+} Options;
+
+static Options normal_options = { NAMES_BOTH };
+static Options no_names_options = { NAMES_MISSING };
+static Options only_names_options = { NAMES_ONLY };
+
+typedef struct {
+ TpBaseConnection *base_conn;
+ TpTestsContactsConnection *service_conn;
+ TpHandleRepoIface *service_repo;
+ TpConnection *client_conn;
+ GAsyncResult *result;
+ GError *error;
+ guint pending;
+} Fixture;
+
+static void
+setup (Fixture *f,
+ gconstpointer user_data)
+{
+ const Options *options = user_data;
+ GType type;
+
+ if (options == NULL)
+ options = &normal_options;
+
+ switch (options->names)
+ {
+ case NAMES_MISSING:
+ type = TP_TESTS_TYPE_NO_NAMES_CONNECTION;
+ break;
+
+ case NAMES_ONLY:
+ type = TP_TESTS_TYPE_NO_ALIASING_CONNECTION;
+ break;
+
+ case NAMES_BOTH:
+ default:
+ type = TP_TESTS_TYPE_CONTACTS_CONNECTION;
+ break;
+ }
+
+ tp_tests_create_conn (type,
+ "me@test.com", TRUE, &f->base_conn, &f->client_conn);
+
+ f->service_conn = TP_TESTS_CONTACTS_CONNECTION (f->base_conn);
+ g_object_ref (f->service_conn);
+
+ f->service_repo = tp_base_connection_get_handles (f->base_conn,
+ TP_HANDLE_TYPE_CONTACT);
+}
+
+static void
+conn_void_cb (TpConnection *conn,
+ const GError *error,
+ gpointer user_data,
+ GObject *nil G_GNUC_UNUSED)
+{
+ Fixture *f = user_data;
+
+ g_assert_no_error (error);
+ g_assert (f->client_conn == conn);
+ f->pending--;
+}
+
+static void
+proxy_void_cb (TpProxy *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *nil G_GNUC_UNUSED)
+{
+ Fixture *f = user_data;
+
+ g_assert_no_error (error);
+ g_assert (f->client_conn == (TpConnection *) proxy);
+ f->pending--;
+}
+
+static void
+test_my_name (Fixture *f,
+ gconstpointer opts)
+{
+ const Options *options = opts;
+ TpContact *self_contact;
+ TpHandle self_handle;
+ TpContactFeature features[] = { TP_CONTACT_FEATURE_NAMES };
+
+ if (options == NULL)
+ options = &normal_options;
+
+ tp_tests_proxy_run_until_prepared (f->client_conn, NULL);
+
+ self_contact = tp_connection_get_self_contact (f->client_conn);
+ self_handle = tp_contact_get_handle (self_contact);
+
+ tp_connection_upgrade_contacts_async (f->client_conn, 1, &self_contact,
+ 1, features, tp_tests_result_ready_cb, &f->result);
+ tp_tests_run_until_result (&f->result);
+ tp_connection_upgrade_contacts_finish (f->client_conn, f->result,
+ NULL, &f->error);
+ g_assert_no_error (f->error);
+ g_clear_object (&f->result);
+
+ if (options->names != NAMES_ONLY)
+ {
+ GHashTable *aus = g_hash_table_new (NULL, NULL);
+
+ /* Changing my legacy alias via Aliasing should modify my nickname */
+ f->pending = 1;
+ g_hash_table_insert (aus, GUINT_TO_POINTER (self_handle),
+ "new legacy alias");
+ tp_cli_connection_interface_aliasing_call_set_aliases (f->client_conn,
+ -1, aus, conn_void_cb, f, NULL, NULL);
+ g_hash_table_unref (aus);
+
+ while (f->pending > 0)
+ g_main_context_iteration (NULL, TRUE);
+
+ g_assert_cmpstr (tp_contact_get_alias (self_contact), ==,
+ "new legacy alias");
+
+ if (options->names == NAMES_MISSING)
+ g_assert_cmpstr (tp_contact_get_nickname (self_contact), ==, NULL);
+ else
+ g_assert_cmpstr (tp_contact_get_nickname (self_contact), ==,
+ "new legacy alias");
+
+ g_assert_cmpstr (tp_contact_get_local_alias (self_contact), ==, NULL);
+ }
+
+ if (options->names != NAMES_MISSING)
+ {
+ GValue value = G_VALUE_INIT;
+
+ /* Changing my nickname via Names should work */
+ f->pending = 1;
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_static_string (&value, "my new nickname");
+ tp_cli_dbus_properties_call_set (f->client_conn, -1,
+ TP_IFACE_CONNECTION_INTERFACE_NAMES, "Nickname",
+ &value, proxy_void_cb, f, NULL, NULL);
+ g_value_unset (&value);
+
+ while (f->pending > 0)
+ g_main_context_iteration (NULL, TRUE);
+
+ g_assert_cmpstr (tp_contact_get_alias (self_contact), ==,
+ "my new nickname");
+ g_assert_cmpstr (tp_contact_get_nickname (self_contact), ==,
+ "my new nickname");
+ g_assert_cmpstr (tp_contact_get_local_alias (self_contact), ==, NULL);
+
+ /* Changing my local alias via Names should also work */
+ f->pending = 1;
+ tp_cli_connection_interface_names_call_set_local_alias (f->client_conn,
+ -1, self_handle, "my new local-alias", conn_void_cb, f, NULL,
+ NULL);
+
+ while (f->pending > 0)
+ g_main_context_iteration (NULL, TRUE);
+
+ g_assert_cmpstr (tp_contact_get_alias (self_contact), ==,
+ "my new local-alias");
+ g_assert_cmpstr (tp_contact_get_nickname (self_contact), ==,
+ "my new nickname");
+ g_assert_cmpstr (tp_contact_get_local_alias (self_contact), ==,
+ "my new local-alias");
+ }
+}
+
+static void
+teardown (Fixture *f,
+ gconstpointer unused G_GNUC_UNUSED)
+{
+ if (f->client_conn != NULL)
+ tp_tests_connection_assert_disconnect_succeeds (f->client_conn);
+
+ g_clear_object (&f->client_conn);
+ f->service_repo = NULL;
+ g_clear_object (&f->service_conn);
+ g_clear_object (&f->base_conn);
+ g_clear_object (&f->result);
+ g_clear_error (&f->error);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ tp_tests_init (&argc, &argv);
+ g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id=");
+
+#define ADD(x, opts) \
+ g_test_add ("/self-names/" #x "/" #opts, \
+ Fixture, &opts, setup, test_ ## x, teardown)
+
+ ADD (my_name, normal_options);
+ ADD (my_name, no_names_options);
+ ADD (my_name, only_names_options);
+
+ return g_test_run ();
+}