From: Ji-hoon Lee Date: Mon, 10 Feb 2020 08:10:07 +0000 (+0900) Subject: Introduce compile-time unit tests X-Git-Tag: submit/tizen/20200408.110745~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d77fde30bd1d77c5c46174d187f6e74137a3de1;p=platform%2Fcore%2Fuifw%2Fmulti-assistant-service.git Introduce compile-time unit tests Change-Id: Id2c98124a993c60f8519fbb48b052664b0922769 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e874905..f92c5fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,3 +78,8 @@ INSTALL(TARGETS ${BINNAME} DESTINATION ${BINDIR}) TARGET_LINK_LIBRARIES(${BINNAME} -ldl ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) ADD_SUBDIRECTORY(plugins) + +IF(NOT "${TEST_TYPE}" STREQUAL "none") +ENABLE_TESTING() +ADD_SUBDIRECTORY(tests) +ENDIF() diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 4a5faeb..bb4d60b 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -26,6 +26,9 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(multi-assistant) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(pkgmgr-info) +%if %{defined _test_type} +BuildRequires: gtest-devel +%endif BuildRequires: boost-system BuildRequires: boost-thread BuildRequires: cmake @@ -58,6 +61,11 @@ export LDFLAGS %cmake \ -DCMAKE_INSTALL_PREFIX=%{_appdir} \ -DTZ_SYS_RO_SHARE=%TZ_SYS_RO_SHARE \ +%if %{defined _test_type} + -DTEST_TYPE="%{_test_type}" \ +%else + -DTEST_TYPE="none" \ +%endif make %{?jobs:-j%jobs} @@ -68,6 +76,11 @@ cp LICENSE.Flora %{buildroot}%{TZ_SYS_RO_SHARE}/license/%{name} %make_install +%check +%if "%{_ctest_enable}" == "true" +ctest --output-on-failure %{?_smp_mflags} +%endif + %post mkdir -p %{_appbindir} mkdir -p %{_libdir}/multiassistant/ma/1.0/engine diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..e70c66e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +ADD_SUBDIRECTORY(utc) diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt new file mode 100644 index 0000000..2c2f631 --- /dev/null +++ b/tests/utc/CMakeLists.txt @@ -0,0 +1,3 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +ADD_SUBDIRECTORY(service) diff --git a/tests/utc/service/CMakeLists.txt b/tests/utc/service/CMakeLists.txt new file mode 100644 index 0000000..b9d543b --- /dev/null +++ b/tests/utc/service/CMakeLists.txt @@ -0,0 +1,47 @@ +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wno-unused-function -Wno-sign-compare") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") + +SET(TEST_SOURCES + main.cpp + ${CMAKE_SOURCE_DIR}/src/multi_assistant_config.cpp +) + +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-preference + multi-assistant + dlog + libxml-2.0 +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FIND_PACKAGE(GTest REQUIRED) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) +LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS}) + +SET(TEST_SERVICE test-service) +ADD_EXECUTABLE(${TEST_SERVICE} + ${TEST_SOURCES} + ) + +TARGET_LINK_LIBRARIES(${TEST_SERVICE} -ldl ${GTEST_LIBRARIES} pthread + ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${TEST_SERVICE} DESTINATION bin) + +ADD_TEST(NAME ${TEST_SERVICE} COMMAND ${TEST_SERVICE}) diff --git a/tests/utc/service/main.cpp b/tests/utc/service/main.cpp new file mode 100644 index 0000000..24271c9 --- /dev/null +++ b/tests/utc/service/main.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2018 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 + +class ServiceWithEmptyWakeWord : public testing::Test { +public: + ServiceWithEmptyWakeWord() { + } + virtual ~ServiceWithEmptyWakeWord() { + } +}; + +class ServiceWithAnArbitraryWakeWord : public testing::Test { +public: + ServiceWithAnArbitraryWakeWord() { + } + virtual ~ServiceWithAnArbitraryWakeWord() { + } +}; + +TEST_F(ServiceWithEmptyWakeWord, HasOneWakeWordAfterAdd) { +} + +TEST_F(ServiceWithAnArbitraryWakeWord, HasTwoWakeWordsAfterAdd) { +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +}