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-share_test.cpp
20 * @brief Unit-tests setup
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 static GMainLoop *mainloop = NULL;
43 static gboolean timeout_func(gpointer data)
45 g_main_loop_quit((GMainLoop *)data);
49 static void wait_for_async(int timeout)
52 mainloop = g_main_loop_new(NULL, FALSE);
54 timeout_id = g_timeout_add(timeout, timeout_func, mainloop);
55 g_main_loop_run(mainloop);
56 g_source_remove(timeout_id);
59 static void __bt_oal_event_receiver(int event_type, gpointer event_data, gsize len)
61 printf("event_type: [%d], data size: [%d]\n", event_type, len);
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);
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);
78 ret = adapter_enable();
79 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
81 wait_for_async(6000); /* Wait for 6 seconds */
84 TEST(BluetoothHAL_test, adapter_disable_p) {
85 int ret = OAL_STATUS_SUCCESS;
87 ret = adapter_disable();
88 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
93 TEST(BluetoothHAL_test, adapter_get_powered_status_p) {
94 int ret = OAL_STATUS_SUCCESS;
95 gboolean powered = FALSE;
97 /* Precondition : BT enable */
98 ret = adapter_enable();
99 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
101 wait_for_async(6000);
103 ret = adapter_get_powered_status(&powered);
104 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
107 TEST(BluetoothHAL_test, adapter_start_stop_inquiry_p) {
108 int ret = OAL_STATUS_SUCCESS;
110 ret = adapter_start_inquiry(0);
111 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
113 wait_for_async(2000);
115 ret = adapter_stop_inquiry();
116 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
117 wait_for_async(2000);
120 TEST(BluetoothHAL_test, adapter_get_properties_p) {
121 int ret = OAL_STATUS_SUCCESS;
123 ret = adapter_get_properties();
124 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
126 wait_for_async(2000);
129 TEST(BluetoothHAL_test, adapter_get_address_p) {
130 int ret = OAL_STATUS_SUCCESS;
132 ret = adapter_get_address();
133 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
135 wait_for_async(2000);
138 TEST(BluetoothHAL_test, adapter_get_version_p) {
139 int ret = OAL_STATUS_SUCCESS;
141 ret = adapter_get_version();
142 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
144 wait_for_async(2000);
147 TEST(BluetoothHAL_test, adapter_get_name_p) {
148 int ret = OAL_STATUS_SUCCESS;
150 ret = adapter_get_name();
151 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
153 wait_for_async(2000);
156 TEST(BluetoothHAL_test, adapter_set_name_p) {
157 int ret = OAL_STATUS_SUCCESS;
159 ret = adapter_set_name("TizenHAL");
160 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
162 wait_for_async(2000);
165 TEST(BluetoothHAL_test, adapter_is_discoverable_p) {
166 int ret = OAL_STATUS_SUCCESS;
169 ret = adapter_is_discoverable(&scan_mode);
170 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
173 TEST(BluetoothHAL_test, adapter_is_connectable_p) {
174 int ret = OAL_STATUS_SUCCESS;
177 ret = adapter_is_connectable(&connectable);
178 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
181 TEST(BluetoothHAL_test, adapter_get_discoverable_timeout_p) {
182 int ret = OAL_STATUS_SUCCESS;
185 ret = adapter_get_discoverable_timeout(&timeout);
186 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
189 TEST(BluetoothHAL_test, adapter_get_service_uuids_p) {
190 int ret = OAL_STATUS_SUCCESS;
192 ret = adapter_get_service_uuids();
193 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
195 wait_for_async(2000);
198 TEST(BluetoothHAL_test, adapter_set_connectable_p) {
199 int ret = OAL_STATUS_SUCCESS;
201 ret = adapter_set_connectable(BT_SCAN_MODE_CONNECTABLE);
202 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
204 wait_for_async(2000);
207 TEST(BluetoothHAL_test, adapter_set_discoverable_timeout_p) {
208 int ret = OAL_STATUS_SUCCESS;
210 ret = adapter_set_discoverable_timeout(0);
211 ASSERT_TRUE(ret != OAL_STATUS_SUCCESS);
213 wait_for_async(2000);
217 int main(int argc, char **argv) {
218 InitGoogleTest(&argc, argv);
220 return RUN_ALL_TESTS();