2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <bluetooth.h>
24 POSITIVE_TC_IDX = 0x01,
28 static void startup(void);
29 static void cleanup(void);
31 static GMainLoop *mainloop;
33 void (*tet_startup) (void) = startup;
34 void (*tet_cleanup) (void) = cleanup;
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);
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);
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 },
59 static void startup(void)
61 int ret = BT_ERROR_NONE;
65 mainloop = g_main_loop_new(NULL, FALSE);
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");
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.");
82 tet_printf("DTS may fail because bt_adapter_disable() failed");
85 if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) {
86 tet_printf("bt_adapter_set_state_changed_cb() failed.");
89 tet_printf("TC start");
92 static void cleanup(void)
96 tet_printf("TC end.");
99 gboolean timeout_func(gpointer data)
101 tet_printf("Callback: Timeout.");
102 g_main_loop_quit((GMainLoop *) data);
107 * @brief Callback funtions
109 void adapter_state_changed_cb_for_hdp_n(int result,
110 bt_adapter_state_e adapter_state, void *user_data)
117 * @brief Negative test case of bt_hdp_set_data_received_cb()
119 static void utc_network_bluetooth_hdp_set_data_received_cb_n(void)
121 int ret = BT_ERROR_NONE;
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");
129 * @brief Negative test case of bt_hdp_set_connection_state_changed_cb()
131 static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void)
133 int ret = BT_ERROR_NONE;
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");
143 * @brief Negative test case of bt_hdp_disconnect()
145 static void utc_network_bluetooth_hdp_disconnect_n(void)
147 int ret = BT_ERROR_NONE;
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");
155 * @brief Negative test case of bt_hdp_connect_to_source()
157 static void utc_network_bluetooth_hdp_connect_to_source_n(void)
159 int ret = BT_ERROR_NONE;
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");
167 * @brief Negative test case of bt_hdp_register_sink_app()
169 static void utc_network_bluetooth_hdp_register_sink_app_n(void)
171 int ret = BT_ERROR_NONE;
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");
179 * @brief Negative test case of bt_hdp_unregister_sink_appe()
181 static void utc_network_bluetooth_hdp_unregister_sink_app_n(void)
183 int ret = BT_ERROR_NONE;
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");
191 * @brief Negative test case of bt_hdp_send_data()
193 static void utc_network_bluetooth_hdp_send_data_n(void)
195 int ret = BT_ERROR_NONE;
196 char *data = "dts_test";
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");