diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-10-17 10:31:42 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-10-31 17:12:21 +0100 |
commit | 726e4173951c47757adaaf97368af862bdd3e2e8 (patch) | |
tree | f28d42cc8c5a0347406127afbd36b480d7818d2e /tests | |
parent | dfe6f80cf4e73d60d06fbe67b1f9c6ef0af4d545 (diff) |
add high level API to block/unblock contacts
https://bugs.freedesktop.org/show_bug.cgi?id=41801
Diffstat (limited to 'tests')
-rw-r--r-- | tests/dbus/Makefile.am | 6 | ||||
-rw-r--r-- | tests/dbus/contact-list-clt.c | 185 |
2 files changed, 191 insertions, 0 deletions
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am index 3f1e8e62..122ef232 100644 --- a/tests/dbus/Makefile.am +++ b/tests/dbus/Makefile.am @@ -26,6 +26,7 @@ noinst_PROGRAMS = \ test-connection-interests \ test-connection-getinterfaces-failure \ test-contact-lists \ + test-contact-list-clt \ test-contacts \ test-contacts-bug-19101 \ test-contacts-mixin \ @@ -116,6 +117,11 @@ test_contact_lists_LDADD = \ $(LDADD) \ $(top_builddir)/examples/cm/contactlist/libexample-cm-contactlist.la +test_contact_list_clt_SOURCES = contact-list-clt.c +test_contact_list_clt_LDADD = \ + $(LDADD) \ + $(top_builddir)/examples/cm/contactlist/libexample-cm-contactlist.la + test_connection_balance_SOURCES = connection-balance.c test_connection_bug_18845_SOURCES = connection-bug-18845.c diff --git a/tests/dbus/contact-list-clt.c b/tests/dbus/contact-list-clt.c new file mode 100644 index 00000000..a5278153 --- /dev/null +++ b/tests/dbus/contact-list-clt.c @@ -0,0 +1,185 @@ +/* Tests of TpTextChannel + * + * Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * + * Copying and distribution of this file, with or without modification, + * are permitted in any medium without royalty provided the copyright + * notice and this notice are preserved. + */ + +#include <string.h> + +#include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/message-mixin.h> + +#include "examples/cm/contactlist/conn.h" + +#include "tests/lib/util.h" + +typedef struct { + GMainLoop *mainloop; + TpDBusDaemon *dbus; + + /* Service side objects */ + TpBaseConnection *base_connection; + TpHandleRepoIface *contact_repo; + + /* Client side objects */ + TpConnection *connection; + TpTextChannel *channel; + TpTextChannel *sms_channel; + + GError *error /* initialized where needed */; + gint wait; +} Test; + +static void +setup (Test *test, + gconstpointer data) +{ + gchar *conn_name, *conn_path; + GQuark conn_features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 }; + + test->mainloop = g_main_loop_new (NULL, FALSE); + test->dbus = tp_tests_dbus_daemon_dup_or_die (); + + test->error = NULL; + + /* Create (service and client sides) connection objects */ + test->base_connection = tp_tests_object_new_static_class ( + EXAMPLE_TYPE_CONTACT_LIST_CONNECTION, + "account", "me@test.com", + "simulation-delay", 0, + "protocol", "test", + NULL); + + g_assert (tp_base_connection_register (test->base_connection, "example", + &conn_name, &conn_path, &test->error)); + g_assert_no_error (test->error); + + test->connection = tp_connection_new (test->dbus, conn_name, conn_path, + &test->error); + g_assert_no_error (test->error); + + test->contact_repo = tp_base_connection_get_handles (test->base_connection, + TP_HANDLE_TYPE_CONTACT); + g_assert (test->contact_repo != NULL); + + /* Connect the connection */ + tp_cli_connection_call_connect (test->connection, -1, NULL, NULL, NULL, NULL); + tp_tests_proxy_run_until_prepared (test->connection, conn_features); + + g_free (conn_name); + g_free (conn_path); +} + +static void +teardown (Test *test, + gconstpointer data) +{ + g_clear_error (&test->error); + + tp_clear_object (&test->dbus); + g_main_loop_unref (test->mainloop); + test->mainloop = NULL; + + tp_cli_connection_run_disconnect (test->connection, -1, &test->error, NULL); + g_assert_no_error (test->error); + + g_object_unref (test->connection); + g_object_unref (test->base_connection); +} + +static void +block_contacts_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + Test *test = user_data; + + tp_connection_block_contacts_finish (TP_CONNECTION (source), result, + &test->error); + g_assert_no_error (test->error); + + test->wait--; + if (test->wait <= 0) + g_main_loop_quit (test->mainloop); +} + +static void +unblock_contacts_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + Test *test = user_data; + + tp_connection_unblock_contacts_finish (TP_CONNECTION (source), result, + &test->error); + g_assert_no_error (test->error); + + test->wait--; + if (test->wait <= 0) + g_main_loop_quit (test->mainloop); +} + +static void +test_block_unblock (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + TpHandle handle; + TpContact *alice, *bob; + GPtrArray *arr; + + /* Create contacts */ + handle = tp_handle_ensure (test->contact_repo, "alice", NULL, &test->error); + g_assert_no_error (test->error); + + alice = tp_connection_dup_contact_if_possible (test->connection, handle, + "alice"); + g_assert (alice != NULL); + + handle = tp_handle_ensure (test->contact_repo, "bob", NULL, &test->error); + g_assert_no_error (test->error); + + bob = tp_connection_dup_contact_if_possible (test->connection, handle, "bob"); + g_assert (bob != NULL); + + arr = g_ptr_array_sized_new (2); + g_ptr_array_add (arr, alice); + g_ptr_array_add (arr, bob); + + /* Block contacts */ + tp_connection_block_contacts_async (test->connection, + arr->len, (TpContact * const *) arr->pdata, FALSE, + block_contacts_cb, test); + + test->wait = 1; + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + /* Unblock contacts */ + tp_connection_unblock_contacts_async (test->connection, + arr->len, (TpContact * const *) arr->pdata, + unblock_contacts_cb, test); + + test->wait = 1; + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + g_object_unref (alice); + g_object_unref (bob); + g_ptr_array_unref (arr); +} + +int +main (int argc, + char **argv) +{ + tp_tests_init (&argc, &argv); + g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id="); + + g_test_add ("/contact-list-clt/blocking/block-unblock", Test, NULL, setup, + test_block_unblock, teardown); + + return g_test_run (); +} |