From: Seungha Son Date: Fri, 8 Jan 2021 07:52:23 +0000 (+0900) Subject: Add hal-api-common uniitest skeleton X-Git-Tag: accepted/tizen/unified/20210113.121021^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F14%2F251114%2F6;p=platform%2Fhal%2Fapi%2Fcommon.git Add hal-api-common uniitest skeleton This test will run automatically when building gbs. The result can be checked by the developer and the side effect of the edited content can be checked. it is a test for the currently implemented operation, and a test for applying TDD in the future. Change-Id: I5af141dbb601524ff517b78e7cc970323ed138fc Signed-off-by: Seungha Son --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fc2b438..060a688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(hal-api-common C) +PROJECT(hal-api-common C CXX) SET(VERSION_MAJOR 0) SET(VERSION "${VERSION_MAJOR}.1.0") @@ -46,3 +46,5 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h") INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) + +ADD_SUBDIRECTORY(haltests) diff --git a/haltests/CMakeLists.txt b/haltests/CMakeLists.txt new file mode 100644 index 0000000..30a7992 --- /dev/null +++ b/haltests/CMakeLists.txt @@ -0,0 +1,30 @@ +ENABLE_TESTING() +SET(HAL_COMMON_UNITTEST "common-unittest") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g -Wall -Werror") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -g -Wall -Werror") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed,--gc-sections -pie") + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src UNITTEST_SRCS) +ADD_EXECUTABLE(${HAL_COMMON_UNITTEST} ${UNITTEST_SRCS}) + +TARGET_INCLUDE_DIRECTORIES(${HAL_COMMON_UNITTEST} PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/../include" + "${CMAKE_CURRENT_SOURCE_DIR}/../src" +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(hal_common_unittest_pkgs REQUIRED gmock) + +FOREACH(flag ${hal_common_unittest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +TARGET_LINK_LIBRARIES(${HAL_COMMON_UNITTEST} ${hal_common_unittest_pkgs_LDFLAGS} hal-api-common) +SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(${HAL_COMMON_UNITTEST} PROPERTIES LINK_FLAGS "-pie") + +ADD_TEST( + NAME ${HAL_COMMON_UNITTEST} + COMMAND ${HAL_COMMON_UNITTEST} +) diff --git a/haltests/src/test_hal.cc b/haltests/src/test_hal.cc new file mode 100644 index 0000000..cb51371 --- /dev/null +++ b/haltests/src/test_hal.cc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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 + +#include +#include +#include + +#include "hal-common.h" +#include "hal-common-interface.h" + +using namespace std; + +class CommonHaltest : public testing::Test { + public: + CommonHaltest() {} + + virtual ~CommonHaltest() {} + + virtual void SetUp() {} + + virtual void TearDown() {} +}; + +TEST(CommonHaltest, get_backend_library_name_unknown) { + const char *ret = hal_common_get_backend_library_name(HAL_MODULE_UNKNOWN); + EXPECT_TRUE(ret == nullptr); +} diff --git a/haltests/src/test_main.cc b/haltests/src/test_main.cc new file mode 100644 index 0000000..c2eb730 --- /dev/null +++ b/haltests/src/test_main.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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 +#include + +int main(int argc, char** argv) { + int ret = -1; + + try { + testing::InitGoogleTest(&argc, argv); + } catch(...) { + std::cout << "Exception occurred" << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& e) { + ret = -1; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + } + + return ret; +} diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 9704ee6..b6e21ee 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -17,6 +17,7 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmock) %description %{name} interface @@ -40,6 +41,9 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir}/ cp %{SOURCE1} . make %{?jobs:-j%jobs} +%check +(cd haltests && LD_LIBRARY_PATH=../ ctest -V) + %install rm -rf %{buildroot} %make_install