summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpr.jung <pr.jung@samsung.com>2018-03-28 11:02:58 (GMT)
committerpr.jung <pr.jung@samsung.com>2018-03-30 10:16:15 (GMT)
commitd7c2cbd3f80d31eedef47ce57f55e73af08b88d1 (patch)
tree04e7e4c86d16f38749abe29a3367263e72897924
parentb93073fa2d54f6976ea441c69c6baeda18113d33 (diff)
downloadlibdevice-node-d7c2cbd3f80d31eedef47ce57f55e73af08b88d1.zip
libdevice-node-d7c2cbd3f80d31eedef47ce57f55e73af08b88d1.tar.gz
libdevice-node-d7c2cbd3f80d31eedef47ce57f55e73af08b88d1.tar.bz2
gtest: Add gtest for irrefs/changes/37/174137/7
Change-Id: I26ae1223e63c650c354a3f152fe6669023ac348a Signed-off-by: pr.jung <pr.jung@samsung.com>
-rw-r--r--CMakeLists.txt8
-rw-r--r--hw/common.h9
-rw-r--r--packaging/libdevice-node.spec9
-rwxr-xr-xunittest/CMakeLists.txt40
-rw-r--r--unittest/gtest_hal_ir.cpp106
5 files changed, 169 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1aafe71..0c4e82d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,8 +8,8 @@ SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}")
SET(VERSION 0.1)
SET(INC_DIR include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR})
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/${INC_DIR})
INCLUDE(FindPkgConfig)
pkg_check_modules(rpkgs REQUIRED dlog vconf glib-2.0)
@@ -62,3 +62,7 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hw/ DESTINATION include/hw
CONFIGURE_FILE(hwcommon.pc.in hwcommon.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hwcommon.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+IF(BUILD_GTESTS STREQUAL on)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF()
diff --git a/hw/common.h b/hw/common.h
index b333532..76c88f4 100644
--- a/hw/common.h
+++ b/hw/common.h
@@ -20,6 +20,10 @@
#ifndef __HW_COMMON_H__
#define __HW_COMMON_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdint.h>
#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
@@ -82,4 +86,9 @@ int hw_get_info(const char *id, const struct hw_info **info);
__attribute__ ((visibility("default"))) \
struct hw_info HARDWARE_INFO_SYM
+#ifdef __cplusplus
+}
#endif
+
+#endif
+
diff --git a/packaging/libdevice-node.spec b/packaging/libdevice-node.spec
index c4b9273..782d7fd 100644
--- a/packaging/libdevice-node.spec
+++ b/packaging/libdevice-node.spec
@@ -10,6 +10,9 @@ BuildRequires: cmake
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
+
+BuildRequires: pkgconfig(gmock)
%description
development package of library to control OAL APIs
@@ -26,7 +29,10 @@ Library to control OAL APIs (devel)
%setup -q
cp %{SOURCE1} .
%build
-%cmake .
+%cmake -DBUILD_GTESTS=on \
+ .
+ #eol
+
make %{?jobs:-j%jobs}
%install
@@ -39,6 +45,7 @@ make %{?jobs:-j%jobs}
%{_libdir}/*.so.*
%manifest %{name}.manifest
%license LICENSE.APLv2
+%{_bindir}/gtest*
%files devel
%{_includedir}/device-node/*.h
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100755
index 0000000..e3f7305
--- /dev/null
+++ b/unittest/CMakeLists.txt
@@ -0,0 +1,40 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-libdevice-node C CXX)
+
+ADD_DEFINITIONS("-DUSE_DLOG")
+#SET(SRCS
+# ../hw/common.c
+# )
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/hw)
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(gtest_pkgs REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${gtest_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+ GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+ MESSAGE("${src_name}")
+ ADD_EXECUTABLE(${src_name} ${CMAKE_SOURCE_DIR}/hw/common.c ${src})
+ TARGET_LINK_LIBRARIES(${src_name} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl)
+ INSTALL(TARGETS ${src_name} DESTINATION bin)
+ENDFOREACH()
+
diff --git a/unittest/gtest_hal_ir.cpp b/unittest/gtest_hal_ir.cpp
new file mode 100644
index 0000000..144a4c0
--- /dev/null
+++ b/unittest/gtest_hal_ir.cpp
@@ -0,0 +1,106 @@
+
+#include <iostream>
+#include <gtest/gtest.h>
+#include "hw/common.h"
+#include "hw/ir.h"
+
+using namespace std;
+
+/*
+ * main class
+ */
+struct ir_device *ir_dev;
+
+class IRHalTest : public testing::Test
+{
+ public:
+ virtual void SetUp()
+ {
+ struct hw_info *info;
+ int ret;
+ ret = hw_get_info(IR_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ if (ret < 0) {
+ cout << "Fail to load ir hal(" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+ if (!info->open) {
+ cout << "Failed to open ir device; open(NULL)" << endl;
+ assert(true);
+ return;
+ }
+
+ ret = info->open(info, NULL, (struct hw_common**)&ir_dev);
+ if (ret < 0 || !ir_dev) {
+ cout << "Failed to get ir device structure (" << ret << ")" << endl;
+ assert(true);
+ return;
+ }
+
+ return;
+ }
+
+ virtual void TearDown()
+ {
+ struct hw_info *info;
+
+ info = ir_dev->common.info;
+ if (!info)
+ free(ir_dev);
+ else
+ info->close((struct hw_common *)ir_dev);
+ ir_dev = NULL;
+
+ return;
+ }
+};
+
+/*
+ * testcase
+ */
+TEST_F(IRHalTest, InitP)
+{
+ EXPECT_NE(ir_dev, nullptr);
+}
+
+TEST_F(IRHalTest, DeinitP)
+{
+ struct ir_device *tmp;
+ struct hw_info *info;
+ int ret;
+
+ hw_get_info(IR_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+
+ EXPECT_NE(info, nullptr);
+ EXPECT_NE(info->open, nullptr);
+ info->open(info, NULL, (struct hw_common**)&tmp);
+
+ ret = info->close((struct hw_common *)tmp);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(IRHalTest, IsAvailableP)
+{
+ bool val;
+
+ EXPECT_NE(ir_dev, nullptr);
+ ir_dev->is_available(&val);
+}
+
+TEST_F(IRHalTest, TransmitP)
+{
+ int pattern[5] = {100, 200, 300, 400, 500};
+
+ EXPECT_NE(ir_dev, nullptr);
+ ir_dev->transmit(pattern, 5);
+}
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}