Remove unused local variable and codes - wait_for_async( )
[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
57     mainloop = g_main_loop_new(NULL, FALSE);
58
59     timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
60     if (timeout_id < 0)
61         return;
62
63     g_main_loop_run(mainloop);
64 }
65
66 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
67 {
68 /*
69         printf("event_type: [%d], data size: [%d]\n", event_type, len);
70 */
71 }
72
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);
77
78         wait_for_async(TIMEOUT_500MILISECONDS);
79
80         oal_bt_deinit();
81
82         wait_for_async(TIMEOUT_500MILISECONDS);
83 }
84
85 TEST(BluetoothHAL_test, adapter_enable_p) {
86         int ret = OAL_STATUS_SUCCESS;
87         gboolean powered = FALSE;
88
89         ret = oal_bt_init(__bt_oal_event_receiver);
90         ASSERT_TRUE(ret == OAL_STATUS_PENDING);
91
92         wait_for_async(TIMEOUT_500MILISECONDS);
93
94         ret = adapter_get_powered_status(&powered);
95
96         /* Already enabled */
97         if (powered == TRUE)
98                 return;
99
100         ret = adapter_enable();
101         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
102
103         wait_for_async(TIMEOUT_6SECONDS); /* Wait for 6 seconds */
104 }
105
106 TEST(BluetoothHAL_test, adapter_disable_p) {
107         int ret = OAL_STATUS_SUCCESS;
108
109         ret = adapter_disable();
110         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
111
112         wait_for_async(TIMEOUT_6SECONDS);
113 }
114
115 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
116         int ret = OAL_STATUS_SUCCESS;
117         gboolean powered = FALSE;
118
119         /* Precondition : BT enable */
120         ret = adapter_enable();
121         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
122
123         wait_for_async(TIMEOUT_6SECONDS);
124
125         ret = adapter_get_powered_status(&powered);
126         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
127 }
128
129 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
130         int ret = OAL_STATUS_SUCCESS;
131
132         ret = adapter_start_inquiry(0);
133         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
134
135         wait_for_async(TIMEOUT_2SECONDS);
136
137         ret = adapter_stop_inquiry();
138         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
139         wait_for_async(TIMEOUT_2SECONDS);
140 }
141
142 TEST(BluetoothHAL_test, adapter_get_properties_p) {
143         int ret = OAL_STATUS_SUCCESS;
144
145         ret = adapter_get_properties();
146         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
147
148         wait_for_async(TIMEOUT_500MILISECONDS);
149 }
150
151 TEST(BluetoothHAL_test, adapter_get_address_p) {
152         int ret = OAL_STATUS_SUCCESS;
153
154         ret = adapter_get_address();
155         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
156
157         wait_for_async(TIMEOUT_500MILISECONDS);
158 }
159
160 TEST(BluetoothHAL_test, adapter_get_version_p) {
161         int ret = OAL_STATUS_SUCCESS;
162
163         ret = adapter_get_version();
164         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
165
166         wait_for_async(TIMEOUT_500MILISECONDS);
167 }
168
169 TEST(BluetoothHAL_test, adapter_get_name_p) {
170         int ret = OAL_STATUS_SUCCESS;
171
172         ret = adapter_get_name();
173         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
174
175         wait_for_async(TIMEOUT_500MILISECONDS);
176 }
177
178 TEST(BluetoothHAL_test, adapter_set_name_p) {
179         int ret = OAL_STATUS_SUCCESS;
180
181         ret = adapter_set_name("TizenHAL");
182         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
183
184         wait_for_async(TIMEOUT_500MILISECONDS);
185 }
186
187 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
188         int ret = OAL_STATUS_SUCCESS;
189         int scan_mode = 0;
190
191         ret = adapter_is_discoverable(&scan_mode);
192         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
193 }
194
195 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
196         int ret = OAL_STATUS_SUCCESS;
197         int connectable = 0;
198
199         ret = adapter_is_connectable(&connectable);
200         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
201 }
202
203 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
204         int ret = OAL_STATUS_SUCCESS;
205         int timeout = 0;
206
207         ret = adapter_get_discoverable_timeout(&timeout);
208         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
209 }
210
211 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
212         int ret = OAL_STATUS_SUCCESS;
213
214         ret = adapter_get_service_uuids();
215         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
216
217         wait_for_async(TIMEOUT_500MILISECONDS);
218 }
219
220 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
221         int ret = OAL_STATUS_SUCCESS;
222
223         ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
224         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
225
226         wait_for_async(TIMEOUT_500MILISECONDS);
227 }
228
229 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
230         int ret = OAL_STATUS_SUCCESS;
231
232         ret = adapter_set_discoverable_timeout(0);
233         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
234
235         wait_for_async(TIMEOUT_500MILISECONDS);
236
237         /* Post condition : Disable BT */
238         ret = adapter_disable();
239         ASSERT_TRUE(ret == OAL_STATUS_SUCCESS);
240
241         wait_for_async(TIMEOUT_6SECONDS);
242
243         oal_bt_deinit();
244
245         wait_for_async(TIMEOUT_500MILISECONDS);
246 }
247
248
249 int main(int argc, char **argv) {
250   InitGoogleTest(&argc, argv);
251
252   return RUN_ALL_TESTS();
253 }