2 * Copyright (c) 2014 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.
17 * @file bluetooth_hal_tc.cpp
23 #include <gmock/gmock.h>
24 #include <gtest/gtest.h>
27 #include <system_info.h>
29 #include "bluetooth.h"
30 #include "oal-manager.h"
31 #include "oal-adapter-mgr.h"
33 using ::testing::EmptyTestEventListener;
34 using ::testing::InitGoogleTest;
35 using ::testing::Test;
36 using ::testing::TestCase;
37 using ::testing::TestEventListeners;
38 using ::testing::TestInfo;
39 using ::testing::TestPartResult;
40 using ::testing::UnitTest;
42 #define TIMEOUT_6SECONDS 6000
43 #define TIMEOUT_2SECONDS 2000
44 #define TIMEOUT_500MILISECONDS 500
46 #define FEATURE_BT "http://tizen.org/feature/network.bluetooth"
48 #define SKIP_NOT_SUPPORTED(bFeature) {\
50 printf("Feature is not support\n");\
55 static bool g_bFeatureBT;
57 static GMainLoop *mainloop = NULL;
59 static gboolean timeout_func(gpointer data)
61 g_main_loop_quit((GMainLoop *)data);
65 static void wait_for_async(int timeout)
69 mainloop = g_main_loop_new(NULL, FALSE);
71 timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
75 g_main_loop_run(mainloop);
78 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
81 printf("event_type: [%d], data size: [%d]\n", event_type, len);
85 static bool __check_feature_supported(char *key)
88 int ret = system_info_get_platform_bool(key, &value);
90 EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
95 TEST(BluetoothHAL_test, oal_bt_init_deinit_p) {
96 g_bFeatureBT = __check_feature_supported((char*)FEATURE_BT);
97 SKIP_NOT_SUPPORTED(g_bFeatureBT);
99 int ret = OAL_STATUS_SUCCESS;
101 ret = oal_bt_init(__bt_oal_event_receiver);
102 ASSERT_TRUE(ret == OAL_STATUS_PENDING);
104 wait_for_async(TIMEOUT_500MILISECONDS);
108 wait_for_async(TIMEOUT_500MILISECONDS);
111 TEST(BluetoothHAL_test, adapter_enable_p) {
112 SKIP_NOT_SUPPORTED(g_bFeatureBT);
114 int ret = OAL_STATUS_SUCCESS;
115 gboolean powered = FALSE;
117 ret = oal_bt_init(__bt_oal_event_receiver);
118 ASSERT_TRUE(ret == OAL_STATUS_PENDING);
120 wait_for_async(TIMEOUT_500MILISECONDS);
122 ret = adapter_get_powered_status(&powered);
124 /* Already enabled */
128 ret = adapter_enable();
129 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
131 wait_for_async(TIMEOUT_6SECONDS); /* Wait for 6 seconds */
134 TEST(BluetoothHAL_test, adapter_disable_p) {
135 SKIP_NOT_SUPPORTED(g_bFeatureBT);
137 int ret = OAL_STATUS_SUCCESS;
139 ret = adapter_disable();
140 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
142 wait_for_async(TIMEOUT_6SECONDS);
145 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
146 SKIP_NOT_SUPPORTED(g_bFeatureBT);
148 int ret = OAL_STATUS_SUCCESS;
149 gboolean powered = FALSE;
151 /* Precondition : BT enable */
152 ret = adapter_enable();
153 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
155 wait_for_async(TIMEOUT_6SECONDS);
157 ret = adapter_get_powered_status(&powered);
158 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
161 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
162 SKIP_NOT_SUPPORTED(g_bFeatureBT);
164 int ret = OAL_STATUS_SUCCESS;
166 ret = adapter_start_inquiry(0);
167 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
169 wait_for_async(TIMEOUT_2SECONDS);
171 ret = adapter_stop_inquiry();
172 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
173 wait_for_async(TIMEOUT_2SECONDS);
176 TEST(BluetoothHAL_test, adapter_get_properties_p) {
177 SKIP_NOT_SUPPORTED(g_bFeatureBT);
179 int ret = OAL_STATUS_SUCCESS;
181 ret = adapter_get_properties();
182 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
184 wait_for_async(TIMEOUT_500MILISECONDS);
187 TEST(BluetoothHAL_test, adapter_get_address_p) {
188 SKIP_NOT_SUPPORTED(g_bFeatureBT);
190 int ret = OAL_STATUS_SUCCESS;
192 ret = adapter_get_address();
193 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
195 wait_for_async(TIMEOUT_500MILISECONDS);
198 TEST(BluetoothHAL_test, adapter_get_version_p) {
199 SKIP_NOT_SUPPORTED(g_bFeatureBT);
201 int ret = OAL_STATUS_SUCCESS;
203 ret = adapter_get_version();
204 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
206 wait_for_async(TIMEOUT_500MILISECONDS);
209 TEST(BluetoothHAL_test, adapter_get_name_p) {
210 SKIP_NOT_SUPPORTED(g_bFeatureBT);
212 int ret = OAL_STATUS_SUCCESS;
214 ret = adapter_get_name();
215 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
217 wait_for_async(TIMEOUT_500MILISECONDS);
220 TEST(BluetoothHAL_test, adapter_set_name_p) {
221 SKIP_NOT_SUPPORTED(g_bFeatureBT);
223 int ret = OAL_STATUS_SUCCESS;
225 ret = adapter_set_name((char *)"TizenHAL");
226 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
228 wait_for_async(TIMEOUT_500MILISECONDS);
231 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
232 SKIP_NOT_SUPPORTED(g_bFeatureBT);
234 int ret = OAL_STATUS_SUCCESS;
237 ret = adapter_is_discoverable(&scan_mode);
238 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
241 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
242 SKIP_NOT_SUPPORTED(g_bFeatureBT);
244 int ret = OAL_STATUS_SUCCESS;
247 ret = adapter_is_connectable(&connectable);
248 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
251 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
252 SKIP_NOT_SUPPORTED(g_bFeatureBT);
254 int ret = OAL_STATUS_SUCCESS;
257 ret = adapter_get_discoverable_timeout(&timeout);
258 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
261 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
262 SKIP_NOT_SUPPORTED(g_bFeatureBT);
264 int ret = OAL_STATUS_SUCCESS;
266 ret = adapter_get_service_uuids();
267 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
269 wait_for_async(TIMEOUT_500MILISECONDS);
272 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
273 SKIP_NOT_SUPPORTED(g_bFeatureBT);
275 int ret = OAL_STATUS_SUCCESS;
277 ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
278 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
280 wait_for_async(TIMEOUT_500MILISECONDS);
283 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
284 SKIP_NOT_SUPPORTED(g_bFeatureBT);
286 int ret = OAL_STATUS_SUCCESS;
288 ret = adapter_set_discoverable_timeout(0);
289 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
291 wait_for_async(TIMEOUT_500MILISECONDS);
293 /* Post condition : Disable BT */
294 ret = adapter_disable();
295 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
297 wait_for_async(TIMEOUT_6SECONDS);
301 wait_for_async(TIMEOUT_500MILISECONDS);
305 int main(int argc, char **argv) {
306 InitGoogleTest(&argc, argv);
308 return RUN_ALL_TESTS();