tizen 2.3 release
[framework/api/bluetooth.git] / TC / testcase / utc_network_bluetooth_hdp_negative.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <tet_api.h>
18 #include <bluetooth.h>
19 #include <stdlib.h>
20 #include <stdbool.h>
21 #include <glib.h>
22
23 enum {
24         POSITIVE_TC_IDX = 0x01,
25         NEGATIVE_TC_IDX,
26 };
27
28 static void startup(void);
29 static void cleanup(void);
30
31 static GMainLoop *mainloop;
32
33 void (*tet_startup) (void) = startup;
34 void (*tet_cleanup) (void) = cleanup;
35
36 static void utc_network_bluetooth_hdp_register_sink_app_n(void);
37 static void utc_network_bluetooth_hdp_unregister_sink_app_n(void);
38 static void utc_network_bluetooth_hdp_connect_to_source_n(void);
39 static void utc_network_bluetooth_hdp_disconnect_n(void);
40 static void utc_network_bluetooth_hdp_send_data_n(void);
41 static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void);
42 static void utc_network_bluetooth_hdp_set_data_received_cb_n(void);
43
44 void adapter_state_changed_cb_for_hdp_n(int result,
45                                         bt_adapter_state_e adapter_state, void *user_data);
46 gboolean timeout_func(gpointer data);
47
48 struct tet_testlist tet_testlist[] = {
49         { utc_network_bluetooth_hdp_register_sink_app_n, NEGATIVE_TC_IDX },
50         { utc_network_bluetooth_hdp_connect_to_source_n, NEGATIVE_TC_IDX },
51         { utc_network_bluetooth_hdp_send_data_n, NEGATIVE_TC_IDX },
52         { utc_network_bluetooth_hdp_set_connection_state_changed_cb_n, NEGATIVE_TC_IDX },
53         { utc_network_bluetooth_hdp_set_data_received_cb_n, NEGATIVE_TC_IDX },
54         { utc_network_bluetooth_hdp_disconnect_n, NEGATIVE_TC_IDX },
55         { utc_network_bluetooth_hdp_unregister_sink_app_n, NEGATIVE_TC_IDX },
56         { NULL, 0 },
57 };
58
59 static void startup(void)
60 {
61         int ret = BT_ERROR_NONE;
62         int timeout_id = 0;
63
64         /* start of TC */
65         mainloop = g_main_loop_new(NULL, FALSE);
66
67         bt_initialize();
68         if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hdp_n, "startup") != BT_ERROR_NONE) {
69                 tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed");
70         }
71
72         tet_printf("bt_adapter_disable() was called.");
73         ret = bt_adapter_disable();
74         if (ret == BT_ERROR_NONE) {
75                 tet_printf("bt_adapter_disable() succeeded.");
76                 timeout_id = g_timeout_add(60000, timeout_func, mainloop);
77                 g_main_loop_run(mainloop);
78                 g_source_remove(timeout_id);
79         } else if (ret == BT_ERROR_NOT_ENABLED) {
80                 tet_printf("Bluetooth adapter is not enabled.");
81         } else {
82                 tet_printf("DTS may fail because bt_adapter_disable() failed");
83         }
84
85         if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) {
86                 tet_printf("bt_adapter_set_state_changed_cb() failed.");
87         }
88
89         tet_printf("TC start");
90 }
91
92 static void cleanup(void)
93 {
94         /* end of TC */
95         bt_deinitialize();
96         tet_printf("TC end.");
97 }
98
99 gboolean timeout_func(gpointer data)
100 {
101         tet_printf("Callback: Timeout.");
102         g_main_loop_quit((GMainLoop *) data);
103         return FALSE;
104 }
105
106 /**
107  * @brief Callback funtions
108  */
109 void adapter_state_changed_cb_for_hdp_n(int result,
110                                                         bt_adapter_state_e adapter_state, void *user_data)
111 {
112
113 }
114
115
116 /**
117  * @brief Negative test case of bt_hdp_set_data_received_cb()
118  */
119 static void utc_network_bluetooth_hdp_set_data_received_cb_n(void)
120 {
121         int ret = BT_ERROR_NONE;
122
123         ret = bt_hdp_set_data_received_cb(NULL, NULL);
124         dts_check_eq("bt_hdp_set_data_received_cb", ret, BT_ERROR_INVALID_PARAMETER,
125                 "BT_ERROR_INVALID_PARAMETER is returned when cb parameters are NULL");
126 }
127
128 /**
129  * @brief Negative test case of bt_hdp_set_connection_state_changed_cb()
130  */
131 static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void)
132 {
133         int ret = BT_ERROR_NONE;
134
135         ret = bt_hdp_set_connection_state_changed_cb(NULL, NULL, NULL);
136         dts_check_eq("bt_hdp_set_connection_state_changed_cb", ret,
137                                 BT_ERROR_INVALID_PARAMETER,
138                 "BT_ERROR_INVALID_PARAMETER is returned when cb parameters are NULL");
139 }
140
141
142 /**
143  * @brief Negative test case of bt_hdp_disconnect()
144  */
145 static void utc_network_bluetooth_hdp_disconnect_n(void)
146 {
147         int ret = BT_ERROR_NONE;
148
149         ret = bt_hdp_disconnect(NULL, 1);
150         dts_check_eq("bt_hdp_disconnect", ret, BT_ERROR_INVALID_PARAMETER,
151                 "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL");
152 }
153
154 /**
155  * @brief Negative test case of bt_hdp_connect_to_source()
156  */
157 static void utc_network_bluetooth_hdp_connect_to_source_n(void)
158 {
159         int ret = BT_ERROR_NONE;
160
161         ret = bt_hdp_connect_to_source(NULL, NULL);
162         dts_check_eq("bt_hdp_connect_to_source", ret, BT_ERROR_INVALID_PARAMETER,
163                 "BT_ERROR_INVALID_PARAMETER must be returned when remote address and app_id parameter are NULL");
164 }
165
166 /**
167  * @brief Negative test case of bt_hdp_register_sink_app()
168  */
169 static void utc_network_bluetooth_hdp_register_sink_app_n(void)
170 {
171         int ret = BT_ERROR_NONE;
172
173         ret = bt_hdp_register_sink_app(1, NULL);
174         dts_check_eq("bt_hdp_register_sink_app", ret, BT_ERROR_INVALID_PARAMETER,
175                         "BT_ERROR_INVALID_PARAMETER must be returned when app_id parameter is NULL");
176 }
177
178 /**
179  * @brief Negative test case of bt_hdp_unregister_sink_appe()
180  */
181 static void utc_network_bluetooth_hdp_unregister_sink_app_n(void)
182 {
183         int ret = BT_ERROR_NONE;
184
185         ret = bt_hdp_unregister_sink_app(NULL);
186         dts_check_eq("bt_shdp_unregister_sink", ret, BT_ERROR_INVALID_PARAMETER,
187                         "BT_ERROR_INVALID_PARAMETER must be returned when app_id parameter is NULL");
188 }
189
190 /**
191  * @brief Negative test case of bt_hdp_send_data()
192  */
193 static void utc_network_bluetooth_hdp_send_data_n(void)
194 {
195         int ret = BT_ERROR_NONE;
196         char *data = "dts_test";
197
198         ret = bt_hdp_send_data(1, data, sizeof(data));
199         dts_check_eq("bt_hdp_send_data", ret, BT_ERROR_NOT_ENABLED,
200                         "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled");
201 }