diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2013-09-27 15:44:43 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2013-09-30 14:06:47 +0200 |
commit | 9eddabeae916e360f2b7dbe1f2b2562ae86a86c3 (patch) | |
tree | 00a16287069cc05cf482ad27bc07561fd86d4c1d | |
parent | 17a57522113faf0a5512746dd21c9a4c51109716 (diff) | |
download | telepathy-logger-9eddabeae916e360f2b7dbe1f2b2562ae86a86c3.tar.gz |
tests/lib: sync with tp-glib next
-rw-r--r-- | tests/lib/contact-list-manager.c | 140 | ||||
-rw-r--r-- | tests/lib/contacts-conn.c | 448 | ||||
-rw-r--r-- | tests/lib/contacts-conn.h | 72 | ||||
-rw-r--r-- | tests/lib/room-list-chan.c | 3 | ||||
-rw-r--r-- | tests/lib/simple-account-manager.c | 59 | ||||
-rw-r--r-- | tests/lib/simple-account-manager.h | 2 | ||||
-rw-r--r-- | tests/lib/simple-account.c | 24 | ||||
-rw-r--r-- | tests/lib/simple-conn.c | 106 | ||||
-rw-r--r-- | tests/lib/simple-conn.h | 6 | ||||
-rw-r--r-- | tests/lib/util.c | 232 | ||||
-rw-r--r-- | tests/lib/util.h | 32 |
11 files changed, 429 insertions, 695 deletions
diff --git a/tests/lib/contact-list-manager.c b/tests/lib/contact-list-manager.c index b816673..bce8e21 100644 --- a/tests/lib/contact-list-manager.c +++ b/tests/lib/contact-list-manager.c @@ -26,8 +26,7 @@ struct _TpTestsContactListManagerPrivate GHashTable *contact_details; TpHandleRepoIface *contact_repo; - TpHandleRepoIface *group_repo; - TpHandleSet *groups; + GHashTable *groups; }; static void contact_groups_iface_init (TpContactGroupListInterface *iface); @@ -49,7 +48,7 @@ typedef struct { TpSubscriptionState subscribe; TpSubscriptionState publish; gchar *publish_request; - TpHandleSet *groups; + GHashTable *groups; TpHandle handle; TpHandleRepoIface *contact_repo; @@ -61,7 +60,7 @@ contact_detail_destroy (gpointer p) ContactDetails *d = p; g_free (d->publish_request); - tp_handle_set_destroy (d->groups); + g_hash_table_unref (d->groups); g_slice_free (ContactDetails, d); } @@ -86,7 +85,7 @@ ensure_contact (TpTestsContactListManager *self, d->subscribe = TP_SUBSCRIPTION_STATE_NO; d->publish = TP_SUBSCRIPTION_STATE_NO; d->publish_request = NULL; - d->groups = tp_handle_set_new (self->priv->group_repo); + 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; @@ -117,7 +116,7 @@ close_all (TpTestsContactListManager *self) self->priv->status_changed_id = 0; } tp_clear_pointer (&self->priv->contact_details, g_hash_table_unref); - tp_clear_pointer (&self->priv->groups, tp_handle_set_destroy); + tp_clear_pointer (&self->priv->groups, g_hash_table_unref); } static void @@ -197,16 +196,15 @@ contact_list_dup_groups (TpBaseContactList *base) if (self->priv->groups != NULL) { - TpIntsetFastIter iter; - TpHandle group; + GHashTableIter iter; + gpointer name; - ret = g_ptr_array_sized_new (tp_handle_set_size (self->priv->groups) + 1); + ret = g_ptr_array_sized_new (g_hash_table_size (self->priv->groups) + 1); - tp_intset_fast_iter_init (&iter, tp_handle_set_peek (self->priv->groups)); - while (tp_intset_fast_iter_next (&iter, &group)) + 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 (tp_handle_inspect ( - self->priv->group_repo, group))); + g_ptr_array_add (ret, g_strdup (name)); } } else @@ -229,16 +227,15 @@ contact_list_dup_contact_groups (TpBaseContactList *base, if (d != NULL && d->groups != NULL) { - TpIntsetFastIter iter; - TpHandle group; + GHashTableIter iter; + gpointer name; - ret = g_ptr_array_sized_new (tp_handle_set_size (d->groups) + 1); + ret = g_ptr_array_sized_new (g_hash_table_size (d->groups) + 1); - tp_intset_fast_iter_init (&iter, tp_handle_set_peek (d->groups)); - while (tp_intset_fast_iter_next (&iter, &group)) + g_hash_table_iter_init (&iter, d->groups); + while (g_hash_table_iter_next (&iter, &name, NULL)) { - g_ptr_array_add (ret, g_strdup (tp_handle_inspect ( - self->priv->group_repo, group))); + g_ptr_array_add (ret, g_strdup (name)); } } else @@ -256,14 +253,13 @@ contact_list_dup_group_members (TpBaseContactList *base, const gchar *group) { TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); - TpHandleSet *set; - TpHandle group_handle; GHashTableIter iter; gpointer k, v; + TpHandleSet *set; set = tp_handle_set_new (self->priv->contact_repo); - group_handle = tp_handle_lookup (self->priv->group_repo, group, NULL, NULL); - if (G_UNLIKELY (group_handle == 0)) + + if (G_UNLIKELY (g_hash_table_lookup (self->priv->groups, group) == NULL)) { /* clearly it doesn't have members */ return set; @@ -275,13 +271,31 @@ contact_list_dup_group_members (TpBaseContactList *base, ContactDetails *d = v; if (d->groups != NULL && - tp_handle_set_is_member (d->groups, group_handle)) + 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, @@ -292,25 +306,24 @@ contact_list_set_contact_groups_async (TpBaseContactList *base, { TpTestsContactListManager *self = TP_TESTS_CONTACT_LIST_MANAGER (base); ContactDetails *d; - TpIntset *set, *added_set, *removed_set; - GPtrArray *added_names, *removed_names; + GHashTable *tmp; + GPtrArray *added, *removed; GPtrArray *new_groups; - TpIntsetFastIter iter; - TpHandle group_handle; guint i; d = ensure_contact (self, contact); new_groups = g_ptr_array_new (); - set = tp_intset_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++) { - group_handle = tp_handle_ensure (self->priv->group_repo, names[i], NULL, NULL); - tp_intset_add (set, group_handle); + g_hash_table_insert (tmp, (gpointer) names[i], GUINT_TO_POINTER (1)); - if (!tp_handle_set_is_member (self->priv->groups, group_handle)) + if (g_hash_table_lookup (self->priv->groups, names[i]) == NULL) { - tp_handle_set_add (self->priv->groups, group_handle); + g_hash_table_insert (self->priv->groups, g_strdup (names[i]), + GUINT_TO_POINTER (1)); g_ptr_array_add (new_groups, (gchar *) names[i]); } } @@ -321,42 +334,30 @@ contact_list_set_contact_groups_async (TpBaseContactList *base, (const gchar * const *) new_groups->pdata, new_groups->len); } - added_set = tp_intset_difference (set, tp_handle_set_peek (d->groups)); - added_names = g_ptr_array_sized_new (tp_intset_size (added_set)); - tp_intset_fast_iter_init (&iter, added_set); - while (tp_intset_fast_iter_next (&iter, &group_handle)) - { - g_ptr_array_add (added_names, (gchar *) tp_handle_inspect ( - self->priv->group_repo, group_handle)); - } - tp_intset_destroy (added_set); + /* see which groups were added and which were removed */ + added = group_difference (tmp, d->groups); + removed = group_difference (d->groups, tmp); - removed_set = tp_intset_difference (tp_handle_set_peek (d->groups), set); - removed_names = g_ptr_array_sized_new (tp_intset_size (removed_set)); - tp_intset_fast_iter_init (&iter, removed_set); - while (tp_intset_fast_iter_next (&iter, &group_handle)) - { - g_ptr_array_add (removed_names, (gchar *) tp_handle_inspect ( - self->priv->group_repo, group_handle)); - } - tp_intset_destroy (removed_set); + g_hash_table_unref (tmp); - tp_handle_set_destroy (d->groups); - d->groups = tp_handle_set_new_from_intset (self->priv->group_repo, set); - tp_intset_destroy (set); + /* 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)); - if (added_names->len > 0 || removed_names->len > 0) + /* signal the change */ + if (added->len > 0 || removed->len > 0) { tp_base_contact_list_one_contact_groups_changed (base, contact, - (const gchar * const *) added_names->pdata, added_names->len, - (const gchar * const *) removed_names->pdata, removed_names->len); + (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_names); - g_ptr_array_unref (removed_names); + g_ptr_array_unref (added); + g_ptr_array_unref (removed); g_ptr_array_unref (new_groups); } @@ -551,9 +552,8 @@ constructed (GObject *object) self->priv->contact_repo = tp_base_connection_get_handles (self->priv->conn, TP_HANDLE_TYPE_CONTACT); - self->priv->group_repo = tp_base_connection_get_handles (self->priv->conn, - TP_HANDLE_TYPE_GROUP); - self->priv->groups = tp_handle_set_new (self->priv->group_repo); + self->priv->groups = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); } static void @@ -606,19 +606,17 @@ tp_tests_contact_list_manager_add_to_group (TpTestsContactListManager *self, { TpBaseContactList *base = TP_BASE_CONTACT_LIST (self); ContactDetails *d = ensure_contact (self, member); - TpHandle group_handle; - group_handle = tp_handle_ensure (self->priv->group_repo, - group_name, NULL, NULL); + g_hash_table_insert (d->groups, g_strdup (group_name), GUINT_TO_POINTER (1)); - if (!tp_handle_set_is_member (self->priv->groups, group_handle)) + if (g_hash_table_lookup (self->priv->groups, group_name) == NULL) { - tp_handle_set_add (self->priv->groups, group_handle); + 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_handle_set_add (d->groups, group_handle); tp_base_contact_list_one_contact_groups_changed (base, member, &group_name, 1, NULL, 0); } @@ -629,14 +627,12 @@ tp_tests_contact_list_manager_remove_from_group (TpTestsContactListManager *self { TpBaseContactList *base = TP_BASE_CONTACT_LIST (self); ContactDetails *d = lookup_contact (self, member); - TpHandle group_handle; if (d == NULL) return; - group_handle = tp_handle_ensure (self->priv->group_repo, group_name, NULL, NULL); + g_hash_table_remove (d->groups, group_name); - tp_handle_set_remove (d->groups, group_handle); tp_base_contact_list_one_contact_groups_changed (base, member, NULL, 0, &group_name, 1); } diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c index 6cca69f..6e7c39c 100644 --- a/tests/lib/contacts-conn.c +++ b/tests/lib/contacts-conn.c @@ -22,8 +22,6 @@ static void init_aliasing (gpointer, gpointer); static void init_avatars (gpointer, gpointer); -static void init_location (gpointer, gpointer); -static void init_contact_caps (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); @@ -37,13 +35,9 @@ G_DEFINE_TYPE_WITH_CODE (TpTestsContactsConnection, init_avatars); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_PRESENCE, tp_presence_mixin_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_SIMPLE_PRESENCE, - tp_presence_mixin_simple_presence_iface_init) - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_LOCATION, - init_location) + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_LOCATION, NULL) G_IMPLEMENT_INTERFACE ( - TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_CAPABILITIES, - init_contact_caps) + TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_CAPABILITIES, NULL) G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO, init_contact_info) G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS, @@ -398,11 +392,17 @@ constructed (GObject *object) 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 (base); + { + 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_ALIASING, aliasing_fill_contact_attributes); @@ -424,7 +424,7 @@ constructed (GObject *object) tp_presence_mixin_init (object, G_STRUCT_OFFSET (TpTestsContactsConnection, presence_mixin)); - tp_presence_mixin_simple_presence_register_with_contacts_mixin (object); + tp_presence_mixin_register_with_contacts_mixin (object); } static const TpPresenceStatusOptionalArgumentSpec can_have_message[] = { @@ -455,8 +455,7 @@ my_status_available (GObject *object, static GHashTable * my_get_contact_statuses (GObject *object, - const GArray *contacts, - GError **error) + const GArray *contacts) { TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); GHashTable *result = g_hash_table_new_full (g_direct_hash, g_direct_equal, @@ -525,15 +524,7 @@ my_get_maximum_status_message_length_cb (GObject *obj) static GPtrArray * create_channel_managers (TpBaseConnection *conn) { - TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (conn); - GPtrArray *ret = g_ptr_array_sized_new (1); - - self->priv->list_manager = g_object_new (TP_TESTS_TYPE_CONTACT_LIST_MANAGER, - "connection", conn, NULL); - - g_ptr_array_add (ret, self->priv->list_manager); - - return ret; + return g_ptr_array_new (); } static GPtrArray * @@ -547,7 +538,6 @@ tp_tests_contacts_get_interfaces_always_present (TpBaseConnection *base) TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST, TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS, TP_IFACE_CONNECTION_INTERFACE_PRESENCE, - TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE, TP_IFACE_CONNECTION_INTERFACE_LOCATION, TP_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES, TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES, @@ -564,6 +554,29 @@ tp_tests_contacts_get_interfaces_always_present (TpBaseConnection *base) 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) { @@ -571,6 +584,10 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) (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_AVATARS, conn_avatars_properties_getter, @@ -582,6 +599,11 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) NULL, conn_contact_info_properties, }, + { TP_IFACE_CONNECTION_INTERFACE_ALIASING, + aliasing_get_dbus_property, + NULL, + aliasing_props, + }, { NULL } }; @@ -603,7 +625,7 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) mixin_class->get_maximum_status_message_length = my_get_maximum_status_message_length_cb; - tp_presence_mixin_simple_presence_init_dbus_properties (object_class); + tp_presence_mixin_init_dbus_properties (object_class); klass->properties_class.interfaces = prop_interfaces; tp_dbus_properties_mixin_class_init (object_class, @@ -633,34 +655,23 @@ tp_tests_contacts_connection_change_aliases (TpTestsContactsConnection *self, const TpHandle *handles, const gchar * const *aliases) { - GPtrArray *structs = g_ptr_array_sized_new (n); + GHashTable *changes = g_hash_table_new (NULL, NULL); guint i; for (i = 0; i < n; i++) { - GValueArray *pair = g_value_array_new (2); - 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_value_array_append (pair, NULL); - g_value_init (pair->values + 0, G_TYPE_UINT); - g_value_set_uint (pair->values + 0, handles[i]); - - g_value_array_append (pair, NULL); - g_value_init (pair->values + 1, G_TYPE_STRING); - g_value_set_string (pair->values + 1, aliases[i]); - - g_ptr_array_add (structs, pair); + g_hash_table_insert (changes, + GUINT_TO_POINTER (handles[i]), (gchar *) aliases[i]); } - tp_svc_connection_interface_aliasing_emit_aliases_changed (self, - structs); + tp_svc_connection_interface_aliasing_emit_aliases_changed (self, changes); - g_ptr_array_foreach (structs, (GFunc) g_value_array_free, NULL); - g_ptr_array_unref (structs); + g_hash_table_unref (changes); } void @@ -803,60 +814,6 @@ tp_tests_contacts_connection_set_default_contact_info ( } static void -my_get_alias_flags (TpSvcConnectionInterfaceAliasing *aliasing, - DBusGMethodInvocation *context) -{ - TpBaseConnection *base = TP_BASE_CONNECTION (aliasing); - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - tp_svc_connection_interface_aliasing_return_from_get_alias_flags (context, - TP_CONNECTION_ALIAS_FLAG_USER_SET); -} - -static void -my_get_aliases (TpSvcConnectionInterfaceAliasing *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); - GHashTable *result; - 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_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); - - 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_hash_table_insert (result, GUINT_TO_POINTER (handle), - (gchar *) tp_handle_inspect (contact_repo, handle)); - else - g_hash_table_insert (result, GUINT_TO_POINTER (handle), - (gchar *) alias); - } - - tp_svc_connection_interface_aliasing_return_from_get_aliases (context, - result); - g_hash_table_unref (result); -} - -static void my_request_aliases (TpSvcConnectionInterfaceAliasing *aliasing, const GArray *contacts, DBusGMethodInvocation *context) @@ -960,105 +917,12 @@ init_aliasing (gpointer g_iface, #define IMPLEMENT(x) tp_svc_connection_interface_aliasing_implement_##x (\ klass, my_##x) - IMPLEMENT(get_alias_flags); IMPLEMENT(request_aliases); - IMPLEMENT(get_aliases); IMPLEMENT(set_aliases); #undef IMPLEMENT } static void -my_get_avatar_tokens (TpSvcConnectionInterfaceAvatars *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; - GHashTable *result; - 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_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); - - 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 || a->token == NULL) - { - /* we're expected to do a round-trip to the server to find out - * their token, so we have to give some sort of result. Assume - * no avatar, here */ - a = avatar_data_new (NULL, NULL, ""); - g_hash_table_insert (self->priv->avatars, - GUINT_TO_POINTER (handle), a); - tp_svc_connection_interface_avatars_emit_avatar_updated (self, - handle, a->token); - } - - g_hash_table_insert (result, GUINT_TO_POINTER (handle), - a->token); - } - - tp_svc_connection_interface_avatars_return_from_get_known_avatar_tokens ( - context, result); - g_hash_table_unref (result); -} - -static void -my_get_known_avatar_tokens (TpSvcConnectionInterfaceAvatars *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; - GHashTable *result; - 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_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); - - 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)); - const gchar *token = a ? a->token : NULL; - - g_hash_table_insert (result, GUINT_TO_POINTER (handle), - (gchar *) (token != NULL ? token : "")); - } - - tp_svc_connection_interface_avatars_return_from_get_known_avatar_tokens ( - context, result); - g_hash_table_unref (result); -} - -static void my_request_avatars (TpSvcConnectionInterfaceAvatars *avatars, const GArray *contacts, DBusGMethodInvocation *context) @@ -1122,8 +986,6 @@ init_avatars (gpointer g_iface, #define IMPLEMENT(x) tp_svc_connection_interface_avatars_implement_##x (\ klass, my_##x) /* IMPLEMENT(get_avatar_requirements); */ - IMPLEMENT(get_avatar_tokens); - IMPLEMENT(get_known_avatar_tokens); /* IMPLEMENT(request_avatar); */ IMPLEMENT(request_avatars); /* IMPLEMENT(set_avatar); */ @@ -1131,113 +993,6 @@ init_avatars (gpointer g_iface, #undef IMPLEMENT } -static void -my_get_locations (TpSvcConnectionInterfaceLocation *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; - GHashTable *result; - 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_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, TpHandle, i); - GHashTable *location = g_hash_table_lookup (self->priv->locations, - GUINT_TO_POINTER (handle)); - - if (location != NULL) - { - g_hash_table_insert (result, GUINT_TO_POINTER (handle), location); - } - } - - tp_svc_connection_interface_location_return_from_get_locations ( - context, result); - g_hash_table_unref (result); -} - -static void -init_location (gpointer g_iface, - gpointer iface_data) -{ - TpSvcConnectionInterfaceLocationClass *klass = g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_location_implement_##x (\ - klass, my_##x) - IMPLEMENT(get_locations); -#undef IMPLEMENT -} - -static void -my_get_contact_capabilities (TpSvcConnectionInterfaceContactCapabilities *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; - GHashTable *result; - 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_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); - - for (i = 0; i < contacts->len; i++) - { - TpHandle handle = g_array_index (contacts, TpHandle, i); - GPtrArray *arr = g_hash_table_lookup (self->priv->capabilities, - GUINT_TO_POINTER (handle)); - - if (arr != NULL) - { - g_hash_table_insert (result, GUINT_TO_POINTER (handle), arr); - } - } - - tp_svc_connection_interface_contact_capabilities_return_from_get_contact_capabilities ( - context, result); - - g_hash_table_unref (result); -} - -static void -init_contact_caps (gpointer g_iface, - gpointer iface_data) -{ - TpSvcConnectionInterfaceContactCapabilitiesClass *klass = g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_contact_capabilities_implement_##x (\ - klass, my_##x) - IMPLEMENT(get_contact_capabilities); -#undef IMPLEMENT -} - static GPtrArray * lookup_contact_info (TpTestsContactsConnection *self, TpHandle handle) @@ -1336,9 +1091,11 @@ my_set_contact_info (TpSvcConnectionInterfaceContactInfo *obj, 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); @@ -1361,104 +1118,3 @@ init_contact_info (gpointer g_iface, IMPLEMENT (set_contact_info); #undef IMPLEMENT } - -/* =============== Legacy version (no Contacts interface) ================= */ - -G_DEFINE_TYPE (TpTestsLegacyContactsConnection, - tp_tests_legacy_contacts_connection, TP_TESTS_TYPE_CONTACTS_CONNECTION); - -enum -{ - LEGACY_PROP_HAS_IMMORTAL_HANDLES = 1 -}; - -static void -legacy_contacts_connection_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) - { - case LEGACY_PROP_HAS_IMMORTAL_HANDLES: - /* Pretend we don't. */ - g_value_set_boolean (value, FALSE); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -tp_tests_legacy_contacts_connection_init (TpTestsLegacyContactsConnection *self) -{ -} - -static GPtrArray * -tp_tests_legacy_contacts_get_interfaces_always_present (TpBaseConnection *base) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CONNECTION_CLASS ( - tp_tests_legacy_contacts_connection_parent_class)->get_interfaces_always_present (base); - - g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_CONTACTS); - g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES); - - return interfaces; -} - -static void -tp_tests_legacy_contacts_connection_class_init ( - TpTestsLegacyContactsConnectionClass *klass) -{ - /* Leave Contacts out of the interfaces we say are present, so clients - * won't use it */ - TpBaseConnectionClass *base_class = - (TpBaseConnectionClass *) klass; - GObjectClass *object_class = (GObjectClass *) klass; - - object_class->get_property = legacy_contacts_connection_get_property; - - base_class->get_interfaces_always_present = tp_tests_legacy_contacts_get_interfaces_always_present; - - g_object_class_override_property (object_class, - LEGACY_PROP_HAS_IMMORTAL_HANDLES, "has-immortal-handles"); -} - -/* =============== No Requests and no ContactCapabilities ================= */ - -G_DEFINE_TYPE (TpTestsNoRequestsConnection, tp_tests_no_requests_connection, - TP_TESTS_TYPE_CONTACTS_CONNECTION); - -static void -tp_tests_no_requests_connection_init (TpTestsNoRequestsConnection *self) -{ -} - -static GPtrArray * -tp_tests_no_requests_get_interfaces_always_present (TpBaseConnection *base) -{ - GPtrArray *interfaces; - - interfaces = TP_BASE_CONNECTION_CLASS ( - tp_tests_no_requests_connection_parent_class)->get_interfaces_always_present (base); - - g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_REQUESTS); - g_ptr_array_remove (interfaces, TP_IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES); - - return interfaces; -} - -static void -tp_tests_no_requests_connection_class_init ( - TpTestsNoRequestsConnectionClass *klass) -{ - TpBaseConnectionClass *base_class = - (TpBaseConnectionClass *) klass; - - base_class->get_interfaces_always_present = tp_tests_no_requests_get_interfaces_always_present; - base_class->create_channel_managers = NULL; -} diff --git a/tests/lib/contacts-conn.h b/tests/lib/contacts-conn.h index c596e3e..679b0eb 100644 --- a/tests/lib/contacts-conn.h +++ b/tests/lib/contacts-conn.h @@ -111,78 +111,6 @@ void tp_tests_contacts_connection_set_default_contact_info ( TpTestsContactsConnection *self, GPtrArray *info); -/* Legacy version (no Contacts interface, and no immortal handles) */ - -typedef struct _TpTestsLegacyContactsConnection TpTestsLegacyContactsConnection; -typedef struct _TpTestsLegacyContactsConnectionClass TpTestsLegacyContactsConnectionClass; -typedef struct _TpTestsLegacyContactsConnectionPrivate - TpTestsLegacyContactsConnectionPrivate; - -struct _TpTestsLegacyContactsConnectionClass { - TpTestsContactsConnectionClass parent_class; -}; - -struct _TpTestsLegacyContactsConnection { - TpTestsContactsConnection parent; - - TpTestsLegacyContactsConnectionPrivate *priv; -}; - -GType tp_tests_legacy_contacts_connection_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_LEGACY_CONTACTS_CONNECTION \ - (tp_tests_legacy_contacts_connection_get_type ()) -#define LEGACY_TP_TESTS_CONTACTS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_LEGACY_CONTACTS_CONNECTION, \ - TpTestsLegacyContactsConnection)) -#define LEGACY_TP_TESTS_CONTACTS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_LEGACY_CONTACTS_CONNECTION, \ - TpTestsLegacyContactsConnectionClass)) -#define TP_TESTS_LEGACY_CONTACTS_IS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_LEGACY_CONTACTS_CONNECTION)) -#define TP_TESTS_LEGACY_CONTACTS_IS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_LEGACY_CONTACTS_CONNECTION)) -#define LEGACY_TP_TESTS_CONTACTS_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_LEGACY_CONTACTS_CONNECTION, \ - TpTestsLegacyContactsConnectionClass)) - -/* No Requests version */ - -typedef struct _TpTestsNoRequestsConnection TpTestsNoRequestsConnection; -typedef struct _TpTestsNoRequestsConnectionClass TpTestsNoRequestsConnectionClass; -typedef struct _TpTestsNoRequestsConnectionPrivate - TpTestsNoRequestsConnectionPrivate; - -struct _TpTestsNoRequestsConnectionClass { - TpTestsContactsConnectionClass parent_class; -}; - -struct _TpTestsNoRequestsConnection { - TpTestsContactsConnection parent; - - TpTestsNoRequestsConnectionPrivate *priv; -}; - -GType tp_tests_no_requests_connection_get_type (void); - -/* TYPE MACROS */ -#define TP_TESTS_TYPE_NO_REQUESTS_CONNECTION \ - (tp_tests_no_requests_connection_get_type ()) -#define TP_TESTS_NO_REQUESTS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TP_TESTS_TYPE_NO_REQUESTS_CONNECTION, \ - TpTestsNoRequestsConnection)) -#define TP_TESTS_NO_REQUESTS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TP_TESTS_TYPE_NO_REQUESTS_CONNECTION, \ - TpTestsNoRequestsConnectionClass)) -#define TP_TESTS_NO_REQUESTS_IS_CONNECTION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TP_TESTS_TYPE_NO_REQUESTS_CONNECTION)) -#define TP_TESTS_NO_REQUESTS_IS_CONNECTION_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TP_TESTS_TYPE_NO_REQUESTS_CONNECTION)) -#define TP_TESTS_NO_REQUESTS_CONNECTION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TESTS_TYPE_NO_REQUESTS_CONNECTION, \ - TpTestsNoRequestsConnectionClass)) - G_END_DECLS #endif /* ifndef __TP_TESTS_CONTACTS_CONN_H__ */ diff --git a/tests/lib/room-list-chan.c b/tests/lib/room-list-chan.c index e6134a3..a94133d 100644 --- a/tests/lib/room-list-chan.c +++ b/tests/lib/room-list-chan.c @@ -4,6 +4,7 @@ #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); @@ -190,7 +191,7 @@ find_rooms (gpointer data) TpTestsRoomListChan *self = TP_TESTS_ROOM_LIST_CHAN (data); GPtrArray *rooms; - rooms = g_ptr_array_new_with_free_func ((GDestroyNotify) g_value_array_free); + rooms = g_ptr_array_new_with_free_func ((GDestroyNotify) tp_value_array_free); /* Find 2 rooms */ add_room (rooms); diff --git a/tests/lib/simple-account-manager.c b/tests/lib/simple-account-manager.c index c38132c..e5bddbc 100644 --- a/tests/lib/simple-account-manager.c +++ b/tests/lib/simple-account-manager.c @@ -35,14 +35,14 @@ enum { PROP_0, PROP_INTERFACES, - PROP_VALID_ACCOUNTS, - PROP_INVALID_ACCOUNTS, + PROP_USABLE_ACCOUNTS, + PROP_UNUSABLE_ACCOUNTS, }; struct _TpTestsSimpleAccountManagerPrivate { - GPtrArray *valid_accounts; - GPtrArray *invalid_accounts; + GPtrArray *usable_accounts; + GPtrArray *unusable_accounts; }; static void @@ -91,8 +91,8 @@ 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->valid_accounts = g_ptr_array_new_with_free_func (g_free); - self->priv->invalid_accounts = g_ptr_array_new_with_free_func (g_free); + 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 @@ -108,12 +108,12 @@ tp_tests_simple_account_manager_get_property (GObject *object, g_value_set_boxed (value, ACCOUNT_MANAGER_INTERFACES); break; - case PROP_VALID_ACCOUNTS: - g_value_set_boxed (value, self->priv->valid_accounts); + case PROP_USABLE_ACCOUNTS: + g_value_set_boxed (value, self->priv->usable_accounts); break; - case PROP_INVALID_ACCOUNTS: - g_value_set_boxed (value, self->priv->invalid_accounts); + case PROP_UNUSABLE_ACCOUNTS: + g_value_set_boxed (value, self->priv->unusable_accounts); break; default: @@ -127,8 +127,8 @@ tp_tests_simple_account_manager_finalize (GObject *object) { TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object); - g_ptr_array_unref (self->priv->valid_accounts); - g_ptr_array_unref (self->priv->invalid_accounts); + 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); @@ -156,8 +156,8 @@ tp_tests_simple_account_manager_class_init ( static TpDBusPropertiesMixinPropImpl am_props[] = { { "Interfaces", "interfaces", NULL }, - { "ValidAccounts", "valid-accounts", NULL }, - { "InvalidAccounts", "invalid-accounts", NULL }, + { "UsableAccounts", "usable-accounts", NULL }, + { "UnusableAccounts", "unusable-accounts", NULL }, /* { "SupportedAccountProperties", "supported-account-properties", NULL }, */ @@ -182,16 +182,16 @@ tp_tests_simple_account_manager_class_init ( 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 ("valid-accounts", "Valid accounts", - "The accounts which are valid on this account. This may be a lie.", + 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_VALID_ACCOUNTS, param_spec); - param_spec = g_param_spec_boxed ("invalid-accounts", "Invalid accounts", - "The accounts which are invalid on this account. This may be a lie.", + 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_INVALID_ACCOUNTS, param_spec); + 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, @@ -215,17 +215,18 @@ void tp_tests_simple_account_manager_add_account ( TpTestsSimpleAccountManager *self, const gchar *object_path, - gboolean valid) + gboolean usable) { - remove_from_array (self->priv->valid_accounts, object_path); - remove_from_array (self->priv->valid_accounts, object_path); + remove_from_array (self->priv->usable_accounts, object_path); + remove_from_array (self->priv->unusable_accounts, object_path); - if (valid) - g_ptr_array_add (self->priv->valid_accounts, g_strdup (object_path)); + if (usable) + g_ptr_array_add (self->priv->usable_accounts, g_strdup (object_path)); else - g_ptr_array_add (self->priv->invalid_accounts, g_strdup (object_path)); + g_ptr_array_add (self->priv->unusable_accounts, g_strdup (object_path)); - tp_svc_account_manager_emit_account_validity_changed (self, object_path, valid); + tp_svc_account_manager_emit_account_usability_changed (self, object_path, + usable); } void @@ -233,8 +234,8 @@ tp_tests_simple_account_manager_remove_account ( TpTestsSimpleAccountManager *self, const gchar *object_path) { - remove_from_array (self->priv->valid_accounts, object_path); - remove_from_array (self->priv->valid_accounts, 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 index 94a60cd..cc65f09 100644 --- a/tests/lib/simple-account-manager.h +++ b/tests/lib/simple-account-manager.h @@ -61,7 +61,7 @@ GType tp_tests_simple_account_manager_get_type (void); void tp_tests_simple_account_manager_add_account ( TpTestsSimpleAccountManager *self, const gchar *object_path, - gboolean valid); + gboolean usable); void tp_tests_simple_account_manager_remove_account ( TpTestsSimpleAccountManager *self, diff --git a/tests/lib/simple-account.c b/tests/lib/simple-account.c index 79673d9..7b9261d 100644 --- a/tests/lib/simple-account.c +++ b/tests/lib/simple-account.c @@ -44,7 +44,7 @@ enum PROP_INTERFACES, PROP_DISPLAY_NAME, PROP_ICON, - PROP_VALID, + PROP_USABLE, PROP_ENABLED, PROP_NICKNAME, PROP_PARAMETERS, @@ -164,7 +164,7 @@ tp_tests_simple_account_get_property (GObject *object, case PROP_ICON: g_value_set_string (value, ""); break; - case PROP_VALID: + case PROP_USABLE: g_value_set_boolean (value, TRUE); break; case PROP_ENABLED: @@ -216,7 +216,7 @@ tp_tests_simple_account_get_property (GObject *object, g_value_set_boolean (value, TRUE); break; case PROP_STORAGE_PROVIDER: - g_value_set_string (value, "org.freedesktop.Telepathy.glib.test"); + g_value_set_string (value, "im.telepathy1.glib.test"); break; case PROP_STORAGE_IDENTIFIER: g_value_set_boxed (value, &identifier); @@ -330,7 +330,7 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) { "Interfaces", "interfaces", NULL }, { "DisplayName", "display-name", NULL }, { "Icon", "icon", NULL }, - { "Valid", "valid", NULL }, + { "Usable", "usable", NULL }, { "Enabled", "enabled", NULL }, { "Nickname", "nickname", NULL }, { "Parameters", "parameters", NULL }, @@ -414,11 +414,11 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_ICON, param_spec); - param_spec = g_param_spec_boolean ("valid", "valid", - "Valid property", + 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_VALID, param_spec); + g_object_class_install_property (object_class, PROP_USABLE, param_spec); param_spec = g_param_spec_boolean ("enabled", "enabled", "Enabled property", @@ -440,7 +440,7 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) param_spec = g_param_spec_boxed ("automatic-presence", "automatic presence", "AutomaticPresence property", - TP_STRUCT_TYPE_SIMPLE_PRESENCE, + TP_STRUCT_TYPE_PRESENCE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_AUTOMATIC_PRESENCE, param_spec); @@ -474,14 +474,14 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass) param_spec = g_param_spec_boxed ("current-presence", "current presence", "CurrentPresence property", - TP_STRUCT_TYPE_SIMPLE_PRESENCE, + 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_SIMPLE_PRESENCE, + TP_STRUCT_TYPE_PRESENCE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_REQUESTED_PRESENCE, param_spec); @@ -572,12 +572,12 @@ tp_tests_simple_account_set_presence (TpTestsSimpleAccount *self, g_object_get (self, "current-presence", &v, NULL); props = tp_asv_new ( - "CurrentPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE, v, + "CurrentPresence", TP_STRUCT_TYPE_PRESENCE, v, NULL); tp_svc_account_emit_account_property_changed (self, props); - g_boxed_free (TP_STRUCT_TYPE_SIMPLE_PRESENCE, v); + g_boxed_free (TP_STRUCT_TYPE_PRESENCE, v); } void diff --git a/tests/lib/simple-conn.c b/tests/lib/simple-conn.c index 6cdc6b0..fa7bfda 100644 --- a/tests/lib/simple-conn.c +++ b/tests/lib/simple-conn.c @@ -20,31 +20,28 @@ #include <telepathy-glib/telepathy-glib.h> #include <telepathy-glib/telepathy-glib-dbus.h> -#include "textchan-null.h" +#include "echo-chan.h" #include "room-list-chan.h" #include "util.h" static void props_iface_init (TpSvcDBusPropertiesClass *); -static void conn_iface_init (TpSvcConnectionClass *); G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleConnection, tp_tests_simple_connection, TP_TYPE_BASE_CONNECTION, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, props_iface_init); - G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION, conn_iface_init)) + G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION, NULL)) /* type definition stuff */ enum { PROP_ACCOUNT = 1, - PROP_BREAK_PROPS = 2, - PROP_DBUS_STATUS = 3, + PROP_DBUS_STATUS, N_PROPS }; enum { - SIGNAL_GOT_SELF_HANDLE, SIGNAL_GOT_ALL, N_SIGNALS }; @@ -56,13 +53,10 @@ struct _TpTestsSimpleConnectionPrivate gchar *account; guint connect_source; guint disconnect_source; - gboolean break_fastpath_props; /* TpHandle => reffed TpTestsTextChannelNull */ GHashTable *text_channels; TpTestsRoomListChan *room_list_chan; - - GError *get_self_handle_error /* initially NULL */ ; }; static void @@ -87,16 +81,7 @@ get_property (GObject *object, case PROP_ACCOUNT: g_value_set_string (value, self->priv->account); break; - case PROP_BREAK_PROPS: - g_value_set_boolean (value, self->priv->break_fastpath_props); - break; case PROP_DBUS_STATUS: - if (self->priv->break_fastpath_props) - { - g_debug ("returning broken value for Connection.Status"); - g_value_set_uint (value, 0xdeadbeefU); - } - else { g_value_set_uint (value, tp_base_connection_get_status (TP_BASE_CONNECTION (self))); @@ -120,9 +105,6 @@ set_property (GObject *object, g_free (self->priv->account); self->priv->account = g_utf8_strdown (g_value_get_string (value), -1); break; - case PROP_BREAK_PROPS: - self->priv->break_fastpath_props = g_value_get_boolean (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec); } @@ -154,7 +136,6 @@ finalize (GObject *object) g_source_remove (self->priv->disconnect_source); } - g_clear_error (&self->priv->get_self_handle_error); g_free (self->priv->account); G_OBJECT_CLASS (tp_tests_simple_connection_parent_class)->finalize (object); @@ -202,7 +183,7 @@ create_handle_repos (TpBaseConnection *conn, } static GPtrArray * -create_channel_factories (TpBaseConnection *conn) +create_channel_managers (TpBaseConnection *conn) { return g_ptr_array_sized_new (0); } @@ -312,7 +293,7 @@ tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) base_class->create_handle_repos = create_handle_repos; base_class->get_unique_connection_name = get_unique_connection_name; - base_class->create_channel_factories = create_channel_factories; + base_class->create_channel_managers = create_channel_managers; base_class->start_connecting = start_connecting; base_class->shut_down = shut_down; @@ -323,12 +304,6 @@ tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) 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_boolean ("break-0192-properties", - "Break 0.19.2 properties", - "Break Connection D-Bus properties introduced in spec 0.19.2", FALSE, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_BREAK_PROPS, 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)", @@ -337,13 +312,6 @@ tp_tests_simple_connection_class_init (TpTestsSimpleConnectionClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_DBUS_STATUS, param_spec); - signals[SIGNAL_GOT_SELF_HANDLE] = g_signal_new ("got-self-handle", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 0); - signals[SIGNAL_GOT_ALL] = g_signal_new ("got-all", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, @@ -383,11 +351,10 @@ tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self, const gchar *target_id, GHashTable **props) { - TpTestsTextChannelNull *chan; + TpTestsEchoChannel *chan; gchar *chan_path; TpHandleRepoIface *contact_repo; TpHandle handle; - static guint count = 0; TpBaseConnection *base_conn = (TpBaseConnection *) self; /* Get contact handle */ @@ -399,21 +366,12 @@ tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self, chan = g_hash_table_lookup (self->priv->text_channels, GUINT_TO_POINTER (handle)); - if (chan != NULL) - { - /* Channel already exist, reuse it */ - g_object_get (chan, "object-path", &chan_path, NULL); - } - else + if (chan == NULL) { - chan_path = g_strdup_printf ("%s/Channel%u", - tp_base_connection_get_object_path (base_conn), count++); - - chan = TP_TESTS_TEXT_CHANNEL_NULL ( + chan = TP_TESTS_ECHO_CHANNEL ( tp_tests_object_new_static_class ( - TP_TESTS_TYPE_TEXT_CHANNEL_NULL, + TP_TESTS_TYPE_ECHO_CHANNEL, "connection", self, - "object-path", chan_path, "handle", handle, NULL)); @@ -421,8 +379,10 @@ tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self, chan); } + g_object_get (chan, "object-path", &chan_path, NULL); + if (props != NULL) - *props = tp_tests_text_channel_get_props (chan); + g_object_get (chan, "channel-properties", props, NULL); return chan_path; } @@ -472,48 +432,6 @@ tp_tests_simple_connection_ensure_room_list_chan (TpTestsSimpleConnection *self, return chan_path; } -void -tp_tests_simple_connection_set_get_self_handle_error ( - TpTestsSimpleConnection *self, - GQuark domain, - gint code, - const gchar *message) -{ - self->priv->get_self_handle_error = g_error_new_literal (domain, code, - message); -} - -static void -get_self_handle (TpSvcConnection *iface, - DBusGMethodInvocation *context) -{ - TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (iface); - TpBaseConnection *base = TP_BASE_CONNECTION (iface); - - g_assert (TP_IS_BASE_CONNECTION (base)); - - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context); - - if (self->priv->get_self_handle_error != NULL) - { - dbus_g_method_return_error (context, self->priv->get_self_handle_error); - return; - } - - tp_svc_connection_return_from_get_self_handle (context, - tp_base_connection_get_self_handle (base)); - g_signal_emit (self, signals[SIGNAL_GOT_SELF_HANDLE], 0); -} - -static void -conn_iface_init (TpSvcConnectionClass *iface) -{ -#define IMPLEMENT(prefix,x) \ - tp_svc_connection_implement_##x (iface, prefix##x) - IMPLEMENT(,get_self_handle); -#undef IMPLEMENT -} - static void get_all (TpSvcDBusProperties *iface, const gchar *interface_name, diff --git a/tests/lib/simple-conn.h b/tests/lib/simple-conn.h index 14d2275..ffe5778 100644 --- a/tests/lib/simple-conn.h +++ b/tests/lib/simple-conn.h @@ -66,12 +66,6 @@ gchar * tp_tests_simple_connection_ensure_text_chan ( const gchar *target_id, GHashTable **props); -void tp_tests_simple_connection_set_get_self_handle_error ( - TpTestsSimpleConnection *self, - GQuark domain, - gint code, - const gchar *message); - gchar * tp_tests_simple_connection_ensure_room_list_chan ( TpTestsSimpleConnection *self, const gchar *server, diff --git a/tests/lib/util.c b/tests/lib/util.c index 51dc5f2..67af4e0 100644 --- a/tests/lib/util.c +++ b/tests/lib/util.c @@ -13,10 +13,10 @@ #include "util.h" #include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/telepathy-glib-dbus.h> #include <glib/gstdio.h> #include <string.h> -#include <stdlib.h> #ifdef G_OS_UNIX # include <unistd.h> /* for alarm() */ @@ -78,10 +78,70 @@ tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy, 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 = tp_dbus_daemon_dup (NULL); + 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, @@ -204,7 +264,6 @@ tp_tests_create_conn (GType conn_type, TpConnection **client_conn) { TpDBusDaemon *dbus; - TpClientFactory *factory; gchar *name; gchar *conn_path; GError *error = NULL; @@ -213,7 +272,6 @@ tp_tests_create_conn (GType conn_type, g_assert (client_conn != NULL); dbus = tp_tests_dbus_daemon_dup_or_die (); - factory = (TpClientFactory *) tp_automatic_client_factory_new (dbus); *service_conn = tp_tests_object_new_static_class ( conn_type, @@ -226,8 +284,7 @@ tp_tests_create_conn (GType conn_type, &name, &conn_path, &error)); g_assert_no_error (error); - *client_conn = tp_client_factory_ensure_connection (factory, - conn_path, NULL, &error); + *client_conn = tp_tests_connection_new (dbus, NULL, conn_path, &error); g_assert (*client_conn != NULL); g_assert_no_error (error); @@ -243,7 +300,6 @@ tp_tests_create_conn (GType conn_type, g_free (conn_path); g_object_unref (dbus); - g_object_unref (factory); } void @@ -485,12 +541,11 @@ one_contact_cb (GObject *object, TpContact * tp_tests_connection_run_until_contact_by_id (TpConnection *connection, const gchar *id, - guint n_features, - const TpContactFeature *features) + const GQuark *features) { TpContact *contact = NULL; - tp_connection_dup_contact_by_id_async (connection, id, n_features, features, + tp_connection_dup_contact_by_id_async (connection, id, features, one_contact_cb, &contact); while (contact == NULL) @@ -498,3 +553,160 @@ tp_tests_connection_run_until_contact_by_id (TpConnection *connection, 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 index 7c75765..183e00f 100644 --- a/tests/lib/util.h +++ b/tests/lib/util.h @@ -13,6 +13,8 @@ #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); @@ -78,7 +80,33 @@ void tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection); TpContact *tp_tests_connection_run_until_contact_by_id ( TpConnection *connection, const gchar *id, - guint n_features, - const TpContactFeature *features); + 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__ */ |