diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/Makefile.am | 32 | ||||
-rw-r--r-- | tests/lib/contact-list-manager.c | 902 | ||||
-rw-r--r-- | tests/lib/contact-list-manager.h | 71 | ||||
-rw-r--r-- | tests/lib/contacts-conn.c | 1120 | ||||
-rw-r--r-- | tests/lib/contacts-conn.h | 116 | ||||
-rw-r--r-- | tests/lib/debug.h | 3 | ||||
-rw-r--r-- | tests/lib/echo-chan.c | 223 | ||||
-rw-r--r-- | tests/lib/echo-chan.h | 56 | ||||
-rw-r--r-- | tests/lib/logger-test-helper.c | 86 | ||||
-rw-r--r-- | tests/lib/logger-test-helper.h | 40 | ||||
-rw-r--r-- | tests/lib/room-list-chan.c | 252 | ||||
-rw-r--r-- | tests/lib/room-list-chan.h | 50 | ||||
-rw-r--r-- | tests/lib/simple-account-manager.c | 241 | ||||
-rw-r--r-- | tests/lib/simple-account-manager.h | 72 | ||||
-rw-r--r-- | tests/lib/simple-account.c | 641 | ||||
-rw-r--r-- | tests/lib/simple-account.h | 71 | ||||
-rw-r--r-- | tests/lib/simple-conn.c | 456 | ||||
-rw-r--r-- | tests/lib/simple-conn.h | 76 | ||||
-rw-r--r-- | tests/lib/util.c | 712 | ||||
-rw-r--r-- | tests/lib/util.h | 112 |
20 files changed, 0 insertions, 5332 deletions
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am deleted file mode 100644 index 1130029..0000000 --- a/tests/lib/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -noinst_LTLIBRARIES = libtp-logger-tests.la - -libtp_logger_tests_la_SOURCES = \ - contacts-conn.c \ - contacts-conn.h \ - contact-list-manager.c \ - contact-list-manager.h \ - echo-chan.c \ - echo-chan.h \ - room-list-chan.c \ - room-list-chan.h \ - simple-account.c \ - simple-account.h \ - simple-account-manager.c \ - simple-account-manager.h \ - simple-conn.c \ - simple-conn.h \ - util.c \ - util.h \ - logger-test-helper.c \ - logger-test-helper.h - -check_c_sources = *.c -include $(top_srcdir)/tools/check-coding-style.mk -check-local: check-coding-style - -AM_CFLAGS = \ - $(ERROR_CFLAGS) \ - $(TPL_CFLAGS)\ - $(NULL) - -libtp_logger_tests_la_LIBADD = $(TPL_LIBS) diff --git a/tests/lib/contact-list-manager.c b/tests/lib/contact-list-manager.c deleted file mode 100644 index bce8e21..0000000 --- a/tests/lib/contact-list-manager.c +++ /dev/null @@ -1,902 +0,0 @@ -/* - * Example channel manager for contact lists - * - * Copyright © 2007-2010 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright © 2007-2010 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 "contact-list-manager.h" - -#include <string.h> -#include <telepathy-glib/telepathy-glib.h> - -struct _TpTestsContactListManagerPrivate -{ - TpBaseConnection *conn; - - gulong status_changed_id; - - /* TpHandle => ContactDetails */ - GHashTable *contact_details; - - TpHandleRepoIface *contact_repo; - GHashTable *groups; -}; - -static void contact_groups_iface_init (TpContactGroupListInterface *iface); -static void mutable_contact_groups_iface_init ( - TpMutableContactGroupListInterface *iface); -static void mutable_iface_init ( - TpMutableContactListInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (TpTestsContactListManager, tp_tests_contact_list_manager, - TP_TYPE_BASE_CONTACT_LIST, - G_IMPLEMENT_INTERFACE (TP_TYPE_CONTACT_GROUP_LIST, - contact_groups_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_MUTABLE_CONTACT_GROUP_LIST, - mutable_contact_groups_iface_init) - G_IMPLEMENT_INTERFACE (TP_TYPE_MUTABLE_CONTACT_LIST, - mutable_iface_init)) - -typedef struct { - TpSubscriptionState subscribe; - TpSubscriptionState publish; - gchar *publish_request; - GHashTable *groups; - - TpHandle handle; - TpHandleRepoIface *contact_repo; -} ContactDetails; - -static void -contact_detail_destroy (gpointer p) -{ - ContactDetails *d = p; - - g_free (d->publish_request); - g_hash_table_unref (d->groups); - - g_slice_free (ContactDetails, d); -} - -static ContactDetails * -lookup_contact (TpTestsContactListManager *self, - TpHandle handle) -{ - return g_hash_table_lookup (self->priv->contact_details, - GUINT_TO_POINTER (handle)); -} - -static ContactDetails * -ensure_contact (TpTestsContactListManager *self, - TpHandle handle) -{ - ContactDetails *d = lookup_contact (self, handle); - - if (d == NULL) - { - d = g_slice_new0 (ContactDetails); - d->subscribe = TP_SUBSCRIPTION_STATE_NO; - d->publish = TP_SUBSCRIPTION_STATE_NO; - d->publish_request = NULL; - d->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - d->handle = handle; - d->contact_repo = self->priv->contact_repo; - - g_hash_table_insert (self->priv->contact_details, - GUINT_TO_POINTER (handle), d); - } - - return d; -} - -static void -tp_tests_contact_list_manager_init (TpTestsContactListManager *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_CONTACT_LIST_MANAGER, TpTestsContactListManagerPrivate); - - self->priv->contact_details = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, contact_detail_destroy); -} - -static void -close_all (TpTestsContactListManager *self) -{ - if (self->priv->status_changed_id != 0) - { - g_signal_handler_disconnect (self->priv->conn, - self->priv->status_changed_id); - self->priv->status_changed_id = 0; - } - tp_clear_pointer (&self->priv->contact_details, g_hash_table_unref); - tp_clear_pointer (&self->priv->groups, g_hash_table_unref); -} - -static void -dispose (GObject *object) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (object); - - close_all (self); - - ((GObjectClass *) tp_tests_contact_list_manager_parent_class)->dispose ( - object); -} - -static TpHandleSet * -contact_list_dup_contacts (TpBaseContactList *base) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - TpHandleSet *set; - GHashTableIter iter; - gpointer k, v; - - set = tp_handle_set_new (self->priv->contact_repo); - - g_hash_table_iter_init (&iter, self->priv->contact_details); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - ContactDetails *d = v; - - /* add all the interesting items */ - if (d->subscribe != TP_SUBSCRIPTION_STATE_NO || - d->publish != TP_SUBSCRIPTION_STATE_NO) - tp_handle_set_add (set, GPOINTER_TO_UINT (k)); - } - - return set; -} - -static void -contact_list_dup_states (TpBaseContactList *base, - TpHandle contact, - TpSubscriptionState *subscribe, - TpSubscriptionState *publish, - gchar **publish_request) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - ContactDetails *d = lookup_contact (self, contact); - - if (d == NULL) - { - if (subscribe != NULL) - *subscribe = TP_SUBSCRIPTION_STATE_NO; - - if (publish != NULL) - *publish = TP_SUBSCRIPTION_STATE_NO; - - if (publish_request != NULL) - *publish_request = NULL; - } - else - { - if (subscribe != NULL) - *subscribe = d->subscribe; - - if (publish != NULL) - *publish = d->publish; - - if (publish_request != NULL) - *publish_request = g_strdup (d->publish_request); - } -} - -static GStrv -contact_list_dup_groups (TpBaseContactList *base) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - GPtrArray *ret; - - if (self->priv->groups != NULL) - { - GHashTableIter iter; - gpointer name; - - ret = g_ptr_array_sized_new (g_hash_table_size (self->priv->groups) + 1); - - g_hash_table_iter_init (&iter, self->priv->groups); - while (g_hash_table_iter_next (&iter, &name, NULL)) - { - g_ptr_array_add (ret, g_strdup (name)); - } - } - else - { - ret = g_ptr_array_sized_new (1); - } - - g_ptr_array_add (ret, NULL); - - return (GStrv) g_ptr_array_free (ret, FALSE); -} - -static GStrv -contact_list_dup_contact_groups (TpBaseContactList *base, - TpHandle contact) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - ContactDetails *d = lookup_contact (self, contact); - GPtrArray *ret; - - if (d != NULL && d->groups != NULL) - { - GHashTableIter iter; - gpointer name; - - ret = g_ptr_array_sized_new (g_hash_table_size (d->groups) + 1); - - g_hash_table_iter_init (&iter, d->groups); - while (g_hash_table_iter_next (&iter, &name, NULL)) - { - g_ptr_array_add (ret, g_strdup (name)); - } - } - else - { - ret = g_ptr_array_sized_new (1); - } - - g_ptr_array_add (ret, NULL); - - return (GStrv) g_ptr_array_free (ret, FALSE); -} - -static TpHandleSet * -contact_list_dup_group_members (TpBaseContactList *base, - const gchar *group) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - GHashTableIter iter; - gpointer k, v; - TpHandleSet *set; - - set = tp_handle_set_new (self->priv->contact_repo); - - if (G_UNLIKELY (g_hash_table_lookup (self->priv->groups, group) == NULL)) - { - /* clearly it doesn't have members */ - return set; - } - - g_hash_table_iter_init (&iter, self->priv->contact_details); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - ContactDetails *d = v; - - if (d->groups != NULL && - g_hash_table_lookup (d->groups, group) != NULL) - tp_handle_set_add (set, GPOINTER_TO_UINT (k)); - } - - return set; -} - -static GPtrArray * -group_difference (GHashTable *left, - GHashTable *right) -{ - GHashTableIter iter; - GPtrArray *set = g_ptr_array_sized_new (g_hash_table_size (left)); - gpointer name; - - g_hash_table_iter_init (&iter, left); - while (g_hash_table_iter_next (&iter, &name, NULL)) - { - if (g_hash_table_lookup (right, name) == NULL) - g_ptr_array_add (set, name); - } - - return set; -} - -static void -contact_list_set_contact_groups_async (TpBaseContactList *base, - TpHandle contact, - const gchar * const *names, - gsize n, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - ContactDetails *d; - GHashTable *tmp; - GPtrArray *added, *removed; - GPtrArray *new_groups; - guint i; - - d = ensure_contact (self, contact); - - new_groups = g_ptr_array_new (); - /* make a hash table so we only have one difference function */ - tmp = g_hash_table_new (g_str_hash, g_str_equal); - for (i = 0; i < n; i++) - { - g_hash_table_insert (tmp, (gpointer) names[i], GUINT_TO_POINTER (1)); - - if (g_hash_table_lookup (self->priv->groups, names[i]) == NULL) - { - g_hash_table_insert (self->priv->groups, g_strdup (names[i]), - GUINT_TO_POINTER (1)); - g_ptr_array_add (new_groups, (gchar *) names[i]); - } - } - - if (new_groups->len > 0) - { - tp_base_contact_list_groups_created ((TpBaseContactList *) self, - (const gchar * const *) new_groups->pdata, new_groups->len); - } - - /* see which groups were added and which were removed */ - added = group_difference (tmp, d->groups); - removed = group_difference (d->groups, tmp); - - g_hash_table_unref (tmp); - - /* update the list of groups the contact thinks it has */ - g_hash_table_remove_all (d->groups); - for (i = 0; i < n; i++) - g_hash_table_insert (d->groups, g_strdup (names[i]), GUINT_TO_POINTER (1)); - - /* signal the change */ - if (added->len > 0 || removed->len > 0) - { - tp_base_contact_list_one_contact_groups_changed (base, contact, - (const gchar * const *) added->pdata, added->len, - (const gchar * const *) removed->pdata, removed->len); - } - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, - user_data, contact_list_set_contact_groups_async); - - g_ptr_array_unref (added); - g_ptr_array_unref (removed); - g_ptr_array_unref (new_groups); -} - -static void -contact_list_set_group_members_async (TpBaseContactList *base, - const gchar *normalized_group, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new_error ((GObject *) base, callback, - user_data, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, "Not implemented"); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); -} - -static void -contact_list_add_to_group_async (TpBaseContactList *base, - const gchar *group, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new_error ((GObject *) base, callback, - user_data, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, "Not implemented"); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); -} - -static void -contact_list_remove_from_group_async (TpBaseContactList *base, - const gchar *group, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new_error ((GObject *) base, callback, - user_data, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, "Not implemented"); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); -} - -static void -contact_list_remove_group_async (TpBaseContactList *base, - const gchar *group, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - - simple = g_simple_async_result_new_error ((GObject *) base, callback, - user_data, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, "Not implemented"); - g_simple_async_result_complete_in_idle (simple); - g_object_unref (simple); -} - -static void -contact_list_request_subscription_async (TpBaseContactList *self, - TpHandleSet *contacts, - const gchar *message, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GArray *handles; - - handles = tp_handle_set_to_array (contacts); - tp_tests_contact_list_manager_request_subscription ( - (TpTestsContactListManager *) self, - handles->len, (TpHandle *) handles->data, message); - g_array_unref (handles); - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, - user_data, contact_list_request_subscription_async); -} - -static void -contact_list_authorize_publication_async (TpBaseContactList *self, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GArray *handles; - - handles = tp_handle_set_to_array (contacts); - tp_tests_contact_list_manager_authorize_publication ( - (TpTestsContactListManager *) self, - handles->len, (TpHandle *) handles->data); - g_array_unref (handles); - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, - user_data, contact_list_authorize_publication_async); -} - -static void -contact_list_remove_contacts_async (TpBaseContactList *self, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GArray *handles; - - handles = tp_handle_set_to_array (contacts); - tp_tests_contact_list_manager_remove ( - (TpTestsContactListManager *) self, - handles->len, (TpHandle *) handles->data); - g_array_unref (handles); - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, - user_data, contact_list_remove_contacts_async); -} - -static void -contact_list_unsubscribe_async (TpBaseContactList *self, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GArray *handles; - - handles = tp_handle_set_to_array (contacts); - tp_tests_contact_list_manager_unsubscribe ( - (TpTestsContactListManager *) self, - handles->len, (TpHandle *) handles->data); - g_array_unref (handles); - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, - user_data, contact_list_unsubscribe_async); -} - -static void -contact_list_unpublish_async (TpBaseContactList *self, - TpHandleSet *contacts, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GArray *handles; - - handles = tp_handle_set_to_array (contacts); - tp_tests_contact_list_manager_unpublish ( - (TpTestsContactListManager *) self, - handles->len, (TpHandle *) handles->data); - g_array_unref (handles); - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, - user_data, contact_list_unpublish_async); -} - -static void -status_changed_cb (TpBaseConnection *conn, - guint status, - guint reason, - TpTestsContactListManager *self) -{ - switch (status) - { - case TP_CONNECTION_STATUS_CONNECTED: - { - tp_base_contact_list_set_list_received (TP_BASE_CONTACT_LIST (self)); - } - break; - - case TP_CONNECTION_STATUS_DISCONNECTED: - { - close_all (self); - } - break; - } -} - -static void -constructed (GObject *object) -{ - TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (object); - void (*chain_up) (GObject *) = - ((GObjectClass *) tp_tests_contact_list_manager_parent_class)->constructed; - - if (chain_up != NULL) - { - chain_up (object); - } - - self->priv->conn = tp_base_contact_list_get_connection ( - TP_BASE_CONTACT_LIST (self), NULL); - self->priv->status_changed_id = g_signal_connect (self->priv->conn, - "status-changed", G_CALLBACK (status_changed_cb), self); - - self->priv->contact_repo = tp_base_connection_get_handles (self->priv->conn, - TP_HANDLE_TYPE_CONTACT); - self->priv->groups = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); -} - -static void -contact_groups_iface_init (TpContactGroupListInterface *iface) -{ - iface->dup_groups = contact_list_dup_groups; - iface->dup_contact_groups = contact_list_dup_contact_groups; - iface->dup_group_members = contact_list_dup_group_members; -} - -static void -mutable_contact_groups_iface_init ( - TpMutableContactGroupListInterface *iface) -{ - iface->set_contact_groups_async = contact_list_set_contact_groups_async; - iface->set_group_members_async = contact_list_set_group_members_async; - iface->add_to_group_async = contact_list_add_to_group_async; - iface->remove_from_group_async = contact_list_remove_from_group_async; - iface->remove_group_async = contact_list_remove_group_async; -} - -static void -mutable_iface_init (TpMutableContactListInterface *iface) -{ - iface->request_subscription_async = contact_list_request_subscription_async; - iface->authorize_publication_async = contact_list_authorize_publication_async; - iface->remove_contacts_async = contact_list_remove_contacts_async; - iface->unsubscribe_async = contact_list_unsubscribe_async; - iface->unpublish_async = contact_list_unpublish_async; -} - -static void -tp_tests_contact_list_manager_class_init (TpTestsContactListManagerClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - TpBaseContactListClass *base_class =(TpBaseContactListClass *) klass; - - g_type_class_add_private (klass, sizeof (TpTestsContactListManagerPrivate)); - - object_class->constructed = constructed; - object_class->dispose = dispose; - - base_class->dup_states = contact_list_dup_states; - base_class->dup_contacts = contact_list_dup_contacts; -} - -void -tp_tests_contact_list_manager_add_to_group (TpTestsContactListManager *self, - const gchar *group_name, TpHandle member) -{ - TpBaseContactList *base = TP_BASE_CONTACT_LIST (self); - ContactDetails *d = ensure_contact (self, member); - - g_hash_table_insert (d->groups, g_strdup (group_name), GUINT_TO_POINTER (1)); - - if (g_hash_table_lookup (self->priv->groups, group_name) == NULL) - { - g_hash_table_insert (self->priv->groups, g_strdup (group_name), - GUINT_TO_POINTER (1)); - tp_base_contact_list_groups_created ((TpBaseContactList *) self, - &group_name, 1); - } - - tp_base_contact_list_one_contact_groups_changed (base, member, - &group_name, 1, NULL, 0); -} - -void -tp_tests_contact_list_manager_remove_from_group (TpTestsContactListManager *self, - const gchar *group_name, TpHandle member) -{ - TpBaseContactList *base = TP_BASE_CONTACT_LIST (self); - ContactDetails *d = lookup_contact (self, member); - - if (d == NULL) - return; - - g_hash_table_remove (d->groups, group_name); - - tp_base_contact_list_one_contact_groups_changed (base, member, - NULL, 0, &group_name, 1); -} - -typedef struct { - TpTestsContactListManager *self; - TpHandleSet *handles; -} SelfAndContact; - -static SelfAndContact * -self_and_contact_new (TpTestsContactListManager *self, - TpHandleSet *handles) -{ - SelfAndContact *ret = g_slice_new0 (SelfAndContact); - - ret->self = g_object_ref (self); - ret->handles = tp_handle_set_copy (handles); - - return ret; -} - -static void -self_and_contact_destroy (gpointer p) -{ - SelfAndContact *s = p; - - tp_handle_set_destroy (s->handles); - g_object_unref (s->self); - g_slice_free (SelfAndContact, s); -} - -static gboolean -receive_authorized (gpointer p) -{ - SelfAndContact *s = p; - GArray *handles_array; - guint i; - - handles_array = tp_handle_set_to_array (s->handles); - for (i = 0; i < handles_array->len; i++) - { - ContactDetails *d = lookup_contact (s->self, - g_array_index (handles_array, TpHandle, i)); - - if (d == NULL) - continue; - - d->subscribe = TP_SUBSCRIPTION_STATE_YES; - - /* if we're not publishing to them, also pretend they have asked us to do so */ - if (d->publish != TP_SUBSCRIPTION_STATE_YES) - { - d->publish = TP_SUBSCRIPTION_STATE_ASK; - tp_clear_pointer (&d->publish_request, g_free); - d->publish_request = g_strdup ("automatic publish request"); - } - } - g_array_unref (handles_array); - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (s->self), - s->handles, NULL); - - return FALSE; -} - -static gboolean -receive_unauthorized (gpointer p) -{ - SelfAndContact *s = p; - GArray *handles_array; - guint i; - - handles_array = tp_handle_set_to_array (s->handles); - for (i = 0; i < handles_array->len; i++) - { - ContactDetails *d = lookup_contact (s->self, - g_array_index (handles_array, TpHandle, i)); - - if (d == NULL) - continue; - - d->subscribe = TP_SUBSCRIPTION_STATE_REMOVED_REMOTELY; - } - g_array_unref (handles_array); - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (s->self), - s->handles, NULL); - - return FALSE; -} - -void -tp_tests_contact_list_manager_request_subscription (TpTestsContactListManager *self, - guint n_members, TpHandle *members, const gchar *message) -{ - TpHandleSet *handles; - guint i; - gchar *message_lc; - - handles = tp_handle_set_new (self->priv->contact_repo); - for (i = 0; i < n_members; i++) - { - ContactDetails *d = ensure_contact (self, members[i]); - - if (d->subscribe == TP_SUBSCRIPTION_STATE_YES) - continue; - - d->subscribe = TP_SUBSCRIPTION_STATE_ASK; - tp_handle_set_add (handles, members[i]); - } - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (self), handles, - NULL); - - message_lc = g_ascii_strdown (message, -1); - if (strstr (message_lc, "please") != NULL) - { - g_idle_add_full (G_PRIORITY_DEFAULT, - receive_authorized, - self_and_contact_new (self, handles), - self_and_contact_destroy); - } - else if (strstr (message_lc, "no") != NULL) - { - g_idle_add_full (G_PRIORITY_DEFAULT, - receive_unauthorized, - self_and_contact_new (self, handles), - self_and_contact_destroy); - } - - g_free (message_lc); - tp_handle_set_destroy (handles); -} - -void -tp_tests_contact_list_manager_unsubscribe (TpTestsContactListManager *self, - guint n_members, TpHandle *members) -{ - TpHandleSet *handles; - guint i; - - handles = tp_handle_set_new (self->priv->contact_repo); - for (i = 0; i < n_members; i++) - { - ContactDetails *d = lookup_contact (self, members[i]); - - if (d == NULL || d->subscribe == TP_SUBSCRIPTION_STATE_NO) - continue; - - d->subscribe = TP_SUBSCRIPTION_STATE_NO; - tp_handle_set_add (handles, members[i]); - } - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (self), handles, - NULL); - - tp_handle_set_destroy (handles); -} - -void -tp_tests_contact_list_manager_authorize_publication (TpTestsContactListManager *self, - guint n_members, TpHandle *members) -{ - TpHandleSet *handles; - guint i; - - handles = tp_handle_set_new (self->priv->contact_repo); - for (i = 0; i < n_members; i++) - { - ContactDetails *d = lookup_contact (self, members[i]); - - if (d == NULL || d->publish != TP_SUBSCRIPTION_STATE_ASK) - continue; - - d->publish = TP_SUBSCRIPTION_STATE_YES; - tp_clear_pointer (&d->publish_request, g_free); - tp_handle_set_add (handles, members[i]); - } - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (self), handles, - NULL); - - tp_handle_set_destroy (handles); -} - -void -tp_tests_contact_list_manager_unpublish (TpTestsContactListManager *self, - guint n_members, TpHandle *members) -{ - TpHandleSet *handles; - guint i; - - handles = tp_handle_set_new (self->priv->contact_repo); - for (i = 0; i < n_members; i++) - { - ContactDetails *d = lookup_contact (self, members[i]); - - if (d == NULL || d->publish == TP_SUBSCRIPTION_STATE_NO) - continue; - - d->publish = TP_SUBSCRIPTION_STATE_NO; - tp_clear_pointer (&d->publish_request, g_free); - tp_handle_set_add (handles, members[i]); - } - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (self), handles, - NULL); - - tp_handle_set_destroy (handles); -} - -void -tp_tests_contact_list_manager_remove (TpTestsContactListManager *self, - guint n_members, TpHandle *members) -{ - TpHandleSet *handles; - guint i; - - handles = tp_handle_set_new (self->priv->contact_repo); - for (i = 0; i < n_members; i++) - { - ContactDetails *d = lookup_contact (self, members[i]); - - if (d == NULL) - continue; - - g_hash_table_remove (self->priv->contact_details, - GUINT_TO_POINTER (members[i])); - tp_handle_set_add (handles, members[i]); - } - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (self), NULL, - handles); - - tp_handle_set_destroy (handles); -} - -void -tp_tests_contact_list_manager_add_initial_contacts (TpTestsContactListManager *self, - guint n_members, TpHandle *members) -{ - TpHandleSet *handles; - guint i; - - g_assert_cmpint (tp_base_connection_get_status (self->priv->conn), ==, - TP_CONNECTION_STATUS_DISCONNECTED); - g_assert (!tp_base_connection_is_destroyed (self->priv->conn)); - - handles = tp_handle_set_new (self->priv->contact_repo); - for (i = 0; i < n_members; i++) - { - ContactDetails *d; - - g_assert (lookup_contact (self, members[i]) == NULL); - d = ensure_contact (self, members[i]); - - d->subscribe = TP_SUBSCRIPTION_STATE_YES; - d->publish = TP_SUBSCRIPTION_STATE_YES; - - tp_handle_set_add (handles, members[i]); - } - - tp_base_contact_list_contacts_changed (TP_BASE_CONTACT_LIST (self), handles, - NULL); - - tp_handle_set_destroy (handles); -} diff --git a/tests/lib/contact-list-manager.h b/tests/lib/contact-list-manager.h deleted file mode 100644 index bc44863..0000000 --- a/tests/lib/contact-list-manager.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Example channel manager for contact lists - * - * Copyright © 2007-2010 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright © 2007-2010 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_CONTACT_LIST_MANAGER_H__ -#define __TP_TESTS_CONTACT_LIST_MANAGER_H__ - -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -#define TP_TESTS_TYPE_CONTACT_LIST_MANAGER \ - (tp_tests_contact_list_manager_get_type ()) -#define TP_TESTS_CONTACT_LIST_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_CONTACT_LIST_MANAGER, \ - TpTestsContactListManager)) -#define TP_TESTS_CONTACT_LIST_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_CONTACT_LIST_MANAGER, \ - TpTestsContactListManagerClass)) -#define TP_TESTS_IS_CONTACT_LIST_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_CONTACT_LIST_MANAGER)) -#define TP_TESTS_IS_CONTACT_LIST_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_CONTACT_LIST_MANAGER)) -#define TP_TESTS_CONTACT_LIST_MANAGER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_CONTACT_LIST_MANAGER, \ - TpTestsContactListManagerClass)) - -typedef struct _TpTestsContactListManager TpTestsContactListManager; -typedef struct _TpTestsContactListManagerClass TpTestsContactListManagerClass; -typedef struct _TpTestsContactListManagerPrivate TpTestsContactListManagerPrivate; - -struct _TpTestsContactListManagerClass { - TpBaseContactListClass parent_class; -}; - -struct _TpTestsContactListManager { - TpBaseContactList parent; - - TpTestsContactListManagerPrivate *priv; -}; - -GType tp_tests_contact_list_manager_get_type (void); - -void tp_tests_contact_list_manager_add_to_group (TpTestsContactListManager *self, - const gchar *group_name, TpHandle member); -void tp_tests_contact_list_manager_remove_from_group (TpTestsContactListManager *self, - const gchar *group_name, TpHandle member); - -void tp_tests_contact_list_manager_request_subscription (TpTestsContactListManager *self, - guint n_members, TpHandle *members, const gchar *message); -void tp_tests_contact_list_manager_unsubscribe (TpTestsContactListManager *self, - guint n_members, TpHandle *members); -void tp_tests_contact_list_manager_authorize_publication (TpTestsContactListManager *self, - guint n_members, TpHandle *members); -void tp_tests_contact_list_manager_unpublish (TpTestsContactListManager *self, - guint n_members, TpHandle *members); -void tp_tests_contact_list_manager_remove (TpTestsContactListManager *self, - guint n_members, TpHandle *members); -void tp_tests_contact_list_manager_add_initial_contacts (TpTestsContactListManager *self, - guint n_members, TpHandle *members); - -G_END_DECLS - -#endif diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c deleted file mode 100644 index 5ebc35f..0000000 --- a/tests/lib/contacts-conn.c +++ /dev/null @@ -1,1120 +0,0 @@ -/* - * contacts-conn.c - connection with contact info - * - * 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. - */ - -#include "config.h" - -#include "contacts-conn.h" - -#include <dbus/dbus-glib.h> - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "debug.h" - -static void init_aliasing (gpointer, gpointer); -static void init_avatars (gpointer, gpointer); -static void init_contact_info (gpointer, gpointer); -static void conn_avatars_properties_getter (GObject *object, GQuark interface, - GQuark name, GValue *value, gpointer getter_data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsContactsConnection, - tp_tests_contacts_connection, - TP_TESTS_TYPE_SIMPLE_CONNECTION, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING1, - init_aliasing); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_AVATARS1, - init_avatars); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_PRESENCE1, - tp_presence_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_LOCATION1, NULL) - G_IMPLEMENT_INTERFACE ( - TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_CAPABILITIES1, NULL) - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO1, - init_contact_info) - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS, - tp_contacts_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_LIST1, - tp_base_contact_list_mixin_list_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_GROUPS1, - tp_base_contact_list_mixin_groups_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CLIENT_TYPES1, - NULL); - ); - -/* type definition stuff */ - -static const char *mime_types[] = { "image/png", NULL }; -static TpDBusPropertiesMixinPropImpl conn_avatars_properties[] = { - { "MinimumAvatarWidth", GUINT_TO_POINTER (1), NULL }, - { "MinimumAvatarHeight", GUINT_TO_POINTER (2), NULL }, - { "RecommendedAvatarWidth", GUINT_TO_POINTER (3), NULL }, - { "RecommendedAvatarHeight", GUINT_TO_POINTER (4), NULL }, - { "MaximumAvatarWidth", GUINT_TO_POINTER (5), NULL }, - { "MaximumAvatarHeight", GUINT_TO_POINTER (6), NULL }, - { "MaximumAvatarBytes", GUINT_TO_POINTER (7), NULL }, - /* special-cased - it's the only one with a non-guint value */ - { "SupportedAvatarMIMETypes", NULL, NULL }, - { NULL } -}; - -enum -{ - N_SIGNALS -}; - -struct _TpTestsContactsConnectionPrivate -{ - /* TpHandle => gchar * */ - GHashTable *aliases; - /* TpHandle => AvatarData */ - GHashTable *avatars; - /* TpHandle => ContactsConnectionPresenceStatusIndex */ - GHashTable *presence_statuses; - /* TpHandle => gchar * */ - GHashTable *presence_messages; - /* TpHandle => GHashTable * */ - GHashTable *locations; - /* TpHandle => GPtrArray * */ - GHashTable *capabilities; - /* TpHandle => GPtrArray * */ - GHashTable *contact_info; - GPtrArray *default_contact_info; - - TpTestsContactListManager *list_manager; -}; - -typedef struct -{ - GArray *data; - gchar *mime_type; - gchar *token; -} AvatarData; - -static AvatarData * -avatar_data_new (GArray *data, - const gchar *mime_type, - const gchar *token) -{ - AvatarData *a; - - a = g_slice_new (AvatarData); - a->data = data ? g_array_ref (data) : NULL; - a->mime_type = g_strdup (mime_type); - a->token = g_strdup (token); - - return a; -} - -static void -avatar_data_free (gpointer data) -{ - AvatarData *a = data; - - if (a != NULL) - { - if (a->data != NULL) - g_array_unref (a->data); - g_free (a->mime_type); - g_free (a->token); - g_slice_free (AvatarData, a); - } -} - -static void -free_rcc_list (GPtrArray *rccs) -{ - g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, rccs); -} - -static void -tp_tests_contacts_connection_init (TpTestsContactsConnection *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TP_TESTS_TYPE_CONTACTS_CONNECTION, - TpTestsContactsConnectionPrivate); - self->priv->aliases = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, g_free); - self->priv->avatars = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, avatar_data_free); - self->priv->presence_statuses = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, NULL); - self->priv->presence_messages = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, g_free); - self->priv->locations = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify) g_hash_table_unref); - self->priv->capabilities = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify) free_rcc_list); - self->priv->contact_info = g_hash_table_new_full (g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify) g_ptr_array_unref); -} - -static void -finalize (GObject *object) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - - tp_contacts_mixin_finalize (object); - g_hash_table_unref (self->priv->aliases); - g_hash_table_unref (self->priv->avatars); - g_hash_table_unref (self->priv->presence_statuses); - g_hash_table_unref (self->priv->presence_messages); - g_hash_table_unref (self->priv->locations); - g_hash_table_unref (self->priv->capabilities); - g_hash_table_unref (self->priv->contact_info); - - if (self->priv->default_contact_info != NULL) - g_ptr_array_unref (self->priv->default_contact_info); - - G_OBJECT_CLASS (tp_tests_contacts_connection_parent_class)->finalize (object); -} - -static void -aliasing_fill_contact_attributes (GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - guint i; - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - TpBaseConnection *base = TP_BASE_CONNECTION (object); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base, - TP_HANDLE_TYPE_CONTACT); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - const gchar *alias = g_hash_table_lookup (self->priv->aliases, - GUINT_TO_POINTER (handle)); - - if (alias == NULL) - { - alias = tp_handle_inspect (contact_repo, handle); - } - - tp_contacts_mixin_set_contact_attribute (attributes, handle, - TP_IFACE_CONNECTION_INTERFACE_ALIASING1 "/alias", - tp_g_value_slice_new_string (alias)); - } -} - -static void -avatars_fill_contact_attributes (GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - guint i; - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - AvatarData *a = g_hash_table_lookup (self->priv->avatars, - GUINT_TO_POINTER (handle)); - - if (a != NULL && a->token != NULL) - { - tp_contacts_mixin_set_contact_attribute (attributes, handle, - TP_IFACE_CONNECTION_INTERFACE_AVATARS1 "/token", - tp_g_value_slice_new_string (a->token)); - } - } -} - -static void -location_fill_contact_attributes (GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - guint i; - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - GHashTable *location = g_hash_table_lookup (self->priv->locations, - GUINT_TO_POINTER (handle)); - - if (location != NULL) - { - tp_contacts_mixin_set_contact_attribute (attributes, handle, - TP_IFACE_CONNECTION_INTERFACE_LOCATION1 "/location", - tp_g_value_slice_new_boxed (TP_HASH_TYPE_LOCATION, location)); - } - } -} - -static void -contact_caps_fill_contact_attributes (GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - guint i; - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - GPtrArray *caps = g_hash_table_lookup (self->priv->capabilities, - GUINT_TO_POINTER (handle)); - - if (caps != NULL) - { - tp_contacts_mixin_set_contact_attribute (attributes, handle, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES1 "/capabilities", - tp_g_value_slice_new_boxed ( - TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, caps)); - } - } -} - -static void -contact_info_fill_contact_attributes (GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - guint i; - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - GPtrArray *info = g_hash_table_lookup (self->priv->contact_info, - GUINT_TO_POINTER (handle)); - - if (info != NULL) - { - tp_contacts_mixin_set_contact_attribute (attributes, handle, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO1 "/info", - tp_g_value_slice_new_boxed (TP_ARRAY_TYPE_CONTACT_INFO_FIELD_LIST, - info)); - } - } -} - -static TpDBusPropertiesMixinPropImpl conn_contact_info_properties[] = { - { "ContactInfoFlags", GUINT_TO_POINTER (TP_CONTACT_INFO_FLAG_PUSH | - TP_CONTACT_INFO_FLAG_CAN_SET), NULL }, - { "SupportedFields", NULL, NULL }, - { NULL } -}; - -static void -conn_contact_info_properties_getter (GObject *object, - GQuark interface, - GQuark name, - GValue *value, - gpointer getter_data) -{ - GQuark q_supported_fields = g_quark_from_static_string ("SupportedFields"); - static GPtrArray *supported_fields = NULL; - - if (name == q_supported_fields) - { - if (supported_fields == NULL) - { - supported_fields = g_ptr_array_new (); - - g_ptr_array_add (supported_fields, tp_value_array_build (4, - G_TYPE_STRING, "bday", - G_TYPE_STRV, NULL, - G_TYPE_UINT, 0, - G_TYPE_UINT, 1, - G_TYPE_INVALID)); - - g_ptr_array_add (supported_fields, tp_value_array_build (4, - G_TYPE_STRING, "email", - G_TYPE_STRV, NULL, - G_TYPE_UINT, 0, - G_TYPE_UINT, G_MAXUINT32, - G_TYPE_INVALID)); - - g_ptr_array_add (supported_fields, tp_value_array_build (4, - G_TYPE_STRING, "fn", - G_TYPE_STRV, NULL, - G_TYPE_UINT, 0, - G_TYPE_UINT, 1, - G_TYPE_INVALID)); - - g_ptr_array_add (supported_fields, tp_value_array_build (4, - G_TYPE_STRING, "tel", - G_TYPE_STRV, NULL, - G_TYPE_UINT, 0, - G_TYPE_UINT, G_MAXUINT32, - G_TYPE_INVALID)); - - g_ptr_array_add (supported_fields, tp_value_array_build (4, - G_TYPE_STRING, "url", - G_TYPE_STRV, NULL, - G_TYPE_UINT, 0, - G_TYPE_UINT, G_MAXUINT32, - G_TYPE_INVALID)); - } - g_value_set_boxed (value, supported_fields); - } - else - { - g_value_set_uint (value, GPOINTER_TO_UINT (getter_data)); - } -} - -static void -client_types_fill_contact_attributes ( - GObject *object, - const GArray *contacts, - GHashTable *attributes) -{ - TpTestsContactsConnectionClass *klass = - TP_TESTS_CONTACTS_CONNECTION_GET_CLASS (object); - - if (klass->fill_client_types != NULL) - klass->fill_client_types (object, contacts, attributes); - /* …else do nothing: a no-op implementation is valid, relatively speaking. - * The spec sez the /client-types attribute should be “omitted from the - * result if the contact's client types are not known.” - */ -} - -static void -constructed (GObject *object) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - TpBaseConnection *base = TP_BASE_CONNECTION (object); - void (*parent_impl) (GObject *) = - G_OBJECT_CLASS (tp_tests_contacts_connection_parent_class)->constructed; - - if (parent_impl != NULL) - parent_impl (object); - - self->priv->list_manager = g_object_new (TP_TESTS_TYPE_CONTACT_LIST_MANAGER, - "connection", self, NULL); - - tp_contacts_mixin_init (object, - G_STRUCT_OFFSET (TpTestsContactsConnection, contacts_mixin)); - tp_base_connection_register_with_contacts_mixin (base); - if (self->priv->list_manager) - { - tp_base_contact_list_mixin_register_with_contacts_mixin ( - TP_BASE_CONTACT_LIST (self->priv->list_manager), base); - } - tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_ALIASING1, - aliasing_fill_contact_attributes); - tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_AVATARS1, - avatars_fill_contact_attributes); - tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_LOCATION1, - location_fill_contact_attributes); - tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES1, - contact_caps_fill_contact_attributes); - tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO1, - contact_info_fill_contact_attributes); - tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES1, - client_types_fill_contact_attributes); - - tp_presence_mixin_init (object, - G_STRUCT_OFFSET (TpTestsContactsConnection, presence_mixin)); - tp_presence_mixin_register_with_contacts_mixin (object); -} - -static const TpPresenceStatusOptionalArgumentSpec can_have_message[] = { - { "message", "s", NULL, NULL }, - { NULL } -}; - -/* Must match TpTestsContactsConnectionPresenceStatusIndex in the .h */ -static const TpPresenceStatusSpec my_statuses[] = { - { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, - can_have_message }, - { "busy", TP_CONNECTION_PRESENCE_TYPE_BUSY, TRUE, can_have_message }, - { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, can_have_message }, - { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, NULL }, - { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, NULL }, - { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, NULL }, - { NULL } -}; - -static gboolean -my_status_available (GObject *object, - guint index) -{ - TpBaseConnection *base = TP_BASE_CONNECTION (object); - - return tp_base_connection_check_connected (base, NULL); -} - -static GHashTable * -my_get_contact_statuses (GObject *object, - const GArray *contacts) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - GHashTable *result = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify) tp_presence_status_free); - guint i; - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, TpHandle, i); - gpointer key = GUINT_TO_POINTER (handle); - TpTestsContactsConnectionPresenceStatusIndex index; - const gchar *presence_message; - GHashTable *parameters; - - index = GPOINTER_TO_UINT (g_hash_table_lookup ( - self->priv->presence_statuses, key)); - presence_message = g_hash_table_lookup ( - self->priv->presence_messages, key); - - parameters = g_hash_table_new_full (g_str_hash, - g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); - - if (presence_message != NULL) - g_hash_table_insert (parameters, (gpointer) "message", - tp_g_value_slice_new_string (presence_message)); - - g_hash_table_insert (result, key, - tp_presence_status_new (index, parameters)); - g_hash_table_unref (parameters); - } - - return result; -} - -static gboolean -my_set_own_status (GObject *object, - const TpPresenceStatus *status, - GError **error) -{ - TpBaseConnection *base_conn = TP_BASE_CONNECTION (object); - TpTestsContactsConnectionPresenceStatusIndex index = status->index; - const gchar *message = ""; - TpHandle self_handle; - - if (status->optional_arguments != NULL) - { - message = g_hash_table_lookup (status->optional_arguments, "message"); - - if (message == NULL) - message = ""; - } - - self_handle = tp_base_connection_get_self_handle (base_conn); - tp_tests_contacts_connection_change_presences (TP_TESTS_CONTACTS_CONNECTION (object), - 1, &self_handle, &index, &message); - - return TRUE; -} - -static guint -my_get_maximum_status_message_length_cb (GObject *obj) -{ - return 512; -} - -static GPtrArray * -create_channel_managers (TpBaseConnection *conn) -{ - return g_ptr_array_new (); -} - -static GPtrArray * -tp_tests_contacts_get_interfaces_always_present (TpBaseConnection *base) -{ - GPtrArray *interfaces; - static const gchar *interfaces_always_present[] = { - TP_IFACE_CONNECTION_INTERFACE_ALIASING1, - TP_IFACE_CONNECTION_INTERFACE_AVATARS1, - TP_IFACE_CONNECTION_INTERFACE_CONTACTS, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST1, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS1, - TP_IFACE_CONNECTION_INTERFACE_PRESENCE1, - TP_IFACE_CONNECTION_INTERFACE_LOCATION1, - TP_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES1, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES1, - TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO1, - NULL }; - guint i; - - interfaces = TP_BASE_CONNECTION_CLASS ( - tp_tests_contacts_connection_parent_class)->get_interfaces_always_present (base); - - for (i = 0; interfaces_always_present[i] != NULL; i++) - g_ptr_array_add (interfaces, (gchar *) interfaces_always_present[i]); - - return interfaces; -} - -enum -{ - ALIASING_DP_ALIAS_FLAGS, -}; - -static void -aliasing_get_dbus_property (GObject *object, - GQuark interface, - GQuark name, - GValue *value, - gpointer user_data) -{ - switch (GPOINTER_TO_UINT (user_data)) - { - case ALIASING_DP_ALIAS_FLAGS: - g_value_set_uint (value, TP_CONNECTION_ALIAS_FLAG_USER_SET); - break; - - default: - g_assert_not_reached (); - } -} - -static void -tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) -{ - TpBaseConnectionClass *base_class = - (TpBaseConnectionClass *) klass; - GObjectClass *object_class = (GObjectClass *) klass; - TpPresenceMixinClass *mixin_class; - static TpDBusPropertiesMixinPropImpl aliasing_props[] = { - { "AliasFlags", GUINT_TO_POINTER (ALIASING_DP_ALIAS_FLAGS), NULL }, - { NULL } - }; - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CONNECTION_INTERFACE_AVATARS1, - conn_avatars_properties_getter, - NULL, - conn_avatars_properties, - }, - { TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO1, - conn_contact_info_properties_getter, - NULL, - conn_contact_info_properties, - }, - { TP_IFACE_CONNECTION_INTERFACE_ALIASING1, - aliasing_get_dbus_property, - NULL, - aliasing_props, - }, - { NULL } - }; - - object_class->constructed = constructed; - object_class->finalize = finalize; - g_type_class_add_private (klass, sizeof (TpTestsContactsConnectionPrivate)); - - base_class->get_interfaces_always_present = tp_tests_contacts_get_interfaces_always_present; - base_class->create_channel_managers = create_channel_managers; - - tp_contacts_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsContactsConnectionClass, contacts_mixin)); - - tp_presence_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsContactsConnectionClass, presence_mixin), - my_status_available, my_get_contact_statuses, - my_set_own_status, my_statuses); - mixin_class = TP_PRESENCE_MIXIN_CLASS(klass); - mixin_class->get_maximum_status_message_length = - my_get_maximum_status_message_length_cb; - - tp_presence_mixin_init_dbus_properties (object_class); - - klass->properties_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsContactsConnectionClass, properties_class)); - - tp_base_contact_list_mixin_class_init (base_class); -} - -TpTestsContactListManager * -tp_tests_contacts_connection_get_contact_list_manager ( - TpTestsContactsConnection *self) -{ - return self->priv->list_manager; -} - -/** - * tp_tests_contacts_connection_change_aliases: - * @self: a #TpTestsContactsConnection - * @n: the number of handles - * @handles: (array length=n): the handles - * @aliases: (array length=n): aliases - * - */ -void -tp_tests_contacts_connection_change_aliases (TpTestsContactsConnection *self, - guint n, - const TpHandle *handles, - const gchar * const *aliases) -{ - GHashTable *changes = g_hash_table_new (NULL, NULL); - guint i; - - for (i = 0; i < n; i++) - { - DEBUG ("contact#%u -> %s", handles[i], aliases[i]); - - g_hash_table_insert (self->priv->aliases, - GUINT_TO_POINTER (handles[i]), g_strdup (aliases[i])); - - g_hash_table_insert (changes, - GUINT_TO_POINTER (handles[i]), (gchar *) aliases[i]); - } - - tp_svc_connection_interface_aliasing1_emit_aliases_changed (self, changes); - - g_hash_table_unref (changes); -} - -void -tp_tests_contacts_connection_change_presences ( - TpTestsContactsConnection *self, - guint n, - const TpHandle *handles, - const TpTestsContactsConnectionPresenceStatusIndex *indexes, - const gchar * const *messages) -{ - GHashTable *presences = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify) tp_presence_status_free); - guint i; - - for (i = 0; i < n; i++) - { - GHashTable *parameters; - gpointer key = GUINT_TO_POINTER (handles[i]); - - DEBUG ("contact#%u -> %s \"%s\"", handles[i], - my_statuses[indexes[i]].name, messages[i]); - - g_hash_table_insert (self->priv->presence_statuses, key, - GUINT_TO_POINTER (indexes[i])); - g_hash_table_insert (self->priv->presence_messages, key, - g_strdup (messages[i])); - - parameters = g_hash_table_new_full (g_str_hash, - g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); - - if (messages[i] != NULL && messages[i][0] != '\0') - g_hash_table_insert (parameters, (gpointer) "message", - tp_g_value_slice_new_string (messages[i])); - - g_hash_table_insert (presences, key, tp_presence_status_new (indexes[i], - parameters)); - g_hash_table_unref (parameters); - } - - tp_presence_mixin_emit_presence_update ((GObject *) self, - presences); - g_hash_table_unref (presences); -} - -void -tp_tests_contacts_connection_change_avatar_tokens (TpTestsContactsConnection *self, - guint n, - const TpHandle *handles, - const gchar * const *tokens) -{ - guint i; - - for (i = 0; i < n; i++) - { - DEBUG ("contact#%u -> %s", handles[i], tokens[i]); - g_hash_table_insert (self->priv->avatars, - GUINT_TO_POINTER (handles[i]), avatar_data_new (NULL, NULL, tokens[i])); - tp_svc_connection_interface_avatars1_emit_avatar_updated (self, - handles[i], tokens[i]); - } -} - -void -tp_tests_contacts_connection_change_avatar_data ( - TpTestsContactsConnection *self, - TpHandle handle, - GArray *data, - const gchar *mime_type, - const gchar *token) -{ - g_hash_table_insert (self->priv->avatars, - GUINT_TO_POINTER (handle), avatar_data_new (data, mime_type, token)); - - tp_svc_connection_interface_avatars1_emit_avatar_updated (self, - handle, token); -} - -void -tp_tests_contacts_connection_change_locations (TpTestsContactsConnection *self, - guint n, - const TpHandle *handles, - GHashTable **locations) -{ - guint i; - - for (i = 0; i < n; i++) - { - DEBUG ("contact#%u ->", handles[i]); - tp_asv_dump (locations[i]); - g_hash_table_insert (self->priv->locations, - GUINT_TO_POINTER (handles[i]), g_hash_table_ref (locations[i])); - - tp_svc_connection_interface_location1_emit_location_updated (self, - handles[i], locations[i]); - } -} - -void -tp_tests_contacts_connection_change_capabilities ( - TpTestsContactsConnection *self, - GHashTable *capabilities) -{ - GHashTableIter iter; - gpointer handle, caps; - - g_hash_table_iter_init (&iter, capabilities); - while (g_hash_table_iter_next (&iter, &handle, &caps)) - { - g_hash_table_insert (self->priv->capabilities, - handle, - g_boxed_copy (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, - caps)); - } - - tp_svc_connection_interface_contact_capabilities1_emit_contact_capabilities_changed ( - self, capabilities); -} - -void -tp_tests_contacts_connection_change_contact_info ( - TpTestsContactsConnection *self, - TpHandle handle, - GPtrArray *info) -{ - g_hash_table_insert (self->priv->contact_info, GUINT_TO_POINTER (handle), - g_ptr_array_ref (info)); - - tp_svc_connection_interface_contact_info1_emit_contact_info_changed (self, - handle, info); -} - -void -tp_tests_contacts_connection_set_default_contact_info ( - TpTestsContactsConnection *self, - GPtrArray *info) -{ - if (self->priv->default_contact_info != NULL) - g_ptr_array_unref (self->priv->default_contact_info); - self->priv->default_contact_info = g_ptr_array_ref (info); -} - -static void -my_request_aliases (TpSvcConnectionInterfaceAliasing1 *aliasing, - const GArray *contacts, - DBusGMethodInvocation *context) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (aliasing); - TpBaseConnection *base = TP_BASE_CONNECTION (aliasing); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base, - TP_HANDLE_TYPE_CONTACT); - GPtrArray *result; - gchar **strings; - GError *error = NULL; - guint i; - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - - if (!tp_handles_are_valid (contact_repo, contacts, FALSE, &error)) - { - dbus_g_method_return_error (context, error); - g_error_free (error); - return; - } - - result = g_ptr_array_sized_new (contacts->len + 1); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, TpHandle, i); - const gchar *alias = g_hash_table_lookup (self->priv->aliases, - GUINT_TO_POINTER (handle)); - - if (alias == NULL) - g_ptr_array_add (result, - (gchar *) tp_handle_inspect (contact_repo, handle)); - else - g_ptr_array_add (result, (gchar *) alias); - } - - g_ptr_array_add (result, NULL); - strings = (gchar **) g_ptr_array_free (result, FALSE); - tp_svc_connection_interface_aliasing1_return_from_request_aliases (context, - (const gchar **) strings); - g_free (strings); -} - -static void -my_set_aliases (TpSvcConnectionInterfaceAliasing1 *aliasing, - GHashTable *table, - DBusGMethodInvocation *context) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (aliasing); - TpBaseConnection *base = TP_BASE_CONNECTION (aliasing); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base, - TP_HANDLE_TYPE_CONTACT); - guint n; - GArray *handles; - GPtrArray *aliases; - GHashTableIter iter; - gpointer key, value; - GError *error = NULL; - - /* Convert the hash table to arrays of handles and aliases */ - n = g_hash_table_size (table); - handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), n); - aliases = g_ptr_array_sized_new (n); - g_hash_table_iter_init (&iter, table); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - TpHandle handle = GPOINTER_TO_UINT (key); - - g_array_append_val (handles, handle); - g_ptr_array_add (aliases, value); - } - g_assert_cmpuint (handles->len, ==, n); - g_assert_cmpuint (aliases->len, ==, n); - - /* Verify all handles are valid */ - if (!tp_handles_are_valid (contact_repo, handles, FALSE, &error)) - { - dbus_g_method_return_error (context, error); - g_clear_error (&error); - goto out; - } - - /* Change aliases */ - tp_tests_contacts_connection_change_aliases (self, n, - (const TpHandle *) handles->data, - (const gchar * const *) aliases->pdata); - - tp_svc_connection_interface_aliasing1_return_from_set_aliases (context); - -out: - g_array_unref (handles); - g_ptr_array_unref (aliases); -} - -static void -init_aliasing (gpointer g_iface, - gpointer iface_data) -{ - TpSvcConnectionInterfaceAliasing1Class *klass = g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_aliasing1_implement_##x (\ - klass, my_##x) - IMPLEMENT(request_aliases); - IMPLEMENT(set_aliases); -#undef IMPLEMENT -} - -static void -my_request_avatars (TpSvcConnectionInterfaceAvatars1 *avatars, - const GArray *contacts, - DBusGMethodInvocation *context) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (avatars); - TpBaseConnection *base = TP_BASE_CONNECTION (avatars); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base, - TP_HANDLE_TYPE_CONTACT); - GError *error = NULL; - guint i; - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - - if (!tp_handles_are_valid (contact_repo, contacts, FALSE, &error)) - { - dbus_g_method_return_error (context, error); - g_error_free (error); - return; - } - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, TpHandle, i); - AvatarData *a = g_hash_table_lookup (self->priv->avatars, - GUINT_TO_POINTER (handle)); - - if (a != NULL) - tp_svc_connection_interface_avatars1_emit_avatar_retrieved (self, handle, - a->token, a->data, a->mime_type); - } - - tp_svc_connection_interface_avatars1_return_from_request_avatars (context); -} - -static void -conn_avatars_properties_getter (GObject *object, - GQuark interface, - GQuark name, - GValue *value, - gpointer getter_data) -{ - GQuark q_mime_types = g_quark_from_static_string ( - "SupportedAvatarMIMETypes"); - - if (name == q_mime_types) - { - g_value_set_static_boxed (value, mime_types); - } - else - { - g_value_set_uint (value, GPOINTER_TO_UINT (getter_data)); - } -} - -static void -init_avatars (gpointer g_iface, - gpointer iface_data) -{ - TpSvcConnectionInterfaceAvatars1Class *klass = g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_avatars1_implement_##x (\ - klass, my_##x) - /* IMPLEMENT(get_avatar_requirements); */ - /* IMPLEMENT(request_avatar); */ - IMPLEMENT(request_avatars); - /* IMPLEMENT(set_avatar); */ - /* IMPLEMENT(clear_avatar); */ -#undef IMPLEMENT -} - -static GPtrArray * -lookup_contact_info (TpTestsContactsConnection *self, - TpHandle handle) -{ - GPtrArray *ret = g_hash_table_lookup (self->priv->contact_info, - GUINT_TO_POINTER (handle)); - - if (ret == NULL && self->priv->default_contact_info != NULL) - { - ret = self->priv->default_contact_info; - g_hash_table_insert (self->priv->contact_info, GUINT_TO_POINTER (handle), - g_ptr_array_ref (ret)); - } - - if (ret == NULL) - return g_ptr_array_new (); - - return g_ptr_array_ref (ret); -} - -static void -my_refresh_contact_info (TpSvcConnectionInterfaceContactInfo1 *obj, - const GArray *contacts, - DBusGMethodInvocation *context) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (obj); - TpBaseConnection *base = TP_BASE_CONNECTION (obj); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base, - TP_HANDLE_TYPE_CONTACT); - GError *error = NULL; - guint i; - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - - if (!tp_handles_are_valid (contact_repo, contacts, FALSE, &error)) - { - dbus_g_method_return_error (context, error); - g_error_free (error); - return; - } - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, guint, i); - GPtrArray *arr = lookup_contact_info (self, handle); - - tp_svc_connection_interface_contact_info1_emit_contact_info_changed (self, - handle, arr); - g_ptr_array_unref (arr); - } - - tp_svc_connection_interface_contact_info1_return_from_refresh_contact_info ( - context); -} - -static void -my_request_contact_info (TpSvcConnectionInterfaceContactInfo1 *obj, - guint handle, - DBusGMethodInvocation *context) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (obj); - TpBaseConnection *base = TP_BASE_CONNECTION (obj); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base, - TP_HANDLE_TYPE_CONTACT); - GError *error = NULL; - GPtrArray *ret; - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - - if (!tp_handle_is_valid (contact_repo, handle, &error)) - { - dbus_g_method_return_error (context, error); - g_error_free (error); - return; - } - - ret = lookup_contact_info (self, handle); - - tp_svc_connection_interface_contact_info1_return_from_request_contact_info ( - context, ret); - - g_ptr_array_unref (ret); -} - -static void -my_set_contact_info (TpSvcConnectionInterfaceContactInfo1 *obj, - const GPtrArray *info, - DBusGMethodInvocation *context) -{ - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (obj); - TpBaseConnection *base = TP_BASE_CONNECTION (obj); - GPtrArray *copy; - guint i; - TpHandle self_handle; - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - - /* Deep copy info */ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - copy = g_ptr_array_new_with_free_func ((GDestroyNotify) g_value_array_free); - for (i = 0; i < info->len; i++) - g_ptr_array_add (copy, g_value_array_copy (g_ptr_array_index (info, i))); - G_GNUC_END_IGNORE_DEPRECATIONS - - self_handle = tp_base_connection_get_self_handle (base); - tp_tests_contacts_connection_change_contact_info (self, self_handle, copy); - g_ptr_array_unref (copy); - - tp_svc_connection_interface_contact_info1_return_from_set_contact_info ( - context); -} - -static void -init_contact_info (gpointer g_iface, - gpointer iface_data) -{ - TpSvcConnectionInterfaceContactInfo1Class *klass = g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_contact_info1_implement_##x (\ - klass, my_##x) - IMPLEMENT (refresh_contact_info); - IMPLEMENT (request_contact_info); - IMPLEMENT (set_contact_info); -#undef IMPLEMENT -} diff --git a/tests/lib/contacts-conn.h b/tests/lib/contacts-conn.h deleted file mode 100644 index 679b0eb..0000000 --- a/tests/lib/contacts-conn.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * contacts-conn.h - header for a connection with contact info - * - * 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_CONTACTS_CONN_H__ -#define __TP_TESTS_CONTACTS_CONN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -#include "simple-conn.h" -#include "contact-list-manager.h" - -G_BEGIN_DECLS - -typedef struct _TpTestsContactsConnection TpTestsContactsConnection; -typedef struct _TpTestsContactsConnectionClass TpTestsContactsConnectionClass; -typedef struct _TpTestsContactsConnectionPrivate TpTestsContactsConnectionPrivate; - -struct _TpTestsContactsConnectionClass { - TpTestsSimpleConnectionClass parent_class; - - TpPresenceMixinClass presence_mixin; - TpContactsMixinClass contacts_mixin; - TpDBusPropertiesMixinClass properties_class; - - TpContactsMixinFillContactAttributesFunc fill_client_types; -}; - -struct _TpTestsContactsConnection { - TpTestsSimpleConnection parent; - - TpPresenceMixin presence_mixin; - TpContactsMixin contacts_mixin; - - TpTestsContactsConnectionPrivate *priv; -}; - -GType tp_tests_contacts_connection_get_type (void); - -/* Must match my_statuses in the .c */ -typedef enum { - TP_TESTS_CONTACTS_CONNECTION_STATUS_AVAILABLE, - TP_TESTS_CONTACTS_CONNECTION_STATUS_BUSY, - TP_TESTS_CONTACTS_CONNECTION_STATUS_AWAY, - TP_TESTS_CONTACTS_CONNECTION_STATUS_OFFLINE, - TP_TESTS_CONTACTS_CONNECTION_STATUS_UNKNOWN, - TP_TESTS_CONTACTS_CONNECTION_STATUS_ERROR -} TpTestsContactsConnectionPresenceStatusIndex; - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_CONTACTS_CONNECTION \ - (tp_tests_contacts_connection_get_type ()) -#define TP_TESTS_CONTACTS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_CONTACTS_CONNECTION, \ - TpTestsContactsConnection)) -#define TP_TESTS_CONTACTS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_CONTACTS_CONNECTION, \ - TpTestsContactsConnectionClass)) -#define TP_TESTS_IS_CONTACTS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_CONTACTS_CONNECTION)) -#define TP_TESTS_IS_CONTACTS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_CONTACTS_CONNECTION)) -#define TP_TESTS_CONTACTS_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_CONTACTS_CONNECTION, \ - TpTestsContactsConnectionClass)) - -TpTestsContactListManager *tp_tests_contacts_connection_get_contact_list_manager ( - TpTestsContactsConnection *self); - -void tp_tests_contacts_connection_change_aliases ( - TpTestsContactsConnection *self, guint n, - const TpHandle *handles, const gchar * const *aliases); - -void tp_tests_contacts_connection_change_presences ( - TpTestsContactsConnection *self, guint n, const TpHandle *handles, - const TpTestsContactsConnectionPresenceStatusIndex *indexes, - const gchar * const *messages); - -void tp_tests_contacts_connection_change_avatar_tokens ( - TpTestsContactsConnection *self, guint n, const TpHandle *handles, - const gchar * const *tokens); - -void tp_tests_contacts_connection_change_avatar_data ( - TpTestsContactsConnection *self, - TpHandle handle, - GArray *data, - const gchar *mime_type, - const gchar *token); - -void tp_tests_contacts_connection_change_locations ( - TpTestsContactsConnection *self, - guint n, - const TpHandle *handles, - GHashTable **locations); - -void tp_tests_contacts_connection_change_capabilities ( - TpTestsContactsConnection *self, GHashTable *capabilities); - -void tp_tests_contacts_connection_change_contact_info ( - TpTestsContactsConnection *self, TpHandle handle, GPtrArray *info); - -void tp_tests_contacts_connection_set_default_contact_info ( - TpTestsContactsConnection *self, - GPtrArray *info); - -G_END_DECLS - -#endif /* ifndef __TP_TESTS_CONTACTS_CONN_H__ */ diff --git a/tests/lib/debug.h b/tests/lib/debug.h deleted file mode 100644 index 60e070b..0000000 --- a/tests/lib/debug.h +++ /dev/null @@ -1,3 +0,0 @@ -#undef DEBUG -#define DEBUG(format, ...) \ - g_debug ("%s: " format, G_STRFUNC, ##__VA_ARGS__) diff --git a/tests/lib/echo-chan.c b/tests/lib/echo-chan.c deleted file mode 100644 index 9234a6a..0000000 --- a/tests/lib/echo-chan.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * chan.c - an example text channel talking to a particular - * contact. Similar code is used for 1-1 IM channels in many protocols - * (IRC private messages ("/query"), XMPP IM etc.) - * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 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 "echo-chan.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -static void destroyable_iface_init (gpointer iface, gpointer data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsEchoChannel, - tp_tests_echo_channel, - TP_TYPE_BASE_CHANNEL, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TEXT, - tp_message_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_DESTROYABLE1, - destroyable_iface_init); - ) - -/* type definition stuff */ - -static GPtrArray * -tp_tests_echo_channel_get_interfaces (TpBaseChannel *self) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CHANNEL_CLASS (tp_tests_echo_channel_parent_class)-> - get_interfaces (self); - - g_ptr_array_add (interfaces, TP_IFACE_CHANNEL_INTERFACE_DESTROYABLE1); - return interfaces; -}; - -static void -tp_tests_echo_channel_init (TpTestsEchoChannel *self) -{ -} - -static void text_send (GObject *object, TpMessage *message, - TpMessageSendingFlags flags); - -static void -constructed (GObject *object) -{ - TpTestsEchoChannel *self = TP_TESTS_ECHO_CHANNEL (object); - TpBaseConnection *conn = tp_base_channel_get_connection (TP_BASE_CHANNEL (self)); - const TpChannelTextMessageType types[] = { - TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, - TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION, - TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE, - }; - const gchar * supported_content_types[] = { - "text/plain", - NULL - }; - g_assert (conn != NULL); - - G_OBJECT_CLASS (tp_tests_echo_channel_parent_class)->constructed (object); - - tp_base_channel_register (TP_BASE_CHANNEL (self)); - - tp_message_mixin_init (object, - G_STRUCT_OFFSET (TpTestsEchoChannel, message), - conn); - tp_message_mixin_implement_sending (object, - text_send, G_N_ELEMENTS (types), types, 0, 0, - supported_content_types); -} - -static void -finalize (GObject *object) -{ - tp_message_mixin_finalize (object); - - ((GObjectClass *) tp_tests_echo_channel_parent_class)->finalize (object); -} - -static void -tp_tests_echo_channel_close (TpTestsEchoChannel *self) -{ - GObject *object = (GObject *) self; - gboolean closed = tp_base_channel_is_destroyed (TP_BASE_CHANNEL (self)); - - if (!closed) - { - TpHandle first_sender; - - /* The manager wants to be able to respawn the channel if it has pending - * messages. When respawned, the channel must have the initiator set - * to the contact who sent us those messages (if it isn't already), - * and the messages must be marked as having been rescued so they - * don't get logged twice. */ - if (tp_message_mixin_has_pending_messages (object, &first_sender)) - { - tp_base_channel_reopened (TP_BASE_CHANNEL (self), first_sender); - tp_message_mixin_set_rescued (object); - } - else - { - tp_base_channel_destroyed (TP_BASE_CHANNEL (self)); - } - } -} - -static void -channel_close (TpBaseChannel *channel) -{ - TpTestsEchoChannel *self = TP_TESTS_ECHO_CHANNEL (channel); - - tp_tests_echo_channel_close (self); -} - -static void -tp_tests_echo_channel_class_init (TpTestsEchoChannelClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - - object_class->constructed = constructed; - object_class->finalize = finalize; - - base_class->channel_type = TP_IFACE_CHANNEL_TYPE_TEXT; - base_class->target_handle_type = TP_HANDLE_TYPE_CONTACT; - base_class->get_interfaces = tp_tests_echo_channel_get_interfaces; - base_class->close = channel_close; - - tp_message_mixin_init_dbus_properties (object_class); -} - - -static void -text_send (GObject *object, - TpMessage *message, - TpMessageSendingFlags flags) -{ - TpTestsEchoChannel *self = TP_TESTS_ECHO_CHANNEL (object); - TpChannelTextMessageType type = tp_message_get_message_type (message); - TpChannelTextMessageType echo_type = type; - TpHandle target = tp_base_channel_get_target_handle (TP_BASE_CHANNEL (self)); - gchar *echo; - gint64 now = time (NULL); - const GHashTable *part; - const gchar *text; - TpMessage *msg; - - /* Pretend that the remote contact has replied. Normally, you'd - * call tp_text_mixin_receive or tp_text_mixin_receive_with_flags - * in response to network events */ - - part = tp_message_peek (message, 1); - text = tp_asv_get_string (part, "content"); - - switch (type) - { - case TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL: - echo = g_strdup_printf ("You said: %s", text); - break; - case TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION: - echo = g_strdup_printf ("notices that the user %s", text); - break; - case TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE: - echo = g_strdup_printf ("You sent a notice: %s", text); - break; - default: - echo = g_strdup_printf ("You sent some weird message type, %u: \"%s\"", - type, text); - echo_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; - } - - tp_message_mixin_sent (object, message, 0, "", NULL); - - msg = tp_cm_message_new ( - tp_base_channel_get_connection (TP_BASE_CHANNEL (self)), - 2); - - tp_cm_message_set_sender (msg, target); - tp_message_set_uint32 (msg, 0, "message-type", echo_type); - tp_message_set_int64 (msg, 0, "message-sent", now); - tp_message_set_int64 (msg, 0, "message-received", now); - - tp_message_set_string (msg, 1, "content-type", "text/plain"); - tp_message_set_string (msg, 1, "content", echo); - - tp_message_mixin_take_received (object, msg); - - g_free (echo); -} - -static void -destroyable_destroy (TpSvcChannelInterfaceDestroyable1 *iface, - DBusGMethodInvocation *context) -{ - TpTestsEchoChannel *self = TP_TESTS_ECHO_CHANNEL (iface); - - tp_message_mixin_clear ((GObject *) self); - tp_base_channel_destroyed (TP_BASE_CHANNEL (self)); - - tp_svc_channel_interface_destroyable1_return_from_destroy (context); -} - -static void -destroyable_iface_init (gpointer iface, - gpointer data) -{ - TpSvcChannelInterfaceDestroyable1Class *klass = iface; - -#define IMPLEMENT(x) \ - tp_svc_channel_interface_destroyable1_implement_##x (klass, destroyable_##x) - IMPLEMENT (destroy); -#undef IMPLEMENT -} diff --git a/tests/lib/echo-chan.h b/tests/lib/echo-chan.h deleted file mode 100644 index 5fbe6ee..0000000 --- a/tests/lib/echo-chan.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * chan.h - header for an example channel - * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 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_CHAN_H__ -#define __TP_TESTS_CHAN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsEchoChannel TpTestsEchoChannel; -typedef struct _TpTestsEchoChannelClass TpTestsEchoChannelClass; -typedef struct _TpTestsEchoChannelPrivate TpTestsEchoChannelPrivate; - -GType tp_tests_echo_channel_get_type (void); - -#define TP_TESTS_TYPE_ECHO_CHANNEL \ - (tp_tests_echo_channel_get_type ()) -#define TP_TESTS_ECHO_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TESTS_TYPE_ECHO_CHANNEL, \ - TpTestsEchoChannel)) -#define TP_TESTS_ECHO_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TESTS_TYPE_ECHO_CHANNEL, \ - TpTestsEchoChannelClass)) -#define TP_TESTS_IS_ECHO_CHANNEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TESTS_TYPE_ECHO_CHANNEL)) -#define TP_TESTS_IS_ECHO_CHANNEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TESTS_TYPE_ECHO_CHANNEL)) -#define TP_TESTS_ECHO_CHANNEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_ECHO_CHANNEL, \ - TpTestsEchoChannelClass)) - -struct _TpTestsEchoChannelClass { - TpBaseChannelClass parent_class; - TpDBusPropertiesMixinClass dbus_properties_class; -}; - -struct _TpTestsEchoChannel { - TpBaseChannel parent; - TpMessageMixin message; - - TpTestsEchoChannelPrivate *priv; -}; - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_CHAN_H__ */ diff --git a/tests/lib/logger-test-helper.c b/tests/lib/logger-test-helper.c deleted file mode 100644 index fd20baf..0000000 --- a/tests/lib/logger-test-helper.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * logger-test-helper.c - * - * Copyright (C) 2013 Collabora Ltd. <http://www.collabora.co.uk/> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <config.h> - -#include "logger-test-helper.h" - -#include <stdlib.h> - -#include "util.h" - -void -tpl_test_create_and_prepare_account (TpDBusDaemon *dbus, - TpClientFactory *factory, - const gchar *path, - TpAccount **account, - TpTestsSimpleAccount **account_service) -{ - GError *error = NULL; - GArray *features; - GQuark zero = 0; - - *account_service = g_object_new (TP_TESTS_TYPE_SIMPLE_ACCOUNT, - NULL); - g_assert (*account_service != NULL); - - tp_dbus_daemon_register_object (dbus, path, *account_service); - - *account = tp_client_factory_ensure_account (factory, path, NULL, - &error); - g_assert_no_error (error); - g_assert (*account != NULL); - - features = tp_client_factory_dup_account_features (factory, *account); - g_array_append_val (features, zero); - - tp_tests_proxy_run_until_prepared (*account, (GQuark *) features->data); - g_array_free (features, FALSE); -} - -void -tpl_test_release_account (TpDBusDaemon *dbus, - TpAccount *account, - TpTestsSimpleAccount *account_service) -{ - tp_dbus_daemon_unregister_object (dbus, account_service); - g_object_unref (account_service); - g_object_unref (account); -} - -void -tp_tests_copy_dir (const gchar *from_dir, const gchar *to_dir) -{ - gchar *command; - - // If destination directory exist erase it - command = g_strdup_printf ("rm -rf %s", to_dir); - g_assert (system (command) == 0); - g_free (command); - - command = g_strdup_printf ("cp -r %s %s", from_dir, to_dir); - g_assert (system (command) == 0); - g_free (command); - - // In distcheck mode the files and directory are read-only, fix that - command = g_strdup_printf ("chmod -R +w %s", to_dir); - g_assert (system (command) == 0); - g_free (command); -} diff --git a/tests/lib/logger-test-helper.h b/tests/lib/logger-test-helper.h deleted file mode 100644 index cb836f2..0000000 --- a/tests/lib/logger-test-helper.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * logger-test-helper.h - * - * Copyright (C) 2013 Collabora Ltd. <http://www.collabora.co.uk/> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __LOGGER_TEST_HELPER_H__ -#define __LOGGER_TEST_HELPER_H__ - -#include <telepathy-glib/telepathy-glib.h> - -#include "simple-account.h" - -void tpl_test_create_and_prepare_account (TpDBusDaemon *dbus, - TpClientFactory *factory, - const gchar *path, - TpAccount **account, - TpTestsSimpleAccount **account_service); - -void tpl_test_release_account (TpDBusDaemon *dbus, - TpAccount *account, - TpTestsSimpleAccount *account_service); - -void tp_tests_copy_dir (const gchar *from_dir, const gchar *to_dir); - -#endif diff --git a/tests/lib/room-list-chan.c b/tests/lib/room-list-chan.c deleted file mode 100644 index a3a7a8c..0000000 --- a/tests/lib/room-list-chan.c +++ /dev/null @@ -1,252 +0,0 @@ - -#include "config.h" - -#include "room-list-chan.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -static void room_list_iface_init (gpointer iface, - gpointer data); - -G_DEFINE_TYPE_WITH_CODE (TpTestsRoomListChan, tp_tests_room_list_chan, TP_TYPE_BASE_CHANNEL, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_ROOM_LIST1, room_list_iface_init)) - -enum { - PROP_SERVER = 1, - LAST_PROPERTY, -}; - -/* -enum { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; -*/ - -struct _TpTestsRoomListChanPriv { - gchar *server; - gboolean listing; -}; - -static void -tp_tests_room_list_chan_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (object); - - switch (property_id) - { - case PROP_SERVER: - g_value_set_string (value, self->priv->server); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -tp_tests_room_list_chan_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (object); - - switch (property_id) - { - case PROP_SERVER: - g_assert (self->priv->server == NULL); /* construct only */ - self->priv->server = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -tp_tests_room_list_chan_constructed (GObject *object) -{ - TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (object); - void (*chain_up) (GObject *) = - ((GObjectClass *) tp_tests_room_list_chan_parent_class)->constructed; - - if (chain_up != NULL) - chain_up (object); - - tp_base_channel_register (TP_BASE_CHANNEL (self)); -} - -static void -tp_tests_room_list_chan_finalize (GObject *object) -{ - TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (object); - void (*chain_up) (GObject *) = - ((GObjectClass *) tp_tests_room_list_chan_parent_class)->finalize; - - g_free (self->priv->server); - - if (chain_up != NULL) - chain_up (object); -} - -static void -fill_immutable_properties (TpBaseChannel *chan, - GHashTable *properties) -{ - TpBaseChannelClass *klass = TP_BASE_CHANNEL_CLASS ( - tp_tests_room_list_chan_parent_class); - - klass->fill_immutable_properties (chan, properties); - - tp_dbus_properties_mixin_fill_properties_hash ( - G_OBJECT (chan), properties, - TP_IFACE_CHANNEL_TYPE_ROOM_LIST1, "Server", - NULL); -} - -static void -room_list_chan_close (TpBaseChannel *channel) -{ - tp_base_channel_destroyed (channel); -} - -static void -tp_tests_room_list_chan_class_init ( - TpTestsRoomListChanClass *klass) -{ - GObjectClass *oclass = G_OBJECT_CLASS (klass); - TpBaseChannelClass *base_class = TP_BASE_CHANNEL_CLASS (klass); - GParamSpec *spec; - static TpDBusPropertiesMixinPropImpl room_list_props[] = { - { "Server", "server", NULL, }, - { NULL } - }; - - oclass->get_property = tp_tests_room_list_chan_get_property; - oclass->set_property = tp_tests_room_list_chan_set_property; - oclass->constructed = tp_tests_room_list_chan_constructed; - oclass->finalize = tp_tests_room_list_chan_finalize; - - base_class->channel_type = TP_IFACE_CHANNEL_TYPE_ROOM_LIST1; - base_class->target_handle_type = TP_HANDLE_TYPE_NONE; - base_class->fill_immutable_properties = fill_immutable_properties; - base_class->close = room_list_chan_close; - - spec = g_param_spec_string ("server", "server", - "Server", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (oclass, PROP_SERVER, spec); - - tp_dbus_properties_mixin_implement_interface (oclass, - TP_IFACE_QUARK_CHANNEL_TYPE_ROOM_LIST1, - tp_dbus_properties_mixin_getter_gobject_properties, NULL, - room_list_props); - - g_type_class_add_private (klass, sizeof (TpTestsRoomListChanPriv)); -} - -static void -tp_tests_room_list_chan_init (TpTestsRoomListChan *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_ROOM_LIST_CHAN, TpTestsRoomListChanPriv); -} - -static void -add_room (GPtrArray *rooms) -{ - GHashTable *hash; - - hash = tp_asv_new ( - "handle-name", G_TYPE_STRING, "the handle name", - "name", G_TYPE_STRING, "the name", - "description", G_TYPE_STRING, "the description", - "subject", G_TYPE_STRING, "the subject", - "members", G_TYPE_UINT, 10, - "password", G_TYPE_BOOLEAN, TRUE, - "invite-only", G_TYPE_BOOLEAN, TRUE, - "room-id", G_TYPE_STRING, "the room id", - "server", G_TYPE_STRING, "the server", - NULL); - - g_ptr_array_add (rooms, tp_value_array_build (3, - G_TYPE_UINT, 0, - G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, - TP_HASH_TYPE_STRING_VARIANT_MAP, hash, - G_TYPE_INVALID)); - - g_hash_table_unref (hash); -} - -static gboolean -find_rooms (gpointer data) -{ - TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (data); - GPtrArray *rooms; - - rooms = g_ptr_array_new_with_free_func ((GDestroyNotify) tp_value_array_free); - - /* Find 2 rooms */ - add_room (rooms); - add_room (rooms); - tp_svc_channel_type_room_list1_emit_got_rooms (self, rooms); - g_ptr_array_set_size (rooms, 0); - - /* Find 1 room */ - add_room (rooms); - tp_svc_channel_type_room_list1_emit_got_rooms (self, rooms); - g_ptr_array_unref (rooms); - - return FALSE; -} - -static void -room_list_list_rooms (TpSvcChannelTypeRoomList1 *chan, - DBusGMethodInvocation *context) -{ - TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (chan); - - if (self->priv->listing) - { - GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Already listing" }; - - dbus_g_method_return_error (context, &error); - return; - } - - if (!tp_strdiff (self->priv->server, "ListRoomsFail")) - { - GError error = { TP_ERROR, TP_ERROR_SERVICE_CONFUSED, - "Computer says no" }; - - dbus_g_method_return_error (context, &error); - return; - } - - self->priv->listing = TRUE; - tp_svc_channel_type_room_list1_emit_listing_rooms (self, TRUE); - - g_idle_add (find_rooms, self); - - tp_svc_channel_type_room_list1_return_from_list_rooms (context); -} - -static void -room_list_iface_init (gpointer iface, - gpointer data) -{ - TpSvcChannelTypeRoomList1Class *klass = iface; - -#define IMPLEMENT(x) \ - tp_svc_channel_type_room_list1_implement_##x (klass, room_list_##x) - IMPLEMENT(list_rooms); -#undef IMPLEMENT -} diff --git a/tests/lib/room-list-chan.h b/tests/lib/room-list-chan.h deleted file mode 100644 index 52dbd2e..0000000 --- a/tests/lib/room-list-chan.h +++ /dev/null @@ -1,50 +0,0 @@ - -#ifndef __TP_TESTS_ROOM_LIST_CHAN_H__ -#define __TP_TESTS_ROOM_LIST_CHAN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsRoomListChan TpTestsRoomListChan; -typedef struct _TpTestsRoomListChanClass TpTestsRoomListChanClass; -typedef struct _TpTestsRoomListChanPriv TpTestsRoomListChanPriv; - -struct _TpTestsRoomListChanClass { - TpBaseChannelClass parent_class; - TpDBusPropertiesMixinClass dbus_properties_class; -}; - -struct _TpTestsRoomListChan { - TpBaseChannel parent; - TpTestsRoomListChanPriv *priv; -}; - -GType tp_tests_room_list_chan_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_ROOM_LIST_CHAN \ - (tp_tests_room_list_chan_get_type ()) -#define TP_TESTS_ROOM_LIST_CHAN(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - TP_TESTS_TYPE_ROOM_LIST_CHAN, \ - TpTestsRoomListChan)) -#define TP_TESTS_ROOM_LIST_CHAN_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), \ - TP_TESTS_TYPE_ROOM_LIST_CHAN, \ - TpTestsRoomListChanClass)) -#define TP_TESTS_IS_ROOM_LIST_CHAN(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - TP_TESTS_TYPE_ROOM_LIST_CHAN)) -#define TP_TESTS_IS_ROOM_LIST_CHAN_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), \ - TP_TESTS_TYPE_ROOM_LIST_CHAN)) -#define TP_TESTS_ROOM_LIST_CHAN_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TP_TESTS_TYPE_ROOM_LIST_CHAN, \ - TpTestsRoomListChanClass)) - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_ROOM_LIST_CHAN_H__*/ diff --git a/tests/lib/simple-account-manager.c b/tests/lib/simple-account-manager.c deleted file mode 100644 index e5bddbc..0000000 --- a/tests/lib/simple-account-manager.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * simple-account-manager.c - a simple account manager service. - * - * Copyright (C) 2007-2012 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. - */ - -#include "config.h" - -#include "simple-account-manager.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -static void account_manager_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleAccountManager, - tp_tests_simple_account_manager, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_ACCOUNT_MANAGER, - account_manager_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init) - ) - - -/* TP_IFACE_ACCOUNT_MANAGER is implied */ -static const char *ACCOUNT_MANAGER_INTERFACES[] = { NULL }; - -enum -{ - PROP_0, - PROP_INTERFACES, - PROP_USABLE_ACCOUNTS, - PROP_UNUSABLE_ACCOUNTS, -}; - -struct _TpTestsSimpleAccountManagerPrivate -{ - GPtrArray *usable_accounts; - GPtrArray *unusable_accounts; -}; - -static void -tp_tests_simple_account_manager_create_account (TpSvcAccountManager *svc, - const gchar *in_Connection_Manager, - const gchar *in_Protocol, - const gchar *in_Display_Name, - GHashTable *in_Parameters, - GHashTable *in_Properties, - DBusGMethodInvocation *context) -{ - TpTestsSimpleAccountManager *self = (TpTestsSimpleAccountManager *) svc; - const gchar *out = TP_ACCOUNT_OBJECT_PATH_BASE "gabble/jabber/lospolloshermanos"; - - /* if we have fail=yes as a parameter, make the call fail */ - if (!tp_strdiff (tp_asv_get_string (in_Parameters, "fail"), "yes")) - { - GError e = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "loldongs" }; - dbus_g_method_return_error (context, &e); - return; - } - - self->create_cm = g_strdup (in_Connection_Manager); - self->create_protocol = g_strdup (in_Protocol); - self->create_display_name = g_strdup (in_Display_Name); - self->create_parameters = g_hash_table_ref (in_Parameters); - self->create_properties = g_hash_table_ref (in_Properties); - - tp_svc_account_manager_return_from_create_account (context, out); -} - -static void -account_manager_iface_init (gpointer klass, - gpointer unused G_GNUC_UNUSED) -{ -#define IMPLEMENT(x) tp_svc_account_manager_implement_##x (\ - klass, tp_tests_simple_account_manager_##x) - IMPLEMENT (create_account); -#undef IMPLEMENT -} - - -static void -tp_tests_simple_account_manager_init (TpTestsSimpleAccountManager *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, TpTestsSimpleAccountManagerPrivate); - - self->priv->usable_accounts = g_ptr_array_new_with_free_func (g_free); - self->priv->unusable_accounts = g_ptr_array_new_with_free_func (g_free); -} - -static void -tp_tests_simple_account_manager_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object); - - switch (property_id) { - case PROP_INTERFACES: - g_value_set_boxed (value, ACCOUNT_MANAGER_INTERFACES); - break; - - case PROP_USABLE_ACCOUNTS: - g_value_set_boxed (value, self->priv->usable_accounts); - break; - - case PROP_UNUSABLE_ACCOUNTS: - g_value_set_boxed (value, self->priv->unusable_accounts); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_account_manager_finalize (GObject *object) -{ - TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object); - - g_ptr_array_unref (self->priv->usable_accounts); - g_ptr_array_unref (self->priv->unusable_accounts); - - tp_clear_pointer (&self->create_cm, g_free); - tp_clear_pointer (&self->create_protocol, g_free); - tp_clear_pointer (&self->create_display_name, g_free); - tp_clear_pointer (&self->create_parameters, g_hash_table_unref); - tp_clear_pointer (&self->create_properties, g_hash_table_unref); - - G_OBJECT_CLASS (tp_tests_simple_account_manager_parent_class)->finalize ( - object); -} - -/** - * This class currently only provides the minimum for - * tp_account_manager_prepare to succeed. This turns out to be only a working - * Properties.GetAll(). If we wanted later to check the case where - * tp_account_prepare succeeds, we would need to implement an account object - * too. - */ -static void -tp_tests_simple_account_manager_class_init ( - TpTestsSimpleAccountManagerClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - static TpDBusPropertiesMixinPropImpl am_props[] = { - { "Interfaces", "interfaces", NULL }, - { "UsableAccounts", "usable-accounts", NULL }, - { "UnusableAccounts", "unusable-accounts", NULL }, - /* - { "SupportedAccountProperties", "supported-account-properties", NULL }, - */ - { NULL } - }; - - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_ACCOUNT_MANAGER, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - am_props - }, - { NULL }, - }; - - g_type_class_add_private (klass, sizeof (TpTestsSimpleAccountManagerPrivate)); - object_class->finalize = tp_tests_simple_account_manager_finalize; - object_class->get_property = tp_tests_simple_account_manager_get_property; - - param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", - "In this case we only implement AccountManager, so none.", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); - param_spec = g_param_spec_boxed ("usable-accounts", "Usable accounts", - "The accounts which are usable on this account manager. This may be a lie.", - TP_ARRAY_TYPE_OBJECT_PATH_LIST, - G_PARAM_READABLE); - g_object_class_install_property (object_class, PROP_USABLE_ACCOUNTS, param_spec); - param_spec = g_param_spec_boxed ("unusable-accounts", "Unusable accounts", - "The accounts which are unusable on this account manager. This may be a lie.", - TP_ARRAY_TYPE_OBJECT_PATH_LIST, - G_PARAM_READABLE); - g_object_class_install_property (object_class, PROP_UNUSABLE_ACCOUNTS, param_spec); - - klass->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsSimpleAccountManagerClass, dbus_props_class)); -} - -static void -remove_from_array (GPtrArray *array, const gchar *str) -{ - guint i; - - for (i = 0; i < array->len; i++) - if (!tp_strdiff (str, g_ptr_array_index (array, i))) - { - g_ptr_array_remove_index_fast (array, i); - return; - } -} - -void -tp_tests_simple_account_manager_add_account ( - TpTestsSimpleAccountManager *self, - const gchar *object_path, - gboolean usable) -{ - remove_from_array (self->priv->usable_accounts, object_path); - remove_from_array (self->priv->unusable_accounts, object_path); - - if (usable) - g_ptr_array_add (self->priv->usable_accounts, g_strdup (object_path)); - else - g_ptr_array_add (self->priv->unusable_accounts, g_strdup (object_path)); - - tp_svc_account_manager_emit_account_usability_changed (self, object_path, - usable); -} - -void -tp_tests_simple_account_manager_remove_account ( - TpTestsSimpleAccountManager *self, - const gchar *object_path) -{ - remove_from_array (self->priv->usable_accounts, object_path); - remove_from_array (self->priv->unusable_accounts, object_path); - - tp_svc_account_manager_emit_account_removed (self, object_path); -} diff --git a/tests/lib/simple-account-manager.h b/tests/lib/simple-account-manager.h deleted file mode 100644 index cc65f09..0000000 --- a/tests/lib/simple-account-manager.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * simple-account-manager.h - header for a simple account manager service. - * - * Copyright (C) 2007-2012 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_SIMPLE_ACCOUNT_MANAGER_H__ -#define __TP_TESTS_SIMPLE_ACCOUNT_MANAGER_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - - -G_BEGIN_DECLS - -typedef struct _TpTestsSimpleAccountManager TpTestsSimpleAccountManager; -typedef struct _TpTestsSimpleAccountManagerClass TpTestsSimpleAccountManagerClass; -typedef struct _TpTestsSimpleAccountManagerPrivate TpTestsSimpleAccountManagerPrivate; - -struct _TpTestsSimpleAccountManagerClass { - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; -}; - -struct _TpTestsSimpleAccountManager { - GObject parent; - - gchar *create_cm; - gchar *create_protocol; - gchar *create_display_name; - GHashTable *create_parameters; - GHashTable *create_properties; - - TpTestsSimpleAccountManagerPrivate *priv; -}; - -GType tp_tests_simple_account_manager_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER \ - (tp_tests_simple_account_manager_get_type ()) -#define SIMPLE_ACCOUNT_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, \ - TpTestsSimpleAccountManager)) -#define SIMPLE_ACCOUNT_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, \ - TpTestsSimpleAccountManagerClass)) -#define SIMPLE_IS_ACCOUNT_MANAGER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER)) -#define SIMPLE_IS_ACCOUNT_MANAGER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER)) -#define SIMPLE_ACCOUNT_MANAGER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, \ - TpTestsSimpleAccountManagerClass)) - -void tp_tests_simple_account_manager_add_account ( - TpTestsSimpleAccountManager *self, - const gchar *object_path, - gboolean usable); - -void tp_tests_simple_account_manager_remove_account ( - TpTestsSimpleAccountManager *self, - const gchar *object_path); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_ACCOUNT_MANAGER_H__ */ diff --git a/tests/lib/simple-account.c b/tests/lib/simple-account.c deleted file mode 100644 index 2c6131b..0000000 --- a/tests/lib/simple-account.c +++ /dev/null @@ -1,641 +0,0 @@ -/* - * simple-account.c - a simple account service. - * - * Copyright (C) 2010-2012 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 "simple-account.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -static void account_iface_init (gpointer, gpointer); - -G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleAccount, - tp_tests_simple_account, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_ACCOUNT, - account_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_ACCOUNT_INTERFACE_AVATAR1, - NULL); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_ACCOUNT_INTERFACE_ADDRESSING1, - NULL); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_ACCOUNT_INTERFACE_STORAGE1, - NULL); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, - tp_dbus_properties_mixin_iface_init) - ) - -/* TP_IFACE_ACCOUNT is implied */ -static const char *ACCOUNT_INTERFACES[] = { - TP_IFACE_ACCOUNT_INTERFACE_ADDRESSING1, - TP_IFACE_ACCOUNT_INTERFACE_STORAGE1, - NULL }; - -enum -{ - PROP_0, - PROP_INTERFACES, - PROP_DISPLAY_NAME, - PROP_ICON, - PROP_USABLE, - PROP_ENABLED, - PROP_NICKNAME, - PROP_PARAMETERS, - PROP_AUTOMATIC_PRESENCE, - PROP_CONNECT_AUTO, - PROP_CONNECTION, - PROP_CONNECTION_STATUS, - PROP_CONNECTION_STATUS_REASON, - PROP_CURRENT_PRESENCE, - PROP_REQUESTED_PRESENCE, - PROP_NORMALIZED_NAME, - PROP_HAS_BEEN_ONLINE, - PROP_URI_SCHEMES, - PROP_STORAGE_PROVIDER, - PROP_STORAGE_IDENTIFIER, - PROP_STORAGE_SPECIFIC_INFORMATION, - PROP_STORAGE_RESTRICTIONS, - PROP_AVATAR, - PROP_SUPERSEDES, - N_PROPS -}; - -struct _TpTestsSimpleAccountPrivate -{ - TpConnectionPresenceType presence; - gchar *presence_status; - gchar *presence_msg; - gchar *connection_path; - gboolean enabled; - GPtrArray *uri_schemes; - GHashTable *parameters; -}; - -static void -tp_tests_simple_account_update_parameters (TpSvcAccount *svc, - GHashTable *parameters, - const gchar **unset_parameters, - DBusGMethodInvocation *context) -{ - GPtrArray *reconnect_required = g_ptr_array_new (); - GHashTableIter iter; - gpointer k; - guint i; - - /* We don't actually store any parameters, but for the purposes - * of this method we pretend that every parameter provided is - * valid and requires reconnection. */ - - g_hash_table_iter_init (&iter, parameters); - - while (g_hash_table_iter_next (&iter, &k, NULL)) - g_ptr_array_add (reconnect_required, k); - - for (i = 0; unset_parameters != NULL && unset_parameters[i] != NULL; i++) - g_ptr_array_add (reconnect_required, (gchar *) unset_parameters[i]); - - g_ptr_array_add (reconnect_required, NULL); - - tp_svc_account_return_from_update_parameters (context, - (const gchar **) reconnect_required->pdata); - g_ptr_array_unref (reconnect_required); -} - -static void -account_iface_init (gpointer klass, - gpointer unused G_GNUC_UNUSED) -{ -#define IMPLEMENT(x) tp_svc_account_implement_##x (\ - klass, tp_tests_simple_account_##x) - IMPLEMENT (update_parameters); -#undef IMPLEMENT -} - -/* you may have noticed this is not entirely realistic */ -static const gchar * const uri_schemes[] = { "about", "telnet", NULL }; - -static void -tp_tests_simple_account_init (TpTestsSimpleAccount *self) -{ - guint i; - - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TP_TESTS_TYPE_SIMPLE_ACCOUNT, - TpTestsSimpleAccountPrivate); - - self->priv->presence = TP_CONNECTION_PRESENCE_TYPE_AWAY; - self->priv->presence_status = g_strdup ("currently-away"); - self->priv->presence_msg = g_strdup ("this is my CurrentPresence"); - self->priv->connection_path = g_strdup ("/"); - self->priv->enabled = TRUE; - - self->priv->uri_schemes = g_ptr_array_new_with_free_func (g_free); - for (i = 0; uri_schemes[i] != NULL; i++) - g_ptr_array_add (self->priv->uri_schemes, g_strdup (uri_schemes[i])); - - self->priv->parameters = g_hash_table_new (NULL, NULL); -} - -static void -tp_tests_simple_account_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object); - GValue identifier = { 0, }; - - g_value_init (&identifier, G_TYPE_STRING); - g_value_set_string (&identifier, "unique-identifier"); - - switch (property_id) { - case PROP_INTERFACES: - g_value_set_boxed (value, ACCOUNT_INTERFACES); - break; - case PROP_DISPLAY_NAME: - g_value_set_string (value, "Fake Account"); - break; - case PROP_ICON: - g_value_set_string (value, ""); - break; - case PROP_USABLE: - g_value_set_boolean (value, TRUE); - break; - case PROP_ENABLED: - g_value_set_boolean (value, self->priv->enabled); - break; - case PROP_NICKNAME: - g_value_set_string (value, "badger"); - break; - case PROP_PARAMETERS: - g_value_set_boxed (value, self->priv->parameters); - break; - case PROP_AUTOMATIC_PRESENCE: - g_value_take_boxed (value, tp_value_array_build (3, - G_TYPE_UINT, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, - G_TYPE_STRING, "automatically-available", - G_TYPE_STRING, "this is my AutomaticPresence", - G_TYPE_INVALID)); - break; - case PROP_CONNECT_AUTO: - g_value_set_boolean (value, FALSE); - break; - case PROP_CONNECTION: - g_value_set_boxed (value, self->priv->connection_path); - break; - case PROP_CONNECTION_STATUS: - g_value_set_uint (value, TP_CONNECTION_STATUS_CONNECTED); - break; - case PROP_CONNECTION_STATUS_REASON: - g_value_set_uint (value, TP_CONNECTION_STATUS_REASON_REQUESTED); - break; - case PROP_CURRENT_PRESENCE: - g_value_take_boxed (value, tp_value_array_build (3, - G_TYPE_UINT, self->priv->presence, - G_TYPE_STRING, self->priv->presence_status, - G_TYPE_STRING, self->priv->presence_msg, - G_TYPE_INVALID)); - break; - case PROP_REQUESTED_PRESENCE: - g_value_take_boxed (value, tp_value_array_build (3, - G_TYPE_UINT, TP_CONNECTION_PRESENCE_TYPE_BUSY, - G_TYPE_STRING, "requesting", - G_TYPE_STRING, "this is my RequestedPresence", - G_TYPE_INVALID)); - break; - case PROP_NORMALIZED_NAME: - g_value_set_string (value, "bob.mcbadgers@example.com"); - break; - case PROP_HAS_BEEN_ONLINE: - g_value_set_boolean (value, TRUE); - break; - case PROP_STORAGE_PROVIDER: - g_value_set_string (value, "im.telepathy1.glib.test"); - break; - case PROP_STORAGE_IDENTIFIER: - g_value_set_boxed (value, &identifier); - break; - case PROP_STORAGE_SPECIFIC_INFORMATION: - g_value_take_boxed (value, tp_asv_new ( - "one", G_TYPE_INT, 1, - "two", G_TYPE_UINT, 2, - "marco", G_TYPE_STRING, "polo", - NULL)); - break; - case PROP_STORAGE_RESTRICTIONS: - g_value_set_uint (value, - TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED | - TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS); - break; - case PROP_URI_SCHEMES: - { - GPtrArray *arr; - guint i; - - arr = g_ptr_array_sized_new (self->priv->uri_schemes->len + 1); - for (i = 0; i < self->priv->uri_schemes->len; i++) - g_ptr_array_add (arr, - g_ptr_array_index (self->priv->uri_schemes, i)); - g_ptr_array_add (arr, NULL); - - g_value_set_boxed (value, arr->pdata); - g_ptr_array_unref (arr); - } - break; - case PROP_AVATAR: - { - GArray *arr = g_array_new (FALSE, FALSE, sizeof (char)); - - /* includes NUL for simplicity */ - g_array_append_vals (arr, ":-)", 4); - - g_value_take_boxed (value, - tp_value_array_build (2, - TP_TYPE_UCHAR_ARRAY, arr, - G_TYPE_STRING, "text/plain", - G_TYPE_INVALID)); - g_array_unref (arr); - } - break; - case PROP_SUPERSEDES: - { - GPtrArray *arr = g_ptr_array_new (); - - g_ptr_array_add (arr, - g_strdup (TP_ACCOUNT_OBJECT_PATH_BASE "super/seded/whatever")); - g_value_take_boxed (value, arr); - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } - - g_value_unset (&identifier); -} - -static void -tp_tests_simple_account_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object); - - switch (property_id) - { - case PROP_PARAMETERS: - self->priv->parameters = g_value_dup_boxed (value); - /* In principle we should be emitting AccountPropertyChanged here */ - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - break; - } -} - -static void -tp_tests_simple_account_finalize (GObject *object) -{ - TpTestsSimpleAccount *self = TP_TESTS_SIMPLE_ACCOUNT (object); - - g_free (self->priv->presence_status); - g_free (self->priv->presence_msg); - g_free (self->priv->connection_path); - - g_ptr_array_unref (self->priv->uri_schemes); - g_hash_table_unref (self->priv->parameters); - - G_OBJECT_CLASS (tp_tests_simple_account_parent_class)->finalize (object); -} - -/** - * This class currently only provides the minimum for - * tp_account_prepare to succeed. This turns out to be only a working - * Properties.GetAll(). - */ -static void -tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - static TpDBusPropertiesMixinPropImpl a_props[] = { - { "Interfaces", "interfaces", NULL }, - { "DisplayName", "display-name", NULL }, - { "Icon", "icon", NULL }, - { "Usable", "usable", NULL }, - { "Enabled", "enabled", NULL }, - { "Nickname", "nickname", NULL }, - { "Parameters", "parameters", NULL }, - { "AutomaticPresence", "automatic-presence", NULL }, - { "ConnectAutomatically", "connect-automatically", NULL }, - { "Connection", "connection", NULL }, - { "ConnectionStatus", "connection-status", NULL }, - { "ConnectionStatusReason", "connection-status-reason", NULL }, - { "CurrentPresence", "current-presence", NULL }, - { "RequestedPresence", "requested-presence", NULL }, - { "NormalizedName", "normalized-name", NULL }, - { "HasBeenOnline", "has-been-online", NULL }, - { "Supersedes", "supersedes", NULL }, - { NULL } - }; - - static TpDBusPropertiesMixinPropImpl ais_props[] = { - { "StorageProvider", "storage-provider", NULL }, - { "StorageIdentifier", "storage-identifier", NULL }, - { "StorageSpecificInformation", "storage-specific-information", NULL }, - { "StorageRestrictions", "storage-restrictions", NULL }, - { NULL }, - }; - - static TpDBusPropertiesMixinPropImpl aia_props[] = { - { "URISchemes", "uri-schemes", NULL }, - { NULL }, - }; - - static TpDBusPropertiesMixinPropImpl avatar_props[] = { - { "Avatar", "avatar", NULL }, - { NULL }, - }; - - static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_ACCOUNT, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - a_props - }, - { - TP_IFACE_ACCOUNT_INTERFACE_STORAGE1, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - ais_props - }, - { - TP_IFACE_ACCOUNT_INTERFACE_ADDRESSING1, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - aia_props - }, - { TP_IFACE_ACCOUNT_INTERFACE_AVATAR1, - tp_dbus_properties_mixin_getter_gobject_properties, - NULL, - avatar_props - }, - { NULL }, - }; - - g_type_class_add_private (klass, sizeof (TpTestsSimpleAccountPrivate)); - object_class->get_property = tp_tests_simple_account_get_property; - object_class->set_property = tp_tests_simple_account_set_property; - object_class->finalize = tp_tests_simple_account_finalize; - - param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces", - "In this case we only implement Account, so none.", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_INTERFACES, param_spec); - - param_spec = g_param_spec_string ("display-name", "display name", - "DisplayName property", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DISPLAY_NAME, param_spec); - - param_spec = g_param_spec_string ("icon", "icon", - "Icon property", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ICON, param_spec); - - param_spec = g_param_spec_boolean ("usable", "usable", - "Usable property", - FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_USABLE, param_spec); - - param_spec = g_param_spec_boolean ("enabled", "enabled", - "Enabled property", - FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ENABLED, param_spec); - - param_spec = g_param_spec_string ("nickname", "nickname", - "Nickname property", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_NICKNAME, param_spec); - - param_spec = g_param_spec_boxed ("parameters", "parameters", - "Parameters property", - TP_HASH_TYPE_STRING_VARIANT_MAP, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_PARAMETERS, param_spec); - - param_spec = g_param_spec_boxed ("automatic-presence", "automatic presence", - "AutomaticPresence property", - TP_STRUCT_TYPE_PRESENCE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_AUTOMATIC_PRESENCE, - param_spec); - - param_spec = g_param_spec_boolean ("connect-automatically", - "connect automatically", "ConnectAutomatically property", - FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECT_AUTO, param_spec); - - param_spec = g_param_spec_boxed ("connection", "connection", - "Connection property", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION, param_spec); - - param_spec = g_param_spec_uint ("connection-status", "connection status", - "ConnectionStatus property", - 0, TP_NUM_CONNECTION_STATUSES, TP_CONNECTION_STATUS_DISCONNECTED, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION_STATUS, - param_spec); - - param_spec = g_param_spec_uint ("connection-status-reason", - "connection status reason", "ConnectionStatusReason property", - 0, TP_NUM_CONNECTION_STATUS_REASONS, - TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON, - param_spec); - - param_spec = g_param_spec_boxed ("current-presence", "current presence", - "CurrentPresence property", - TP_STRUCT_TYPE_PRESENCE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CURRENT_PRESENCE, - param_spec); - - param_spec = g_param_spec_boxed ("requested-presence", "requested presence", - "RequestedPresence property", - TP_STRUCT_TYPE_PRESENCE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_REQUESTED_PRESENCE, - param_spec); - - param_spec = g_param_spec_string ("normalized-name", "normalized name", - "NormalizedName property", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_NORMALIZED_NAME, - param_spec); - - param_spec = g_param_spec_boolean ("has-been-online", "has been online", - "HasBeenOnline property", - FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_HAS_BEEN_ONLINE, - param_spec); - - param_spec = g_param_spec_string ("storage-provider", "storage provider", - "StorageProvider property", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STORAGE_PROVIDER, - param_spec); - - param_spec = g_param_spec_boxed ("storage-identifier", "storage identifier", - "StorageIdentifier property", - G_TYPE_VALUE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STORAGE_IDENTIFIER, - param_spec); - - param_spec = g_param_spec_boxed ("storage-specific-information", - "storage specific information", "StorageSpecificInformation property", - TP_HASH_TYPE_STRING_VARIANT_MAP, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, - PROP_STORAGE_SPECIFIC_INFORMATION, param_spec); - - param_spec = g_param_spec_uint ("storage-restrictions", - "storage restrictions", "StorageRestrictions property", - 0, G_MAXUINT, 0, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STORAGE_RESTRICTIONS, - param_spec); - - param_spec = g_param_spec_boxed ("uri-schemes", "URI schemes", - "Some URI schemes", - G_TYPE_STRV, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_URI_SCHEMES, param_spec); - - param_spec = g_param_spec_boxed ("avatar", - "Avatar", "Avatar", - TP_STRUCT_TYPE_AVATAR, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, - PROP_AVATAR, param_spec); - - param_spec = g_param_spec_boxed ("supersedes", - "Supersedes", "List of superseded accounts", - TP_ARRAY_TYPE_OBJECT_PATH_LIST, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, - PROP_SUPERSEDES, param_spec); - - klass->dbus_props_class.interfaces = prop_interfaces; - tp_dbus_properties_mixin_class_init (object_class, - G_STRUCT_OFFSET (TpTestsSimpleAccountClass, dbus_props_class)); -} - -void -tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self, - TpConnectionPresenceType presence, - const gchar *status, - const gchar *message) -{ - GHashTable *props; - GValueArray *v; - - g_free (self->priv->presence_status); - g_free (self->priv->presence_msg); - - self->priv->presence = presence; - self->priv->presence_status = g_strdup (status); - self->priv->presence_msg = g_strdup (message); - - g_object_get (self, "current-presence", &v, NULL); - - props = tp_asv_new ( - "CurrentPresence", TP_STRUCT_TYPE_PRESENCE, v, - NULL); - - tp_svc_account_emit_account_property_changed (self, props); - - g_boxed_free (TP_STRUCT_TYPE_PRESENCE, v); -} - -void -tp_tests_simple_account_set_connection (TpTestsSimpleAccount *self, - const gchar *object_path) -{ - GHashTable *change; - - if (object_path == NULL) - object_path = "/"; - - g_free (self->priv->connection_path); - self->priv->connection_path = g_strdup (object_path); - - change = tp_asv_new (NULL, NULL); - tp_asv_set_string (change, "Connection", object_path); - tp_svc_account_emit_account_property_changed (self, change); - g_hash_table_unref (change); -} - -void -tp_tests_simple_account_removed (TpTestsSimpleAccount *self) -{ - tp_svc_account_emit_removed (self); -} - -void -tp_tests_simple_account_set_enabled (TpTestsSimpleAccount *self, - gboolean enabled) -{ - GHashTable *change; - - self->priv->enabled = enabled; - - change = tp_asv_new (NULL, NULL); - tp_asv_set_boolean (change, "Enabled", enabled); - tp_svc_account_emit_account_property_changed (self, change); - g_hash_table_unref (change); -} - -void -tp_tests_simple_account_add_uri_scheme (TpTestsSimpleAccount *self, - const gchar *uri_scheme) -{ - GHashTable *changed; - GStrv schemes; - - g_ptr_array_add (self->priv->uri_schemes, g_strdup (uri_scheme)); - - g_object_get (self, "uri-schemes", &schemes, NULL); - - changed = tp_asv_new ( - "URISchemes", G_TYPE_STRV, schemes, - NULL); - - tp_svc_dbus_properties_emit_properties_changed (self, - TP_IFACE_ACCOUNT_INTERFACE_ADDRESSING1, changed, NULL); - - g_strfreev (schemes); - g_hash_table_unref (changed); -} diff --git a/tests/lib/simple-account.h b/tests/lib/simple-account.h deleted file mode 100644 index 351c6cc..0000000 --- a/tests/lib/simple-account.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * simple-account.h - header for a simple account service. - * - * Copyright (C) 2010-2012 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. - */ - -#ifndef __TP_TESTS_SIMPLE_ACCOUNT_H__ -#define __TP_TESTS_SIMPLE_ACCOUNT_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsSimpleAccount TpTestsSimpleAccount; -typedef struct _TpTestsSimpleAccountClass TpTestsSimpleAccountClass; -typedef struct _TpTestsSimpleAccountPrivate TpTestsSimpleAccountPrivate; - -struct _TpTestsSimpleAccountClass { - GObjectClass parent_class; - TpDBusPropertiesMixinClass dbus_props_class; -}; - -struct _TpTestsSimpleAccount { - GObject parent; - - TpTestsSimpleAccountPrivate *priv; -}; - -GType tp_tests_simple_account_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_ACCOUNT \ - (tp_tests_simple_account_get_type ()) -#define TP_TESTS_SIMPLE_ACCOUNT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT, \ - TpTestsSimpleAccount)) -#define TP_TESTS_SIMPLE_ACCOUNT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_ACCOUNT, \ - TpTestsSimpleAccountClass)) -#define TP_TESTS_SIMPLE_IS_ACCOUNT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT)) -#define TP_TESTS_SIMPLE_IS_ACCOUNT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_ACCOUNT)) -#define TP_TESTS_SIMPLE_ACCOUNT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_ACCOUNT, \ - TpTestsSimpleAccountClass)) - -void tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self, - TpConnectionPresenceType presence, - const gchar *status, - const gchar *message); - -void tp_tests_simple_account_set_connection (TpTestsSimpleAccount *self, - const gchar *object_path); - -void tp_tests_simple_account_removed (TpTestsSimpleAccount *self); -void tp_tests_simple_account_set_enabled (TpTestsSimpleAccount *self, - gboolean enabled); - -void tp_tests_simple_account_add_uri_scheme (TpTestsSimpleAccount *self, - const gchar * uri_scheme); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_ACCOUNT_H__ */ diff --git a/tests/lib/simple-conn.c b/tests/lib/simple-conn.c deleted file mode 100644 index fa7bfda..0000000 --- a/tests/lib/simple-conn.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - * simple-conn.c - a simple connection - * - * Copyright (C) 2007-2010 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. - */ - -#include "config.h" - -#include "simple-conn.h" - -#include <string.h> - -#include <dbus/dbus-glib.h> - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "echo-chan.h" -#include "room-list-chan.h" -#include "util.h" - -static void props_iface_init (TpSvcDBusPropertiesClass *); - -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, NULL)) - -/* type definition stuff */ - -enum -{ - PROP_ACCOUNT = 1, - PROP_DBUS_STATUS, - N_PROPS -}; - -enum -{ - SIGNAL_GOT_ALL, - N_SIGNALS -}; - -static guint signals[N_SIGNALS] = {0}; - -struct _TpTestsSimpleConnectionPrivate -{ - gchar *account; - guint connect_source; - guint disconnect_source; - - /* TpHandle => reffed TpTestsTextChannelNull */ - GHashTable *text_channels; - TpTestsRoomListChan *room_list_chan; -}; - -static void -tp_tests_simple_connection_init (TpTestsSimpleConnection *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TP_TESTS_TYPE_SIMPLE_CONNECTION, TpTestsSimpleConnectionPrivate); - - self->priv->text_channels = g_hash_table_new_full (NULL, NULL, NULL, - (GDestroyNotify) g_object_unref); -} - -static void -get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (object); - - switch (property_id) { - case PROP_ACCOUNT: - g_value_set_string (value, self->priv->account); - break; - case PROP_DBUS_STATUS: - { - g_value_set_uint (value, - tp_base_connection_get_status (TP_BASE_CONNECTION (self))); - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - } -} - -static void -set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *spec) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (object); - - switch (property_id) { - case PROP_ACCOUNT: - g_free (self->priv->account); - self->priv->account = g_utf8_strdown (g_value_get_string (value), -1); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); - } -} - -static void -dispose (GObject *object) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (object); - - g_hash_table_unref (self->priv->text_channels); - g_clear_object (&self->priv->room_list_chan); - - G_OBJECT_CLASS (tp_tests_simple_connection_parent_class)->dispose (object); -} - -static void -finalize (GObject *object) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (object); - - if (self->priv->connect_source != 0) - { - g_source_remove (self->priv->connect_source); - } - - if (self->priv->disconnect_source != 0) - { - g_source_remove (self->priv->disconnect_source); - } - - g_free (self->priv->account); - - G_OBJECT_CLASS (tp_tests_simple_connection_parent_class)->finalize (object); -} - -static gchar * -get_unique_connection_name (TpBaseConnection *conn) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (conn); - - return g_strdup (self->priv->account); -} - -static gchar * -tp_tests_simple_normalize_contact (TpHandleRepoIface *repo, - const gchar *id, - gpointer context, - GError **error) -{ - if (id[0] == '\0') - { - g_set_error (error, TP_ERROR, TP_ERROR_INVALID_HANDLE, - "ID must not be empty"); - return NULL; - } - - if (strchr (id, ' ') != NULL) - { - g_set_error (error, TP_ERROR, TP_ERROR_INVALID_HANDLE, - "ID must not contain spaces"); - return NULL; - } - - return g_utf8_strdown (id, -1); -} - -static void -create_handle_repos (TpBaseConnection *conn, - TpHandleRepoIface *repos[TP_NUM_HANDLE_TYPES]) -{ - repos[TP_HANDLE_TYPE_CONTACT] = tp_dynamic_handle_repo_new - (TP_HANDLE_TYPE_CONTACT, tp_tests_simple_normalize_contact, NULL); - repos[TP_HANDLE_TYPE_ROOM] = tp_dynamic_handle_repo_new - (TP_HANDLE_TYPE_ROOM, NULL, NULL); -} - -static GPtrArray * -create_channel_managers (TpBaseConnection *conn) -{ - return g_ptr_array_sized_new (0); -} - -void -tp_tests_simple_connection_inject_disconnect (TpTestsSimpleConnection *self) -{ - tp_base_connection_change_status ((TpBaseConnection *) self, - TP_CONNECTION_STATUS_DISCONNECTED, - TP_CONNECTION_STATUS_REASON_REQUESTED); -} - -static gboolean -pretend_connected (gpointer data) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (data); - TpBaseConnection *conn = (TpBaseConnection *) self; - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn, - TP_HANDLE_TYPE_CONTACT); - TpHandle self_handle; - - self_handle = tp_handle_ensure (contact_repo, self->priv->account, - NULL, NULL); - tp_base_connection_set_self_handle (conn, self_handle); - - if (tp_base_connection_get_status (conn) == TP_CONNECTION_STATUS_CONNECTING) - { - tp_base_connection_change_status (conn, TP_CONNECTION_STATUS_CONNECTED, - TP_CONNECTION_STATUS_REASON_REQUESTED); - } - - self->priv->connect_source = 0; - return FALSE; -} - -static gboolean -start_connecting (TpBaseConnection *conn, - GError **error) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (conn); - - tp_base_connection_change_status (conn, TP_CONNECTION_STATUS_CONNECTING, - TP_CONNECTION_STATUS_REASON_REQUESTED); - - /* In a real connection manager we'd ask the underlying implementation to - * start connecting, then go to state CONNECTED when finished. Here there - * isn't actually a connection, so we'll fake a connection process that - * takes time. */ - self->priv->connect_source = g_timeout_add (0, pretend_connected, self); - - return TRUE; -} - -static gboolean -pretend_disconnected (gpointer data) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (data); - - /* We are disconnected, all our channels are invalidated */ - g_hash_table_remove_all (self->priv->text_channels); - g_clear_object (&self->priv->room_list_chan); - - tp_base_connection_finish_shutdown (TP_BASE_CONNECTION (data)); - self->priv->disconnect_source = 0; - return FALSE; -} - -static void -shut_down (TpBaseConnection *conn) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (conn); - - /* In a real connection manager we'd ask the underlying implementation to - * start shutting down, then call this function when finished. Here there - * isn't actually a connection, so we'll fake a disconnection process that - * takes time. */ - self->priv->disconnect_source = g_timeout_add (0, pretend_disconnected, - conn); -} - -static GPtrArray * -get_interfaces_always_present (TpBaseConnection *base) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CONNECTION_CLASS ( - tp_tests_simple_connection_parent_class)->get_interfaces_always_present (base); - - g_ptr_array_add (interfaces, TP_IFACE_CONNECTION_INTERFACE_REQUESTS); - - return interfaces; -} - -static void -tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) -{ - TpBaseConnectionClass *base_class = - (TpBaseConnectionClass *) klass; - GObjectClass *object_class = (GObjectClass *) klass; - GParamSpec *param_spec; - - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->dispose = dispose; - object_class->finalize = finalize; - g_type_class_add_private (klass, sizeof (TpTestsSimpleConnectionPrivate)); - - base_class->create_handle_repos = create_handle_repos; - base_class->get_unique_connection_name = get_unique_connection_name; - base_class->create_channel_managers = create_channel_managers; - base_class->start_connecting = start_connecting; - base_class->shut_down = shut_down; - - base_class->get_interfaces_always_present = get_interfaces_always_present; - - param_spec = g_param_spec_string ("account", "Account name", - "The username of this user", NULL, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_uint ("dbus-status", - "Connection.Status", - "The connection status as visible on D-Bus (overridden so can break it)", - TP_CONNECTION_STATUS_CONNECTED, G_MAXUINT, - TP_CONNECTION_STATUS_DISCONNECTED, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DBUS_STATUS, param_spec); - - 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 -tp_tests_simple_connection_set_identifier (TpTestsSimpleConnection *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); -} - -TpTestsSimpleConnection * -tp_tests_simple_connection_new (const gchar *account, - const gchar *protocol) -{ - return TP_TESTS_SIMPLE_CONNECTION (g_object_new ( - TP_TESTS_TYPE_SIMPLE_CONNECTION, - "account", account, - "protocol", protocol, - NULL)); -} - -gchar * -tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self, - const gchar *target_id, - GHashTable **props) -{ - TpTestsEchoChannel *chan; - gchar *chan_path; - TpHandleRepoIface *contact_repo; - TpHandle handle; - TpBaseConnection *base_conn = (TpBaseConnection *) self; - - /* Get contact handle */ - contact_repo = tp_base_connection_get_handles (base_conn, - TP_HANDLE_TYPE_CONTACT); - g_assert (contact_repo != NULL); - - handle = tp_handle_ensure (contact_repo, target_id, NULL, NULL); - - chan = g_hash_table_lookup (self->priv->text_channels, - GUINT_TO_POINTER (handle)); - if (chan == NULL) - { - chan = TP_TESTS_ECHO_CHANNEL ( - tp_tests_object_new_static_class ( - TP_TESTS_TYPE_ECHO_CHANNEL, - "connection", self, - "handle", handle, - NULL)); - - g_hash_table_insert (self->priv->text_channels, GUINT_TO_POINTER (handle), - chan); - } - - g_object_get (chan, "object-path", &chan_path, NULL); - - if (props != NULL) - g_object_get (chan, "channel-properties", props, NULL); - - return chan_path; -} - -static void -room_list_chan_closed_cb (TpBaseChannel *channel, - TpTestsSimpleConnection *self) -{ - g_clear_object (&self->priv->room_list_chan); -} - -gchar * -tp_tests_simple_connection_ensure_room_list_chan (TpTestsSimpleConnection *self, - const gchar *server, - GHashTable **props) -{ - gchar *chan_path; - TpBaseConnection *base_conn = (TpBaseConnection *) self; - - if (self->priv->room_list_chan != NULL) - { - /* Channel already exist, reuse it */ - g_object_get (self->priv->room_list_chan, - "object-path", &chan_path, NULL); - } - else - { - chan_path = g_strdup_printf ("%s/RoomListChannel", - tp_base_connection_get_object_path (base_conn)); - - self->priv->room_list_chan = TP_TESTS_ROOM_LIST_CHAN ( - tp_tests_object_new_static_class ( - TP_TESTS_TYPE_ROOM_LIST_CHAN, - "connection", self, - "object-path", chan_path, - "server", server ? server : "", - NULL)); - - g_signal_connect (self->priv->room_list_chan, "closed", - G_CALLBACK (room_list_chan_closed_cb), self); - } - - if (props != NULL) - g_object_get (self->priv->room_list_chan, - "channel-properties", props, NULL); - - return chan_path; -} - -static void -get_all (TpSvcDBusProperties *iface, - const gchar *interface_name, - DBusGMethodInvocation *context) -{ - GHashTable *values = tp_dbus_properties_mixin_dup_all (G_OBJECT (iface), - interface_name); - - 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)); -} - -static void -props_iface_init (TpSvcDBusPropertiesClass *iface) -{ -#define IMPLEMENT(x) \ - tp_svc_dbus_properties_implement_##x (iface, x) - IMPLEMENT (get_all); -#undef IMPLEMENT -} diff --git a/tests/lib/simple-conn.h b/tests/lib/simple-conn.h deleted file mode 100644 index ffe5778..0000000 --- a/tests/lib/simple-conn.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * simple-conn.h - header for a simple connection - * - * 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_SIMPLE_CONN_H__ -#define __TP_TESTS_SIMPLE_CONN_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -typedef struct _TpTestsSimpleConnection TpTestsSimpleConnection; -typedef struct _TpTestsSimpleConnectionClass TpTestsSimpleConnectionClass; -typedef struct _TpTestsSimpleConnectionPrivate TpTestsSimpleConnectionPrivate; - -struct _TpTestsSimpleConnectionClass { - TpBaseConnectionClass parent_class; -}; - -struct _TpTestsSimpleConnection { - TpBaseConnection parent; - - TpTestsSimpleConnectionPrivate *priv; -}; - -GType tp_tests_simple_connection_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_SIMPLE_CONNECTION \ - (tp_tests_simple_connection_get_type ()) -#define TP_TESTS_SIMPLE_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_SIMPLE_CONNECTION, \ - TpTestsSimpleConnection)) -#define TP_TESTS_SIMPLE_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_SIMPLE_CONNECTION, \ - TpTestsSimpleConnectionClass)) -#define TP_TESTS_SIMPLE_IS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_SIMPLE_CONNECTION)) -#define TP_TESTS_SIMPLE_IS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_SIMPLE_CONNECTION)) -#define TP_TESTS_SIMPLE_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_SIMPLE_CONNECTION, \ - TpTestsSimpleConnectionClass)) - -TpTestsSimpleConnection * tp_tests_simple_connection_new (const gchar *account, - const gchar *protocol); - -/* Cause "network events", for debugging/testing */ - -void tp_tests_simple_connection_inject_disconnect ( - TpTestsSimpleConnection *self); - -void tp_tests_simple_connection_set_identifier (TpTestsSimpleConnection *self, - const gchar *identifier); - -gchar * tp_tests_simple_connection_ensure_text_chan ( - TpTestsSimpleConnection *self, - const gchar *target_id, - GHashTable **props); - -gchar * tp_tests_simple_connection_ensure_room_list_chan ( - TpTestsSimpleConnection *self, - const gchar *server, - GHashTable **props); - -G_END_DECLS - -#endif /* #ifndef __TP_TESTS_SIMPLE_CONN_H__ */ diff --git a/tests/lib/util.c b/tests/lib/util.c deleted file mode 100644 index 67af4e0..0000000 --- a/tests/lib/util.c +++ /dev/null @@ -1,712 +0,0 @@ -/* Simple utility code used by the regression tests. - * - * Copyright © 2008-2010 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright © 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 "util.h" - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include <glib/gstdio.h> -#include <string.h> - -#ifdef G_OS_UNIX -# include <unistd.h> /* for alarm() */ -#endif - -#ifdef HAVE_GIO_UNIX -#include <gio/gunixsocketaddress.h> -#include <gio/gunixconnection.h> -#endif - -void -tp_tests_proxy_run_until_prepared (gpointer proxy, - const GQuark *features) -{ - GError *error = NULL; - - tp_tests_proxy_run_until_prepared_or_failed (proxy, features, &error); - g_assert_no_error (error); -} - -/* A GAsyncReadyCallback whose user_data is a GAsyncResult **. It writes a - * reference to the result into that pointer. */ -void -tp_tests_result_ready_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - GAsyncResult **result = user_data; - - *result = g_object_ref (res); -} - -/* Run until *result contains a result. Intended to be used with a pending - * async call that uses tp_tests_result_ready_cb. */ -void -tp_tests_run_until_result (GAsyncResult **result) -{ - /* not synchronous */ - g_assert (*result == NULL); - - while (*result == NULL) - g_main_context_iteration (NULL, TRUE); -} - -gboolean -tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy, - const GQuark *features, - GError **error) -{ - GAsyncResult *result = NULL; - gboolean r; - - tp_proxy_prepare_async (proxy, features, tp_tests_result_ready_cb, &result); - - tp_tests_run_until_result (&result); - - r = tp_proxy_prepare_finish (proxy, result, error); - g_object_unref (result); - return r; -} - -static GTestDBus *test_dbus = NULL; - -static void -start_dbus_session (void) -{ - g_assert (test_dbus == NULL); - - g_type_init (); - - /* Make sure we won't be using user's bus. This unsets more than - * g_test_dbus_unset() currently does (glib 2.36) */ - g_unsetenv ("DISPLAY"); - g_unsetenv ("DBUS_STARTER_ADDRESS"); - g_unsetenv ("DBUS_STARTER_BUS_TYPE"); - g_unsetenv ("DBUS_SESSION_BUS_ADDRESS"); - - test_dbus = g_test_dbus_new (G_TEST_DBUS_NONE); - g_test_dbus_add_service_dir (test_dbus, g_getenv ("TP_TESTS_SERVICES_DIR")); - g_test_dbus_up (test_dbus); -} - -static void -stop_dbus_session (void) -{ - g_assert (test_dbus != NULL); - g_test_dbus_down (test_dbus); - g_clear_object (&test_dbus); -} - -gint -tp_tests_run_with_bus (void) -{ - gint ret; - - if (test_dbus != NULL) - return g_test_run (); - - start_dbus_session (); - ret = g_test_run (); - stop_dbus_session (); - - return ret; -} - -TpDBusDaemon * -tp_tests_dbus_daemon_dup_or_die (void) -{ - TpDBusDaemon *d; - - if (test_dbus == NULL) - { - /* HACK: Some tests are not yet ported to GTest and thus are not using - * tp_tests_run_with_bus(). In that case we make sure to start the dbus - * session before aquiring the TpDBusDaemon and we stop the session when - * the daemon is disposed. In a perfect world this should not be needed. - */ - start_dbus_session (); - d = tp_dbus_daemon_dup (NULL); - g_object_weak_ref ((GObject *) d, (GWeakNotify) stop_dbus_session, NULL); - } - else - { - d = tp_dbus_daemon_dup (NULL); - } - - /* In a shared library, this would be very bad (see fd.o #18832), but in a - * regression test that's going to be run under a temporary session bus, - * it's just what we want. */ - if (d == NULL) - { - g_error ("Unable to connect to session bus"); - } - - return d; -} - -static void -introspect_cb (TpProxy *proxy G_GNUC_UNUSED, - const gchar *xml G_GNUC_UNUSED, - const GError *error G_GNUC_UNUSED, - gpointer user_data, - GObject *weak_object G_GNUC_UNUSED) -{ - g_main_loop_quit (user_data); -} - -void -tp_tests_proxy_run_until_dbus_queue_processed (gpointer proxy) -{ - GMainLoop *loop = g_main_loop_new (NULL, FALSE); - - tp_cli_dbus_introspectable_call_introspect (proxy, -1, introspect_cb, - loop, NULL, NULL); - g_main_loop_run (loop); - g_main_loop_unref (loop); -} - -void -_test_assert_empty_strv (const char *file, - int line, - gconstpointer strv) -{ - const gchar * const *strings = strv; - - if (strv != NULL && strings[0] != NULL) - { - guint i; - - g_message ("%s:%d: expected empty strv, but got:", file, line); - - for (i = 0; strings[i] != NULL; i++) - { - g_message ("* \"%s\"", strings[i]); - } - - g_error ("%s:%d: strv wasn't empty (see above for contents", - file, line); - } -} - -void -_tp_tests_assert_strv_equals (const char *file, - int line, - const char *expected_desc, - gconstpointer expected_strv, - const char *actual_desc, - gconstpointer actual_strv) -{ - const gchar * const *expected = expected_strv; - const gchar * const *actual = actual_strv; - guint i; - - g_assert (expected != NULL); - g_assert (actual != NULL); - - for (i = 0; expected[i] != NULL || actual[i] != NULL; i++) - { - if (expected[i] == NULL) - { - g_error ("%s:%d: assertion failed: (%s)[%u] == (%s)[%u]: " - "NULL == %s", file, line, expected_desc, i, - actual_desc, i, actual[i]); - } - else if (actual[i] == NULL) - { - g_error ("%s:%d: assertion failed: (%s)[%u] == (%s)[%u]: " - "%s == NULL", file, line, expected_desc, i, - actual_desc, i, expected[i]); - } - else if (tp_strdiff (expected[i], actual[i])) - { - g_error ("%s:%d: assertion failed: (%s)[%u] == (%s)[%u]: " - "%s == %s", file, line, expected_desc, i, - actual_desc, i, expected[i], actual[i]); - } - } -} - -void -_tp_tests_assert_bytes_equal (const gchar *file, int line, - GBytes *actual, gconstpointer expected_data, - gsize expected_length) -{ - if (expected_length != g_bytes_get_size (actual)) - { - g_error ("%s:%d: assertion failed: expected %"G_GSIZE_FORMAT - " bytes, got %"G_GSIZE_FORMAT, - file, line, expected_length, g_bytes_get_size (actual)); - } - else if (memcmp (g_bytes_get_data (actual, NULL), - expected_data, expected_length) != 0) - { - g_error ( - "%s:%d: assertion failed: expected data didn't match the actual data", - file, line); - } -} - -void -tp_tests_create_conn (GType conn_type, - const gchar *account, - gboolean connect, - TpBaseConnection **service_conn, - TpConnection **client_conn) -{ - TpDBusDaemon *dbus; - gchar *name; - gchar *conn_path; - GError *error = NULL; - - g_assert (service_conn != NULL); - g_assert (client_conn != NULL); - - dbus = tp_tests_dbus_daemon_dup_or_die (); - - *service_conn = tp_tests_object_new_static_class ( - conn_type, - "account", account, - "protocol", "simple", - NULL); - g_assert (*service_conn != NULL); - - g_assert (tp_base_connection_register (*service_conn, "simple", - &name, &conn_path, &error)); - g_assert_no_error (error); - - *client_conn = tp_tests_connection_new (dbus, NULL, conn_path, &error); - g_assert (*client_conn != NULL); - g_assert_no_error (error); - - if (connect) - { - GQuark conn_features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 }; - - tp_cli_connection_call_connect (*client_conn, -1, NULL, NULL, NULL, NULL); - tp_tests_proxy_run_until_prepared (*client_conn, conn_features); - } - - g_free (name); - g_free (conn_path); - - g_object_unref (dbus); -} - -void -tp_tests_create_and_connect_conn (GType conn_type, - const gchar *account, - TpBaseConnection **service_conn, - TpConnection **client_conn) -{ - tp_tests_create_conn (conn_type, account, TRUE, service_conn, client_conn); -} - -/* This object exists solely so that tests/tests.supp can ignore "leaked" - * classes. */ -gpointer -tp_tests_object_new_static_class (GType type, - ...) -{ - va_list ap; - GObject *object; - const gchar *first_property; - - va_start (ap, type); - first_property = va_arg (ap, const gchar *); - object = g_object_new_valist (type, first_property, ap); - va_end (ap); - return object; -} - -static gboolean -time_out (gpointer nil G_GNUC_UNUSED) -{ - g_error ("Timed out"); - g_assert_not_reached (); - return FALSE; -} - -void -tp_tests_abort_after (guint sec) -{ - gboolean debugger = FALSE; - gchar *contents; - - if (g_file_get_contents ("/proc/self/status", &contents, NULL, NULL)) - { -/* http://www.youtube.com/watch?v=SXmv8quf_xM */ -#define TRACER_T "\nTracerPid:\t" - gchar *line = strstr (contents, TRACER_T); - - if (line != NULL) - { - gchar *value = line + strlen (TRACER_T); - - if (value[0] != '0' || value[1] != '\n') - debugger = TRUE; - } - - g_free (contents); - } - - if (g_getenv ("TP_TESTS_NO_TIMEOUT") != NULL || debugger) - return; - - g_timeout_add_seconds (sec, time_out, NULL); - -#ifdef G_OS_UNIX - /* On Unix, we can kill the process more reliably; this is a safety-catch - * in case it deadlocks or something, in which case the main loop won't be - * processed. The default handler for SIGALRM is process termination. */ - alarm (sec + 2); -#endif -} - -void -tp_tests_init (int *argc, - char ***argv) -{ - g_type_init (); - tp_tests_abort_after (10); - tp_debug_set_flags ("all"); - - g_test_init (argc, argv, NULL); -} - -void -_tp_destroy_socket_control_list (gpointer data) -{ - GArray *tab = data; - g_array_unref (tab); -} - -GValue * -_tp_create_local_socket (TpSocketAddressType address_type, - TpSocketAccessControl access_control, - GSocketService **service, - gchar **unix_address, - gchar **unix_tmpdir, - GError **error) -{ - gboolean success; - GSocketAddress *address, *effective_address; - GValue *address_gvalue; - - g_assert (service != NULL); - g_assert (unix_address != NULL); - - switch (access_control) - { - case TP_SOCKET_ACCESS_CONTROL_LOCALHOST: - case TP_SOCKET_ACCESS_CONTROL_CREDENTIALS: - case TP_SOCKET_ACCESS_CONTROL_PORT: - break; - - default: - g_assert_not_reached (); - } - - switch (address_type) - { -#ifdef HAVE_GIO_UNIX - case TP_SOCKET_ADDRESS_TYPE_UNIX: - { - GError *e = NULL; - gchar *dir = g_dir_make_tmp ("tp-glib-tests.XXXXXX", &e); - gchar *name; - - g_assert_no_error (e); - - name = g_build_filename (dir, "s", NULL); - address = g_unix_socket_address_new (name); - g_free (name); - - if (unix_tmpdir != NULL) - *unix_tmpdir = dir; - else - g_free (dir); - break; - } -#endif - - case TP_SOCKET_ADDRESS_TYPE_IPV4: - case TP_SOCKET_ADDRESS_TYPE_IPV6: - { - GInetAddress *localhost; - - localhost = g_inet_address_new_loopback ( - address_type == TP_SOCKET_ADDRESS_TYPE_IPV4 ? - G_SOCKET_FAMILY_IPV4 : G_SOCKET_FAMILY_IPV6); - address = g_inet_socket_address_new (localhost, 0); - - g_object_unref (localhost); - break; - } - - default: - g_assert_not_reached (); - } - - *service = g_socket_service_new (); - - success = g_socket_listener_add_address ( - G_SOCKET_LISTENER (*service), - address, G_SOCKET_TYPE_STREAM, - G_SOCKET_PROTOCOL_DEFAULT, - NULL, &effective_address, NULL); - g_assert (success); - - switch (address_type) - { -#ifdef HAVE_GIO_UNIX - case TP_SOCKET_ADDRESS_TYPE_UNIX: - *unix_address = g_strdup (g_unix_socket_address_get_path ( - G_UNIX_SOCKET_ADDRESS (effective_address))); - address_gvalue = tp_g_value_slice_new_bytes ( - g_unix_socket_address_get_path_len ( - G_UNIX_SOCKET_ADDRESS (effective_address)), - g_unix_socket_address_get_path ( - G_UNIX_SOCKET_ADDRESS (effective_address))); - break; -#endif - - case TP_SOCKET_ADDRESS_TYPE_IPV4: - case TP_SOCKET_ADDRESS_TYPE_IPV6: - *unix_address = NULL; - - address_gvalue = tp_g_value_slice_new_take_boxed ( - TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4, - dbus_g_type_specialized_construct ( - TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4)); - - dbus_g_type_struct_set (address_gvalue, - 0, address_type == TP_SOCKET_ADDRESS_TYPE_IPV4 ? - "127.0.0.1" : "::1", - 1, g_inet_socket_address_get_port ( - G_INET_SOCKET_ADDRESS (effective_address)), - G_MAXUINT); - break; - - default: - g_assert_not_reached (); - } - - g_object_unref (address); - g_object_unref (effective_address); - return address_gvalue; -} - -void -tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection) -{ - GAsyncResult *result = NULL; - GError *error = NULL; - gboolean ok; - - tp_connection_disconnect_async (connection, tp_tests_result_ready_cb, - &result); - tp_tests_run_until_result (&result); - ok = tp_connection_disconnect_finish (connection, result, &error); - g_assert_no_error (error); - g_assert (ok); - g_object_unref (result); -} - -static void -one_contact_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - TpConnection *connection = (TpConnection *) object; - TpContact **contact_loc = user_data; - GError *error = NULL; - - *contact_loc = tp_connection_dup_contact_by_id_finish (connection, result, - &error); - - g_assert_no_error (error); - g_assert (TP_IS_CONTACT (*contact_loc)); -} - -TpContact * -tp_tests_connection_run_until_contact_by_id (TpConnection *connection, - const gchar *id, - const GQuark *features) -{ - TpContact *contact = NULL; - - tp_connection_dup_contact_by_id_async (connection, id, features, - one_contact_cb, &contact); - - while (contact == NULL) - g_main_context_iteration (NULL, TRUE); - - return contact; -} - -void -tp_tests_channel_assert_expect_members (TpChannel *channel, - TpIntset *expected_members) -{ - GPtrArray *contacts; - TpIntset *members; - guint i; - - members = tp_intset_new (); - contacts = tp_channel_group_dup_members (channel); - if (contacts != NULL) - { - for (i = 0; i < contacts->len; i++) - { - TpContact *contact = g_ptr_array_index (contacts, i); - tp_intset_add (members, tp_contact_get_handle (contact)); - } - } - - g_assert (tp_intset_is_equal (members, expected_members)); - - g_ptr_array_unref (contacts); - tp_intset_destroy (members); -} - -TpConnection * -tp_tests_connection_new (TpDBusDaemon *dbus, - const gchar *bus_name, - const gchar *object_path, - GError **error) -{ - TpClientFactory *factory; - gchar *dup_path = NULL; - TpConnection *ret = NULL; - - g_return_val_if_fail (TP_IS_DBUS_DAEMON (dbus), NULL); - g_return_val_if_fail (object_path != NULL || - (bus_name != NULL && bus_name[0] != ':'), NULL); - - if (object_path == NULL) - { - dup_path = g_strdelimit (g_strdup_printf ("/%s", bus_name), ".", '/'); - object_path = dup_path; - } - - if (!tp_dbus_check_valid_object_path (object_path, error)) - goto finally; - - factory = tp_automatic_client_factory_new (dbus); - ret = tp_client_factory_ensure_connection (factory, - object_path, NULL, error); - g_object_unref (factory); - -finally: - g_free (dup_path); - - return ret; -} - -TpAccount * -tp_tests_account_new (TpDBusDaemon *dbus, - const gchar *object_path, - GError **error) -{ - TpClientFactory *factory; - TpAccount *ret; - - if (!tp_dbus_check_valid_object_path (object_path, error)) - return NULL; - - factory = tp_automatic_client_factory_new (dbus); - ret = tp_client_factory_ensure_account (factory, - object_path, NULL, error); - g_object_unref (factory); - - return ret; -} - -TpChannel * -tp_tests_channel_new (TpConnection *conn, - const gchar *object_path, - const gchar *optional_channel_type, - TpHandleType optional_handle_type, - TpHandle optional_handle, - GError **error) -{ - TpChannel *ret; - GHashTable *asv; - - asv = tp_asv_new (NULL, NULL); - - if (optional_channel_type != NULL) - { - tp_asv_set_string (asv, - TP_PROP_CHANNEL_CHANNEL_TYPE, optional_channel_type); - } - if (optional_handle_type != TP_HANDLE_TYPE_NONE) - { - tp_asv_set_uint32 (asv, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, optional_handle_type); - } - if (optional_handle != 0) - { - tp_asv_set_uint32 (asv, - TP_PROP_CHANNEL_TARGET_HANDLE, optional_handle); - } - - ret = tp_tests_channel_new_from_properties (conn, object_path, asv, error); - - g_hash_table_unref (asv); - - return ret; -} - -TpChannel * -tp_tests_channel_new_from_properties (TpConnection *conn, - const gchar *object_path, - const GHashTable *immutable_properties, - GError **error) -{ - TpClientFactory *factory; - - if (!tp_dbus_check_valid_object_path (object_path, error)) - return NULL; - - factory = tp_proxy_get_factory (conn); - return tp_client_factory_ensure_channel (factory, conn, - object_path, immutable_properties, error); -} - -void -tp_tests_add_channel_to_ptr_array (GPtrArray *arr, - TpChannel *channel) -{ - GValueArray *tmp; - GVariant *variant; - GValue v = G_VALUE_INIT; - GHashTable *asv; - - g_assert (arr != NULL); - g_assert (channel != NULL); - - variant = tp_channel_dup_immutable_properties (channel); - dbus_g_value_parse_g_variant (variant, &v); - asv = g_value_get_boxed (&v); - - tmp = tp_value_array_build (2, - DBUS_TYPE_G_OBJECT_PATH, tp_proxy_get_object_path (channel), - TP_HASH_TYPE_STRING_VARIANT_MAP, asv, - G_TYPE_INVALID); - - g_ptr_array_add (arr, tmp); - g_variant_unref (variant); - g_value_unset (&v); -} - diff --git a/tests/lib/util.h b/tests/lib/util.h deleted file mode 100644 index 183e00f..0000000 --- a/tests/lib/util.h +++ /dev/null @@ -1,112 +0,0 @@ -/* Simple utility code used by the regression tests. - * - * Copyright © 2008-2010 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright © 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_LIB_UTIL_H__ -#define __TP_TESTS_LIB_UTIL_H__ - -#include <telepathy-glib/telepathy-glib.h> - -gint tp_tests_run_with_bus (void); - -TpDBusDaemon *tp_tests_dbus_daemon_dup_or_die (void); - -void tp_tests_proxy_run_until_dbus_queue_processed (gpointer proxy); - -void tp_tests_proxy_run_until_prepared (gpointer proxy, - const GQuark *features); -gboolean tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy, - const GQuark *features, - GError **error); - -#define test_assert_empty_strv(strv) \ - _test_assert_empty_strv (__FILE__, __LINE__, strv) -void _test_assert_empty_strv (const char *file, int line, gconstpointer strv); - -#define tp_tests_assert_strv_equals(actual, expected) \ - _tp_tests_assert_strv_equals (__FILE__, __LINE__, \ - #actual, actual, \ - #expected, expected) -void _tp_tests_assert_strv_equals (const char *file, int line, - const char *actual_desc, gconstpointer actual_strv, - const char *expected_desc, gconstpointer expected_strv); - -#define tp_tests_assert_bytes_equals(actual, expected, expected_length) \ - _tp_tests_assert_bytes_equal (__FILE__, __LINE__, \ - actual, expected, expected_length) -void _tp_tests_assert_bytes_equal (const gchar *file, int line, - GBytes *actual, gconstpointer expected_data, gsize expected_length); - -void tp_tests_create_conn (GType conn_type, - const gchar *account, - gboolean connect, - TpBaseConnection **service_conn, - TpConnection **client_conn); - -void tp_tests_create_and_connect_conn (GType conn_type, - const gchar *account, - TpBaseConnection **service_conn, - TpConnection **client_conn); - -gpointer tp_tests_object_new_static_class (GType type, - ...) G_GNUC_NULL_TERMINATED; - -void tp_tests_run_until_result (GAsyncResult **result); -void tp_tests_result_ready_cb (GObject *object, - GAsyncResult *res, gpointer user_data); - -void tp_tests_abort_after (guint sec); - -void tp_tests_init (int *argc, - char ***argv); - -GValue *_tp_create_local_socket (TpSocketAddressType address_type, - TpSocketAccessControl access_control, - GSocketService **service, - gchar **unix_address, - gchar **unix_tmpdir, - GError **error); - -void _tp_destroy_socket_control_list (gpointer data); - -void tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection); - -TpContact *tp_tests_connection_run_until_contact_by_id ( - TpConnection *connection, - const gchar *id, - const GQuark *features); - -void tp_tests_channel_assert_expect_members (TpChannel *channel, - TpIntset *expected_members); - -TpConnection *tp_tests_connection_new (TpDBusDaemon *dbus, - const gchar *bus_name, - const gchar *object_path, - GError **error); - -TpAccount *tp_tests_account_new (TpDBusDaemon *dbus, - const gchar *object_path, - GError **error); - -TpChannel *tp_tests_channel_new (TpConnection *conn, - const gchar *object_path, - const gchar *optional_channel_type, - TpHandleType optional_handle_type, - TpHandle optional_handle, - GError **error); - -TpChannel *tp_tests_channel_new_from_properties (TpConnection *conn, - const gchar *object_path, - const GHashTable *immutable_properties, - GError **error); - -void tp_tests_add_channel_to_ptr_array (GPtrArray *arr, - TpChannel *channel); - -#endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */ |