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>
28 #include "bluetooth.h"
29 #include "oal-manager.h"
30 #include "oal-adapter-mgr.h"
32 using ::testing::EmptyTestEventListener;
33 using ::testing::InitGoogleTest;
34 using ::testing::Test;
35 using ::testing::TestCase;
36 using ::testing::TestEventListeners;
37 using ::testing::TestInfo;
38 using ::testing::TestPartResult;
39 using ::testing::UnitTest;
41 #define TIMEOUT_6SECONDS 6000
42 #define TIMEOUT_2SECONDS 2000
43 #define TIMEOUT_500MILISECONDS 500
45 static GMainLoop *mainloop = NULL;
47 static gboolean timeout_func(gpointer data)
49 g_main_loop_quit((GMainLoop *)data);
53 static void wait_for_async(int timeout)
56 mainloop = g_main_loop_new(NULL, FALSE);
58 timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
59 g_main_loop_run(mainloop);
61 g_source_remove(timeout_id);
65 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
68 printf("event_type: [%d], data size: [%d]\n", event_type, len);
72 TEST(BluetoothHAL_test, oal_bt_init_deinit_p) {
73 int ret = OAL_STATUS_SUCCESS;
74 ret = oal_bt_init(__bt_oal_event_receiver);
75 ASSERT_TRUE(ret == OAL_STATUS_PENDING);
77 wait_for_async(TIMEOUT_500MILISECONDS);
81 wait_for_async(TIMEOUT_500MILISECONDS);
84 TEST(BluetoothHAL_test, adapter_enable_p) {
85 int ret = OAL_STATUS_SUCCESS;
86 gboolean powered = FALSE;
88 ret = oal_bt_init(__bt_oal_event_receiver);
89 ASSERT_TRUE(ret == OAL_STATUS_PENDING);
91 wait_for_async(TIMEOUT_500MILISECONDS);
93 ret = adapter_get_powered_status(&powered);
99 ret = adapter_enable();
100 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
102 wait_for_async(TIMEOUT_6SECONDS); /* Wait for 6 seconds */
105 TEST(BluetoothHAL_test, adapter_disable_p) {
106 int ret = OAL_STATUS_SUCCESS;
108 ret = adapter_disable();
109 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
111 wait_for_async(TIMEOUT_6SECONDS);
114 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
115 int ret = OAL_STATUS_SUCCESS;
116 gboolean powered = FALSE;
118 /* Precondition : BT enable */
119 ret = adapter_enable();
120 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
122 wait_for_async(TIMEOUT_6SECONDS);
124 ret = adapter_get_powered_status(&powered);
125 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
128 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
129 int ret = OAL_STATUS_SUCCESS;
131 ret = adapter_start_inquiry(0);
132 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
134 wait_for_async(TIMEOUT_2SECONDS);
136 ret = adapter_stop_inquiry();
137 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
138 wait_for_async(TIMEOUT_2SECONDS);
141 TEST(BluetoothHAL_test, adapter_get_properties_p) {
142 int ret = OAL_STATUS_SUCCESS;
144 ret = adapter_get_properties();
145 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
147 wait_for_async(TIMEOUT_500MILISECONDS);
150 TEST(BluetoothHAL_test, adapter_get_address_p) {
151 int ret = OAL_STATUS_SUCCESS;
153 ret = adapter_get_address();
154 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
156 wait_for_async(TIMEOUT_500MILISECONDS);
159 TEST(BluetoothHAL_test, adapter_get_version_p) {
160 int ret = OAL_STATUS_SUCCESS;
162 ret = adapter_get_version();
163 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
165 wait_for_async(TIMEOUT_500MILISECONDS);
168 TEST(BluetoothHAL_test, adapter_get_name_p) {
169 int ret = OAL_STATUS_SUCCESS;
171 ret = adapter_get_name();
172 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
174 wait_for_async(TIMEOUT_500MILISECONDS);
177 TEST(BluetoothHAL_test, adapter_set_name_p) {
178 int ret = OAL_STATUS_SUCCESS;
180 ret = adapter_set_name("TizenHAL");
181 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
183 wait_for_async(TIMEOUT_500MILISECONDS);
186 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
187 int ret = OAL_STATUS_SUCCESS;
190 ret = adapter_is_discoverable(&scan_mode);
191 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
194 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
195 int ret = OAL_STATUS_SUCCESS;
198 ret = adapter_is_connectable(&connectable);
199 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
202 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
203 int ret = OAL_STATUS_SUCCESS;
206 ret = adapter_get_discoverable_timeout(&timeout);
207 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
210 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
211 int ret = OAL_STATUS_SUCCESS;
213 ret = adapter_get_service_uuids();
214 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
216 wait_for_async(TIMEOUT_500MILISECONDS);
219 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
220 int ret = OAL_STATUS_SUCCESS;
222 ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
223 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
225 wait_for_async(TIMEOUT_500MILISECONDS);
228 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
229 int ret = OAL_STATUS_SUCCESS;
231 ret = adapter_set_discoverable_timeout(0);
232 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
234 wait_for_async(TIMEOUT_500MILISECONDS);
236 /* Post condition : Disable BT */
237 ret = adapter_disable();
238 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
240 wait_for_async(TIMEOUT_6SECONDS);
244 wait_for_async(TIMEOUT_500MILISECONDS);
248 int main(int argc, char **argv) {
249 InitGoogleTest(&argc, argv);
251 return RUN_ALL_TESTS();