Add the base code for gtest verification 57/166157/2
authorDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 8 Jan 2018 08:46:04 +0000 (17:46 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 8 Jan 2018 08:54:15 +0000 (17:54 +0900)
Change-Id: I7de555d205946e879e3961172798454b69b89208
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
CMakeLists.txt
bt-share/CMakeLists.txt
lib/CMakeLists.txt
packaging/bluetooth-share.spec
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/bluetooth-share_test.cpp [new file with mode: 0644]

index 3debe04..afe91b3 100644 (file)
@@ -3,3 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 ADD_SUBDIRECTORY(lib)
 
 ADD_SUBDIRECTORY(bt-share)
+
+IF (BUILD_GTESTS)
+ADD_SUBDIRECTORY(unittest)
+ENDIF (BUILD_GTESTS)
index 5c73189..4307483 100644 (file)
@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(bluetooth-share C)
+PROJECT(bluetooth-share C CXX)
 
 SET(SRCS src/bt-share-main.c
 src/bt-share-notification.c
@@ -54,9 +54,23 @@ ADD_DEFINITIONS("-DSLP_DEBUG")
 #endif(CONTACTS_SERVICE2_FOUND)
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+
 #TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${CALENDAR_SERVICE2_LDFLAGS} ${CONTACTS_SERVICE2_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../lib -lbluetooth-share-api)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../lib -lbluetooth-share-api)
 
+IF (BUILD_GTESTS)
+# Do not include "-fvisibility=hidden" option to call internal functions
+SET(CMAKE_C_FLAGS "-fpie ${EXTRA_CFLAGS} -fPIC -Werror -Wno-deprecated-declarations")
+
+ADD_LIBRARY(bt-share SHARED ${SRCS})
+SET_TARGET_PROPERTIES(bt-share
+       PROPERTIES
+       SOVERSION 0.1.0
+       CLEAN_DIRECT_OUTPUT 1)
+
+TARGET_LINK_LIBRARIES(bt-share ${pkgs_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../lib -lbluetooth-share-api)
+INSTALL(TARGETS bt-share DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+ENDIF (BUILD_GTESTS)
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 #INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/org.bluetooth.share.service DESTINATION share/dbus-1/system-services)
index 3ab3806..a3d63c2 100644 (file)
@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(bluetooth-share-api C)
+PROJECT(bluetooth-share-api C CXX)
 
 SET(SRCS bt-share-db.c
 )
index 76da9eb..3c9eecc 100644 (file)
@@ -4,7 +4,7 @@
 
 Name:       bluetooth-share
 Summary:    Bluetooth file share Agent
-Version:    0.0.48
+Version:    0.0.49
 Release:    0
 Group:      Network & Connectivity/Bluetooth
 License:    Apache-2.0
@@ -39,6 +39,9 @@ BuildRequires:  pkgconfig(cynara-creds-dbus)
 BuildRequires:  pkgconfig(eventsystem)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(libsystemd)
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+%endif
 
 %description
 Bluetooth File Share Agent
@@ -73,7 +76,9 @@ export CXXFLAGS+=" -fpie -fvisibility=hidden"
 export LDFLAGS+=" -Wl,--rpath=/usr/lib -Wl,--as-needed -Wl,--unresolved-symbols=ignore-in-shared-libs -pie"
 
 %cmake . \
-       -DCMAKE_INSTALL_PREFIX=%{_prefix}
+       -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+       -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+       -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
 make
 
 %install
@@ -110,6 +115,12 @@ ln -sf %{_libdir}/systemd/system/bluetooth-share.service %{_sysconfdir}/systemd/
 %{_libdir}/systemd/system/bluetooth-share.service
 %{upgrade_script_path}/500.bluetooth-share_upgrade.sh
 %{upgrade_data_path}/init_db.sh
+%if 0%{?gtests:1}
+%{_bindir}/gtest-bluetooth-share
+%exclude %{_libdir}/libbt-share.so*
+%exclude %{_libdir}/debug/*
+%exclude %{_libdir}/debug/.build-id/*
+%endif
 
 %files -n libbluetooth-share
 %manifest libbluetooth-share.manifest
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1f043dc
--- /dev/null
@@ -0,0 +1,54 @@
+# Copyright (c) 2014-2017 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        CMakeLists.txt
+# @author
+# @brief       Cmake for tests
+#
+SET(TARGET_GTEST_TESTS "gtest-bluetooth-share")
+
+INCLUDE_DIRECTORIES(/usr/include)
+INCLUDE_DIRECTORIES(/usr/include/db-util)
+INCLUDE_DIRECTORIES(/usr/include/glib-2.0)
+INCLUDE_DIRECTORIES(/usr/lib/glib-2.0/include/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/bt-share/include)
+
+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-share_test.cpp
+)
+
+ADD_EXECUTABLE(${TARGET_GTEST_TESTS}
+       ${GTEST_TESTS_SOURCES}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_GTEST_TESTS}
+       ${pkgs_LDFLAGS}
+       ${pkgs_LIBRARIES}
+       gmock
+       -L${CMAKE_SOURCE_DIR}/lib
+       -lbluetooth-share-api
+       -L${CMAKE_SOURCE_DIR}/bt-share
+       -lbt-share
+)
+
+INSTALL(TARGETS ${TARGET_GTEST_TESTS} DESTINATION /usr/bin)
diff --git a/unittest/bluetooth-share_test.cpp b/unittest/bluetooth-share_test.cpp
new file mode 100644 (file)
index 0000000..756275a
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014 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-share_test.cpp
+ * @author      abc
+ * @version     1.0
+ * @brief       Unit-tests setup
+ */
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <glib.h>
+#include "bluetooth-share-api.h"
+#include "bt-share-common.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(BluetoothShare_test, _bt_share_block_sleep_p) {
+       int ret = BT_SHARE_ERROR_NONE;
+
+       ret = _bt_share_block_sleep(TRUE);
+       ASSERT_FALSE(ret == BT_SHARE_ERROR_NONE);
+
+       ret = _bt_share_block_sleep(FALSE);
+       ASSERT_FALSE(ret == BT_SHARE_ERROR_NONE);
+}
+
+int main(int argc, char **argv) {
+  InitGoogleTest(&argc, argv);
+
+  return RUN_ALL_TESTS();
+}