unit: Use D-Bus watch for testing ConnMan running
[framework/connectivity/connman.git] / unit / test-connman.h
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. 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 #include <glib.h>
23
24 #include <connman/dbus.h>
25
26 #include "../src/connman.h"
27
28 struct test_session;
29
30 struct test_fix {
31         gpointer user_data;
32
33         GMainLoop *main_loop;
34         DBusConnection *main_connection;
35         guint watch;
36
37         /* session test cases */
38         unsigned int max_sessions;
39         struct test_session *session;
40 };
41
42 /* utils.c */
43 typedef void (* util_test_setup_cb) (struct test_fix *fix,
44                                         gconstpointer data);
45 typedef void (* util_test_teardown_cb) (struct test_fix *fix,
46                                         gconstpointer data);
47
48 gboolean util_quit_loop(gpointer fix);
49 guint util_idle_call(struct test_fix *fix, GSourceFunc func,
50                         GDestroyNotify notify);
51 guint util_call(struct test_fix *fix, GSourceFunc func,
52                 GDestroyNotify notify);
53 void util_test_add(const char *test_name, GSourceFunc test_func,
54                         util_test_setup_cb setup_cb,
55                         util_test_teardown_cb teardown_cb);
56 void util_setup(struct test_fix *fix, gconstpointer data);
57 void util_teardown(struct test_fix *fix, gconstpointer data);
58
59 void util_session_create(struct test_fix *fix, unsigned int max_sessions);
60 void util_session_destroy(gpointer fix);
61 void util_session_init(struct test_session *session);
62 void util_session_cleanup(struct test_session *session);
63
64 typedef void (* notify_cb) (struct test_session *session);
65
66 enum connman_session_roaming_policy {
67         CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN          = 0,
68         CONNMAN_SESSION_ROAMING_POLICY_DEFAULT          = 1,
69         CONNMAN_SESSION_ROAMING_POLICY_ALWAYS           = 2,
70         CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN        = 3,
71         CONNMAN_SESSION_ROAMING_POLICY_NATIONAL         = 4,
72         CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL    = 5,
73 };
74
75 struct test_session_info {
76         char *bearer;
77         connman_bool_t online;
78         char *name;
79         /* ipv4, ipv6 dicts */
80         GSList *allowed_bearers;
81         connman_bool_t priority;
82         connman_bool_t avoid_handover;
83         connman_bool_t stay_connected;
84         unsigned int periodic_connect;
85         unsigned int idle_timeout;
86         connman_bool_t ecall;
87         enum connman_session_roaming_policy roaming_policy;
88         char *interface;
89         unsigned int marker;
90 };
91
92 struct test_session {
93         gpointer user_data;
94
95         struct test_fix *fix;
96         DBusConnection *connection;
97
98         char *session_path;
99         char *notify_path;
100         notify_cb notify;
101
102         struct test_session_info *info;
103 };
104
105 struct test_bearer_info {
106         char *name;
107 };
108
109 /* session-api.c */
110 void bearer_info_cleanup(gpointer bearer_info, gpointer user_data);
111
112 void session_append_settings(DBusMessageIter *dict,
113                                 struct test_session_info *info);
114 int session_notify_register(struct test_session *session,
115                                 const char *notify_path);
116 int session_notify_unregister(struct test_session *session,
117                                 const char *notify_path);
118
119 DBusMessage *session_connect(DBusConnection *connection,
120                                 struct test_session *session);
121 DBusMessage *session_disconnect(DBusConnection *connection,
122                                         struct test_session *session);
123
124 /* manager-api.c */
125 DBusMessage *manager_get_services(DBusConnection *connection);
126 DBusMessage *manager_create_session(DBusConnection *connection,
127                                         struct test_session_info *info,
128                                         const char *notifier_path);
129 DBusMessage *manager_destroy_session(DBusConnection *connection,
130                                         const char *notifier_path);
131 DBusMessage *manager_set_session_mode(DBusConnection *connection,
132                                         connman_bool_t enable);
133
134
135 /* #define DEBUG */
136 #ifdef DEBUG
137 #include <stdio.h>
138
139 #define LOG(fmt, arg...) do { \
140         fprintf(stdout, "%s:%s() " fmt "\n", \
141                         __FILE__, __FUNCTION__ , ## arg); \
142 } while (0)
143 #else
144 #define LOG(fmt, arg...)
145 #endif