Prep gmock tests 08/238308/3
authorDaehyeon Jung <darrenh.jung@samsung.com>
Fri, 10 Jul 2020 07:01:43 +0000 (16:01 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Wed, 15 Jul 2020 02:27:47 +0000 (11:27 +0900)
Change-Id: I9f6fbe93ec1ae8b82288633ea7f3cf94c03d27e7
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
CMakeLists.txt
cmake/Modules/ApplyPkgConfig.cmake [new file with mode: 0644]
packaging/app2sd.spec
unit-tests/CMakeLists.txt [new file with mode: 0644]
unit-tests/test_main.cc [new file with mode: 0644]

index 48417f0..2b987cb 100644 (file)
@@ -1,11 +1,15 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(app2ext C)
+PROJECT(app2ext C CXX)
 
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror")
 
+SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
+
 INCLUDE(FindPkgConfig)
-pkg_check_modules(app2ext_libpkgs REQUIRED dlog glib-2.0)
+INCLUDE(ApplyPkgConfig)
+PKG_CHECK_MODULES(app2ext_libpkgs REQUIRED dlog glib-2.0)
+PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
 
 FOREACH(flag ${app2ext_libpkgs_CFLAGS})
        SET(APP2EXT_CFLAGS "${APP2EXT_CFLAGS} ${flag}")
@@ -36,3 +40,4 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/inc/ DESTINATION include)
 
 ADD_SUBDIRECTORY(plugin/app2sd)
 ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(unit-tests)
diff --git a/cmake/Modules/ApplyPkgConfig.cmake b/cmake/Modules/ApplyPkgConfig.cmake
new file mode 100644 (file)
index 0000000..97679d7
--- /dev/null
@@ -0,0 +1,35 @@
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+#
+# This function applies external (out of source tree) dependencies
+# to given target. Arguments are:
+#   TARGET - valid cmake target
+#   PRIVACY - dependency can be inherited by dependent targets or not:
+#     PUBLIC - this should be used by default, cause compile/link flags passing
+#     PRIVATE - do not passes any settings to dependent targets,
+#               may be usefull for static libraries from the inside of the project
+# Argument ARGV2 and following are supposed to be names of checked pkg config
+# packages. This function will use variables created by check_pkg_modules().
+#  - ${DEP_NAME}_LIBRARIES
+#  - ${DEP_NAME}_INCLUDE_DIRS
+#  - ${DEP_NAME}_CFLAGS
+#
+FUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
+  MATH(EXPR DEST_INDEX "${ARGC}-1")
+  FOREACH(I RANGE 2 ${DEST_INDEX})
+    IF(NOT ${ARGV${I}}_FOUND)
+      MESSAGE(FATAL_ERROR "Not found dependency - ${ARGV${I}}_FOUND")
+    ENDIF(NOT ${ARGV${I}}_FOUND)
+    TARGET_LINK_LIBRARIES(${TARGET} ${PRIVACY} "${${ARGV${I}}_LIBRARIES}")
+    TARGET_INCLUDE_DIRECTORIES(${TARGET} ${PRIVACY} SYSTEM "${${ARGV${I}}_INCLUDE_DIRS}")
+    STRING(REPLACE ";" " " CFLAGS_STR "${${ARGV${I}}_CFLAGS}")
+    SET(CFLAGS_LIST ${CFLAGS_STR})
+    SEPARATE_ARGUMENTS(CFLAGS_LIST)
+    FOREACH(OPTION ${CFLAGS_LIST})
+      TARGET_COMPILE_OPTIONS(${TARGET} ${PRIVACY} ${OPTION})
+    ENDFOREACH(OPTION)
+    SET_TARGET_PROPERTIES(${TARGET} PROPERTIES SKIP_BUILD_RPATH true)
+  ENDFOREACH(I RANGE 2 ${DEST_INDEX})
+ENDFUNCTION(APPLY_PKG_CONFIG TARGET PRIVACY)
index 4666b51..9285709 100644 (file)
@@ -17,6 +17,7 @@ BuildRequires:  pkgconfig(pkgmgr-info)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(pkgmgr)
@@ -65,6 +66,10 @@ make %{?jobs:-j%jobs}
 rm -rf %{buildroot}
 %make_install
 
+%check
+cd unit-tests
+ctest -V
+
 %post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..cfb6cce
--- /dev/null
@@ -0,0 +1,15 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ TEST_SRCS)
+
+ENABLE_TESTING()
+
+SET(TARGET_TEST "app2sd-test")
+
+ADD_EXECUTABLE(${TARGET_TEST} ${TEST_SRCS})
+
+APPLY_PKG_CONFIG(${TARGET_TEST} PUBLIC
+  GMOCK_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_TEST} PUBLIC ${TARGET_LIB_COMMON} pthread)
+
+ADD_TEST(${TARGET_TEST} ${TARGET_TEST})
diff --git a/unit-tests/test_main.cc b/unit-tests/test_main.cc
new file mode 100644 (file)
index 0000000..c6f2820
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * app2sd-unittest
+ *
+ * Copyright (c) 2020 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.
+ *
+ */
+
+#include <gmock/gmock.h>
+
+namespace {
+const ::testing::Environment* env = nullptr;
+}
+
+namespace app2sd {
+
+class App2sdEnvironment : public ::testing::Environment {
+ public:
+  void SetUp() override {
+
+  }
+
+  void TearDown() override {
+
+  }
+};
+
+} // namespace app2sd
+
+int main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    ::env = testing::AddGlobalTestEnvironment(new app2sd::App2sdEnvironment);
+    return RUN_ALL_TESTS();
+}