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>
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")
FILES_MATCHING PATTERN "*.h")
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc
DESTINATION ${LIBDIR}/pkgconfig)
+
+ADD_SUBDIRECTORY(haltests)
--- /dev/null
+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}
+)
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+}
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gmock)
%description
%{name} interface
cp %{SOURCE1} .
make %{?jobs:-j%jobs}
+%check
+(cd haltests && LD_LIBRARY_PATH=../ ctest -V)
+
%install
rm -rf %{buildroot}
%make_install