5 * Copyright (C) 2011 BWM CarIT GmbH. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "gdbus/gdbus.h"
30 #include "test-connman.h"
32 #define ENABLE_WRAPPER 1
34 gboolean util_quit_loop(gpointer data)
36 struct test_fix *fix = data;
38 g_main_loop_quit(fix->main_loop);
43 guint util_idle_call(struct test_fix *fix, GSourceFunc func,
44 GDestroyNotify notify)
49 source = g_idle_source_new();
50 g_source_set_callback(source, func, fix, notify);
51 id = g_source_attach(source, g_main_loop_get_context(fix->main_loop));
52 g_source_unref(source);
57 guint util_call(struct test_fix *fix, GSourceFunc func,
58 GDestroyNotify notify)
63 source = g_timeout_source_new(0);
64 g_source_set_callback(source, func, fix, notify);
65 id = g_source_attach(source, g_main_loop_get_context(fix->main_loop));
66 g_source_unref(source);
71 void util_setup(struct test_fix *fix, gconstpointer data)
73 fix->main_loop = g_main_loop_new(NULL, FALSE);
74 fix->main_connection = g_dbus_setup_private(DBUS_BUS_SYSTEM,
78 void util_teardown(struct test_fix *fix, gconstpointer data)
80 dbus_connection_close(fix->main_connection);
81 dbus_connection_unref(fix->main_connection);
83 g_main_loop_unref(fix->main_loop);
86 static void util_wrapper(struct test_fix *fix, gconstpointer data)
88 GSourceFunc func = data;
90 if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
91 util_call(fix, func, NULL);
92 g_main_loop_run(fix->main_loop);
96 g_test_trap_assert_passed();
98 util_call(fix, func, NULL);
99 g_main_loop_run(fix->main_loop);
103 void util_test_add(const char *test_name, GSourceFunc test_func,
104 util_test_setup_cb setup_cb,
105 util_test_teardown_cb teardown_cb)
107 g_test_add(test_name, struct test_fix, test_func,
108 setup_cb, util_wrapper, teardown_cb);
111 void util_session_create(struct test_fix *fix, unsigned int max_sessions)
115 fix->max_sessions = max_sessions;
116 fix->session = g_try_new0(struct test_session, max_sessions);
118 for (i = 0; i < max_sessions; i++) {
119 fix->session[i].fix = fix;
120 fix->session[i].info = g_try_new0(struct test_session_info, 1);
121 fix->session[i].connection = g_dbus_setup_private(
122 DBUS_BUS_SYSTEM, NULL, NULL);
126 void util_session_destroy(gpointer data)
128 struct test_fix *fix = data;
132 for (i = 0; i < fix->max_sessions; i++) {
133 dbus_connection_close(fix->session[i].connection);
134 g_free(fix->session[i].info);
137 g_free(fix->session);
140 void util_session_init(struct test_session *session)
143 DBusMessageIter iter;
147 err = session_notify_register(session, session->notify_path);
150 msg = manager_create_session(session->connection,
152 session->notify_path);
153 g_assert(msg != NULL);
154 dbus_message_iter_init(msg, &iter);
156 dbus_message_iter_get_basic(&iter, &path);
157 session->session_path = g_strdup(path);
159 dbus_message_unref(msg);
162 void util_session_cleanup(struct test_session *session)
167 msg = manager_destroy_session(session->connection,
168 session->session_path);
169 g_assert(msg != NULL);
170 dbus_message_unref(msg);
172 err = session_notify_unregister(session,
173 session->notify_path);
176 g_free(session->info->bearer);
177 g_free(session->info->name);
178 g_free(session->info->interface);
179 g_slist_foreach(session->info->allowed_bearers,
180 bearer_info_cleanup, NULL);
181 g_slist_free(session->info->allowed_bearers);
183 session->notify = NULL;
184 g_free(session->notify_path);
185 g_free(session->session_path);