From 812ff16b822ef2ab1b10d8bf7db0774b299e4e73 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 26 Sep 2013 16:46:50 +0200 Subject: [PATCH 1/6] add logger-test-helper.c Introduce a new helper file to contain logger test specific helper functions. Add helper function to register and prepare accounts. https://bugs.freedesktop.org/show_bug.cgi?id=69814 --- tests/lib/Makefile.am | 4 ++- tests/lib/logger-test-helper.c | 79 ++++++++++++++++++++++++++++++++++++++++++ tests/lib/logger-test-helper.h | 39 +++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 tests/lib/logger-test-helper.c create mode 100644 tests/lib/logger-test-helper.h diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 0f7fc28..5a3b35d 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -16,7 +16,9 @@ libtp_logger_tests_la_SOURCES = \ textchan-null.c \ textchan-null.h \ util.c \ - util.h + util.h \ + logger-test-helper.c \ + logger-test-helper.h check_c_sources = *.c include $(top_srcdir)/tools/check-coding-style.mk diff --git a/tests/lib/logger-test-helper.c b/tests/lib/logger-test-helper.c new file mode 100644 index 0000000..6ec8a59 --- /dev/null +++ b/tests/lib/logger-test-helper.c @@ -0,0 +1,79 @@ +/* + * logger-test-helper.c + * + * Copyright (C) 2013 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "logger-test-helper.h" + +static void +account_prepare_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GMainLoop *main_loop = user_data; + GError *error = NULL; + + tp_proxy_prepare_finish (source, result, &error); + g_assert_no_error (error); + + g_main_loop_quit (main_loop); +} + +void +tpl_test_create_and_prepare_account (TpDBusDaemon *dbus, + TpSimpleClientFactory *factory, + GMainLoop *main_loop, + const gchar *path, + TpAccount **account, + TpTestsSimpleAccount **account_service) +{ + GError *error = NULL; + GArray *features; + + *account_service = g_object_new (TP_TESTS_TYPE_SIMPLE_ACCOUNT, + NULL); + g_assert (*account_service != NULL); + + tp_dbus_daemon_register_object (dbus, path, *account_service); + + *account = tp_simple_client_factory_ensure_account (factory, path, NULL, + &error); + g_assert_no_error (error); + g_assert (*account != NULL); + + features = tp_simple_client_factory_dup_account_features (factory, *account); + + tp_proxy_prepare_async (*account, (GQuark *) features->data, + account_prepare_cb, main_loop); + g_free (features->data); + g_array_free (features, FALSE); + + g_main_loop_run (main_loop); +} + +void +tpl_test_release_account (TpDBusDaemon *dbus, + TpAccount *account, + TpTestsSimpleAccount *account_service) +{ + tp_dbus_daemon_unregister_object (dbus, account_service); + g_object_unref (account_service); + g_object_unref (account); +} diff --git a/tests/lib/logger-test-helper.h b/tests/lib/logger-test-helper.h new file mode 100644 index 0000000..36d5af2 --- /dev/null +++ b/tests/lib/logger-test-helper.h @@ -0,0 +1,39 @@ +/* + * logger-test-helper.h + * + * Copyright (C) 2013 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __LOGGER_TEST_HELPER_H__ +#define __LOGGER_TEST_HELPER_H__ + +#include + +#include "simple-account.h" + +void tpl_test_create_and_prepare_account (TpDBusDaemon *dbus, + TpSimpleClientFactory *factory, + GMainLoop *main_loop, + const gchar *path, + TpAccount **account, + TpTestsSimpleAccount **account_service); + +void tpl_test_release_account (TpDBusDaemon *dbus, + TpAccount *account, + TpTestsSimpleAccount *account_service); + +#endif -- 1.8.3.1