diff options
author | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-06-09 07:57:56 +0200 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-09-13 10:54:40 +0200 |
commit | 280577868fc124cc4e3b874f9d3f6d0a6400b0b0 (patch) | |
tree | a2c550227a4a150f5db7b818881813f27432eb9e | |
parent | 04a5da520a65317eda730ee29ebea90f3ad43661 (diff) |
Tests: port to new Avatars API
-rw-r--r-- | tests/dbus/connection-interests.c | 4 | ||||
-rw-r--r-- | tests/dbus/contacts-mixin.c | 15 | ||||
-rw-r--r-- | tests/dbus/contacts.c | 207 | ||||
-rw-r--r-- | tests/lib/contacts-conn.c | 259 | ||||
-rw-r--r-- | tests/lib/contacts-conn.h | 15 |
5 files changed, 142 insertions, 358 deletions
diff --git a/tests/dbus/connection-interests.c b/tests/dbus/connection-interests.c index ca7f79b0e..87494d52b 100644 --- a/tests/dbus/connection-interests.c +++ b/tests/dbus/connection-interests.c @@ -269,7 +269,7 @@ test_interested_client (Test *test, tp_connection_add_client_interest_by_id (test->conn, TP_IFACE_QUARK_CONNECTION_INTERFACE_LOCATION); tp_connection_add_client_interest_by_id (test->conn, - TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS); + TP_IFACE_QUARK_CONNECTION_INTERFACE_PRESENCE); /* run until (after) the AddClientInterest calls have gone out */ tp_tests_proxy_run_until_dbus_queue_processed (test->client_bus); @@ -316,7 +316,7 @@ test_interest (Test *test, { static const gchar * telepathy[] = { TP_IFACE_CONNECTION_INTERFACE_LOCATION, - TP_IFACE_CONNECTION_INTERFACE_AVATARS, + TP_IFACE_CONNECTION_INTERFACE_PRESENCE, NULL }; static const gchar * hansard[] = { diff --git a/tests/dbus/contacts-mixin.c b/tests/dbus/contacts-mixin.c index 0f410a8ed..311e37cca 100644 --- a/tests/dbus/contacts-mixin.c +++ b/tests/dbus/contacts-mixin.c @@ -95,10 +95,6 @@ test_features (TpTestsContactsConnection *service_conn, tp_asv_get_string (attrs, TP_IFACE_CONNECTION_INTERFACE_ALIASING "/alias"), ==, "Alice in Wonderland"); - g_assert_cmpstr ( - tp_asv_get_string (attrs, - TP_IFACE_CONNECTION_INTERFACE_AVATARS "/token"), ==, - "aaaaa"); attrs = g_hash_table_lookup (contacts, GUINT_TO_POINTER (g_array_index (handles, guint, 1))); @@ -110,10 +106,6 @@ test_features (TpTestsContactsConnection *service_conn, tp_asv_get_string (attrs, TP_IFACE_CONNECTION_INTERFACE_ALIASING "/alias"), ==, "Bob the Builder"); - g_assert_cmpstr ( - tp_asv_get_string (attrs, - TP_IFACE_CONNECTION_INTERFACE_AVATARS "/token"), ==, - "bbbbb"); attrs = g_hash_table_lookup (contacts, GUINT_TO_POINTER (g_array_index (handles, guint, 2))); @@ -125,10 +117,6 @@ test_features (TpTestsContactsConnection *service_conn, tp_asv_get_string (attrs, TP_IFACE_CONNECTION_INTERFACE_ALIASING "/alias"), ==, "Christopher Robin"); - g_assert_cmpstr ( - tp_asv_get_string (attrs, - TP_IFACE_CONNECTION_INTERFACE_AVATARS "/token"), ==, - "ccccc"); g_hash_table_unref (contacts); } @@ -144,7 +132,6 @@ main (int argc, static const gchar * const ids[] = { "alice", "bob", "chris" }; static const gchar * const aliases[] = { "Alice in Wonderland", "Bob the Builder", "Christopher Robin" }; - static const gchar * const tokens[] = { "aaaaa", "bbbbb", "ccccc" }; static TpTestsContactsConnectionPresenceStatusIndex statuses[] = { TP_TESTS_CONTACTS_CONNECTION_STATUS_AVAILABLE, TP_TESTS_CONTACTS_CONNECTION_STATUS_BUSY, @@ -180,8 +167,6 @@ main (int argc, (const TpHandle *) handles->data, aliases); tp_tests_contacts_connection_change_presences (service_conn, 3, (const TpHandle *) handles->data, statuses, messages); - tp_tests_contacts_connection_change_avatar_tokens (service_conn, 3, - (const TpHandle *) handles->data, tokens); /* Tests */ diff --git a/tests/dbus/contacts.c b/tests/dbus/contacts.c index 268fce6b2..3bc475a25 100644 --- a/tests/dbus/contacts.c +++ b/tests/dbus/contacts.c @@ -438,32 +438,25 @@ test_avatar_requirements (Fixture *f, g_main_loop_unref (result.loop); } +static const gchar *fake_avatar_token = "fake-avatar-token"; +static const gchar *fake_avatar_data = "fake-avatar-data"; +static const gchar *fake_avatar_mime_type = "fake-avatar-mime-type"; + static TpContact * create_contact_with_fake_avatar (Fixture *f, - const gchar *id, - gboolean request_avatar) + const gchar *id) { Result result = { g_main_loop_new (NULL, FALSE), NULL }; - GQuark features[] = { TP_CONTACT_FEATURE_AVATAR_DATA, 0 }; - const gchar avatar_data[] = "fake-avatar-data"; - const gchar avatar_token[] = "fake-avatar-token"; - const gchar avatar_mime_type[] = "fake-avatar-mime-type"; + GQuark features[] = { TP_CONTACT_FEATURE_AVATAR, 0 }; TpContact *contact; TpHandle handle; - GArray *array; gchar *content = NULL; + GFile *avatar_file; contact = ensure_contact (f, id, &handle); - array = g_array_new (FALSE, FALSE, sizeof (gchar)); - g_array_append_vals (array, avatar_data, strlen (avatar_data) + 1); - tp_tests_contacts_connection_change_avatar_data (f->service_conn, handle, - array, avatar_mime_type, avatar_token); - - if (request_avatar) - features[0] = TP_CONTACT_FEATURE_AVATAR_DATA; - else - features[0] = TP_CONTACT_FEATURE_AVATAR_TOKEN; + tp_tests_contacts_connection_avatar_changed (f->service_conn, handle, + fake_avatar_token); tp_connection_upgrade_contacts_async (f->client_conn, 1, &contact, features, @@ -471,54 +464,27 @@ create_contact_with_fake_avatar (Fixture *f, g_main_loop_run (result.loop); g_assert_no_error (result.error); - g_assert_cmpstr (tp_contact_get_avatar_token (contact), ==, avatar_token); - - if (request_avatar) + if (tp_contact_get_avatar_file (contact) == NULL) { - GFile *avatar_file; - - /* If we requested avatar, it could come later */ - if (tp_contact_get_avatar_file (contact) == NULL) - { - g_signal_connect_swapped (contact, "notify::avatar-file", - G_CALLBACK (finish), &result); - g_main_loop_run (result.loop); - } - - g_assert_cmpstr (tp_contact_get_avatar_mime_type (contact), ==, - avatar_mime_type); - - avatar_file = tp_contact_get_avatar_file (contact); - g_assert (avatar_file != NULL); - g_file_load_contents (avatar_file, NULL, &content, NULL, NULL, - &result.error); - g_assert_no_error (result.error); - g_assert_cmpstr (content, ==, avatar_data); - g_free (content); + g_signal_connect_swapped (contact, "notify::avatar-file", + G_CALLBACK (finish), &result); + g_main_loop_run (result.loop); } + avatar_file = tp_contact_get_avatar_file (contact); + g_assert (avatar_file != NULL); + g_file_load_contents (avatar_file, NULL, &content, NULL, NULL, + &result.error); + g_assert_no_error (result.error); + g_assert_cmpstr (content, ==, fake_avatar_data); + g_free (content); + reset_result (&result); g_main_loop_unref (result.loop); - g_array_unref (array); - return contact; } -static void -avatar_retrieved_cb (TpConnection *connection, - guint handle, - const gchar *token, - const GArray *avatar, - const gchar *mime_type, - gpointer user_data, - GObject *weak_object) -{ - gboolean *called = user_data; - - *called = TRUE; -} - /* From telepathy-haze, with permission */ static gboolean haze_remove_directory (const gchar *path) @@ -562,70 +528,54 @@ haze_remove_directory (const gchar *path) } static void -test_avatar_data (Fixture *f, - gconstpointer unused G_GNUC_UNUSED) +request_avatar_cb (TpTestsContactsConnection *conn, + TpHandle handle, + gpointer user_data) { - TpConnection *client_conn = f->client_conn; - gboolean avatar_retrieved_called; - GError *error = NULL; - TpContact *contact1, *contact2; - TpProxySignalConnection *signal_id; + guint *count = user_data; + GArray *data; - g_message (G_STRFUNC); + (*count)++; - /* Check if AvatarRetrieved gets called */ - signal_id = tp_cli_connection_interface_avatars_connect_to_avatar_retrieved ( - client_conn, avatar_retrieved_cb, &avatar_retrieved_called, NULL, NULL, - &error); - g_assert_no_error (error); + data = g_array_new (FALSE, FALSE, sizeof (gchar)); + g_array_append_vals (data, fake_avatar_data, strlen (fake_avatar_data) + 1); - /* First time we create a contact, avatar should not be in cache, so - * AvatarRetrived should be called */ - avatar_retrieved_called = FALSE; - contact1 = create_contact_with_fake_avatar (f, "fake-id1", TRUE); - g_assert (avatar_retrieved_called); - g_assert (contact1 != NULL); - g_assert (tp_contact_get_avatar_file (contact1) != NULL); + tp_tests_contacts_connection_avatar_retrieved (conn, handle, + fake_avatar_token, data, fake_avatar_mime_type); - /* Second time we create a contact, avatar should be in cache now, so - * AvatarRetrived should NOT be called */ - avatar_retrieved_called = FALSE; - contact2 = create_contact_with_fake_avatar (f, "fake-id2", TRUE); - g_assert (!avatar_retrieved_called); - g_assert (contact2 != NULL); - g_assert (tp_contact_get_avatar_file (contact2) != NULL); - - g_assert (g_file_equal ( - tp_contact_get_avatar_file (contact1), - tp_contact_get_avatar_file (contact2))); - - tp_proxy_signal_connection_disconnect (signal_id); - g_object_unref (contact1); - g_object_unref (contact2); + g_array_unref (data); } static void -test_avatar_data_after_token (Fixture *f, +test_avatar_data (Fixture *f, gconstpointer unused G_GNUC_UNUSED) { - const gchar *id = "avatar-data-after-token"; TpContact *contact1, *contact2; + guint request_count = 0; g_message (G_STRFUNC); - /* Create a contact with AVATAR_TOKEN feature */ - contact1 = create_contact_with_fake_avatar (f, id, FALSE); + g_signal_connect (f->service_conn, "request-avatar", + G_CALLBACK (request_avatar_cb), &request_count); + + /* First time we create a contact, avatar should not be in cache, so + * RequestAvatars should be called */ + contact1 = create_contact_with_fake_avatar (f, "fake-id1"); + g_assert_cmpuint (request_count, ==, 1); g_assert (contact1 != NULL); - g_assert (tp_contact_get_avatar_file (contact1) == NULL); + g_assert (tp_contact_get_avatar_file (contact1) != NULL); - /* Now create the same contact with AVATAR_DATA feature */ - contact2 = create_contact_with_fake_avatar (f, id, TRUE); + /* Second time we create a contact, avatar should be in cache now, so + * RequestAvatars should NOT be called */ + contact2 = create_contact_with_fake_avatar (f, "fake-id2"); + g_assert_cmpuint (request_count, ==, 1); g_assert (contact2 != NULL); g_assert (tp_contact_get_avatar_file (contact2) != NULL); - g_assert (contact1 == contact2); + g_assert (g_file_equal ( + tp_contact_get_avatar_file (contact1), + tp_contact_get_avatar_file (contact2))); - /* Cleanup */ g_object_unref (contact1); g_object_unref (contact2); } @@ -736,8 +686,6 @@ test_no_features (Fixture *f, ids[i]); g_assert_cmpstr (tp_contact_get_alias (contacts[i]), ==, tp_contact_get_identifier (contacts[i])); - MYASSERT (tp_contact_get_avatar_token (contacts[i]) == NULL, - ": %s", tp_contact_get_avatar_token (contacts[i])); g_assert_cmpuint (tp_contact_get_presence_type (contacts[i]), ==, TP_CONNECTION_PRESENCE_TYPE_UNSET); g_assert_cmpstr (tp_contact_get_presence_status (contacts[i]), ==, @@ -747,8 +695,6 @@ test_no_features (Fixture *f, MYASSERT (!tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_ALIAS), ""); MYASSERT (!tp_contact_has_feature (contacts[i], - TP_CONTACT_FEATURE_AVATAR_TOKEN), ""); - MYASSERT (!tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_PRESENCE), ""); MYASSERT (!tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_LOCATION), ""); @@ -844,7 +790,6 @@ test_upgrade (Fixture *f, static const gchar * const ids[] = { "alice", "bob", "chris" }; static const gchar * const aliases[] = { "Alice in Wonderland", "Bob the Builder", "Christopher Robin" }; - static const gchar * const tokens[] = { "aaaaa", "bbbbb", "ccccc" }; static TpTestsContactsConnectionPresenceStatusIndex statuses[] = { TP_TESTS_CONTACTS_CONNECTION_STATUS_AVAILABLE, TP_TESTS_CONTACTS_CONNECTION_STATUS_BUSY, @@ -861,7 +806,7 @@ test_upgrade (Fixture *f, GHashTable *capabilities; TpContact *contacts[3]; GQuark features[] = { TP_CONTACT_FEATURE_ALIAS, - TP_CONTACT_FEATURE_AVATAR_TOKEN, TP_CONTACT_FEATURE_PRESENCE, + TP_CONTACT_FEATURE_PRESENCE, TP_CONTACT_FEATURE_LOCATION, TP_CONTACT_FEATURE_CAPABILITIES, 0 }; guint i; @@ -874,8 +819,6 @@ test_upgrade (Fixture *f, aliases); tp_tests_contacts_connection_change_presences (service_conn, 3, handles, statuses, messages); - tp_tests_contacts_connection_change_avatar_tokens (service_conn, 3, handles, - tokens); tp_tests_contacts_connection_change_locations (service_conn, 3, handles, locations); @@ -903,8 +846,6 @@ test_upgrade (Fixture *f, ids[i]); g_assert_cmpstr (tp_contact_get_alias (contacts[i]), ==, tp_contact_get_identifier (contacts[i])); - MYASSERT (tp_contact_get_avatar_token (contacts[i]) == NULL, - ": %s", tp_contact_get_avatar_token (contacts[i])); g_assert_cmpuint (tp_contact_get_presence_type (contacts[i]), ==, TP_CONNECTION_PRESENCE_TYPE_UNSET); g_assert_cmpstr (tp_contact_get_presence_status (contacts[i]), ==, @@ -914,8 +855,6 @@ test_upgrade (Fixture *f, MYASSERT (!tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_ALIAS), ""); MYASSERT (!tp_contact_has_feature (contacts[i], - TP_CONTACT_FEATURE_AVATAR_TOKEN), ""); - MYASSERT (!tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_PRESENCE), ""); MYASSERT (!tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_LOCATION), ""); @@ -953,11 +892,6 @@ test_upgrade (Fixture *f, aliases[i]); MYASSERT (tp_contact_has_feature (contacts[i], - TP_CONTACT_FEATURE_AVATAR_TOKEN), ""); - g_assert_cmpstr (tp_contact_get_avatar_token (contacts[i]), ==, - tokens[i]); - - MYASSERT (tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_PRESENCE), ""); g_assert_cmpstr (tp_contact_get_presence_message (contacts[i]), ==, messages[i]); @@ -1036,7 +970,6 @@ test_upgrade_noop (Fixture *f, typedef struct { gboolean alias_changed; - gboolean avatar_token_changed; gboolean presence_type_changed; gboolean presence_status_changed; gboolean presence_msg_changed; @@ -1048,8 +981,7 @@ static void notify_ctx_init (notify_ctx *ctx) { ctx->alias_changed = FALSE; - ctx->avatar_token_changed = FALSE; - ctx->presence_type_changed = FALSE; + ctx->presence_type_changed = FALSE; ctx->presence_status_changed = FALSE; ctx->presence_msg_changed = FALSE; ctx->location_changed = FALSE; @@ -1059,7 +991,7 @@ notify_ctx_init (notify_ctx *ctx) static gboolean notify_ctx_is_fully_changed (notify_ctx *ctx) { - return ctx->alias_changed && ctx->avatar_token_changed && + return ctx->alias_changed && ctx->presence_type_changed && ctx->presence_status_changed && ctx->presence_msg_changed && ctx->location_changed && ctx->capabilities_changed; @@ -1068,7 +1000,7 @@ notify_ctx_is_fully_changed (notify_ctx *ctx) static gboolean notify_ctx_is_changed (notify_ctx *ctx) { - return ctx->alias_changed || ctx->avatar_token_changed || + return ctx->alias_changed || ctx->presence_type_changed || ctx->presence_status_changed || ctx->presence_msg_changed || ctx->location_changed || ctx->capabilities_changed; @@ -1081,8 +1013,6 @@ contact_notify_cb (TpContact *contact, { if (!tp_strdiff (param->name, "alias")) ctx->alias_changed = TRUE; - else if (!tp_strdiff (param->name, "avatar-token")) - ctx->avatar_token_changed = TRUE; else if (!tp_strdiff (param->name, "presence-type")) ctx->presence_type_changed = TRUE; else if (!tp_strdiff (param->name, "presence-status")) @@ -1128,7 +1058,6 @@ test_features (Fixture *f, static const gchar * const ids[] = { "alice", "bob", "chris" }; static const gchar * const aliases[] = { "Alice in Wonderland", "Bob the Builder", "Christopher Robin" }; - static const gchar * const tokens[] = { "aaaaa", "bbbbb", "ccccc" }; static TpTestsContactsConnectionPresenceStatusIndex statuses[] = { TP_TESTS_CONTACTS_CONNECTION_STATUS_AVAILABLE, TP_TESTS_CONTACTS_CONNECTION_STATUS_BUSY, @@ -1137,7 +1066,6 @@ test_features (Fixture *f, "GON OUT BACKSON" }; static const gchar * const new_aliases[] = { "Alice [at a tea party]", "Bob the Plumber" }; - static const gchar * const new_tokens[] = { "AAAA", "BBBB" }; static TpTestsContactsConnectionPresenceStatusIndex new_statuses[] = { TP_TESTS_CONTACTS_CONNECTION_STATUS_AWAY, TP_TESTS_CONTACTS_CONNECTION_STATUS_AVAILABLE }; @@ -1162,7 +1090,7 @@ test_features (Fixture *f, gboolean new_support_text_chatrooms[] = { TRUE, FALSE }; TpContact *contacts[3]; GQuark features[] = { TP_CONTACT_FEATURE_ALIAS, - TP_CONTACT_FEATURE_AVATAR_TOKEN, TP_CONTACT_FEATURE_PRESENCE, + TP_CONTACT_FEATURE_PRESENCE, TP_CONTACT_FEATURE_LOCATION, TP_CONTACT_FEATURE_CAPABILITIES, 0 }; guint i; struct { @@ -1170,7 +1098,6 @@ test_features (Fixture *f, TpHandle handle; gchar *identifier; gchar *alias; - gchar *avatar_token; TpConnectionPresenceType presence_type; gchar *presence_status; gchar *presence_message; @@ -1188,8 +1115,6 @@ test_features (Fixture *f, aliases); tp_tests_contacts_connection_change_presences (service_conn, 3, handles, statuses, messages); - tp_tests_contacts_connection_change_avatar_tokens (service_conn, 3, handles, - tokens); tp_tests_contacts_connection_change_locations (service_conn, 3, handles, locations); @@ -1228,11 +1153,6 @@ test_features (Fixture *f, aliases[i]); MYASSERT (tp_contact_has_feature (contacts[i], - TP_CONTACT_FEATURE_AVATAR_TOKEN), ""); - g_assert_cmpstr (tp_contact_get_avatar_token (contacts[i]), ==, - tokens[i]); - - MYASSERT (tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_PRESENCE), ""); g_assert_cmpstr (tp_contact_get_presence_message (contacts[i]), ==, messages[i]); @@ -1274,7 +1194,6 @@ test_features (Fixture *f, "handle", &from_gobject.handle, "identifier", &from_gobject.identifier, "alias", &from_gobject.alias, - "avatar-token", &from_gobject.avatar_token, "presence-type", &from_gobject.presence_type, "presence-status", &from_gobject.presence_status, "presence-message", &from_gobject.presence_message, @@ -1285,7 +1204,6 @@ test_features (Fixture *f, g_assert_cmpuint (from_gobject.handle, ==, handles[0]); g_assert_cmpstr (from_gobject.identifier, ==, "alice"); g_assert_cmpstr (from_gobject.alias, ==, "Alice in Wonderland"); - g_assert_cmpstr (from_gobject.avatar_token, ==, "aaaaa"); g_assert_cmpuint (from_gobject.presence_type, ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE); g_assert_cmpstr (from_gobject.presence_status, ==, "available"); @@ -1300,7 +1218,6 @@ test_features (Fixture *f, g_object_unref (from_gobject.connection); g_free (from_gobject.identifier); g_free (from_gobject.alias); - g_free (from_gobject.avatar_token); g_free (from_gobject.presence_status); g_free (from_gobject.presence_message); g_hash_table_unref (from_gobject.location); @@ -1319,8 +1236,6 @@ test_features (Fixture *f, new_aliases); tp_tests_contacts_connection_change_presences (service_conn, 2, handles, new_statuses, new_messages); - tp_tests_contacts_connection_change_avatar_tokens (service_conn, 2, handles, - new_tokens); tp_tests_contacts_connection_change_locations (service_conn, 2, handles, new_locations); @@ -1348,11 +1263,6 @@ test_features (Fixture *f, new_aliases[i]); MYASSERT (tp_contact_has_feature (contacts[i], - TP_CONTACT_FEATURE_AVATAR_TOKEN), ""); - g_assert_cmpstr (tp_contact_get_avatar_token (contacts[i]), ==, - new_tokens[i]); - - MYASSERT (tp_contact_has_feature (contacts[i], TP_CONTACT_FEATURE_PRESENCE), ""); g_assert_cmpstr (tp_contact_get_presence_message (contacts[i]), ==, new_messages[i]); @@ -1941,7 +1851,6 @@ test_contact_list (Fixture *f, factory = tp_proxy_get_factory (f->client_conn); tp_client_factory_add_contact_features_varargs (factory, TP_CONTACT_FEATURE_ALIAS, - TP_CONTACT_FEATURE_AVATAR_DATA, 0); /* Now put it online and wait for contact list state move to success */ @@ -1969,10 +1878,6 @@ test_contact_list (Fixture *f, /* Even if we didn't explicitely asked that feature, we should have it for free */ g_assert (tp_contact_has_feature (contact, TP_CONTACT_FEATURE_SUBSCRIPTION_STATES)); g_assert_cmpint (tp_contact_get_subscribe_state (contact), ==, TP_SUBSCRIPTION_STATE_ASK); - /* We asked for AVATAR_DATA, verify we got it. This is special because it has - * no contact attribute, and ContactList preparation does not go through - * the slow path. */ - g_assert (tp_contact_has_feature (contact, TP_CONTACT_FEATURE_AVATAR_DATA)); g_ptr_array_unref (contacts); } @@ -2075,11 +1980,10 @@ setup_internal (Fixture *f, * TpContactFeature... */ const GQuark features[] = { TP_CONTACT_FEATURE_ALIAS, - TP_CONTACT_FEATURE_AVATAR_TOKEN, + TP_CONTACT_FEATURE_AVATAR, TP_CONTACT_FEATURE_PRESENCE, TP_CONTACT_FEATURE_LOCATION, TP_CONTACT_FEATURE_CAPABILITIES, - TP_CONTACT_FEATURE_AVATAR_DATA, TP_CONTACT_FEATURE_CONTACT_INFO, TP_CONTACT_FEATURE_CLIENT_TYPES, TP_CONTACT_FEATURE_SUBSCRIPTION_STATES, @@ -2163,7 +2067,6 @@ main (int argc, ADD (by_id); ADD (avatar_requirements); ADD (avatar_data); - ADD (avatar_data_after_token); ADD (contact_info); ADD (dup_if_possible); ADD (subscription_states); diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c index cda0020ac..87a1bdc09 100644 --- a/tests/lib/contacts-conn.c +++ b/tests/lib/contacts-conn.c @@ -15,6 +15,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/avatars-mixin.h> #include <telepathy-glib/interfaces.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/errors.h> @@ -26,10 +27,7 @@ #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, @@ -37,7 +35,7 @@ G_DEFINE_TYPE_WITH_CODE (TpTestsContactsConnection, G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING, init_aliasing); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_AVATARS, - init_avatars); + tp_avatars_mixin_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_PRESENCE, tp_presence_mixin_iface_init); G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_LOCATION, NULL) @@ -57,31 +55,18 @@ G_DEFINE_TYPE_WITH_CODE (TpTestsContactsConnection, /* 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 { + REQUEST_AVATAR, N_SIGNALS }; +static guint signals[N_SIGNALS] = {0}; + struct _TpTestsContactsConnectionPrivate { /* TpHandle => gchar * */ GHashTable *aliases; - /* TpHandle => AvatarData */ - GHashTable *avatars; /* TpHandle => ContactsConnectionPresenceStatusIndex */ GHashTable *presence_statuses; /* TpHandle => gchar * */ @@ -97,42 +82,6 @@ struct _TpTestsContactsConnectionPrivate 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) @@ -147,8 +96,6 @@ tp_tests_contacts_connection_init (TpTestsContactsConnection *self) 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, @@ -167,8 +114,8 @@ finalize (GObject *object) TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); tp_contacts_mixin_finalize (object); + tp_avatars_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); @@ -209,28 +156,6 @@ aliasing_fill_contact_attributes (GObject *object, } } -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_AVATARS "/token", - tp_g_value_slice_new_string (a->token)); - } - } -} static void location_fill_contact_attributes (GObject *object, @@ -386,6 +311,44 @@ client_types_fill_contact_attributes ( */ } +static gboolean +set_avatar_impl (GObject *obj, + const GArray *avatar, + const gchar *mime_type, + GError **error) +{ + g_set_error (error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, + "SetAvatar is not implemented on the test CM"); + + return FALSE; +} + +static gboolean +clear_avatar_impl (GObject *obj, + GError **error) +{ + g_set_error (error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED, + "ClearAvatar is not implemented on the test CM"); + + return FALSE; +} + +static gboolean +request_avatars_impl (GObject *obj, + const GArray *handles, + GError **error) +{ + guint i; + + for (i = 0; i < handles->len; i++) + { + g_signal_emit (obj, signals[REQUEST_AVATAR], 0, + g_array_index (handles, TpHandle, i)); + } + + return TRUE; +} + static void constructed (GObject *object) { @@ -393,6 +356,8 @@ constructed (GObject *object) TpBaseConnection *base = TP_BASE_CONNECTION (object); void (*parent_impl) (GObject *) = G_OBJECT_CLASS (tp_tests_contacts_connection_parent_class)->constructed; + gchar *mime_types[] = { "image/png", NULL }; + TpAvatarRequirements *req; if (parent_impl != NULL) parent_impl (object); @@ -412,9 +377,6 @@ constructed (GObject *object) TP_IFACE_CONNECTION_INTERFACE_ALIASING, aliasing_fill_contact_attributes); tp_contacts_mixin_add_contact_attributes_iface (object, - TP_IFACE_CONNECTION_INTERFACE_AVATARS, - avatars_fill_contact_attributes); - tp_contacts_mixin_add_contact_attributes_iface (object, TP_IFACE_CONNECTION_INTERFACE_LOCATION, location_fill_contact_attributes); tp_contacts_mixin_add_contact_attributes_iface (object, @@ -430,6 +392,17 @@ constructed (GObject *object) tp_presence_mixin_init (object, G_STRUCT_OFFSET (TpTestsContactsConnection, presence_mixin)); tp_presence_mixin_register_with_contacts_mixin (object); + + req = tp_avatar_requirements_new (mime_types, 1, 2, 3, 4, 5, 6, 7); + tp_avatars_mixin_init (object, + G_STRUCT_OFFSET (TpTestsContactsConnection, avatars_mixin), + set_avatar_impl, + clear_avatar_impl, + request_avatars_impl, + TRUE, req); + tp_avatar_requirements_destroy (req); + + tp_avatars_mixin_register_with_contacts_mixin (object); } static const TpPresenceStatusOptionalArgumentSpec can_have_message[] = { @@ -567,11 +540,6 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) GObjectClass *object_class = (GObjectClass *) klass; TpPresenceMixinClass *mixin_class; static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = { - { TP_IFACE_CONNECTION_INTERFACE_AVATARS, - conn_avatars_properties_getter, - NULL, - conn_avatars_properties, - }, { TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO, conn_contact_info_properties_getter, NULL, @@ -587,6 +555,14 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) base_class->get_interfaces_always_present = tp_tests_contacts_get_interfaces_always_present; base_class->create_channel_managers = create_channel_managers; + signals[REQUEST_AVATAR] = + g_signal_new ("request-avatar", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, NULL, + G_TYPE_NONE, 1, G_TYPE_UINT); + tp_contacts_mixin_class_init (object_class, G_STRUCT_OFFSET (TpTestsContactsConnectionClass, contacts_mixin)); @@ -605,6 +581,8 @@ tp_tests_contacts_connection_class_init (TpTestsContactsConnectionClass *klass) G_STRUCT_OFFSET (TpTestsContactsConnectionClass, properties_class)); tp_base_contact_list_mixin_class_init (base_class); + + tp_avatars_mixin_init_dbus_properties (object_class); } TpTestsContactListManager * @@ -701,36 +679,22 @@ tp_tests_contacts_connection_change_presences ( } void -tp_tests_contacts_connection_change_avatar_tokens (TpTestsContactsConnection *self, - guint n, - const TpHandle *handles, - const gchar * const *tokens) +tp_tests_contacts_connection_avatar_retrieved (TpTestsContactsConnection *self, + TpHandle handle, + const gchar *token, + GArray *data, + const gchar *mime_type) { - 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_avatars_emit_avatar_updated (self, - handles[i], tokens[i]); - } + tp_avatars_mixin_avatar_retrieved ((GObject *) self, handle, + token, data, mime_type); } void -tp_tests_contacts_connection_change_avatar_data ( - TpTestsContactsConnection *self, +tp_tests_contacts_connection_avatar_changed (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_avatars_emit_avatar_updated (self, - handle, token); + tp_avatars_mixin_avatar_changed ((GObject *) self, handle, token); } void @@ -918,77 +882,6 @@ init_aliasing (gpointer g_iface, #undef IMPLEMENT } -static void -my_request_avatars (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; - 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_avatars_emit_avatar_retrieved (self, handle, - a->token, a->data, a->mime_type); - } - - tp_svc_connection_interface_avatars_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) -{ - TpSvcConnectionInterfaceAvatarsClass *klass = g_iface; - -#define IMPLEMENT(x) tp_svc_connection_interface_avatars_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) diff --git a/tests/lib/contacts-conn.h b/tests/lib/contacts-conn.h index 174f1de02..0f600cee6 100644 --- a/tests/lib/contacts-conn.h +++ b/tests/lib/contacts-conn.h @@ -13,6 +13,7 @@ #define __TP_TESTS_CONTACTS_CONN_H__ #include <glib-object.h> +#include <telepathy-glib/avatars-mixin.h> #include <telepathy-glib/base-connection.h> #include <telepathy-glib/contacts-mixin.h> #include <telepathy-glib/dbus-properties-mixin.h> @@ -42,6 +43,7 @@ struct _TpTestsContactsConnection { TpPresenceMixin presence_mixin; TpContactsMixin contacts_mixin; + TpAvatarsMixin avatars_mixin; TpTestsContactsConnectionPrivate *priv; }; @@ -87,15 +89,16 @@ void tp_tests_contacts_connection_change_presences ( 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 ( +void tp_tests_contacts_connection_avatar_retrieved ( TpTestsContactsConnection *self, TpHandle handle, + const gchar *token, GArray *data, - const gchar *mime_type, + const gchar *mime_type); + +void tp_tests_contacts_connection_avatar_changed ( + TpTestsContactsConnection *self, + TpHandle handle, const gchar *token); void tp_tests_contacts_connection_change_locations ( |