Add bluetooth-haltests package 21/253321/1 accepted/tizen/unified/20210218.042126 submit/tizen/20210216.223518
authorDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 9 Feb 2021 01:35:28 +0000 (10:35 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 9 Feb 2021 01:41:07 +0000 (10:41 +0900)
Change-Id: Idd27a568b30094c86cc440d3b84f85cad11988c2
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
CMakeLists.txt
packaging/hal-api-bluetooth.spec
test/CMakeLists.txt [new file with mode: 0644]
test/bluetooth_hal_tc.cpp [new file with mode: 0644]

index 09c959a..f33061f 100644 (file)
@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(hal-api-bluetooth C)
+PROJECT(hal-api-bluetooth C CXX)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin")
@@ -20,6 +20,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 SET(PKG_MODULES
        dlog
        hal-api-common
+       libtzplatform-config
+       gmock
 )
 
 INCLUDE(FindPkgConfig)
@@ -29,10 +31,9 @@ FOREACH(flag ${pkgs_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt")
-SET(CMAKE_EXE_LINKER_FLAGS "-pie")
 
 ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_BLUETOOTH\"")
 
@@ -40,7 +41,7 @@ SET(SRCS
         src/hal-api-bluetooth.c)
 
 ADD_LIBRARY(           ${PROJECT_NAME} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -lm -Wl,-z,nodelete,--no-undefined,--rpath=${LIBDIR}/hal)
+TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -lgcov -lm -Wl,-z,nodelete,--no-undefined,--rpath=${LIBDIR}/hal)
 SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
 
@@ -49,3 +50,5 @@ INSTALL(TARGETS               ${PROJECT_NAME} DESTINATION ${LIBDIR}/hal)
 INSTALL(FILES          ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-bluetooth.h DESTINATION ${INCLUDEDIR}/hal)
 INSTALL(FILES          ${CMAKE_CURRENT_SOURCE_DIR}/include/hal-bluetooth-interface.h DESTINATION ${INCLUDEDIR}/hal)
 INSTALL(FILES          ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig)
+
+ADD_SUBDIRECTORY(test)
index 2985d7c..60b24cb 100644 (file)
@@ -20,6 +20,7 @@ BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(hal-api-common)
 
 %description
@@ -34,6 +35,15 @@ Requires:    %{name} = %{version}-%{release}
 %description -n        %{devel_name}
 %{name} Interface for product vendor developer
 
+### test package #########
+%package -n bluetooth-haltests
+Summary: Test package for BT HAL interface
+Group:   TO_BE/FILLED
+Requires: %{name} = %{version}-%{release}
+
+%description -n bluetooth-haltests
+This package is C-API test application.
+
 ### build and install #########
 %prep
 %setup -q
@@ -71,3 +81,7 @@ rm -rf %{buildroot}
 %license LICENSE
 %{_includedir}/hal/*.h
 %{_libdir}/pkgconfig/%{name}.pc
+
+%files -n bluetooth-haltests
+%manifest %{name}.manifest
+%{_bindir}/hal/bluetooth-haltests
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4a27f92
--- /dev/null
@@ -0,0 +1,33 @@
+SET(TARGET_GTEST_TESTS "bluetooth-haltests")
+
+INCLUDE_DIRECTORIES(/usr/include)
+#INCLUDE_DIRECTORIES(/usr/include/db-util)
+INCLUDE_DIRECTORIES(/usr/include/glib-2.0)
+INCLUDE_DIRECTORIES(/usr/include/system)
+INCLUDE_DIRECTORIES(/usr/lib/glib-2.0/include/)
+INCLUDE_DIRECTORIES(/usr/lib64/glib-2.0/include/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(INCLUDEDIR "/usr/include")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(testpkgs REQUIRED glib-2.0 gmock)
+
+SET(GTEST_TESTS_SOURCES
+bluetooth_hal_tc.cpp
+)
+
+ADD_EXECUTABLE(${TARGET_GTEST_TESTS}
+       ${GTEST_TESTS_SOURCES}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_GTEST_TESTS}
+       ${testpkgs_LDFLAGS}
+       ${testpkgs_LIBRARIES}
+       gmock
+       hal-api-bluetooth
+)
+
+INSTALL(TARGETS ${TARGET_GTEST_TESTS} DESTINATION /usr/bin/hal)
diff --git a/test/bluetooth_hal_tc.cpp b/test/bluetooth_hal_tc.cpp
new file mode 100644 (file)
index 0000000..c855511
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        bluetooth_hal_tc.cpp
+ * @author      abc
+ * @version     1.0
+ * @brief       BT hal tests
+ */
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "hal-bluetooth-interface.h"
+#include "hal-bluetooth.h"
+
+using ::testing::EmptyTestEventListener;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+using ::testing::TestEventListeners;
+using ::testing::TestInfo;
+using ::testing::TestPartResult;
+using ::testing::UnitTest;
+
+TEST(BluetoothHALtest, bluetooth_get_put_backend_p) {
+       int ret = HAL_BACKEND_ERROR_NONE;
+
+       ret = hal_bluetooth_get_backend();
+       ASSERT_TRUE(ret == HAL_BACKEND_ERROR_NONE);
+
+       ret = hal_bluetooth_put_backend();
+       ASSERT_TRUE(ret == HAL_BACKEND_ERROR_NONE);
+}
+
+TEST(BluetoothHALtest, bluetooth_start_p) {
+       int ret = HAL_BACKEND_ERROR_NONE;
+
+       ret = hal_bluetooth_get_backend();
+       ASSERT_TRUE(ret == HAL_BACKEND_ERROR_NONE);
+
+       ret = hal_bluetooth_start();
+       ASSERT_TRUE(ret == HAL_BACKEND_ERROR_NONE);
+}
+
+TEST(BluetoothHALtest, bluetooth_stop_p) {
+       int ret = HAL_BACKEND_ERROR_NONE;
+
+       ret = hal_bluetooth_get_backend();
+       ASSERT_TRUE(ret == HAL_BACKEND_ERROR_NONE);
+
+       ret = hal_bluetooth_stop();
+       ASSERT_TRUE(ret == HAL_BACKEND_ERROR_NONE);
+}
+
+int main(int argc, char **argv) {
+  InitGoogleTest(&argc, argv);
+
+  return RUN_ALL_TESTS();
+}