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