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 static connman_bool_t is_connman_running(DBusConnection *connection)
35 connman_bool_t running;
37 dbus_error_init(&error);
39 running = dbus_bus_name_has_owner(connection, CONNMAN_SERVICE, &error);
41 if (dbus_error_is_set(&error) == TRUE) {
42 fprintf(stderr, "%s\n", error.message);
43 dbus_error_free(&error);
51 static gboolean test_session_create_no_notify(gpointer data)
53 struct test_fix *fix = data;
56 util_session_create(fix, 1);
58 msg = manager_create_session(fix->session->connection,
59 fix->session->info, "/foo");
60 g_assert(msg != NULL);
61 g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
63 dbus_message_unref(msg);
65 g_assert(is_connman_running(fix->session->connection) == TRUE);
66 util_idle_call(fix, util_quit_loop, util_session_destroy);
71 static gboolean test_session_destroy_no_notify(gpointer data)
73 struct test_fix *fix = data;
76 util_session_create(fix, 1);
78 msg = manager_destroy_session(fix->session->connection, "/foo");
79 g_assert(msg == NULL);
81 g_assert(is_connman_running(fix->session->connection) == TRUE);
82 util_idle_call(fix, util_quit_loop, util_session_destroy);
87 static void set_session_mode(struct test_fix *fix,
88 connman_bool_t enable)
92 msg = manager_set_session_mode(fix->main_connection, enable);
93 g_assert(msg != NULL);
94 g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
96 dbus_message_unref(msg);
98 util_idle_call(fix, util_quit_loop, NULL);
101 static gboolean enable_session_mode(gpointer data)
103 struct test_fix *fix = data;
105 set_session_mode(fix, TRUE);
110 static gboolean disable_session_mode(gpointer data)
112 struct test_fix *fix = data;
114 set_session_mode(fix, FALSE);
119 static void setup_cb(struct test_fix *fix, gconstpointer data)
121 util_setup(fix, data);
123 util_call(fix, enable_session_mode, NULL);
124 g_main_loop_run(fix->main_loop);
127 static void teardown_cb(struct test_fix *fix, gconstpointer data)
129 util_call(fix, disable_session_mode, NULL);
130 g_main_loop_run(fix->main_loop);
132 util_teardown(fix, data);
135 int main(int argc, char *argv[])
137 g_test_init(&argc, &argv, NULL);
139 util_test_add("/manager/session create no notify",
140 test_session_create_no_notify, setup_cb, teardown_cb);
141 util_test_add("/manager/session destroy no notify",
142 test_session_destroy_no_notify, setup_cb, teardown_cb);