Fix resource leak
[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 struct test_fix;
30
31 struct test_manager {
32         char *state;
33 };
34
35 typedef void (* util_test_func_t) (struct test_fix *fix);
36
37 struct test_fix {
38         gpointer user_data;
39
40         GMainLoop *main_loop;
41         DBusConnection *main_connection;
42         unsigned int watch;
43         unsigned int manager_watch;
44
45         struct test_manager manager;
46         util_test_func_t manager_changed;
47
48         /* session test cases */
49         unsigned int max_sessions;
50         struct test_session *session;
51 };
52
53 void util_quit_loop(struct test_fix *fix);
54 void util_idle_call(struct test_fix *fix, util_test_func_t func,
55                         util_test_func_t destroy);
56 void util_call(struct test_fix *fix, util_test_func_t func,
57                 util_test_func_t destroy);
58 void util_test_add(const char *test_name, util_test_func_t test,
59                         util_test_func_t setup,
60                         util_test_func_t teardown);
61 void util_setup(struct test_fix *fix);
62 void util_teardown(struct test_fix *fix);
63
64 void util_session_create(struct test_fix *fix, unsigned int max_sessions);
65 void util_session_destroy(struct test_fix *fix);
66 void util_session_init(struct test_session *session);
67 void util_session_cleanup(struct test_session *session);
68
69 typedef void (* notify_func_t) (struct test_session *session);
70
71 struct test_session_info {
72         enum connman_session_state state;
73         char *name;
74         char *bearer;
75         char *interface;
76         enum connman_session_type type;
77         /* ipv4, ipv6 dicts */
78         GSList *allowed_bearers;
79         char *allowed_interface;
80         bool source_ip_rule;
81         char *context_identifier;
82 };
83
84 struct test_session {
85         void *user_data;
86
87         struct test_fix *fix;
88         DBusConnection *connection;
89
90         char *session_path;
91         char *notify_path;
92         notify_func_t notify;
93
94         struct test_session_info *info;
95 };
96
97 struct test_bearer_info {
98         char *name;
99 };
100
101 /* session-api.c */
102 void bearer_info_cleanup(gpointer bearer_info, gpointer user_data);
103
104 void session_append_settings(DBusMessageIter *dict,
105                                 struct test_session_info *info);
106 int session_notify_register(struct test_session *session,
107                                 const char *notify_path);
108 int session_notify_unregister(struct test_session *session,
109                                 const char *notify_path);
110
111 DBusMessage *session_connect(DBusConnection *connection,
112                                 struct test_session *session);
113 DBusMessage *session_disconnect(DBusConnection *connection,
114                                         struct test_session *session);
115
116 /* manager-api.c */
117 DBusMessage *manager_get_services(DBusConnection *connection);
118 DBusMessage *manager_get_properties(DBusConnection *connection);
119 DBusMessage *manager_create_session(DBusConnection *connection,
120                                         struct test_session_info *info,
121                                         const char *notifier_path);
122 DBusMessage *manager_destroy_session(DBusConnection *connection,
123                                         const char *notifier_path);
124 DBusMessage *manager_set_session_mode(DBusConnection *connection,
125                                         bool enable);
126 int manager_parse_properties(DBusMessage *msg,
127                                 struct test_manager *manager);
128
129 /* #define DEBUG */
130 #ifdef DEBUG
131 #include <stdio.h>
132
133 #define LOG(fmt, arg...) do { \
134         fprintf(stdout, "%s:%s() " fmt "\n", \
135                         __FILE__, __FUNCTION__ , ## arg); \
136 } while (0)
137 #else
138 #define LOG(fmt, arg...)
139 #endif