1b88352c131ed79e58c20fdd5b6e03ce16f6b690
[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-share_test.cpp
18  * @author      abc
19  * @version     1.0
20  * @brief       Unit-tests setup
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 static GMainLoop *mainloop = NULL;
42
43 static gboolean timeout_func(gpointer data)
44 {
45     g_main_loop_quit((GMainLoop *)data);
46     return FALSE;
47 }
48
49 static void wait_for_async(int timeout)
50 {
51     int timeout_id = 0;
52     mainloop = g_main_loop_new(NULL, FALSE);
53
54     timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
55     g_main_loop_run(mainloop);
56     g_source_remove(timeout_id);
57 }
58
59 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
60 {
61         printf("event_type: [%d], data size: [%d]\n", event_type, len);
62 }
63
64 TEST(BluetoothHAL_test, oal_bt_init_deinit_p) {
65         int ret = OAL_STATUS_SUCCESS;
66         ret = oal_bt_init(__bt_oal_event_receiver);
67         ASSERT_TRUE(ret != OAL_STATUS_PENDING);
68
69         oal_bt_deinit();
70 }
71
72 TEST(BluetoothHAL_test, adapter_enable_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
78         ret = adapter_enable();
79         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
80
81         wait_for_async(6000); /* Wait for 6 seconds */
82 }
83
84 TEST(BluetoothHAL_test, adapter_disable_p) {
85         int ret = OAL_STATUS_SUCCESS;
86
87         ret = adapter_disable();
88         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
89
90         wait_for_async(6000);
91 }
92
93 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
94         int ret = OAL_STATUS_SUCCESS;
95         gboolean powered = FALSE;
96
97         /* Precondition : BT enable */
98         ret = adapter_enable();
99         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
100
101         wait_for_async(6000);
102
103         ret = adapter_get_powered_status(&powered);
104         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
105 }
106
107 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
108         int ret = OAL_STATUS_SUCCESS;
109
110         ret = adapter_start_inquiry(0);
111         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
112
113         wait_for_async(2000);
114
115         ret = adapter_stop_inquiry();
116         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
117         wait_for_async(2000);
118 }
119
120 TEST(BluetoothHAL_test, adapter_get_properties_p) {
121         int ret = OAL_STATUS_SUCCESS;
122
123         ret = adapter_get_properties();
124         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
125
126         wait_for_async(2000);
127 }
128
129 TEST(BluetoothHAL_test, adapter_get_address_p) {
130         int ret = OAL_STATUS_SUCCESS;
131
132         ret = adapter_get_address();
133         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
134
135         wait_for_async(2000);
136 }
137
138 TEST(BluetoothHAL_test, adapter_get_version_p) {
139         int ret = OAL_STATUS_SUCCESS;
140
141         ret = adapter_get_version();
142         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
143
144         wait_for_async(2000);
145 }
146
147 TEST(BluetoothHAL_test, adapter_get_name_p) {
148         int ret = OAL_STATUS_SUCCESS;
149
150         ret = adapter_get_name();
151         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
152
153         wait_for_async(2000);
154 }
155
156 TEST(BluetoothHAL_test, adapter_set_name_p) {
157         int ret = OAL_STATUS_SUCCESS;
158
159         ret = adapter_set_name("TizenHAL");
160         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
161
162         wait_for_async(2000);
163 }
164
165 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
166         int ret = OAL_STATUS_SUCCESS;
167         int scan_mode = 0;
168
169         ret = adapter_is_discoverable(&scan_mode);
170         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
171 }
172
173 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
174         int ret = OAL_STATUS_SUCCESS;
175         int connectable = 0;
176
177         ret = adapter_is_connectable(&connectable);
178         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
179 }
180
181 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
182         int ret = OAL_STATUS_SUCCESS;
183         int timeout = 0;
184
185         ret = adapter_get_discoverable_timeout(&timeout);
186         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
187 }
188
189 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
190         int ret = OAL_STATUS_SUCCESS;
191
192         ret = adapter_get_service_uuids();
193         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
194
195         wait_for_async(2000);
196 }
197
198 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
199         int ret = OAL_STATUS_SUCCESS;
200
201         ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
202         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
203
204         wait_for_async(2000);
205 }
206
207 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
208         int ret = OAL_STATUS_SUCCESS;
209
210         ret = adapter_set_discoverable_timeout(0);
211         ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
212
213         wait_for_async(2000);
214 }
215
216
217 int main(int argc, char **argv) {
218   InitGoogleTest(&argc, argv);
219
220   return RUN_ALL_TESTS();
221 }