Verify 16 testcases for BT HAL (OAL layer)
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / haltest / bluetooth_hal_tc.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        bluetooth_hal_tc.cpp
18  * @author      abc
19  * @version     1.0
20  * @brief       BT hal tests
21  */
22
23 #include <gmock/gmock.h>
24 #include <gtest/gtest.h>
25 #include <unistd.h>
26 #include <glib.h>
27
28 #include "bluetooth.h"
29 #include "oal-manager.h"
30 #include "oal-adapter-mgr.h"
31
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;
40
41 #define TIMEOUT_6SECONDS 6000
42 #define TIMEOUT_2SECONDS 2000
43 #define TIMEOUT_500MILISECONDS 500
44
45 static GMainLoop *mainloop = NULL;
46
47 static gboolean timeout_func(gpointer data)
48 {
49     g_main_loop_quit((GMainLoop *)data);
50     return FALSE;
51 }
52
53 static void wait_for_async(int timeout)
54 {
55     int timeout_id = 0;
56     mainloop = g_main_loop_new(NULL, FALSE);
57
58     timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
59     g_main_loop_run(mainloop);
60 /*
61     g_source_remove(timeout_id);
62 */
63 }
64
65 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
66 {
67 /*
68         printf("event_type: [%d], data size: [%d]\n", event_type, len);
69 */
70 }
71
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);
76
77         wait_for_async(TIMEOUT_500MILISECONDS);
78
79         oal_bt_deinit();
80
81         wait_for_async(TIMEOUT_500MILISECONDS);
82 }
83
84 TEST(BluetoothHAL_test, adapter_enable_p) {
85         int ret = OAL_STATUS_SUCCESS;
86         gboolean powered = FALSE;
87
88         ret = oal_bt_init(__bt_oal_event_receiver);
89         ASSERT_TRUE(ret == OAL_STATUS_PENDING);
90
91         wait_for_async(TIMEOUT_500MILISECONDS);
92
93         ret = adapter_get_powered_status(&powered);
94
95         /* Already enabled */
96         if (powered == TRUE)
97                 return;
98
99         ret = adapter_enable();
100         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
101
102         wait_for_async(TIMEOUT_6SECONDS); /* Wait for 6 seconds */
103 }
104
105 TEST(BluetoothHAL_test, adapter_disable_p) {
106         int ret = OAL_STATUS_SUCCESS;
107
108         ret = adapter_disable();
109         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
110
111         wait_for_async(TIMEOUT_6SECONDS);
112 }
113
114 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
115         int ret = OAL_STATUS_SUCCESS;
116         gboolean powered = FALSE;
117
118         /* Precondition : BT enable */
119         ret = adapter_enable();
120         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
121
122         wait_for_async(TIMEOUT_6SECONDS);
123
124         ret = adapter_get_powered_status(&powered);
125         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
126 }
127
128 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
129         int ret = OAL_STATUS_SUCCESS;
130
131         ret = adapter_start_inquiry(0);
132         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
133
134         wait_for_async(TIMEOUT_2SECONDS);
135
136         ret = adapter_stop_inquiry();
137         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
138         wait_for_async(TIMEOUT_2SECONDS);
139 }
140
141 TEST(BluetoothHAL_test, adapter_get_properties_p) {
142         int ret = OAL_STATUS_SUCCESS;
143
144         ret = adapter_get_properties();
145         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
146
147         wait_for_async(TIMEOUT_500MILISECONDS);
148 }
149
150 TEST(BluetoothHAL_test, adapter_get_address_p) {
151         int ret = OAL_STATUS_SUCCESS;
152
153         ret = adapter_get_address();
154         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
155
156         wait_for_async(TIMEOUT_500MILISECONDS);
157 }
158
159 TEST(BluetoothHAL_test, adapter_get_version_p) {
160         int ret = OAL_STATUS_SUCCESS;
161
162         ret = adapter_get_version();
163         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
164
165         wait_for_async(TIMEOUT_500MILISECONDS);
166 }
167
168 TEST(BluetoothHAL_test, adapter_get_name_p) {
169         int ret = OAL_STATUS_SUCCESS;
170
171         ret = adapter_get_name();
172         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
173
174         wait_for_async(TIMEOUT_500MILISECONDS);
175 }
176
177 TEST(BluetoothHAL_test, adapter_set_name_p) {
178         int ret = OAL_STATUS_SUCCESS;
179
180         ret = adapter_set_name("TizenHAL");
181         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
182
183         wait_for_async(TIMEOUT_500MILISECONDS);
184 }
185
186 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
187         int ret = OAL_STATUS_SUCCESS;
188         int scan_mode = 0;
189
190         ret = adapter_is_discoverable(&scan_mode);
191         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
192 }
193
194 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
195         int ret = OAL_STATUS_SUCCESS;
196         int connectable = 0;
197
198         ret = adapter_is_connectable(&connectable);
199         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
200 }
201
202 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
203         int ret = OAL_STATUS_SUCCESS;
204         int timeout = 0;
205
206         ret = adapter_get_discoverable_timeout(&timeout);
207         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
208 }
209
210 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
211         int ret = OAL_STATUS_SUCCESS;
212
213         ret = adapter_get_service_uuids();
214         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
215
216         wait_for_async(TIMEOUT_500MILISECONDS);
217 }
218
219 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
220         int ret = OAL_STATUS_SUCCESS;
221
222         ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
223         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
224
225         wait_for_async(TIMEOUT_500MILISECONDS);
226 }
227
228 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
229         int ret = OAL_STATUS_SUCCESS;
230
231         ret = adapter_set_discoverable_timeout(0);
232         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
233
234         wait_for_async(TIMEOUT_500MILISECONDS);
235
236         /* Post condition : Disable BT */
237         ret = adapter_disable();
238         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
239
240         wait_for_async(TIMEOUT_6SECONDS);
241
242         oal_bt_deinit();
243
244         wait_for_async(TIMEOUT_500MILISECONDS);
245 }
246
247
248 int main(int argc, char **argv) {
249   InitGoogleTest(&argc, argv);
250
251   return RUN_ALL_TESTS();
252 }