unit: Toggle SessionMode for each test case
[framework/connectivity/connman.git] / unit / test-session.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2011  BWM CarIT GmbH. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "gdbus/gdbus.h"
27
28 #include "test-connman.h"
29
30 static gboolean test_empty(gpointer data)
31 {
32         struct test_fix *fix = data;
33
34         util_idle_call(fix, util_quit_loop, NULL);
35
36         return FALSE;
37 }
38
39 static void set_session_mode(struct test_fix *fix,
40                                         connman_bool_t enable)
41 {
42         DBusMessage *msg;
43
44         msg = manager_set_session_mode(fix->main_connection, enable);
45         g_assert(msg != NULL);
46         g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);
47
48         dbus_message_unref(msg);
49
50         util_idle_call(fix, util_quit_loop, NULL);
51 }
52
53 static gboolean enable_session_mode(gpointer data)
54 {
55         struct test_fix *fix = data;
56
57         set_session_mode(fix, TRUE);
58
59         return FALSE;
60 }
61
62 static gboolean disable_session_mode(gpointer data)
63 {
64         struct test_fix *fix = data;
65
66         set_session_mode(fix, FALSE);
67
68         return FALSE;
69 }
70
71 static void setup_cb(struct test_fix *fix, gconstpointer data)
72 {
73         util_setup(fix, data);
74
75         util_call(fix, enable_session_mode, NULL);
76         g_main_loop_run(fix->main_loop);
77 }
78
79 static void teardown_cb(struct test_fix *fix, gconstpointer data)
80 {
81         util_call(fix, disable_session_mode, NULL);
82         g_main_loop_run(fix->main_loop);
83
84         util_teardown(fix, data);
85 }
86
87 int main(int argc, char *argv[])
88 {
89         g_test_init(&argc, &argv, NULL);
90
91         util_test_add("/empty",
92                 test_empty, setup_cb, teardown_cb);
93
94         return g_test_run();
95 }