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)
57 mainloop = g_main_loop_new(NULL, FALSE);
59 timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
63 g_main_loop_run(mainloop);
66 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
69 printf("event_type: [%d], data size: [%d]\n", event_type, len);
73 TEST(BluetoothHAL_test, oal_bt_init_deinit_p) {
74 int ret = OAL_STATUS_SUCCESS;
75 ret = oal_bt_init(__bt_oal_event_receiver);
76 ASSERT_TRUE(ret == OAL_STATUS_PENDING);
78 wait_for_async(TIMEOUT_500MILISECONDS);
82 wait_for_async(TIMEOUT_500MILISECONDS);
85 TEST(BluetoothHAL_test, adapter_enable_p) {
86 int ret = OAL_STATUS_SUCCESS;
87 gboolean powered = FALSE;
89 ret = oal_bt_init(__bt_oal_event_receiver);
90 ASSERT_TRUE(ret == OAL_STATUS_PENDING);
92 wait_for_async(TIMEOUT_500MILISECONDS);
94 ret = adapter_get_powered_status(&powered);
100 ret = adapter_enable();
101 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
103 wait_for_async(TIMEOUT_6SECONDS); /* Wait for 6 seconds */
106 TEST(BluetoothHAL_test, adapter_disable_p) {
107 int ret = OAL_STATUS_SUCCESS;
109 ret = adapter_disable();
110 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
112 wait_for_async(TIMEOUT_6SECONDS);
115 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
116 int ret = OAL_STATUS_SUCCESS;
117 gboolean powered = FALSE;
119 /* Precondition : BT enable */
120 ret = adapter_enable();
121 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
123 wait_for_async(TIMEOUT_6SECONDS);
125 ret = adapter_get_powered_status(&powered);
126 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
129 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
130 int ret = OAL_STATUS_SUCCESS;
132 ret = adapter_start_inquiry(0);
133 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
135 wait_for_async(TIMEOUT_2SECONDS);
137 ret = adapter_stop_inquiry();
138 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
139 wait_for_async(TIMEOUT_2SECONDS);
142 TEST(BluetoothHAL_test, adapter_get_properties_p) {
143 int ret = OAL_STATUS_SUCCESS;
145 ret = adapter_get_properties();
146 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
148 wait_for_async(TIMEOUT_500MILISECONDS);
151 TEST(BluetoothHAL_test, adapter_get_address_p) {
152 int ret = OAL_STATUS_SUCCESS;
154 ret = adapter_get_address();
155 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
157 wait_for_async(TIMEOUT_500MILISECONDS);
160 TEST(BluetoothHAL_test, adapter_get_version_p) {
161 int ret = OAL_STATUS_SUCCESS;
163 ret = adapter_get_version();
164 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
166 wait_for_async(TIMEOUT_500MILISECONDS);
169 TEST(BluetoothHAL_test, adapter_get_name_p) {
170 int ret = OAL_STATUS_SUCCESS;
172 ret = adapter_get_name();
173 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
175 wait_for_async(TIMEOUT_500MILISECONDS);
178 TEST(BluetoothHAL_test, adapter_set_name_p) {
179 int ret = OAL_STATUS_SUCCESS;
181 ret = adapter_set_name((char *)"TizenHAL");
182 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
184 wait_for_async(TIMEOUT_500MILISECONDS);
187 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
188 int ret = OAL_STATUS_SUCCESS;
191 ret = adapter_is_discoverable(&scan_mode);
192 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
195 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
196 int ret = OAL_STATUS_SUCCESS;
199 ret = adapter_is_connectable(&connectable);
200 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
203 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
204 int ret = OAL_STATUS_SUCCESS;
207 ret = adapter_get_discoverable_timeout(&timeout);
208 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
211 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
212 int ret = OAL_STATUS_SUCCESS;
214 ret = adapter_get_service_uuids();
215 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
217 wait_for_async(TIMEOUT_500MILISECONDS);
220 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
221 int ret = OAL_STATUS_SUCCESS;
223 ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
224 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
226 wait_for_async(TIMEOUT_500MILISECONDS);
229 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
230 int ret = OAL_STATUS_SUCCESS;
232 ret = adapter_set_discoverable_timeout(0);
233 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
235 wait_for_async(TIMEOUT_500MILISECONDS);
237 /* Post condition : Disable BT */
238 ret = adapter_disable();
239 ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
241 wait_for_async(TIMEOUT_6SECONDS);
245 wait_for_async(TIMEOUT_500MILISECONDS);
249 int main(int argc, char **argv) {
250 InitGoogleTest(&argc, argv);
252 return RUN_ALL_TESTS();