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 GMainLoop *mainloop;
29 gboolean timeout_func(gpointer data);
31 static void startup(void);
32 static void cleanup(void);
34 void (*tet_startup) (void) = startup;
35 void (*tet_cleanup) (void) = cleanup;
37 static void utc_network_bluetooth_device_discovery_cancel_n(void);
38 static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_n(void);
39 static void utc_network_bluetooth_device_discovery_set_state_changed_cb_n(void);
40 static void utc_network_bluetooth_device_discovery_start_n(void);
41 static void utc_network_bluetooth_device_discovery_get_status_n(void);
43 void adapter_state_changed_cb_for_discovery_n(int result,
44 bt_adapter_state_e adapter_state,
47 struct tet_testlist tet_testlist[] = {
48 {utc_network_bluetooth_device_discovery_cancel_n, NEGATIVE_TC_IDX},
49 {utc_network_bluetooth_device_discovery_set_state_changed_cb_n, NEGATIVE_TC_IDX},
50 {utc_network_bluetooth_device_discovery_get_status_n, NEGATIVE_TC_IDX},
51 {utc_network_bluetooth_device_discovery_start_n, NEGATIVE_TC_IDX},
52 {utc_network_bluetooth_device_discovery_unset_state_changed_cb_n, NEGATIVE_TC_IDX},
56 static void startup(void)
58 int ret = BT_ERROR_NONE;
62 mainloop = g_main_loop_new(NULL, FALSE);
65 if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_discovery_n, "startup") != BT_ERROR_NONE) {
66 tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed");
69 tet_printf("bt_adapter_disable() was called.");
70 ret = bt_adapter_disable();
71 if (ret == BT_ERROR_NONE) {
72 tet_printf("bt_adapter_disable() succeeded.");
73 timeout_id = g_timeout_add(60000, timeout_func, mainloop);
74 g_main_loop_run(mainloop);
75 g_source_remove(timeout_id);
76 } else if (ret == BT_ERROR_NOT_ENABLED) {
77 tet_printf("Bluetooth adapter is not enabled.");
79 tet_printf("DTS may fail because bt_adapter_disable() failed");
82 if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) {
83 tet_printf("bt_adapter_set_state_changed_cb() failed.");
86 tet_printf("TC start");
89 static void cleanup(void)
96 gboolean timeout_func(gpointer data)
98 tet_printf("Callback: Timeout.");
99 g_main_loop_quit((GMainLoop *) data);
104 * @brief Callback funtions
106 void adapter_state_changed_cb_for_discovery_n(int result,
107 state_e adapter_state,
110 tet_printf("Callback: bt_adapter_state_changed_cb was called.");
111 if (user_data != NULL && !strcmp((char *)user_data, "startup")) {
112 if (adapter_state == BT_ADAPTER_DISABLED &&
113 result == BT_ERROR_NONE) {
114 tet_printf("Callback: BT was disabled. DTS will be started.");
116 tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail.");
120 g_main_loop_quit(mainloop);
126 *@brief Negative test case of bt_adapter_stop_device_discovery()
128 static void utc_network_bluetooth_device_discovery_cancel_n(void)
130 int ret = bt_adapter_stop_device_discovery();
132 dts_check_eq("bt_adapter_stop_device_discovery", ret,
133 BT_ERROR_NOT_ENABLED,
134 "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled");
138 *@brief Negative test case of bt_adapter_unset_device_discovery_state_changed_cb()
140 static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_n(void)
142 int ret = BT_ERROR_NONE;
144 if (bt_deinitialize() != BT_ERROR_NONE) {
145 dts_fail("bt_adapter_unset_device_discovery_state_changed_cb",
146 "bt_deinitialize() failed.");
148 ret = bt_adapter_unset_device_discovery_state_changed_cb();
149 dts_check_eq("bt_adapter_unset_device_discovery_state_changed_cb", ret,
150 BT_ERROR_NOT_INITIALIZED,
151 "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized.");
155 *@brief Negative test case of bt_adapter_set_device_discovery_state_changed_cb()
157 static void utc_network_bluetooth_device_discovery_set_state_changed_cb_n(void)
159 int ret = BT_ERROR_NONE;
161 ret = bt_adapter_set_device_discovery_state_changed_cb(NULL, NULL);
162 dts_check_eq("bt_adapter_set_device_discovery_state_changed_cb", ret,
163 BT_ERROR_INVALID_PARAMETER,
164 "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL");
168 *@brief Negative test case of bt_adapter_start_device_discovery()
170 static void utc_network_bluetooth_device_discovery_start_n(void)
172 bt_error_e ret = BT_ERROR_NONE;
174 ret = bt_adapter_start_device_discovery();;
175 dts_check_eq("bt_adapter_start_device_discovery", ret,
176 BT_ERROR_NOT_ENABLED,
177 "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled");
181 *@brief Negative test case of bt_adapter_is_discovering()
183 static void utc_network_bluetooth_device_discovery_get_status_n(void)
185 bt_error_e ret = BT_ERROR_NONE;
188 ret = bt_adapter_is_discovering(&status);
189 dts_check_eq("bt_adapter_is_discovering", ret, BT_ERROR_NOT_ENABLED,
190 "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled");