tizen 2.3 release
[framework/api/bluetooth.git] / TC / testcase / utc_network_bluetooth_pan_positive.c
1 /*
2  * utc_network_bluetooth_pan_positive.c
3  *
4  *  Created on: 20-Sep-2013
5  *      Author: mrinal.m
6  */
7
8 #include <bluetooth.h>
9 #include <tet_api.h>
10 #include <glib.h>
11
12 enum {
13         POSITIVE_TC_IDX = 0x01,
14         NEGATIVE_TC_IDX,
15 };
16
17 static void startup(void);
18 static void cleanup(void);
19
20 static GMainLoop *mainloop;
21
22 void (*tet_startup) (void) = startup;
23 void (*tet_cleanup) (void) = cleanup;
24
25 static void utc_network_bluetooth_nap_activate_p(void);
26 static void utc_network_bluetooth_nap_deactivate_p(void);
27 static void utc_network_bluetooth_nap_disconnect_all_p(void);
28 static void utc_network_bluetooth_nap_set_connection_state_changed_p(void);
29 static void utc_network_bluetooth_nap_unset_connection_state_changed_p(void);
30 static void utc_network_bluetooth_panu_set_connection_state_changed_p(void);
31 static void utc_network_bluetooth_panu_unset_connection_state_changed_p(void);
32 static void utc_network_bluetooth_panu_connect_p(void);
33 static void utc_network_bluetooth_nap_disconnect_p(void);
34 static void utc_network_bluetooth_panu_disconnect_p(void);
35
36 void connection_state_changed_cb_for_nap_p(bool connected,
37                                                 const char *remote_address,
38                                                 const char *interface_name,
39                                                 void *user_data);
40 void connection_state_changed_cb_for_panu_p(int result,
41                                                 bool connected,
42                                                 const char *remote_address,
43                                                 bt_panu_service_type_e type,
44                                                 void *user_data);
45
46 void adapter_state_changed_cb_for_pan_p(int result,
47                                                 bt_adapter_state_e adapter_state,
48                                                 void *user_data);
49 gboolean timeout_func(gpointer data);
50
51 struct tet_testlist tet_testlist[] = {
52         {utc_network_bluetooth_nap_activate_p, POSITIVE_TC_IDX},
53         {utc_network_bluetooth_nap_set_connection_state_changed_p, POSITIVE_TC_IDX},
54         {utc_network_bluetooth_nap_unset_connection_state_changed_p, POSITIVE_TC_IDX},
55         {utc_network_bluetooth_nap_deactivate_p, POSITIVE_TC_IDX},
56         {utc_network_bluetooth_nap_disconnect_all_p, POSITIVE_TC_IDX},
57         {utc_network_bluetooth_panu_connect_p, POSITIVE_TC_IDX},
58         {utc_network_bluetooth_panu_set_connection_state_changed_p, POSITIVE_TC_IDX},
59         {utc_network_bluetooth_panu_unset_connection_state_changed_p, POSITIVE_TC_IDX},
60         {utc_network_bluetooth_nap_disconnect_p, POSITIVE_TC_IDX},
61         {utc_network_bluetooth_panu_disconnect_p, POSITIVE_TC_IDX},
62         {NULL, 0},
63 };
64
65
66 static void startup(void)
67 {
68         int ret = BT_ERROR_NONE;
69         int timeout_id = 0;
70
71         /* start of TC */
72         mainloop = g_main_loop_new(NULL, FALSE);
73
74         bt_initialize();
75         if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_pan_p, "startup") != BT_ERROR_NONE) {
76                 tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed");
77         }
78
79         tet_printf("bt_adapter_enable() was called.");
80
81         ret = bt_adapter_enable();
82         if (ret == BT_ERROR_NONE) {
83                 tet_printf("bt_adapter_enable() succeeded.");
84                 timeout_id = g_timeout_add(60000, timeout_func, mainloop);
85                 g_main_loop_run(mainloop);
86                 g_source_remove(timeout_id);
87         } else if (ret != BT_ERROR_ALREADY_DONE) {
88                 tet_printf("DTS may fail because bt_adapter_disable() failed");
89         }
90
91         if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) {
92                 tet_printf("bt_adapter_set_state_changed_cb() failed.");
93         }
94
95         tet_printf("TC start");
96 }
97
98 static void cleanup(void)
99 {
100         /* end of TC */
101         bt_deinitialize();
102         tet_printf("TC end.");
103 }
104
105 gboolean timeout_func(gpointer data)
106 {
107         tet_printf("Callback: Timeout.");
108         g_main_loop_quit((GMainLoop *) data);
109         return FALSE;
110 }
111
112 /**
113  * @brief Callback funtions
114 */
115
116 void adapter_state_changed_cb_for_pan_p(int result,
117                                         bt_adapter_state_e adapter_state,
118                                         void *user_data)
119 {
120
121 }
122
123 void connection_state_changed_cb_for_nap_p(bool connected,
124                                         const char *remote_address,
125                                         const char *interface_name,
126                                         void *user_data)
127 {
128
129 }
130
131 void connection_state_changed_cb_for_panu_p(int result,
132                                         bool connected,
133                                         const char *remote_address,
134                                         bt_panu_service_type_e type,
135                                         void *user_data)
136 {
137
138 }
139
140 /**
141  * @brief Positive test case of bt_nap_activate()
142 */
143 static void utc_network_bluetooth_nap_activate_p(void)
144 {
145         int ret = BT_ERROR_NONE;
146         ret = bt_nap_activate();
147         if (ret != BT_ERROR_ALREADY_DONE) {
148                 dts_check_eq("bt_nap_activate", ret, BT_ERROR_NONE, "bt_nap_activate() failed.");
149         } else {
150                 dts_check_eq("bt_nap_activate", ret, BT_ERROR_ALREADY_DONE,
151                         "bt_nap_activate() failed.");
152         }
153 }
154
155 /**
156  * @brief Positive test case of bt_nap_deactivate()
157 */
158 static void utc_network_bluetooth_nap_deactivate_p(void)
159 {
160         int ret = BT_ERROR_NONE;
161         ret = bt_nap_deactivate();
162         dts_check_eq("bt_nap_deactivate", ret, BT_ERROR_NONE,
163                         "bt_nap_deactivate() failed.");
164
165 }
166
167 /**
168  * @brief Positive test case of bt_nap_disconnect_all()
169  */
170 static void utc_network_bluetooth_nap_disconnect_all_p(void)
171 {
172         int ret = BT_ERROR_NONE;
173         ret = bt_nap_disconnect_all();
174         dts_check_eq("bt_nap_disconnect_all", ret, BT_ERROR_NONE,
175                         "bt_nap_disconnect_all() failed.");
176 }
177
178 /**
179  * @brief Positive test case of bt_nap_set_connection_state_changed_cb()
180  */
181 static void utc_network_bluetooth_nap_set_connection_state_changed_p(void)
182 {
183         int ret = BT_ERROR_NONE;
184         ret = bt_nap_set_connection_state_changed_cb(connection_state_changed_cb_for_nap_p, NULL);
185         dts_check_eq("bt_nap_set_connection_state_changed_cb", ret, BT_ERROR_NONE,
186                         "bt_nap_set_connection_state_changed_cb() failed.");
187 }
188
189
190 /**
191  * @brief Positive test case of bt_nap_unset_connection_state_changed_cb()
192 */
193 static void utc_network_bluetooth_nap_unset_connection_state_changed_p(void)
194 {
195         int ret = BT_ERROR_NONE;
196         ret = bt_nap_unset_connection_state_changed_cb();
197         dts_check_eq("bt_nap_unset_connection_state_changed_cb", ret, BT_ERROR_NONE,
198                         "bt_nap_unset_connection_state_changed_cb() failed.");
199 }
200
201
202 /**
203  * @brief Positive test case of bt_panu_set_connection_state_changed_cb()
204 */
205 static void utc_network_bluetooth_panu_set_connection_state_changed_p(void)
206 {
207         int ret = BT_ERROR_NONE;
208
209         ret = bt_panu_set_connection_state_changed_cb(connection_state_changed_cb_for_panu_p, NULL);
210         dts_check_eq("bt_panu_set_connection_state_changed_cb", ret, BT_ERROR_NONE,
211                         "bt_panu_set_connection_state_changed_cb() failed.");
212
213 }
214
215
216 /**
217  * @brief Positive test case of bt_panu_unset_connection_state_changed_cb()
218 */
219 static void utc_network_bluetooth_panu_unset_connection_state_changed_p(void)
220 {
221         int ret = BT_ERROR_NONE;
222         ret = bt_panu_unset_connection_state_changed_cb();
223         dts_check_eq("bt_panu_unset_connection_state_changed_cb", ret, BT_ERROR_NONE,
224                         "bt_panu_unset_connection_state_changed_cb() failed.");
225
226 }
227
228 /**
229  * @brief Positive test case of bt_panu_connect()
230 */
231 static void utc_network_bluetooth_panu_connect_p(void)
232 {
233         int ret = BT_ERROR_NONE;
234         const char *remote_address = "00:00:00:00:00:00";
235         ret = bt_panu_connect(remote_address, BT_PANU_SERVICE_TYPE_NAP);
236         dts_check_eq("bt_panu_connect", ret, BT_ERROR_NONE,
237                         "bt_panu_connect() failed.");
238
239 }
240
241 /**
242  * @brief Positive test case of bt_nap_disconnect()
243 */
244 static void utc_network_bluetooth_nap_disconnect_p(void)
245 {
246         int ret = BT_ERROR_NONE;
247         const char *remote_address = "00:00:00:00:00:00";
248         ret = bt_nap_disconnect(remote_address);
249         dts_check_eq("bt_nap_disconnect", ret, BT_ERROR_NONE,
250                         "bt_nap_disconnect() failed.");
251
252 }
253
254 /**
255  * @brief Positive test case of bt_panu_disconnect()
256 */
257 static void utc_network_bluetooth_panu_disconnect_p(void)
258 {
259         int ret = BT_ERROR_NONE;
260         const char *remote_address = "00:00:00:00:00:00";
261         ret = bt_panu_disconnect(remote_address);
262         dts_check_eq("bt_panu_disconnect", ret, BT_ERROR_NONE,
263                         "bt_panu_disconnect() failed.");
264
265 }