tizen 2.3 release
[framework/api/bluetooth.git] / TC / testcase / utc_network_bluetooth_pan_negative.c
1 /*
2  * utc_network_bluetooth_pan_negative.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_set_connection_state_changed_n(void);
26 static void utc_network_bluetooth_panu_set_connection_state_changed_n(void);
27 static void utc_network_bluetooth_panu_connect_n(void);
28 static void utc_network_bluetooth_nap_disconnect_n(void);
29 static void utc_network_bluetooth_panu_disconnect_n(void);
30
31 void adapter_state_changed_cb_for_pan_n(int result,
32                                                 bt_adapter_state_e adapter_state, void *user_data);
33 gboolean timeout_func(gpointer data);
34
35
36 struct tet_testlist tet_testlist[] = {
37         {utc_network_bluetooth_nap_set_connection_state_changed_n, NEGATIVE_TC_IDX},
38         {utc_network_bluetooth_panu_set_connection_state_changed_n, NEGATIVE_TC_IDX},
39         {utc_network_bluetooth_panu_connect_n, NEGATIVE_TC_IDX},
40         {utc_network_bluetooth_nap_disconnect_n, NEGATIVE_TC_IDX},
41         {utc_network_bluetooth_panu_disconnect_n, NEGATIVE_TC_IDX},
42         {NULL, 0},
43 };
44
45 static void startup(void)
46 {
47         int ret = BT_ERROR_NONE;
48         int timeout_id = 0;
49
50         /* start of TC */
51         mainloop = g_main_loop_new(NULL, FALSE);
52
53         bt_initialize();
54         if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_pan_n, "startup") != BT_ERROR_NONE) {
55                 tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed");
56         }
57
58         tet_printf("bt_adapter_disable() was called.");
59         ret = bt_adapter_disable();
60         if (ret == BT_ERROR_NONE) {
61                 tet_printf("bt_adapter_disable() succeeded.");
62                 timeout_id = g_timeout_add(60000, timeout_func, mainloop);
63                 g_main_loop_run(mainloop);
64                 g_source_remove(timeout_id);
65         } else if (ret == BT_ERROR_NOT_ENABLED) {
66                 tet_printf("Bluetooth adapter is not enabled.");
67         } else {
68                 tet_printf("DTS may fail because bt_adapter_disable() failed");
69         }
70
71         if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) {
72                 tet_printf("bt_adapter_set_state_changed_cb() failed.");
73         }
74
75         tet_printf("TC start");
76 }
77
78
79 static void cleanup(void)
80 {
81         /* end of TC */
82         bt_deinitialize();
83         tet_printf("TC end.");
84 }
85
86
87 gboolean timeout_func(gpointer data)
88 {
89         tet_printf("Callback: Timeout.");
90         g_main_loop_quit((GMainLoop *)data);
91         return FALSE;
92 }
93
94
95
96
97 /**
98  * @brief Negative test case of bt_nap_set_connection_state_changed_cb()
99  */
100
101 void adapter_state_changed_cb_for_pan_n(int result,
102                                         bt_adapter_state_e adapter_state,
103                                         void *user_data)
104 {
105
106 }
107
108 static void utc_network_bluetooth_nap_set_connection_state_changed_n(void)
109 {
110         int ret = BT_ERROR_NONE;
111
112         ret = bt_nap_set_connection_state_changed_cb(NULL, NULL);
113         dts_check_eq("bt_nap_set_connection_state_changed_cb", ret,
114                      BT_ERROR_INVALID_PARAMETER,
115                      "bt_nap_set_connection_state_changed_cb() failed.");
116
117 }
118
119 /**
120  * @brief Negative test case of bt_panu_set_connection_state_changed_cb()
121  */
122 static void utc_network_bluetooth_panu_set_connection_state_changed_n(void)
123 {
124         int ret = BT_ERROR_NONE;
125
126         ret = bt_panu_set_connection_state_changed_cb(NULL, NULL);
127         dts_check_eq("bt_panu_set_connection_state_changed_cb", ret,
128                      BT_ERROR_INVALID_PARAMETER,
129                      "bt_panu_set_connection_state_changed_cb() failed.");
130
131 }
132
133 /**
134  * @brief Negative test case of bt_panu_connect()
135  */
136 static void utc_network_bluetooth_panu_connect_n(void)
137 {
138         int ret = BT_ERROR_NONE;
139         ret = bt_panu_connect(NULL, BT_PANU_SERVICE_TYPE_NAP);
140         dts_check_eq("bt_panu_connect", ret, BT_ERROR_INVALID_PARAMETER,
141                         "bt_panu_connect() failed.");
142
143 }
144
145 /**
146  * @brief Negative test case of bt_nap_disconnect()
147  */
148 static void utc_network_bluetooth_nap_disconnect_n(void)
149 {
150         int ret = BT_ERROR_NONE;
151         ret = bt_nap_disconnect(NULL);
152         dts_check_eq("bt_nap_disconnect", ret, BT_ERROR_INVALID_PARAMETER,
153                         "bt_nap_disconnect() failed.");
154
155 }
156 /**
157  * @brief Negative test case of bt_panu_disconnect()
158  */
159 static void utc_network_bluetooth_panu_disconnect_n(void)
160 {
161         int ret = BT_ERROR_NONE;
162         ret = bt_panu_disconnect(NULL);
163         dts_check_eq("bt_panu_disconnect", ret, BT_ERROR_INVALID_PARAMETER,
164                         "bt_panu_disconnect() failed.");
165
166 }