a21f5269d3eead6e176eb4f687062a8ffa610854
[platform/upstream/connman.git] / tools / session-test.h
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2012  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         GSourceFunc manager_changed;
44
45         /* session test cases */
46         unsigned int max_sessions;
47         struct test_session *session;
48 };
49
50 /* utils.c */
51 typedef void (* util_test_setup_cb) (struct test_fix *fix,
52                                         gconstpointer data);
53 typedef void (* util_test_teardown_cb) (struct test_fix *fix,
54                                         gconstpointer data);
55
56 gboolean util_quit_loop(gpointer fix);
57 guint util_idle_call(struct test_fix *fix, GSourceFunc func,
58                         GDestroyNotify notify);
59 guint util_call(struct test_fix *fix, GSourceFunc func,
60                 GDestroyNotify notify);
61 void util_test_add(const char *test_name, GSourceFunc test_func,
62                         util_test_setup_cb setup_cb,
63                         util_test_teardown_cb teardown_cb);
64 void util_setup(struct test_fix *fix, gconstpointer data);
65 void util_teardown(struct test_fix *fix, gconstpointer data);
66
67 void util_session_create(struct test_fix *fix, unsigned int max_sessions);
68 void util_session_destroy(gpointer fix);
69 void util_session_init(struct test_session *session);
70 void util_session_cleanup(struct test_session *session);
71
72 typedef void (* notify_cb) (struct test_session *session);
73
74 enum connman_session_state {
75         CONNMAN_SESSION_STATE_DISCONNECTED   = 0,
76         CONNMAN_SESSION_STATE_CONNECTED      = 1,
77         CONNMAN_SESSION_STATE_ONLINE         = 2,
78 };
79
80 struct test_session_info {
81         enum connman_session_state state;
82         char *name;
83         char *bearer;
84         char *interface;
85         enum connman_session_type type;
86         /* ipv4, ipv6 dicts */
87         GSList *allowed_bearers;
88 };
89
90 struct test_session {
91         gpointer user_data;
92
93         struct test_fix *fix;
94         DBusConnection *connection;
95
96         char *session_path;
97         char *notify_path;
98         notify_cb notify;
99
100         struct test_session_info *info;
101 };
102
103 struct test_bearer_info {
104         char *name;
105 };
106
107 /* session-api.c */
108 void bearer_info_cleanup(gpointer bearer_info, gpointer user_data);
109
110 void session_append_settings(DBusMessageIter *dict,
111                                 struct test_session_info *info);
112 int session_notify_register(struct test_session *session,
113                                 const char *notify_path);
114 int session_notify_unregister(struct test_session *session,
115                                 const char *notify_path);
116
117 DBusMessage *session_connect(DBusConnection *connection,
118                                 struct test_session *session);
119 DBusMessage *session_disconnect(DBusConnection *connection,
120                                         struct test_session *session);
121
122 /* manager-api.c */
123 DBusMessage *manager_get_services(DBusConnection *connection);
124 DBusMessage *manager_get_properties(DBusConnection *connection);
125 DBusMessage *manager_create_session(DBusConnection *connection,
126                                         struct test_session_info *info,
127                                         const char *notifier_path);
128 DBusMessage *manager_destroy_session(DBusConnection *connection,
129                                         const char *notifier_path);
130 DBusMessage *manager_set_session_mode(DBusConnection *connection,
131                                         connman_bool_t enable);
132 int manager_parse_properties(DBusMessage *msg,
133                                 struct test_manager *manager);
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