diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-01-08 15:08:03 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-01-08 15:08:03 +0000 |
commit | e55d7bc56c4af7e80d9be785596844255de7875d (patch) | |
tree | f4168aeef133381c1eb0628a33ca3f5a46e2de0b | |
parent | cd8d95a24089186352dff4b6ae26568f26015844 (diff) |
Move test_names from test-contacts to test-names
-rw-r--r-- | tests/dbus/contacts.c | 261 | ||||
-rw-r--r-- | tests/dbus/names.c | 229 |
2 files changed, 229 insertions, 261 deletions
diff --git a/tests/dbus/contacts.c b/tests/dbus/contacts.c index 5823e27d6..c640ef183 100644 --- a/tests/dbus/contacts.c +++ b/tests/dbus/contacts.c @@ -42,14 +42,6 @@ "member='MembersChanged'" typedef struct { - enum { NAMES_BOTH, NAMES_MISSING, NAMES_ONLY } names; -} Options; - -static Options normal_options = { NAMES_BOTH }; -static Options no_names_options = { NAMES_MISSING }; -static Options only_names_options = { NAMES_ONLY }; - -typedef struct { GMainLoop *loop; GError *error /* initialized to 0 */; GPtrArray *contacts; @@ -69,11 +61,6 @@ typedef struct { TpConnection *client_conn; TpConnection *legacy_client_conn; TpConnection *no_requests_client_conn; - GAsyncResult *async_result; - gsize notify_alias_received; - gsize notify_nickname_received; - gsize notify_local_alias_received; - GError *error; } Fixture; /* We only really actively test TP_CONTACT_FEATURE_ALIAS, but preparing any @@ -2951,252 +2938,11 @@ test_self_contact (Fixture *f, } static void -notify_alias_cb (gpointer p) -{ - Fixture *f = p; - - DEBUG ("notify::alias"); - - f->notify_alias_received++; -} - -static void -notify_nickname_cb (gpointer p) -{ - Fixture *f = p; - - DEBUG ("notify::nickname"); - - f->notify_nickname_received++; -} - -static void -notify_local_alias_cb (gpointer p) -{ - Fixture *f = p; - - DEBUG ("notify::local_alias"); - - f->notify_local_alias_received++; -} - -static void -test_names (Fixture *f, - gconstpointer opts) -{ - TpConnection *client_conn = f->client_conn; - TpHandleRepoIface *service_repo = tp_base_connection_get_handles ( - f->base_connection, TP_HANDLE_TYPE_CONTACT); - TpContact *contact; - TpHandle handle; - const gchar *cstrv[] = { NULL, NULL }; - const Options *options = opts; - static TpContactFeature names_features[] = { - TP_CONTACT_FEATURE_NAMES - }; - - if (options == NULL) - options = &normal_options; - - handle = tp_handle_ensure (service_repo, "test-names", NULL, NULL); - contact = tp_tests_connection_run_until_contact_by_id (client_conn, - "test-names", 0, NULL); - - /* Initially alias fallbacks to id */ - g_assert_cmpstr (tp_contact_get_alias (contact), ==, "test-names"); - g_assert (tp_contact_get_nickname (contact) == NULL); - g_assert (tp_contact_get_local_alias (contact) == NULL); - - g_signal_connect_swapped (contact, "notify::alias", - G_CALLBACK (notify_alias_cb), f); - g_signal_connect_swapped (contact, "notify::local-alias", - G_CALLBACK (notify_local_alias_cb), f); - g_signal_connect_swapped (contact, "notify::nickname", - G_CALLBACK (notify_nickname_cb), f); - - /* Enable the Names (formerly Aliasing) feature */ - tp_connection_upgrade_contacts_async (f->client_conn, - 1, &contact, - G_N_ELEMENTS (names_features), names_features, - tp_tests_result_ready_cb, &f->async_result); - tp_tests_run_until_result (&f->async_result); - tp_connection_upgrade_contacts_finish (f->client_conn, f->async_result, - NULL, &f->error); - g_assert_no_error (f->error); - g_clear_object (&f->async_result); - - f->notify_alias_received = 0; - f->notify_nickname_received = 0; - f->notify_local_alias_received = 0; - - /* Contact creation should have implicitly initiated a nickname request, - * but it doesn't finish until later. When it does, it changes the - * nickname and alias, or if we only have Aliasing, just the alias. */ - while (f->notify_alias_received == 0 || - (options->names != NAMES_MISSING && - f->notify_nickname_received == 0)) - { - g_main_context_iteration (NULL, TRUE); - } - - g_assert_cmpuint (f->notify_local_alias_received, ==, 0); - g_assert_cmpstr (tp_contact_get_alias (contact), ==, "default-nickname"); - - if (options->names == NAMES_MISSING) - g_assert_cmpstr (tp_contact_get_nickname (contact), ==, NULL); - else - g_assert_cmpstr (tp_contact_get_nickname (contact), ==, - "default-nickname"); - - g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, NULL); - - /* Changing the nickname should change legacy alias as well */ - cstrv[0] = "test-nickname"; - tp_tests_contacts_connection_change_nicknames (f->service_conn, - 1, &handle, cstrv); - - f->notify_alias_received = 0; - f->notify_nickname_received = 0; - f->notify_local_alias_received = 0; - - while (f->notify_alias_received == 0 || - (options->names != NAMES_MISSING && - f->notify_nickname_received == 0)) - { - g_main_context_iteration (NULL, TRUE); - } - - g_assert_cmpuint (f->notify_local_alias_received, ==, 0); - g_assert_cmpstr (tp_contact_get_alias (contact), ==, "test-nickname"); - - if (options->names == NAMES_MISSING) - g_assert_cmpstr (tp_contact_get_nickname (contact), ==, NULL); - else - g_assert_cmpstr (tp_contact_get_nickname (contact), ==, - "test-nickname"); - - g_assert (tp_contact_get_local_alias (contact) == NULL); - - /* CM-side: overriding nickname with a local alias should modify legacy - * alias as well */ - cstrv[0] = "test-local-alias"; - tp_tests_contacts_connection_change_aliases (f->service_conn, - 1, &handle, cstrv); - - f->notify_alias_received = 0; - f->notify_nickname_received = 0; - f->notify_local_alias_received = 0; - - while (f->notify_alias_received == 0 || - (options->names != NAMES_MISSING && - f->notify_local_alias_received == 0)) - { - g_main_context_iteration (NULL, TRUE); - } - - g_assert_cmpuint (f->notify_nickname_received, ==, 0); - g_assert_cmpstr (tp_contact_get_alias (contact), ==, "test-local-alias"); - - if (options->names == NAMES_MISSING) - { - g_assert_cmpstr (tp_contact_get_nickname (contact), ==, NULL); - g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, NULL); - } - else - { - g_assert_cmpstr (tp_contact_get_nickname (contact), ==, - "test-nickname"); - g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, - "test-local-alias"); - } - - if (options->names != NAMES_MISSING) - { - /* Client-side: changing local alias via Names should modify - * legacy alias as well */ - tp_cli_connection_interface_names_call_set_local_alias (client_conn, -1, - handle, "new-local-alias", NULL, NULL, NULL, NULL); - - f->notify_alias_received = 0; - f->notify_nickname_received = 0; - f->notify_local_alias_received = 0; - - while (f->notify_alias_received == 0 || - f->notify_local_alias_received == 0) - { - g_main_context_iteration (NULL, TRUE); - } - - g_assert_cmpuint (f->notify_nickname_received, ==, 0); - g_assert_cmpstr (tp_contact_get_alias (contact), ==, "new-local-alias"); - g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, - "new-local-alias"); - } - - if (options->names != NAMES_ONLY) - { - GHashTable *aus = g_hash_table_new (NULL, NULL); - - /* Client-side: changing legacy alias via Aliasing should modify - * local alias as well */ - g_hash_table_insert (aus, GUINT_TO_POINTER (handle), "new-legacy-alias"); - tp_cli_connection_interface_aliasing_call_set_aliases (client_conn, -1, - aus, NULL, NULL, NULL, NULL); - g_hash_table_unref (aus); - - f->notify_alias_received = 0; - f->notify_nickname_received = 0; - f->notify_local_alias_received = 0; - - while (f->notify_alias_received == 0 || - (options->names != NAMES_MISSING && - f->notify_local_alias_received == 0)) - { - g_main_context_iteration (NULL, TRUE); - } - - g_assert_cmpuint (f->notify_nickname_received, ==, 0); - - g_assert_cmpstr (tp_contact_get_alias (contact), ==, "new-legacy-alias"); - - if (options->names == NAMES_MISSING) - g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, NULL); - else - g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, - "new-legacy-alias"); - } - - g_object_unref (contact); -} - -static void setup_internal (Fixture *f, gboolean connect, gconstpointer user_data) { - const Options *options = user_data; - GType type; - - if (options == NULL) - options = &normal_options; - - switch (options->names) - { - case NAMES_MISSING: - type = TP_TESTS_TYPE_NO_NAMES_CONNECTION; - break; - - case NAMES_ONLY: - type = TP_TESTS_TYPE_NO_ALIASING_CONNECTION; - break; - - case NAMES_BOTH: - default: - type = TP_TESTS_TYPE_CONTACTS_CONNECTION; - break; - } - - tp_tests_create_conn (type, + tp_tests_create_conn (TP_TESTS_TYPE_CONTACTS_CONNECTION, "me@test.com", connect, &f->base_connection, &f->client_conn); f->service_conn = TP_TESTS_CONTACTS_CONNECTION (f->base_connection); @@ -3294,11 +3040,6 @@ main (int argc, ADD (dup_if_possible); ADD (subscription_states); ADD (contact_groups); - ADD (names); - g_test_add ("/contacts/names/only-aliasing", Fixture, - &no_names_options, setup, test_names, teardown); - g_test_add ("/contacts/names/no-aliasing", Fixture, - &only_names_options, setup, test_names, teardown); /* test if TpContact fallbacks to connection's capabilities if * ContactCapabilities is not implemented. */ diff --git a/tests/dbus/names.c b/tests/dbus/names.c index e05460377..ada0024ae 100644 --- a/tests/dbus/names.c +++ b/tests/dbus/names.c @@ -1,6 +1,7 @@ /* Feature test for setting your own name. * - * Copyright © 2013 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright © 2008–2013 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright © 2008 Nokia Corporation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -34,6 +35,9 @@ typedef struct { GAsyncResult *result; GError *error; guint pending; + gsize notify_alias_received; + gsize notify_nickname_received; + gsize notify_local_alias_received; } Fixture; static void @@ -191,6 +195,225 @@ test_my_name (Fixture *f, } static void +notify_alias_cb (gpointer p) +{ + Fixture *f = p; + + DEBUG ("notify::alias"); + + f->notify_alias_received++; +} + +static void +notify_nickname_cb (gpointer p) +{ + Fixture *f = p; + + DEBUG ("notify::nickname"); + + f->notify_nickname_received++; +} + +static void +notify_local_alias_cb (gpointer p) +{ + Fixture *f = p; + + DEBUG ("notify::local_alias"); + + f->notify_local_alias_received++; +} + +static void +test_names (Fixture *f, + gconstpointer opts) +{ + TpConnection *client_conn = f->client_conn; + TpHandleRepoIface *service_repo = tp_base_connection_get_handles ( + f->base_conn, TP_HANDLE_TYPE_CONTACT); + TpContact *contact; + TpHandle handle; + const gchar *cstrv[] = { NULL, NULL }; + const Options *options = opts; + static TpContactFeature names_features[] = { + TP_CONTACT_FEATURE_NAMES + }; + + if (options == NULL) + options = &normal_options; + + handle = tp_handle_ensure (service_repo, "test-names", NULL, NULL); + contact = tp_tests_connection_run_until_contact_by_id (client_conn, + "test-names", 0, NULL); + + /* Initially alias fallbacks to id */ + g_assert_cmpstr (tp_contact_get_alias (contact), ==, "test-names"); + g_assert (tp_contact_get_nickname (contact) == NULL); + g_assert (tp_contact_get_local_alias (contact) == NULL); + + g_signal_connect_swapped (contact, "notify::alias", + G_CALLBACK (notify_alias_cb), f); + g_signal_connect_swapped (contact, "notify::local-alias", + G_CALLBACK (notify_local_alias_cb), f); + g_signal_connect_swapped (contact, "notify::nickname", + G_CALLBACK (notify_nickname_cb), f); + + /* Enable the Names (formerly Aliasing) feature */ + tp_connection_upgrade_contacts_async (f->client_conn, + 1, &contact, + G_N_ELEMENTS (names_features), names_features, + tp_tests_result_ready_cb, &f->result); + tp_tests_run_until_result (&f->result); + tp_connection_upgrade_contacts_finish (f->client_conn, f->result, + NULL, &f->error); + g_assert_no_error (f->error); + g_clear_object (&f->result); + + f->notify_alias_received = 0; + f->notify_nickname_received = 0; + f->notify_local_alias_received = 0; + + /* Contact creation should have implicitly initiated a nickname request, + * but it doesn't finish until later. When it does, it changes the + * nickname and alias, or if we only have Aliasing, just the alias. */ + while (f->notify_alias_received == 0 || + (options->names != NAMES_MISSING && + f->notify_nickname_received == 0)) + { + g_main_context_iteration (NULL, TRUE); + } + + g_assert_cmpuint (f->notify_local_alias_received, ==, 0); + g_assert_cmpstr (tp_contact_get_alias (contact), ==, "default-nickname"); + + if (options->names == NAMES_MISSING) + g_assert_cmpstr (tp_contact_get_nickname (contact), ==, NULL); + else + g_assert_cmpstr (tp_contact_get_nickname (contact), ==, + "default-nickname"); + + g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, NULL); + + /* Changing the nickname should change legacy alias as well */ + cstrv[0] = "test-nickname"; + tp_tests_contacts_connection_change_nicknames (f->service_conn, + 1, &handle, cstrv); + + f->notify_alias_received = 0; + f->notify_nickname_received = 0; + f->notify_local_alias_received = 0; + + while (f->notify_alias_received == 0 || + (options->names != NAMES_MISSING && + f->notify_nickname_received == 0)) + { + g_main_context_iteration (NULL, TRUE); + } + + g_assert_cmpuint (f->notify_local_alias_received, ==, 0); + g_assert_cmpstr (tp_contact_get_alias (contact), ==, "test-nickname"); + + if (options->names == NAMES_MISSING) + g_assert_cmpstr (tp_contact_get_nickname (contact), ==, NULL); + else + g_assert_cmpstr (tp_contact_get_nickname (contact), ==, + "test-nickname"); + + g_assert (tp_contact_get_local_alias (contact) == NULL); + + /* CM-side: overriding nickname with a local alias should modify legacy + * alias as well */ + cstrv[0] = "test-local-alias"; + tp_tests_contacts_connection_change_aliases (f->service_conn, + 1, &handle, cstrv); + + f->notify_alias_received = 0; + f->notify_nickname_received = 0; + f->notify_local_alias_received = 0; + + while (f->notify_alias_received == 0 || + (options->names != NAMES_MISSING && + f->notify_local_alias_received == 0)) + { + g_main_context_iteration (NULL, TRUE); + } + + g_assert_cmpuint (f->notify_nickname_received, ==, 0); + g_assert_cmpstr (tp_contact_get_alias (contact), ==, "test-local-alias"); + + if (options->names == NAMES_MISSING) + { + g_assert_cmpstr (tp_contact_get_nickname (contact), ==, NULL); + g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, NULL); + } + else + { + g_assert_cmpstr (tp_contact_get_nickname (contact), ==, + "test-nickname"); + g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, + "test-local-alias"); + } + + if (options->names != NAMES_MISSING) + { + /* Client-side: changing local alias via Names should modify + * legacy alias as well */ + tp_cli_connection_interface_names_call_set_local_alias (client_conn, -1, + handle, "new-local-alias", NULL, NULL, NULL, NULL); + + f->notify_alias_received = 0; + f->notify_nickname_received = 0; + f->notify_local_alias_received = 0; + + while (f->notify_alias_received == 0 || + f->notify_local_alias_received == 0) + { + g_main_context_iteration (NULL, TRUE); + } + + g_assert_cmpuint (f->notify_nickname_received, ==, 0); + g_assert_cmpstr (tp_contact_get_alias (contact), ==, "new-local-alias"); + g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, + "new-local-alias"); + } + + if (options->names != NAMES_ONLY) + { + GHashTable *aus = g_hash_table_new (NULL, NULL); + + /* Client-side: changing legacy alias via Aliasing should modify + * local alias as well */ + g_hash_table_insert (aus, GUINT_TO_POINTER (handle), "new-legacy-alias"); + tp_cli_connection_interface_aliasing_call_set_aliases (client_conn, -1, + aus, NULL, NULL, NULL, NULL); + g_hash_table_unref (aus); + + f->notify_alias_received = 0; + f->notify_nickname_received = 0; + f->notify_local_alias_received = 0; + + while (f->notify_alias_received == 0 || + (options->names != NAMES_MISSING && + f->notify_local_alias_received == 0)) + { + g_main_context_iteration (NULL, TRUE); + } + + g_assert_cmpuint (f->notify_nickname_received, ==, 0); + + g_assert_cmpstr (tp_contact_get_alias (contact), ==, "new-legacy-alias"); + + if (options->names == NAMES_MISSING) + g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, NULL); + else + g_assert_cmpstr (tp_contact_get_local_alias (contact), ==, + "new-legacy-alias"); + } + + g_object_unref (contact); +} + +static void teardown (Fixture *f, gconstpointer unused G_GNUC_UNUSED) { @@ -216,6 +439,10 @@ main (int argc, g_test_add ("/self-names/" #x "/" #opts, \ Fixture, &opts, setup, test_ ## x, teardown) + ADD (names, normal_options); + ADD (names, no_names_options); + ADD (names, only_names_options); + ADD (my_name, normal_options); ADD (my_name, no_names_options); ADD (my_name, only_names_options); |