Add hal-api-common uniitest skeleton 14/251114/6 accepted/tizen/unified/20210113.121021 submit/tizen/20210113.011459
authorSeungha Son <linuxias@gmail.com>
Fri, 8 Jan 2021 07:52:23 +0000 (16:52 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 12 Jan 2021 23:02:52 +0000 (23:02 +0000)
 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 <linuxias@gmail.com>
CMakeLists.txt
haltests/CMakeLists.txt [new file with mode: 0644]
haltests/src/test_hal.cc [new file with mode: 0644]
haltests/src/test_main.cc [new file with mode: 0644]
packaging/hal-api-common.spec

index fc2b438..060a688 100644 (file)
@@ -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 (file)
index 0000000..30a7992
--- /dev/null
@@ -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 (file)
index 0000000..cb51371
--- /dev/null
@@ -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 <gtest/gtest.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#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 (file)
index 0000000..c2eb730
--- /dev/null
@@ -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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+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;
+}
index 9704ee6..b6e21ee 100644 (file)
@@ -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